:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #1d2733; --muted: #66727f; --line: #dfe4ea;
  --brand: #1f4e78; --brand-2: #2d6aa3; --ok: #1e7f4f; --ok-bg: #e5f4ec; --warn: #9a5b00; --warn-bg: #fff3dc;
  --bad: #b3261e; --bad-bg: #fde8e6; --focus: #2d6aa3; --radius: 8px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); height: 100vh; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 12px; }
button:hover { border-color: var(--brand-2); }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.primary:hover { background: var(--brand-2); }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
a { color: var(--brand-2); }

.topbar { display: flex; align-items: center; gap: 24px; padding: 0 18px; height: 52px; background: var(--brand); color: #fff; flex: none; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.brand em { font-style: normal; opacity: .75; font-weight: 400; }
.topbar nav { display: flex; gap: 4px; }
.topbar .nav { background: transparent; color: #dce6f0; border: none; padding: 8px 14px; border-radius: 6px; }
.topbar .nav.active, .topbar .nav:hover { background: rgba(255,255,255,.14); color: #fff; }
.topstatus { margin-left: auto; font-size: 12px; opacity: .85; }

main { flex: 1; overflow: auto; }
.page { max-width: 1250px; margin: 0 auto; padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card h3 { margin: 16px 0 8px; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.banner { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }

.drop { border: 2px dashed #b8c4d1; border-radius: var(--radius); padding: 26px; text-align: center; background: #fafcfe; cursor: pointer; }
.drop.over { border-color: var(--brand-2); background: #eef5fc; }
.drop strong { display: block; font-size: 15px; margin-bottom: 4px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--muted); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tabs .count { background: #e9eef4; border-radius: 10px; padding: 0 7px; margin-left: 4px; font-size: 12px; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 8px; border-bottom: 1px solid #eef1f4; vertical-align: middle; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #f5f9fd; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; }
.pill.queued, .pill.reading { background: #e9eef4; color: var(--muted); }
.pill.review { background: var(--warn-bg); color: var(--warn); }
.pill.approved { background: var(--ok-bg); color: var(--ok); }
.pill.exported { background: #e3ecf7; color: var(--brand); }
.pill.error { background: var(--bad-bg); color: var(--bad); }
.flagcount { color: var(--warn); font-weight: 600; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* review */
div.review { display: grid; grid-template-columns: minmax(380px, 44%) 1fr; height: 100%; }
.viewer { background: #2b3138; display: flex; flex-direction: column; min-height: 0; }
.viewer .tools { display: flex; gap: 6px; padding: 8px; background: #20252b; align-items: center; color: #cfd6de; flex-wrap: wrap; }
.viewer .tools button { background: #3a424b; color: #fff; border-color: #4a535d; padding: 4px 10px; }
.viewer .tools button.active { background: var(--brand-2); }
.viewer .canvas { flex: 1; overflow: auto; position: relative; cursor: grab; }
.viewer .canvas img { display: block; transform-origin: 0 0; user-select: none; }
.editor { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.editor .scroll { flex: 1; overflow: auto; padding: 14px 16px; }
.editor .actions { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel); align-items: center; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 12px; }
.fields label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.fields label.wide { grid-column: span 2; }
.fields input, .fields select { color: var(--ink); width: 100%; }
.read-as { font-size: 11px; color: var(--muted); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #e9eef4; border: none; }
.chip:hover { background: #d7e3ef; }
input.flagged, select.flagged { background: var(--warn-bg); border-color: #e7c27c; }
input.bad { background: var(--bad-bg); border-color: #e9a29c; }
input.good { background: var(--ok-bg); border-color: #a9d7bd; }

table.items { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.items th { font-size: 11px; color: var(--muted); text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); font-weight: 600; white-space: nowrap; }
table.items td { padding: 3px 4px; border-bottom: 1px solid #eef1f4; vertical-align: top; }
table.items input { width: 100%; padding: 4px 6px; }
table.items input.num { text-align: right; }
table.items tr.excluded td { opacity: .45; }
table.items tr.excluded td:first-child { opacity: 1; }
table.items .written { font-size: 11px; color: var(--muted); padding: 2px 6px 0; }
table.items .lineflags { font-size: 11px; color: var(--warn); padding: 2px 6px 4px; }
table.items .note { font-size: 11px; color: var(--muted); padding: 0 6px 4px; font-style: italic; }
.totals { display: flex; gap: 22px; padding: 10px 2px; font-size: 13px; flex-wrap: wrap; }
.totals b { font-variant-numeric: tabular-nums; }
.flaglist { margin: 0 0 12px; padding: 10px 14px 10px 30px; background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); }
.flaglist.ok { background: var(--ok-bg); color: var(--ok); list-style: none; padding-left: 14px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1d2733; color: #fff; padding: 10px 18px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: 80vw; z-index: 10; }
.toast.bad { background: var(--bad); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } div.review { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.mid { font-family: Consolas, monospace; font-size: 20px; letter-spacing: 2px; background: #eef3f8; padding: 10px 14px; border-radius: 6px; display: inline-block; user-select: all; }
textarea.key { width: 100%; height: 90px; font-family: Consolas, monospace; font-size: 12px; }

.login { max-width: 420px; margin: 40px auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.stack input { color: var(--ink); }
.linkbtn { background: rgba(255,255,255,.14); color: #fff; border: none; margin-left: 10px; padding: 4px 10px; }
.linkbtn:hover { background: rgba(255,255,255,.25); }
[hidden] { display: none !important; }
