:root {
  --bg: #f6f6f6; --surface: #ffffff; --surface-2: #f3f3f3; --border: #e2e2e2;
  --text: #000000; --muted: #5e5e5e; --primary: #000000; --primary-ink: #ffffff;
  --primary-soft: #eeeeee; --danger: #b42318; --danger-soft: #fee4e2;
  --warn: #b45309; --warn-soft: #fef3c7; --ok: #067647; --ok-soft: #dcfae6;
  --info: #276ef1; --info-soft: #e8effd; --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --surface: #121212; --surface-2: #1f1f1f; --border: #333333;
    --text: #ffffff; --muted: #afafaf; --primary: #ffffff; --primary-ink: #000000;
    --primary-soft: #2c2c2c; --danger: #f97066; --danger-soft: #3d1714;
    --warn: #fbbf24; --warn-soft: #3a2a07; --ok: #47cd89; --ok-soft: #0f3322;
    --info: #6d9bf8; --info-soft: #172646;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px;
  padding: 0 24px; height: 56px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--text); }
.main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); margin-bottom: 20px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat.link { cursor: pointer; } .stat.link:hover { border-color: var(--primary); }
.two-col { grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } .topbar { padding: 0 12px; gap: 8px; } .main { padding: 14px; } }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.wrap { white-space: normal; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; 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.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* Tabs */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 6px 12px; border-radius: 999px; cursor: pointer; font: inherit; }
.tab.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.tab .count { opacity: .75; margin-left: 4px; }

/* Forms & buttons */
input[type=text], input[type=password], input[type=search], textarea, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { width: 100%; min-height: 80px; resize: vertical; }
.btn { font: inherit; font-weight: 600; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--primary); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* Documents */
.docs { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.doc { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.doc .thumb { height: 150px; border-radius: 8px; background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  overflow: hidden; cursor: pointer; border: 1px solid var(--border); color: var(--muted); font-weight: 600; }
.doc .thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc .thumb.missing { cursor: default; font-weight: 400; }
.doc .reason { color: var(--danger); font-size: 12px; }
.doc.rejected { border-color: var(--danger); }
.doc.approved { border-color: var(--ok); }

/* Key/value */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; }
.kv .k { color: var(--muted); }

/* Modal */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; max-width: 520px; width: 100%; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.3); max-height: 90vh; overflow: auto; }
.modal.viewer { max-width: 1000px; }
.modal .viewer-body { display: flex; justify-content: center; }
.modal .viewer-body img { max-width: 100%; max-height: 75vh; border-radius: 8px; }
.modal .viewer-body iframe { width: 100%; height: 75vh; border: 0; border-radius: 8px; background: #fff; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Login */
.login { max-width: 400px; margin: 12vh auto; }
.login input { width: 100%; }

/* Toast */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; }
#toast .t { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); margin-top: 8px; }
#toast .t.error { background: var(--danger); color: #fff; }

.loading { padding: 40px; text-align: center; color: var(--muted); }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); }
.notice.danger { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
