:root {
  --bg:        #0e1116;
  --bg-raise:  #161b22;
  --bg-hover:  #1c232d;
  --line:      #262d38;
  --line-soft: #1d232c;
  --text:      #e6edf3;
  --text-dim:  #8b949e;
  --text-faint:#5d6773;
  --accent:    #f0b429;
  --accent-dim:#3a2f10;
  --hot:       #f85149;
  --warm:      #d29922;
  --cold:      #6e7681;
  --ok:        #3fb950;
  --info:      #58a6ff;
  --radius:    8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------- layout --- */
.shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--bg-raise);
  border-right: 1px solid var(--line);
  padding: 20px 0;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  padding: 0 20px 20px;
  font-weight: 700; font-size: 15px; letter-spacing: -0.2px;
  display: flex; align-items: center; gap: 9px;
}
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--text-faint); }

.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 20px; color: var(--text-dim); text-decoration: none;
  border-left: 2px solid transparent; font-size: 13.5px;
}
.nav a:hover { background: var(--bg-hover); color: var(--text); }
.nav a.active { color: var(--text); border-left-color: var(--accent); background: var(--bg-hover); }
.nav .badge {
  background: var(--accent); color: #1a1206; border-radius: 10px;
  padding: 0 6px; font-size: 11px; font-weight: 700; min-width: 18px; text-align: center;
}
.nav .badge.quiet { background: var(--line); color: var(--text-dim); }
.nav-group { margin-top: 18px; padding: 0 20px 6px; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-faint); }

