/* DocArchive — design system. Auto light/dark (system), indigo accent.
   Class names are kept stable so templates need no structural changes. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #e9edf2;
  --border: #e2e6ec;
  --border-strong: #d2d8e0;
  --text: #1a1f24;
  --text-2: #3c4651;
  --muted: #6b7480;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-contrast: #ffffff;
  --accent-soft: #eef2ff;
  --accent-soft-2: #e0e7ff;
  --ok: #15803d;  --ok-soft: #dcfce7;
  --warn: #b45309; --warn-soft: #fef3c7;
  --err: #dc2626; --err-soft: #fee2e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
  --ring: 0 0 0 3px rgba(79, 70, 229, .25);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f2430;
    --surface-3: #272d3a;
    --border: #2a313c;
    --border-strong: #353d4a;
    --text: #e7ebf0;
    --text-2: #c3ccd6;
    --muted: #99a2ad;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-contrast: #ffffff;
    --accent-soft: #1b2140;
    --accent-soft-2: #252c52;
    --ok: #22c55e;  --ok-soft: rgba(34, 197, 94, .16);
    --warn: #f59e0b; --warn-soft: rgba(245, 158, 11, .16);
    --err: #f87171; --err-soft: rgba(248, 113, 113, .16);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --ring: 0 0 0 3px rgba(99, 102, 241, .4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.3; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 22px 0 8px; }
h3 { font-size: 14px; margin: 16px 0 6px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 10px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9em;
  background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.container { max-width: 1000px; margin: 0 auto; padding: 20px 18px 60px; }

/* ---- Icons ---- */
svg.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
a .icon, button .icon, label .icon, .btn .icon, .topnav a .icon { margin-right: 6px; }
.brand .icon { width: 22px; height: 22px; margin-right: 8px; color: var(--accent); }

