:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e2e1dc;
  --line-strong: #cfcdc6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #75746f;
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --accent-soft: #e6effb;
  --series-1: #2a78d6;
  --grid: #e8e7e2;
  --good: #0a7d0a;
  --good-soft: #e5f4e5;
  --warn: #8a5a00;
  --warn-soft: #fff4d9;
  --bad: #b42828;
  --bad-soft: #fbe9e9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 18, .06), 0 2px 8px rgba(20, 20, 18, .04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2e2e2b;
    --line-strong: #41413d;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #9a998f;
    --accent: #5598e7;
    --accent-ink: #0b0b0b;
    --accent-soft: #1b2a3f;
    --series-1: #3987e5;
    --grid: #2a2a27;
    --good: #5fcf5f;
    --good-soft: #17301a;
    --warn: #f2c14e;
    --warn-soft: #33290f;
    --bad: #ef7d7d;
    --bad-soft: #3a1b1b;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #2e2e2b; --line-strong: #41413d;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #9a998f; --accent: #5598e7; --accent-ink: #0b0b0b;
  --accent-soft: #1b2a3f; --series-1: #3987e5; --grid: #2a2a27; --good: #5fcf5f; --good-soft: #17301a;
  --warn: #f2c14e; --warn-soft: #33290f; --bad: #ef7d7d; --bad-soft: #3a1b1b; --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.lbl { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
label > .pill { align-self: flex-start; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
p { margin: 0 0 10px; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.hidden { display: none !important; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Top bar */
.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(--line); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; color: var(--text); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #1c5cab, #3987e5); position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 4px; right: 4px; bottom: 5px; height: 4px; border-radius: 1px; background: #fff; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 8px 12px; border-radius: 8px; color: var(--text-2); font-weight: 550; white-space: nowrap; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.intro { margin-bottom: 16px; max-width: 760px; }
.foot { max-width: 1280px; margin: 0 auto; padding: 8px 24px 32px; }
.banner { max-width: 1232px; margin: 16px auto 0; padding: 10px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--text); border: 1px solid var(--line); }

/* Controls */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); min-height: 38px; }
textarea { resize: vertical; font-family: var(--sans); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="range"] { padding: 0; min-height: 0; accent-color: var(--accent); border: 0; background: transparent; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 12.5px; color: var(--text-2); }
button { cursor: pointer; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); padding: 8px 14px; font-weight: 600; min-height: 38px; white-space: nowrap; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.07); }
button.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--accent); font-weight: 600; }
button[disabled] { opacity: .55; cursor: progress; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.searchbar { display: flex; gap: 8px; max-width: 760px; }
.searchbar input { font-size: 15px; min-height: 44px; }
.searchbar button { min-height: 44px; padding: 0 20px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.toolbar label { min-width: 130px; flex: 1 1 130px; }
.toolbar label:first-child { flex: 0 1 140px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-content: start; }
.span-2 { grid-column: span 2; }
.actions { display: flex; align-items: center; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.split { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; align-items: start; }
.landed-split { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.empty { color: var(--text-3); padding: 28px 8px; text-align: center; }

/* HS results */
.list-card { padding: 6px; max-height: calc(100vh - 230px); overflow: auto; }
.hs-item { display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.hs-item:hover { background: var(--surface-2); }
.hs-item.active { background: var(--accent-soft); border-color: var(--accent); }
.hs-item .code { font-family: var(--mono); font-weight: 650; font-size: 13px; }
.hs-item .desc { overflow: hidden; }
.hs-item .path { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hs-item .rate { font-size: 12.5px; color: var(--text-2); text-align: right; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-card { position: sticky; top: 72px; max-height: calc(100vh - 96px); overflow: auto; }
.crumbs { font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.detail-title { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 650; background: var(--surface); position: sticky; top: 0; }
tbody tr:hover td { background: var(--surface-2); }
.tree td.code { font-family: var(--mono); white-space: nowrap; font-size: 12.5px; }
.tree td:nth-child(2) { min-width: 240px; }
.tree tr.sub td { color: var(--text-2); }
.tree tr.sel td { background: var(--accent-soft); }
.tree tr.clickable { cursor: pointer; }
.table-wrap { overflow: auto; max-height: 520px; border: 1px solid var(--line); border-radius: 8px; }
.table-wrap table th:first-child, .table-wrap table td:first-child { padding-left: 12px; }

/* Rate cards */
.rates { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 10px 0; }
.rate-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--surface-2); }
.rate-box .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 650; }
.rate-box .v { font-size: 15px; font-weight: 650; margin-top: 2px; word-break: break-word; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 650; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); margin: 8px 0; font-size: 13px; }
.note.info { background: var(--accent-soft); }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--bad-soft); color: var(--bad); font-weight: 600; }
ul.warnings { margin: 8px 0 0; padding-left: 18px; color: var(--text-2); font-size: 13px; }
ul.warnings li { margin-bottom: 4px; }

/* KPIs & charts */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .k { font-size: 12px; color: var(--text-2); font-weight: 600; }
.kpi .v { font-size: 22px; font-weight: 700; letter-spacing: -.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--text-3); }
.charts { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.chart-card h2 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chart-box { position: relative; height: 300px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 10px; }

/* Screening */
.screen-result { margin-bottom: 12px; }
.screen-result .head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.screen-result .q { font-weight: 650; font-size: 15px; }
.match { border-top: 1px solid var(--line); padding: 10px 0 2px; display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; }
.score { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.match .meta { font-size: 12.5px; color: var(--text-2); }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 12.5px; margin-top: 4px; }

/* Landed */
.breakdown td.num { font-weight: 600; }
.breakdown tr.total td { font-weight: 750; font-size: 15px; border-top: 2px solid var(--line-strong); border-bottom: 0; }
.big { font-size: 30px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* Data page */
.status-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.status-row:last-of-type { border-bottom: 0; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.progress > div { height: 100%; width: 0; background: var(--series-1); border-radius: 99px; transition: width .3s; }

/* Sign-in screens */
body.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; }
.gate-brand { margin-bottom: 18px; }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .split, .landed-split, .grid-2, .charts { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-card { position: static; max-height: none; }
  .list-card { max-height: 420px; }
}
@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 0 16px; gap: 10px; height: auto; min-height: 56px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .topbar #logout { margin-left: auto; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: span 1; }
  .rates { grid-template-columns: minmax(0, 1fr); }
  .hs-item { grid-template-columns: 96px minmax(0, 1fr); }
  .hs-item .rate { display: none; }
  .searchbar { flex-direction: column; }
}
