:root {
  color-scheme: dark;
  --bg: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2d2d2a;
  --line: #34342f;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e85;
  --accent: #3987e5;
  --focus: #fab219;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767; --s0: #77766f;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --hot-bg: #3a1d14;
  --radius: 14px;
  --font: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f2ef;
  --surface-1: #fcfcfb;
  --surface-2: #f0efeb;
  --surface-3: #e5e4df;
  --line: #d9d8d2;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7973;
  --accent: #2a78d6;
  --focus: #b86e00;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948; --s0: #9a9992;
  --hot-bg: #fde9df;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text-primary); font: 15px/1.45 var(--font); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 208px 1fr; height: 100vh; }
.side { background: var(--surface-1); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; gap: 4px; overflow-y: auto; }
.brand { font-weight: 600; font-size: 14px; letter-spacing: .02em; color: var(--text-secondary); padding: 4px 12px 14px; }
.brand b { color: var(--text-primary); display: block; font-size: 17px; }
.tab { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; border: 0; background: none; text-align: left; cursor: pointer; color: var(--text-secondary); width: 100%; font-weight: 500; }
.tab svg { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab:hover { background: var(--surface-2); color: var(--text-primary); }
.tab[aria-current="page"] { background: var(--surface-3); color: var(--text-primary); }
.tab .badge { margin-left: auto; }
.side .spacer { flex: 1; }
.side .stamp { font-size: 12px; color: var(--text-muted); padding: 8px 12px; }
.main { overflow-y: auto; padding: 22px 26px 60px; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top h1 { font-size: 24px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.top .sub { color: var(--text-muted); font-size: 13px; }
.top .grow { flex: 1; }

.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--critical); color: #fff; font-size: 12px; font-weight: 600; font-family: var(--mono); }
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface-2); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; min-height: 40px; }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 5px 10px; min-height: 34px; font-size: 13px; }
.btn.ghost { background: none; }
.btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 8px; cursor: pointer; color: var(--text-secondary); font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text-primary); }
select.pick { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-height: 40px; font-weight: 500; }

/* ---------- cards ---------- */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; color: var(--text-secondary); letter-spacing: .01em; }
.card h2 .count { color: var(--text-muted); font-weight: 500; }
.empty { color: var(--text-muted); padding: 10px 0; }

.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.stat .v { font-family: var(--mono); font-size: 30px; font-weight: 500; line-height: 1.1; }
.stat .l { color: var(--text-muted); font-size: 13px; }
.stat.alert .v { color: var(--serious); }

/* ---------- attention list ---------- */
.items { display: flex; flex-direction: column; gap: 10px; }
.item { display: grid; grid-template-columns: 6px 1fr auto; gap: 14px; background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 14px 0; align-items: start; }
.item .bar { align-self: stretch; border-radius: 0 4px 4px 0; background: var(--s0); }
.item.hot { background: var(--hot-bg); border-color: var(--critical); }
.item .kind { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); }
.item .kind svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }
.item .kind.hot { color: var(--serious); }
.item .kind.alarm { color: var(--warning); }
.item .t { font-size: 16px; font-weight: 600; margin: 3px 0 2px; }
.item .d { color: var(--text-secondary); font-size: 14px; overflow-wrap: anywhere; }
.item .meta { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.item .acts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.tag i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; background: var(--s0); }

/* ---------- tables ---------- */
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; color: var(--text-muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; padding: 6px 10px; border-bottom: 1px solid var(--line); }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t td.n, table.t th.n { text-align: right; font-family: var(--mono); }
table.t tr:last-child td { border-bottom: 0; }

/* ---------- timeline ---------- */
.tl { display: flex; flex-direction: column; }
.tl .row { display: grid; grid-template-columns: 64px 10px 1fr auto; gap: 12px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.tl .row.future { opacity: .55; }
.tl .row .time { font-family: var(--mono); color: var(--text-secondary); }
.tl .row .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--s0); }
.tl .row .who { font-weight: 500; }
.tl .row .subj { color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.st { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-3); color: var(--text-secondary); white-space: nowrap; }
.st::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); }
.st.sent::before { background: var(--good); }
.st.replied { color: var(--text-primary); } .st.replied::before { background: var(--accent); }
.st.bounced::before, .st.failed::before, .st.missed::before { background: var(--critical); }
.st.notseen::before, .st.held::before { background: var(--warning); }

