:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7385;
  --line: #dde1e8;
  --accent: #2f6fe0;
  --right: #1a9e4d;
  --wrong: #d63a3a;
  --seg: #2666e6;
  --layout: #f2800d;
  --page-shadow: 0 1px 4px rgba(0, 0, 0, .18);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181e; --panel: #1e222a; --text: #e6e9ef; --muted: #959cab; --line: #333946;
    --accent: #6a9cff; --page-shadow: 0 1px 6px rgba(0, 0, 0, .6);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* hidden wins over any display rule */
html, body { height: 100%; margin: 0; }
body {
  display: grid; grid-template-columns: 250px 1fr 300px; background: var(--bg); color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
aside { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; }
#panel { border-right: 0; border-left: 1px solid var(--line); }
main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 15px; margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px; }
section { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
section:last-child { border-bottom: 0; }
input:not([type]), input[type="text"] {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
.field { display: block; margin-bottom: 8px; color: var(--muted); }
.field input, .field select { margin-top: 3px; }
select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
#filter { margin-bottom: 8px; }
#doc-list { list-style: none; margin: 0; padding: 0; }
#doc-list li {
  padding: 6px 8px; border-radius: 6px; cursor: pointer; margin-bottom: 2px; overflow-wrap: anywhere;
}
#doc-list li:hover { background: var(--bg); }
#doc-list li.batch {
  cursor: default; background: none; margin-top: 10px; padding: 2px 8px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
}
#doc-list li.active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
#doc-list .bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 4px; overflow: hidden; }
#doc-list .bar div { height: 100%; background: var(--accent); }
#doc-list .tags { font-size: 11px; color: var(--muted); }
#doc-list .tag-done { color: var(--right); font-weight: 600; }
#batch { margin-top: 12px; font-size: 11px; word-break: break-all; }
button.wide { width: 100%; margin-bottom: 8px; }

