/* ============================================================
   TransCheck v2 — macOS-style tokens
   ============================================================ */
:root {
  --bg: #f5f5f7;
  --sidebar-bg: rgba(246,246,248,.75);
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --border: rgba(0,0,0,.08);
  --accent: #0071e3;
  --accent-tint: color-mix(in srgb, var(--accent) 14%, transparent);
  --accent-tint-strong: color-mix(in srgb, var(--accent) 22%, transparent);
  --sev-critical: #ff3b30;
  --sev-high: #ff9500;
  --sev-medium: #ffcc00;
  --sev-warning: #ffcc00;
  --sev-low: #34c759;
  --sev-info: #8e8e93;
  --risk-high: #ff3b30;
  --risk-mid: #ff9500;
  --risk-low: #ffcc00;
  --risk-ok: #34c759;
}
[data-theme="dark"] {
  --bg: #1c1c1e;
  --sidebar-bg: rgba(28,28,30,.72);
  --surface: #2c2c2e;
  --surface-2: #252527;
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --border: rgba(255,255,255,.1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 13px; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(128,128,128,.35); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- Login gate ---- */
.login-overlay { position: fixed; inset: 0; display: flex; align-items: center;
  justify-content: center; background: var(--bg); z-index: 100; }
.login-card { background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px 36px; width: 320px; }
.login-card h1 { margin: 0 0 4px 0; font-size: 20px; }
.login-card p { margin: 0 0 20px 0; color: var(--text-secondary); font-size: 12px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; background: var(--surface-2); color: var(--text); }
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card .err { color: var(--sev-critical); font-size: 12px; margin-top: 8px; min-height: 16px; }

/* ---- App shell ---- */
.shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 220px; flex-shrink: 0; background: var(--sidebar-bg);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  padding: 12px 10px; }
.traffic { display: flex; gap: 8px; padding: 6px 6px 16px 6px; }
.traffic i { width: 12px; height: 12px; border-radius: 50%; display: block; }
.traffic i:nth-child(1) { background: #ff5f57; }
.traffic i:nth-child(2) { background: #febc2e; }
.traffic i:nth-child(3) { background: #28c840; }
.logo { display: flex; align-items: center; gap: 8px; padding: 2px 6px 16px 6px; }
.logo .mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; color: #fff;
  font-weight: 700; font-size: 13px; }
.logo .name { font-weight: 700; font-size: 14px; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border-radius: 7px; cursor: pointer; color: var(--text-secondary);
  font-size: 13px; font-weight: 500; }
.nav-item:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
.nav-item.active { background: var(--accent-tint); color: var(--accent); }
.nav-item .ico { width: 16px; height: 16px; flex-shrink: 0; position: relative; color: currentColor; }
.sidebar .spacer { flex: 1; }
.theme-toggle { display: flex; background: var(--surface-2); border-radius: 20px;
  padding: 2px; margin: 6px; border: 1px solid var(--border); }
.theme-toggle button { flex: 1; padding: 5px 10px; border: 0; background: transparent;
  border-radius: 18px; font-size: 11px; color: var(--text-secondary); cursor: pointer; }
.theme-toggle button.on { background: var(--surface); color: var(--text); }
.logout-btn { margin: 6px; padding: 6px 10px; border: 1px solid var(--border);
  background: transparent; color: var(--text-secondary); border-radius: 6px;
  font-size: 11px; cursor: pointer; }

/* ---- Icons (pure divs) ---- */
.ico.check-ico { }
.ico.check-ico::before { content: ""; position: absolute; top: 0; left: 0;
  width: 11px; height: 11px; border-radius: 50%; border: 2px solid currentColor; }
.ico.check-ico::after { content: ""; position: absolute; bottom: 0; right: 0;
  width: 2px; height: 6px; background: currentColor; transform: rotate(45deg); border-radius: 1px; }
.ico.folder-ico::before { content: ""; position: absolute; top: 0; left: 0;
  width: 7px; height: 2px; background: currentColor; border-radius: 2px 2px 0 0; }
.ico.folder-ico::after { content: ""; position: absolute; top: 2px; left: 0;
  width: 16px; height: 11px; background: currentColor; opacity: .9; border-radius: 2px; }
.ico.clock-ico { border-radius: 50%; border: 2px solid currentColor; }
.ico.clock-ico::before { content: ""; position: absolute; top: 1px; left: 50%;
  width: 2px; height: 5px; background: currentColor; transform: translateX(-50%); }
.ico.clock-ico::after { content: ""; position: absolute; top: 5px; left: 50%;
  width: 4px; height: 2px; background: currentColor; transform-origin: left center;
  transform: rotate(25deg); }
.ico.person-ico::before { content: ""; position: absolute; top: 0; left: 5px;
  width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ico.person-ico::after { content: ""; position: absolute; bottom: 0; left: 2px;
  width: 12px; height: 7px; border-radius: 6px 6px 2px 2px; background: currentColor; }
.ico.grid-ico::before { content: ""; position: absolute; inset: 0; background:
  linear-gradient(currentColor, currentColor) top left / 7px 7px no-repeat,
  linear-gradient(currentColor, currentColor) top right / 7px 7px no-repeat,
  linear-gradient(currentColor, currentColor) bottom left / 7px 7px no-repeat,
  linear-gradient(currentColor, currentColor) bottom right / 7px 7px no-repeat; }

/* ---- Toolbar + content ---- */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.toolbar { height: 56px; flex-shrink: 0; display: flex; align-items: center;
  justify-content: space-between; padding: 0 24px; border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg); backdrop-filter: blur(20px); }
.toolbar .title { font-size: 17px; font-weight: 700; }
.toolbar .actions { display: flex; align-items: center; gap: 10px; }
.search { width: 240px; padding: 6px 12px; border: 1px solid var(--border);
  border-radius: 20px; background: var(--surface-2); font-size: 12px;
  color: var(--text); outline: none; }
.search:focus { border-color: var(--accent); }
.density-btn { padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text-secondary); font-size: 12px; cursor: pointer; }
.density-btn.on { color: var(--accent); border-color: var(--accent); }

.content { flex: 1; overflow: auto; padding: 22px 26px; }

/* ---- Cards ---- */
.card { background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; }
.metric-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.metric-row.n3 { grid-template-columns: repeat(3, 1fr); }
.metric-card { background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; }
.metric-card .lbl { font-size: 11px; color: var(--text-secondary); }
.metric-card .val { font-size: 22px; font-weight: 700; margin-top: 4px; }
.metric-card .val.hist { font-size: 20px; }
.metric-card .val.dmg { color: var(--sev-critical); }
.metric-card .sub { font-size: 11px; color: var(--text-secondary); margin-top: 3px; }
.metric-card .sub.dmg { color: var(--sev-critical); }

/* ---- Section titles ---- */
.section-title { font-size: 13px; font-weight: 600; margin: 20px 0 10px 0;
  color: var(--text); display: flex; align-items: center; justify-content: space-between; }

/* ---- Buttons ---- */
.btn { padding: 8px 16px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 12.5px; font-weight: 600;
  cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:disabled { background: color-mix(in srgb, var(--text-secondary) 30%, transparent);
  border-color: transparent; color: color-mix(in srgb, var(--text-secondary) 80%, transparent);
  cursor: not-allowed; }
.btn.ghost { background: transparent; }

/* ---- Chips ---- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.chip { padding: 4px 12px; border-radius: 20px; border: 1px solid var(--border);
  font-size: 11px; font-weight: 600; cursor: pointer; color: var(--text-secondary);
  background: transparent; }
.chip.on { border-color: currentColor; background: color-mix(in srgb, currentColor 14%, transparent); }
.chip.sev-CRITICAL { color: var(--sev-critical); }
.chip.sev-HIGH { color: var(--sev-high); }
.chip.sev-MEDIUM, .chip.sev-WARNING { color: #d19b00; }
.chip.sev-LOW { color: var(--sev-low); }
.chip.sev-INFO { color: var(--sev-info); }

/* ---- Badges ---- */
.badge { padding: 3px 8px; border-radius: 5px; font-size: 11px; font-weight: 600;
  display: inline-block; }
.badge.CRITICAL { background: color-mix(in srgb, var(--sev-critical) 16%, transparent); color: var(--sev-critical); }
.badge.HIGH { background: color-mix(in srgb, var(--sev-high) 16%, transparent); color: var(--sev-high); }
.badge.MEDIUM, .badge.WARNING { background: color-mix(in srgb, var(--sev-medium) 25%, transparent); color: #a67a00; }
.badge.LOW { background: color-mix(in srgb, var(--sev-low) 16%, transparent); color: var(--sev-low); }
.badge.INFO { background: color-mix(in srgb, var(--sev-info) 16%, transparent); color: var(--sev-info); }
.badge.risk-high { background: color-mix(in srgb, var(--risk-high) 16%, transparent); color: var(--risk-high); }
.badge.risk-mid { background: color-mix(in srgb, var(--risk-mid) 16%, transparent); color: var(--risk-mid); }
.badge.risk-low { background: color-mix(in srgb, var(--risk-low) 25%, transparent); color: #a67a00; }
.badge.risk-ok { background: color-mix(in srgb, var(--risk-ok) 16%, transparent); color: var(--risk-ok); }

/* ---- Critical banner ---- */
.crit-banner { background: color-mix(in srgb, var(--sev-critical) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--sev-critical) 40%, transparent);
  color: var(--sev-critical); padding: 10px 14px; border-radius: 10px;
  font-size: 13px; font-weight: 600; margin-bottom: 16px; }

/* ---- Drop zones ---- */
.dropzones { display: flex; gap: 12px; margin-bottom: 16px; }
.dropzone { flex: 1; height: 130px; border: 1.5px dashed var(--border);
  border-radius: 12px; background: var(--surface); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; cursor: pointer; position: relative;
  transition: background .15s, border-color .15s; }
.dropzone:hover { background: var(--surface-2); }
.dropzone.drag { border-color: var(--accent); background: var(--accent-tint); }
.dropzone .dz-icon { width: 34px; height: 34px; border-radius: 8px;
  background: var(--accent-tint-strong); display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-size: 18px; font-weight: 700; }
.dropzone .dz-title { font-size: 13px; font-weight: 600; }
.dropzone .dz-sub { font-size: 11.5px; color: var(--text-secondary); }
.dropzone input[type=file] { display: none; }

/* ---- Tables ---- */
.tbl { background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; }
.tbl .hdr, .tbl .row { display: grid; padding: 11px 16px; gap: 10px; align-items: center;
  border-bottom: 1px solid var(--border); font-size: 12.5px; }
.tbl.dense .row, .tbl.dense .hdr { padding: 6px 16px; }
.tbl .row:last-child { border-bottom: none; }
.tbl .hdr { font-size: 11px; font-weight: 600; color: var(--text-secondary);
  background: var(--surface-2); }
.tbl .hdr .sortable { cursor: pointer; user-select: none; }
.tbl .hdr .sortable:hover { color: var(--text); }
.tbl .empty { padding: 40px; text-align: center; color: var(--text-secondary); font-size: 13px; }
.tbl .row .dmg { color: var(--sev-critical); font-weight: 600; }
.tbl .row .num { text-align: right; }
.tbl .hdr .num { text-align: right; }

/* ---- Segmented control ---- */
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 2px; gap: 2px; }
.segmented button { padding: 5px 12px; border: 0; background: transparent;
  border-radius: 6px; font-size: 12px; color: var(--text-secondary); cursor: pointer;
  font-weight: 500; }
.segmented button.on { background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.seg-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.seg-row label { font-size: 11px; color: var(--text-secondary); margin-right: 4px; }

/* ---- History chart ---- */
.chart-card { height: 240px; padding: 12px 16px 8px 8px; margin-bottom: 16px; display: flex;
  flex-direction: column; }
.chart-wrap { display: flex; height: 100%; gap: 6px; }
.chart-yaxis { width: 62px; flex-shrink: 0; display: flex; flex-direction: column;
  justify-content: space-between; font-size: 10px; color: var(--text-secondary);
  padding: 2px 4px 18px 0; text-align: right; }
.chart-yaxis span { line-height: 1; }
.chart-plot { flex: 1; position: relative; }
.chart-plot::before, .chart-plot::after,
.chart-plot .grid { content: ''; position: absolute; left: 0; right: 0; height: 1px;
  background: var(--border); }
.chart-plot .grid.g0 { top: 0; }
.chart-plot .grid.g1 { top: 25%; }
.chart-plot .grid.g2 { top: 50%; }
.chart-plot .grid.g3 { top: 75%; }
.chart-plot .grid.g4 { bottom: 18px; }
.chart-plot .xlabel { position: absolute; bottom: 0; font-size: 9px;
  color: var(--text-secondary); transform: translateX(-50%); }
.chart-card svg { width: 100%; height: 100%; display: block; }
.bar-chart { display: flex; align-items: flex-end; gap: 3px; height: 100%;
  position: absolute; inset: 0 0 18px 0; }
.bar-chart .bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0;
  min-height: 2px; position: relative; cursor: pointer;
  transition: background .1s; }
.bar-chart .bar:hover { background: color-mix(in srgb, var(--accent) 75%, black); }
.bar-chart .bar .tip { position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%); background: var(--text); color: var(--bg);
  font-size: 10px; padding: 3px 8px; border-radius: 4px; white-space: nowrap;
  display: none; margin-bottom: 4px; pointer-events: none; z-index: 10; }
.bar-chart .bar:hover .tip { display: block; }
.chart-empty { display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--text-secondary); font-size: 13px; }

/* ---- Modal ---- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 250; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; width: min(920px, 100%); max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 15px; font-weight: 700; }
.modal-close { background: transparent; border: 0; font-size: 18px; cursor: pointer;
  color: var(--text-secondary); padding: 4px 8px; }
.modal-body { padding: 14px 18px; overflow: auto; }
.run-row { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px;
  margin-bottom: 10px; background: var(--surface-2); }
.run-row-head { display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; }
.run-row-head .info { font-size: 12.5px; }
.run-row-head .info .meta { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.run-row-head .actions { display: flex; gap: 6px; align-items: center; }
.log-view { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px;
  max-height: 380px; overflow: auto; background: var(--bg); border-radius: 6px;
  padding: 8px 10px; }
.log-line { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 11px;
  color: var(--text-secondary); white-space: pre; padding: 1px 4px; border-radius: 2px; }
.log-line.dup { background: color-mix(in srgb, var(--sev-critical) 16%, transparent);
  color: var(--sev-critical); font-weight: 600; }
.log-line .n { display: inline-block; width: 44px; color: color-mix(in srgb, var(--text-secondary) 60%, transparent); text-align: right; padding-right: 8px; }

/* ---- Rank medals ---- */
.rank { font-weight: 700; }
.rank.gold { color: #d4a017; }
.rank.silver { color: #a0a0a0; }
.rank.bronze { color: #b87333; }

/* ---- Toast ---- */
#toast-root { position: fixed; top: 20px; right: 20px; display: flex;
  flex-direction: column; gap: 8px; z-index: 200; }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--surface);
  border: 1px solid var(--border); font-size: 12.5px; box-shadow: 0 2px 8px rgba(0,0,0,.08);
  max-width: 400px; }
.toast.err { border-color: var(--sev-critical); color: var(--sev-critical); }
.toast.ok { border-color: var(--sev-low); color: var(--sev-low); }

/* ---- Spinner overlay ---- */
.spinner-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.3);
  display: flex; align-items: center; justify-content: center; z-index: 150; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Watcher status pill ---- */
.watcher-pill { font-size: 11px; padding: 3px 10px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-secondary); }
.watcher-pill.on { color: var(--risk-ok); border-color: color-mix(in srgb, var(--risk-ok) 30%, transparent); }
.watcher-pill.off { color: var(--sev-critical); border-color: color-mix(in srgb, var(--sev-critical) 30%, transparent); }

.narrow-warn { position: fixed; inset: 0; display: none; align-items: center;
  justify-content: center; background: var(--bg); z-index: 300; padding: 20px;
  text-align: center; color: var(--text-secondary); font-size: 14px; }
@media (max-width: 899px) { .narrow-warn { display: flex; } }
