:root {
  --bg: #ffffff; --surface: #f4f2ed; --line: #e3e0d8; --ink: #0e1310; --ink-2: #2f3531; --muted: #5b625e;
  --link: #146a43; --mark: #1b8354; --wash: rgba(27, 131, 84, 0.12); --danger: #a1261b; --grid: #ece9e2;
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141816; --surface: #1c211e; --line: #2c332f; --ink: #eef1ee; --ink-2: #c9cfca; --muted: #9aa39d;
    --link: #6fcf9f; --mark: #35a673; --wash: rgba(53, 166, 115, 0.16); --danger: #f0877c; --grid: #232926; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .5rem; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--link); }
button { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .45rem .8rem; cursor: pointer; }
button:hover { border-color: var(--mark); }
button.primary { background: var(--mark); color: #fff; border-color: var(--mark); }
button.danger { color: var(--danger); }
button.link { background: none; border: 0; padding: 0; color: var(--link); text-decoration: underline; }
input, select { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .45rem .6rem; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--mark); outline-offset: 2px; }

.top { display: flex; align-items: center; gap: 1.5rem; padding: .8rem 1.5rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 5; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--mark); text-decoration: none; font-weight: 600; }
.brand svg { height: 22px; fill: currentColor; }
.brand span { color: var(--ink-2); font-weight: 500; border-left: 1px solid var(--line); padding-left: .6rem; }
.tabs { display: flex; gap: .25rem; }
.tabs button { background: none; border: 0; border-radius: 999px; padding: .4rem .9rem; color: var(--ink-2); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; }
.who { margin-left: auto; color: var(--muted); font-size: .9rem; }

