:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #1b1f24;
  --muted: #5e6671;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #eceef2;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eef0ff;
  --good: #16794c;
  --good-soft: #e3f5ec;
  --warn: #9a5b00;
  --warn-soft: #fff3dc;
  --bad: #b42318;
  --bad-soft: #fde9e7;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 8px 24px rgb(16 24 40 / 8%);
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1d222b;
    --border: #2a303b;
    --text: #e6e9ee;
    --muted: #9aa3af;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #232933;
    --accent: #8b8cff;
    --accent-text: #0b1020;
    --accent-soft: #1d2242;
    --good: #4ccf8e;
    --good-soft: #13291f;
    --warn: #f0b44c;
    --warn-soft: #2c2413;
    --bad: #ff7b6e;
    --bad-soft: #321a18;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 35%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 1.25rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.25rem;
  padding: .6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; }
.nav { display: flex; gap: .25rem; overflow-x: auto; }
.nav a {
  padding: .35rem .75rem; border-radius: 999px; color: var(--muted); white-space: nowrap; font-weight: 500;
}
.nav a:hover { text-decoration: none; background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

.setup-banner {
  margin: 1rem auto 0; max-width: 1200px; padding: .75rem 1rem;
  border: 1px solid var(--warn); background: var(--warn-soft); color: var(--text);
  border-radius: var(--radius);
}
.setup-banner ul { margin: .25rem 0 0; padding-left: 1.2rem; }

.main { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }

/* ---------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: .3rem .6rem; font-size: .85rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: .25rem; }

/* Plan tab: a column per step, lines from each blocker to what it holds up. */
.plan-board { position: relative; display: flex; gap: 2.25rem; overflow-x: auto; padding: .5rem .25rem 1rem; align-items: flex-start; }
.plan-lines { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; z-index: 0; }
.plan-line { fill: none; stroke: var(--muted); stroke-opacity: .45; stroke-width: 1.5; }
.plan-line.critical { stroke: var(--accent); stroke-opacity: .9; stroke-width: 2.25; }
.plan-board.focus .plan-line { stroke-opacity: .12; }
.plan-board.focus .plan-line.near { stroke-opacity: 1; stroke-width: 2.5; }
.plan-col { position: relative; z-index: 1; display: flex; flex-direction: column; gap: .6rem; min-width: 13rem; max-width: 15rem; flex: 0 0 auto; }
.plan-col.done { opacity: .7; }
.plan-col-head { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.plan-card { border: 1px solid var(--border); border-left-width: 4px; border-radius: 10px; padding: .55rem .65rem; background: var(--surface); cursor: pointer; }
.plan-card.ready { border-left-color: var(--good); }
.plan-card.blocked { border-left-color: var(--warn); }
.plan-card.done { border-left-color: var(--border); }
.plan-card.critical { box-shadow: 0 0 0 2px var(--accent); }
.plan-card.outside { border-style: dashed; }
.plan-board.focus .plan-card { opacity: .35; }
.plan-board.focus .plan-card.near { opacity: 1; }
.plan-card-title { font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field-inline { display: flex; flex-direction: column; gap: .25rem; flex: 1 1 14rem; }
.card.warn { border-color: var(--warn); }

input, textarea, select {
  width: 100%; padding: .5rem .65rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; min-height: 6rem; line-height: 1.5; }
input:focus, textarea:focus, select:focus, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
label { display: block; font-size: .85rem; font-weight: 550; margin-bottom: .25rem; }
.field { margin-bottom: .85rem; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.checkbox input { width: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem 1rem; margin-bottom: .85rem; }

/* Client setup: which playbooks templates a client gets */
.setup-warnings { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .4rem; }
.setup-warnings li { font-size: .9rem; }
.setup-group h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 1rem 0 .3rem; }
.setup-table { width: 100%; border-collapse: collapse; margin-bottom: .5rem; }
.setup-table th { text-align: left; font-size: .75rem; color: var(--muted); font-weight: 600; padding: .3rem .4rem; }
.setup-table td { padding: .4rem; border-top: 1px solid var(--border); vertical-align: top; }
.setup-table td:first-child { width: 38%; }
.setup-table td:nth-child(3) { min-width: 9rem; }
.setup-table .sub { font-size: .8rem; color: var(--muted); }
.setup-table select, .setup-table input { width: 100%; }
.invoice-lines td:first-child { width: auto; }
.invoice-lines td:nth-child(2), .invoice-lines td:nth-child(3) { width: 7rem; min-width: 0; }
.invoice-lines td:last-child { width: 2.5rem; }
.invoice-row { flex-direction: column; align-items: flex-start; gap: .4rem; }
.invoice-new { margin-top: 1rem; }

/* ---------------------------------------------------------------- cards and stats */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem;
}
.card + .card { margin-top: 1rem; }
.card.warn { border-left: 4px solid var(--bad); } /* a workspace asking for owner access */
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }

.stages { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stage {
  display: flex; flex-direction: column; align-items: flex-start; min-width: 7.5rem;
  padding: .6rem .8rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer; font: inherit; text-align: left;
}
.stage:hover { border-color: var(--accent); }
.stage.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.stage .count { font-size: 1.4rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stage .label { font-size: .8rem; color: var(--muted); font-weight: 550; }

/* ---------------------------------------------------------------- lead list */
.leads { width: 100%; border-collapse: collapse; }
.leads th {
  text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: .5rem .75rem; border-bottom: 1px solid var(--border);
}
.leads td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.leads tbody tr { cursor: pointer; }
.leads tbody tr:hover { background: var(--surface-2); }
.leads .name { font-weight: 600; }
.leads .sub { font-size: .82rem; color: var(--muted); }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }

.pill {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.score { display: inline-flex; align-items: center; gap: .4rem; font-variant-numeric: tabular-nums; font-weight: 600; }
.score-bar { width: 3.5rem; height: .4rem; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.score-bar > span { display: block; height: 100%; background: var(--bad); }
.score-bar.mid > span { background: var(--warn); }
.score-bar.low > span { background: var(--good); }

/* ---------------------------------------------------------------- drawer */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 35%); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
  width: min(760px, 100%); background: var(--bg); border-left: 1px solid var(--border);
  box-shadow: var(--shadow); overflow-y: auto;
}
.drawer-inner { padding: 1.25rem; }
.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  position: sticky; top: -1.25rem; margin: -1.25rem -1.25rem 1rem; padding: 1.25rem;
  background: var(--bg); border-bottom: 1px solid var(--border); z-index: 1;
}
.facts { display: grid; grid-template-columns: 7rem 1fr; gap: .35rem 1rem; margin: 0; }
.facts dt { color: var(--muted); font-size: .85rem; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.message { white-space: pre-wrap; margin: 0; overflow-wrap: anywhere; }
.issues { margin: .25rem 0 0; padding-left: 1.2rem; }
.issues li { margin: .2rem 0; }
.speed { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }
.footer-preview {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: .85rem; color: var(--muted); background: var(--surface-2);
  border-radius: 8px; padding: .65rem .75rem; margin: .25rem 0 .85rem;
}
.chip-action { border-color: var(--accent); color: var(--accent); }
.tech-findings li::marker { color: var(--warn); }
.tech-ok { color: var(--good); }
.tech-bad { color: var(--bad); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: .75rem; padding: .35rem 0; border-bottom: 1px dashed var(--border); font-size: .88rem; }
.timeline time { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 8.5rem; }

.quote-lines { width: 100%; border-collapse: collapse; margin-bottom: .5rem; }
.quote-lines td { padding: .25rem .25rem .25rem 0; vertical-align: middle; }
.quote-lines td:first-child { width: 55%; }
.quote-lines input { padding: .35rem .5rem; }
.quote-total { text-align: right; font-variant-numeric: tabular-nums; margin: .5rem 0 .85rem; }
.package-row { display: grid; grid-template-columns: 1.3fr .6fr .6fr 2fr auto; gap: .5rem; margin-bottom: .5rem; align-items: start; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 0; }
.chip {
  padding: .25rem .65rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font: inherit; font-size: .83rem; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--accent); }

.search-form { display: grid; grid-template-columns: 1fr 8rem auto; gap: .5rem; align-items: end; }
.setup-list { list-style: none; padding: 0; margin: 0; }
.setup-list li { display: flex; gap: .6rem; align-items: baseline; padding: .4rem 0; }
code { font-family: var(--mono); font-size: .82rem; background: var(--surface-2); padding: .1rem .35rem; border-radius: 4px; overflow-wrap: anywhere; }

.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; box-shadow: var(--shadow);
  max-width: calc(100% - 2rem);
}
.toast.error { background: var(--bad); color: #fff; }

/* ---------------------------------------------------------------- AI */
.drawer-actions { display: flex; align-items: center; gap: .35rem; flex: none; }
.ai-drawer { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.card-head-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.shots { display: grid; grid-template-columns: 3fr 1fr; gap: .75rem; align-items: start; margin: .75rem 0; }
.shot { display: block; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2); color: var(--muted); text-decoration: none; }
.shot img { display: block; width: 100%; height: auto; max-height: 260px; object-fit: cover; object-position: top; }
.shot span { display: block; font-size: .75rem; font-weight: 600; padding: .25rem .5rem; }
.shot:hover { border-color: var(--accent); text-decoration: none; }
.pitch { background: var(--accent-soft); border-radius: 8px; padding: .6rem .75rem; }
details summary { cursor: pointer; font-weight: 600; margin: .5rem 0; }
.suggestion { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 10px; padding: .75rem .9rem; margin-bottom: .85rem; }
.suggestion .footer-preview { background: var(--surface); color: var(--text); margin: .5rem 0; }
.duplicates { margin: .5rem 0; padding-left: 1.1rem; }
.duplicates li + li { margin-top: .35rem; }
.ai-row { display: flex; gap: .5rem; margin-bottom: .6rem; }
.ai-row input { flex: 1; }
/* Names the AI feature a button runs or a result came from. */
.ai-tag { display: inline-flex; align-items: center; align-self: center; flex: none; white-space: nowrap; font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.ai-note { margin: 0 0 .6rem; }
.ai-note p { margin: 0 0 .35rem; }
.ai-note ul { margin: 0; padding-left: 1rem; list-style: none; }
@media (max-width: 640px) { .ai-row { flex-wrap: wrap; } .ai-row input { flex-basis: 100%; } .ai-row .ai-tag { align-self: flex-start; } }
.ai-toggle {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 35;
  padding: .75rem 1.15rem; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 650; box-shadow: var(--shadow);
}
.ai-top { display: none; }
body.ai-open .ai-toggle { display: none; }
.ai-panel {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 36;
  width: min(440px, calc(100% - 2.5rem)); height: min(640px, calc(100vh - 6rem));
  display: flex; flex-direction: column; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden;
}
.ai-head { display: flex; align-items: center; gap: .35rem; padding: .7rem .8rem .7rem 1rem; border-bottom: 1px solid var(--border); }
.ai-title { display: flex; flex-direction: column; margin-right: auto; line-height: 1.25; min-width: 0; }
.ai-title .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-thread { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .7rem; overscroll-behavior: contain; }
.ai-msg { max-width: 88%; padding: .65rem .85rem; border-radius: 16px; background: var(--surface-2); }
.ai-msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.ai-msg.assistant { align-self: flex-start; border-bottom-left-radius: 6px; }
.ai-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .94rem; line-height: 1.5; }
.ai-copy { margin-top: .35rem; padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: .78rem; font-weight: 600; cursor: pointer; }
.ai-copy:hover { color: var(--accent); }
.ai-empty { margin: auto 0; }
.ai-empty .chips { margin-top: .6rem; }
.ai-history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.ai-history button {
  width: 100%; text-align: left; display: flex; flex-direction: column; gap: .15rem; cursor: pointer;
  padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); font: inherit;
}
.ai-history button:hover { border-color: var(--accent); }
.ai-history-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-typing { display: flex; align-items: center; gap: .55rem; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .6; } }
.ai-form { display: flex; align-items: flex-end; gap: .5rem; padding: .7rem .8rem; border-top: 1px solid var(--border); background: var(--surface); }
.ai-form textarea { flex: 1; min-height: 2.6rem; max-height: 160px; resize: none; border-radius: 20px; padding: .6rem .9rem; line-height: 1.35; }
.ai-send { width: 2.6rem; height: 2.6rem; padding: 0; border-radius: 50%; font-size: 1.15rem; flex: none; }

