/* ==========================================================================
   Amiba — application styles
   Palette: Black + White + Red, red used as the accent (see specification).
   ========================================================================== */

:root {
  color-scheme: light;
  --brand: #F00000;          /* Amiba Red — accents, active states, focus */
  --brand-strong: #E00000;   /* solid buttons (white text ≥ 4.5:1) */
  --brand-hover: #C40000;
  --brand-text: #D00000;     /* red text on light surfaces */
  --brand-wash: rgba(240, 0, 0, 0.07);

  --ink: #050505;            /* Deep Black — main text */
  --ink-2: #3a3a3a;
  --muted: #737373;          /* Muted Gray — secondary text */
  --bg: #F5F5F5;             /* Light Gray — page */
  --surface: #FFFFFF;        /* White — cards */
  --surface-2: #FAFAFA;
  --surface-3: #F0F0F0;
  --border: #E5E5E5;
  --border-strong: #D4D4D4;

  --nav-bg: #151515;         /* Soft Black — navigation */
  --nav-ink: #D4D4D4;
  --nav-muted: #8A8A8A;
  --nav-hover: #222222;
  --nav-active: #050505;

  --good: #0B7A0B;  --good-bg: #EAF6EA;
  --warn: #8A5A00;  --warn-bg: #FFF4DB;
  --serious: #B34A12; --serious-bg: #FDEEE6;
  --danger: #C21A1A; --danger-bg: #FDECEC;
  --info: #1F5FAD;  --info-bg: #EAF2FC;

  --viz-revenue: #2A78D6;
  --viz-expense: #F00000;
  --viz-grid: #ECECEC;
  --viz-axis: #CFCFCF;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(5, 5, 5, 0.04), 0 1px 1px rgba(5, 5, 5, 0.03);
  --shadow-lg: 0 12px 32px rgba(5, 5, 5, 0.14);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-w: 248px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand-strong: #E00000; --brand-hover: #FF1F1F; --brand-text: #FF5A5A;
    --brand-wash: rgba(255, 42, 42, 0.12);
    --ink: #F5F5F5; --ink-2: #D4D4D4; --muted: #A3A3A3;
    --bg: #050505; --surface: #151515; --surface-2: #1A1A1A; --surface-3: #222222;
    --border: #2A2A2A; --border-strong: #3A3A3A;
    --nav-bg: #0B0B0B; --nav-hover: #1C1C1C; --nav-active: #151515;
    --good: #4CC24C; --good-bg: rgba(12, 163, 12, 0.14);
    --warn: #F2B544; --warn-bg: rgba(250, 178, 25, 0.13);
    --serious: #F0915F; --serious-bg: rgba(236, 131, 90, 0.14);
    --danger: #FF6B6B; --danger-bg: rgba(255, 60, 60, 0.13);
    --info: #6FA8EE; --info-bg: rgba(57, 135, 229, 0.14);
    --viz-revenue: #3987E5; --viz-expense: #F52A2A; --viz-grid: #262626; --viz-axis: #3A3A3A;
    --shadow: none; --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
  }
  :root:not([data-theme="light"]) .logo-for-light { display: none; }
  :root:not([data-theme="light"]) .logo-for-dark { display: block; }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand-strong: #E00000; --brand-hover: #FF1F1F; --brand-text: #FF5A5A;
  --brand-wash: rgba(255, 42, 42, 0.12);
  --ink: #F5F5F5; --ink-2: #D4D4D4; --muted: #A3A3A3;
  --bg: #050505; --surface: #151515; --surface-2: #1A1A1A; --surface-3: #222222;
  --border: #2A2A2A; --border-strong: #3A3A3A;
  --nav-bg: #0B0B0B; --nav-hover: #1C1C1C; --nav-active: #151515;
  --good: #4CC24C; --good-bg: rgba(12, 163, 12, 0.14);
  --warn: #F2B544; --warn-bg: rgba(250, 178, 25, 0.13);
  --serious: #F0915F; --serious-bg: rgba(236, 131, 90, 0.14);
  --danger: #FF6B6B; --danger-bg: rgba(255, 60, 60, 0.13);
  --info: #6FA8EE; --info-bg: rgba(57, 135, 229, 0.14);
  --viz-revenue: #3987E5; --viz-expense: #F52A2A; --viz-grid: #262626; --viz-axis: #3A3A3A;
  --shadow: none; --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
}
:root[data-theme="dark"] .logo-for-light { display: none; }
:root[data-theme="dark"] .logo-for-dark { display: block; }

