@import url("https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;500;600;700;800&display=swap");

:root {
  --bg: #efe8d9;
  --bg-2: #e7dfcc;
  --panel: #fffdf8;
  --panel-2: #f6f0e4;
  --ink: #171714;
  --muted: #5a5c56;
  --line: #d9d0be;
  --line-strong: #c3b79e;
  --sidebar: #141613;
  --sidebar-2: #1d1f1c;
  --gold: #8d5a10;
  --gold-bright: #c49a3c;
  --gold-soft: #f4e5c4;
  --green: #1f6b48;
  --green-soft: #e5f3ea;
  --red: #b42318;
  --red-soft: #fbe8e6;
  --blue: #1f4e79;
  --blue-soft: #e6eef6;
  --shadow: 0 18px 40px rgba(28, 26, 20, .1);
  --shadow-soft: 0 2px 10px rgba(28, 26, 20, .06);
  --radius: 16px;
  --radius-sm: 10px;
  --control: 48px;
  --focus: 0 0 0 3px rgba(141, 90, 16, .28);
  --space: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { background: var(--sidebar); }
body {
  color: var(--ink);
  background:
    radial-gradient(circle at 88% -12%, rgba(196, 154, 60, .16), transparent 28rem),
    linear-gradient(180deg, #f4eee1 0%, var(--bg) 42%);
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; opacity: .5; }
:focus { outline: none; }
:focus-visible {
  border-color: var(--gold) !important;
  box-shadow: var(--focus);
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 80;
  padding: 10px 14px;
  color: #fff;
  background: var(--ink);
  border-radius: 8px;
  transform: translateY(-160%);
}
.skip-link:focus { transform: none; }

.app {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  min-height: 100dvh;
}

aside {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: 76px;
  min-width: 0;
  height: 100dvh;
  padding: 18px 8px 16px;
  overflow: hidden;
  color: #f4efe4;
  background:
    linear-gradient(180deg, rgba(196, 154, 60, .08), transparent 28%),
    var(--sidebar);
  border-right: 1px solid #2a2c28;
  transition: width 180ms ease, padding 180ms ease, box-shadow 180ms ease;
}
aside:hover,
aside:focus-within {
  width: 272px;
  padding: 22px 14px 16px;
  box-shadow: 16px 0 32px rgba(20, 22, 19, .28);
}
aside:not(:hover):not(:focus-within) .brand {
  justify-content: center;
  padding: 4px 0 18px;
}
aside:not(:hover):not(:focus-within) .brand > div:last-child,
aside:not(:hover):not(:focus-within) .nav-label,
aside:not(:hover):not(:focus-within) .nav button span,
aside:not(:hover):not(:focus-within) .sidebar-footer > div {
  display: none;
}
aside:not(:hover):not(:focus-within) .nav button {
  justify-content: center;
  padding: 10px 0;
}
aside:not(:hover):not(:focus-within) .sidebar-footer {
  justify-content: center;
  padding: 12px 0 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 24px;
}
.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  place-items: center;
  color: #171714;
  background: linear-gradient(180deg, #e4c16a, #c49a3c);
  border: 1px solid #efd58a;
  border-radius: 12px;
  box-shadow: 0 8px 18px rgba(196, 154, 60, .24);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .04em;
}
.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -.02em;
  white-space: nowrap;
}
.brand p {
  margin: 3px 0 0;
  color: #b7b3a8;
  font-size: 12px;
  white-space: nowrap;
}

.nav {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  overflow: auto;
}
.nav-label {
  margin: 16px 12px 6px;
  color: #8d8a80;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.nav-label:first-child { margin-top: 0; }
.nav button {
  display: flex;
  min-height: var(--control);
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  color: #d8d4c8;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}
.nav button svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  stroke-width: 1.9;
}
.nav button:hover {
  color: #fff;
  background: rgba(255, 255, 255, .06);
}
.nav button.active {
  color: #fff8e8;
  background: #262823;
  border-color: #3a3c37;
  box-shadow: inset 3px 0 0 var(--gold-bright);
}
.nav button.active svg { color: var(--gold-bright); }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 12px 10px 4px;
  color: #ece8de;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: 12px;
}
.sidebar-footer strong, .sidebar-footer small { display: block; }
.sidebar-footer small { margin-top: 2px; color: #9b978c; }
.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  background: #5ea67c;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(94, 166, 124, .16);
}

main {
  min-width: 0;
  padding: 24px clamp(18px, 3vw, 40px) 48px;
}
.top {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page-heading { min-width: 0; }
.eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.top h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(28px, 3vw, 36px);
  font-weight: 780;
  line-height: 1.1;
  letter-spacing: -.04em;
}
.small { color: var(--muted); font-size: 13px; }
.top .small { margin-top: 4px; }
.page-meta {
  display: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  min-height: var(--control);
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover {
  background: #fff;
  border-color: #b7ab90;
  transform: translateY(-1px);
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  color: #fffaf1;
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: 0 10px 22px rgba(141, 90, 16, .22);
}
.btn.primary:hover {
  background: #75490c;
  border-color: #75490c;
}
.btn.danger {
  color: var(--red);
  background: #fff;
  border-color: #e3b4af;
}
.btn.danger:hover { background: var(--red-soft); }
.btn.success {
  color: #145a38;
  background: var(--green-soft);
  border-color: #b7d8c4;
}
.btn.success:hover {
  background: #d7eee0;
  border-color: #8fc9a8;
}
.top-cta {
  min-height: 52px;
  padding-inline: 18px;
  font-size: 16px;
}
.close,
.close {
  display: grid;
  width: var(--control);
  height: var(--control);
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  font-size: 28px;
  line-height: 1;
}
.close:hover,
.close:hover {
  color: var(--ink);
  background: var(--panel-2);
}

.section { display: none; }
.section.active {
  display: block;
  animation: rise 220ms ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.card {
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}
.card .card {
  background: var(--panel-2);
  box-shadow: none;
}
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 16px;
}
.stat {
  position: relative;
  min-height: 118px;
  overflow: hidden;
  padding: 16px 16px 16px 18px;
}
.stat::before {
  position: absolute;
  inset: 16px auto 16px 0;
  width: 3px;
  content: "";
  background: var(--gold-bright);
  border-radius: 0 4px 4px 0;
}
.stat .label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.stat .value {
  margin-top: 14px;
  color: var(--ink);
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.03em;
}
.stat .value.good, .good { color: var(--green); }
.stat .value.bad, .bad { color: var(--red); }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -.02em;
}
.toolbar input,
.search-field {
  flex: 1 1 280px;
  max-width: 460px;
}
.toolbar.page-actions { justify-content: flex-end; }
.filters .search-field,
.filter-search-field input {
  flex: none;
  max-width: none;
}

label {
  display: block;
  margin-bottom: 6px;
  color: #4e514b;
  font-size: 13px;
  font-weight: 700;
}
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fffef9;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
textarea { min-height: 88px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #8b8d86; }
input:hover, select:hover, textarea:hover { border-color: #aea48d; }
[aria-invalid="true"] {
  border-color: var(--red);
  background: #fff8f7;
}

.form-grid,
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.full { grid-column: 1 / -1; }

.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
  padding: 8px;
}
.chart-grid,
.chart-grid {
  display: grid;
  grid-template-columns: 1.3fr .7fr;
  gap: 16px;
  margin-bottom: 16px;
}
.chart-wrap,
.chart-wrap {
  position: relative;
  height: 300px;
  padding: 12px;
  overflow: hidden;
  background: #171916;
  border: 1px solid #2c2e2a;
  border-radius: 12px;
}
.chart-wrap canvas,
.chart-wrap canvas { max-width: 100%; max-height: 100%; }

table {
  width: 100%;
  min-width: 720px;
  border-collapse: separate;
  border-spacing: 0;
}
th, td {
  padding: 13px 12px;
  border-bottom: 1px solid #ebe4d4;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}
th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #6a6d66;
  background: #f4eee1;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable,
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td,
tbody tr.clickable:hover td { background: #faf4e6; }
td .btn { min-height: 40px; padding: 7px 10px; font-size: 13px; }

#customersTable, #vehiclesTable, #maintenanceTable, #inventoryTable,
#invoicesTable, #accountingTable, #accountingInvoicesTable, #accountingExpensesTable,
#techniciansTable, #suppliersTable, #dashboardReorderTable {
  min-height: 240px;
  max-height: 62vh;
  overflow: auto;
  background: rgba(255, 253, 248, .8);
  border: 1px solid var(--line);
  border-radius: 12px;
}
#customersTable table, #vehiclesTable table, #maintenanceTable table,
#inventoryTable table, #invoicesTable table, #accountingTable table,
#accountingInvoicesTable table, #accountingExpensesTable table,
#techniciansTable table, #suppliersTable table, #dashboardReorderTable table,
.platform-table {
  width: 100%;
  min-width: 1080px;
}

.badge {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  color: #4f524c;
  background: #efe9db;
  border: 1px solid #ddd4c0;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}
.badge.green, .green.badge {
  color: #1a5a3d;
  background: var(--green-soft);
  border-color: #b7d8c4;
}
.badge.gold, .gold.badge {
  color: #6f470b;
  background: var(--gold-soft);
  border-color: #e3c88a;
}
.badge.red {
  color: #922017;
  background: var(--red-soft);
  border-color: #ecc0bb;
}

.empty {
  padding: 48px 20px;
  color: var(--muted);
  text-align: center;
  background: repeating-linear-gradient(-45deg, transparent, transparent 8px, rgba(0,0,0,.015) 8px, rgba(0,0,0,.015) 16px);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(16, 17, 15, .72);
  backdrop-filter: blur(6px);
}
.modal.show { display: flex; }
.modal-box,
.modal-box {
  width: min(860px, 100%);
  max-height: calc(100dvh - 36px);
  padding: 0 20px 20px;
  overflow: auto;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .32);
}
.modal-box.wide,
.modal-box.wide { width: min(1240px, 100%); }
.modal-head,
.modal-head {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  margin: 0 -20px 18px;
  padding: 10px 20px;
  background: rgba(255, 253, 248, .96);
  border-bottom: 1px solid var(--line);
}
.modal-head h3,
.modal-head h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 750;
}

#invoiceModal .modal-box { padding-bottom: 0; }
#invoiceModal form > .actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 18px -20px 0 !important;
  padding: 12px 20px;
  background: rgba(255, 253, 248, .96);
  border-top: 1px solid var(--line);
}
.invoice-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}
.summary {
  padding: 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.summary::before {
  display: block;
  margin-bottom: 10px;
  content: "Invoice summary";
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.sum {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  color: var(--muted);
  font-size: 14px;
}
.sum strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.sum.total {
  margin-top: 8px;
  padding-top: 12px;
  color: var(--ink);
  border-top: 1px solid var(--line-strong);
  font-size: 18px;
  font-weight: 800;
}
.sum.total strong { color: var(--gold); }
.invoice-line-card {
  margin-bottom: 10px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold-bright);
  border-radius: 12px;
}
.invoice-line-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.invoice-line-fields {
  display: grid;
  grid-template-columns: 1.8fr .55fr .75fr .75fr .65fr .8fr .8fr;
  gap: 8px;
  align-items: end;
}
.invoice-line-fields.service { grid-template-columns: 2fr .85fr .7fr .9fr .9fr; }
.invoice-line-fields.external { grid-template-columns: 1.5fr 1.05fr .5fr .7fr .7fr .62fr .8fr .8fr; }
.line-metric {
  min-height: 44px;
  padding: 6px 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
.vehicle-box, .payment-context, .payment-fields {
  margin-top: 10px;
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.payment-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.balance-row { color: var(--red); }
.search-results {
  max-height: 200px;
  margin-top: 5px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}
.search-item {
  min-height: 48px;
  padding: 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.search-item:hover { background: var(--gold-soft); }
.validation-summary {
  display: none;
  margin-bottom: 12px;
  padding: 12px;
  color: #7a1c16;
  background: var(--red-soft);
  border: 1px solid #ecc0bb;
  border-radius: 10px;
}
.validation-summary.show { display: block; }
.flow-banner {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 14px;
  padding: 12px 14px;
  color: #1a4a35;
  background: var(--green-soft);
  border: 1px solid #b7d8c4;
  border-left: 4px solid var(--green);
  border-radius: 10px;
}
.table-actions { display: flex; min-width: 180px; flex-wrap: wrap; gap: 6px; }
.table-actions.compact .btn { min-height: 40px; }
.maint-status-cell {
  position: sticky;
  right: 0;
  z-index: 2;
  min-width: 220px;
  width: 220px;
  padding: 10px 12px !important;
  vertical-align: top;
  background: #fffdf8;
  box-shadow: -8px 0 14px rgba(28, 26, 20, .06);
}
#maintenanceTable .platform-table th:last-child {
  position: sticky;
  right: 0;
  z-index: 3;
  min-width: 220px;
  width: 220px;
  background: #f4eee1;
  box-shadow: -8px 0 14px rgba(28, 26, 20, .06);
}
tbody tr:hover td.maint-status-cell { background: #faf4e6; }
.maint-status-meta {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  margin-bottom: 8px;
}
.maint-status-meta .badge {
  min-height: 30px;
  justify-content: center;
  padding: 4px 10px;
  font-size: 12px;
}
.maint-status-meta .small {
  text-align: center;
}
.maint-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  min-width: 0;
}
.maint-actions .btn {
  min-height: 48px;
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
}
td.maint-status-cell .maint-actions .btn { min-height: 48px; }
.maint-actions .btn.primary,
.maint-actions .btn.success { grid-column: 1; }
.maint-actions .btn svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.settings-tabs,
.accounting-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.settings-tabs .btn,
.accounting-tabs .btn {
  min-width: 132px;
}
.settings-tabs button.active,
.accounting-tabs button.active {
  color: #fff8ec;
  background: var(--sidebar);
  border-color: var(--sidebar);
  box-shadow: 0 8px 18px rgba(20, 22, 19, .18);
}
.settings-panel { display: none; }
.settings-panel.active { display: block; }
.accounting-panel.active { animation: rise 220ms ease; }
.accounting-tabs .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tab-count {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  place-items: center;
  padding-inline: 6px;
  color: #5a5c56;
  background: #ece4d2;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.accounting-tabs .btn.active .tab-count {
  color: #171714;
  background: var(--gold-bright);
}

.backup-card {
  padding: 18px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.backup-card h4 { margin: 0 0 8px; font-size: 18px; }

.invoice-html-view,
.invoice-html-view {
  min-height: 520px;
  padding: 34px;
  color: #171714;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.invoice-html-view table { min-width: 0; }
.invoice-html-view th {
  color: #61645e;
  background: #f4eee1;
}
.invoice-meta {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 24px;
  margin: 24px 0;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.invoice-total-box { width: min(370px, 100%); margin: 24px 0 0 auto; }
.invoice-total-row {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 7px 0;
}
.invoice-grand-total {
  margin-top: 7px;
  padding-top: 12px;
  border-top: 2px solid var(--ink);
  font-size: 20px;
  font-weight: 800;
}
.invoice-doc-head,
.invoice-doc-head {
  display: flex;
  justify-content: space-between;
  gap: 30px;
  padding-bottom: 20px;
}
.invoice-brand-mark,
.invoice-brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: #171714;
  background: var(--gold-bright);
  border-radius: 10px;
  font-weight: 800;
}
.invoice-title { display: flex; align-items: flex-end; flex-direction: column; gap: 3px; text-align: right; }
.invoice-work, .invoice-notes, .invoice-work, .invoice-notes {
  margin-bottom: 14px;
  padding: 12px;
  background: var(--panel-2);
  border-left: 3px solid var(--gold-bright);
}
.invoice-kicker {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: grid;
  width: min(360px, calc(100vw - 36px));
  gap: 8px;
}
.toast {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--green);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.toast.error { border-left-color: var(--red); }
.toast strong, .toast span { display: block; }
.toast span { margin-top: 2px; color: var(--muted); font-size: 13px; }

.filters.platform-filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 6px;
  margin: 0 0 10px;
  padding: 6px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.filters.platform-filters label {
  margin-bottom: 2px;
  font-size: 11px;
  line-height: 1.2;
}
.filters.platform-filters input,
.filters.platform-filters select,
.filters.platform-filters textarea {
  min-height: 28px;
  padding: 3px 7px;
  font-size: 13px;
  border-radius: 6px;
}
.filters.platform-filters .btn {
  min-height: 28px;
  padding: 3px 8px;
  font-size: 12px;
  border-radius: 6px;
}
.platform-filter-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.platform-filter-head > div { display: flex; align-items: baseline; gap: 6px; }
.filter-toggle {
  display: flex;
  flex: 1;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 1px 4px;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
}
.filter-toggle:hover,
.filter-toggle:focus-visible {
  background: var(--gold-soft);
  border-color: var(--line-strong);
}
.filter-toggle-text { display: flex; align-items: center; gap: 8px; }
.filter-toggle-text strong { font-size: 12px; font-weight: 750; }
.filter-toggle-hint { display: none; }
.filter-arrow {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  color: #6f470b;
  background: var(--gold-soft);
  border: 1px solid #e3c88a;
  border-radius: 6px;
}
.filter-arrow svg {
  width: 14px;
  height: 14px;
  transition: transform 160ms ease;
}
.filters.platform-filters:not(.is-collapsed) .filter-arrow svg { transform: rotate(180deg); }
.filters.platform-filters.is-collapsed {
  grid-template-columns: 1fr;
  gap: 0;
  padding: 2px 6px;
}
.filters.platform-filters.is-collapsed .platform-filter-head {
  padding-bottom: 0;
  border-bottom: 0;
}
.filters.platform-filters.is-collapsed > :not(.platform-filter-head),
.filters.platform-filters.is-collapsed .filter-reset-cell {
  display: none !important;
}
.filter-status { color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; }
.filter-search-field { grid-column: span 2; }
.filter-reset-cell {
  display: flex;
  align-items: end;
  justify-content: flex-end;
}

.work-items-field {
  padding: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.repeatable-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}
.add-work-btn {
  color: #6f470b;
  background: var(--gold-soft);
  border-color: #e3c88a;
}
.work-items-list { display: grid; gap: 9px; }
.work-item-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
}
.work-item-row.readonly { grid-template-columns: 30px minmax(0, 1fr); }
.work-item-number {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  color: #6f470b;
  background: var(--gold-soft);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
}
.work-item-control { min-width: 0; }
.work-item-input { min-height: 62px; resize: vertical; }
.work-item-actions {
  display: grid;
  gap: 8px;
  min-width: 168px;
}
.work-item-bill {
  display: flex;
  min-height: var(--control);
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: #145a38;
  background: var(--green-soft, #e7f5ec);
  border: 1px solid #b7d8c4;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}
.work-item-bill-input {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  accent-color: #1f7a46;
}
.work-item-row.not-billed .work-item-bill {
  color: #6f470b;
  background: var(--gold-soft);
  border-color: #e3c88a;
}
.work-item-row.not-billed .work-item-input {
  opacity: .78;
}
.work-item-remove {
  min-width: 120px;
  min-height: var(--control);
}
.invoice-line-note { color: var(--muted); font-size: 12px; }
#invoiceForm input[readonly],
#invoiceForm textarea[readonly],
#invoiceForm select:disabled {
  color: #3f423c;
  background: #efe9db;
  border-color: #d5cdb8;
  cursor: default;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.bottom-nav { display: none; }

@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters:not(.is-collapsed),
  .filters.platform-filters:not(.is-collapsed) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .invoice-layout { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .chart-grid, .chart-grid, .grid.two { grid-template-columns: 1fr; }
  .invoice-line-fields,
  .invoice-line-fields.service,
  .invoice-line-fields.external { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (hover: none) and (min-width: 761px) {
  .app { grid-template-columns: 272px minmax(0, 1fr); }
  aside,
  aside:hover,
  aside:focus-within {
    width: 272px;
    padding: 22px 14px 16px;
    box-shadow: none;
  }
  aside:not(:hover):not(:focus-within) .brand,
  aside:not(:hover):not(:focus-within) .nav button,
  aside:not(:hover):not(:focus-within) .sidebar-footer {
    justify-content: flex-start;
  }
  aside:not(:hover):not(:focus-within) .brand { padding: 4px 8px 24px; }
  aside:not(:hover):not(:focus-within) .brand > div:last-child,
  aside:not(:hover):not(:focus-within) .nav-label,
  aside:not(:hover):not(:focus-within) .nav button span,
  aside:not(:hover):not(:focus-within) .sidebar-footer > div {
    display: revert;
  }
  aside:not(:hover):not(:focus-within) .nav button { padding: 10px 12px; }
  aside:not(:hover):not(:focus-within) .sidebar-footer { padding: 12px 10px 4px; }
}
@media (prefers-reduced-motion: reduce) {
  aside, .filter-arrow svg { transition: none; }
}
@media (max-width: 760px) {
  .app { display: block; }
  aside { display: none; }
  main { padding: 16px 14px 108px; }
  .top { align-items: flex-start; }
  .top .small, .eyebrow { display: none; }
  .top .btn span { display: none; }
  .top-cta { width: 52px; padding: 0; }
  .stats, .filters:not(.is-collapsed), .form-grid, .form-grid, .filters.platform-filters:not(.is-collapsed) { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .filter-search-field, .platform-filter-head { grid-column: 1 / -1; }
  .modal { align-items: stretch; padding: 0; }
  .modal-box, .modal-box.wide, .modal-box, .modal-box.wide {
    width: 100%;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }
  .invoice-meta { grid-template-columns: 1fr; }
  .invoice-title { align-items: flex-start; text-align: left; }
  input, select, textarea { font-size: 16px; }
  .bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: flex;
    gap: 4px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    overflow-x: auto;
    background: #141613;
    border-top: 1px solid #2a2c28;
    scrollbar-width: none;
  }
  .bottom-nav::-webkit-scrollbar { display: none; }
  .bottom-nav button {
    display: flex;
    min-width: 76px;
    min-height: 64px;
    flex: 1 0 auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: #cfcabf;
    background: transparent;
    border: 0;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
  }
  .bottom-nav button svg { width: 20px; height: 20px; }
  .bottom-nav button.active {
    color: #fff8e8;
    background: #262823;
    box-shadow: inset 0 -3px 0 var(--gold-bright);
  }
}
@media (min-width: 1100px) {
  .page-meta { display: block; text-align: right; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .work-item-row { grid-template-columns: 28px minmax(0, 1fr); }
  .work-item-actions { grid-column: 2; min-width: 0; }
  .payment-fields { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
@media print {
  aside, .top, .no-print, .modal, .toast-region, .bottom-nav { display: none !important; }
  .app { display: block; }
  main { padding: 0; }
  .section { display: none !important; }
  #printArea { display: block !important; }
  body, .invoice-html-view, .invoice-html-view { background: #fff; box-shadow: none; }
}
