:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --panel-2: #f1f1ee;
  --line: #e3e3de;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --hot: #d9480f;
  --hot-bg: #fff0e6;
  --warm: #b7791f;
  --warm-bg: #fdf6e3;
  --cold: #4a6fa5;
  --cold-bg: #eaf1fb;
  --good: #2b8a3e;
  --good-bg: #e9f7ec;
  --bad: #c92a2a;
  --bad-bg: #fdecec;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --panel: #1d1d1b; --panel-2: #262624; --line: #33332f; --text: #ededea; --muted: #9a9a94;
    --accent: #5b8ff9; --hot: #ff8a4c; --hot-bg: #3a2216; --warm: #e0b04a; --warm-bg: #352b14;
    --cold: #8fb0e0; --cold-bg: #1c2738; --good: #5cc472; --good-bg: #17301d; --bad: #ff6b6b; --bad-bg: #3a1a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413; --panel: #1d1d1b; --panel-2: #262624; --line: #33332f; --text: #ededea; --muted: #9a9a94;
  --accent: #5b8ff9; --hot: #ff8a4c; --hot-bg: #3a2216; --warm: #e0b04a; --warm-bg: #352b14;
  --cold: #8fb0e0; --cold-bg: #1c2738; --good: #5cc472; --good-bg: #17301d; --bad: #ff6b6b; --bad-bg: #3a1a1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 4px 8px 14px; }
.brand svg { width: 24px; height: 24px; }
.side-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 12px 8px 4px; }
.side-link {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 7px; color: var(--text);
  cursor: pointer; border: 0; background: none; font: inherit; text-align: left; width: 100%;
}
.side-link:hover { background: var(--panel-2); text-decoration: none; }
.side-link.active { background: var(--panel-2); font-weight: 600; }
.side-link .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.side-foot { margin-top: auto; padding-top: 12px; }
.main { min-width: 0; padding: 22px 28px 60px; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }

/* Controls */
button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
button:hover, .btn:hover { background: var(--panel-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.07); background: var(--accent); }
button.danger { color: var(--bad); }
button.ghost { border-color: transparent; background: none; }
button.ghost:hover { background: var(--panel-2); }
button.sm { padding: 4px 9px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
textarea { width: 100%; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.field input, label.field select, label.field textarea { font-size: 14px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .wide { grid-column: 1 / -1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type="search"] { width: 260px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--muted); }
.tab:hover { background: none; color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* Cards and grids */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 14px; }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid.two { grid-template-columns: 1fr 1fr; }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; }
.tile .sub { color: var(--muted); font-size: 12px; }
.stack > * + * { margin-top: 14px; }

.bar-row { display: grid; grid-template-columns: 130px 1fr 56px; gap: 10px; align-items: center; padding: 4px 0; font-size: 13px; }
.bar { height: 10px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; min-width: 2px; }
.bar.good > span { background: var(--good); }

/* Badges */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.HOT { background: var(--hot-bg); color: var(--hot); }
.badge.WARM { background: var(--warm-bg); color: var(--warm); }
.badge.COLD { background: var(--cold-bg); color: var(--cold); }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.stage { background: var(--panel-2); color: var(--text); font-weight: 500; }

/* Tables */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel); position: sticky; top: 0; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: 0; }
td .sub { color: var(--muted); font-size: 12px; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; padding: 12px 0; color: var(--muted); }
.overdue { color: var(--bad); font-weight: 600; }
.due-today { color: var(--warm); font-weight: 600; }

/* Board */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: 260px; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.column { background: var(--panel-2); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.column.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }
.column-head { display: flex; justify-content: space-between; font-weight: 600; font-size: 13px; padding: 2px 4px 10px; }
.lead-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; cursor: grab; box-shadow: 0 1px 1px rgba(0,0,0,.03); }
.lead-card:active { cursor: grabbing; }
.lead-card .name { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.lead-card .meta { color: var(--muted); font-size: 12px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.more { color: var(--muted); font-size: 12px; text-align: center; padding: 6px; }

/* Lists */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; cursor: pointer; }
.list-item .title:hover { color: var(--accent); }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* Outreach */
.steps { display: flex; gap: 8px; flex-wrap: wrap; }
.step-chip { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; min-width: 130px; }
.step-chip .n { font-size: 20px; font-weight: 650; }
.step-chip .due { font-size: 12px; color: var(--warm); font-weight: 600; }
.progress-dots { display: flex; gap: 4px; align-items: center; }
.progress-dots span { width: 18px; height: 5px; border-radius: 3px; background: var(--line); }
.progress-dots span.done { background: var(--good); }
.progress-dots span.current { background: var(--accent); }
.template { white-space: pre-wrap; font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel-2); border-radius: 8px; padding: 12px; margin: 0; overflow-x: auto; }
.playbook { display: grid; grid-template-columns: 240px 1fr; gap: 14px; align-items: start; }
.playbook-list .side-link { font-size: 13px; }
.kind { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

/* Drawer */
.drawer {
  position: fixed; inset: 0 0 0 auto; width: min(620px, 100vw); background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: var(--shadow); overflow-y: auto; z-index: 20; padding: 20px 22px 60px;
}
.drawer-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; }
.drawer-head h1 { font-size: 19px; flex: 1; }
.section { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.outreach-box { background: var(--panel-2); border-radius: var(--radius); padding: 14px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 9px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 72px 1fr auto; gap: 10px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .type { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); padding-top: 2px; }
.timeline .text { white-space: pre-wrap; }
.timeline .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 19; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(360px, 100%); padding: 28px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.error { color: var(--bad); font-size: 13px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 40; font-size: 13px;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .menu-btn { display: inline-flex; }
  .main { padding: 14px 16px 60px; }
  .grid.two, .playbook { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .filters input[type="search"] { width: 100%; }
  .bar-row { grid-template-columns: 100px 1fr 44px; }
  .drawer { padding: 16px 16px 60px; }
  .hide-sm { display: none; }
}
