/* ---------- tokens (light default; dark via OS or the toggle) ---------- */
:root {
  color-scheme: light;
  --bg: #f3f5f8; --panel: #fff; --ink: #1b1f24; --muted: #5f6b7a; --line: #e3e6ea;
  --side: #14213d; --side-ink: #c9d2e3; --side-muted: #7f8aa3; --side-on: #ffffff; --side-on-bg: rgba(255,255,255,.09);
  --brand: #0b6e4f; --brand-ink: #fff; --brand-soft: #e3f2ec;
  --good: #11704a; --good-bg: #e2f4ea; --warn: #8a5a00; --warn-bg: #fdf1d8;
  --bad: #b42318; --bad-bg: #fde7e5; --info: #1f5fa8; --info-bg: #e3edf9; --mute-bg: #eef0f3;
  --series-1: #257de0; --series-2: #f47230; --grid: #e6e8eb; --axis: #c3c8cf;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.04);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #111418; --panel: #1a1f25; --ink: #e8ebef; --muted: #98a3b1; --line: #2a313a;
    --side: #0d1117; --side-ink: #b8c1cf; --side-muted: #6c7787; --side-on: #fff; --side-on-bg: rgba(255,255,255,.07);
    --brand: #2fb488; --brand-ink: #06110d; --brand-soft: #173329;
    --good: #5fd3a0; --good-bg: #16302a; --warn: #f2c063; --warn-bg: #3a2e14; --bad: #ff8a80; --bad-bg: #3b1d1b;
    --info: #8db8ee; --info-bg: #1b2a3d; --mute-bg: #242a32;
    --series-1: #338ced; --series-2: #e76624; --grid: #262c34; --axis: #3a424d;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111418; --panel: #1a1f25; --ink: #e8ebef; --muted: #98a3b1; --line: #2a313a;
  --side: #0d1117; --side-ink: #b8c1cf; --side-muted: #6c7787; --side-on: #fff; --side-on-bg: rgba(255,255,255,.07);
  --brand: #2fb488; --brand-ink: #06110d; --brand-soft: #173329;
  --good: #5fd3a0; --good-bg: #16302a; --warn: #f2c063; --warn-bg: #3a2e14; --bad: #ff8a80; --bad-bg: #3b1d1b;
  --info: #8db8ee; --info-bg: #1b2a3d; --mute-bg: #242a32;
  --series-1: #338ced; --series-2: #e76624; --grid: #262c34; --axis: #3a424d;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .2rem; line-height: 1.25; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .4rem; }
small { display: block; color: var(--muted); font-size: .8rem; }
.small { font-size: .85rem; }
.muted { color: var(--muted); margin: .1rem 0; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .88em; }
.neg { color: var(--bad); }
.pos { color: var(--good); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 1rem .75rem 1.5rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: .65rem; align-items: center; color: inherit; padding: .2rem .4rem 1rem; }
.brand:hover { text-decoration: none; }
.brand strong { color: var(--side-on); }
.brand small { color: var(--side-muted); font-size: .78rem; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; flex: none; }
.side nav { display: flex; flex-direction: column; gap: 1px; }
.nav-group { margin: 1.1rem .7rem .35rem; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--side-muted); font-weight: 600; }
.side nav a { color: var(--side-ink); padding: .5rem .7rem; border-radius: 8px; display: flex; align-items: center; gap: .6rem; font-size: .92rem; }
.side nav a:hover { background: var(--side-on-bg); text-decoration: none; color: var(--side-on); }
.side nav a.on { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.ico { width: 1.1rem; text-align: center; opacity: .85; flex: none; }
.count { margin-left: auto; font-size: .72rem; font-weight: 600; padding: 0 .45rem; border-radius: 999px; background: var(--side-on-bg); color: var(--side-on); }
.count.warn { background: #f2c063; color: #3a2e14; }
.side nav a.on .count { background: rgba(0,0,0,.15); color: inherit; }

.frame { display: flex; flex-direction: column; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; padding: .6rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.top-search { flex: 1; max-width: 460px; }
.top-search input { background: var(--bg); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: .35rem; }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; border: 0; background: transparent; color: var(--ink); font-size: 1.05rem; cursor: pointer; list-style: none; }
.icon-btn:hover { background: var(--mute-bg); }
.icon-btn::-webkit-details-marker, .profile::-webkit-details-marker { display: none; }
.dot { position: absolute; top: 3px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--bad); color: #fff; font-size: .66rem; font-weight: 700; display: grid; place-items: center; }
.drop { position: relative; }
.drop > summary { list-style: none; cursor: pointer; }
.drop-menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 220px; padding: .35rem; z-index: 30; }
.drop-menu.wide { width: min(22rem, calc(100vw - 1rem)); }
.drop-head { margin: 0; padding: .5rem .6rem .6rem; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: .3rem; }
.drop-head small { width: 100%; font-weight: 400; }
.drop-item { display: block; width: 100%; text-align: left; padding: .55rem .6rem; border-radius: 7px; color: var(--ink); background: none; border: 0; font: inherit; cursor: pointer; }
.drop-item:hover { background: var(--mute-bg); text-decoration: none; }
.profile { display: flex; align-items: center; gap: .5rem; padding: .2rem .5rem .2rem .2rem; border-radius: 999px; font-weight: 600; font-size: .9rem; }
.profile:hover { background: var(--mute-bg); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.main { padding: 1.4rem 1.5rem 2.5rem; width: 100%; max-width: 1440px; }
.foot { margin-top: auto; padding: 1rem 1.5rem; color: var(--muted); font-size: .8rem; border-top: 1px solid var(--line); }
.solo { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.only-mobile { display: none; }

/* ---------- blocks ---------- */
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.crumb { margin: 0 0 .3rem; font-size: .85rem; color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; box-shadow: var(--shadow); overflow-x: auto; min-width: 0; }
.card.flush { padding: 0; }
.card.flush table th:first-child, .card.flush table td:first-child { padding-left: 1.2rem; }
.card.narrow { max-width: 640px; }
.card.subtle { background: transparent; box-shadow: none; }
.card.login { width: 100%; max-width: 380px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .6rem; }
.card-head h2 { margin: 0; }
.card-head select { width: auto; padding: .3rem .5rem; font-size: .85rem; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.grid2.wide-left { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.grid3 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr) minmax(0, 1.1fr); gap: 0 1rem; }
.empty { color: var(--muted); margin: .2rem 0; }
.empty.pad { padding: 1.2rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; box-shadow: var(--shadow); }
.kpi span { color: var(--muted); font-size: .82rem; }
.kpi strong { display: block; font-size: 1.45rem; font-variant-numeric: tabular-nums; margin: .15rem 0; }

/* stat cards */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { display: flex; gap: .85rem; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); color: var(--ink); min-width: 0; }
.stat:hover { text-decoration: none; border-color: var(--axis); }
.stat > div { min-width: 0; }
.stat-ico { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; font-size: 1.15rem; flex: none; }
.stat-ico.c1 { background: var(--info-bg); color: var(--info); }
.stat-ico.c2 { background: #efe9fd; color: #5b3fd6; }
.stat-ico.c3 { background: var(--warn-bg); color: var(--warn); }
.stat-ico.c4, .stat-ico.bad { background: var(--bad-bg); color: var(--bad); }
.stat-ico.good { background: var(--good-bg); color: var(--good); }
:root[data-theme="dark"] .stat-ico.c2 { background: #26213d; color: #b4a6f5; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .stat-ico.c2 { background: #26213d; color: #b4a6f5; } }
.stat-label { color: var(--muted); font-size: .8rem; display: block; }
.stat strong { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; line-height: 1.3; margin: .1rem 0 .15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trend { font-size: .78rem; font-weight: 600; display: block; }
.trend.up { color: var(--good); }
.trend.down { color: var(--bad); }
.trend.flat { color: var(--muted); font-weight: 400; }
.trend .muted { font-weight: 400; }

/* charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .grid.base { stroke: var(--axis); }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .s1, .key.s1, .tip-key.s1 { fill: var(--series-1); background: var(--series-1); }
.chart .s2, .key.s2, .tip-key.s2 { fill: var(--series-2); background: var(--series-2); }
.chart .hit { fill: transparent; cursor: crosshair; outline: none; }
.chart .hit.active, .chart .hit:focus-visible { fill: var(--ink); fill-opacity: .05; }
.legend { display: flex; gap: 1rem; font-size: .82rem; color: var(--muted); margin-bottom: .3rem; }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.key { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.shares { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: .25rem; margin-top: .6rem; border-top: 1px solid var(--line); padding-top: .6rem; }
.shares div { text-align: center; min-width: 0; }
.shares span { display: block; color: var(--muted); font-size: .72rem; }
.shares strong { font-size: .88rem; font-variant-numeric: tabular-nums; }
.table-view { margin-top: .5rem; font-size: .85rem; }
.table-view summary { cursor: pointer; color: var(--muted); }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.15); padding: .5rem .65rem; font-size: .82rem; min-width: 150px; }
.tip-title { color: var(--muted); margin-bottom: .25rem; }
.tip-row { display: flex; align-items: center; gap: .45rem; }
.tip-row strong { font-variant-numeric: tabular-nums; }
.tip-row span:last-child { color: var(--muted); }
.tip-key { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }

/* feed */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; align-items: center; gap: .7rem; padding: .6rem 0; border-top: 1px solid var(--line); }
.feed li:first-child { border-top: 0; }
.feed-main { flex: 1; min-width: 0; }
.feed-main a { font-weight: 600; }
.feed-end { text-align: right; white-space: nowrap; }
.pill { font-size: .66rem; font-weight: 700; letter-spacing: .03em; padding: .3rem .45rem; border-radius: 6px; width: 62px; text-align: center; flex: none; background: var(--mute-bg); color: var(--muted); }
.pill.mpesa { background: var(--good-bg); color: var(--good); }
.pill.airtel_money { background: var(--bad-bg); color: var(--bad); }
.pill.cash { background: var(--warn-bg); color: var(--warn); }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; padding: .55rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { border-bottom: 0; padding: .3rem .6rem; }
tfoot tr.due td { border-top: 2px solid var(--ink); padding-top: .5rem; }

.badge { display: inline-block; padding: .08rem .5rem; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; vertical-align: middle; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.muted { background: var(--mute-bg); color: var(--muted); }

.flash { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.ok { background: var(--good-bg); color: var(--good); }
.flash.error { background: var(--bad-bg); color: var(--bad); }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; font-size: .9rem;
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--mute-bg); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { padding: .3rem .65rem; font-size: .84rem; }
.btn.wide { width: 100%; margin-top: .5rem; }
.form { display: flex; flex-direction: column; gap: .85rem; }
.form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .88rem; }
.form label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
.form label.check.end { align-self: end; padding-bottom: .55rem; }
input, select, textarea { font: inherit; font-weight: 400; padding: .5rem .6rem; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 100%; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .7rem .9rem .9rem; display: flex; flex-direction: column; gap: .7rem; }
legend { font-weight: 600; font-size: .85rem; color: var(--muted); padding: 0 .3rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .3rem; }
.hint { color: var(--muted); font-size: .84rem; margin: -.3rem 0 0; }
.filters { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters input { flex: 1 1 280px; width: auto; }
.filters select { width: auto; }
.tabs { display: flex; gap: .3rem; margin-bottom: .8rem; }
.tabs a { padding: .35rem .8rem; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a.on { background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.login .brand strong { color: var(--ink); }
.login .brand small { color: var(--muted); }
.brand.big { margin-bottom: .6rem; }

/* connection rows */
.conn { display: flex; justify-content: space-between; gap: 1rem; padding: .9rem 0; border-top: 1px solid var(--line); }
.conn:first-of-type { border-top: 0; padding-top: .2rem; }
.conn-title { display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; margin-bottom: .45rem; }
.meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .35rem 1rem; margin: 0; }
.meta dt { color: var(--muted); font-size: .76rem; }
.meta dd { margin: 0; font-size: .9rem; }
.conn-actions { display: flex; flex-direction: column; gap: .4rem; align-items: stretch; min-width: 110px; }
.plain { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .35rem; }

/* tickets */
.thread { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .7rem; }
.thread li { padding: .7rem .9rem; border-radius: 10px; background: var(--mute-bg); max-width: 760px; }
.thread li.from-staff { background: var(--info-bg); margin-left: auto; }
.thread li.internal { background: var(--warn-bg); }
.thread .who { font-weight: 600; font-size: .85rem; display: flex; gap: .5rem; }
.thread .who span { color: var(--muted); font-weight: 400; margin-left: auto; }
.thread p { margin: .3rem 0 0; white-space: pre-wrap; }

/* invoice paper */
.paper { max-width: 820px; padding: 2rem 2.2rem; }
.paper-head, .paper-meta { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.paper-head h2 { font-size: 1.3rem; letter-spacing: .08em; margin: 0; }
.paper-meta strong { display: block; font-size: 1.05rem; }
.right { text-align: right; }
.howto { margin-top: 1.5rem; padding: .8rem 1rem; border-radius: 8px; background: var(--brand-soft); display: flex; flex-direction: column; gap: .2rem; }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  body.menu-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .only-mobile { display: inline-grid; }
  .hide-mobile { display: none; }
  .topbar { padding: .5rem .75rem; }
  .main { padding: 1rem .75rem 2rem; }
  .grid2, .grid2.wide-left, .grid3 { grid-template-columns: 1fr; }
  .shares { grid-template-columns: repeat(6, minmax(0, 1fr)); row-gap: .5rem; }
  .row2 { grid-template-columns: 1fr; }
  .conn { flex-direction: column; }
  .conn-actions { flex-direction: row; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr; }
}
@media print {
  .side, .topbar, .foot, .no-print, .flash { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  body { background: #fff; color: #000; }
  .card { border: 0; box-shadow: none; }
}

/* notices, code, router pages */
.notice { padding: .8rem 1rem; border-radius: 10px; background: var(--warn-bg); color: var(--ink); margin-bottom: 1rem; border: 1px solid var(--line); }
.notice strong { color: var(--warn); }
.notice.bad { background: var(--bad-bg); }
.notice.bad strong { color: var(--bad); }
pre.code { margin: 0; padding: 1rem; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); font: .82rem/1.55 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre-wrap; word-break: break-all; max-height: 520px; overflow: auto; }
.steps { margin: 0 0 1rem; padding-left: 1.3rem; display: flex; flex-direction: column; gap: .35rem; }
.pad-head { padding: 1rem 1.2rem 0; }
.kpis.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 900px) { .kpis.three { grid-template-columns: 1fr; } }

/* admin forms */
form.inline { display: flex; gap: .35rem; align-items: center; margin: 0; }
form.inline select, .sm-input { width: auto; padding: .3rem .5rem; font-size: .85rem; }
.sm-input { max-width: 140px; }
.row-actions { text-align: right; }
.pad-form { padding: .5rem; }
.as-button { border: 0; cursor: pointer; font: inherit; font-size: .74rem; font-weight: 600; }
dl.roles { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .35rem .8rem; font-size: .9rem; }
dl.roles dt { font-weight: 600; }
dl.roles dd { margin: 0; color: var(--muted); }
.import-report td { font-size: .85rem; }
.import-report tr.err td { background: var(--bad-bg); }

/* report filters */
.filters-card { padding: 1rem 1.2rem; }
.filter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .7rem; }
.filter-grid label { display: flex; flex-direction: column; gap: .25rem; font-size: .8rem; font-weight: 600; color: var(--muted); }
.filter-actions { display: flex; gap: .5rem; justify-content: flex-end; align-items: center; margin-top: .8rem; }
.filter-actions .quick { margin-right: auto; display: flex; gap: .8rem; font-size: .88rem; }
@media (max-width: 900px) { .filter-grid { grid-template-columns: 1fr 1fr; } }

.inline-note { display: inline; font-weight: 400; font-size: .75rem; margin-left: .3rem; }

/* debts aging */
.aging { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .6rem; }
.age { display: flex; flex-direction: column; gap: .1rem; padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); }
.age:hover, .age.on { text-decoration: none; border-color: var(--brand); }
.age span { font-size: .8rem; color: var(--muted); }
.age strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.age-bar { display: block; height: 6px; border-radius: 3px; background: var(--mute-bg); margin-top: .35rem; overflow: hidden; }
.age-bar b { display: block; height: 100%; border-radius: 3px; background: var(--bad); }
.age.not_due .age-bar b { background: var(--muted); }
.age.d1_7 .age-bar b { background: #f2a600; }
.age-bar b.w0 { width: 0%; }
.age-bar b.w5 { width: 5%; }
.age-bar b.w10 { width: 10%; }
.age-bar b.w15 { width: 15%; }
.age-bar b.w20 { width: 20%; }
.age-bar b.w25 { width: 25%; }
.age-bar b.w30 { width: 30%; }
.age-bar b.w35 { width: 35%; }
.age-bar b.w40 { width: 40%; }
.age-bar b.w45 { width: 45%; }
.age-bar b.w50 { width: 50%; }
.age-bar b.w55 { width: 55%; }
.age-bar b.w60 { width: 60%; }
.age-bar b.w65 { width: 65%; }
.age-bar b.w70 { width: 70%; }
.age-bar b.w75 { width: 75%; }
.age-bar b.w80 { width: 80%; }
.age-bar b.w85 { width: 85%; }
.age-bar b.w90 { width: 90%; }
.age-bar b.w95 { width: 95%; }
.age-bar b.w100 { width: 100%; }
@media (max-width: 900px) { .aging { grid-template-columns: 1fr 1fr; } }

/* ---------- cash book report ---------- */
.seg { display: inline-flex; gap: 0; border: 1px solid var(--line); border-radius: 9px; padding: 3px; margin-bottom: .9rem; background: var(--bg); }
.seg label { display: inline-flex; align-items: center; padding: .35rem .9rem; border-radius: 7px; font-size: .88rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg label input { position: absolute; opacity: 0; pointer-events: none; }
.seg label.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.seg label:focus-within { outline: 2px solid var(--brand); }
.filter-actions .quick a { padding: .2rem .55rem; border-radius: 999px; }
.filter-actions .quick a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; text-decoration: none; }
.search-inline { width: 260px; }

.equation { display: flex; align-items: stretch; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.equation .eq { flex: 1 1 170px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.equation .eq span { display: block; font-size: .8rem; color: var(--muted); }
.equation .eq strong { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; margin: .1rem 0; }
.equation .eq.in strong { color: var(--good); }
.equation .eq.out strong { color: var(--bad); }
.equation .eq.total { border: 2px solid var(--ink); }
.equation .eq.muted-eq strong { color: var(--muted); font-size: 1.1rem; }
.equation .op { align-self: center; font-size: 1.5rem; font-weight: 300; color: var(--muted); }

.ledger { font-variant-numeric: tabular-nums; }
.ledger td.num, .ledger th.num { white-space: nowrap; }
.ledger tfoot tr.grand td { border-top: 2px solid var(--ink); border-bottom: 3px double var(--ink); font-weight: 700; padding: .6rem; background: var(--bg); }
.book th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
.book tr.day td { background: var(--mute-bg); font-weight: 600; font-size: .84rem; color: var(--ink); padding: .4rem .6rem .4rem 1.2rem; letter-spacing: .01em; }
.book tr.subtotal td { border-top: 1px solid var(--axis); font-weight: 600; font-size: .85rem; color: var(--muted); background: var(--bg); }
.book tr.subtotal td.num { color: inherit; }
.book tr.subtotal td.pos { color: var(--good); }
.book tr.subtotal td.neg { color: var(--bad); }
.book tr.opening td { background: var(--info-bg); font-weight: 600; }
.book tr.void td { color: var(--muted); }
.book tr.void td.num { text-decoration: line-through; }
.book td.bal { font-weight: 600; border-left: 1px solid var(--line); }
.book .w-time { width: 4.5rem; color: var(--muted); }
.book td small { margin-top: .1rem; }
.table-scroll { overflow-x: auto; }
.check-line { margin: 0; padding: .7rem 1.2rem; font-size: .9rem; border-top: 1px solid var(--line); }
.check-line.ok { color: var(--good); background: var(--good-bg); }
.check-line.bad { color: var(--bad); background: var(--bad-bg); }
.warn-text { color: var(--warn) !important; }
.empty-state { text-align: center; padding: 2.2rem 1rem; }
.empty-state h2 { font-size: 1.15rem; }
.empty-state p { margin: .5rem 0; }
.empty-state .btn { margin: .2rem; }
.share { display: block; height: 4px; border-radius: 2px; background: var(--mute-bg); margin-top: .35rem; overflow: hidden; max-width: 240px; }
.share b { display: block; height: 100%; background: var(--series-1); }
.share b.w0 { width: 0%; }
.share b.w5 { width: 5%; }
.share b.w10 { width: 10%; }
.share b.w15 { width: 15%; }
.share b.w20 { width: 20%; }
.share b.w25 { width: 25%; }
.share b.w30 { width: 30%; }
.share b.w35 { width: 35%; }
.share b.w40 { width: 40%; }
.share b.w45 { width: 45%; }
.share b.w50 { width: 50%; }
.share b.w55 { width: 55%; }
.share b.w60 { width: 60%; }
.share b.w65 { width: 65%; }
.share b.w70 { width: 70%; }
.share b.w75 { width: 75%; }
.share b.w80 { width: 80%; }
.share b.w85 { width: 85%; }
.share b.w90 { width: 90%; }
.share b.w95 { width: 95%; }
.share b.w100 { width: 100%; }
@media print { .equation .eq, .card { box-shadow: none; } .book th { position: static; } .check-line { background: none; } }

/* ---------- messaging ---------- */
.hidden { display: none !important; }
.msg-tabs { flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.chip { font: inherit; font-size: .76rem; font-family: ui-monospace, Consolas, monospace; padding: .15rem .45rem; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--info); cursor: pointer; }
.chip:hover { border-color: var(--info); }
.counter { font-size: .8rem; color: var(--muted); margin-top: -.5rem; }
.bubble { border-radius: 12px; padding: .6rem .8rem; margin: .5rem 0; max-width: 420px; background: var(--mute-bg); border: 1px solid var(--line); }
.bubble.whatsapp { background: #dcf8c6; border-color: #c6eab0; color: #102a12; }
:root[data-theme="dark"] .bubble.whatsapp { background: #144d37; border-color: #1d6247; color: #e9fff3; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .bubble.whatsapp { background: #144d37; border-color: #1d6247; color: #e9fff3; } }
.bubble p { margin: .2rem 0 0; white-space: pre-wrap; }
.bubble small { color: inherit; opacity: .7; }
.msg-text { max-width: 460px; white-space: pre-wrap; font-size: .88rem; }
.nowrap { white-space: nowrap; }
.big-number { font-size: 1.1rem; margin: .2rem 0; }
.big-number strong { font-size: 1.8rem; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 0 1rem; }
.auto-table td { vertical-align: middle; }
.inline-field { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.inline-field input { width: 90px; padding: .25rem .4rem; }
.inline-form { margin-top: .6rem; }
.inline-test { flex-direction: row !important; align-items: flex-end; gap: .5rem; margin-top: .9rem; border-top: 1px solid var(--line); padding-top: .9rem; }
.inline-test label { flex: 1; }
.side nav a.nav-sub { padding-left: 2.15rem; font-size: .86rem; }
.side nav a.nav-sub.on { background: var(--side-on-bg); color: var(--side-on); }
.actions-right { order: 2; }

/* ---------- WhatsApp inbox / AI support ---------- */
.link-kpi { color: var(--ink); }
.link-kpi:hover { text-decoration: none; border-color: var(--axis); }
.pad-tabs { padding: .8rem 1rem 0; margin: 0; }
.chat-list { list-style: none; margin: 0; padding: 0; }
.chat-row { display: flex; gap: .75rem; align-items: center; padding: .75rem 1.2rem; border-top: 1px solid var(--line); color: var(--ink); }
.chat-row:hover { background: var(--bg); text-decoration: none; }
.chat-row.needs { border-left: 3px solid var(--bad); padding-left: calc(1.2rem - 3px); }
.chat-main { flex: 1; min-width: 0; }
.chat-main small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-end { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; flex: none; }
.chat-card { padding: 0; display: flex; flex-direction: column; }
.wa-thread { list-style: none; margin: 0; padding: 1rem; display: flex; flex-direction: column; gap: .5rem; background: var(--bg); max-height: 62vh; overflow-y: auto; border-radius: var(--radius) var(--radius) 0 0; }
.wa-thread li { display: flex; }
.wa-thread li.out { justify-content: flex-end; }
.wa-bubble { max-width: 75%; padding: .5rem .75rem; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.wa-thread li.out .wa-bubble { background: #dcf8c6; border-color: #c6eab0; color: #102a12; }
.wa-thread li.out.ai_agent .wa-bubble { background: var(--info-bg); border-color: transparent; color: var(--ink); }
:root[data-theme="dark"] .wa-thread li.out .wa-bubble { background: #144d37; border-color: #1d6247; color: #e9fff3; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .wa-thread li.out .wa-bubble { background: #144d37; border-color: #1d6247; color: #e9fff3; } }
.wa-thread li.out.ai_agent .wa-bubble { background: var(--info-bg) !important; border-color: transparent !important; color: var(--ink) !important; }
.wa-bubble p { margin: .15rem 0; white-space: pre-wrap; }
.wa-bubble .who { font-weight: 600; color: inherit; opacity: .75; }
.wa-bubble .meta { font-size: .72rem; color: inherit; opacity: .6; text-align: right; }
.reply-box { padding: 1rem; border-top: 1px solid var(--line); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wide-meta { grid-template-columns: 1fr; }
.wide-meta dd { word-break: break-all; }
