:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #18202f; --muted: #667085; --line: #e3e6ec;
  --brand: #1f2a44; --brand-soft: #e8ecf6; --accent: #2f5bd3;
  --crit: #b42318; --crit-bg: #fdecea; --warn: #8a4b00; --warn-bg: #fff1e0; --info: #344054; --info-bg: #eef1f6;
  --good: #0a7a3d; --good-bg: #e6f4ec;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f131b; --panel: #171d28; --ink: #e6e9ef; --muted: #98a2b3; --line: #273041; --brand: #c7d2fe; --brand-soft: #1e2638; --accent: #7c9cff;
    --crit: #ff8a80; --crit-bg: #3a1d1c; --warn: #ffc580; --warn-bg: #3a2a17; --info: #c9d1e0; --info-bg: #1f2635; --good: #7ee2a8; --good-bg: #16301f; }
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--crit); margin: 0; min-height: 1.2em; font-size: 14px; }
button, input, select, textarea { font: inherit; color: var(--ink); }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-block; }
.btn.primary { background: var(--brand); color: var(--panel); border-color: var(--brand); font-weight: 600; }
.btn.small { padding: 3px 8px; font-size: 13px; }
.btn.danger { color: var(--crit); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.logo { display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 5px; border-radius: 8px; background: var(--brand); color: var(--panel); font-size: 12px; font-weight: 800; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; padding: 24px; display: grid; gap: 14px; }
.login-card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

.top { position: sticky; top: 0; z-index: 5; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 10px 16px; flex-wrap: wrap; }
nav { display: flex; gap: 4px; overflow-x: auto; }
nav button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
nav button.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.view { max-width: 1180px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
h2 { margin: 0; font-size: 18px; }
h3 { margin: 0 0 8px; font-size: 15px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.kpi { padding: 14px; }
.kpi .v { font-size: 24px; font-weight: 700; }
.kpi .k { font-size: 13px; color: var(--muted); }
.section { padding: 14px; }

.alerts { display: grid; gap: 6px; }
.alert { display: flex; gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.alert.critical { background: var(--crit-bg); color: var(--crit); }
.alert.warning { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--info-bg); color: var(--info); }
.alert b { white-space: nowrap; }
.ok { background: var(--good-bg); color: var(--good); padding: 8px 10px; border-radius: 8px; }

.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
table.t td.n, table.t th.n { text-align: right; white-space: nowrap; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover { background: var(--bg); }

.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--info-bg); color: var(--info); white-space: nowrap; }
.pill.live, .pill.paid, .pill.won { background: var(--good-bg); color: var(--good); }
.pill.onboarding, .pill.sent, .pill.demo, .pill.proposal { background: var(--brand-soft); color: var(--brand); }
.pill.paused, .pill.draft, .pill.contacted { background: var(--warn-bg); color: var(--warn); }
.pill.cancelled, .pill.void, .pill.lost { background: var(--bg); color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.good { background: #16a34a; } .dot.bad { background: #dc2626; } .dot.warn { background: #d97706; }
.meter { height: 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; min-width: 80px; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.meter.warn > span { background: #d97706; } .meter.over > span { background: #dc2626; }

.board { display: grid; grid-template-columns: repeat(6, minmax(170px, 1fr)); gap: 10px; overflow-x: auto; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; min-height: 120px; }
.col h4 { margin: 2px 4px 8px; font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.lead { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-bottom: 8px; cursor: pointer; background: var(--bg); font-size: 13px; }
.lead b { display: block; font-size: 14px; }
.lead .due { color: var(--warn); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card { width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; padding: 20px; display: grid; gap: 12px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label { display: grid; gap: 3px; font-size: 13px; color: var(--muted); }
.form .wide { grid-column: span 2; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.checklist label { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; color: var(--ink); }
.checklist input { width: auto; margin-top: 3px; }
.lines td input { min-width: 60px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: calc(100% - 32px); }

@media (max-width: 720px) {
  .form { grid-template-columns: 1fr; } .form .wide { grid-column: auto; }
  .board { grid-template-columns: repeat(6, 78vw); }
}
