:root {
  --bg: #0f1419;
  --surface: #161c23;
  --surface-2: #1d252e;
  --line: #2a343f;
  --text: #e6edf3;
  --muted: #8b98a5;
  --dim: #5c6773;
  --accent: #2f9e6e;
  --accent-dim: #1d6b49;
  --known: #2f9e6e;
  --est: #b8862f;
  --warn: #c96442;
  --danger: #b4453a;
  --info: #3d7fb8;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 7px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), var(--accent-dim));
  color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -0.5px;
}
.brand-text { line-height: 1.2; }
.brand-text b { display: block; font-size: 14px; letter-spacing: 0.2px; }
.brand-text span { font-size: 11px; color: var(--muted); letter-spacing: 0.6px; }

.nav-label {
  font-size: 10px; letter-spacing: 1.2px; color: var(--dim);
  text-transform: uppercase; padding: 14px 8px 6px; margin: 0;
}
.nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  background: none; border: 0; color: var(--muted); font: inherit; font-size: 14px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .5; }

.sidebar-foot { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--line); font-size: 11px; color: var(--dim); }

/* ------------------------------------------------------------------ main */
.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; border-bottom: 1px solid var(--line);
  font-size: 13px; color: var(--muted); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.wrap { padding: 26px 28px 60px; max-width: 1240px; }

h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -0.4px; }
h2 { font-size: 17px; margin: 0 0 3px; letter-spacing: -0.2px; }
h3 { font-size: 13px; margin: 0 0 10px; color: var(--muted); font-weight: 600;
     text-transform: uppercase; letter-spacing: 0.8px; }
.eyebrow { font-size: 10.5px; letter-spacing: 1.3px; color: var(--dim); text-transform: uppercase; margin: 0 0 6px; }
.sub { color: var(--muted); font-size: 13.5px; margin: 0; }
.head { margin-bottom: 22px; }

/* --------------------------------------------------------------- banners */
.banner {
  display: flex; gap: 12px; padding: 13px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); margin-bottom: 22px;
  font-size: 13px; line-height: 1.5;
}
.banner.provenance { border-left: 3px solid var(--est); }
.banner b { color: var(--text); }
.banner p { margin: 0; color: var(--muted); }
.banner p + p { margin-top: 5px; }

/* ---------------------------------------------------------------- panels */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }

.grid { display: grid; gap: 14px; }
.grid.metrics { grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); margin-bottom: 20px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }

.metric {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 16px;
}
.metric .label { font-size: 11px; letter-spacing: 0.5px; color: var(--muted); text-transform: uppercase; }
.metric .value { font-size: 27px; font-weight: 650; letter-spacing: -0.8px; margin: 5px 0 2px; font-variant-numeric: tabular-nums; }
.metric .detail { font-size: 12px; color: var(--dim); }
.metric.accent .value { color: var(--accent); }
.metric.warn .value { color: var(--warn); }

/* -------------------------------------------------------------- coverage */
.coverage { margin-bottom: 16px; }
.coverage-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: 13px; }
.coverage-head .attr { font-weight: 600; }
.coverage-head .split { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.coverage-bar { display: flex; height: 7px; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.coverage-bar .known { background: var(--known); }
.coverage-bar .est { background: var(--est); }
.coverage-bar .missing { background: var(--line); }
.legend { display: flex; gap: 16px; font-size: 11.5px; color: var(--muted); margin-top: 7px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; vertical-align: -1px; }
.legend .known i { background: var(--known); }
.legend .est i { background: var(--est); }

/* ----------------------------------------------------------------- bars */
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 148px 1fr 92px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 18px; background: var(--surface-2); border-radius: 3px; overflow: hidden; display: flex; }
.bar-track .k { background: var(--known); height: 100%; }
.bar-track .e { background: var(--est); height: 100%; opacity: .85; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- table */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-size: 10.5px; letter-spacing: 0.9px; text-transform: uppercase;
  color: var(--dim); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line);
}
td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

