/* Customer Manager — application styles. Light and dark themes follow the OS setting. */
:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #f7f9f8;
  --ink: #15211d;
  --muted: #64716c;
  --line: #e1e7e4;
  --line-strong: #c9d3cf;
  --accent: #0b7a4b;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3ea;
  --side: #10241e;
  --side-ink: #a9bdb5;
  --side-active: #1d3a31;
  --danger: #c0392b;
  --danger-soft: #fbe9e7;
  --warn: #b26a00;
  --warn-soft: #fff3df;
  --info: #2459a8;
  --info-soft: #e7effb;
  --c0: #0b7a4b; --c1: #2f80c9; --c2: #d08a1a; --c3: #8e5bb8; --c4: #cf4f45; --c5: #5c8f8a;
  --bronze: #a8692e; --silver: #6f7d86; --gold: #b88a00; --platinum: #3f51a6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 36, 30, .05), 0 1px 1px rgba(16, 36, 30, .03);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513; --surface: #151e1b; --surface-2: #1a2522; --ink: #e4ece8; --muted: #93a39d;
    --line: #26332f; --line-strong: #34433e; --accent: #34c486; --accent-ink: #06140e; --accent-soft: #143326;
    --side: #0a110f; --side-ink: #8fa59c; --side-active: #18302a;
    --danger: #ff7a6b; --danger-soft: #3a1a17; --warn: #f0b04a; --warn-soft: #33260f; --info: #7fb0ff; --info-soft: #172741;
    --c0: #34c486; --c1: #5aa8f0; --c2: #f0b04a; --c3: #b88ae0; --c4: #ff7a6b; --c5: #7fbcb5;
    --bronze: #d08c4c; --silver: #9aa8b1; --gold: #e2b52a; --platinum: #8a9bf0;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14.5px/1.5 var(--font); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0; letter-spacing: -.01em; text-wrap: balance; }
