/* ── Docket design system ─────────────────────────────────────────────────────
   Archive-room aesthetic: cool paper, blue-black ink, deep archival blue brand.
   Three-font system: Space Grotesk (display), Inter (UI), IBM Plex Mono (codes,
   numbers, filenames — the "records room" texture). */

:root {
  --paper:      #F6F7F5;
  --surface:    #FFFFFF;
  --surface-2:  #FAFBF9;
  --ink:        #161D27;   /* blue-black */
  --ink-2:      #32404E;
  --muted:      #66717C;
  --line:       #E3E6E4;
  --line-2:     #EDEFEC;
  --brand:      #1F4FA0;   /* archival blue — brand only */
  --brand-ink:  #173D7E;
  --brand-bg:   #E8EEF9;

  --ok:      #12805C;  --ok-bg:      #E6F3EC;  --ok-line:      #BFE0CE;
  --warn:    #B4740A;  --warn-bg:    #FBF0DC;  --warn-line:    #EAD3A0;
  --risk:    #BE3A2F;  --risk-bg:    #FBE9E7;  --risk-line:    #F0C4BE;
  --pending: #5B6B7A;  --pending-bg: #EDF0F2;  --pending-line: #D3DAE0;
  --ocr:     #6D4FA3;  --ocr-bg:     #F0EBF8;  --ocr-line:     #D8CCEC;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(22,29,39,.04), 0 8px 24px -12px rgba(22,29,39,.10);
  --shadow-lg: 0 24px 60px -24px rgba(22,29,39,.28);

  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv05" 1, "ss01" 1;
}
h1,h2,h3,h4 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; margin: 0; color: var(--ink); }
p { margin: 0 0 10px; }
a { color: var(--brand); }
.num, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.money { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ── App shell ── */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink); color: #C6CFD8; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; padding: 22px 16px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px 20px; }
.brand .word { font-family: var(--font-display); font-weight: 700; font-size: 18px; color: #fff; line-height: 1.15; }
.brand .word small { display: block; font-family: var(--font-mono); font-weight: 400; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: #7C8B99; }
.nav { display: flex; flex-direction: column; flex: 1; gap: 2px; }
.nav-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: #64737F; padding: 16px 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: #C6CFD8; text-decoration: none; font-weight: 500; font-size: 14px; transition: background .12s, color .12s;
}
.nav-link svg { width: 17px; height: 17px; flex: none; }
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active { background: var(--brand); color: #fff; }
.nav .spacer { flex: 1; }
.side-foot { padding: 14px 10px 4px; font-size: 12px; color: #64737F; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot .co { color: #AEBBc6; font-weight: 600; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 62px; display: flex; align-items: stretch; border-bottom: 1px solid var(--line);
  background: rgba(246,247,245,.85); backdrop-filter: saturate(1.4) blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 18px; width: 100%; max-width: 1240px; margin-inline: auto; padding: 0 32px; }
.crumb { font-size: 14px; color: var(--muted); }
.crumb b { color: var(--ink); font-weight: 600; }
.usermenu { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
}
.content { padding: 30px 32px 64px; max-width: 1240px; width: 100%; margin-inline: auto; }

/* ── Page head ── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head .eyebrow { font-family: var(--font-mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--brand); margin-bottom: 8px; }
.page-head h1 { font-size: 27px; }
.page-head .sub { color: var(--muted); margin: 6px 0 0; max-width: 68ch; }

/* ── Cards / KPIs ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.card-head h3 { font-size: 16px; }
.card-pad { padding: 18px 20px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; text-decoration: none; color: var(--ink); display: block; }
.stat .k { font-size: 12.5px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.stat .k .dot { width: 8px; height: 8px; border-radius: 50%; }
.stat .v { font-family: var(--font-display); font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.stat .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
a.stat { transition: border-color .14s, box-shadow .14s; }
a.stat:hover { border-color: var(--brand); box-shadow: var(--shadow), 0 0 0 3px var(--brand-bg); }

/* ── Pills / tags / chips ── */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.pill.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.pill.risk { color: var(--risk); background: var(--risk-bg); border-color: var(--risk-line); }
.pill.pending { color: var(--pending); background: var(--pending-bg); border-color: var(--pending-line); }
.pill.ocr { color: var(--ocr); background: var(--ocr-bg); border-color: var(--ocr-line); }
.pill.brand { color: var(--brand); background: var(--brand-bg); border-color: #C6D5EF; }
.pill.neutral { color: var(--ink-2); background: var(--surface-2); border-color: var(--line); }
.pill.pending .dot, .pill.working .dot { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.tag { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 11px; padding: 3px 9px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 5px 12px; border-radius: 999px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--muted); transition: all .12s; text-decoration: none; }
.chip b { font-weight: 700; }
.chip:hover { border-color: var(--ink-2); color: var(--ink); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-ui); font-weight: 600;
  font-size: 14px; padding: 10px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; transition: all .14s ease; text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-ink); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { border-color: var(--ink-2); }
.btn-danger { background: var(--risk); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ── Tables ── */
table.ledger { width: 100%; border-collapse: collapse; font-size: 14px; }
table.ledger th {
  text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  font-weight: 600; padding: 11px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2);
  position: sticky; top: 0; z-index: 1;
}
table.ledger td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.ledger tbody tr:hover { background: var(--surface-2); }
table.ledger .r { text-align: right; }
tr.rowlink { cursor: pointer; }

/* ── Search ── */
.searchbar { position: relative; margin-bottom: 14px; }
.searchbar input {
  width: 100%; font-family: var(--font-ui); font-size: 16px; padding: 14px 190px 14px 46px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  color: var(--ink); box-shadow: var(--shadow); transition: border-color .14s, box-shadow .14s;
}
.searchbar input:focus { outline: none; border-color: var(--brand); box-shadow: var(--shadow), 0 0 0 3px var(--brand-bg); }
.searchbar .ico { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.searchbar .meta { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); pointer-events: none; }
.search-help { font-size: 12.5px; color: var(--muted); margin: -6px 0 14px 4px; }
.search-help code { font-family: var(--font-mono); font-size: 11.5px; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 5px; padding: 1px 5px; }

.result { display: block; padding: 14px 18px; border-bottom: 1px solid var(--line-2); text-decoration: none; color: var(--ink); transition: background .1s; }
.result:hover { background: var(--surface-2); }
.result .r-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.result .r-name { font-weight: 600; font-size: 14.5px; font-family: var(--font-mono); letter-spacing: -.01em; }
.result .r-meta { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.result .r-snip { color: var(--ink-2); font-size: 13.5px; margin-top: 6px; line-height: 1.55; }
.result .r-snip mark { background: #FFF1B8; color: inherit; border-radius: 3px; padding: 0 2px; font-weight: 600; }
.result .r-foot { display: flex; gap: 14px; margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ── Meter (segmented pipeline bar) ── */
.meter { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--line); box-shadow: inset 0 0 0 1px rgba(22,29,39,.04); }
.meter span { display: block; height: 100%; transition: width .5s cubic-bezier(.4,0,.1,1); }
.meter .s-ok { background: var(--ok); }
.meter .s-warn { background: var(--warn); }
.meter .s-risk { background: var(--risk); }
.meter .s-pending {
  background: var(--pending);
  background-image: linear-gradient(45deg, rgba(255,255,255,.18) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.18) 50%, rgba(255,255,255,.18) 75%, transparent 75%);
  background-size: 14px 14px; animation: stripe 1s linear infinite;
}
@keyframes stripe { to { background-position: 14px 0; } }
.legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: baseline; }

/* ── Dropzone / upload ── */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 220px; padding: 36px; border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; text-align: center; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-bg); }
.dropzone .ico { width: 40px; height: 40px; color: var(--brand); }
.dropzone h4 { font-size: 18px; }
.dropzone p { color: var(--muted); font-size: 13.5px; margin: 0; }
.filelist { display: flex; flex-direction: column; gap: 4px; margin-top: 14px; max-height: 320px; overflow-y: auto; }
.filelist .f { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface); font-size: 13px; }
.filelist .nm { font-family: var(--font-mono); font-size: 12.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filelist .sz { color: var(--muted); font-size: 12px; flex: none; }
.upload-progress { margin-top: 16px; }
.upload-progress .bar { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.upload-progress .bar > span { display: block; height: 100%; background: var(--brand); border-radius: 5px; transition: width .25s ease; }
.upload-progress .txt { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-top: 6px; font-family: var(--font-mono); }

/* ── Forms ── */
label.fld { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
input.txt, select.txt {
  width: 100%; font-family: var(--font-ui); font-size: 14px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}
input.txt:focus, select.txt:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-bg); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-err { color: var(--risk); font-size: 13px; margin-top: 6px; }

/* ── Empty state ── */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 54px 24px; text-align: center; color: var(--muted); }
.empty svg { width: 38px; height: 38px; color: var(--pending); }
.empty h4 { color: var(--ink); font-size: 16px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  z-index: 100; display: flex; align-items: center; gap: 10px; transition: opacity .4s ease;
  animation: toast-in .35s cubic-bezier(.2,.8,.2,1); max-width: min(640px, 90vw);
}
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
@keyframes toast-in { from { transform: translate(-50%, 12px); opacity: 0; } }

/* ── Modal (confirm) ── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(22,29,39,.44); display: flex; align-items: center; justify-content: center;
  z-index: 90; opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: min(430px, 92vw); padding: 22px; transform: translateY(8px); transition: transform .18s ease; }
.modal-backdrop.open .modal { transform: none; }
.modal h3 { font-size: 17px; margin-bottom: 6px; }
.modal p { color: var(--muted); font-size: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-ico { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.modal-ico.info { background: var(--brand-bg); color: var(--brand); }
.modal-ico.danger { background: var(--risk-bg); color: var(--risk); }

/* ── Auth (signed-out) ── */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: min(400px, 94vw); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 34px; }
.auth-card .brandrow { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-card .brandrow .word { font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.auth-card .brandrow small { display: block; font-family: var(--font-mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }

/* ── Document details ── */
.doc-grid { display: grid; grid-template-columns: 340px 1fr; gap: 18px; align-items: start; }
.meta-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 13.5px; }
.meta-list dt { color: var(--muted); }
.meta-list dd { margin: 0; font-weight: 500; }
.page-text { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 14px 16px; max-height: 460px; overflow-y: auto; }
.page-text mark { background: #FFF1B8; border-radius: 3px; padding: 0 2px; }
.timeline { display: flex; gap: 0; margin: 4px 0 0; }
.timeline .step { flex: 1; text-align: center; font-size: 12px; color: var(--muted); position: relative; padding-top: 16px; }
.timeline .step::before { content: ""; position: absolute; top: 4px; left: 50%; transform: translateX(-50%); width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.timeline .step.done::before { background: var(--ok); }
.timeline .step .ms { font-family: var(--font-mono); color: var(--ink-2); display: block; }

/* ── Utility ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.mb-8 { margin-bottom: 8px; } .mb-14 { margin-bottom: 14px; } .mb-20 { margin-bottom: 20px; } .mt-14 { margin-top: 14px; } .mt-20 { margin-top: 20px; }
.flex { display: flex; align-items: center; gap: 10px; }
.spin { width: 15px; height: 15px; border: 2px solid var(--pending-line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.kbd { font-family: var(--font-mono); font-size: 11px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; background: var(--surface); color: var(--muted); }
.pagenav { display: flex; align-items: center; gap: 10px; justify-content: center; padding: 14px; }

@media (max-width: 940px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .doc-grid, .grid-2, .form-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
