:root {
  --paper: #f6f3ec;
  --card: #fffdf8;
  --ink: #1c2421;
  --ink-2: #4a5550;
  --muted: #6f7873;
  --line: #e3ddd0;
  --line-2: #d4ccbb;
  --green: #1f3a32;
  --green-2: #2e5a4c;
  --green-soft: #e3eee8;
  --oak: #a86f3c;
  --oak-soft: #f4e7d6;
  --blue: #2c4f7c;
  --blue-soft: #e4ecf6;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --stop: #9b2c22;
  --stop-soft: #fae5e1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 36, 33, .05), 0 2px 8px rgba(28, 36, 33, .04);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--green-2); }
a:hover { color: var(--green); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0 0 .4em; color: var(--ink); }
h1 { font-size: 1.75rem; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
code { font-family: var(--mono); font-size: .85em; background: #f0ebe0; padding: 1px 5px; border-radius: 4px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(46, 90, 76, .15); }
textarea { resize: vertical; }
input[type="checkbox"] { width: auto; accent-color: var(--green-2); }
:focus-visible { outline: 2px solid var(--green-2); outline-offset: 2px; }

.boot, .loading { padding: 48px; color: var(--muted); }

/* ---------- shell ---------- */
.demo-band {
  position: sticky; top: 0; z-index: 30; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 18px;
  background: repeating-linear-gradient(-45deg, #f3c84b, #f3c84b 14px, #f6d36f 14px, #f6d36f 28px); color: #3b2a00; font-size: .9rem;
  border-bottom: 2px solid #c99a12;
}
.demo-band strong { letter-spacing: .06em; }
.demo-band .link-btn { color: #3b2a00; font-weight: 600; }
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 16px; padding: 20px 14px;
  background: var(--green); color: #e9e3d6;
}
.demo-band + .shell .side { top: 37px; height: calc(100vh - 37px); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 6px; color: #f1e3c9; }
.brand-name { font-family: var(--serif); font-size: 1.1rem; font-weight: 600; }
.brand-sub { font-size: .78rem; opacity: .75; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: #e1dccf; text-decoration: none; padding: 8px 10px; border-radius: 8px; font-size: .95rem; }
.side nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.side nav a.active { background: rgba(255, 255, 255, .12); color: #fff; box-shadow: inset 3px 0 0 var(--oak); }
.add-btn { margin: 4px 6px; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 0 6px; font-size: .8rem; }
.side-foot .link-btn { color: #d9d2c2; text-align: left; }
.mode-chip, .ai-chip { display: inline-block; padding: 3px 8px; border-radius: 99px; background: rgba(255, 255, 255, .1); width: fit-content; }
.mode-chip.demo { background: #f3c84b; color: #3b2a00; font-weight: 600; }
.main { min-width: 0; }
.topbar { display: none; }
.content { padding: 28px 32px 64px; max-width: 1320px; }

/* ---------- generic ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin-bottom: 2px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.gap { gap: 8px; }
.mt { margin-top: 10px; }
.grow { flex: 1; min-width: 200px; width: auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.narrow { max-width: 380px; width: 100%; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two-col > .card { margin-bottom: 18px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.error-text { color: var(--stop); }
.unknown { color: var(--muted); font-style: italic; }
.overdue { color: var(--stop); }
.err-cell { color: var(--stop); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-2);
  background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; font-weight: 550; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: #f5f1e8; color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--green-2); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--stop); border-color: var(--stop); color: #fff; }
.btn.danger-ghost { background: transparent; color: var(--stop); border-color: #e6bdb6; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.link-btn { background: none; border: 0; padding: 0; color: var(--green-2); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.icon-btn { background: none; border: 0; font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 4px 8px; color: inherit; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; border: 0; padding: 0; min-width: 0; }
.field-label { font-weight: 600; font-size: .88rem; color: var(--ink-2); }
.field-hint { font-size: .8rem; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line-2); background: #fff; padding: 6px 12px; border-radius: 99px; cursor: pointer; font-size: .9rem; }
.chip.on { background: var(--green); color: #fff; border-color: var(--green); }

.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: #efeadf; color: var(--ink-2); white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.stop { background: var(--stop-soft); color: var(--stop); }
.badge.muted { background: #ece8df; color: var(--muted); }
.badge.gold { background: var(--oak-soft); color: #7a4a1d; }
.badge.demo { background: #f3c84b; color: #3b2a00; letter-spacing: .04em; }

.status { display: inline-block; font-size: .78rem; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: #ece8df; color: var(--ink-2); white-space: nowrap; }
.status.s-new { background: var(--blue-soft); color: var(--blue); }
.status.s-contacted, .status.s-replied, .status.s-site_visit_booked, .status.s-quote_sent { background: var(--oak-soft); color: #7a4a1d; }
.status.s-won { background: var(--green-soft); color: var(--green); }
.status.s-lost, .status.s-archived { background: #ece8df; color: var(--muted); }

.notice { border-radius: 8px; padding: 10px 14px; margin: 10px 0; font-size: .9rem; border: 1px solid; }
.notice.info { background: #f1f4f2; border-color: #d6e0da; }
.notice.warn { background: var(--warn-soft); border-color: #ecd7a5; color: #5d3e00; }
.notice.stop { background: var(--stop-soft); border-color: #ecc3bc; color: #6e1e17; }
.notice.ok { background: var(--green-soft); border-color: #c6dccf; color: var(--green); }

.meter { display: grid; grid-template-columns: 52px 1fr 26px; align-items: center; gap: 6px; font-size: .75rem; }
.meter-name { color: var(--muted); }
.meter-track { height: 6px; background: #ebe5d8; border-radius: 99px; overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 99px; }
.meter-fill.hi { background: var(--green-2); }
.meter-fill.mid { background: var(--oak); }
.meter-fill.lo { background: #b9b2a3; }
.meter-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink-2); }
.indicators { display: flex; flex-direction: column; gap: 3px; min-width: 150px; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.table.compact th, .table.compact td { padding: 6px 8px; font-size: .88rem; }
.table.facts th { width: 38%; color: var(--ink-2); font-size: .88rem; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); border: 1px dashed var(--line-2); border-radius: var(--radius); }
.empty h3 { color: var(--ink-2); }
ul.plain { list-style: none; padding: 0; margin: 0 0 10px; }
ul.plain li { padding: 4px 0; }
.warn-list li::before { content: "?"; display: inline-grid; place-items: center; width: 16px; height: 16px; margin-right: 8px; border-radius: 50%; background: var(--warn-soft); color: var(--warn); font-size: .7rem; font-weight: 700; }
.facts-dl { display: grid; grid-template-columns: 120px 1fr; gap: 4px 12px; margin: 10px 0; font-size: .88rem; }
.facts-dl dt { color: var(--muted); }
.facts-dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- overview ---------- */
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.tile { display: flex; flex-direction: column; padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: transform .12s, border-color .12s; }
.tile:hover { transform: translateY(-1px); border-color: var(--line-2); color: var(--ink); }
.tile-n { font-family: var(--serif); font-size: 2rem; font-weight: 600; line-height: 1.1; color: var(--green); }
.tile-t { font-size: .88rem; color: var(--ink-2); }
.tile-sub { font-size: .78rem; color: var(--stop); margin-top: 2px; }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { padding: 10px 8px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 6px; }
.mini-list li:hover { background: #f8f4ec; }
.mini-title { font-weight: 600; }
.mini-meta { font-size: .82rem; color: var(--muted); margin-bottom: 4px; }

/* ---------- opportunities ---------- */
.filters { padding: 14px 16px; }
.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin-bottom: 6px; }
.filter-grid select, .filter-grid input { font-size: .88rem; padding: 6px 8px; }
.opp-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.opp-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px 100px 180px 110px; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; align-items: center; }
.opp-row:last-child { border-bottom: 0; }
a.opp-row:hover { background: #faf6ee; color: inherit; }
.opp-row.head { font-size: .78rem; color: var(--muted); font-weight: 600; background: #f8f4ec; padding-top: 8px; padding-bottom: 8px; }
.opp-row.dim { opacity: .55; }
.opp-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.opp-badges { display: flex; flex-wrap: wrap; gap: 5px; }
.opp-summary { font-weight: 600; font-size: .98rem; }
.opp-meta { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.opp-loc, .opp-date { font-size: .88rem; }
.opp-loc .badge { margin-left: 4px; }

/* ---------- detail ---------- */
.back { display: inline-block; margin-bottom: 10px; font-size: .9rem; text-decoration: none; }
.detail .page-head h1 { margin-top: 8px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 18px; align-items: start; }
.evidence { margin: 0; padding: 12px 16px; border-left: 3px solid var(--oak); background: #fbf6ec; border-radius: 0 8px 8px 0; font-family: var(--serif); font-size: 1.02rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.source-text { white-space: pre-wrap; max-height: 320px; overflow: auto; background: #f7f3ea; border: 1px solid var(--line); padding: 10px; border-radius: 8px; font-size: .82rem; font-family: var(--mono); }
.quotes summary { cursor: pointer; font-weight: 600; font-size: .9rem; margin-top: 8px; }
.quotes ul { list-style: none; padding: 0; }
.quotes li { padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.quotes q { font-family: var(--serif); }
.rank-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.rank-n { font-family: var(--serif); font-size: 2rem; font-weight: 600; color: var(--green); }
.score-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.score-col .meter { grid-template-columns: 1fr 70px 26px; font-size: .85rem; margin-bottom: 6px; }
.score-col .meter-name { color: var(--ink); font-weight: 600; }
.score-col ul { list-style: none; padding: 0; margin: 0; font-size: .82rem; }
.score-col li { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.pts { display: inline-block; min-width: 40px; font-variant-numeric: tabular-nums; color: var(--muted); }
.inline-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.draft textarea { font-family: var(--sans); font-size: .9rem; margin: 10px 0 6px; background: #fffef9; }
.timeline { list-style: none; padding: 0; margin: 12px 0; }
.timeline li { border-left: 2px solid var(--line-2); padding: 2px 0 10px 12px; font-size: .88rem; }
.timeline li.act-note { border-color: var(--oak); }
.timeline li.act-suppression { border-color: var(--stop); }
.timeline li.act-contacted { border-color: var(--green-2); }
.narrow-input { width: 100px; }
.small-select { font-size: .82rem; padding: 4px 6px; width: auto; }

/* ---------- pipeline ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.board-col { background: #efeadf; border-radius: var(--radius); padding: 10px; min-height: 200px; }
.board-col h2 { font-family: var(--sans); font-size: .88rem; font-weight: 700; color: var(--ink-2); display: flex; justify-content: space-between; margin: 2px 4px 10px; }
.count { background: #fff; border-radius: 99px; padding: 0 8px; font-weight: 600; }
.board-card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 5px; box-shadow: var(--shadow); }
.board-title { font-weight: 600; text-decoration: none; color: var(--ink); font-size: .9rem; }
.board-meta { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---------- sources ---------- */
.connectors { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 14px; }
.connector { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: #fff; }
.connector.unconfigured { background: #fdfaf2; border-style: dashed; }
.connector header { display: flex; flex-direction: column; gap: 6px; }
.connector h3 { margin: 0; }
.integration { padding: 12px 0; border-bottom: 1px solid var(--line); }
.integration h3 { margin: 0; }
.runs details summary { cursor: pointer; font-size: .85rem; }
.prose p { max-width: 75ch; }
.danger-zone { border-color: #ecc3bc; }

/* ---------- tabs, modal, toast ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line-2); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--ink-2); font-weight: 550; }
.tabs button.on { border-bottom-color: var(--green); color: var(--green); }
.modal-back { position: fixed; inset: 0; background: rgba(20, 28, 25, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--card); border-radius: 12px; width: min(560px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.wide { width: min(780px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px 20px 20px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--green); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 60; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: 90vw; cursor: pointer; }
.toast.error { background: var(--stop); }

/* ---------- onboarding ---------- */
.onboard { max-width: 1040px; margin: 0 auto; padding: 48px 24px; display: grid; grid-template-columns: 1fr 1.6fr; gap: 32px; align-items: start; }
.onboard-intro h1 { font-size: 2.2rem; }
.ticks { list-style: none; padding: 0; }
.ticks li { padding: 6px 0 6px 26px; position: relative; }
.ticks li::before { content: ""; position: absolute; left: 0; top: 12px; width: 12px; height: 7px; border-left: 2px solid var(--oak); border-bottom: 2px solid var(--oak); transform: rotate(-45deg); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .opp-row { grid-template-columns: minmax(0, 1fr) 130px 160px 100px; }
  .opp-row > :nth-child(3) { display: none; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; height: 100vh; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .demo-band + .shell .side { top: 0; height: 100vh; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--green); color: #f1e3c9; position: sticky; top: 0; z-index: 20; }
  .demo-band { position: static; }
  .topbar-title { font-family: var(--serif); font-weight: 600; flex: 1; }
  .content { padding: 18px 14px 48px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .two-col, .grid2, .grid3, .onboard, .score-cols { grid-template-columns: 1fr; }
  .opp-row { grid-template-columns: 1fr; gap: 6px; }
  .opp-row.head { display: none; }
  .opp-row > :nth-child(3) { display: block; }
  .connectors { grid-template-columns: 1fr; }
  .table.compact { display: block; overflow-x: auto; }
  .board { grid-auto-columns: 80%; }
}

.auto-w { width: auto; }
.row > input.grow { width: auto; }