main { max-width: 1180px; margin: 0 auto; padding: 1.5rem; }
.signin { max-width: 380px; margin: 12vh auto; text-align: center; }
.signin #gsi { display: flex; justify-content: center; margin: 1.25rem 0; }
.err, .msg.bad { color: var(--danger); }
.msg { background: var(--surface); border-radius: 10px; padding: .6rem .8rem; }
.note { color: var(--muted); margin: .25rem 0 1rem; font-size: .9rem; }
.bar { display: flex; align-items: end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.range { display: flex; gap: .5rem; align-items: center; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin: .5rem 0 1rem; }
.kpi { background: var(--surface); border-radius: 16px; padding: .9rem 1rem; }
.kpi b { display: block; font-size: 1.7rem; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi span { color: var(--muted); font-size: .85rem; }

.chart { margin: 0 0 1.5rem; position: relative; }
.chart figcaption { font-weight: 600; margin-bottom: .4rem; }
.plot svg { width: 100%; height: 200px; display: block; }
.plot .gridline { stroke: var(--grid); stroke-width: 1; }
.plot .bar-mark { fill: var(--mark); }
.plot .hit { fill: transparent; cursor: default; }
.plot .hit:hover + .bar-mark, .plot .bar-mark.on { opacity: .8; }
.plot text { fill: var(--muted); font-size: 11px; }
.tip { position: absolute; background: var(--ink); color: var(--bg); padding: .35rem .55rem; border-radius: 8px; font-size: .85rem; pointer-events: none; white-space: nowrap; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.card { border: 1px solid var(--line); border-radius: 16px; padding: .9rem 1rem; }
.card h3 { margin: 0 0 .6rem; font-size: .95rem; }
.rank { width: 100%; border-collapse: collapse; font-size: .9rem; }
.rank td { padding: .28rem 0; vertical-align: middle; }
.rank td.k { max-width: 0; width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank td.v { text-align: right; font-variant-numeric: tabular-nums; width: 3.5rem; }
.rank .meter { height: 6px; background: var(--wash); border-radius: 3px; }
.rank .meter i { display: block; height: 6px; background: var(--mark); border-radius: 3px; }
.empty { color: var(--muted); font-size: .9rem; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0 .5rem; }
.filters input[type=search] { flex: 1 1 280px; }
.check { display: flex; align-items: center; gap: .35rem; color: var(--ink-2); }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: .25rem 0 .75rem; }
.chip { background: var(--surface); border-radius: 999px; padding: .2rem .65rem; font-size: .85rem; color: var(--ink-2); border: 0; }
.chip[aria-pressed="true"] { background: var(--mark); color: #fff; }
.table-wrap { overflow-x: auto; }
.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
.list th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
.list td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.list tr { cursor: pointer; }
.list tbody tr:hover { background: var(--surface); }
.list .num { text-align: right; font-variant-numeric: tabular-nums; }
.list small { color: var(--muted); display: block; }
.pill { display: inline-block; border-radius: 999px; padding: .1rem .55rem; font-size: .8rem; background: var(--surface); border: 1px solid var(--line); }
.pill.qualified, .pill.customer { background: var(--wash); border-color: transparent; color: var(--link); font-weight: 600; }
.pill.lost { color: var(--muted); }
.pager { display: flex; gap: 1rem; align-items: center; margin-top: .75rem; color: var(--muted); }

.drawer { position: fixed; inset: 0 0 0 auto; width: min(560px, 100vw); background: var(--bg); border-left: 1px solid var(--line); box-shadow: -12px 0 32px rgba(0,0,0,.08); overflow-y: auto; padding: 1.5rem; z-index: 10; }
.drawer .close { position: absolute; right: 1rem; top: 1rem; border-radius: 999px; width: 2.2rem; height: 2.2rem; padding: 0; font-size: 1.3rem; }
.drawer dl { display: grid; grid-template-columns: 9rem 1fr; gap: .35rem .75rem; margin: .5rem 0 1rem; font-size: .92rem; }
.drawer dt { color: var(--muted); }
.drawer dd { margin: 0; overflow-wrap: anywhere; }
.stack { display: grid; gap: .6rem; max-width: 460px; }
.stack label { display: grid; gap: .25rem; color: var(--ink-2); font-size: .9rem; }
.inline { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }
.notes { list-style: none; padding: 0; margin: .5rem 0; }
.notes li { background: var(--surface); border-radius: 10px; padding: .5rem .7rem; margin-bottom: .4rem; font-size: .9rem; white-space: pre-wrap; }
.notes small, .timeline small { color: var(--muted); display: block; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.timeline li { padding: 0 0 .75rem .8rem; font-size: .9rem; }
.members { list-style: none; padding: 0; }
.members li { display: flex; justify-content: space-between; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.danger-zone { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
body:not([data-role="owner"]) .owner-only { display: none; }

@media (max-width: 720px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top { padding: .7rem 1rem; gap: .75rem; }
  main { padding: 1rem; }
  .list th:nth-child(4), .list td:nth-child(4), .list th:nth-child(8), .list td:nth-child(8) { display: none; }
}

/* ---- spec 012 ------------------------------------------------------------------------ */
textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .6rem; }
.stamp { color: var(--muted); font-size: .85rem; }
.kpis.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi small { display: block; margin-top: .35rem; font-size: .8rem; color: var(--muted); }
.kpi small em { font-style: normal; }
.kpi i { font-style: normal; cursor: help; }
.d { font-weight: 600; color: var(--muted); }
.d.up { color: var(--link); }
.d.down { color: var(--danger); }
.live { display: flex; align-items: center; gap: .5rem; color: var(--ink-2); margin: .25rem 0 .75rem; }
.dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--line); display: inline-block; }
.dot.on { background: var(--mark); box-shadow: 0 0 0 4px var(--wash); }
.split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; align-items: start; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: .6rem .2rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.feed li:last-child { border-bottom: 0; }
.feed li:hover { background: var(--surface); }
.feed .what { margin: .15rem 0; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed small { color: var(--muted); }
.plot.small svg { height: 130px; }
.waiting { margin-top: .75rem; }
.seg { display: inline-flex; gap: 0; margin-left: .75rem; vertical-align: middle; }
.seg button { border-radius: 0; padding: .25rem .6rem; font-size: .85rem; font-weight: 500; }
.seg button:first-child { border-radius: 999px 0 0 999px; }
.seg button:last-child { border-radius: 0 999px 999px 0; }
.seg button[aria-pressed="true"] { background: var(--mark); color: #fff; border-color: var(--mark); }
.chart figcaption { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
.rank th { font-size: .72rem; color: var(--muted); font-weight: 500; text-align: right; padding-bottom: .2rem; }
.rank td.m { width: 26%; }
.rank td.l { width: 3rem; color: var(--link); font-weight: 600; }
.bulk { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; background: var(--surface); border-radius: 12px; padding: .5rem .75rem; margin: .25rem 0 .75rem; }
.list th.sel, .list td.sel { width: 2rem; padding-right: 0; }
.inline-status { padding: .15rem .4rem; border-radius: 999px; font-size: .82rem; background: var(--surface); }
/* skeletons: the shape of what is coming, instead of "Loading…" */
@keyframes sk { 0% { opacity: .55; } 50% { opacity: 1; } 100% { opacity: .55; } }
.kpi.sk { min-height: 5.2rem; animation: sk 1.2s ease-in-out infinite; }
.sk-line { list-style: none; height: 2.6rem; border-radius: 10px; background: var(--surface); margin: .4rem 0; animation: sk 1.2s ease-in-out infinite; }
.sk-line.wide { height: 2.2rem; width: 60%; }
@media (prefers-reduced-motion: reduce) { .kpi.sk, .sk-line { animation: none; } }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } .kpis.five { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---- spec 013: pipeline, board, dialogs, the drawer's deal form, timeline and visit ------------ */
.col { display: grid; gap: 1rem; align-content: start; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .45rem .8rem; }
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary { border-color: var(--mark); }
.menu-body { position: absolute; right: 0; top: calc(100% + .35rem); z-index: 6; display: grid; gap: .35rem; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: .5rem; box-shadow: 0 12px 32px rgba(0,0,0,.12); min-width: 15rem; }
.menu-body button { text-align: left; }
.chip.ghost { background: none; border: 1px dashed var(--line); }
.pill.warn { background: #fff1d6; border-color: transparent; color: #7a4a00; }
.pill.late, .inline-due.late { background: rgba(161, 38, 27, .1); border-color: transparent; color: var(--danger); font-weight: 600; }
.pill.today, .inline-due.today { background: var(--wash); border-color: transparent; color: var(--link); font-weight: 600; }
@media (prefers-color-scheme: dark) { .pill.warn { background: #3a2c10; color: #f3c46b; } .pill.late, .inline-due.late { background: rgba(240, 135, 124, .14); } }
.pill.lead { background: var(--wash); border-color: transparent; color: var(--link); }
.inline-owner, .inline-due { padding: .15rem .4rem; border-radius: 999px; font-size: .82rem; background: var(--surface); max-width: 9.5rem; }
.list td.next span { display: block; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); margin-bottom: .2rem; }
.bulk .mini { display: flex; align-items: center; gap: .3rem; color: var(--muted); font-size: .9rem; }
.bulk input, .bulk select { padding: .3rem .5rem; }

.board { display: grid; grid-template-columns: repeat(5, minmax(210px, 1fr)); gap: .75rem; overflow-x: auto; padding-bottom: .5rem; align-items: start; }
.board > section { background: var(--surface); border-radius: 14px; padding: .6rem; min-height: 12rem; border: 2px solid transparent; }
.board > section.over { border-color: var(--mark); background: var(--wash); }
.board header { display: flex; align-items: baseline; gap: .4rem; padding: .2rem .3rem .6rem; }
.board header span { color: var(--muted); font-variant-numeric: tabular-nums; }
.board header small { margin-left: auto; color: var(--link); font-weight: 600; font-variant-numeric: tabular-nums; }
.board .col-lost { opacity: .85; }
.cards { display: grid; gap: .5rem; }
.kcard { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .7rem; cursor: grab; display: grid; gap: .25rem; font-size: .9rem; }
.kcard:hover, .kcard:focus-visible { border-color: var(--mark); outline: none; }
.kcard.dragging { opacity: .45; }
.kcard .k-int { color: var(--ink-2); }
.kcard .k-meta { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.kcard .k-meta b { font-variant-numeric: tabular-nums; margin-right: .2rem; }
.kcard small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dlg { border: 1px solid var(--line); border-radius: 18px; padding: 1.25rem 1.4rem; width: min(440px, calc(100vw - 2rem)); background: var(--bg); color: var(--ink); box-shadow: 0 24px 64px rgba(0,0,0,.25); }
.dlg.wide { width: min(680px, calc(100vw - 2rem)); }
.dlg::backdrop { background: rgba(10, 14, 12, .45); }
.dlg h2 { margin: 0 0 .75rem; }
.dlg-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
button.danger-fill { background: var(--danger); color: #fff; border-color: var(--danger); }
.stack-l { display: grid; gap: .3rem; color: var(--ink-2); font-size: .9rem; margin: .5rem 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem .75rem; }
.form-grid label { display: grid; gap: .25rem; color: var(--ink-2); font-size: .88rem; }
.form-grid .span2 { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
.problems { margin: .5rem 0 0; padding-left: 1.1rem; max-height: 12rem; overflow: auto; font-size: .88rem; color: var(--ink-2); }
.dupes { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; max-height: 60vh; overflow: auto; }
.dupes li { display: grid; grid-template-columns: 1fr auto 1fr; gap: .4rem .6rem; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: .6rem .7rem; }
.dupes li > .pill, .dupes li > button[data-merge], .dupes li > .err { grid-column: 1 / -1; justify-self: start; }
.dupes small { display: block; color: var(--muted); }

.quick { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .25rem 0 1rem; }
a.btn { display: inline-block; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .45rem .8rem; text-decoration: none; color: var(--ink); }
a.btn:hover { border-color: var(--mark); }
.compose { display: grid; gap: .5rem; background: var(--surface); border-radius: 14px; padding: .8rem; margin: 0 0 1rem; }
.compose label { display: grid; gap: .25rem; color: var(--ink-2); font-size: .88rem; }
.compose input, .compose textarea, .compose select { width: 100%; }
.deal { margin: 0 0 1rem; padding: .9rem; border: 1px solid var(--line); border-radius: 14px; }
.tabs2 { margin: 1rem 0 .6rem; }
.chips.small .chip { font-size: .8rem; }
.timeline li[hidden] { display: none; }
.timeline .note-text { white-space: pre-wrap; background: var(--surface); border-radius: 8px; padding: .35rem .5rem; margin-top: .25rem; }
.timeline s { color: var(--muted); }
.timeline details summary { color: var(--link); cursor: pointer; font-size: .85rem; }
.timeline pre { white-space: pre-wrap; font: inherit; background: var(--surface); border-radius: 8px; padding: .5rem; margin: .3rem 0 0; }
.visit { border: 1px solid var(--line); border-radius: 12px; padding: .6rem .8rem; margin-bottom: .6rem; }
.visit h3 { margin: 0 0 .4rem; font-size: .92rem; }
.visit h3 small { color: var(--muted); font-weight: 400; }
.visit ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.visit li { padding: .15rem 0 .15rem .7rem; font-size: .9rem; }
.visit li.lead { border-left: 2px solid var(--mark); margin-left: -2px; }
.visit time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: .35rem; }
code { font-size: .86em; background: var(--surface); border-radius: 6px; padding: .05rem .3rem; }
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .list th:nth-child(6), .list td:nth-child(6), .list th:nth-child(7), .list td:nth-child(7) { display: none; }
  .board { grid-template-columns: repeat(5, minmax(78vw, 1fr)); }
}
@media (max-width: 720px) {
  .tabs { order: 3; flex: 1 1 100%; overflow-x: auto; min-width: 0; scrollbar-width: none; }
  .who { font-size: .8rem; }
}
