:root {
  --bg: #0f1216; --panel: #161b22; --panel2: #1c2230; --line: #262d3a;
  --fg: #e6edf3; --muted: #8b98a9; --accent: #4c8dff;
  --green: #2ea043; --gold: #d9a441; --teal: #2bb6a3; --red: #d1555f; --gray: #6b7688;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa; --panel: #fff; --panel2: #eef1f5; --line: #d8dee6;
    --fg: #1c2128; --muted: #5a6673;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg); display: flex; flex-direction: column;
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Segoe UI, sans-serif;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none;
}
.brand { font-weight: 700; letter-spacing: .3px; }
.brand .dot { color: var(--accent); margin: 0 4px; }
.brand .sub { color: var(--muted); font-weight: 500; }
.tabs { display: flex; gap: 4px; }
.tab { color: var(--muted); text-decoration: none; padding: 4px 10px; border-radius: 6px;
  display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.tab:hover { background: var(--panel2); color: var(--fg); }
.tab.active { background: var(--accent); color: #fff; }
.tab .count { font-size: 11px; background: rgba(255,255,255,.14); padding: 0 6px;
  border-radius: 10px; min-width: 18px; text-align: center; }
.tab:not(.active) .count { background: var(--panel2); }
/* scan-health indicator (reads scan_runs; the nightly heartbeat) */
.scanhealth { display: flex; align-items: center; gap: 6px; margin-left: auto;
  font-size: 11.5px; color: var(--muted); padding: 3px 9px; border: 1px solid var(--line);
  border-radius: 20px; white-space: nowrap; }
.scanhealth .sh-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gray); flex: none; }
.scanhealth .sh-detail { opacity: .75; }
.h-ok { color: var(--fg); } .h-ok .sh-dot { background: var(--green); }
.h-warn { border-color: var(--gold); color: var(--gold); } .h-warn .sh-dot { background: var(--gold); }
.h-bad { border-color: var(--red); color: var(--red); } .h-bad .sh-dot { background: var(--red); }
.h-run .sh-dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.controls { display: flex; gap: 8px; align-items: center; }
.logout { color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 6px; line-height: 1.4; }
.logout:hover { color: var(--red); border-color: var(--red); }
.controls input.search, .controls select {
  background: var(--panel2); border: 1px solid var(--line); color: var(--fg);
  border-radius: 6px; padding: 5px 8px; font: inherit; }
.controls .search { width: 220px; }
.nonetoggle { color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }

/* ---- split: list + detail ---- */
.split { flex: 1; display: flex; min-height: 0; }
.listpane {
  width: 540px; flex: none; margin: 0; padding: 0; list-style: none;
  overflow-y: auto; border-right: 1px solid var(--line); background: var(--bg);
}
.detailpane { flex: 1; overflow-y: auto; padding: 22px 26px; min-width: 0; }

