:root {
  --bg: #f5f6f8; --surface: #fff; --text: #1f2328; --muted: #636c76; --line: #d8dee4; --line-soft: #eaeef2;
  --accent: #0f3d5e; --accent-text: #fff; --accent-soft: #e6eef5; --link: #0b5cad;
  --ok: #1a7f37; --ok-soft: #dafbe1; --warn: #9a6700; --warn-soft: #fff8c5; --bad: #cf222e; --bad-soft: #ffebe9;
  --info: #0969da; --info-soft: #ddf4ff; --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #171b21; --text: #e6edf3; --muted: #8d96a0; --line: #30363d; --line-soft: #21262d;
    --accent: #5aa9e6; --accent-text: #0b1520; --accent-soft: #15283a; --link: #6cb6ff;
    --ok: #3fb950; --ok-soft: #12261a; --warn: #d29922; --warn-soft: #2a2110; --bad: #f85149; --bad-soft: #2d1416;
    --info: #58a6ff; --info-soft: #102236;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.pre { white-space: pre-wrap; margin: 0; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 700; }
.spacer { flex: 1; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.brand span { color: var(--muted); font-weight: 500; }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { padding: 6px 12px; border-radius: 6px; color: var(--muted); white-space: nowrap; }
.topbar nav a:hover { background: var(--line-soft); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.linkish { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px; }
.narrow { max-width: 400px; margin: 10vh auto; padding: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.card.plain { gap: 24px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + * { margin-top: 18px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; display: flex; flex-direction: column; }
.stat span { color: var(--muted); font-size: 0.82rem; }
.stat strong { font-size: 1.55rem; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat small { color: var(--muted); }
.stat.warn strong { color: var(--bad); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--line-soft); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--line-soft); color: var(--text); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 9px; font-size: 0.85rem; }
.btn.block { width: 100%; }
form.inline { display: inline; margin: 0; }

table.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: 0.78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.list td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.list tbody tr:last-child td { border-bottom: 0; }
.list tfoot td { font-weight: 600; border-top: 1px solid var(--line); border-bottom: 0; }
.list.compact td { padding: 6px 4px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.list th.num, .items th.num { text-align: right; }
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: var(--line-soft); }
tr.dim td { opacity: 0.6; }

.badge { display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; vertical-align: middle; letter-spacing: 0.02em; }
.badge-draft { background: var(--line-soft); color: var(--muted); }
.badge-sent { background: var(--info-soft); color: var(--info); }
.badge-partial { background: var(--warn-soft); color: var(--warn); }
.badge-overdue { background: var(--bad-soft); color: var(--bad); }
.badge-paid { background: var(--ok-soft); color: var(--ok); }
.badge-credited { background: var(--line-soft); color: var(--muted); }
.badge-void { background: var(--line-soft); color: var(--muted); text-decoration: line-through; }

.flash { background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent); padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; }
.error { background: var(--bad-soft); color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.cap-warn { padding: 9px 14px; border-radius: 8px; margin: 0 0 12px; font-size: 0.9rem; background: var(--warn-soft); color: var(--warn); }
.cap-warn.over { background: var(--bad-soft); color: var(--bad); }
.cap-box { background: var(--warn-soft); border-radius: 8px; padding: 12px 14px; margin: 12px 0; }
.cap-box ul { margin: 6px 0; padding-left: 20px; }
.cap-box p { margin: 4px 0 8px; }
.receipts { display: flex; flex-wrap: wrap; gap: 14px; margin: 4px 0 14px; }
.receipt { width: 180px; display: flex; flex-direction: column; gap: 4px; }
.receipt img, .receipt-doc { width: 180px; height: 140px; object-fit: cover; border: 1px solid var(--line); border-radius: 6px; background: var(--line-soft); display: flex; align-items: center; justify-content: center; font-weight: 600; color: var(--muted); }
.receipt .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.receipt .btn { align-self: flex-start; }
.list.middle td { vertical-align: middle; }
.inline-edit { display: flex; gap: 8px; align-items: center; }
.inline-edit input { max-width: 320px; }
.pl .pl-head td { font-weight: 600; padding-top: 12px; border-bottom: 0; }
.pl .pl-indent { padding-left: 22px; }
.pl .pl-total td { font-weight: 600; border-top: 1px solid var(--line); }
.pl .pl-net td { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--text); border-bottom: 0; }
.neg { color: var(--bad); }
@media print {
  .topbar, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
.rebill { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; background: var(--line-soft); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }
.rebill .inline-label { color: var(--text); }
.progress { height: 6px; background: var(--line-soft); border-radius: 3px; margin: -8px 0 16px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); }
.txn { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.txn-desc { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.02rem; margin-top: 2px; word-break: break-word; }
.txn-amt { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.current td { background: var(--warn-soft); }
.table-scroll { overflow-x: auto; margin-bottom: 10px; }
.csv-preview td { white-space: nowrap; font-size: 0.85rem; }
.csv-preview select { font-size: 0.82rem; padding: 4px 6px; min-width: 120px; }
.csv-preview tr.csv-header td { font-weight: 600; color: var(--muted); }
.note { background: var(--warn-soft); color: var(--warn); padding: 8px 14px; border-radius: 8px; margin: -6px 0 16px; font-size: 0.9rem; }

.form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; font-weight: 500; color: var(--muted); margin-bottom: 14px; }
input, select, textarea { font: inherit; font-size: 0.95rem; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
textarea { resize: vertical; }
label.check, .form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row2.tight { gap: 10px; }
.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 14px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.inline-label { display: flex !important; flex-direction: row !important; align-items: center; gap: 8px; margin: 0 !important; }
.inline-label input { width: auto; }
.login h1 { margin-bottom: 0; }
.login form { margin-top: 18px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); margin-bottom: 14px; }

.timeform { display: grid; grid-template-columns: 1.3fr 0.9fr 0.6fr 0.6fr 2.4fr auto auto; gap: 10px; align-items: end; }
.timeform label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); }
.timeform label.check { flex-direction: row; padding-bottom: 9px; color: var(--text); }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.filters select, .filters input { width: auto; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

.invoice-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.paper { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 36px 40px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); position: relative; overflow: hidden; }
.paper iframe { width: 100%; border: 0; min-height: 600px; display: block; background: #fff; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0; font-variant-numeric: tabular-nums; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; }
.totals .strong { color: var(--text); font-size: 1.1rem; border-top: 1px solid var(--line); padding-top: 6px; margin-top: 4px; }
.plain-list { list-style: none; padding: 0; margin: 0; font-size: 0.9rem; }
.plain-list li + li { margin-top: 8px; }
.danger-zone form + form { margin-top: 6px; }

table.items { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.items th { text-align: left; font-size: 0.78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; padding: 6px; border-bottom: 1px solid var(--line); }
.items td { padding: 5px 6px; }
.items td:nth-child(2), .items td:nth-child(3) { width: 120px; }
.items td:nth-child(4) { width: 120px; }
.items td:nth-child(5) { width: 40px; }
.items input.num { text-align: right; }
.items tr.sum td { padding: 3px 6px; color: var(--muted); }
.items tr.sum.strong td { color: var(--text); font-size: 1.05rem; border-top: 1px solid var(--line); padding-top: 8px; }

@media (max-width: 900px) {
  .grid2, .invoice-layout { grid-template-columns: 1fr; }
  .timeform { grid-template-columns: 1fr 1fr; }
  .timeform .f-desc { grid-column: 1 / -1; }
  .row4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .topbar nav { order: 3; width: 100%; flex: none; }
  .logout { margin-left: auto; }
  .wrap { padding: 16px; }
  .row2, .row3, .row4 { grid-template-columns: 1fr; }
  .card { padding: 14px; overflow-x: auto; }
  .paper { padding: 12px; }
  .list th, .list td { padding: 7px 6px; }
}

.label-row, .card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.label-row { font-size: 0.85rem; font-weight: 500; color: var(--muted); margin-bottom: 4px; }
.card-head { margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card.empty p { margin: 0 0 14px; }
.steps { margin: 0 0 16px; padding-left: 20px; }
.steps li + li { margin-top: 4px; }

/* reports menu */
.crumb { margin: 0 0 2px; font-size: 0.85rem; color: var(--muted); }
.report-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.report-card { display: block; color: inherit; transition: border-color .15s; }
.report-card:hover { text-decoration: none; border-color: var(--accent); }
.report-card h2 { color: var(--accent); }
.report-card p { margin: 0; }

/* ---------------------------------------------------------------- labels (3 × 1.5 in sheets) */
.labels-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; align-items: start; }
.labels-controls { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 16px; }
.labels-controls h2 { font-size: .95rem; margin: 0; }
.pick-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.pick-list { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.pick-list label { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line-soft); margin: 0; font-weight: 400; cursor: pointer; }
.pick-list label:last-child { border-bottom: 0; }
.pick-list label span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-list input, label.check input { width: auto; margin: 0; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.sheet-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.sheetmap { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.sheetmap .cell { height: 26px; border-radius: 4px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font: 500 .72rem inherit; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 0 4px; }
.sheetmap .cell.used { background: repeating-linear-gradient(45deg, var(--line-soft) 0 4px, var(--line) 4px 8px); text-decoration: line-through; }
.sheetmap .cell.next { background: var(--accent); border-color: var(--accent); color: var(--accent-text); cursor: default; }
.sheetmap .cell:not(.next):hover { border-color: var(--accent); }
.labels-preview { overflow: auto; }
.sheet-page { position: relative; width: 215.9mm; height: 279.4mm; background: #fff; box-shadow: 0 0 0 1px var(--line); margin-bottom: 12px; overflow: hidden; }
.lbl { position: absolute; width: 76.2mm; height: 38.1mm; padding: 3mm; display: flex; align-items: center; gap: 2.5mm; background: #fff; color: #000; box-shadow: 0 0 0 1px #c9ced6; border-radius: 1.5mm; overflow: hidden; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
.lbl img { width: 32mm; height: 32mm; flex: none; }
.lbl .txt { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 1.5mm; }
.lbl .ln-name { font-weight: 800; line-height: 1.08; font-size: 7mm; max-height: 15.6mm; overflow: hidden; overflow-wrap: anywhere; letter-spacing: -.01em; }
.lbl .ln-num { font: 700 4.4mm ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; }
.lbl .ln-num span { display: block; font: 600 2.6mm system-ui, sans-serif; text-transform: uppercase; letter-spacing: .06em; color: #555; }
.lbl.blank { background: repeating-linear-gradient(45deg, #fafafa 0 6px, #f1f2f4 6px 12px); box-shadow: 0 0 0 1px #e4e7eb inset; }
.lbl.outline { outline: .25mm dashed #9aa0a6; outline-offset: -.125mm; }
@media (max-width: 900px) { .labels-layout { grid-template-columns: 1fr; } .labels-controls { position: static; } }
@media print {
  body:has([data-labels]) .topbar, body:has([data-labels]) .page-head, body:has([data-labels]) .flash, .labels-controls { display: none !important; }
  body:has([data-labels]) main { padding: 0; margin: 0; max-width: none; }
  body:has([data-labels]) { background: #fff; }
  .labels-layout { display: block; }
  .labels-preview { border: 0; padding: 0; margin: 0; background: none; overflow: visible; }
  [data-preview] { zoom: 1 !important; }
  .sheet-page { box-shadow: none; margin: 0; break-after: page; }
  .sheet-page:last-child { break-after: auto; }
  .lbl { box-shadow: none; border-radius: 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .lbl.blank { visibility: hidden; }
}
