:root {
  --ink: #18212f;
  --muted: #667085;
  --line: #d9dee7;
  --line-strong: #aeb8c8;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --soft: #eef2f7;
  --accent: #2459d3;
  --accent-dark: #1946ae;
  --accent-soft: #eaf0ff;
  --ok: #16734a;
  --ok-soft: #e9f7f0;
  --warn: #a15b05;
  --warn-soft: #fff5df;
  --danger: #b42318;
  --danger-soft: #fff0ef;
  --map-link: #8c8c8c;
  --map-strong: #a63a2e;
  --radius: 10px;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
h1, h2, h3 { margin-top: 0; line-height: 1.2; }
h1 { font-size: 20px; margin-bottom: 0; }
h2 { font-size: 22px; margin-bottom: 7px; }
h3 { font-size: 16px; margin-bottom: 4px; }
p { margin-top: 0; }
.muted { color: var(--muted); }
.eyebrow { font-size: 11px; letter-spacing: .11em; color: var(--muted); font-weight: 750; }

.app-header { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 22px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); }
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-actions form { margin: 0; }
.identity { color: var(--muted); font-size: 13px; }
.app-main { max-width: 1540px; margin: 0 auto; padding: 24px 22px 48px; }
.intro-grid { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 28px; margin-bottom: 18px; }

