:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #16181d; --muted: #5d6471; --line: #e2e5ea; --line-2: #cfd4dc;
  --accent: #1f4e8c; --accent-ink: #ffffff; --accent-soft: #e6eef8;
  --ok: #17803d; --ok-soft: #e4f5ea; --warn: #a15c00; --warn-soft: #fdf1dc; --danger: #b42318; --danger-soft: #fdecea; --info: #3a4a63; --info-soft: #eaeef4;
  --side: #15191f; --side-ink: #c9ced6; --side-active: #ffffff;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --panel: #171b21; --ink: #e8eaee; --muted: #9aa3b0; --line: #262c35; --line-2: #343c47;
    --accent: #5b8fd6; --accent-ink: #0b0e12; --accent-soft: #1b2738;
    --ok: #4cc27a; --ok-soft: #13291c; --warn: #e3a64a; --warn-soft: #2e2312; --danger: #f07167; --danger-soft: #321816; --info: #aab6c8; --info-soft: #1d232c;
    --side: #0b0e12; --side-ink: #a9b1bd; --side-active: #ffffff; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.boot { padding: 40px; color: var(--muted); }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 16px; color: #fff; font-weight: 700; }
.brand img { width: 28px; height: 28px; }
.side .brand { flex-direction: column; gap: 6px; padding: 6px 8px 14px; }
.side .brand img.side-logo { width: 118px; height: auto; }
.brand small { display: block; font-weight: 400; color: var(--side-ink); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.auth-logo { text-align: center; margin-bottom: 4px; }
.auth-logo img { width: 150px; height: auto; }
.auth-logo .for-dark { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .auth-logo .for-light { display: none; } :root:not([data-theme="light"]) .auth-logo .for-dark { display: inline; } }
.inv-from { display: flex; gap: 18px; align-items: flex-start; }
.inv-logo { width: 96px; height: auto; flex: none; }
.invoice .inv-from .title { font-size: 22px; }
.nav-group { margin: 12px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7b8494; }
.side a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--side-ink); text-decoration: none; }
.side a:hover { background: rgba(255,255,255,.06); }
.side a.active { background: rgba(255,255,255,.12); color: var(--side-active); }
.side .me { margin-top: 18px; padding: 10px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.side .me button { margin-top: 6px; }
.menu-btn { display: none; }

main { padding: 20px 24px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.panel.flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { color: var(--muted); font-size: 12px; }

button, .btn { font: inherit; border: 1px solid var(--line-2); background: var(--panel); color: var(--ink); padding: 7px 12px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--muted); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--danger); }
button.small, .btn.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
.side button { background: transparent; color: var(--side-ink); border-color: rgba(255,255,255,.2); }

input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line-2); border-radius: 6px; padding: 7px 9px; width: 100%; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.form .check { display: flex; align-items: center; gap: 8px; }
.form .check input { width: auto; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 260px; }
.toolbar select, .toolbar input[type=date] { width: auto; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel); position: sticky; top: 0; white-space: nowrap; }
td.num, th.num { text-align: right; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--accent-soft); }
tfoot td { font-weight: 650; border-top: 2px solid var(--line-2); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--info-soft); color: var(--info); white-space: nowrap; }
.badge.ok, .badge.paid, .badge.pass, .badge.active, .badge.delivered { background: var(--ok-soft); color: var(--ok); }
.badge.warn, .badge.due_soon, .badge.in_transit, .badge.dispatched, .badge.invoiced, .badge.defects, .badge.in_shop, .badge.open { background: var(--warn-soft); color: var(--warn); }
.badge.danger, .badge.overdue, .badge.fail, .badge.cancelled, .badge.out_of_service, .badge.void { background: var(--danger-soft); color: var(--danger); }

.alerts { display: grid; gap: 6px; }
.alert { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 6px; background: var(--info-soft); color: var(--ink); text-decoration: none; border-left: 3px solid var(--info); }
.alert.warn { background: var(--warn-soft); border-color: var(--warn); }
.alert.danger { background: var(--danger-soft); border-color: var(--danger); }

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

.modal-back { position: fixed; inset: 0; background: rgba(10,12,16,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--panel); border-radius: 10px; width: min(760px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .body { padding: 18px; }
.modal footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); }
.modal footer .left { margin-right: auto; }
.error { color: var(--danger); background: var(--danger-soft); padding: 8px 10px; border-radius: 6px; margin-bottom: 12px; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; }
#toast.show { opacity: 1; }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .panel { width: min(400px, 100%); }
.auth .stack { display: grid; gap: 12px; }

.chart { width: 100%; height: 220px; }
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bar-rev { fill: var(--accent); } .bar-exp { fill: #c07a2c; }
.legend .rev { background: var(--accent); } .legend .exp { background: #c07a2c; }

.map-table td { vertical-align: middle; }
.map-table select { min-width: 180px; }
.docs { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.docs ul { list-style: none; padding: 0; margin: 0 0 10px; }
.docs li { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.docs li .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* invoice */
.invoice { background: #fff; color: #111; max-width: 820px; margin: 0 auto; padding: 40px; border: 1px solid var(--line); }
.invoice table th { background: #fff; color: #555; }
.invoice .top { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.invoice .title { font-size: 28px; font-weight: 700; letter-spacing: .02em; }
.invoice .total { font-size: 18px; }
@media print {
  .side, .page-head, .no-print, #toast { display: none !important; }
  .layout { display: block; } main { padding: 0; }
  .invoice { border: 0; padding: 0; max-width: none; }
  body { background: #fff; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  main { padding: 14px 16px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .invoice { padding: 18px; }
}
