/* Tokens from DESIGN.md (Linear analysis via getdesign.md) */
[hidden] { display: none !important; }
:root {
  color-scheme: dark;
  --primary: #5e6ad2;
  --primary-hover: #828fff;
  --primary-focus: #5e69d1;
  --ink: #f7f8f8;
  --ink-muted: #d0d6e0;
  --ink-subtle: #8a8f98;
  --ink-tertiary: #62666d;
  --canvas: #010102;
  --s1: #0f1011;
  --s2: #141516;
  --s3: #18191a;
  --s4: #191a1b;
  --line: #23252a;
  --line-strong: #34343a;
  --line-3: #3e3e44;
  --success: #27a644;

  --r-xs: 4px; --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-xl: 16px; --pill: 9999px;
  --font: "Inter", -apple-system, "SF Pro Display", system-ui, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--canvas);
  color: var(--ink);
  font: 400 14px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01", "tnum";
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid color-mix(in srgb, var(--primary-focus) 50%, transparent); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--primary) 45%, transparent); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100%; }
.side {
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; font-weight: 600; letter-spacing: -0.2px; }
.brand img { width: 22px; height: 22px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: var(--r-sm);
  color: var(--ink-subtle); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--s2); color: var(--ink-muted); }
.nav a[aria-current="page"] { background: var(--s3); color: var(--ink); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav svg { width: 16px; height: 16px; flex: none; opacity: .85; }
.nav a[aria-current="page"] svg { opacity: 1; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--ink-tertiary); }
.side-foot { margin-top: auto; padding: 8px 10px; }
.side-foot button { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; color: var(--ink-subtle); cursor: pointer; font-size: 13px; }
.side-foot svg { width: 15px; height: 15px; }
.side-foot button:hover { color: var(--ink); }

main { overflow: auto; min-width: 0; }
.view { padding: 28px 32px 64px; max-width: 1280px; margin: 0 auto; }
.view[hidden] { display: none; }
.head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.head h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.6px; line-height: 1.2; margin: 0; }
.head p { margin: 4px 0 0; color: var(--ink-subtle); }
.head .actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; min-height: 36px;
  border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--s1); color: var(--ink);
  font-weight: 500; font-size: 14px; line-height: 1.2; cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--s2); border-color: var(--line-strong); }
