/* CrewCab — LINE-X McKinney team portal
   Shop-floor palette: concrete, liner black, signal yellow. Barlow is a
   highway-signage family; the condensed cut carries all the numbers. */

:root {
  --bg: #E7E9EA;          /* concrete */
  --panel: #FFFFFF;
  --panel-2: #F4F5F6;
  --ink: #1F2326;         /* liner black */
  --ink-2: #4E5962;       /* steel */
  --ink-3: #7B868F;
  --rule: #D3D7DA;
  --signal: #F5C518;      /* signal yellow */
  --signal-ink: #1F2326;
  --paid: #1F7A4D;
  --open: #2D5F8A;
  --overdue: #B3261E;
  --void: #8A939A;
  --focus: #2D5F8A;
  --shadow: 0 1px 0 rgba(31, 35, 38, .06), 0 8px 24px -12px rgba(31, 35, 38, .25);
  --bar-cur-edge: color-mix(in srgb, var(--signal) 62%, var(--ink));
  --bar-p1: var(--ink-2);
  --bar-p2: var(--ink-3);
  --bar-p3: color-mix(in srgb, var(--ink-3) 78%, var(--panel));
  --bar-p4: color-mix(in srgb, var(--ink-3) 62%, var(--panel));
  --radius: 6px;
  --cond: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --sans: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171A;
    --panel: #1D2125;
    --panel-2: #23282D;
    --ink: #E9ECEE;
    --ink-2: #AAB4BC;
    --ink-3: #7F8A93;
    --rule: #2F353B;
    --paid: #46B07C;
    --open: #6FA3D4;
    --overdue: #EF6B5F;
    --void: #6E7880;
    --focus: #F5C518;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 28px -14px rgba(0, 0, 0, .7);
    --bar-cur-edge: var(--signal);
    --bar-p3: color-mix(in srgb, var(--ink-3) 75%, var(--panel));
    --bar-p4: color-mix(in srgb, var(--ink-3) 50%, var(--panel));
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 var(--sans);
  font-feature-settings: 'tnum' 1;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Top band ---------- */

.band {
  background: var(--signal);
  color: var(--signal-ink);
  border-bottom: 3px solid var(--ink);
  padding: 0 max(16px, env(safe-area-inset-left));
}
@media (prefers-color-scheme: dark) { .band { border-bottom-color: #000; } }
.band-inner {
  max-width: 1180px; margin: 0 auto;
  display: flex; align-items: center; gap: 20px; min-height: 56px;
}
.brand {
  font: 700 24px/1 var(--cond);
  letter-spacing: .005em;
  text-decoration: none;
  display: flex; align-items: center; gap: 9px;
  white-space: nowrap;
}
.brand-mark { width: 38px; height: 22px; flex: none; overflow: visible; }
.brand-mark .bm-ink { fill: currentColor; }
.brand-mark .bm-cut { fill: var(--signal); }
.brand-mark .bm-wheel { fill: currentColor; stroke: var(--signal); stroke-width: 2.5; }
.brand-name { line-height: 1; }
.brand small {
  font: 600 14px/1 var(--cond); opacity: .75;
  padding-left: 10px; border-left: 2px solid currentColor; margin-left: 1px;
}
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a {
  font: 600 16px/1 var(--cond); text-decoration: none;
  padding: 9px 12px; border-radius: 4px;
}
.nav a[aria-current="page"] { background: var(--signal-ink); color: var(--signal); }
.nav a:not([aria-current="page"]):hover { background: rgba(31, 35, 38, .1); }
.band-right { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 14px; }
.sync { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.sync .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--signal-ink); }
.sync .dot.bad { background: #B3261E; box-shadow: 0 0 0 2px #fff; }
.icon-btn {
  border: 2px solid var(--signal-ink); background: transparent; border-radius: 4px;
  height: 34px; padding: 0 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  font: 600 15px/1 var(--cond);
}
.icon-btn:hover { background: var(--signal-ink); color: var(--signal); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn[aria-busy="true"] svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.user-menu { position: relative; }
.user-menu > button { border: 0; background: transparent; cursor: pointer; font: 600 15px/1 var(--cond); padding: 8px 4px; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  background: var(--panel); color: var(--ink); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--rule); min-width: 200px; padding: 6px; display: none;
}
.menu.open { display: block; }
.menu .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--rule); margin-bottom: 6px; font-size: 14px; color: var(--ink-2); }
.menu .who strong { display: block; color: var(--ink); font-weight: 600; }
.menu a, .menu button {
  display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 4px;
  border: 0; background: none; text-decoration: none; cursor: pointer; font-size: 15px;
}
.menu a:hover, .menu button:hover { background: var(--panel-2); }

/* ---------- Page ---------- */

main { max-width: 1180px; margin: 0 auto; padding: 28px max(16px, env(safe-area-inset-left)) 64px; }
h1, h2, h3 { font-family: var(--cond); font-weight: 700; line-height: 1.1; margin: 0; }
h1 { font-size: 30px; }
h2 { font-size: 24px; }
h3 { font-size: 19px; font-weight: 600; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }

/* ---------- Period strip: the one bold thing ---------- */

.periods {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--panel); border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  position: relative; z-index: 1;
}
.period {
  appearance: none; border: 0; background: none; text-align: left; cursor: pointer;
  padding: 22px 24px 22px; position: relative;
  border-right: 1px solid var(--rule);
  border-top: 6px solid transparent;
  display: grid; gap: 4px; align-content: start;
  text-decoration: none;
}
.period:last-child { border-right: 0; }
.period:first-child { border-top-left-radius: var(--radius); }
.period:last-child { border-top-right-radius: var(--radius); }
.period:hover { background: var(--panel-2); }
.period[aria-selected="true"] { border-top-color: var(--signal); background: var(--panel); }
.period[aria-selected="false"] { background: var(--panel-2); }
.period[aria-selected="false"] .amount { color: var(--ink-2); }
.period .name { font: 600 19px/1.1 var(--cond); display: flex; justify-content: space-between; gap: 8px; }
.period .range { font-size: 14px; color: var(--ink-3); }
.period .amount {
  font: 700 clamp(40px, 5.4vw, 64px)/1 var(--cond);
  letter-spacing: -.01em; margin: 10px 0 2px;
}
.period .amount .cents { font-size: .5em; vertical-align: .62em; margin-left: 1px; letter-spacing: 0; }
.period .count { font-size: 14px; color: var(--ink-2); }
.period .cash-basis, .period .with-tax { font-size: 14px; color: var(--ink-2); }
.period .cash-basis b { font-weight: 600; color: var(--ink); }