.main { padding: 26px 30px 60px; max-width: 1500px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
h1 { font-size: 21px; font-weight: 650; letter-spacing: -0.3px; }
h2 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
h3 { font-size: 13px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; }
.subtitle { color: var(--text-dim); font-size: 13px; }

/* -------------------------------------------------------------- pieces --- */
.card {
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 1100px) { .grid.cols-4, .grid.cols-5 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 800px)  { .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }

.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-faint); }
.stat .value { font-size: 27px; font-weight: 650; margin-top: 4px;
  font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.stat .hint { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }
.stat.accent .value { color: var(--accent); }
.stat.hot .value { color: var(--hot); }
.stat.ok .value { color: var(--ok); }

button, .btn {
  background: var(--bg-hover); color: var(--text); border: 1px solid var(--line);
  padding: 6px 13px; border-radius: 6px; cursor: pointer; font-size: 13px;
  font-family: inherit; text-decoration: none; display: inline-flex;
  align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--text-faint); background: #222a35; }
button.primary, .btn.primary {
  background: var(--accent); border-color: var(--accent); color: #1a1206; font-weight: 600;
}
button.primary:hover { background: #ffc53d; }
button.ghost { background: transparent; }
button.danger { color: var(--hot); border-color: #3d2224; }
button.danger:hover { background: #3d2224; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.sm, .btn.sm { padding: 3px 9px; font-size: 12px; }

input, select, textarea {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  padding: 7px 10px; border-radius: 6px; font-size: 13px; font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
}
textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 12.5px; }
label { display: block; font-size: 11.5px; color: var(--text-dim); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 130px; }
.row > .shrink { flex: 0 0 auto; min-width: 0; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-faint); font-weight: 600; padding: 8px 10px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:hover { background: var(--bg-hover); cursor: pointer; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--bg-raise); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.pill {
  display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 11px;
  font-weight: 600; letter-spacing: 0.2px; border: 1px solid transparent;
}
.pill.HOT      { background: #3d1d1d; color: #ff7b72; border-color: #5c2a2a; }
.pill.WARM     { background: #3a2f10; color: #e3b341; border-color: #574a1c; }
.pill.COLD     { background: #21262d; color: var(--text-dim); border-color: var(--line); }
.pill.EXCLUDED { background: #21262d; color: var(--text-faint); }
.pill.NEW      { background: #1c2333; color: #79c0ff; }
.pill.CONTACTED{ background: #12261e; color: #56d364; }
.pill.REPLIED  { background: #2b1d3d; color: #d2a8ff; }
.pill.MEETING_SET  { background: #0d2b31; color: #56d4dd; }
.pill.PROPOSAL_SENT{ background: #3a2f10; color: #e3b341; }
.pill.NEGOTIATION  { background: #3a2410; color: #ffa657; }
.pill.WON      { background: #12261e; color: #3fb950; }
.pill.LOST     { background: #2d2020; color: #a1666a; }
.pill.FRESH    { background: #12261e; color: #3fb950; }
.pill.STALE    { background: #3a2f10; color: #e3b341; }
.pill.NEVER    { background: #3d1d1d; color: #ff7b72; }
.pill.EXHAUSTED{ background: #21262d; color: var(--text-faint); }
.pill.PENDING  { background: #3a2f10; color: #e3b341; }
.pill.APPROVED { background: #12261e; color: #56d364; }
.pill.SENT     { background: #1c2333; color: #79c0ff; }
.pill.SKIPPED, .pill.FAILED { background: #2d2020; color: #a1666a; }
.pill.RUNNING  { background: #1c2333; color: #79c0ff; }
.pill.COMPLETED{ background: #12261e; color: #3fb950; }
.pill.STOPPED_QUOTA { background: #3a2f10; color: #e3b341; }

.score {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 22px; border-radius: 5px; font-weight: 700;
  font-size: 12px; font-variant-numeric: tabular-nums; background: var(--bg-hover);
}
.score.s-hot { background: #3d1d1d; color: #ff7b72; }
.score.s-warm { background: #3a2f10; color: #e3b341; }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex.between { justify-content: space-between; }
.flex.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

.banner {
  border-radius: var(--radius); padding: 11px 14px; font-size: 13px;
  border: 1px solid var(--line); background: var(--bg-raise); margin-bottom: 16px;
}
.banner.warn { border-color: #574a1c; background: #241d0c; color: #e3b341; }
.banner.err  { border-color: #5c2a2a; background: #2b1516; color: #ff7b72; }
.banner.info { border-color: #1f3a5f; background: #10203a; color: #a5d6ff; }

.empty { padding: 40px 20px; text-align: center; color: var(--text-faint); font-size: 13px; }

.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.ok > span { background: var(--ok); }
.bar.danger > span { background: var(--hot); }

/* --------------------------------------------------------------- drawer --- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 94vw);
  background: var(--bg-raise); border-left: 1px solid var(--line); z-index: 41;
  overflow-y: auto; padding: 22px 24px 60px;
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; margin-bottom: 6px; }
.drawer h2 { font-size: 18px; margin-bottom: 2px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 16px 0; }
.tabs button {
  background: none; border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 7px 12px; color: var(--text-dim); font-size: 13px;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; }
dl.kv dt { color: var(--text-faint); font-size: 12px; }
dl.kv dd { word-break: break-word; }

ul.issues { list-style: none; }
ul.issues li { padding: 5px 0 5px 16px; position: relative; font-size: 12.5px;
  border-bottom: 1px solid var(--line-soft); }
ul.issues li::before { content: "▸"; position: absolute; left: 0; color: var(--warm); }
ul.reasons li::before { content: "✓"; color: var(--ok); }

.timeline { list-style: none; }
.timeline li { border-left: 2px solid var(--line); padding: 0 0 14px 14px;
  position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 5px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.timeline .when { font-size: 11px; color: var(--text-faint); }

.msg-preview {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 12px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap;
  max-height: 340px; overflow-y: auto;
}

.switch { display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--line-soft); }
.switch:last-child { border-bottom: none; }
.switch .name { flex: 1; }
.switch .name small { display: block; color: var(--text-faint); font-size: 11.5px; }
.toggle { position: relative; width: 40px; height: 22px; border-radius: 11px;
  background: var(--line); border: none; cursor: pointer; padding: 0; flex: 0 0 auto; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px;
  height: 16px; border-radius: 50%; background: var(--text-faint); transition: 0.15s; }
.toggle.on { background: var(--accent-dim); }
.toggle.on::after { left: 21px; background: var(--accent); }

.coverage-cell { padding: 5px 8px; border-radius: 4px; font-size: 11px; text-align: center;
  font-weight: 600; }

/* ---------------------------------------------------------------- login --- */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: 340px; }
.login-card .brand { justify-content: center; padding-bottom: 22px; }

#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--bg-raise); border: 1px solid var(--line); padding: 10px 18px;
  border-radius: 8px; z-index: 100; font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
#toast.err { border-color: #5c2a2a; color: #ff7b72; }
#toast.ok  { border-color: #1f4a2c; color: #56d364; }

.loading { color: var(--text-faint); font-size: 13px; padding: 30px; text-align: center; }

/* ------------------------------------------------------------------ map --- */
.dot-key { display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle; }

/* Leaflet ships a light-theme control set. These pull it into the dark shell
   without touching the vendored file, so upgrading Leaflet is still a drop-in. */
.leaflet-container { background: var(--bg); font: inherit; }
.leaflet-control-zoom a {
  background: var(--bg-raise); color: var(--text); border-color: var(--line);
}
.leaflet-control-zoom a:hover { background: var(--bg-hover); color: var(--text); }
.leaflet-control-attribution {
  background: rgba(14, 17, 22, .8); color: var(--text-faint); font-size: 10px;
}
.leaflet-control-attribution a { color: var(--text-dim); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-raise); color: var(--text); border: 1px solid var(--line);
}
.leaflet-popup-content { margin: 11px 13px; font-size: 12.5px; line-height: 1.5; }
.leaflet-popup-content a { color: var(--info); }
.leaflet-popup-close-button { color: var(--text-faint) !important; }

/* OSM tiles are bright next to a dark UI; take the edge off without washing out
   the markers drawn on top of them. */
.leaflet-tile-pane { filter: brightness(.72) saturate(.85) contrast(1.05); }