/* ---------- the account (left), the login page, the admin page ---------- */
.account { padding: 8px 10px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.account-name { font-weight: 700; font-size: 14px; overflow-wrap: anywhere; }
.account-links { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; }
.account-links a, a { color: var(--accent); text-decoration: none; }
.account-links a:hover, a:hover { text-decoration: underline; }
body.plain { display: block; min-height: 100vh; overflow-y: auto; }
body.plain main { display: block; height: auto; }
.auth-card {
  width: min(380px, calc(100vw - 32px)); margin: 12vh auto 0; padding: 28px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--panel); box-shadow: 0 10px 40px rgba(0, 0, 0, .08);
}
.auth-brand { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
.auth-card h1 { margin: 6px 0 4px; font-size: 22px; }
.auth-field { display: block; margin: 14px 0 0; font-weight: 600; }
.auth-field input {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
.auth-field input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
.auth-error { min-height: 1.4em; margin: 10px 0 4px; color: var(--wrong); font-size: 12px; }
.auth-submit { width: 100%; padding: 9px; font-weight: 600; }
.admin { width: min(900px, calc(100vw - 32px)); margin: 0 auto; padding: 28px 0 60px; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.admin-head h1 { margin: 6px 0 4px; font-size: 22px; }
.admin-card { padding: 18px 20px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.admin-add { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; }
.admin-add .auth-field { margin: 0; flex: 1 1 200px; }
.admin-add .check { padding-bottom: 8px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.admin-table th, .admin-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.admin-table td.name { font-weight: 600; width: 40%; }
.admin-table td.role.admin { color: var(--accent); font-weight: 600; }
.admin-table td.actions { text-align: right; white-space: nowrap; }
.admin-table td.actions button { margin-left: 6px; }
#add-result, #list-result { margin-top: 10px; overflow-wrap: anywhere; }
.admin.wide { width: min(1200px, calc(100vw - 32px)); }
.admin.wide .admin-table td, .admin.wide .admin-table th { white-space: normal; }
.admin.wide .admin-table td.name { width: auto; }
.admin-nav { margin-bottom: 2px; }
.admin-table th.grow, .admin-table td.grow { width: 34%; white-space: normal; }
.pbar { position: relative; height: 20px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; min-width: 180px; }
.pbar-fill { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--right) 28%, transparent); }
.pbar-text { position: relative; display: block; padding: 0 8px; line-height: 18px; font-size: 11px; font-weight: 600; }
.admin-table tr.prow { cursor: pointer; }
.admin-table tr.prow:hover { background: var(--bg); }
.admin-table tr.prow.open { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.pdetails { padding: 4px 0 10px 16px; }
.admin-table.inner { font-size: 12px; }
.admin-table.inner td, .admin-table.inner th { padding: 4px 6px; }
.ok { color: var(--right); }
.bad { color: var(--wrong); }
#doc-list li.not-ready { cursor: default; opacity: .75; }
#doc-list .tag-wait { color: var(--accent); font-weight: 600; }
#doc-list .tag-failed { color: var(--wrong); font-weight: 600; }
#doc-title .missing { color: var(--wrong); font-weight: 600; }
/* ---------- upload window ---------- */
#upload {
  width: min(720px, 94vw); max-height: 90vh; padding: 0; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
#upload[open] { display: flex; flex-direction: column; }
#upload::backdrop { background: rgba(15, 18, 25, .5); }
#upload code { font: 11px ui-monospace, monospace; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.up-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 16px 20px 12px; border-bottom: 1px solid var(--line); }
.up-head h3 { margin: 0 0 2px; font-size: 16px; }
.up-x { border: 0; background: none; font-size: 22px; line-height: 1; padding: 0 4px; color: var(--muted); }
.up-x:hover { color: var(--text); }
.up-main { padding: 16px 20px; overflow-y: auto; flex: 1; }
.up-batch { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.up-batch span { font-weight: 600; flex: none; }
.up-tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 2px; gap: 2px; margin-bottom: 12px; }
.up-tabs button { border: 0; border-radius: 6px; padding: 5px 14px; }

.up-zone {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
  border: 1.5px dashed var(--line); border-radius: 10px; transition: border-color .15s, background .15s;
}
.up-zone:hover, .up-zone.drag { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.up-zone input { display: none; }
.up-zone-icon {
  flex: none; width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center;
  font: 700 10px ui-monospace, monospace; background: var(--bg); color: var(--muted);
}
#up-zone-pdf .up-zone-icon { background: color-mix(in srgb, var(--wrong) 14%, transparent); color: var(--wrong); }
.up-zone-folder .up-zone-icon { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.up-zone-text { flex: 1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.up-zone-text .small { flex-basis: 100%; }
.up-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 10px; background: var(--bg); color: var(--muted); }
.up-tag.need { background: color-mix(in srgb, var(--wrong) 12%, transparent); color: var(--wrong); }
.up-count { flex: none; font-size: 12px; font-weight: 600; color: var(--right); }
.up-zone.off { opacity: .45; cursor: not-allowed; }
.up-zone.off:hover { border-color: var(--line); background: none; }
.up-hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.up-tree { margin-top: 4px; }
.up-tree pre {
  margin: 6px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--bg);
  font: 12px/1.6 ui-monospace, monospace; overflow-x: auto;
}

.up-list-head { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 0 6px; }
.up-list { border: 1px solid var(--line); border-radius: 10px; max-height: 32vh; overflow-y: auto; }
.up-empty { padding: 18px; text-align: center; color: var(--muted); font-size: 12px; }
.up-row { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: 12px; }
.up-row:last-child { border-bottom: 0; }
.up-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.up-files { display: flex; gap: 4px; flex: none; }
.up-file { font: 600 10px ui-monospace, monospace; padding: 2px 5px; border-radius: 4px; background: var(--bg); color: var(--muted); opacity: .45; }
.up-file.has { opacity: 1; color: var(--text); }
.up-gets-badge { flex: none; width: 150px; white-space: nowrap; text-align: center; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.up-gets-badge.both { background: color-mix(in srgb, var(--right) 15%, transparent); color: var(--right); }
.up-gets-badge.layout { background: color-mix(in srgb, var(--layout) 15%, transparent); color: var(--layout); }
.up-gets-badge.none { background: var(--bg); color: var(--muted); }
.up-del { border: 0; background: none; color: var(--muted); font-size: 16px; padding: 0 4px; line-height: 1; }
.up-del:hover { color: var(--wrong); }

.up-foot { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--bg); border-radius: 0 0 12px 12px; }
.up-foot-status { flex: 1; min-width: 0; }
#up-status.bad { color: var(--wrong); }
#up-status.good { color: var(--right); }
#up-progress { width: 100%; height: 6px; margin-top: 4px; accent-color: var(--accent); }

#toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
#toolbar .title { font-weight: 600; flex: 1 1 200px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group { display: inline-flex; align-items: center; gap: 4px; }
#zoom-label { min-width: 42px; text-align: center; }
button {
  font: inherit; padding: 5px 10px; border-radius: 6px; border: 1px solid var(--line); cursor: pointer;
  background: var(--panel); color: var(--text);
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.toggle.on { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.right { border-color: var(--right); color: var(--right); }
button.wrong { border-color: var(--wrong); color: var(--wrong); }
kbd {
  font: 10px ui-monospace, monospace; padding: 0 4px; border: 1px solid currentColor; border-radius: 3px;
  opacity: .6; margin-left: 2px;
}
.check { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

#pages { position: relative; flex: 1; overflow: auto; padding: 16px 40px 16px 16px; }
.page { position: relative; margin: 0 auto 16px; background: #fff; box-shadow: var(--page-shadow); }
.page img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.page svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.page .no { position: absolute; top: 4px; right: -2px; transform: translateX(100%); padding-left: 6px;
            color: var(--muted); font-size: 11px; }
body.adding .page svg { cursor: crosshair; touch-action: none; }
body.adding .page { user-select: none; }
body.hide-boxes .page svg .start { display: none; }

.start { cursor: pointer; }
.start rect.box { stroke-width: .8; fill-opacity: .10; }
.start.right rect.box { stroke-width: 1.6; fill-opacity: .25; }
.start.wrong rect.box { stroke: var(--wrong) !important; fill: var(--wrong) !important; fill-opacity: .08; stroke-dasharray: 3 2; }
.start.wrong .tag { opacity: .55; }
.start.selected rect.box { stroke-width: 2.4; filter: drop-shadow(0 0 2px rgba(0, 0, 0, .55)); }
.start text { font: 600 6px system-ui, sans-serif; pointer-events: none; }
.status-bg { stroke-width: .5; }
.drawing { fill: var(--accent); fill-opacity: .15; stroke: var(--accent); stroke-width: .8; stroke-dasharray: 2 1; }
.flash rect.box { animation: flash .6s 2; }
@keyframes flash { 50% { fill-opacity: .6; } }

/* Selected: stays at the top of the panel */
#selected {
  position: sticky; top: -12px; z-index: 2; background: var(--panel);
  margin: -12px -12px 14px; padding: 12px 12px 12px; box-shadow: 0 1px 0 var(--line);
  max-height: 55vh; overflow-y: auto;  /* never more than half the panel: the rest stays in view */
}
#selected h2 { margin-bottom: 2px; }
#selected .label { margin: 8px 0 3px; }
#selected .text {
  font-family: Georgia, serif; font-size: 12.5px; line-height: 1.35; padding: 4px 8px; background: var(--bg);
  border-radius: 6px; margin: 4px 0 2px; overflow-wrap: anywhere;
}
#selected .text.clamped { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#selected .systems { grid-template-columns: 1fr 1fr; }
#selected button.system { padding: 4px 6px; gap: 4px; }
#selected .depths { flex-wrap: nowrap; gap: 3px; margin-top: 4px; }
#selected .depths button { flex: 1; min-width: 0; padding: 3px 0; }
#selected #note { width: 100%; resize: vertical; font: inherit; font-size: 12px; padding: 4px 6px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); }
.note-open { display: block; margin-top: 8px; }

/* everyone's say on the selected box */
.opinions { margin-top: 6px; padding: 6px 8px; border-radius: 6px; background: var(--bg);
  border-left: 3px solid #0f9d9a; }
.opinions .label { margin: 0 0 4px; }
.op { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; padding: 2px 0; }
.op-who { font-weight: 600; }
.op-tag { font-size: 10px; padding: 0 5px; border-radius: 8px; background: var(--line); color: var(--muted); }
.op-tag.first { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.op-tag.you { background: color-mix(in srgb, #0f9d9a 18%, transparent); color: #0f9d9a; }
.op-mark.right { color: var(--right); font-weight: 700; }
.op-mark.wrong { color: var(--wrong); font-weight: 700; }
.op-depth { color: var(--muted); }
.op-note { flex-basis: 100%; color: var(--muted); font-style: italic; overflow-wrap: anywhere; }

/* Edit / Second reviewer */
.review-mode #first-reviewer { margin-left: 4px; white-space: nowrap; }
body.voting #rmode-vote.on { background: #0f9d9a; border-color: #0f9d9a; }
#doc-list .tags.who { color: var(--muted); }
.vote-tag { font: 700 5.5px system-ui, sans-serif; fill: var(--muted); }
.vote-tag.split { fill: var(--wrong); }
#selected-why { margin-top: 6px; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: 12px; }
.label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 10px 0 4px; }
.buttons.tight { margin-top: 0; }
button.on-right { background: var(--right); border-color: var(--right); color: #fff; }
button.on-wrong { background: var(--wrong); border-color: var(--wrong); color: #fff; }

/* Depth: blue = segmentation, orange = segment layout, green = your correct depth */
.systems { display: grid; gap: 4px; }
button.system { display: flex; align-items: center; gap: 6px; text-align: left; }
button.system .verdict { margin-left: auto; font-weight: 700; }
button.system .verdict.ok { color: var(--right); }
button.system .verdict.no { color: var(--wrong); }
.badge {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 4px; border-radius: 5px;
  color: #fff; font-weight: 700; font-variant-numeric: tabular-nums;
}
.badge.seg { background: var(--seg); }
.badge.layout { background: var(--layout); }
.badge.none { background: var(--line); color: var(--muted); }
.depths { display: flex; flex-wrap: wrap; gap: 4px; }
.depths button {
  min-width: 30px; padding: 4px 0; font-weight: 700; font-variant-numeric: tabular-nums; position: relative;
}
.depths button.chosen { background: var(--right); border-color: var(--right); color: #fff; }
.depths button .dots { position: absolute; left: 0; right: 0; bottom: 1px; display: flex; justify-content: center; gap: 2px; }
.depths button .dots i { width: 5px; height: 5px; border-radius: 50%; }
.depths button .dots i.seg { background: var(--seg); }
.depths button .dots i.layout { background: var(--layout); }
#depth-editor.off { opacity: .45; pointer-events: none; }

/* depth badges on the page (SVG) */
.dbadge rect { stroke-width: .6; }
.dbadge text { font: 700 6.5px system-ui, sans-serif; fill: #fff; }
.dbadge.no rect { stroke: var(--wrong); stroke-width: 1.4; opacity: .55; }

#counts { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
#counts .n { text-align: right; font-variant-numeric: tabular-nums; }
#scores, #depth-scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
#scores th, #scores td, #depth-scores th, #depth-scores td {
  padding: 3px 4px; text-align: right; border-bottom: 1px solid var(--line);
}
#scores th:first-child, #scores td:first-child, #depth-scores th:first-child, #depth-scores td:first-child { text-align: left; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; margin: 0; }
.keys dt { font-family: ui-monospace, monospace; }
.keys dd { margin: 0; color: var(--muted); }
#not-placed { padding-left: 16px; margin: 0; }
#not-placed li { margin-bottom: 4px; overflow-wrap: anywhere; }
#export-result a { color: var(--accent); }
#folder-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-right: 4px; }

/* the reviewer's note */
textarea {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; resize: vertical;
  background: var(--bg); color: var(--text); font: inherit; min-height: 38px;
}
textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.start .note-tag { fill: #d4900a; font: 700 5.5px system-ui, sans-serif; }