h2 { font-size: 1rem; margin: 0; }
h3 { font-size: .9rem; margin: 0 0 .6rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.mono { font-family: var(--mono); font-size: .9em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ic { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex: none; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 20px 18px 18px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; letter-spacing: .02em; flex: none; }
.brand strong { display: block; font-size: .95rem; line-height: 1.2; }
.brand small { color: var(--side-ink); font-size: .74rem; letter-spacing: .04em; text-transform: uppercase; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; flex: 1; }
.sidebar nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px; color: var(--side-ink); font-weight: 500; }
.sidebar nav a:hover { background: var(--side-active); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar .count { margin-left: auto; font-style: normal; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.nav-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; padding: 18px 12px 6px; opacity: .7; }
.side-foot { padding: 14px 22px; font-size: .75rem; opacity: .5; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 12px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.menu-btn { display: none; background: none; border: 0; color: var(--ink); padding: 6px; cursor: pointer; }
.search { flex: 1; max-width: 460px; display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; color: var(--muted); }
.search input { border: 0; background: transparent; padding: 9px 0; width: 100%; }
.search input:focus { outline: none; }
.search:focus-within { border-color: var(--accent); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.userchip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: .8rem; flex: none; }
.avatar.lg { width: 56px; height: 56px; font-size: 1.15rem; }
.who { display: flex; flex-direction: column; line-height: 1.2; }
.who small { color: var(--muted); font-size: .75rem; }
.icon-btn { color: var(--muted); display: grid; place-items: center; padding: 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--danger); }
.content { padding: 26px 28px 40px; max-width: 1320px; width: 100%; }

/* ---------- Page pieces ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { margin-top: 4px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.card-body { padding: 18px 20px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 20px; }
.grid > .card { margin-bottom: 0; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.stack { display: flex; flex-direction: column; gap: 20px; }
.mb { margin-bottom: 20px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi .label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi .value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; overflow-wrap: anywhere; }
.kpi .sub { font-size: .82rem; color: var(--muted); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi.alert .value { color: var(--danger); }
.delta-up { color: var(--accent); font-weight: 600; }
.delta-down { color: var(--danger); font-weight: 600; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td .sub { display: block; color: var(--muted); font-size: .8rem; }
tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--line); }
.cust-cell { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.empty { padding: 34px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .72rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.b-platinum { background: var(--platinum); color: #fff; border-color: transparent; }
.b-gold { background: var(--gold); color: #fff; border-color: transparent; }
.b-silver { background: var(--silver); color: #fff; border-color: transparent; }
.b-bronze { background: var(--bronze); color: #fff; border-color: transparent; }
.b-paid, .b-active, .b-done { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.b-partial, .b-at-risk, .b-due-today, .b-low-stock { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.b-unpaid, .b-lapsed, .b-overdue, .b-out-of-stock, .b-inactive { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.b-new, .b-upcoming, .b-admin { background: var(--info-soft); color: var(--info); border-color: transparent; }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); padding: 8px 15px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; line-height: 1.3; }
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn .ic { width: 16px; height: 16px; }
.btn-sm { padding: 6px 11px; font-size: .86rem; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); filter: none; }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link-btn.danger { color: var(--danger); }

input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 11px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: .82rem; font-weight: 600; }
.field small { color: var(--muted); font-size: .78rem; }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding-top: 18px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.filters input[type=search] { flex: 1 1 220px; }
.filters select, .filters input[type=date] { width: auto; }
.period { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.period select, .period input { width: auto; }
.custom-range { display: inline-flex; gap: 6px; align-items: center; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-weight: 500; }
.flash-ok { background: var(--accent-soft); color: var(--accent); }
.flash-err { background: var(--danger-soft); color: var(--danger); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.pager .muted { margin-right: auto; font-size: .85rem; }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .bar { fill: var(--accent); opacity: .55; }
.chart .bar-current { opacity: 1; }
.chart .bar:hover { opacity: .9; }
.chart .line { fill: none; stroke: var(--c2); stroke-width: 2; }
.chart .dot { fill: var(--surface); stroke: var(--c2); stroke-width: 2; }
.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut { width: 170px; flex: none; }
.donut-bg { stroke: var(--surface-2); }
.donut-num { fill: var(--ink); font-size: 22px; font-weight: 700; font-family: var(--font); }
.seg-0 { stroke: var(--c0); background: var(--c0); } .seg-1 { stroke: var(--c1); background: var(--c1); }
.seg-2 { stroke: var(--c2); background: var(--c2); } .seg-3 { stroke: var(--c3); background: var(--c3); }
.seg-4 { stroke: var(--c4); background: var(--c4); } .seg-5 { stroke: var(--c5); background: var(--c5); }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 150px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.legend b { margin-left: auto; font-variant-numeric: tabular-nums; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.spark { width: 120px; height: 32px; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 1.8; }
.spark-area { fill: var(--accent-soft); }
.spark-dot { fill: var(--accent); }
.legend-inline { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); }
.legend-inline i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.hbar { display: grid; grid-template-columns: minmax(90px, 140px) 1fr auto; gap: 10px; align-items: center; margin-bottom: 10px; font-size: .88rem; }
.hbar .track { background: var(--surface-2); border-radius: 99px; height: 9px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 99px; background: var(--accent); }

/* ---------- Customer profile ---------- */
.profile { display: flex; gap: 16px; align-items: center; }
.profile h1 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dl { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 9px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: .86rem; }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 34px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.tl-ic { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-size: .7rem; font-weight: 700; }
.tl-meta { font-size: .8rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 0; }
.chips li { background: var(--surface-2); border: 1px solid var(--line); padding: 4px 11px; border-radius: 99px; font-size: .85rem; }

/* ---------- Sale form ---------- */
.items-table td { padding: 8px 8px; }
.items-table input, .items-table select { padding: 7px 9px; }
.items-table .c-qty { width: 90px; } .items-table .c-price { width: 150px; } .items-table .c-total { width: 150px; } .items-table .c-del { width: 40px; }
.totals { margin-left: auto; width: min(340px, 100%); display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; padding: 16px 20px; }
.totals .grand { font-size: 1.2rem; font-weight: 800; border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- Auth & installer ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--side); }
.auth-card { background: var(--surface); border-radius: 14px; padding: 32px; width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.auth-card.wide { width: min(640px, 100%); }
.auth-card h1 { margin: 14px 0 4px; }
.auth-card .form-grid { grid-template-columns: 1fr; }
.auth-card .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.demo-logins { margin-top: 18px; font-size: .84rem; background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
.demo-logins code { font-family: var(--mono); }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px 16px; margin: 0 0 16px; }
legend { font-weight: 700; padding: 0 6px; }

/* ---------- Invoice (print) ---------- */
.invoice { background: #fff; color: #15211d; max-width: 820px; margin: 0 auto; padding: 44px; border: 1px solid var(--line); border-radius: var(--radius); }
.invoice table th { background: #f3f5f4; color: #64716c; }
.invoice td, .invoice th { border-color: #e1e7e4; }
.inv-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 30px; }
.inv-title { font-size: 2rem; font-weight: 800; letter-spacing: .04em; color: #0b7a4b; }
.inv-meta { display: grid; grid-template-columns: auto auto; gap: 3px 14px; font-size: .9rem; }
.inv-meta dt { color: #64716c; } .inv-meta dd { margin: 0; text-align: right; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 26px; }
.inv-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #64716c; font-weight: 700; margin-bottom: 4px; }
.inv-foot { margin-top: 34px; padding-top: 16px; border-top: 1px solid #e1e7e4; color: #64716c; font-size: .85rem; text-align: center; }
.stamp { display: inline-block; border: 3px solid currentColor; padding: 4px 14px; border-radius: 6px; font-weight: 800; letter-spacing: .1em; transform: rotate(-6deg); }
.stamp.paid { color: #0b7a4b; } .stamp.unpaid { color: #c0392b; } .stamp.partial { color: #b26a00; }

@media print {
  .sidebar, .topbar, .no-print, .flash { display: none !important; }
  body, .content { background: #fff; padding: 0; }
  .invoice { border: 0; padding: 0; max-width: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .g-3-1, .g-1-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .menu-btn { display: block; }
  .topbar { padding: 10px 16px; }
  .content { padding: 20px 16px 32px; }
  .who { display: none; }
  .g-2, .form-grid, .form-grid.c3, .inv-parties, .auth-card .form-grid.two { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .invoice { padding: 22px; }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .dl dd { margin-bottom: 8px; }
}
@media (max-width: 560px) {
  .top-actions .btn { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Invoices and statements always print on white */
.invoice { --ink: #15211d; --muted: #64716c; --line: #e1e7e4; --surface: #fff; --surface-2: #f3f5f4; --accent: #0b7a4b; color-scheme: light; }
