@import url('https://fonts.googleapis.com/css2?family=Newsreader:opsz,wght@6..72,400;6..72,500;6..72,600&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --ink: #1A1B1D; --muted: #646A72; --faint: #9AA0A8; --rule: #E5E3DC;
  --accent: #2B4B7E; --accent-ink: #ffffff; --paper: #FBFBF9; --sidebar: #EEF0E4;
  --good: #2F7D5B; --warn: #B8860B;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace; --serif: 'Newsreader', Georgia, serif;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
::selection { background: rgba(43, 75, 126, .16); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── layout ─────────────────────────────────────────────────────────── */

.layout { display: flex; align-items: stretch; min-height: 100vh; }

.sidebar {
  width: 280px; flex: none; background: var(--sidebar);
  border-right: 1px solid var(--rule); padding: 2.25rem 1.75rem;
}
.main { flex: 1; min-width: 0; max-width: 860px; padding: 2.75rem 3rem 4rem; }

@media (max-width: 860px) {
  .layout { flex-direction: column; min-height: 0; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--rule); padding: 1.5rem 1.25rem; }
  .main { max-width: 100%; padding: 2rem 1.25rem 3rem; }
}

/* ── sidebar ────────────────────────────────────────────────────────── */

.sb-block { font-family: var(--mono); font-size: .75rem; color: var(--muted); line-height: 1.8; margin-bottom: 1.2rem; }
.sb-block b { color: var(--ink); font-size: .82rem; letter-spacing: -.01em; }
.sb-block a { color: var(--accent); text-decoration-color: rgba(43,75,126,.35); text-underline-offset: 2px; }
.sb-block a:hover { text-decoration-color: var(--accent); }

.hr { height: 1px; background: var(--rule); border: 0; margin: 1.2rem 0; }
.status-ok, .status-bad {
  font-family: var(--mono); font-size: .75rem; display: flex; align-items: center; gap: .45rem;
}
.status-ok { color: var(--good); }
.status-bad { color: var(--warn); }
.status-ok::before, .status-bad::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

label.field-label {
  display: block; font-family: var(--mono); font-size: .72rem; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted); margin: 1.1rem 0 .4rem;
}

/* ── form controls ─────────────────────────────────────────────────── */

select, input[type=text] {
  width: 100%; font-family: var(--sans); font-size: .88rem; color: var(--ink);
  background: #fff; border: 1px solid var(--rule); border-radius: 5px; padding: .5rem .65rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
select:hover, input[type=text]:hover { border-color: var(--faint); }
select:focus, input[type=text]:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(43,75,126,.12);
}
select:disabled { color: var(--faint); background: #F4F3EF; cursor: not-allowed; }

select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='7' viewBox='0 0 11 7' fill='none'%3E%3Cpath d='M1 1L5.5 5.5L10 1' stroke='%23646A72' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2rem;
  cursor: pointer;
}

/* custom checkbox */
.checkbox-row { display: flex; align-items: center; gap: .55rem; margin: .55rem 0; font-family: var(--mono); font-size: .78rem; color: var(--muted); }
.checkbox-row label { cursor: pointer; }
.checkbox-row input[type=checkbox] {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none; position: relative;
  width: 15px; height: 15px; border: 1px solid var(--faint); border-radius: 4px;
  background: #fff; cursor: pointer; transition: background .12s ease, border-color .12s ease;
}
.checkbox-row input[type=checkbox]:hover { border-color: var(--accent); }
.checkbox-row input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
.checkbox-row input[type=checkbox]:checked::after {
  content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.checkbox-row input[type=checkbox]:disabled { opacity: .45; cursor: not-allowed; border-color: var(--rule); }
.checkbox-row input[type=checkbox]:disabled:hover { border-color: var(--rule); }

/* custom radio */
.radio-row { display: flex; gap: 1.4rem; font-family: var(--mono); font-size: .8rem; color: var(--muted); margin: .5rem 0; }
.radio-row label { display: flex; align-items: center; gap: .45rem; cursor: pointer; }
.radio-row input[type=radio] {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none; position: relative;
  width: 15px; height: 15px; border: 1px solid var(--faint); border-radius: 50%;
  background: #fff; cursor: pointer; transition: border-color .12s ease;
}
.radio-row input[type=radio]:hover { border-color: var(--accent); }
.radio-row input[type=radio]:checked { border-color: var(--accent); }
.radio-row input[type=radio]:checked::after {
  content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--accent);
}

