:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #191919;
  --muted: #666666;
  --line: #e3e5e8;
  --accent: #257de0;
  --accent-ink: #ffffff;
  --track: #e9edf2;
  --good: #0f7b2d;
  --good-bg: #e3f4e7;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --bad: #b42318;
  --bad-bg: #fde8e7;
  --hot: #c2410c;
  --warm: #a16207;
  --cold: #475569;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #191b20;
    --text: #efefef;
    --muted: #9c9c9c;
    --line: #2a2d34;
    --accent: #338ced;
    --track: #262a31;
    --good: #5bd27a;
    --good-bg: #133220;
    --warn: #f2c14e;
    --warn-bg: #3a2d0c;
    --bad: #ff8a80;
    --bad-bg: #3d1614;
    --hot: #fb923c;
    --warm: #facc15;
    --cold: #94a3b8;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.5; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
#app { max-width: 860px; margin: 0 auto; }
main { padding: 12px 12px 120px; display: flex; flex-direction: column; gap: 12px; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 8px 0 4px; }
a { color: var(--accent); }
pre.body { white-space: pre-wrap; word-break: break-word; font: inherit; background: var(--bg);
  padding: 10px; border-radius: 8px; margin: 8px 0; max-height: 50vh; overflow: auto; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; gap: 8px; }
.wrap { flex-wrap: wrap; }
.gap { gap: 6px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.error { color: var(--bad); }
.card.error { background: var(--bad-bg); margin: 12px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }

button, .btn, select, input {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; min-height: 40px; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; cursor: pointer;
}
input, select { cursor: auto; width: 100%; }
button:disabled { opacity: .5; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.wide { width: 100%; }
button.icon { min-width: 40px; padding: 0; font-size: 18px; }
button.ok { color: var(--good); }
button.bad { color: var(--bad); }
button.ok.on { background: var(--good); color: #fff; border-color: var(--good); }
button.bad.on { background: var(--bad); color: #fff; border-color: var(--bad); }
button.on:not(.ok):not(.bad):not([role="tab"]) { background: var(--accent); color: #fff; }

header.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; background: var(--surface);
  border-bottom: 1px solid var(--line); }
header.top .row { gap: 6px; }

nav.tabs { position: fixed; bottom: 0; inset-inline: 0; z-index: 6; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.tabs button { flex: 1; flex-direction: column; border: 0; border-radius: 0; font-size: 12px; gap: 2px;
  min-height: 60px; color: var(--muted); position: relative; background: transparent; }
nav.tabs button.on { color: var(--accent); font-weight: 600; }
nav.tabs .ico { font-size: 18px; line-height: 1; }
.badge { position: absolute; top: 6px; inset-inline-start: 50%; margin-inline-start: 8px; background: var(--bad);
  color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; line-height: 18px; min-width: 18px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.tile-v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-l { color: var(--muted); font-size: 13px; }
.tile-h { font-size: 12px; }

.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 34%) 1fr 44px; align-items: center; gap: 8px; }
.bar-label { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: var(--track); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; min-width: 2px; }
.bar-value { font-size: 13px; font-variant-numeric: tabular-nums; text-align: end; }

.kv { list-style: none; margin: 0; padding: 0; }
.kv li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.kv li:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.bullets { margin: 6px 0; padding-inline-start: 20px; }

.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--track);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.pill.muted { color: var(--muted); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.good, .pill.st-won, .pill.st-replied { background: var(--good-bg); color: var(--good); }
.pill.bad, .pill.st-lost, .pill.st-opted_out { background: var(--bad-bg); color: var(--bad); }

.score { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: 52px;
  height: 52px; border-radius: 12px; border: 2px solid currentColor; flex-shrink: 0; line-height: 1.1; }
.score b { font-size: 18px; }
.score small { font-size: 11px; }
.tier-hot { color: var(--hot); }
.tier-warm { color: var(--warm); }
.tier-cold, .tier-none { color: var(--cold); }

.draft { display: flex; flex-direction: column; gap: 10px; }
.draft.decided-approve { border-color: var(--good); }
.draft.decided-reject { border-color: var(--bad); opacity: .75; }
details summary { cursor: pointer; font-weight: 600; padding: 4px 0; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters input[type="search"] { grid-column: 1 / -1; }
@media (min-width: 700px) { .filters { grid-template-columns: 2fr 1fr 1fr 1fr 1fr; } .filters input[type="search"] { grid-column: auto; } }

.list { display: flex; flex-direction: column; gap: 8px; }
.lead-row { display: flex; gap: 10px; align-items: flex-start; text-align: start; width: 100%; padding: 12px;
  border-radius: var(--radius); justify-content: flex-start; }
.lead-row .row { margin-top: 4px; }

.runs { list-style: none; padding: 0; margin: 0; }
.runs li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }

.tray { position: fixed; z-index: 7; bottom: calc(68px + env(safe-area-inset-bottom)); inset-inline: 8px;
  max-width: 844px; margin: 0 auto; display: flex; gap: 8px; align-items: center; background: var(--surface);
  border: 2px solid var(--accent); border-radius: var(--radius); padding: 10px; box-shadow: 0 6px 24px rgb(0 0 0 / .18); }
.check { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.check input { width: auto; min-height: 0; }

.toast { position: fixed; z-index: 9; top: 70px; inset-inline: 12px; max-width: 600px; margin: 0 auto;
  background: var(--text); color: var(--bg); padding: 12px 14px; border-radius: var(--radius); text-align: center; }

dialog#lead { width: min(760px, 100vw); max-height: 92vh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 16px 16px 0 0; background: var(--surface); color: var(--text); }
@media (min-width: 760px) { dialog#lead { margin: auto; border-radius: 16px; } }
dialog#lead::backdrop { background: rgb(0 0 0 / .45); }
.sheet { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.sheet section { border-top: 1px solid var(--line); padding-top: 8px; }

.setup { min-height: 100vh; justify-content: center; }
.setup form { display: flex; flex-direction: column; gap: 6px; max-width: 460px; margin: 0 auto; width: 100%; }
.setup label { font-weight: 600; margin-top: 6px; }
.setup button.primary { margin-top: 10px; }

@media (prefers-reduced-motion: no-preference) { button { transition: background .15s, color .15s; } }

.live { color: var(--accent); }
.setup form > button[type="button"] { margin-top: 4px; }