/* ---- Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 8px; }
small, .muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.92em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
svg.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }

/* ---- Shell: sidebar + main ---------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: var(--nav-bg); color: var(--nav-ink);
  display: flex; flex-direction: column; overflow-y: auto;
  transition: transform 0.2s ease;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 18px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand img, .brand .brand-logo { height: 38px; width: auto; max-width: 170px; object-fit: contain; display: block; }
.auth-art .brand-logo { height: 52px; max-width: 220px; }
.logo { display: block; width: auto; max-width: 220px; object-fit: contain; }
.logo-for-dark { display: none; }
.auth-logo { margin-bottom: 28px; }
@media (min-width: 861px) { .auth-logo { display: none; } }  /* the dark panel already shows it */
.nav { padding: 6px 12px 16px; flex: 1; }
.nav-section { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--nav-muted); padding: 16px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; margin: 1px 0; border-radius: 8px;
  color: var(--nav-ink); font-weight: 500; position: relative;
}
.nav a:hover { background: var(--nav-hover); color: #fff; text-decoration: none; }
.nav a.active { background: var(--nav-active); color: #fff; }
.nav a.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--brand);
}
.nav a.active .icon { color: var(--brand); }
.nav .count {
  margin-left: auto; background: var(--brand); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 1px 7px;
}
.sidebar-foot { padding: 14px 16px; border-top: 1px solid #242424; display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: #2A2A2A; color: #fff; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; flex: none;
}
.sidebar-foot .who { min-width: 0; flex: 1; }
.sidebar-foot .who strong { display: block; color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .who span { font-size: 12px; color: var(--nav-muted); }
.sidebar-foot a, .sidebar-foot button { color: var(--nav-muted); }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: 60px; display: flex; align-items: center; gap: 12px;
  padding: 0 28px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--border);
}
.topbar .spacer { flex: 1; }
.menu-toggle { display: none; }
.content { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }
.scrim { display: none; }

/* ---- Page header -------------------------------------------------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--ink); }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--brand-strong); border-color: var(--brand-strong); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
.btn-dark { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.btn-dark:hover { background: var(--ink-2); border-color: var(--ink-2); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: var(--surface); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; }
.btn-block { width: 100%; }
.icon-btn { width: 36px; padding: 0; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--brand-text); cursor: pointer; }

/* ---- Cards & grid ------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.between { justify-content: space-between; }

/* ---- Stat tiles --------------------------------------------------------- */
.stat { padding: 16px 18px; position: relative; overflow: hidden; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 550; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; }
.stat .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat.accent::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); }
.stat.hero .value { font-size: 34px; }
.value.pos { color: var(--good); }
.value.neg { color: var(--danger); }
.key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.key-revenue { background: var(--viz-revenue); }
.key-expense { background: var(--viz-expense); }

.segmented { display: inline-flex; background: var(--surface-3); border-radius: 8px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented a, .segmented button {
  padding: 5px 11px; border-radius: 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); border: 0;
  background: none; cursor: pointer; font-family: inherit;
}
.segmented a:hover { color: var(--ink); text-decoration: none; }
.segmented .on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---- Tables ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 650;
  color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2);
  white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tfoot td { font-weight: 700; border-top: 1px solid var(--border-strong); background: var(--surface-2); }
.table .num { text-align: right; }
.table th.num { text-align: right; }
.table a.row-link { color: var(--ink); font-weight: 600; }
.table td.nowrap .row-link, .table td.nowrap { white-space: nowrap; }
.table .sub { display: block; color: var(--muted); font-size: 12px; }
.table.compact td, .table.compact th { padding: 8px 12px; }
tr.is-cancelled td { color: var(--muted); }
tr.is-cancelled .row-link { text-decoration: line-through; color: var(--muted); }