/* upload dropzone */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; padding: 0; margin: -1px; }
.dropzone {
  display: flex; align-items: center; gap: .85rem; border: 1px dashed var(--faint);
  border-radius: 6px; background: #fff; padding: .85rem 1rem; cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover { border-color: var(--accent); background: #fdfdfc; }
.dropzone.has-file { border-style: solid; border-color: var(--accent); }
.dropzone-icon { flex: none; color: var(--accent); display: flex; }
.dropzone-text { min-width: 0; }
.dropzone-title { display: block; font-family: var(--sans); font-weight: 500; font-size: .88rem; color: var(--ink); }
.dropzone-hint { display: block; font-family: var(--mono); font-size: .73rem; color: var(--faint); margin-top: .15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── typography ─────────────────────────────────────────────────────── */

.kicker { font-family: var(--mono); font-size: .74rem; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); margin: 0 0 .35rem; }
h1.title { font-family: var(--serif); font-weight: 500; font-size: 2.3rem; line-height: 1.1; letter-spacing: -.01em; margin: 0; color: var(--ink); }
.lede { color: var(--muted); font-size: 1rem; line-height: 1.55; margin: .7rem 0 0; max-width: 62ch; }

.seclabel { font-family: var(--mono); font-size: .72rem; letter-spacing: .2em; text-transform: uppercase; color: var(--faint); margin: 2rem 0 .8rem; }

.stg { display: flex; align-items: baseline; gap: .7rem; margin: .2rem 0 .15rem; }
.stg .no { font-family: var(--mono); font-size: .82rem; color: var(--accent); font-weight: 500; }
.stg .nm { font-family: var(--serif); font-size: 1.18rem; font-weight: 600; color: var(--ink); }
.stg .mt { font-family: var(--mono); font-size: .74rem; color: var(--faint); margin-left: auto; text-align: right; }
.ds { color: var(--muted); font-size: .9rem; margin: 0 0 .7rem; }

.stage-img { border: 1px solid var(--rule); border-radius: 6px; background: #fff; padding: 6px; max-width: 100%; display: block; margin-bottom: 1rem; }
.stage-img img { border-radius: 2px; max-width: 100%; display: block; }

.kv { display: flex; gap: 1rem; font-family: var(--mono); font-size: .86rem; padding: .5rem 0; border-bottom: 1px solid var(--rule); }
.kv .k { color: var(--muted); min-width: 120px; text-transform: uppercase; font-size: .74rem; letter-spacing: .05em; }
.kv .v { color: var(--ink); font-weight: 500; word-break: break-word; }
.ocr { font-family: var(--mono); font-size: .82rem; line-height: 1.6; color: var(--ink); background: #fff; border: 1px solid var(--rule); border-radius: 6px; padding: .9rem 1rem; max-height: 300px; overflow: auto; white-space: pre-wrap; }
.summary { font-family: var(--mono); font-size: .82rem; color: var(--muted); }
.summary b { color: var(--ink); font-weight: 600; }

.badge { display: inline-block; font-family: var(--mono); font-size: .7rem; letter-spacing: .04em; padding: .2rem .55rem; border-radius: 3px; border: 1px solid var(--rule); margin-bottom: .6rem; }
.badge.llm { color: var(--good); border-color: var(--good); }
.badge.fallback { color: var(--warn); border-color: var(--warn); }

.hit { font-family: var(--mono); font-size: .8rem; color: var(--muted); padding: .5rem 0; border-bottom: 1px solid var(--rule); }
.hit b { color: var(--ink); }

/* ── buttons ────────────────────────────────────────────────────────── */

button {
  font-family: var(--sans); font-weight: 500; font-size: .85rem; border-radius: 5px;
  border: 1px solid var(--rule); background: #fff; color: var(--ink); padding: .55rem 1.1rem;
  cursor: pointer; transition: border-color .15s ease, color .15s ease, background .15s ease, transform .1s ease;
}
button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); }
button.primary:hover:not(:disabled) { background: #23416d; color: var(--accent-ink); border-color: #23416d; }
@media (prefers-reduced-motion: reduce) { button { transition: none; } button:active:not(:disabled) { transform: none; } }

table.line-items { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .8rem; margin-top: .5rem; }
table.line-items th, table.line-items td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--rule); }
table.line-items th { color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: .7rem; }
table.line-items tr:hover td { background: #F8F7F3; }

.error-box { font-family: var(--mono); font-size: .85rem; color: var(--warn); border: 1px solid var(--warn); background: #FBF6EA; border-radius: 6px; padding: .75rem 1rem; margin: .8rem 0; overflow-wrap: break-word; }
.caption { font-family: var(--mono); font-size: .74rem; color: var(--faint); }
.preview-img { max-width: 320px; border: 1px solid var(--rule); border-radius: 6px; margin: .5rem 0; display: block; }
.spinner { font-family: var(--mono); font-size: .8rem; color: var(--muted); }

.foot { font-family: var(--mono); font-size: .72rem; color: var(--faint); margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