/* list items — compact action rows with enough context to triage */
.litem {
  display: flex; align-items: flex-start; gap: 8px; padding: 7px 12px;
  border-bottom: 1px solid var(--line); cursor: pointer; min-height: 56px;
}
.litem:hover { background: var(--panel2); }
.litem.sel { background: rgba(76,141,255,.16); box-shadow: inset 3px 0 0 var(--accent); }
.litem.leaving { opacity: 0; transition: opacity .16s ease; }
.litem.is-gone { opacity: .5; }
.li-main { min-width: 0; flex: 1; display: grid; gap: 2px; }
.li-top { display: flex; align-items: baseline; gap: 7px; min-width: 0; white-space: nowrap; }
.li-firm { font-weight: 700; flex: none; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.li-title { color: var(--fg); flex: 1; overflow: hidden; text-overflow: ellipsis; }
.li-sub { display: flex; gap: 6px; align-items: center; min-width: 0; color: var(--muted);
  font-size: 11.5px; white-space: nowrap; overflow: hidden; }
.li-sub span { min-width: 0; overflow: hidden; text-overflow: ellipsis; flex: none; max-width: 130px; }
.li-sub span::before { content: ""; }
.li-sub span + span::before { content: "·"; color: var(--line); margin-right: 6px; }
.li-sub .li-why { flex: 1; max-width: none; }
.li-marks { flex: none; display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end;
  max-width: 74px; padding-top: 1px; }
.empty { color: var(--muted); padding: 40px 20px; text-align: center; }

/* tier badges (shared) */
.tier { display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: 10px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .3px; flex: none; }
.t-highest { background: rgba(217,164,65,.18); color: var(--gold); border: 1px solid var(--gold); }
.t-strong { background: rgba(46,160,67,.16); color: var(--green); border: 1px solid var(--green); }
.t-selective { background: rgba(43,182,163,.16); color: var(--teal); border: 1px solid var(--teal); }
.t-adjacent { background: rgba(107,118,136,.16); color: var(--gray); border: 1px solid var(--gray); }
.t-none { background: transparent; color: var(--muted); border: 1px solid var(--line); }

/* small inline markers (age / gone / status) */
.mark { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px;
  padding: 1px 5px; border-radius: 8px; border: 1px solid var(--line); color: var(--muted); }
.mark.stale { color: var(--gold); border-color: var(--gold); }
.mark.gone { color: var(--red); border-color: var(--red); }
.mark.s-interested { color: var(--gold); border-color: var(--gold); }
.mark.s-applied { color: var(--green); border-color: var(--green); }
.mark.s-dismissed { color: var(--muted); }
.mark.priority { color: var(--accent); border-color: var(--accent); }
.mark.fit { color: var(--teal); border-color: var(--teal); }

/* ---- detail pane ---- */
.detail-empty { color: var(--muted); padding: 40px 0; }
.d-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.statusnow { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.s-new { color: var(--muted); } .s-interested { color: var(--gold); }
.s-applied { color: var(--green); } .s-dismissed { color: var(--red); }
.d-firm { font-size: 13px; color: var(--muted); font-weight: 600; }
.d-title { font-size: 22px; line-height: 1.25; margin: 2px 0 12px; max-width: 720px; }
.d-title a { color: var(--fg); text-decoration: none; }
.d-title a:hover { color: var(--accent); text-decoration: underline; }
.d-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted);
  font-size: 12.5px; padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.d-meta span { white-space: nowrap; }
.d-rationale { max-width: 680px; font-size: 15px; line-height: 1.6; color: var(--fg); }
.d-rationale span { display: block; margin-bottom: 3px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); font-weight: 700; }
.d-feedback { display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  max-width: 680px; margin-top: 12px; color: var(--muted); font-size: 11px; }
.d-feedback span { text-transform: uppercase; letter-spacing: .5px; font-weight: 700; margin-right: 2px; }
.fb { background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 12px; padding: 2px 8px; font: inherit; cursor: pointer; }
.fb:hover, .fb.active { color: var(--fg); border-color: var(--accent); }
.fb.active { background: rgba(76,141,255,.16); }
.d-noteslabel { display: block; margin: 20px 0 5px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); font-weight: 700; }
.d-notes { width: 100%; max-width: 680px; min-height: 60px; resize: vertical;
  background: var(--panel2); border: 1px solid var(--line); color: var(--fg);
  border-radius: 6px; padding: 8px 10px; font: inherit; }
.d-notes.saved { border-color: var(--green); }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; max-width: 680px; }
.b { border: 1px solid var(--line); background: var(--panel2); color: var(--fg);
  border-radius: 6px; padding: 7px 12px; cursor: pointer; font: inherit; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; }
.b b { font-family: monospace; background: var(--bg); border: 1px solid var(--line);
  border-radius: 3px; padding: 0 5px; font-size: 11px; font-weight: 700; }
.b:hover { border-color: var(--accent); }
.b-interested:hover { color: var(--gold); } .b-applied:hover { color: var(--green); }
.b-dismissed:hover { color: var(--red); }