/* ---------------------------------------------------------------- costs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius, 12px); padding: 1rem 1.1rem; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.6rem; font-weight: 650; margin: .15rem 0; letter-spacing: -.01em; }
.notes ul { margin: 0; padding-left: 1.1rem; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar.s1, .swatch.s1 { fill: var(--series-1); background: var(--series-1); }
.chart .bar.s2, .swatch.s2 { fill: var(--series-2); background: var(--series-2); }
.chart .hit { fill: transparent; outline: none; cursor: default; }
.chart .col:hover .bar, .chart .col:focus-within .bar { filter: brightness(1.12); }
.chart .hit:focus-visible { stroke: var(--accent); stroke-width: 1; }
.chart-tip {
  position: absolute; top: 0; transform: translateX(-50%); pointer-events: none; z-index: 2;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  padding: .5rem .65rem; font-size: .82rem; min-width: 9rem;
}
.tip-date { color: var(--muted); margin-bottom: .2rem; }
.tip-row { display: flex; align-items: center; gap: .45rem; font-variant-numeric: tabular-nums; }
.tip-row .key { width: 12px; height: 2px; border-radius: 1px; background: transparent; flex: none; }
.tip-row .key.s1 { background: var(--series-1); }
.tip-row .key.s2 { background: var(--series-2); }
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--muted); margin: .25rem 0 .5rem; }
.legend > span { display: inline-flex; align-items: center; gap: .4rem; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-table { margin-top: .5rem; font-size: .85rem; }
.chart-table table, .amounts { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.chart-table th, .chart-table td, .amounts td { text-align: left; padding: .3rem .25rem; border-bottom: 1px solid var(--border); }
.chart-table td:not(:first-child), .chart-table th:not(:first-child), .amounts td:last-child { text-align: right; }
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.rank li { display: grid; grid-template-columns: minmax(7rem, 11rem) 1fr auto; align-items: center; gap: .6rem; font-size: .9rem; }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-track { height: 10px; }
.rank-bar { display: block; height: 10px; background: var(--series-1); border-radius: 0 4px 4px 0; }
.rank-value { font-variant-numeric: tabular-nums; }
.subs { display: grid; gap: .5rem; margin-bottom: .6rem; }
.sub-row { display: grid; grid-template-columns: 1fr 7rem 5rem 7.5rem auto; gap: .5rem; align-items: center; }
.steps li { margin: .35rem 0; }
.costs-grid { margin: 1rem 0; align-items: start; gap: 1rem; }
.meter-head { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; flex-wrap: wrap; margin-bottom: .45rem; }
.meter { height: 10px; border-radius: 999px; background: color-mix(in srgb, var(--series-1) 18%, var(--surface)); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--series-1); }
.meter.warn { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); }
.meter.warn > span { background: var(--warn); }
.meter.bad { background: color-mix(in srgb, var(--bad) 18%, var(--surface)); }
.meter.bad > span { background: var(--bad); }
.meter-state { margin: .45rem 0 .25rem; font-weight: 600; }
.meter-state.ok { color: var(--good); }
.meter-state.warn { color: var(--warn); }
.meter-state.bad { color: var(--bad); }
.costs-grid > .card { margin: 0; }

/* ---------------------------------------------------------------- small screens */
@media (max-width: 760px) {
  /* Ask AI becomes a full-screen sheet, opened from the top bar */
  .ai-toggle { display: none; }
  .ai-top { display: inline-flex; background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
  .ai-panel { inset: 0; width: 100%; height: 100dvh; border: 0; border-radius: 0; box-shadow: none; z-index: 50; }
  .ai-head { padding-top: calc(.7rem + env(safe-area-inset-top)); }
  .ai-form { padding-bottom: calc(.7rem + env(safe-area-inset-bottom)); }
  .ai-form textarea { font-size: 16px; } /* 16px stops iPhones zooming in when you tap the box */
  .ai-msg { max-width: 92%; }
  body.ai-open { overflow: hidden; }
  .ai-row { flex-direction: column; }
  .topbar { flex-wrap: wrap; gap: .5rem; padding: .6rem 1rem; }
  .nav { order: 3; width: 100%; }
  .main { padding: 1rem; }
  .grid-2, .grid-3, .search-form { grid-template-columns: 1fr; }
  .setup-table thead { display: none; }
  .setup-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem .5rem; padding: .5rem 0; border-top: 1px solid var(--border); }
  .setup-table td { border: 0; padding: 0; width: auto !important; min-width: 0 !important; }
  .setup-table td:first-child, .setup-table td:last-child { grid-column: 1 / -1; }
  .package-row { grid-template-columns: 1fr 1fr; }
  .package-row textarea { grid-column: 1 / -1; }
  .leads thead { display: none; }
  .leads tr { display: block; padding: .6rem 0; border-bottom: 1px solid var(--border); }
  .leads td { display: block; border: 0; padding: .1rem .5rem; }
  .drawer-inner { padding: 1rem; }
  .drawer-head { top: -1rem; margin: -1rem -1rem .85rem; padding: .75rem 1rem; gap: .6rem; }
  /* Long business names would fill a quarter of the screen: two lines, smaller */
  .drawer-head h1 {
    font-size: 1.1rem; margin-bottom: .35rem;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .facts { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .sub-row { grid-template-columns: 1fr 4.5rem 6.5rem auto; }
  .sub-row input[type=text] { grid-column: 1 / -1; }
  .rank li { grid-template-columns: 6.5rem 1fr auto; }
  .facts dt { margin-top: .4rem; }
  .timeline li { flex-direction: column; gap: 0; }
}

/* ---------------------------------------------------------------- printable quote */
.print-only { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; color: #000; font: 11pt/1.5 var(--font); padding: 0 1cm; }
  #print-area table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
  #print-area th, #print-area td { text-align: left; padding: .35rem .25rem; border-bottom: 1px solid #ccc; }
  #print-area .num { text-align: right; }
  #print-area .quote-head { display: flex; justify-content: space-between; margin-bottom: 1.5rem; }
}

/* ---------------------------------------------------------------- client page (full screen) */
.main.wide { max-width: 1600px; }
.list-tools { display: flex; justify-content: flex-end; margin-bottom: .75rem; }
.list-tools input { max-width: 20rem; }
.client-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.client-title h1 { font-size: 1.6rem; margin: .2rem 0 .35rem; }
.client-kpis { grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); }
.client-kpis .stat-value { font-size: 1.35rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat.warn { border-color: var(--warn); }
.stat.warn .stat-value { color: var(--warn); }
.stat.bad { border-color: var(--bad); }
.stat.bad .stat-value { color: var(--bad); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a {
  position: relative; padding: .55rem .9rem; color: var(--muted); font-weight: 550; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); margin-left: .35rem; vertical-align: middle; }
.client-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.client-grid .col { display: grid; gap: 1rem; min-width: 0; }
.client-grid .card + .card, .project-grid .card + .card { margin-top: 0; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 32rem), 1fr)); gap: 1rem; align-items: start; }
.project-row { padding: .6rem 0; border-top: 1px solid var(--border); }
.project-row:first-of-type { border-top: 0; }
.project-grid > details.card { grid-column: 1 / -1; }
.project-summary { margin: .4rem 0; overflow-wrap: anywhere; }
.project-scope { margin: .2rem 0 .6rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.project-update { margin: .5rem 0; padding: .5rem .75rem; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; display: grid; gap: .15rem; overflow-wrap: anywhere; }
.project-details h3 { margin: .8rem 0 .2rem; }
.card-head-row .btn-row h2 { margin: 0; }
.project-status-form input[type=text] { flex: 1; min-width: 12rem; }
.project-history ul { margin: .25rem 0 .5rem; padding-left: 1.1rem; }
.project-links { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .2rem .75rem; margin: .6rem 0; }
.project-links dd { margin: 0; overflow-wrap: anywhere; }
.timeline li.spread { justify-content: space-between; align-items: center; }
.tone-accent { color: var(--accent); }
.tone-good { color: var(--good); }

.stepper { list-style: none; display: flex; margin: .6rem 0 1rem; padding: 0; counter-reset: step; }
.stepper li { flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; gap: .3rem; min-width: 0; }
.stepper li::before {
  content: ""; position: absolute; top: 6px; right: 50%; width: 100%; height: 2px; background: var(--border);
}
.stepper li:first-child::before { display: none; }
.stepper li.done::before, .stepper li.current::before { background: var(--accent); }
.stepper .dot { position: relative; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border); }
.stepper li.done .dot { background: var(--accent); border-color: var(--accent); }
.stepper li.current .dot { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); background: var(--surface); }
.step-label { font-size: .75rem; color: var(--muted); line-height: 1.2; }
.stepper li.current .step-label { color: var(--accent); font-weight: 650; }
.step-due { font-size: .7rem; color: var(--muted); }
.stepper li.overdue .dot { border-color: var(--bad); }
.stepper li.overdue .step-due { color: var(--bad); font-weight: 650; }