.btn.primary { background: var(--primary); border-color: transparent; color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.primary:active { background: var(--primary-focus); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-subtle); }
.btn.ghost:hover { color: var(--ink); background: var(--s2); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn svg { width: 14px; height: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 500; color: var(--ink-muted); }
.field .hint { font-size: 12px; color: var(--ink-tertiary); }
.input, select.input, textarea.input {
  width: 100%; min-height: 36px;
  padding: 8px 12px; border-radius: var(--r-md);
  background: var(--s1); border: 1px solid var(--line); color: var(--ink);
}
.input::placeholder { color: var(--ink-tertiary); }
.input:hover { border-color: var(--line-strong); }
.input:focus { outline: 2px solid color-mix(in srgb, var(--primary-focus) 50%, transparent); outline-offset: 0; border-color: var(--line-strong); }
textarea.input { resize: vertical; line-height: 1.5; }
select.input { appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a8f98' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }

.tabs { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: var(--pill); background: var(--canvas); }
.tabs button {
  border: 0; background: transparent; color: var(--ink-subtle);
  padding: 6px 14px; border-radius: var(--pill); font-weight: 500; cursor: pointer; min-height: 32px;
}
.tabs button[aria-selected="true"] { background: var(--s2); color: var(--ink); }
.tabs button:hover:not([aria-selected="true"]) { color: var(--ink-muted); }

.panel { background: var(--s1); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 24px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.03); }
.panel + .panel { margin-top: 16px; }
.panel h2 { font-size: 16px; font-weight: 600; letter-spacing: -0.2px; margin: 0 0 4px; }
.panel > p { margin: 0 0 20px; color: var(--ink-subtle); }

.grid { display: grid; gap: 16px; }
.grid.find { grid-template-columns: 1.3fr 1fr 160px auto; align-items: end; }
.grid.two { grid-template-columns: 1fr 1fr; }

.budget { display: flex; align-items: center; gap: 10px; margin-top: 16px; font-size: 12px; color: var(--ink-subtle); }
.meter { width: 120px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--ink-muted); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: var(--pill);
  background: var(--s2); color: var(--ink-muted); font-size: 12px; line-height: 1.4; white-space: nowrap;
}
.badge.won { color: var(--success); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- signal bars: the one recurring motif ---------- */
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.bars i { width: 3px; border-radius: 1px; background: var(--line-3); }
.bars i:nth-child(1) { height: 5px; } .bars i:nth-child(2) { height: 8px; }
.bars i:nth-child(3) { height: 11px; } .bars i:nth-child(4) { height: 14px; }
.bars i.on { background: var(--ink); }
.bars.hot i.on { background: var(--primary-hover); }
.score { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-variant-numeric: tabular-nums; }
.score.none { color: var(--ink-tertiary); font-weight: 400; }

/* ---------- leads table ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters .input { width: auto; min-width: 140px; }
.filters .search { flex: 1 1 220px; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--r-lg); overflow: auto; background: var(--canvas); }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--ink-subtle);
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--s1);
  position: sticky; top: 0; white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--s1); }
tbody tr[aria-selected="true"] { background: var(--s2); }
tbody tr:last-child td { border-bottom: 0; }
.lead-name { font-weight: 500; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--ink-subtle); font-size: 12px; }
.muted { color: var(--ink-subtle); }
.dim { color: var(--ink-tertiary); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 12px; color: var(--ink-subtle); font-size: 12px; }

.empty { padding: 56px 24px; text-align: center; color: var(--ink-subtle); }
.empty h3 { color: var(--ink); font-size: 16px; font-weight: 600; margin: 0 0 6px; }
.empty .btn { margin-top: 16px; }

.spin { width: 12px; height: 12px; border: 1.5px solid var(--line-3); border-top-color: var(--ink-muted); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%);
  background: var(--s1); border-left: 1px solid var(--line-strong);
  transform: translateX(100%); transition: transform .22s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column; z-index: 20;
}
.drawer.open { transform: none; }
.drawer-top { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.drawer-body { overflow: auto; padding: 24px; display: flex; flex-direction: column; gap: 28px; }
.drawer h2 { font-size: 22px; font-weight: 500; letter-spacing: -0.4px; line-height: 1.25; margin: 0; }
.drawer section h3 { font-size: 13px; font-weight: 500; color: var(--ink-subtle); margin: 0 0 10px; letter-spacing: 0.2px; }
.links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.links a { font-size: 13px; padding: 4px 10px; border: 1px solid var(--line); border-radius: var(--r-sm); text-decoration: none; color: var(--ink-muted); }
.links a:hover { border-color: var(--line-strong); color: var(--ink); }

.status-row { display: flex; flex-wrap: wrap; gap: 4px; }
.status-row button {
  border: 1px solid var(--line); background: var(--canvas); color: var(--ink-subtle);
  padding: 5px 12px; border-radius: var(--pill); font-size: 13px; cursor: pointer; min-height: 32px;
}
.status-row button[aria-pressed="true"] { background: var(--s3); color: var(--ink); border-color: var(--line-strong); }
.status-row button[data-s="won"][aria-pressed="true"] { color: var(--success); }

.issues { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.issues li { display: grid; grid-template-columns: 20px 1fr; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--canvas); }
.issues li:last-child { border-bottom: 0; }
.issues .bars { margin-top: 3px; }
.issues strong { font-weight: 500; display: block; }
.issues .detail { color: var(--ink-subtle); font-size: 13px; }
.issues .pitchline { margin-top: 6px; font-size: 13px; color: var(--ink-muted); border-left: 2px solid var(--line-3); padding-left: 10px; }

.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.facts div { background: var(--canvas); padding: 10px 14px; }
.facts dt { font-size: 12px; color: var(--ink-subtle); }
.facts dd { margin: 2px 0 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 19; }
.scrim.open { opacity: 1; pointer-events: auto; }

/* ---------- map ---------- */
#map { height: calc(100vh - 160px); min-height: 420px; border: 1px solid var(--line); border-radius: var(--r-xl); overflow: hidden; background: var(--s1); }
.maplibregl-popup-content { background: var(--s2) !important; color: var(--ink) !important; border: 1px solid var(--line-strong); border-radius: var(--r-md) !important; padding: 10px 12px !important; font: 13px/1.4 var(--font); }
.maplibregl-popup-tip { display: none; }
.maplibregl-ctrl-attrib { background: rgba(1,1,2,.7) !important; color: var(--ink-tertiary) !important; }
.maplibregl-ctrl-attrib a { color: var(--ink-subtle) !important; }

/* ---------- recent searches ---------- */
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: 0; }
.history .what { font-weight: 500; }
.history .btn { margin-left: auto; }

.status-list { display: grid; gap: 0; }
.status-list div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.status-list div:last-child { border-bottom: 0; }
.ok { color: var(--success); }
code { font-family: var(--mono); font-size: 12px; background: var(--s3); padding: 1px 6px; border-radius: var(--r-xs); color: var(--ink-muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--s3); border: 1px solid var(--line-strong); color: var(--ink);
  padding: 10px 16px; border-radius: var(--r-md); opacity: 0; transition: .2s; z-index: 40; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */
@media (max-width: 1024px) {
  .grid.find { grid-template-columns: 1fr 1fr; }
  .hide-md { display: none; }
}
@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; }
  .brand span, .side-foot { display: none; }
  .nav { flex-direction: row; gap: 2px; }
  .nav .count { display: none; }
  .view { padding: 20px 16px 48px; }
  .grid.find, .grid.two { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .head .actions { margin-left: 0; width: 100%; }
  .drawer-body { padding: 20px 16px; }
  .facts { grid-template-columns: 1fr; }
  #map { height: calc(100vh - 180px); }
  .filters .input { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .filters .search { flex-basis: 100%; }
  td, th { padding: 10px; }
  td:nth-child(2) { white-space: normal; }
  .lead-name { max-width: 46vw; white-space: normal; }
  .head .actions .btn { flex: 1; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

.site-edit { display: flex; gap: 8px; margin-top: 12px; }
.site-edit .input { flex: 1; }