/* keyboard help footer */
.keys { display: flex; gap: 16px; flex-wrap: wrap; padding: 5px 14px; flex: none;
  background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: 4px;
  padding: 0 5px; font: 11px monospace; }

/* "new since last visit" dot + marker */
.newdot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  flex: none; box-shadow: 0 0 0 2px rgba(76,141,255,.25); }
.mark.isnew { color: var(--accent); border-color: var(--accent); }

/* lazy-loaded JD block in the detail pane */
.d-jdwrap { margin-top: 18px; max-width: 680px; border-top: 1px solid var(--line); padding-top: 12px; }
.d-jdwrap summary { cursor: pointer; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); font-weight: 700; }
.d-jd { margin-top: 10px; font-size: 13.5px; line-height: 1.6; color: var(--fg);
  max-height: 320px; overflow-y: auto; }
.muted { color: var(--muted); }

/* follow-up date field (applied/interested roles) */
.d-followup { margin-top: 18px; max-width: 680px; }
.fu-input { background: var(--panel2); border: 1px solid var(--line); color: var(--fg);
  border-radius: 6px; padding: 6px 9px; font: inherit; }
.fu-input.saved { border-color: var(--green); }

/* back button — desktop hides it; mobile drill-in shows it */
.d-back { display: none; background: none; border: none; color: var(--accent);
  font: inherit; cursor: pointer; padding: 0 0 10px; }

/* ---- analytics / stats view ---- */
.statswrap { flex: 1; overflow-y: auto; padding: 18px 22px; }
.kpirow { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.kpi { flex: 1 1 130px; background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--gray); border-radius: 8px; padding: 12px 14px; }
.kpi-val { font-size: 28px; font-weight: 700; line-height: 1; }
.kpi-val .pct { font-size: 16px; color: var(--muted); font-weight: 600; }
.kpi-label { color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: .4px; margin-top: 6px; font-weight: 600; }
.kpi-viewed { border-left-color: var(--accent); }
.kpi-interested { border-left-color: var(--gold); }
.kpi-applied { border-left-color: var(--green); }
.kpi-dismissed { border-left-color: var(--red); }
.kpi-rate { border-left-color: var(--accent); }

.chartgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card { margin: 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 14px 16px; }
.card.wide { grid-column: 1 / -1; }
.card figcaption { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.card .cap-sub { color: var(--muted); font-weight: 500; font-size: 12px; }
.chartbox { width: 100%; }
.chartbox .muted { display: block; padding: 24px 6px; font-size: 12.5px; }
.legend { display: flex; gap: 16px; margin-bottom: 8px; }
.legend .lg { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }

.charttip { position: fixed; z-index: 50; pointer-events: none; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; font-size: 12px;
  color: var(--fg); box-shadow: 0 4px 14px rgba(0,0,0,.3); max-width: 240px; }

.stats-tab { text-decoration: none; }
.yieldgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.yieldgrid h2 { margin: 0 0 10px; font-size: 14px; }
.yieldtable { width: 100%; border-collapse: collapse; font-size: 12px; }
.yieldtable th, .yieldtable td { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: right; }
.yieldtable th:first-child, .yieldtable td:first-child { text-align: left; max-width: 320px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.yieldtable th { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; }

/* phone: drill-in — list is the default view; selecting a role slides the
   detail over full-screen with a Back button (instead of stacking below fold) */
@media (max-width: 720px) {
  .split { flex-direction: column; }
  .listpane { width: 100%; flex: 1; max-height: none; border-right: none; }
  .detailpane { display: none; }
  body.show-detail .listpane { display: none; }
  body.show-detail .detailpane { display: block; flex: 1; }
  .d-back { display: block; }
  .controls .search { width: 120px; }
  .d-title { font-size: 19px; }
  .li-sub .li-why { display: none; }
  .li-marks { max-width: 64px; }
  .chartgrid { grid-template-columns: 1fr; }
  .yieldgrid { grid-template-columns: 1fr; }
  .kpi { flex-basis: calc(50% - 12px); }
}