/* ---- Top nav ---- */
.topnav {
  display: flex; gap: 4px; align-items: center; flex-wrap: wrap;
  background: var(--surface); padding: 10px 16px;
  position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.topnav .brand { display: inline-flex; align-items: center; margin-right: auto;
  font-weight: 700; font-size: 16px; letter-spacing: -0.02em; color: var(--text); }
.topnav .brand:hover { text-decoration: none; }
.topnav a {
  display: inline-flex; align-items: center; color: var(--muted);
  padding: 8px 12px; border-radius: var(--radius-sm); font-weight: 550; font-size: 14px;
}
.topnav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topnav a.active { background: var(--accent-soft); color: var(--accent); }
.topnav .who { font-size: 13px; color: var(--muted); padding: 0 6px 0 10px; }
.topnav form { display: inline-flex; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; font-size: 14px; font-weight: 600; font-family: inherit;
  background: var(--accent); color: var(--accent-contrast);
  cursor: pointer; transition: background .12s, border-color .12s, box-shadow .12s, transform .04s;
  text-decoration: none; line-height: 1.2;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.ghost { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.danger { background: var(--err); }
.btn.danger.ghost { background: var(--err-soft); color: var(--err); border-color: transparent; }

/* ---- Forms ---- */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 5px; font-weight: 550; }
input, select, textarea {
  width: 100%; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 10px 12px; font: inherit; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input[type=checkbox], input[type=radio] { width: auto; margin: 0 6px 0 0; transform: translateY(1px); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.muted { color: var(--muted); }

/* ---- Cards / sections ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm);
}
.section-title { font-size: 17px; font-weight: 650; margin: 24px 0 10px; }
.empty-state { text-align: center; color: var(--muted); padding: 36px 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---- Badges / pills ---- */
.badge {
  display: inline-flex; align-items: center; font-size: 12px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.pill { display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ---- Document grid ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.doc-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; text-decoration: none; color: var(--text);
  transition: box-shadow .14s, border-color .14s, transform .14s;
}
.doc-card:hover { box-shadow: var(--shadow); border-color: var(--border-strong); transform: translateY(-2px); text-decoration: none; }
.doc-card img { width: 100%; height: 150px; object-fit: cover; background: var(--surface-2); display: block; }
.doc-card .body { padding: 11px 13px; }
.doc-card .title { font-weight: 600; font-size: 14px; line-height: 1.3; }
.doc-card .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---- Detail / review ---- */
.page-thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.page-thumbs img { height: 120px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.bar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.spacer { flex: 1; }
.flash { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 14px;
  border: 1px solid transparent; }
.flash.info { background: var(--accent-soft); color: var(--text); border-color: var(--accent-soft-2); }
.flash.warn { background: var(--warn-soft); color: var(--text); border-color: transparent; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
dl.pairs { display: grid; grid-template-columns: max-content 1fr; gap: 7px 16px; margin: 10px 0; }
dl.pairs dt { color: var(--muted); font-size: 13px; }
dl.pairs dd { margin: 0; word-break: break-word; }

/* ---- Tables ---- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th, table.tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table.tbl tr:hover td { background: var(--surface-2); }
table.tbl .act { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Search ---- */
.searchbar { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.searchbar input[type=text] { flex: 1; min-width: 200px; font-size: 15px; padding: 12px 14px; }
.facets { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 16px; }
.facets a { font-size: 13px; padding: 5px 11px; border-radius: 999px; background: var(--surface);
  color: var(--muted); border: 1px solid var(--border); }
.facets a:hover { background: var(--surface-2); text-decoration: none; }
.facets a.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.facets a .n { opacity: .7; margin-left: 4px; }
.result {
  display: flex; gap: 13px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px; margin-bottom: 10px; text-decoration: none; color: var(--text);
  transition: box-shadow .14s, border-color .14s;
}
.result:hover { box-shadow: var(--shadow); border-color: var(--border-strong); text-decoration: none; }
.result img { width: 60px; height: 80px; object-fit: cover; border-radius: var(--radius-sm); flex: none; background: var(--surface-2); }
.result .rbody { min-width: 0; }
.result .rtitle { font-weight: 600; font-size: 15px; }
.result .rsnippet { font-size: 13px; color: var(--muted); margin-top: 4px; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.result .rmeta { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.result .rreason { font-size: 13px; color: var(--accent); margin-top: 5px; padding-left: 9px; border-left: 2px solid var(--accent-soft-2); }
.result .rreason::before { content: "AI · "; font-weight: 600; opacity: .85; }
mark { background: #fde68a; color: #1a1f24; border-radius: 3px; padding: 0 2px; }
@media (prefers-color-scheme: dark) { mark { background: #ca8a04; color: #1a1f24; } }
.help-link { font-size: 12px; color: var(--muted); }
.ai-toggle {
  display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 550;
  color: var(--text-2); background: var(--surface); padding: 9px 12px; border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap; border: 1px solid var(--border-strong);
}
.ai-toggle input { width: auto; margin: 0; }

/* ---- Scan (camera capture) ---- */
.stage {
  position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 3/4; max-height: 66vh; margin: 0 auto;
}
.stage video { width: 100%; height: 100%; object-fit: cover; display: block; }
.stage .no-cam { color: var(--muted); padding: 24px; text-align: center;
  display: flex; align-items: center; justify-content: center; height: 100%; }
.capture-row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.thumb { position: relative; }
.thumb img { height: 84px; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; }
.thumb .rm { position: absolute; top: -6px; right: -6px; background: var(--err); color: #fff; border: 2px solid var(--surface);
  width: 22px; height: 22px; border-radius: 50%; font-size: 13px; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.thumb .pdf-tile { height: 84px; width: 60px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--muted); text-align: center; font-weight: 600; }
.pagecount { color: var(--muted); font-size: 13px; margin-top: 9px; }

/* ---- Misc ---- */
.danger-zone h2, h2.danger { color: var(--err); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