details.group { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
details.group summary { padding: 14px 16px; cursor: pointer; display: flex; gap: 14px; align-items: center; list-style: none; font-weight: 600; }
details.group summary::-webkit-details-marker { display: none; }
details.group summary .counts { margin-left: auto; color: var(--text-muted); font-weight: 400; font-size: 13px; }
details.group .tl { padding: 0 12px 8px; }

/* ---------- charts ---------- */
.chart { position: relative; }
.chart svg { width: 100%; display: block; overflow: visible; }
.chart .axis text { fill: var(--text-muted); font-size: 12px; font-family: var(--mono); }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .capline { stroke: var(--text-muted); stroke-dasharray: 4 4; stroke-width: 1.5; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0 0; font-size: 13px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.tip { position: fixed; pointer-events: none; background: var(--surface-3); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 13px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.35); max-width: 260px; display: none; }
.tip b { display: block; margin-bottom: 2px; }

/* ---------- pipeline ---------- */
.board { display: grid; grid-template-columns: repeat(7, minmax(150px, 1fr)); gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.col { background: var(--surface-2); border-radius: 12px; padding: 10px; min-height: 120px; }
.col h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--text-secondary); display: flex; justify-content: space-between; }
.col h3 span { font-family: var(--mono); color: var(--text-primary); }
.pcard { display: block; width: 100%; text-align: left; background: var(--surface-1); border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; margin-bottom: 6px; cursor: pointer; font-size: 13px; }
.pcard small { display: block; color: var(--text-muted); font-size: 11px; }
.col .more { font-size: 12px; color: var(--text-muted); padding: 4px; }
.strip { display: flex; flex-wrap: wrap; gap: 10px 26px; align-items: center; }
.strip .k { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.strip .v { font-weight: 600; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-weight: 600; font-size: 13px; }
.pill.on { background: color-mix(in srgb, var(--good) 22%, transparent); color: var(--text-primary); }
.pill.off { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--text-primary); }

/* ---------- calls ---------- */
.call { display: grid; grid-template-columns: 1fr auto; gap: 10px 18px; }
.call .phone { font-family: var(--mono); font-size: 18px; text-decoration: none; display: inline-flex; gap: 8px; align-items: center; }
.call .why { color: var(--text-secondary); font-size: 14px; }
.call .outs { display: flex; gap: 8px; flex-wrap: wrap; grid-column: 1 / -1; }
.warm { color: var(--serious); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- calendar ---------- */
.cal-day { display: grid; grid-template-columns: 120px 1fr; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.cal-day .dname { font-weight: 600; }
.cal-day .dname small { display: block; color: var(--text-muted); font-weight: 400; }
.ev { display: grid; grid-template-columns: 4px 1fr; gap: 10px; padding: 6px 0; }
.ev .c { border-radius: 2px; }
.ev .tt { font-weight: 500; }
.ev .dd { color: var(--text-muted); font-size: 13px; }
.ev.meeting .c { background: var(--accent); }
.ev.followup .c { background: var(--s3); }
.ev.deadline .c { background: var(--critical); }
.ev.hold .c { background: var(--warning); }
.evtype { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-right: 6px; }

/* ---------- modal, banner, toast ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 20px; }
.modal { background: var(--surface-1); border: 1px solid var(--line); border-radius: 18px; max-width: 760px; width: 100%; max-height: 88vh; overflow-y: auto; padding: 22px 24px; }
.modal h2 { margin: 0 0 4px; }
.modal pre { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 12px; border-radius: 10px; }
.msg { border-bottom: 1px solid var(--line); padding: 10px 0; }
.msg .h { font-size: 13px; color: var(--text-muted); }
.banner { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: var(--critical); color: #fff; padding: 14px 22px; border-radius: 14px; z-index: 60; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 80vw; }
.banner small { display: block; font-weight: 400; opacity: .9; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--surface-3); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; z-index: 60; display: flex; gap: 12px; align-items: center; }

/* ---------- login ---------- */
.login { max-width: 460px; margin: 10vh auto; padding: 0 16px; }
.login .card { padding: 24px; }
.login h1 { font-size: 22px; margin: 0 0 6px; }
.login p { color: var(--text-secondary); }
.login label { display: block; font-size: 13px; color: var(--text-muted); margin: 12px 0 4px; }
.login input, .field { width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; }
.paircode { font-family: var(--mono); font-size: 56px; letter-spacing: .18em; text-align: center; margin: 18px 0; }
.err { color: var(--serious); margin-top: 10px; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

/* ---------- focus (TV remote and keyboard) ---------- */
:focus { outline: none; }
:focus-visible, body.tv :focus { outline: 3px solid var(--focus); outline-offset: 2px; }
body.tv { font-size: 19px; }
body.tv .shell { grid-template-columns: 250px 1fr; }
body.tv .item .t { font-size: 20px; }
body.tv .btn { min-height: 48px; padding: 10px 18px; }
body.tv .stat .v { font-size: 38px; }

/* ---------- narrow screens (phone, tablet portrait) ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side { order: 2; flex-direction: row; padding: 4px; border-right: 0; border-top: 1px solid var(--line); overflow-x: auto; }
  .brand, .side .spacer, .side .stamp { display: none; }
  .tab { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 8px; min-width: 64px; align-items: center; position: relative; }
  .tab .badge { position: absolute; top: 0; right: 4px; margin: 0; min-width: 18px; height: 18px; font-size: 10px; }
  .main { padding: 16px 16px 40px; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .g2, .g3 { grid-template-columns: 1fr; }
  .item { grid-template-columns: 6px 1fr; }
  .item .acts { grid-column: 2; justify-content: flex-start; }
  .tl .row { grid-template-columns: 50px 8px 1fr; }
  .tl .row .st { grid-column: 3; justify-self: start; }
  .cal-day { grid-template-columns: 1fr; gap: 4px; }
}
