:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1b1f24; --muted: #667085; --line: #e4e7ec;
  --accent: #1f5eff; --accent-ink: #ffffff; --accent-soft: #e8efff;
  --ok: #157f3b; --ok-soft: #e3f5e9; --warn: #a15c00; --warn-soft: #fff3df; --bad: #b42318; --bad-soft: #fde8e7;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 14px; line-height: 1.5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #171b21; --text: #e6e9ee; --muted: #98a2b3; --line: #2a3039;
    --accent: #6b93ff; --accent-ink: #0b0d10; --accent-soft: #1d2740;
    --ok: #4cc27a; --ok-soft: #14291c; --warn: #f0a646; --warn-soft: #2e2312; --bad: #f97066; --bad-soft: #331715;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.shell { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
nav.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
nav.side .brand { font-weight: 700; font-size: 16px; padding: 0 10px 16px; }
nav.side a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--text); }
nav.side a:hover { background: var(--bg); text-decoration: none; }
nav.side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav.side form { margin-top: 20px; padding: 0 10px; }
main { padding: 24px 28px 60px; max-width: 1280px; width: 100%; }

.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: 2fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .shell { grid-template-columns: 1fr; } nav.side { position: static; height: auto; } .g2, .g3, .g4 { grid-template-columns: 1fr; } main { padding: 16px; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.stat .n { font-size: 22px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.client, .badge.won, .badge.paid, .badge.signed, .badge.crm { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.lead, .badge.prospect, .badge.proposal, .badge.negotiation, .badge.qualified, .badge.sent, .badge.review { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.lost, .badge.void, .badge.overdue { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.draft, .badge.pending { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

.btn, button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover, button:hover { border-color: var(--muted); text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.ai, button.ai { border-color: var(--accent); color: var(--accent); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; padding: 0; color: var(--muted); font-size: 12px; }
button[disabled] { opacity: .6; cursor: progress; }
form.inline { display: inline; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 0 0 4px; }
input, select, textarea { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); font: inherit; }
textarea { min-height: 90px; resize: vertical; }
textarea.tall { min-height: 520px; font-family: ui-monospace, "JetBrains Mono", monospace; font-size: 13px; }
.field { margin-bottom: 12px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.filters { display: flex; gap: 8px; margin-bottom: 14px; }
.filters input { max-width: 280px; }
.filters select { max-width: 160px; }

.flash { background: var(--accent-soft); color: var(--accent); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }
.error { background: var(--bad-soft); color: var(--bad); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.pre { white-space: pre-wrap; word-break: break-word; }
.summary { background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; }
.summary p:first-child { margin-top: 0; } .summary p:last-child, .summary ul:last-child { margin-bottom: 0; }

.board { display: grid; grid-template-columns: repeat(6, minmax(170px, 1fr)); gap: 12px; overflow-x: auto; }
.board .col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 200px; }
.board .col h3 { display: flex; justify-content: space-between; text-transform: capitalize; }
.board .deal { border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-top: 8px; background: var(--bg); }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--accent); border-color: var(--accent); font-weight: 600; }

.doc { max-width: 820px; }
.doc table { margin: 10px 0; border: 1px solid var(--line); }
.doc th, .doc td { border: 1px solid var(--line); text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); }
.items td input { min-width: 0; }
.code { font-family: ui-monospace, monospace; font-size: 30px; letter-spacing: .15em; font-weight: 700; }
.busy-note { display: none; color: var(--muted); font-size: 12px; }
form.busy .busy-note { display: inline; }
details summary { cursor: pointer; color: var(--muted); }
.login { max-width: 360px; margin: 12vh auto; }
