:root {
  color-scheme: light;
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #f1f3f0;
  --border: #e2e5e0;
  --text: #111412;
  --text-2: #4d5550;
  --muted: #858c87;
  /* ChatGrow brand: logo green #00a63d, navy #0f172a. --brand is a darker step so white text on it stays readable. */
  --brand: #008a33;
  --brand-fill: #00a63d;
  --brand-navy: #0f172a;
  --brand-ink: #ffffff;
  --brand-soft: #e0f5e7;
  --danger: #c93434;
  --danger-soft: #fbe9e9;
  --warn: #9a6400;
  --warn-soft: #fdf2d9;
  --info: #2a78d6;
  --info-soft: #e5effb;
  --good: #0b7a33;
  --good-soft: #e1f3e6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1110; --surface: #181b19; --surface-2: #202421; --border: #2c312d;
    --text: #eef0ed; --text-2: #c0c6c1; --muted: #8a918c;
    --brand: #1fbf5a; --brand-fill: #00a63d; --brand-navy: #0f172a; --brand-ink: #03170a; --brand-soft: #123220;
    --danger: #ef6b6b; --danger-soft: #3a1c1c; --warn: #f0b440; --warn-soft: #3a2e12;
    --info: #5d9ff0; --info-soft: #172a42; --good: #3ccf6e; --good-soft: #15301f;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --grid: #2c2c2a; --axis: #383835; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1110; --surface: #181b19; --surface-2: #202421; --border: #2c312d;
  --text: #eef0ed; --text-2: #c0c6c1; --muted: #8a918c;
  --brand: #1fbf5a; --brand-fill: #00a63d; --brand-navy: #0f172a; --brand-ink: #03170a; --brand-soft: #123220;
  --danger: #ef6b6b; --danger-soft: #3a1c1c; --warn: #f0b440; --warn-soft: #3a2e12;
  --info: #5d9ff0; --info-soft: #172a42; --good: #3ccf6e; --good-soft: #15301f;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --grid: #2c2c2a; --axis: #383835; --shadow: 0 1px 2px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.logo { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 4px 10px 16px; color: inherit; }
.logo:hover { text-decoration: none; }
.brand-chip { display: inline-flex; border-radius: 8px; }
.brand-logo { display: block; width: 168px; height: auto; }
/* The wordmark's navy text needs a light backing on dark surfaces. */
:root[data-theme="dark"] .brand-chip { background: #fff; padding: 6px 10px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-chip { background: #fff; padding: 6px 10px; } }
.logo small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav a .count { margin-left: auto; font-size: 11px; background: var(--danger); color: #fff; border-radius: 10px; padding: 0 6px; }
.nav svg { width: 17px; height: 17px; flex: none; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.sidebar-foot .me { color: var(--text); font-weight: 600; font-size: 13px; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar .search { flex: 1; max-width: 420px; }
.menu-btn { display: none; }
.page { padding: 22px 24px 60px; max-width: 1440px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1; }
.sub { color: var(--muted); font-size: 13px; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.wa { background: #25d366; color: #052e14; border-color: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--border); background: var(--surface); padding: 7px 10px; border-radius: 8px; outline: none; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.input { min-height: 80px; resize: vertical; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters .input { width: auto; min-width: 140px; }
.filters .input.q { min-width: 220px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); font-weight: 550; }
label.field.full { grid-column: 1 / -1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 0; }
.grid { display: grid; gap: 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 550; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 4px; letter-spacing: -.01em; }
.kpi .hint { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.cols-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 14px; }
.cols-3 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 14px; }
.promo { display: flex; align-items: center; gap: 14px; padding: 12px 16px; margin-bottom: 14px; background: linear-gradient(90deg, var(--warn-soft), var(--surface)); border: 1px solid var(--border); border-radius: var(--radius); }
.promo b { font-size: 15px; }

/* tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th, .t td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.t th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; cursor: pointer; user-select: none; white-space: nowrap; }
.t tbody tr:hover { background: var(--surface-2); }
.t tbody tr.click { cursor: pointer; }
.t td.num, .t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.t .strong { font-weight: 600; }
.t .small { font-size: 12px; color: var(--muted); }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.table-foot { padding: 10px 14px; color: var(--muted); font-size: 12.5px; display: flex; justify-content: space-between; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 16px; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attention-group h3 { padding: 12px 16px 6px; font-size: 12.5px; color: var(--text-2); display: flex; gap: 8px; align-items: center; }

/* kanban */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.col { background: var(--surface-2); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 420px; border: 1px solid var(--border); }
.col-head { padding: 10px 12px; display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--border); }
.col-head .sum { font-size: 12px; color: var(--muted); }
.col-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.col.drop { outline: 2px dashed var(--brand); outline-offset: -2px; }
.deal { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px; cursor: grab; box-shadow: var(--shadow); }
.deal:active { cursor: grabbing; }
.deal .t1 { font-weight: 600; font-size: 13px; }
.deal .t2 { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--text-2); }

/* modal & drawer */
.overlay { position: fixed; inset: 0; background: rgba(10,14,12,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { width: 100%; max-width: 680px; background: var(--surface); border-radius: 12px; border: 1px solid var(--border); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-body { padding: 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.overlay.drawer { justify-content: flex-end; padding: 0; align-items: stretch; }
.overlay.drawer .modal { max-width: 560px; border-radius: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.overlay.drawer .modal-body { flex: 1; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0; border-top: 1px solid var(--border); font-size: 13px; }
.timeline .meta { color: var(--muted); font-size: 12px; }
.section-title { margin: 18px 0 8px; font-size: 13px; color: var(--text-2); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 9px 12px; cursor: pointer; color: var(--text-2); font-weight: 550; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

/* progress / usage */
.meter { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.meter > span { display: block; height: 100%; background: var(--series-1); border-radius: 6px; }
.meter.warn > span { background: var(--warn); }
.meter.bad > span { background: var(--danger); }
.usage-row { display: grid; grid-template-columns: 120px 1fr 120px; gap: 10px; align-items: center; font-size: 13px; margin-bottom: 10px; }
.usage-row .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: 6px 0; display: flex; gap: 8px; align-items: center; }
.checklist li.done span { color: var(--muted); }
.checklist input { accent-color: var(--brand); }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .base-line { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart .bar { transition: opacity .1s; }
.chart:hover .bar { opacity: .55; }
.chart .bar.on { opacity: 1; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); padding: 0 16px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
#tooltip { position: fixed; z-index: 100; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0,0,0,.15); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; opacity: 0; transition: opacity .08s; max-width: 260px; }
#tooltip.show { opacity: 1; }
#tooltip b { display: block; margin-bottom: 2px; }

/* toast */
#toast-root { position: fixed; bottom: 18px; right: 18px; z-index: 120; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); max-width: 360px; }
.toast.err { background: var(--danger); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { margin: 14px 0 4px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.err-text { color: var(--danger); font-size: 13px; min-height: 18px; }

/* invoice */
.invoice { background: #fff; color: #111; padding: 32px; font-size: 13px; }
.invoice table { width: 100%; border-collapse: collapse; margin-top: 14px; }
.invoice th, .invoice td { border-bottom: 1px solid #ddd; padding: 8px; text-align: left; }
.invoice td.num, .invoice th.num { text-align: right; }
.invoice .inv-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #00a63d; padding-bottom: 14px; }
.invoice .inv-logo { width: 190px; height: auto; display: block; margin-bottom: 8px; }
.invoice .totals { margin-left: auto; width: 300px; margin-top: 10px; }
.invoice .totals div { display: flex; justify-content: space-between; padding: 4px 8px; }
.invoice .totals .grand { border-top: 2px solid #111; font-weight: 700; font-size: 15px; }
.invoice .muted { color: #666; }
.stamp { display: inline-block; border: 2px solid; padding: 2px 10px; border-radius: 6px; font-weight: 700; transform: rotate(-4deg); }

@media print {
  body * { visibility: hidden; }
  .invoice, .invoice * { visibility: visible; }
  .invoice { position: absolute; left: 0; top: 0; width: 100%; padding: 0; }
  .overlay { position: static; background: none; padding: 0; }
}

@media (max-width: 1180px) {
  .cols-3 { grid-template-columns: 1fr; }
}
.card .kv { grid-template-columns: 120px 1fr; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; width: 250px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .page { padding: 16px 16px 60px; }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
  .usage-row { grid-template-columns: 90px 1fr 90px; }
  .filters .input, .filters .input.q { min-width: 0; flex: 1 1 140px; }
}
