/* DocFlow — dashboard styles (no framework, no build step) */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #344054;
  --muted: #667085;
  --primary: #2e5bdb;
  --primary-600: #2349b8;
  --primary-50: #eef3ff;
  --sidebar: #0f1729;
  --sidebar-text: #c7d0e0;
  --sidebar-active: #1d2a45;
  --ok: #067647;   --ok-bg: #ecfdf3;
  --warn: #b54708; --warn-bg: #fffaeb;
  --bad: #b42318;  --bad-bg: #fef3f2;
  --info: #175cd3; --info-bg: #eff8ff;
  --neutral: #475467; --neutral-bg: #f2f4f7;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, "SFMono-Regular", monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; line-height: 1.25; color: var(--text); }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; display: inline-block; vertical-align: bottom; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------------ layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 20px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 17px; padding: 0 8px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #3b82f6, #6366f1); display: grid; place-items: center; font-size: 15px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: #8b97ad; letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--sidebar-text); padding: 9px 10px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #6d8dff; }
.nav svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .85; }
.sidebar-footer { margin-top: auto; font-size: 12px; color: #8b97ad; padding: 0 8px; display: flex; flex-direction: column; gap: 8px; }
.sidebar-footer form button { background: none; border: 1px solid #2c3a57; color: var(--sidebar-text); border-radius: 6px; padding: 6px 10px; cursor: pointer; width: 100%; }
.sidebar-footer form button:hover { background: var(--sidebar-active); }
.main { padding: 28px 32px 48px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: minmax(0, 2.3fr) minmax(260px, 1fr); }
.grid > *, .stack > * { min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ------------------------------------------------------------------ cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -.02em; }
.stat .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); }
.dot.info { background: var(--info); } .dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: #f79009; } .dot.proc { background: #7a5af8; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-link { color: var(--text); font-weight: 550; }
.empty { text-align: center; padding: 42px 16px; color: var(--muted); }
.empty svg { width: 36px; height: 36px; opacity: .5; display: block; margin: 0 auto 8px; }