/* ---- Badges ------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 600; line-height: 18px; white-space: nowrap; background: var(--surface-3); color: var(--ink-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge-draft { background: var(--surface-3); color: var(--muted); }
.badge-finalized { background: var(--warn-bg); color: var(--warn); }
.badge-partially_paid { background: var(--info-bg); color: var(--info); }
.badge-paid { background: var(--good-bg); color: var(--good); }
.badge-cancelled { background: var(--danger-bg); color: var(--danger); }
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-admin { background: var(--ink); color: var(--surface); }
.badge-admin::before { background: var(--brand); }

/* ---- Forms -------------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label-text { font-weight: 600; font-size: 13px; color: var(--ink-2); }
.field .req { color: var(--brand-text); }
.field .help { font-size: 12px; color: var(--muted); }
.field .error, .errorlist { color: var(--danger); font-size: 12.5px; margin: 0; padding: 0; list-style: none; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"],
input[type="search"], input[type="tel"], input[type="url"], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 11px; min-height: 38px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-wash);
}
.field.has-error input, .field.has-error select, .field.has-error textarea, .input-error { border-color: var(--danger) !important; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); width: 16px; height: 16px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.radio-group > div { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-group label {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border-strong);
  border-radius: 8px; cursor: pointer; font-weight: 500;
}
.radio-group label:has(input:checked) { border-color: var(--brand); background: var(--brand-wash); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.input-prefix { position: relative; }
.input-prefix > span { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-prefix > input { padding-left: 26px; }

/* Filter bar (wrapped in <details> so phones can collapse it) */
details.filters-wrap > summary {
  display: none; align-items: center; gap: 8px; padding: 12px 18px; cursor: pointer; font-weight: 600;
  border-bottom: 1px solid var(--border); list-style: none;
}
details.filters-wrap > summary::-webkit-details-marker { display: none; }
details.filters-wrap > summary .badge { margin-left: auto; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 14px 18px;
  border-bottom: 1px solid var(--border); }
.filters .field { flex: 1 1 150px; max-width: 240px; }
.filters .field.wide { flex: 2 1 220px; max-width: 320px; }
.filters .field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.filters input, .filters select { min-height: 36px; padding: 6px 10px; }
.filters .filter-actions { display: flex; gap: 6px; }

