:root {
  --night: #1f2a44; --night-2: #2a3758; --amber: #f2a93b; --glow: #ffd27a; --air: #4a90c2;
  --bg: #f4f5f2; --surface: #fff; --fg: #1c2230; --muted: #5b6475; --line: #dfe2e8; --link: #9a5a07;
  --good: #1f7a4d; --warn: #b26a00; --bad: #b3261e; --chip: #eef0f4;
  --display: "Zilla Slab", Georgia, serif; --body: "Work Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 10px; --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161f; --surface: #1b2130; --fg: #e8ebf1; --muted: #9aa3b5; --line: #2c3446; --link: #f2b85c; --chip: #252c3d;
    --good: #5cc98f; --warn: #f0b04a; --bad: #ff7b72; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.5 var(--body); -webkit-text-size-adjust: 100%; }
a { color: var(--link); }
h1, h2, h3 { font-family: var(--display); line-height: 1.2; margin: 0; }
h1 { font-size: 24px; } h2 { font-size: 19px; } h3 { font-size: 16px; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--night); color: #fff; padding: 16px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-family: var(--display); font-weight: 700; font-size: 17px; }
.brand img { width: 34px; height: 34px; }
.nav a { display: flex; gap: 10px; align-items: center; color: #dfe4f0; text-decoration: none; padding: 9px 10px; border-radius: 8px; }
.nav a.on, .nav a:hover { background: var(--night-2); color: var(--glow); }
.side .who { margin-top: auto; font-size: 13px; color: #aeb7cc; padding: 8px; }
main { padding: 20px 24px 100px; min-width: 0; }
.bottom { display: none; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  main { padding: 14px 16px 96px; }
  .bottom { display: flex; position: fixed; inset: auto 0 0 0; background: var(--night); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .bottom a { flex: 1; text-align: center; color: #cfd6e6; text-decoration: none; font-size: 11px; padding: 8px 2px; }
  .bottom a .i { display: block; font-size: 20px; line-height: 1.2; }
  .bottom a.on { color: var(--glow); }
}

/* bits */
.top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.top h1 { flex: 1; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); }
.stack { display: grid; gap: 12px; align-content: start; min-width: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .right { margin-left: auto; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--fg); min-height: 40px; }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #1c2230; font-weight: 600; }
.btn.dark { background: var(--night); border-color: var(--night); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 9px 10px; width: 100%; min-height: 40px; font-size: 16px; }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; min-height: 0; accent-color: var(--amber); }
.check { display: flex; gap: 8px; align-items: center; color: var(--fg); font-size: 15px; }
.chip { display: inline-block; background: var(--chip); border-radius: 99px; padding: 2px 10px; font-size: 12px; white-space: nowrap; }
.chip.amber { background: #fdf0d8; color: #7a4a00; } .chip.green { background: #dff3e8; color: #135c37; } .chip.red { background: #fde4e2; color: #8c1d16; } .chip.blue { background: #e2eef8; color: #1d4f78; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.amber { background: #4a3510; color: #ffd27a; } :root:not([data-theme="light"]) .chip.green { background: #173a29; color: #8de0b2; } :root:not([data-theme="light"]) .chip.red { background: #4a1d1a; color: #ffb4ab; } :root:not([data-theme="light"]) .chip.blue { background: #1b3550; color: #a9d1f3; } }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips button { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 5px 12px; white-space: nowrap; cursor: pointer; font-size: 13px; }
.chips button.on { background: var(--night); color: #fff; border-color: var(--night); }
.list { display: grid; }
.list > * { padding: 11px 4px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; min-width: 0; }
.list > *:last-child { border-bottom: 0; }
.grow { flex: 1; min-width: 0; }
.trunc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--night); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; box-shadow: 0 4px 16px rgb(0 0 0 / .25); max-width: 90vw; }
.toast.err { background: var(--bad); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.kpi b { display: block; font-size: 20px; font-family: var(--display); }
.kpi span { font-size: 12px; color: var(--muted); }

/* pipeline */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 10px; scroll-snap-type: x mandatory; }
.col { background: var(--chip); border-radius: var(--r); padding: 8px; min-height: 200px; scroll-snap-align: start; }
.col.drop { outline: 2px dashed var(--amber); }
.col h3 { font-size: 14px; display: flex; justify-content: space-between; padding: 2px 4px 8px; }
.jc { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; text-decoration: none; color: inherit; cursor: grab; }
.jc .t { font-weight: 600; }
.jc .fu { color: var(--warn); font-size: 12px; margin-top: 4px; }
@media (max-width: 820px) { .board { grid-auto-columns: 82%; } }

/* timeline */
.tl { display: grid; gap: 10px; }
.tl .e { display: grid; grid-template-columns: 28px 1fr; gap: 8px; }
.tl .ic { width: 28px; height: 28px; border-radius: 50%; background: var(--chip); display: grid; place-items: center; font-size: 14px; }
.tl .when { font-size: 12px; color: var(--muted); }
.bubble { background: var(--chip); border-radius: 12px; padding: 8px 12px; white-space: pre-wrap; display: inline-block; max-width: 100%; }
.bubble.out { background: #fdf0d8; color: #3b2a07; }
.thread { display: grid; gap: 6px; }
.thread .out { justify-self: end; }
.transcript p { margin: 4px 0; } .transcript b { color: var(--muted); font-weight: 600; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgb(10 14 24 / .55); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; width: min(640px, 100%); max-height: 90vh; overflow: auto; padding: 18px; }
@media (max-width: 820px) { .modal-bg { place-items: end stretch; padding: 0; } .modal { border-radius: 14px 14px 0 0; max-height: 92vh; padding-bottom: calc(18px + env(safe-area-inset-bottom)); } }

/* builder */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; color: var(--muted); }
.tabs button.on { border-color: var(--amber); color: var(--fg); font-weight: 600; }
.progress { height: 6px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--amber); }
.step-prompt { background: #fdf6e8; border-left: 4px solid var(--amber); padding: 10px 12px; border-radius: 6px; color: #3b2a07; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .step-prompt { background: #2e2615; color: #f6e2b8; } }
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 12px; }
.opt.rec { border-color: var(--amber); border-width: 2px; }
.line { display: grid; grid-template-columns: 1fr 56px 92px 32px; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.line input { min-height: 34px; padding: 5px 6px; font-size: 15px; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos .ph { position: relative; }
.photos img { width: 92px; height: 92px; object-fit: cover; border-radius: 8px; display: block; }
.photos .x { position: absolute; top: -6px; right: -6px; background: var(--bad); color: #fff; border: 0; border-radius: 50%; width: 22px; height: 22px; cursor: pointer; }
.money-box { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; font-size: 13px; }
.step-edit { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 8px; }
table.t { width: 100%; border-collapse: collapse; }
table.t td, table.t th { padding: 6px; border-bottom: 1px solid var(--line); text-align: left; }
.line > div:first-child { grid-column: 1 / -1; }
.line { grid-template-columns: 1fr 70px 110px 32px; }