/* One month, reached from By month: the same block, not a tab. */
.periods.single { grid-template-columns: 1fr; }
.period.static { cursor: default; border-top-color: var(--signal); border-right: 0; }
.period.static:hover { background: none; }
.period.static .name { font-size: 26px; font-weight: 700; }
.back-link { font-size: 14px; font-weight: 500; color: var(--ink-2); text-decoration: none; justify-self: start; margin-bottom: 6px; }
.back-link:hover { text-decoration: underline; }

.split { margin-top: 14px; }
.split-bar {
  display: flex; height: 14px; border-radius: 3px; overflow: hidden;
  background: var(--rule);
}
.split-bar span { display: block; height: 100%; min-width: 0; transition: flex-grow .5s ease; }
.split-bar .s-paid { background: var(--paid); }
.split-bar .s-open { background: var(--open); }
.split-bar .s-overdue {
  background: repeating-linear-gradient(135deg, var(--overdue) 0 5px, color-mix(in srgb, var(--overdue) 70%, #000) 5px 10px);
}
.split-legend {
  display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 14px; color: var(--ink-2);
}
.split-legend b { font-weight: 600; color: var(--ink); }
.key { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.key.paid { background: var(--paid); }
.key.open { background: var(--open); }
.key.overdue { background: var(--overdue); }

/* ---------- Invoice list ---------- */

.list-panel {
  background: var(--panel); border-radius: 0 0 var(--radius) var(--radius); box-shadow: var(--shadow);
  border-top: 1px solid var(--rule);
}
.list-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px 24px; border-bottom: 1px solid var(--rule);
}
.list-head h2 { font-size: 21px; margin-right: auto; }
.filters { display: flex; gap: 4px; background: var(--panel-2); padding: 3px; border-radius: 5px; }
.filters button {
  border: 0; background: none; padding: 6px 11px; border-radius: 3px; cursor: pointer; font-size: 14px; font-weight: 500;
  color: var(--ink-2);
}
.filters button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.filters .n { color: var(--ink-3); margin-left: 4px; }
.search {
  border: 1px solid var(--rule); background: var(--panel); border-radius: 5px; padding: 7px 10px; width: 200px;
  font-size: 15px;
}

table.sales { width: 100%; border-collapse: collapse; }
.sales th {
  text-align: left; font: 600 14px/1 var(--sans); color: var(--ink-3);
  padding: 12px 12px; border-bottom: 1px solid var(--rule);
}
.sales td { padding: 13px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.sales th:first-child, .sales td:first-child { padding-left: 24px; }
.sales th:last-child, .sales td:last-child { padding-right: 24px; }
.sales tbody tr { cursor: pointer; }
.sales tbody tr:hover td { background: var(--panel-2); }
.sales tbody tr:last-child td { border-bottom: 0; }
.sales .num { text-align: right; white-space: nowrap; }
.sales .doc { color: var(--ink-2); white-space: nowrap; }
.sales .cust { font-weight: 600; }
.sales .cust a { text-decoration: none; }
.sales .cust a:hover { text-decoration: underline; }
.sales .sub { display: block; font-weight: 400; font-size: 13px; color: var(--ink-3); }
.sales tr.is-void td { color: var(--ink-3); }
.sales tr.is-void .cust { text-decoration: line-through; font-weight: 500; }

.status {
  display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.paid { color: var(--paid); }
.status.open, .status.partial { color: var(--open); }
.status.overdue { color: var(--overdue); }
.status.void, .status.zero { color: var(--void); }

.empty { padding: 48px 24px; text-align: center; color: var(--ink-2); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }

.list-foot { padding: 12px 24px; font-size: 13px; color: var(--ink-3); border-top: 1px solid var(--rule); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- Money owed and cash received ---------- */

.money-band { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; margin-bottom: 16px; }
.money-card {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 24px;
  display: grid; gap: 4px; align-content: start; text-decoration: none; border-top: 6px solid var(--rule);
}
a.money-card:hover { background: var(--panel-2); }
.money-card h2.stat-label { margin: 0; }
.overdue-text { color: var(--overdue); font-weight: 600; }
table.cash-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.cash-table th, .cash-table td { padding: 3px 0 3px 12px; text-align: left; font-weight: 400; }
.cash-table th:first-child { padding-left: 0; }
.cash-table .num { text-align: right; white-space: nowrap; }
.cash-table thead th { color: var(--ink-3); font-weight: 600; font-size: 13px; }
.cash-table tfoot th, .cash-table tfoot td { font-weight: 700; border-top: 1px solid var(--rule); }
.cash-note { margin: 2px 0 0; font-size: 13px; color: var(--ink-3); }

.age-tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.age-tile {
  background: var(--panel); border: 2px solid transparent; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 14px; text-align: left; cursor: pointer; display: grid; gap: 1px;
}
.age-tile[aria-pressed="true"] { border-color: var(--ink); }
.age-tile:hover { background: var(--panel-2); }
.age-label { font-size: 14px; color: var(--ink-2); font-weight: 500; }
.age-amount { font: 700 24px/1.15 var(--cond); }
.age-count { font-size: 13px; color: var(--ink-3); }

table.owed-table { width: 100%; border-collapse: collapse; }
.owed-table thead th { font: 600 14px/1 var(--sans); color: var(--ink-3); text-align: left; padding: 12px; border-bottom: 1px solid var(--rule); }
.owed-table td { padding: 11px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.owed-table th:first-child, .owed-table td:first-child { padding-left: 24px; }
.owed-table th:last-child, .owed-table td:last-child { padding-right: 24px; }
.owed-table .num { text-align: right; white-space: nowrap; }
.owed-row { cursor: pointer; }
.owed-row:hover td { background: var(--panel-2); }
.owed-group th { background: var(--panel-2); text-align: left; padding: 9px 24px; font: 700 17px/1.2 var(--cond); border-bottom: 1px solid var(--rule); }
.group-total { float: right; font: 500 14px/1.4 var(--sans); color: var(--ink-2); }
.o-cust { font-weight: 600; }
.o-cust a { text-decoration: none; }
.o-cust a:hover { text-decoration: underline; }
.o-cust .sub { display: block; font-weight: 400; font-size: 13px; color: var(--ink-3); }
.o-balance { font-weight: 600; }
.o-last { font-size: 14px; color: var(--ink-2); white-space: nowrap; }
.o-call { text-align: right; white-space: nowrap; }

/* ---------- By month ---------- */

.monthly { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.month-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.month-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.month-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.month-stat {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 24px;
  display: grid; gap: 2px; border-top: 6px solid var(--signal);
}
.stat-label { font: 600 19px/1.1 var(--cond); }
.stat-value { font: 700 clamp(34px, 4.4vw, 48px)/1.05 var(--cond); letter-spacing: -.01em; }
.stat-note { font-size: 14px; color: var(--ink-2); }

.chg { font-weight: 600; white-space: nowrap; }
.chg.up { color: var(--paid); }
.chg.down { color: var(--overdue); }

.chart-card { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.chart-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 14px; color: var(--ink-2); }
.chart-legend b { color: var(--ink); font-weight: 600; }
.chart-legend .no-data { color: var(--ink-3); }
.chart-legend li, .read-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.swatch { width: 11px; height: 11px; flex: none; }
.chart-readout {
  display: flex; flex-wrap: wrap; gap: 2px 14px; align-items: center; min-height: 44px; align-content: center;
  font-size: 14px; color: var(--ink-2); border-top: 1px solid var(--rule); padding-top: 8px;
}
.chart-readout strong { color: var(--ink); font-weight: 600; }
.chart-readout b { color: var(--ink); font-weight: 600; }
.chart-frame { position: relative; }
.chart-scroll { overflow-x: auto; overscroll-behavior-x: contain; }
.chart-yaxis { display: none; position: absolute; left: 0; top: 0; background: var(--panel); pointer-events: none; }
.chart-svg { display: block; width: 100%; height: auto; }
.gridline { stroke: var(--rule); stroke-width: 1; }
.axis { stroke: var(--ink-3); stroke-width: 1; }
.tick { fill: var(--ink-3); font: 500 14px var(--sans); }
.month-label { fill: var(--ink-2); font: 500 15px var(--sans); }
.month-label.is-current { fill: var(--ink); font-weight: 700; }
.month-note { fill: var(--ink-3); font: 500 13px var(--sans); }
.bar-cur { fill: var(--signal); stroke: var(--bar-cur-edge); stroke-width: 1; }
.bar-p1 { fill: var(--bar-p1); }
.bar-p2 { fill: var(--bar-p2); }
.bar-p3 { fill: var(--bar-p3); }
.bar-p4 { fill: var(--bar-p4); }
.bar-none { fill: none; stroke: var(--ink-3); stroke-width: 1; }
.m-hit { fill: transparent; }
.m-group { cursor: default; outline: none; }
.m-group.is-active .m-hit { fill: var(--panel-2); }
.m-group:focus-visible .m-hit { stroke: var(--focus); stroke-width: 2; }

.month-panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); }
table.month-table { width: 100%; border-collapse: collapse; }
.month-table th, .month-table td { padding: 11px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; text-align: left; }
.month-table thead th { font: 600 14px/1 var(--sans); color: var(--ink-3); }
.month-table th:first-child { padding-left: 24px; }
.month-table th:last-child, .month-table td:last-child { padding-right: 24px; }
.month-table .num { text-align: right; white-space: nowrap; }
.month-table tbody th { font-weight: 600; }
.month-table td a { text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px; }
.month-table td a:hover { text-decoration-color: currentColor; }
.month-table .y-cur { font-weight: 600; }
.month-table .is-current th, .month-table .is-current td { background: color-mix(in srgb, var(--signal) 12%, var(--panel)); }
.month-table .is-future td { color: var(--ink-3); }
.month-table .y-cur a { text-decoration-color: var(--signal); text-decoration-thickness: 2px; }
.month-table .phone-only { display: none; }
.cell-note { display: block; font-size: 13px; font-weight: 400; color: var(--ink-2); white-space: nowrap; }
.month-table tfoot th, .month-table tfoot td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; }
.month-table tfoot .chg { font-weight: 700; }
.month-table tfoot .cell-note { font-weight: 400; }

/* ---------- Detail drawer ---------- */

.scrim {
  position: fixed; inset: 0; background: rgba(20, 23, 26, .45); z-index: 40;
  opacity: 0; transition: opacity .2s ease;
}
.scrim.show { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 41;
  background: var(--panel); box-shadow: -12px 0 40px -12px rgba(0,0,0,.35);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .24s cubic-bezier(.2,.8,.2,1);
}
.drawer.show { transform: none; }
.drawer-head {
  padding: 18px 24px 16px; border-bottom: 1px solid var(--rule);
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: start;
}
.drawer-head .kind { font-size: 14px; color: var(--ink-2); }
.drawer-head h2 { font-size: 28px; grid-column: 1; }
.close {
  grid-row: 1 / span 2; grid-column: 2;
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--rule); background: var(--panel);
  cursor: pointer; display: grid; place-items: center;
}
.close:hover { background: var(--panel-2); }
.drawer-body { overflow-y: auto; padding: 20px 24px 32px; flex: 1; }
.drawer-body section + section { margin-top: 26px; }
.drawer-body h3 { margin-bottom: 10px; }

.money-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--rule);
  border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden;
}
.money-row div { background: var(--panel); padding: 12px 14px; }
.money-row dt { font-size: 13px; color: var(--ink-2); }
.money-row dd { margin: 2px 0 0; font: 700 26px/1.1 var(--cond); }

dl.facts { display: grid; grid-template-columns: 120px 1fr; gap: 8px 14px; margin: 0; font-size: 15px; }
dl.facts dt { color: var(--ink-2); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
dl.facts a { color: var(--open); }

table.lines { width: 100%; border-collapse: collapse; font-size: 15px; }
.lines th { text-align: left; font-weight: 600; font-size: 13px; color: var(--ink-3); padding: 0 0 8px; border-bottom: 1px solid var(--rule); }
.lines td { padding: 10px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.lines td + td, .lines th + th { padding-left: 12px; }
.lines .num { text-align: right; white-space: nowrap; }
.lines .desc { color: var(--ink-2); font-size: 14px; display: block; }
.lines tfoot td { border-bottom: 0; padding: 6px 0; }
.lines tfoot tr.total td { font: 700 20px/1.2 var(--cond); padding-top: 10px; border-top: 2px solid var(--ink); }
.lines .discount td { color: var(--paid); }

.note { background: var(--panel-2); border-radius: var(--radius); padding: 12px 14px; font-size: 15px; white-space: pre-wrap; }
.drawer-foot { padding: 14px 24px; border-top: 1px solid var(--rule); display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Buttons & forms ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 5px; cursor: pointer; text-decoration: none;
  border: 2px solid var(--ink); background: var(--ink); color: var(--panel);
  font: 600 17px/1 var(--cond); letter-spacing: .01em;
}
.btn:hover { background: color-mix(in srgb, var(--ink) 85%, var(--panel)); }
.btn.secondary { background: transparent; color: var(--ink); }
.btn.secondary:hover { background: var(--panel-2); }
.btn.signal { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.btn.danger { background: transparent; color: var(--overdue); border-color: currentColor; }
.btn.small { height: 32px; padding: 0 10px; font-size: 15px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

label.field { display: grid; gap: 6px; font-size: 14px; font-weight: 500; color: var(--ink-2); }
.field input, .field select {
  height: 42px; border: 1px solid var(--rule); border-radius: 5px; padding: 0 12px; background: var(--panel);
  font-size: 16px; color: var(--ink);
}
.field input:focus, .field select:focus { border-color: var(--focus); outline: 2px solid color-mix(in srgb, var(--focus) 35%, transparent); outline-offset: 0; }
.field .hint { font-weight: 400; color: var(--ink-3); font-size: 13px; }

.alert { border-radius: 5px; padding: 12px 14px; font-size: 15px; border-left: 4px solid; }
.alert.error { background: color-mix(in srgb, var(--overdue) 10%, var(--panel)); border-color: var(--overdue); }
.alert.ok { background: color-mix(in srgb, var(--paid) 10%, var(--panel)); border-color: var(--paid); }
.alert.info { background: color-mix(in srgb, var(--open) 10%, var(--panel)); border-color: var(--open); }

/* ---------- Sign in ---------- */

.signin-wrap { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.signin {
  width: min(400px, calc(100vw - 32px)); margin: 10vh auto 0; align-self: start;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px;
  display: grid; gap: 16px; border-top: 6px solid var(--signal);
}
.signin h1 { font-size: 34px; }
.signin p { margin: 0; }

/* ---------- Settings ---------- */

.settings { display: grid; gap: 24px; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 24px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin-right: auto; }
.conn { display: flex; gap: 14px; align-items: center; }
.conn .badge {
  width: 44px; height: 44px; border-radius: 8px; display: grid; place-items: center;
  font: 700 18px/1 var(--cond); background: var(--panel-2);
}
.conn .badge.on { background: var(--paid); color: #fff; }
.conn .badge.off { background: var(--overdue); color: #fff; }

table.team { width: 100%; border-collapse: collapse; font-size: 15px; }
.team th { text-align: left; font-size: 13px; color: var(--ink-3); font-weight: 600; padding: 8px 10px 8px 0; border-bottom: 1px solid var(--rule); }
.team td { padding: 12px 10px 12px 0; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.team tr:last-child td { border-bottom: 0; }
.team .actions { text-align: right; white-space: nowrap; }
.team .actions .btn + .btn { margin-left: 6px; }
.role-tag { font-size: 13px; font-weight: 600; padding: 3px 8px; border-radius: 3px; background: var(--panel-2); }
.role-tag.admin { background: var(--signal); color: var(--signal-ink); }
.inactive td { color: var(--ink-3); }

.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.form-grid > * { min-width: 0; }
.field input, .field select { width: 100%; min-width: 0; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; }

dialog {
  border: 0; border-radius: var(--radius); padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--panel); color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(20, 23, 26, .5); }
dialog form { padding: 22px 24px; display: grid; gap: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--panel); padding: 11px 16px; border-radius: 5px; z-index: 60;
  font-size: 15px; box-shadow: var(--shadow);
}

.skeleton { background: linear-gradient(90deg, var(--panel-2), var(--rule), var(--panel-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 4px; color: transparent !important; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Small screens ---------- */

@media (max-width: 860px) {
  .brand small { display: none; }
  .brand-mark { width: 34px; height: 20px; }
  .sync .label { display: none; }
}

@media (max-width: 720px) {
  .band-inner { flex-wrap: wrap; gap: 8px 14px; padding: 8px 0; }
  .nav { order: 3; width: 100%; margin: 0; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; flex: none; }
  main { padding-top: 16px; }
  .periods { grid-template-columns: 1fr; border-radius: var(--radius) var(--radius) 0 0; }
  .period { border-right: 0; border-top: 0; border-left: 6px solid transparent; border-bottom: 1px solid var(--rule); padding: 14px 16px; }
  .period:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
  .period:last-child { border-top-right-radius: 0; border-bottom: 0; }
  .period[aria-selected="true"], .period.static { border-left-color: var(--signal); }
  .period .amount { font-size: 40px; margin-top: 4px; }
  /* Unselected periods collapse to one line so the list stays near the top. */
  .period[aria-selected="false"] { grid-template-columns: 1fr auto; align-items: baseline; padding: 12px 16px; }
  .period[aria-selected="false"] .amount { font-size: 26px; margin: 0; grid-column: 2; grid-row: 1 / span 2; }
  .period[aria-selected="false"] .count,
  .period[aria-selected="false"] .cash-basis,
  .period[aria-selected="false"] .with-tax,
  .period[aria-selected="false"] .split { display: none; }
  .sync { display: none; }
  .split { margin-top: 8px; }
  .list-head { padding: 14px 16px; }
  .search { width: 100%; order: 3; }
  .filters { order: 2; overflow-x: auto; max-width: 100%; }
  .sales thead { display: none; }
  .sales, .sales tbody { display: block; }
  .sales tr {
    display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 16px; border-bottom: 1px solid var(--rule);
  }
  .sales td { padding: 0 !important; border: 0; }
  .sales td.c-date, .sales td.c-doc, .sales td.c-tax { display: none; }
  .sales td.c-cust { grid-column: 1; }
  .sales td.c-total { grid-column: 2; grid-row: 1; font-weight: 600; }
  .sales td.c-status { grid-column: 1; }
  .sales td.c-balance { grid-column: 2; font-size: 14px; color: var(--ink-2); }
  .sales tbody tr:hover td { background: none; }
  .list-foot { padding: 12px 16px; }
  .month-stats { grid-template-columns: 1fr; gap: 10px; }
  /* The sales list stays near the top on a phone, so these follow it. */
  .sales-main { display: flex; flex-direction: column; }
  .money-band { grid-template-columns: 1fr; gap: 10px; order: 2; margin: 16px 0 0; }
  .money-card { padding: 12px 16px; }
  .age-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .age-tile:first-child { grid-column: 1 / -1; }
  /* Unpaid invoices become cards, with a call button that's easy to hit. */
  .owed-table, .owed-table tbody { display: block; }
  .owed-table thead { display: none; }
  .owed-group { display: block; }
  .owed-group th { display: block; padding: 9px 16px !important; }
  .owed-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 12px 16px; border-bottom: 1px solid var(--rule); }
  .owed-table td { padding: 0 !important; border: 0; }
  .owed-row:hover td { background: none; }
  .o-cust { grid-column: 1; grid-row: 1; }
  .o-balance { grid-column: 2; grid-row: 1; }
  .o-status { grid-column: 1; grid-row: 2; }
  .o-age { grid-column: 2; grid-row: 2; font-size: 14px; color: var(--ink-2); }
  .o-last { grid-column: 1; grid-row: 3; align-self: center; white-space: normal; }
  .o-last::before { content: attr(data-label) ': '; color: var(--ink-3); }
  .o-call { grid-column: 2; grid-row: 3; }
  .btn.small.call { height: 44px; padding: 0 18px; }
  .month-stat { padding: 12px 16px; }
  /* The table becomes month cards: month, this year, last year, change. */
  .month-table, .month-table tbody, .month-table tfoot { display: block; }
  .month-table thead { display: none; }
  .month-table tr {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px 10px; align-items: start;
    padding: 12px 16px; border-bottom: 1px solid var(--rule);
  }
  .month-table th, .month-table td { padding: 0 !important; border: 0 !important; background: none !important; }
  .month-table tr.is-current { background: color-mix(in srgb, var(--signal) 12%, var(--panel)); }
  .month-table tfoot tr { border-top: 2px solid var(--ink); border-bottom: 0; }
  .month-table .c-month { grid-column: 1 / -1; font-size: 16px; font-weight: 700; }
  .month-table .c-month .cell-note { display: inline; margin-left: 6px; white-space: normal; }
  .month-table .wide-only { display: none; }
  .chart-yaxis { display: block; }
  .month-table .y-old { display: none; }
  .month-table td.num { text-align: left; }
  .month-table td::before { content: attr(data-label); display: block; font-size: 13px; font-weight: 500; color: var(--ink-3); }
  .month-table .y-cur { order: 1; }
  .month-table .y-last { order: 2; }
  .month-table .c-change { order: 3; }
  .month-table .c-percent { order: 4; grid-column: 3; }
  .month-table td.c-percent::before { display: none; }
  .month-table .is-future .c-percent { display: none; }
  .drawer-head, .drawer-body, .drawer-foot { padding-left: 16px; padding-right: 16px; }
  .money-row dd { font-size: 22px; }
  dl.facts { grid-template-columns: 96px 1fr; }
  .card { padding: 18px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .team thead { display: none; }
  .team tr { display: grid; grid-template-columns: 1fr auto; padding: 10px 0; border-bottom: 1px solid var(--rule); }
  .team td { border: 0; padding: 2px 0; }
  .team td.t-role { grid-column: 2; grid-row: 1; text-align: right; }
  .team td.t-last { display: none; }
  .team td.actions { grid-column: 1 / -1; text-align: left; padding-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Legal pages ---------- */
.legal { max-width: 720px; margin: 8px auto 0; line-height: 1.6; }
.legal h2 { margin-top: 22px; font-size: 21px; }
.legal ul { padding-left: 22px; }
.legal li + li { margin-top: 4px; }
.legal-foot { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--rule); font-size: 14px; }
.signin-legal { margin-top: 18px; text-align: center; }
.signin-legal a { color: inherit; }