/* ---------------------------------------------------------------- pills */
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
  border: 1px solid transparent;
}
.pill.confirmed { background: rgba(180,69,58,.16); color: #e08578; border-color: rgba(180,69,58,.35); }
.pill.probable  { background: rgba(201,100,66,.15); color: #dda07f; border-color: rgba(201,100,66,.35); }
.pill.reported  { background: rgba(61,127,184,.15); color: #86b6dd; border-color: rgba(61,127,184,.35); }
.pill.known     { background: rgba(47,158,110,.15); color: #6fc79b; border-color: rgba(47,158,110,.35); }
.pill.est       { background: rgba(184,134,47,.15); color: #d6ac5e; border-color: rgba(184,134,47,.35); }
.pill.muted     { background: var(--surface-2); color: var(--muted); border-color: var(--line); }

.delta { font-variant-numeric: tabular-nums; font-size: 12.5px; }
.delta.up { color: var(--accent); }
.delta.down { color: var(--warn); }

/* -------------------------------------------------------------- controls */
.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
select, input[type=text], input[type=password], input[type=email], input[type=number] {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 7px 10px; font: inherit; font-size: 13.5px; min-width: 160px;
}
select:focus, input:focus { outline: 2px solid var(--accent-dim); outline-offset: -1px; }
.btn {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 7px 13px; font: inherit; font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--dim); }
.btn.primary { background: var(--accent-dim); border-color: var(--accent-dim); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.tab {
  background: none; border: 1px solid var(--line); color: var(--muted);
  padding: 5px 12px; border-radius: 20px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.tab.active { background: var(--surface-2); color: var(--text); border-color: var(--dim); }

/* ---------------------------------------------------------------- detail */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.note { font-size: 12.5px; color: var(--dim); margin-top: 10px; line-height: 1.5; }
.empty { color: var(--dim); font-size: 13px; padding: 18px 0; text-align: center; }

.modal-back {
  position: fixed; inset: 0; background: rgba(8,11,14,.72); display: grid; place-items: center;
  padding: 24px; z-index: 40; backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 22px; max-width: 640px; width: 100%; max-height: 84vh; overflow-y: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.x { background: none; border: 0; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav-label, .sidebar-foot { display: none; }
  .bar-row { grid-template-columns: 110px 1fr 78px; }
}

/* ─────────────────────────────────────────────────────── VRM additions */
.tag { margin-left: auto; font-size: 9.5px; letter-spacing: .5px; color: var(--dim);
       border: 1px solid var(--line); border-radius: 3px; padding: 1px 4px; }
.nav-item.active .tag { color: var(--muted); }

.modal.wide { max-width: 900px; }

/* funnel */
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel-row { display: grid; grid-template-columns: 280px 1fr 120px; gap: 14px; align-items: center; }
.funnel-label b { display: block; font-size: 14px; }
.funnel-label .note { display: block; font-size: 11.5px; line-height: 1.4; }
.funnel-bar-wrap { background: var(--surface-2); border-radius: 4px; height: 26px; overflow: hidden; }
.funnel-bar { height: 100%; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); border-radius: 4px; }
.funnel-bar.neg { background: linear-gradient(90deg, #7d3229, var(--danger)); }
.funnel-num { text-align: right; }
.funnel-num b { font-size: 17px; font-variant-numeric: tabular-nums; }
.funnel-num .note { display: block; font-size: 11px; }
.funnel-row.detractor { margin-top: 10px; padding-top: 12px; border-top: 1px dashed var(--line); }

/* score badge */
.score-badge { display: inline-flex; flex-direction: column; align-items: center;
  padding: 8px 16px; border-radius: 10px; margin-bottom: 8px; border: 1px solid var(--line); }
.score-badge.high { background: rgba(47,158,110,.16); border-color: rgba(47,158,110,.4); }
.score-badge.mid  { background: rgba(184,134,47,.15); border-color: rgba(184,134,47,.4); }
.score-badge.low  { background: rgba(201,100,66,.14); border-color: rgba(201,100,66,.35); }
.score-badge.neg  { background: rgba(180,69,58,.15); border-color: rgba(180,69,58,.4); }
.score-num { font-size: 30px; font-weight: 700; letter-spacing: -1px; line-height: 1; font-variant-numeric: tabular-nums; }
.score-cap { font-size: 9.5px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin-top: 3px; }

/* next best action */
.nba { padding: 12px 14px; border-radius: var(--radius); background: var(--surface-2);
       border-left: 3px solid var(--accent); font-size: 13.5px; }
.nba.high { border-left-color: var(--warn); }
.nba.blocked, .nba.none { border-left-color: var(--danger); }
.nba b { display: block; margin-bottom: 3px; }
.nba span { color: var(--muted); }

/* timeline */
.timeline { position: relative; padding-left: 18px; }
.timeline::before { content: ''; position: absolute; left: 4px; top: 6px; bottom: 6px; width: 1px; background: var(--line); }
.tl-item { position: relative; padding: 9px 0; }
.tl-dot { position: absolute; left: -18px; top: 15px; width: 9px; height: 9px; border-radius: 50%;
          background: var(--dim); border: 2px solid var(--bg); }
.tl-item.complaint .tl-dot { background: var(--danger); }
.tl-item.praise .tl-dot { background: var(--accent); }
.tl-item.office_visit .tl-dot, .tl-item.meeting .tl-dot { background: var(--info); }
.tl-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 3px; font-size: 13px; }
.tl-body > div { font-size: 13.5px; }
.tl-body .btn { margin-top: 6px; }

/* API reference */
.endpoint { padding: 14px 0; border-bottom: 1px solid var(--line); }
.endpoint:last-child { border-bottom: 0; }
.ep-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 6px; }
.verb { font-size: 10.5px; font-weight: 700; letter-spacing: .6px; padding: 2px 7px; border-radius: 3px; }
.verb.get { background: rgba(61,127,184,.2); color: #86b6dd; }
.verb.post { background: rgba(47,158,110,.2); color: #6fc79b; }
.ep-path { font-size: 13.5px; font-weight: 600; }

/* ───────────────────────────────────────────── auth: login page */
.login-back {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(47,158,110,.14), transparent 60%),
    radial-gradient(700px 500px at 90% 100%, rgba(61,127,184,.10), transparent 60%),
    var(--bg);
  padding: 24px; overflow-y: auto;
}
.login-card {
  width: 100%; max-width: 880px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; padding: 34px 38px;
  display: grid; grid-template-columns: 1.1fr 1fr; gap: 34px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand .brand-mark { width: 42px; height: 42px; font-size: 19px; }
.login-left h1 { font-size: 24px; margin: 0 0 6px; }
.login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.login-form input {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 12px 14px; font: inherit; font-size: 15px;
}
.login-error { color: var(--warn); font-size: 13px; min-height: 18px; }
.login-note { font-size: 12px; color: var(--dim); line-height: 1.6; margin-top: 14px; }
.role-cards { display: flex; flex-direction: column; gap: 8px; max-height: 430px; overflow-y: auto; padding-right: 4px; }
.role-card {
  display: flex; align-items: center; gap: 11px; text-align: left; width: 100%;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 12px; cursor: pointer; color: var(--text); font: inherit;
}
.role-card:hover { border-color: var(--accent-dim); }
.role-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.role-card .avatar { flex: none; }
.role-card b { display: block; font-size: 13.5px; }
.role-card span { display: block; font-size: 11.5px; color: var(--muted); }
@media (max-width: 760px) { .login-card { grid-template-columns: 1fr; } }

/* avatar + topbar chip */
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), var(--accent-dim));
  color: #fff; font-weight: 700; font-size: 12px; letter-spacing: .3px;
}
.avatar.lg { width: 58px; height: 58px; font-size: 21px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text); }
.user-chip .role-cap { color: var(--muted); font-size: 11px; }

/* ───────────────────────────────────────────── themes */
/* Each theme overrides the token set. Dark themes inherit most defaults;
   light themes must override everything that assumes a dark ground. */
html[data-theme="emerald"] { --bg:#0a1410; --surface:#101c16; --surface-2:#16261d; --line:#22382c; --accent:#34b578; --accent-dim:#1f7a4f; }
html[data-theme="ocean"]   { --bg:#0a121c; --surface:#0f1a28; --surface-2:#152337; --line:#223550; --accent:#3d9fd8; --accent-dim:#256a94; --known:#3d9fd8; }
html[data-theme="violet"]  { --bg:#120f1c; --surface:#181428; --surface-2:#211b38; --line:#332a52; --accent:#8f6fe8; --accent-dim:#5f47a8; --known:#8f6fe8; }
html[data-theme="crimson"] { --bg:#160e10; --surface:#1e1316; --surface-2:#2a181c; --line:#42262c; --accent:#d8556a; --accent-dim:#96394a; --known:#d8556a; }
html[data-theme="contrast"]{ --bg:#000; --surface:#0a0a0a; --surface-2:#161616; --line:#3a3a3a; --text:#fff; --muted:#c8c8c8; --dim:#9a9a9a; --accent:#00e08a; --accent-dim:#00a865; }
html[data-theme="sand"], html[data-theme="paper"] {
  --text:#22292f; --muted:#5a6570; --dim:#8a949e;
  --known:#1e7a52; --est:#96700f; --warn:#b04a20; --danger:#a03028; --info:#25628f;
  --accent:#1e7a52; --accent-dim:#2f9e6e;
}
html[data-theme="sand"]  { --bg:#f4efe6; --surface:#fbf8f1; --surface-2:#efe8da; --line:#ddd3bf; }
html[data-theme="paper"] { --bg:#f2f4f6; --surface:#fcfdfe; --surface-2:#e9edf1; --line:#d5dce2; }
html[data-theme="sand"] .brand-mark, html[data-theme="paper"] .brand-mark,
html[data-theme="sand"] .avatar, html[data-theme="paper"] .avatar { color:#fff; }
html[data-theme="sand"] .funnel-bar, html[data-theme="paper"] .funnel-bar { opacity:.85; }

.theme-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(150px,1fr)); gap:12px; }
.theme-swatch {
  border:1px solid var(--line); border-radius:9px; padding:0; cursor:pointer; overflow:hidden;
  background:none; font:inherit; color:var(--text); text-align:left;
}
.theme-swatch.selected { border-color:var(--accent); box-shadow:0 0 0 1px var(--accent); }
.theme-swatch .sw-preview { height:56px; display:flex; }
.theme-swatch .sw-preview i { flex:1; }
.theme-swatch .sw-name { padding:8px 10px; font-size:12.5px; }
.theme-swatch .sw-name span { display:block; color:var(--muted); font-size:11px; }