button.primary, button.secondary, button.ghost, a.button-link { border-radius: 8px; padding: 8px 12px; border: 1px solid transparent; font-weight: 650; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button.primary { background: var(--accent); color: white; }
button.primary:hover:not(:disabled) { background: var(--accent-dark); }
button.secondary, a.button-link { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
button.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
button.small { padding: 5px 8px; font-size: 12px; }

.progress-panel { width: min(360px, 38vw); }
.progress-line { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.progress-line strong { color: var(--ink); }
.progress-track { height: 8px; overflow: hidden; border-radius: 999px; background: var(--soft); }
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s ease; }

.tabs { display: flex; gap: 8px; margin: 0 0 12px; flex-wrap: wrap; }
.tab { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 7px 12px; }
.tab.active { background: var(--ink); color: white; border-color: var(--ink); }
.tab .done { color: #c7f1dc; margin-left: 6px; }

.notice, .flash { border-radius: var(--radius); border: 1px solid var(--line); padding: 10px 12px; }
.notice.info { background: var(--accent-soft); border-color: #cbd9ff; }
.notice.warn { background: var(--warn-soft); border-color: #eed29f; }
.flash { display: none; position: sticky; top: 76px; z-index: 20; margin-bottom: 12px; background: var(--surface); }
.flash.show { display: block; }
.flash.error { background: var(--danger-soft); border-color: #ffc7c3; color: var(--danger); }
.flash.success { background: var(--ok-soft); border-color: #bde5cf; color: var(--ok); }

.toolbar { display: flex; justify-content: space-between; align-items: end; gap: 18px; margin: 18px 0; }
.search-label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 650; }
.search-label input { width: min(420px, 55vw); padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink); }

.view-switch { display: inline-flex; gap: 4px; margin: 0 0 16px; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft); }
.view-switch-button { min-width: 132px; padding: 7px 12px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--muted); font-weight: 680; }
.view-switch-button:hover { color: var(--ink); background: rgba(255,255,255,.65); }
.view-switch-button.active, .view-switch-button[aria-pressed="true"] { color: var(--ink); background: var(--surface); border-color: var(--line); box-shadow: 0 1px 2px rgba(24,33,47,.08); }
.view-switch-button:focus-visible { outline: 3px solid rgba(36,89,211,.25); outline-offset: 2px; }
.view-panel[hidden] { display: none; }

.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 320px); gap: 14px; align-items: start; }
.map-main-panel, .map-inspector { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.map-main-panel { overflow: hidden; }
.map-toolbar { display: flex; align-items: start; justify-content: space-between; gap: 20px; padding: 12px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.map-toolbar-heading { max-width: 620px; }
.map-toolbar-heading h3 { margin: 0 0 3px; }
.map-toolbar-heading p { margin: 0; color: var(--muted); font-size: 11.5px; }
.map-legend { display: flex; align-items: center; justify-content: flex-end; gap: 8px 14px; flex-wrap: wrap; color: var(--muted); font-size: 10.5px; }
.map-legend-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-line { display: inline-block; width: 27px; border-radius: 999px; background: var(--map-link); }
.legend-line-thin { height: 1px; }
.legend-line-medium { height: 3px; }
.legend-line-strong { height: 5px; background: var(--map-strong); }
.legend-node { display: inline-block; width: 18px; height: 12px; border-radius: 3px; background: white; }
.legend-node-pending { border: 2px dashed var(--accent); }
.legend-node-reviewed { border: 2px solid var(--ok); box-shadow: inset 0 -3px 0 var(--ok-soft); }
.map-svg-wrapper { width: 100%; overflow: auto; overscroll-behavior: contain; background: #fff; scrollbar-gutter: stable; }
.map-svg-wrapper:focus-visible { outline: 3px solid rgba(36,89,211,.2); outline-offset: -3px; }
#paper-map { display: block; width: 100%; min-width: 920px; height: auto; aspect-ratio: 1400 / 860; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

/* The map remains deliberately close to the restrained, paper-style figure. */
#paper-map .map-layer-band, #paper-map .layer-band { fill: #f7f8fa; }
#paper-map .map-layer-band:nth-of-type(even), #paper-map .layer-band:nth-of-type(even) { fill: #fbfbfc; }
#paper-map .map-layer-rule, #paper-map .layer-rule { stroke: #e5e7eb; stroke-width: 1; }
#paper-map .map-layer-label, #paper-map .layer-label { fill: #555f70; font-size: 17px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
#paper-map .map-link, #paper-map .map-edge { fill: none; stroke: var(--map-link); stroke-linecap: round; opacity: .58; transition: opacity .14s ease, stroke .14s ease; }
#paper-map .map-link.strong, #paper-map .map-edge.strong, #paper-map .strong-link { stroke: var(--map-strong); opacity: .82; }
#paper-map .map-link-hit, #paper-map .map-edge-hit { fill: none; stroke: transparent; stroke-width: 15px; pointer-events: stroke; cursor: pointer; }
#paper-map .map-review-overlay { fill: none; stroke: var(--ok); stroke-width: 2px; stroke-dasharray: 4 7; stroke-linecap: round; opacity: .82; pointer-events: none; }
#paper-map .map-node { cursor: pointer; outline: none; }
#paper-map .map-node.static { cursor: default; }
#paper-map .map-node rect, #paper-map .node-box { fill: #fff; stroke: #858b94; stroke-width: 1.2px; rx: 5px; ry: 5px; transition: fill .14s ease, stroke .14s ease, stroke-width .14s ease, opacity .14s ease; }
#paper-map .map-node text, #paper-map .map-node-label { fill: #20252d; font-size: 13px; font-weight: 560; pointer-events: none; }
#paper-map .map-node.pending rect, #paper-map .map-node.pending-review rect, #paper-map .map-node.is-pending rect { stroke: var(--accent); stroke-width: 1.8px; stroke-dasharray: 5 3; }
#paper-map .map-node.reviewed rect, #paper-map .map-node.is-reviewed rect { stroke: var(--ok); stroke-width: 2px; }
#paper-map .map-review-marker, #paper-map .reviewed-marker { fill: var(--ok); stroke: #fff; stroke-width: 1.5px; }
#paper-map .map-node:hover rect, #paper-map .map-node:focus-visible rect { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2.4px; }
#paper-map .map-link:hover, #paper-map .map-edge:hover, #paper-map .map-link:focus, #paper-map .map-edge:focus { opacity: 1; }
#paper-map .map-edge-group:hover .map-edge, #paper-map .map-edge-group:focus-within .map-edge { stroke: var(--accent); opacity: 1; }
#paper-map .map-node.selected rect, #paper-map .map-node.is-selected rect { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 3px; stroke-dasharray: none; }
#paper-map .map-link.selected, #paper-map .map-edge.selected, #paper-map .map-link.is-selected, #paper-map .map-edge.is-selected { stroke: var(--accent); opacity: 1; }
#paper-map .filter-muted, #paper-map .is-muted, #paper-map [data-filter-muted="true"] { opacity: .1; pointer-events: none; }
#paper-map .map-edge-label { fill: #626b78; font-size: 10px; paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round; }
#paper-map .map-cluster-marker { pointer-events: none; }
#paper-map .map-cluster-marker circle { stroke: #fff; stroke-width: 2px; }
#paper-map .map-cluster-marker text { fill: #fff; font-size: 10px; font-weight: 800; }

.map-inspector { position: sticky; top: 76px; min-height: 220px; padding: 15px; }
.map-inspector h3 { margin-bottom: 5px; overflow-wrap: anywhere; }
.map-inspector p { color: var(--muted); font-size: 12px; }
.map-inspector .level-badge { display: inline-block; margin-bottom: 8px; }
.map-inspector dl, .map-detail-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 5px 10px; margin: 12px 0; font-size: 12px; }
.map-inspector dt, .map-detail-list dt { color: var(--muted); }
.map-inspector dd, .map-detail-list dd { margin: 0; overflow-wrap: anywhere; }
.map-inspector label { display: grid; gap: 5px; margin-top: 12px; color: var(--muted); font-size: 11.5px; font-weight: 650; }
.map-inspector select { width: 100%; border: 1px solid var(--line-strong); border-radius: 7px; padding: 7px 8px; background: #fff; color: var(--ink); }
.map-inspector button { width: 100%; margin-top: 9px; }
.map-inspector .reviewed-badge { display: inline-flex; }
.pending-badge { display: inline-flex; color: var(--accent-dark); background: var(--accent-soft); border-radius: 999px; padding: 3px 8px; font-size: 10.5px; font-weight: 700; }
.map-connections { margin: 10px 0; color: var(--muted); font-size: 11px; }
.map-connections summary { cursor: pointer; }
.notice.compact { margin-top: 10px; padding: 7px 8px; font-size: 11px; }
.map-inspector-empty { color: var(--muted); font-size: 13px; }
.zone-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 8px; }
.zone-heading h3 { margin: 0; display: inline; }
.zone-heading p { margin: 0; font-size: 12px; color: var(--muted); }
.count { font-size: 12px; color: var(--muted); margin-left: 8px; }
.pool-section { margin: 18px 0 24px; }
.drop-zone { min-height: 84px; border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 9px; background: var(--surface); transition: background .12s, border-color .12s; }
.drop-zone.drag-over { background: var(--accent-soft); border-color: var(--accent); }
.pool { min-height: 84px; display: grid; grid-template-columns: repeat(auto-fill, minmax(235px, 1fr)); gap: 8px; padding: 9px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.cluster-board { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 12px; align-items: start; }
.cluster-column { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.cluster-header { padding: 10px 11px; border-bottom: 1px solid var(--line); background: var(--soft); min-height: 94px; }
.cluster-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.cluster-title strong { font-size: 14px; }
.cluster-description { margin: 5px 0 0; font-size: 11.5px; line-height: 1.4; color: var(--muted); }
.cluster-column .drop-zone { border: 0; border-radius: 0; min-height: 110px; }

.item-card { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 9px; margin-bottom: 7px; }
.pool .item-card { margin-bottom: 0; }
.item-card[draggable="true"] { cursor: grab; }
.item-card.dragging { opacity: .45; }
.item-top { display: flex; align-items: start; justify-content: space-between; gap: 8px; }
.item-label { font-weight: 680; font-size: 13px; overflow-wrap: anywhere; }
.level-badge { min-width: 22px; border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; text-align: center; color: var(--muted); font-size: 10px; font-weight: 750; }
.item-meta { color: var(--muted); font-size: 11px; margin: 5px 0 7px; }
.item-card select { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; background: white; color: var(--ink); font-size: 11.5px; }
.item-card.pending-review { border-color: #b7c8f7; box-shadow: inset 3px 0 0 var(--accent); }
.card-review-actions { display: flex; justify-content: flex-end; align-items: center; min-height: 27px; margin-top: 7px; }
.confirm-assignment { width: 100%; }
.reviewed-badge { color: var(--ok); background: var(--ok-soft); border-radius: 999px; padding: 3px 8px; font-size: 10.5px; font-weight: 700; }
.saving-badge { color: var(--muted); background: var(--soft); border-radius: 999px; padding: 3px 8px; font-size: 10.5px; font-weight: 700; }
.item-card details { margin-top: 7px; font-size: 11px; color: var(--muted); }
.item-card summary { cursor: pointer; }
.edge-list { margin: 6px 0 0; padding-left: 16px; }
.edge-list li { margin: 3px 0; }
.empty-zone { color: var(--muted); font-size: 12px; padding: 12px; text-align: center; }
.hidden-by-filter { display: none; }

.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.status-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 15px; }
.status-card h3 { display: flex; justify-content: space-between; gap: 12px; }
.status-row { margin: 12px 0; }
.status-row-header { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 5px; }
.mini-track { height: 7px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.mini-track span { display: block; height: 100%; background: var(--accent); }
.status-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 12px; }

.results-section { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(135px, 1fr)); gap: 10px; margin: 14px 0 22px; }
.metric { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 13px; }
.metric strong { display: block; font-size: 24px; line-height: 1.1; }
.metric span { color: var(--muted); font-size: 11px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 8px 9px; border-bottom: 1px solid var(--line); }
th { background: var(--soft); font-weight: 700; }
td.number, th.number { text-align: right; font-variant-numeric: tabular-nums; }
.results-grid { display: grid; grid-template-columns: minmax(360px, .8fr) minmax(500px, 1.2fr); gap: 18px; align-items: start; }
.conflicts { display: grid; gap: 10px; }
.conflict-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 12px; }
.conflict-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.choice { background: var(--soft); border-radius: 7px; padding: 7px 8px; font-size: 12px; }
.choice strong { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.adjudication-form { display: grid; gap: 7px; }
.adjudication-form select, .adjudication-form textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: 7px; padding: 7px 8px; background: white; }
.adjudication-form textarea { min-height: 62px; resize: vertical; }
.resolved-note { color: var(--ok); background: var(--ok-soft); padding: 7px 8px; border-radius: 7px; font-size: 12px; margin-bottom: 7px; }

dialog { width: min(500px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 12px; padding: 0; color: var(--ink); }
dialog::backdrop { background: rgba(10, 18, 30, .42); }
dialog form { padding: 22px; }
.confirm-check { display: flex; align-items: start; gap: 8px; background: var(--soft); border-radius: 8px; padding: 10px; }
.confirm-check input { margin-top: 4px; }
.dialog-actions { display: flex; justify-content: end; gap: 8px; margin-top: 18px; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(390px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 26px; }
.login-card h1 { font-size: 24px; margin: 5px 0 8px; }
.login-card p { color: var(--muted); }
.login-card form { display: grid; gap: 12px; margin-top: 18px; }
.login-card label { display: grid; gap: 5px; font-size: 12px; font-weight: 650; color: var(--muted); }
.login-card input { width: 100%; border: 1px solid var(--line-strong); border-radius: 8px; padding: 10px; color: var(--ink); }
.login-error { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 9px; }
.local-hint { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; color: var(--muted); font-size: 12px; }

@media (max-width: 1100px) {
  .cluster-board { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
  .results-grid { grid-template-columns: 1fr; }
  .map-layout { grid-template-columns: 1fr; }
  .map-inspector { position: static; min-height: 130px; }
}
@media (max-width: 680px) {
  .app-header, .app-main { padding-left: 14px; padding-right: 14px; }
  .intro-grid, .toolbar { display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
  .progress-panel, .search-label input { width: 100%; }
  .cluster-board, .metrics-grid { grid-template-columns: 1fr; }
  .zone-heading { align-items: start; flex-direction: column; gap: 4px; }
  .view-switch { display: flex; width: 100%; }
  .view-switch-button { flex: 1; min-width: 0; }
  .map-toolbar { flex-direction: column; }
  .map-legend { justify-content: flex-start; }
  #paper-map { min-width: 820px; }
}