/* ---- Alerts / messages -------------------------------------------------- */
.messages { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.alert {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 8px; border: 1px solid transparent;
  background: var(--info-bg); color: var(--ink);
}
.alert .icon { margin-top: 1px; }
.alert-success { background: var(--good-bg); border-color: color-mix(in srgb, var(--good) 25%, transparent); }
.alert-success .icon { color: var(--good); }
.alert-error { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-error .icon { color: var(--danger); }
.alert-warning { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-warning .icon { color: var(--warn); }
.alert-info .icon { color: var(--info); }
.alert .close { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; }

/* ---- Pagination --------------------------------------------------------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px;
  border-top: 1px solid var(--border); flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.pagination .pages { display: flex; gap: 4px; }

/* ---- Empty state -------------------------------------------------------- */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .icon { width: 36px; height: 36px; color: var(--border-strong); margin-bottom: 8px; }
.empty h3 { color: var(--ink); margin-bottom: 4px; }

/* ---- Definition lists / detail ----------------------------------------- */
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.totals { margin-left: auto; width: min(340px, 100%); }
.totals .line { display: flex; justify-content: space-between; padding: 6px 0; color: var(--ink-2); }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; font-size: 18px; font-weight: 750; color: var(--ink); }
.totals .grand span:last-child { color: var(--ink); }

/* ---- Lists (low stock, top products) ----------------------------------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .grow strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .grow span { font-size: 12px; color: var(--muted); }
.meter { height: 6px; border-radius: 3px; background: var(--danger-bg); overflow: hidden; margin-top: 5px; }
.meter > i { display: block; height: 100%; background: var(--danger); border-radius: 3px; }

/* ---- Charts ------------------------------------------------------------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--viz-grid); stroke-width: 1; }
.chart .baseline { stroke: var(--viz-axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar-revenue { fill: var(--viz-revenue); }
.chart .bar-expense { fill: var(--viz-expense); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover, .chart .hit.on { fill: color-mix(in srgb, var(--ink) 5%, transparent); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 170px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 10px 12px;
  font-size: 12.5px; transform: translate(-50%, calc(-100% - 10px));
}
.tooltip strong { display: block; margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .t-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.tooltip .t-row b { font-variant-numeric: tabular-nums; }
.hbar { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr auto; align-items: center; gap: 10px; padding: 7px 0; }
.hbar .track { height: 10px; background: var(--surface-3); border-radius: 0 4px 4px 0; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; }
.hbar .fill.revenue { background: var(--viz-revenue); }
.hbar .fill.expense { background: var(--viz-expense); }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.table-view summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin-top: 10px; }

/* ---- Dialog ------------------------------------------------------------- */
dialog.modal {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(5, 5, 5, 0.55); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); }

/* ---- Invoice builder ---------------------------------------------------- */
.builder-lines th, .builder-lines td { padding: 8px 8px; }
.builder-lines td { vertical-align: top; }
.builder-lines input { min-height: 36px; padding: 6px 9px; }
.builder-lines .c-qty { width: 90px; }
.builder-lines .p-meta { overflow-wrap: anywhere; }
.builder-lines .c-price { width: 140px; }
.builder-lines .c-disc { width: 120px; }
.builder-lines .c-total { width: 130px; padding-top: 16px; }
.builder-lines .c-del { width: 44px; }
.line-error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); max-height: 280px; overflow-y: auto;
  margin: 0; padding: 4px; list-style: none; min-width: 260px;
}
.combo-list li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.combo-list li[aria-selected="true"], .combo-list li:hover { background: var(--surface-3); }
.combo-list li .sub { color: var(--muted); font-size: 12px; }
.combo-list .none { color: var(--muted); cursor: default; }
.picked { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.picked strong { display: block; }
.picked .sub { color: var(--muted); font-size: 12px; }
.sticky-summary { position: sticky; top: 76px; }
.inv-title { text-align: right; }

/* ---- Auth pages --------------------------------------------------------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-art {
  background: var(--nav-bg); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth-art::after {
  content: ""; position: absolute; right: -120px; bottom: -120px; width: 420px; height: 420px; border-radius: 50%;
  border: 56px solid var(--brand); opacity: 0.9;
}
.auth-art h2 { font-size: 34px; line-height: 1.15; max-width: 420px; font-weight: 750; letter-spacing: -0.03em; }
.auth-art h2 em { color: var(--brand); font-style: normal; }
.auth-art p { color: #A3A3A3; max-width: 380px; margin-top: 14px; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 32px 20px; background: var(--surface); }
.auth-form .inner { width: min(380px, 100%); }
.auth-form h1 { font-size: 26px; margin-bottom: 6px; }
.auth-form .sub { color: var(--muted); margin-bottom: 24px; }
.auth-form .field { margin-bottom: 14px; }
.qr { background: #fff; padding: 10px; border-radius: 10px; border: 1px solid var(--border); width: 200px; }

/* ---- Tabs --------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 12px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--brand); }

/* ---- Timeline (activity) ----------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); margin-top: 7px; flex: none; }
.timeline .dot.red { background: var(--brand); }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .sticky-summary { position: static; }
}
@media (min-width: 561px) and (max-width: 1100px) {
  .hide-md { display: none !important; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(5, 5, 5, 0.5); z-index: 35; }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .content { padding: 18px 16px 40px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
}
@media (max-width: 560px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid-4 .stat { padding: 12px 14px; }
  .grid-4 .stat .value { font-size: 17px; }
  .grid-4 .stat .meta { font-size: 11.5px; }
  .grid-4 .stat.hero { grid-column: 1 / -1; }
  details.filters-wrap > summary { display: flex; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .filters .field, .filters .field.wide { max-width: none; flex-basis: 100%; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 8px; }
  .page-head .actions { width: 100%; }
  .stat .value { font-size: 21px; }
  /* Stack table rows as cards on phones: label on the left, the cell's content kept together on the right. */
  table.stack-sm thead { display: none; }
  table.stack-sm, table.stack-sm tbody, table.stack-sm tfoot, table.stack-sm tr, table.stack-sm td { display: block; width: 100%; }
  table.stack-sm tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.stack-sm tbody tr:hover td { background: transparent; }
  table.stack-sm td { border: 0; padding: 5px 16px; text-align: right; overflow-wrap: anywhere; white-space: normal; }
  table.stack-sm td[data-label]::before {
    content: attr(data-label); float: left; margin-right: 12px; color: var(--muted); font-size: 12px; font-weight: 600;
    text-align: left; line-height: 21px;
  }
  table.stack-sm td::after { content: ""; display: block; clear: both; }
  table.stack-sm td:not([data-label]) { text-align: center; }
  table.stack-sm td .sub { display: block; }

  /* 1) Invoice builder lines: product on its own row, qty / price / discount side by side. */
  table.stack-sm.builder-lines tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; padding: 14px 16px; }
  table.stack-sm.builder-lines td { width: auto; padding: 0; text-align: left; }
  table.stack-sm.builder-lines td[data-label]::before { float: none; display: block; margin: 0 0 4px; line-height: 1.3; }
  table.stack-sm.builder-lines td[data-label="Product"] { grid-column: 1 / -1; }
  table.stack-sm.builder-lines td.c-total { grid-column: 1 / 3; align-self: center; padding-top: 0; font-size: 15px; }
  table.stack-sm.builder-lines td.c-total::before { display: inline; margin-right: 8px; }
  table.stack-sm.builder-lines td.c-del { grid-column: 3; justify-self: end; align-self: center; }
  table.stack-sm.builder-lines input { width: 100%; }
  .hide-sm { display: none !important; }
  .inv-title { text-align: left !important; }
}

