:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e3e6eb;
  --text: #1a1d23;
  --muted: #5b6471;
  --accent: #2b6cb0;
  --accent-soft: #e8f0fa;
  --success: #2f8a3c;
  --warning: #e0a800;
  --danger: #b03a3a;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
header.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}
header.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; }
header.topbar h1 a { color: var(--text); }
header.topbar .spacer { flex: 1; }
header.topbar .user { font-size: 13px; color: var(--muted); }

.btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
  color: var(--text);
  display: inline-block;
}
.btn:hover { background: #f0f2f5; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
.btn-primary:hover { background: #245a93; border-color: #245a93; }
.btn-danger { color: var(--danger); border-color: #e6c3c3; }
.btn-mini { padding: 3px 9px; font-size: 12px; }

.save-btn.dirty {
  box-shadow: 0 0 0 0 rgba(43, 108, 176, 0.55);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(43, 108, 176, 0.5); }
  50% { box-shadow: 0 0 0 5px rgba(43, 108, 176, 0); }
}
.status { font-size: 13px; color: var(--muted); transition: opacity .3s, color .3s; }
.status.success { color: var(--success); }
.status.error { color: var(--danger); }

main { padding: 24px; max-width: 1400px; margin: 0 auto; }

.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.controls input, .controls select {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}
.controls input[type="search"] { width: 240px; }
.counter { color: var(--muted); font-size: 13px; }

/* ---------- Messages ---------- */
.messages { list-style: none; margin: 0 0 16px; padding: 0; }
.messages li {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
}
.messages li.success { border-color: #bfe3c4; background: #f0faf1; }
.messages li.warning { border-color: #f0dfa8; background: #fdf8e8; }
.messages li.error { border-color: #e6c3c3; background: #fbf0f0; }

/* ---------- Login ---------- */
.login-wrap { display: flex; justify-content: center; padding: 60px 20px; }
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.login-card h2 { margin: 0 0 20px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.login-card input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  margin-bottom: 14px;
}
.login-card .errornote, .login-card .errorlist {
  color: var(--danger);
  font-size: 13px;
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}

/* ---------- Lists (versions / documents) ---------- */
.list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  transition: border-color .12s, box-shadow .12s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
a.card { color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.card .title { font-weight: 600; line-height: 1.4; display: flex; align-items: center; gap: 8px; }
.card .dot { flex: 0 0 auto; width: 8px; height: 8px; background: var(--warning); border-radius: 50%; }
.card .dot.done { background: var(--success); }
.card .meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card .sub { font-size: 13px; color: var(--muted); }
.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
  white-space: nowrap;
}
.card .idx { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.comments-count { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); margin-left: 6px; }
.comments-count.has { color: var(--accent); font-weight: 500; }
.empty { color: var(--muted); text-align: center; padding: 60px 20px; grid-column: 1 / -1; }
.pagination { margin-top: 18px; display: flex; gap: 10px; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }

/* ---------- Detail ---------- */
.detail-header {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 22px;
  margin-bottom: 16px;
}
.detail-header .row1 { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.detail-header h2 { margin: 0 0 8px; font-size: 22px; line-height: 1.3; }
.detail-header .source { font-size: 13px; color: var(--muted); word-break: break-all; }
.field-select {
  font: inherit; font-size: 13px; padding: 5px 8px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text);
}

.conflict-banner {
  background: #fdf4e3;
  border: 1px solid #f0dfa8;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.conflict-banner .msg { flex: 1; }

.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
/* Pane count is written by editor.js: source + editor, plus the optional original-ETR
   and cross-version panes. One attribute instead of a modifier class per combination. */
.split[data-cols="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split[data-cols="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* main caps at 1400px, which would leave four panes at ~320px each on any wide screen —
   the viewport-keyed breakpoints below would never fire. Let the widest layout use more
   of the monitor instead. */
main:has(.split[data-cols="4"]) { max-width: 1800px; }
.pane {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.pane h3 {
  margin: 0;
  padding: 12px 18px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px 8px;
  /* h3 is a flex container, so each text run and <code> would otherwise become its own
     flex item and "ETR — wersja (" / "psoni_etr" / ")" would break apart in a narrow
     column. .pane-title keeps the heading one item; wrapping drops the hint below it. */
  flex-wrap: wrap;
}
.pane h3 .pane-title { display: inline-block; }
.pane h3 .edit-hint { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 12px; color: var(--muted); }
.pane .content {
  padding: 18px 22px;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: break-word;
  margin: 0;
}
.pane.etr .content { font-size: 16px; }
.pane.etr textarea.content {
  border: none; outline: none; resize: none; width: 100%; display: block; overflow: hidden;
  font-family: inherit; color: var(--text); background: transparent; min-height: 240px; transition: background .12s;
}
.pane.etr textarea.content:focus { background: #fffbef; }
.pane.etr-original .content { background: #fbfbfc; cursor: text; }
.pane.etr-compare .content { background: #fbfbfc; }
.pane.etr-original .content mark.anchor {
  background: #fff3a8; padding: 0 1px; border-radius: 2px; cursor: pointer;
  transition: background .12s, box-shadow .12s;
}
.pane.etr-original .content mark.anchor:hover { background: #ffe761; }
.pane.etr-original .content mark.anchor.resolved { background: #e6e6e6; color: var(--muted); text-decoration: line-through; }
.pane.etr-original .content mark.anchor.focused { box-shadow: 0 0 0 2px var(--accent); }

/* Rendered Markdown */
.content.md { white-space: normal; }
.content.md > :first-child { margin-top: 0; }
.content.md > :last-child { margin-bottom: 0; }
.content.md h1, .content.md h2, .content.md h3 { line-height: 1.3; margin: 18px 0 10px; }
.content.md h1 { font-size: 20px; font-weight: 700; }
.content.md h2 { font-size: 17px; font-weight: 650; }
.content.md h3 { font-size: 15.5px; font-weight: 600; }
.content.md p { margin: 0 0 12px; }
.content.md ul { margin: 0 0 12px; padding-left: 24px; }
.content.md li { margin: 3px 0; }
.content.md blockquote {
  margin: 0 0 12px; padding: 8px 14px; border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 6px 6px 0;
}
.content.md strong { font-weight: 650; }
.content .missing-field { color: var(--muted); font-style: italic; }
#etrPreview { background: #fbfbfc; }

/* Floating "add comment" button */
.floating-action {
  position: fixed; z-index: 50; background: var(--accent); color: #fff; border: none;
  border-radius: 6px; padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.floating-action:hover { background: #245a93; }

/* Comments panel */
.comments-section {
  margin-top: 16px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.comments-section > header {
  padding: 12px 18px; background: #fafbfc; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 14px;
}
.comments-section > header .meta { color: var(--muted); font-weight: 400; font-size: 13px; }
.comments-section .body { padding: 12px 16px 16px; }
.comment-empty { color: var(--muted); font-size: 14px; padding: 12px 4px; }
.comment {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 14px;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.comment:first-child { border-top: none; }
.comment.resolved .quote, .comment.resolved .text { opacity: 0.55; }
.comment.resolved .text { text-decoration: line-through; }
.comment.focused { background: #fffbeb; margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 6px; }
.comment .quote {
  grid-column: 1 / -1; font-style: italic; color: var(--muted); font-size: 13px;
  border-left: 3px solid #fff3a8; padding-left: 10px; line-height: 1.5; cursor: pointer;
}
.comment .quote:hover { color: var(--text); }
.comment .text { white-space: pre-wrap; overflow-wrap: break-word; font-size: 14.5px; line-height: 1.55; }
.comment .author { font-size: 12px; color: var(--muted); }
.comment .meta-row { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
.comment .ts { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.comment .actions { grid-column: 2; display: flex; gap: 6px; align-items: flex-start; }
.comment .icon-btn {
  background: none; border: 1px solid transparent; border-radius: 4px; padding: 3px 7px;
  font-size: 12px; color: var(--muted); cursor: pointer;
}
.comment .icon-btn:hover { background: #f0f2f5; color: var(--text); border-color: var(--border); }

.composer { border: 1px solid var(--accent); border-radius: 6px; background: #f6faff; padding: 12px; margin: 10px 0; }
.composer .quote {
  font-style: italic; color: var(--muted); font-size: 13px; border-left: 3px solid #fff3a8;
  padding-left: 10px; margin-bottom: 8px; white-space: pre-wrap;
}
.composer textarea {
  width: 100%; min-height: 64px; font: inherit; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 4px; resize: vertical;
}
.composer .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

@media (max-width: 1300px) {
  /* Four columns break first: fold to three and give the source text its own row. */
  .split[data-cols="4"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .split[data-cols="4"] .pane.source { grid-column: 1 / -1; }
}
@media (max-width: 1100px) {
  .split[data-cols="3"], .split[data-cols="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split[data-cols="3"] .pane.source, .split[data-cols="4"] .pane.source { grid-column: 1 / -1; }
}
@media (max-width: 880px) {
  .split, .split[data-cols="3"], .split[data-cols="4"] { grid-template-columns: 1fr; }
  .split[data-cols="3"] .pane.source, .split[data-cols="4"] .pane.source { grid-column: auto; }
  header.topbar { padding: 12px 16px; }
  main { padding: 16px; }
}

/* ---------- Ocena: formularz 22 kryteriów ---------- */

.assess-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
/* Tekst zostaje w polu widzenia przez całą listę kryteriów — inaczej oceniająca
   przewija w górę przy każdym mierniku. */
.assess-text {
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.assess-text h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.assess-text h3 + .content { margin-bottom: 16px; }
.assess-text .source-fold { border-top: 1px solid var(--border); padding-top: 12px; }
.assess-text .source-fold summary {
  cursor: pointer; font-size: 13px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
}
.assess-text .source-fold .content { margin-top: 12px; }
.assess-criteria { display: flex; flex-direction: column; gap: 12px; }

.criterion {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
}
.criterion.overridden { border-left-color: var(--warning); }
.criterion.has-error { border-left-color: var(--danger); }
.criterion-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.criterion-head .lp {
  font-variant-numeric: tabular-nums; font-weight: 600; color: var(--muted);
  min-width: 22px; font-size: 13px;
}
.criterion-head .name { font-weight: 600; flex: 1; min-width: 200px; }
.criterion-head .target { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.badge.verification { font-size: 11px; text-transform: none; }
.badge.verification.auto { background: #eef2f7; color: var(--muted); }
.badge.verification.hybrid { background: var(--accent-soft); color: var(--accent); }
.badge.verification.llm { background: #fdf3e0; color: #8a6100; }

.criterion .auto {
  font-size: 13px; padding: 6px 10px; border-radius: 4px; margin-bottom: 8px;
  background: #f5f7fa; border: 1px solid var(--border);
}
.criterion .auto.ok { background: #f0faf1; border-color: #bfe3c4; }
.criterion .auto.bad { background: #fbf0f0; border-color: #e6c3c3; }
.criterion .auto.none { color: var(--muted); font-style: italic; }
.criterion .auto .sub { color: var(--muted); font-size: 12px; }

.criterion .examples, .criterion .guidance { margin-bottom: 10px; font-size: 13px; }
.criterion .examples summary, .criterion .guidance summary { cursor: pointer; color: var(--accent); }
.criterion .examples ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.criterion .examples li { margin-bottom: 4px; }
.criterion .guidance p { margin: 8px 0 0; color: var(--muted); }
.criterion .note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.criterion .field-error { color: var(--danger); font-size: 13px; margin: 6px 0 0; font-weight: 500; }

.criterion .answer { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.criterion .numeric { display: inline-flex; align-items: center; gap: 6px; }
.criterion .numeric input {
  width: 90px; font: inherit; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 4px; font-variant-numeric: tabular-nums;
}
.criterion .numeric .unit { color: var(--muted); font-size: 13px; }
.criterion .fraction { display: inline-flex; align-items: center; gap: 6px; }
.criterion .fraction input {
  width: 74px; font: inherit; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 4px; font-variant-numeric: tabular-nums;
}
/* Mianownik jest z pomiaru — edytowalny, ale wizualnie drugorzędny. */
.criterion .fraction input.total { width: 66px; color: var(--muted); background: #fafbfc; }
.criterion .fraction .of, .criterion .fraction .unit { color: var(--muted); font-size: 13px; }
.criterion .fraction .computed {
  margin-left: 4px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.criterion .points { display: inline-flex; gap: 4px; }
.criterion .point input { position: absolute; opacity: 0; width: 0; height: 0; }
.criterion .point span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 32px; border: 1px solid var(--border); border-radius: 4px;
  cursor: pointer; font-variant-numeric: tabular-nums;
}
.criterion .point input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.criterion .point input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.criterion .overridden-flag { font-size: 12px; color: var(--warning); font-weight: 500; }
.criterion textarea {
  width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 4px; resize: vertical;
}
.assess-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 4px 0 24px; }

.status-chip { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); }
.status-chip.submitted { background: #f0faf1; border-color: #bfe3c4; color: var(--success); }
.status-chip.draft { background: #fdf8e8; border-color: #f0dfa8; color: #8a6100; }

/* ---------- Ocena: listy i statystyki ---------- */

.progress-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.progress-strip .chip {
  font-size: 13px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel); color: var(--muted);
}
.progress-strip .chip.submitted { border-color: #bfe3c4; color: var(--success); }
.progress-strip .chip.draft { border-color: #f0dfa8; color: #8a6100; }
.card .dot.submitted { background: var(--success); }
.card .dot.draft { background: var(--warning); }
.card .dot.none { background: var(--border); }

.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
}
.stat-card.accent { border-color: var(--accent); }
.stat-card .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-card .label { font-size: 12px; color: var(--muted); line-height: 1.4; }

.table-scroll { overflow-x: auto; margin-bottom: 20px; }
table.stats { width: 100%; border-collapse: collapse; background: var(--panel); font-size: 14px; }
table.stats th, table.stats td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
table.stats th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
table.stats td.num, table.stats th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.stats td.sub { color: var(--muted); font-size: 13px; }
table.stats .bar {
  display: inline-block; width: 60px; height: 6px; background: var(--border);
  border-radius: 3px; overflow: hidden; vertical-align: middle; margin-right: 6px;
}
table.stats .bar span { display: block; height: 100%; background: var(--accent); }

table.stats.compare th.group {
  text-align: center; border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--muted); background: #fafbfc;
}
table.stats.compare td:nth-child(4) { border-left: 1px solid var(--border); }
table.stats.compare td:nth-child(8) { border-left: 1px solid var(--border); }
.delta { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }
.delta.flat { color: var(--muted); font-weight: 400; }
.caveats { margin: 4px 0 24px; display: flex; flex-direction: column; gap: 8px; }
.caveats .note { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; }
.caveats .note.warn {
  background: #fdf8e8; border: 1px solid #f0dfa8; border-radius: 4px;
  padding: 8px 10px; color: #7a5600;
}

@media (max-width: 1100px) {
  .assess-layout { grid-template-columns: 1fr; }
  .assess-text { position: static; max-height: 420px; }
}

.hidden { display: none !important; }