/* A project's own stages and fields, edited in its form. */
.stage-editor { list-style: none; margin: .25rem 0 .5rem; padding: 0; display: grid; gap: .4rem; counter-reset: stage; }
.stage-editor li { display: grid; grid-template-columns: minmax(8rem, 1fr) auto auto auto; gap: .4rem; align-items: center; }
.fields-editor { display: grid; gap: .4rem; margin: .25rem 0 .5rem; }
.field-row { display: grid; grid-template-columns: minmax(6rem, 12rem) minmax(8rem, 1fr) auto auto; gap: .4rem; align-items: center; }
.project-tasks { margin: .25rem 0 .5rem; padding-left: 1.1rem; }
.project-tasks li { margin: .15rem 0; }
.project-tasks .pill { margin-left: .4rem; }

.convo { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.convo-scroll { max-height: 55vh; overflow-y: auto; margin-bottom: .85rem; padding-right: .25rem; }
.bubble { max-width: 80%; padding: .55rem .8rem; border-radius: 14px; background: var(--surface-2); font-size: .92rem; }
.bubble.client { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.you { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.bubble.update { align-self: center; max-width: 90%; background: transparent; border: 1px dashed var(--border); color: var(--muted); }
.bubble-meta { font-size: .75rem; font-weight: 600; color: var(--muted); margin-bottom: .15rem; }

@media (max-width: 1000px) {
  .client-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .client-title h1 { font-size: 1.2rem; }
  .list-tools input { max-width: none; }
  .stepper .step-label { display: none; }
  .stepper li.current .step-label { display: block; position: absolute; top: 1.3rem; white-space: nowrap; }
  .stepper { margin-bottom: 1.8rem; }
  .stepper .step-due { display: none; }
  .stage-editor li, .field-row { grid-template-columns: 1fr 1fr; }
  .bubble { max-width: 92%; }
  .client-kpis { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .client-kpis .stat { padding: .75rem .85rem; }
  .timeline li.spread { flex-direction: row; align-items: flex-start; gap: .5rem; }
}

/* A new quote for a client sits in a narrow column: stack its lines whenever the editor is narrow. */
.quote-new { container-type: inline-size; }
.quote-new .invoice-lines td:nth-child(4) { width: 7rem; }
@container (max-width: 600px) {
  .quote-new .setup-table thead { display: none; }
  .quote-new .setup-table tr { display: grid; grid-template-columns: 1fr 1fr 1fr 2rem; gap: .3rem .5rem; padding: .5rem 0; border-top: 1px solid var(--border); }
  .quote-new .setup-table td { border: 0; padding: 0; width: auto !important; min-width: 0 !important; }
  .quote-new .setup-table td:first-child { grid-column: 1 / -1; }
}

/* ---------------------------------------------------------------- website previews */
.project-grid > .card.has-preview { grid-column: 1 / -1; }
.preview-section { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: .75rem; }
.preview-section h3 { margin: 0; }
.preview-upload input[type="file"] { flex: 1; min-width: 0; }
.seg { display: inline-flex; gap: .25rem; flex-wrap: wrap; }
.seg .btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.preview-box { margin: .75rem 0; padding: .5rem; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.preview-frame { display: block; margin: 0 auto; width: 100%; height: min(75vh, 900px); border: 0; border-radius: 6px; background: #fff; }
.preview-box.tablet .preview-frame { max-width: 820px; }
.preview-box.phone .preview-frame { max-width: 390px; height: min(75vh, 780px); }

/* ---------------------------------------------------------------- website drafts */
.site-draft { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: .75rem; }
.site-draft h3 { margin: 0; }
.prompt-warnings { border: 1px solid var(--warn); background: var(--warn-soft); border-radius: 8px; padding: .6rem .8rem; margin: .5rem 0; font-size: .9rem; }
.prompt-warnings ul { margin: .3rem 0 0; padding-left: 1.1rem; }
.prompt-sections { display: grid; gap: .5rem; margin: .5rem 0; }
.prompt-section { border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem; }
.prompt-section.untrusted { border-color: var(--warn); }
.prompt-section pre, .prompt-system { white-space: pre-wrap; overflow-wrap: anywhere; margin: .35rem 0 0; font-size: .82rem; max-height: 14rem; overflow: auto; }
.prompt-text { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }

/* ---------------------------------------------------------------- files for the website */
.assets { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: .75rem; }
.assets h3 { margin: 0 0 .5rem; }
.asset-grid { list-style: none; padding: 0; margin: 0 0 .5rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: .6rem; }
.asset { border: 1px solid var(--border); border-radius: 8px; padding: .4rem; min-width: 0; overflow-wrap: anywhere; }
.asset img, .asset-doc { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; background: var(--surface-2); margin-bottom: .3rem; }
.asset-doc { display: grid; place-items: center; font-weight: 700; color: var(--muted); text-decoration: none; }
.assets .btn-row input[type="text"] { flex: 1; min-width: 12rem; }
.assets .btn-row input[type="file"] { min-width: 0; max-width: 100%; }

/* Live figures on quotes (quote_costs.py) */
.live-figures { display: grid; gap: 0.2rem; margin-top: 0.35rem; }
.live-figures details summary { cursor: pointer; }
.live-figures ul { margin: 0.25rem 0 0 1rem; padding: 0; }
.live-figures .bad { color: var(--bad); }
.live-costs:not(:empty) { margin: 0.5rem 0; padding: 0.5rem 0.75rem; border-radius: 8px; background: var(--accent-soft); }

/* ---------------------------------------------------------------- client hub: tasks, systems, running costs */
.tab-count { color: var(--muted); font-weight: 500; }
.tasks { list-style: none; margin: 0; padding: 0; }
.tasks > li { display: flex; align-items: flex-start; gap: .7rem; padding: .6rem 0; border-top: 1px solid var(--border); }
.tasks > li:first-child { border-top: 0; }
.tasks > li > input[type=checkbox] { width: 1.1rem; height: 1.1rem; margin-top: .15rem; flex: none; }
.tasks > li.editing { display: block; }
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 550; overflow-wrap: anywhere; }
.task.done .task-title { color: var(--muted); text-decoration: line-through; }
.task-meta { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .25rem; align-items: center; }
.task-notes { margin-top: .25rem; white-space: pre-wrap; }
.task-form { display: grid; gap: .5rem; }
.task-form-row { display: grid; grid-template-columns: minmax(0, 1fr) 9rem 8rem; gap: .5rem; align-items: center; }
.task-form-row + .task-form-row { grid-template-columns: minmax(0, 1fr) 10rem 8rem auto; }
.tasks-grid, .systems-grid { gap: 1rem; align-items: start; }
.tasks-grid > .card, .systems-grid > .card { margin: 0; }
.running .amounts { margin: .6rem 0; }
.running h3 { margin: 1rem 0 .2rem; font-size: 1rem; }
.amounts.planned th { text-align: left; font-weight: 550; color: var(--muted); font-size: .85rem; }
.amounts.planned tr.over td:first-child { color: var(--bad); }
.running-edit { margin-top: .75rem; }
.running-row { grid-template-columns: 1fr 6rem 5rem 7.5rem auto auto; }
@media (max-width: 760px) {
  .task-form-row, .task-form-row + .task-form-row { grid-template-columns: 1fr 1fr; }
  .task-form-row > input[type=text] { grid-column: 1 / -1; }
  .running-row { grid-template-columns: 1fr 4.5rem 6.5rem auto; }
  .running-row input[type=text] { grid-column: 1 / -1; }
}

/* Client hub polish */
.kpis.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.card-head-row.wrap { flex-wrap: wrap; gap: .1rem 1rem; }
.tasks > li.editing { padding: .75rem; margin: .35rem 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.systems-grid + details.card { margin-top: 1rem; }
.billing-setup { margin: .5rem 0 .85rem; }
.billing-setup .steps { margin: .5rem 0; padding-left: 1.2rem; display: grid; gap: .25rem; }
.billing-setup .policy { margin-top: .6rem; }
.billing-setup .policy .spread { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.billing-setup pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: .35rem 0 0; padding: .6rem .7rem; font-size: .8rem; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
@media (max-width: 1000px) {
  /* One column: running costs, then what's waiting, then the rest. */
  .client-grid .col { display: contents; }
  .client-grid > .col > * { order: 3; }
  .client-grid > .col > .running { order: 1; }
  .client-grid > .col > .waiting { order: 2; }
}
@media (max-width: 760px) {
  .kpis.five { grid-template-columns: 1fr 1fr; }
}
.amounts.planned td:not(:first-child), .amounts.planned th:not(:first-child) { white-space: nowrap; }
@media (max-width: 760px) {
  /* A fixed cost on a phone: name; amount, currency, period; then "estimate" and remove. */
  .running-row { grid-template-columns: minmax(0, 1fr) 5.5rem minmax(0, 1fr); }
  .running-row > label.checkbox { grid-column: 1 / 3; }
  .running-row > button { justify-self: end; }
}
/* Editing a task or system inside a half-width column: title on its own line, the rest in pairs. */
.tasks > li.editing .task-form-row, .tasks > li.editing .task-form-row + .task-form-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.tasks > li.editing .task-form-row > input[type=text] { grid-column: 1 / -1; }
.tasks-grid { margin-top: 1rem; }
.tasks-grid + details.card { margin-top: 1rem; }

/* Service agreements */
.agreement-form label { display: grid; gap: .25rem; font-size: .85rem; align-content: start; }
.agreement-form .hint { font-size: .78rem; color: var(--muted); }
.agreement-form textarea.mono { min-height: 16rem; }
.agreement.ended { opacity: .75; }
.agreement-read summary { cursor: pointer; }
.agreement-text { max-height: 28rem; overflow: auto; margin-top: .5rem; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: 8px; line-height: 1.55; }
.agreement-text h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.agreement-text h4 { font-size: .92rem; margin: .8rem 0 .3rem; }
.agreement-text h3:first-child, .agreement-text h4:first-child { margin-top: 0; }
.agreement-text p, .agreement-text ul { margin: 0 0 .6rem; }

/* Agent suggestions on an agreement, and a task's links */
.agreement-suggestions { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }
.agreement-suggestions .suggestion { padding: 8px 0; }
.agreement-suggestions .suggestion + .suggestion { border-top: 1px dashed var(--border); }
.task-links a { word-break: break-all; }
/* SDLC (app.js: clientDelivery, renderSdlc) */
.sdlc-scope details { border-top: 1px solid var(--border); padding: .2rem 0; }
.sdlc-scope details:first-child { border-top: 0; }
.sdlc-scope .tasks { margin-bottom: .5rem; }
.sdlc-table { overflow-x: auto; }
.sdlc-table td.num { text-align: right; white-space: nowrap; }
.warn-text { color: var(--warn); }
.h2-like { font-size: 1.1rem; font-weight: 650; }