/* ---- Print -------------------------------------------------------------- */
@media print {
  .sidebar, .topbar, .page-head .actions, .no-print, .filters, .pagination { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; }
  .card { box-shadow: none; border-color: #ccc; }
  body { background: #fff; }
}
@media (forced-colors: active) {
  .chart .bar-revenue, .chart .bar-expense, .hbar .fill { fill: CanvasText; background: CanvasText; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Number boxes with thousands separators (data-number) */
input.num-input, input[data-number] { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Compact list rows on phones ----------------------------------------
   <table class="table m-list">: on phones each row becomes a 2–3 line list item.
   Only cells marked .m-main (left: title + detail lines), .m-end (right: amount/status)
   and .m-actions (right, under .m-end) are shown; everything else lives on desktop only.
   Put phone-only detail lines in .m-line elements inside .m-main. */
.m-line, .m-only { display: none; }
@media (max-width: 560px) {
  table.m-list thead { display: none; }
  table.m-list, table.m-list tbody, table.m-list tfoot { display: block; width: 100%; }
  table.m-list tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "main end" "main actions";
    column-gap: 14px; row-gap: 4px; align-items: start; padding: 12px 16px;
    border-bottom: 1px solid var(--border); position: relative;
  }
  table.m-list tbody tr:last-child { border-bottom: 0; }
  table.m-list tbody tr:hover td { background: transparent; }
  table.m-list tbody tr:active { background: var(--surface-2); }
  table.m-list td { display: none; padding: 0; border: 0; background: transparent; }
  table.m-list td.m-main { display: block; grid-area: main; min-width: 0; }
  table.m-list td.m-end { display: block; grid-area: end; text-align: right; white-space: nowrap; }
  table.m-list td.m-actions { display: flex; gap: 4px; grid-area: actions; justify-self: end; position: relative; z-index: 1; }
  table.m-list tbody td[colspan] { display: block; grid-column: 1 / -1; }
  table.m-list tfoot tr { background: var(--surface-2); }
  table.m-list tfoot td.m-main, table.m-list tfoot td.m-end { font-weight: 700; }
  table.m-list .m-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; }
  table.m-list .m-title > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  table.m-list .m-line {
    display: block; font-size: 13px; color: var(--ink-2); margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  table.m-list .m-line.muted { color: var(--muted); font-size: 12.5px; }
  table.m-list .m-line.wrap {
    white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  }
  table.m-list .m-only { display: block; }
  table.m-list .m-only.m-title { display: flex; }   /* keep the ellipsis layout for phone titles */
  table.m-list td.m-main > .sub { display: none; }   /* desktop sub-lines are replaced by .m-line */
  table.m-list .m-end .amount { font-weight: 700; font-size: 14.5px; }
  table.m-list .m-end .m-line { margin-top: 3px; }
  table.m-list .m-end .badge { margin-top: 4px; }
  /* Whole row is tappable when its title is a link. */
  table.m-list .row-link::after { content: ""; position: absolute; inset: 0; }
  table.m-list .m-desktop-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}