/* ------------------------------------------------------------------ badges */
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; line-height: 18px; white-space: nowrap; border: 1px solid transparent; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.badge.QUEUED { color: var(--info); background: var(--info-bg); border-color: #d1e9ff; }
.badge.PROCESSING { color: #5925dc; background: #f4f3ff; border-color: #e0dcff; }
.badge.PROCESSING::before { animation: pulse 1.2s ease-in-out infinite; }
.badge.COMPLETED { color: var(--ok); background: var(--ok-bg); border-color: #d1fadf; }
.badge.FAILED { color: var(--bad); background: var(--bad-bg); border-color: #fee4e2; }
.badge.CANCELLED { color: var(--neutral); background: var(--neutral-bg); border-color: var(--border); }
.badge.warn { color: var(--warn); background: var(--warn-bg); border-color: #fedf89; }
.badge.ok { color: var(--ok); background: var(--ok-bg); border-color: #d1fadf; }
.badge.bad { color: var(--bad); background: var(--bad-bg); border-color: #fee4e2; }
.badge.neutral { color: var(--neutral); background: var(--neutral-bg); border-color: var(--border); }
.badge.info { color: var(--info); background: var(--info-bg); border-color: #d1e9ff; }
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* ------------------------------------------------------------------ progress */
progress { -webkit-appearance: none; appearance: none; width: 100%; height: 8px; border: none; border-radius: 999px; background: #eaecf0; overflow: hidden; vertical-align: middle; }
progress::-webkit-progress-bar { background: #eaecf0; border-radius: 999px; }
progress::-webkit-progress-value { background: linear-gradient(90deg, #4f7cff, #6366f1); border-radius: 999px; transition: width .4s ease; }
progress::-moz-progress-bar { background: linear-gradient(90deg, #4f7cff, #6366f1); border-radius: 999px; }
progress.done::-webkit-progress-value { background: #12b76a; } progress.done::-moz-progress-bar { background: #12b76a; }
progress.failed::-webkit-progress-value { background: #f04438; } progress.failed::-moz-progress-bar { background: #f04438; }
progress.mini { height: 6px; width: 90px; }
.progress-line { display: flex; align-items: center; gap: 10px; }
.progress-line .pct { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 40px; text-align: right; }
.big-progress { height: 12px; }
.stepper { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 14px; }
.step { font-size: 12px; color: var(--muted); padding-top: 8px; border-top: 3px solid #eaecf0; }
.step.done { color: var(--text-2); border-color: #12b76a; }
.step.current { color: var(--primary); font-weight: 600; border-color: var(--primary); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.metrics-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.metric { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.metric .label { color: var(--muted); font-size: 12px; }
.metric .value { font-weight: 600; margin-top: 2px; }

/* ------------------------------------------------------------------ forms */
label { font-weight: 550; font-size: 13px; color: var(--text-2); display: block; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=search], input[type=date], select, textarea {
  font: inherit; color: var(--text); background: #fff; border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 11px; width: 100%; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: #84adff; box-shadow: 0 0 0 4px rgba(46, 91, 219, .12); }
textarea { min-height: 96px; resize: vertical; }
.field { margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 5px; }
.btn { font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: #fff; color: var(--text-2); cursor: pointer; text-decoration: none; white-space: nowrap; box-shadow: 0 1px 2px rgba(16,24,40,.05); }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.success { background: #079455; border-color: #079455; color: #fff; }
.btn.success:hover { background: #067647; }
.btn.danger { color: var(--bad); border-color: #fda29b; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn svg { width: 16px; height: 16px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.filters { display: grid; grid-template-columns: 2fr repeat(4, 1fr) 150px 150px auto; gap: 10px; align-items: end; padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; }
.filters label { font-size: 12px; margin-bottom: 4px; }
.pagination { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-top: 1px solid var(--border); color: var(--muted); }
.pagination .pages { display: flex; gap: 6px; }

/* ------------------------------------------------------------------ alerts */
.alert { border-radius: 8px; padding: 12px 14px; border: 1px solid; display: flex; gap: 10px; align-items: flex-start; margin-bottom: 16px; }
.alert.error { background: var(--bad-bg); border-color: #fecdca; color: #912018; }
.alert.success { background: var(--ok-bg); border-color: #abefc6; color: #05603a; }
.alert.info { background: var(--info-bg); border-color: #b2ddff; color: #194185; }
.alert strong { display: block; }

/* ------------------------------------------------------------------ upload */
.dropzone { border: 2px dashed var(--border-strong); border-radius: 12px; background: var(--surface-2); padding: 38px 20px; text-align: center; cursor: pointer; transition: all .15s ease; }
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: var(--primary-50); }
.dropzone svg { width: 42px; height: 42px; color: var(--primary); }
.dropzone .title { font-weight: 600; font-size: 15px; margin-top: 8px; }
.dropzone input[type=file] { display: none; }
.file-chip { display: none; margin-top: 14px; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; text-align: left; align-items: center; gap: 10px; }
.file-chip.show { display: flex; }
.upload-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; }

/* ------------------------------------------------------------------ job detail */
.pages-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.page-card { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.page-card .page-meta { padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--border); }
.viewer { position: relative; background: #eef0f3; line-height: 0; }
.viewer img { width: 100%; height: auto; display: block; }
.viewer svg.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.overlay polygon { fill: rgba(46, 91, 219, .10); stroke: rgba(46, 91, 219, .55); stroke-width: 2; vector-effect: non-scaling-stroke; }
.overlay polygon.review { fill: rgba(247, 144, 9, .12); stroke: rgba(220, 104, 3, .8); }
.overlay polygon.active { fill: rgba(240, 68, 56, .16); stroke: #d92d20; stroke-width: 3; }
details.text summary { cursor: pointer; color: var(--primary); font-weight: 550; }
pre.page-text { white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; max-height: 360px; overflow: auto; margin: 10px 0 0; }
tr.field-row { cursor: pointer; }
tr.field-row.selected { background: var(--primary-50); }
.value-cell { max-width: 360px; overflow-wrap: anywhere; }
.value-table { font-size: 12px; margin: 0; }
.value-table th, .value-table td { padding: 4px 6px; vertical-align: top; }
.raw { color: var(--muted); font-size: 12px; }
.conf { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; font-weight: 600; }
.conf.good { color: var(--ok); } .conf.warn { color: var(--warn); } .conf.bad { color: var(--bad); } .conf.muted { color: var(--muted); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ review */
.review-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(340px, 1fr); gap: 18px; align-items: start; }
.review-layout .viewer { border-radius: 8px; overflow: hidden; border: 1px solid var(--border); max-height: 78vh; overflow-y: auto; }
.crop-box { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px; text-align: center; }
.crop-box img { max-width: 100%; max-height: 220px; image-rendering: auto; }
.value-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-family: var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.review-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.primary .kbd, .btn.success .kbd { color: rgba(255,255,255,.85); border-color: rgba(255,255,255,.55); }
.kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: var(--muted); }
.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { border-left: 2px solid var(--border); padding-left: 10px; }
.item-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.item-nav a { padding: 3px 8px; border-radius: 6px; border: 1px solid var(--border); font-size: 12px; color: var(--text-2); }
.item-nav a.current { border-color: var(--primary); color: var(--primary); background: var(--primary-50); }
.item-nav a.PENDING { border-style: dashed; }

/* ------------------------------------------------------------------ login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% -10%, #dfe7ff 0, transparent 60%), var(--bg); padding: 24px; }
.login-card { width: 100%; max-width: 400px; padding: 30px; }
.login-card .brand { color: var(--text); padding: 0; margin-bottom: 22px; }
.login-card .brand small { color: var(--muted); }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1360px) {
  .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1200px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(4, 1fr); }
  .filters .search { grid-column: 1 / -1; }
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 14px; gap: 12px; overflow-x: auto; }
  .nav { flex-direction: row; }
  .sidebar-footer { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .sidebar-footer .version { display: none; }
  .main { padding: 18px 16px 40px; }
  .grid-2, .grid-3, .upload-grid, .review-layout { grid-template-columns: 1fr; }
  .metrics-row { grid-template-columns: repeat(2, 1fr); }
  .kv { grid-template-columns: 120px 1fr; }
}
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: 1fr 1fr; }
  .nav a span { display: none; }
}
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
