:root {
  --brand: #a3474a;
  --brand-strong: #8b3a3d;
  --brand-soft: #f6e9e9;
  --rental: #2f5d7c;
  --rental-soft: #e6eef4;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --border: #e5e7eb;
  --text: #1f2933;
  --muted: #6b7280;
  --ok: #2e7d4f;
  --ok-soft: #e3f3ea;
  --warn: #b7791f;
  --warn-soft: #fbf1dc;
  --danger: #c0392b;
  --danger-soft: #fbe5e2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --brand: #c4595d;
  --brand-strong: #d26b6f;
  --brand-soft: #3a2324;
  --rental: #5b8fb3;
  --rental-soft: #1e2a33;
  --bg: #121417;
  --surface: #1b1e23;
  --surface-2: #23272d;
  --border: #2f343b;
  --text: #e8eaed;
  --muted: #9aa1ab;
  --ok: #5fbf86;
  --ok-soft: #1c2d23;
  --warn: #e0a54a;
  --warn-soft: #2f2618;
  --danger: #ec7063;
  --danger-soft: #35201e;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --brand: #c4595d;
  --brand-strong: #d26b6f;
  --brand-soft: #3a2324;
  --rental: #5b8fb3;
  --rental-soft: #1e2a33;
  --bg: #121417;
  --surface: #1b1e23;
  --surface-2: #23272d;
  --border: #2f343b;
  --text: #e8eaed;
  --muted: #9aa1ab;
  --ok: #5fbf86;
  --ok-soft: #1c2d23;
  --warn: #e0a54a;
  --warn-soft: #2f2618;
  --danger: #ec7063;
  --danger-soft: #35201e;
  color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; line-height: 1.45; color: var(--text); background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.boot { padding: 40px; color: var(--muted); }
svg.ic { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 14px; position: sticky; top: 0; height: 100vh; }
.sidebar .logo { display: block; padding: 4px 6px 16px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.sidebar .logo img { width: 100%; max-width: 190px; display: block; }
.sidebar .logo img.dark-only { display: none; }
:root[data-theme="dark"] .sidebar .logo img.light-only { display: none; }
:root[data-theme="dark"] .sidebar .logo img.dark-only { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sidebar .logo img.light-only { display: none; }
  :root:not([data-theme="light"]) .sidebar .logo img.dark-only { display: block; }
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: var(--text); font-size: 15px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.nav .badge { margin-left: auto; }
.me-card { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; margin-top: 12px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; }
.avatar.sm { width: 30px; height: 30px; font-size: 13px; }
.avatar.alt { background: #d9772b; }
.main { min-width: 0; padding: 16px 24px 40px; }
.topbar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 20px; }
.topbar .search { flex: 1; max-width: 420px; }
.topbar .spacer { flex: 1; }
.mode-pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
.icon-btn.menu-btn { display: none; }

.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .grow { flex: 1; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* ---------- elements ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; background: var(--brand); color: #fff; padding: 9px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--brand-strong); text-decoration: none; }
.btn.secondary { background: var(--brand-soft); color: var(--brand); }
.btn.secondary:hover { filter: brightness(.97); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger-soft); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 6px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { flex: 1; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent { border-left: 4px solid var(--brand); }

.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.red { background: var(--brand); color: #fff; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge.rental { background: var(--rental-soft); color: var(--rental); }

table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table tr.click { cursor: pointer; }
.table td:first-child { white-space: nowrap; }
.table tr.click:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

dl.facts { display: grid; grid-template-columns: 160px 1fr; gap: 8px 14px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; word-break: break-word; }

/* ---------- forms ---------- */
.form { display: grid; gap: 14px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form .three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
textarea { min-height: 84px; resize: vertical; }
input[type="checkbox"] { width: auto; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.question { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.question .q { font-weight: 600; }
.yesno { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.yesno label { padding: 6px 14px; cursor: pointer; font-weight: 600; }
.yesno input { display: none; }
.yesno label:has(input:checked) { background: var(--brand); color: #fff; }
.form-error { color: var(--danger); font-weight: 600; }
.search input { padding-left: 12px; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 18, 22, .55); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 720px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 960px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 24px 6px; }
.modal-head h2 { font-size: 20px; }
.modal-head .grow { flex: 1; }
.modal-body { padding: 14px 24px 24px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding-top: 6px; }

.stepper { display: flex; align-items: flex-start; margin: 8px 0 22px; }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; color: var(--muted); font-size: 13px; text-align: center; }
.step .dot { width: 46px; height: 46px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; color: var(--text); position: relative; z-index: 1; }
.step.done .dot, .step.current .dot { background: var(--brand); color: #fff; }
.step.current { color: var(--text); font-weight: 600; }
.step:not(:last-child)::after { content: ""; position: absolute; top: 22px; left: 50%; width: 100%; height: 4px; background: var(--surface-2); }
.step.done:not(:last-child)::after { background: var(--brand); }

/* ---------- toast ---------- */
#toast-root { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- calendar ---------- */
.cal { overflow: hidden; }
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--surface-2); border-bottom: 1px solid var(--border); }
.cal-head div { text-align: center; padding: 8px 0; font-weight: 600; color: var(--muted); }
.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: 24px; min-height: 120px; border-bottom: 1px solid var(--border); position: relative; padding-bottom: 6px; row-gap: 3px; }
.cal-week:last-child { border-bottom: 0; }
.cal-day { grid-row: 1 / -1; border-right: 1px solid var(--border); text-align: right; padding: 4px 8px; color: var(--muted); font-size: 13px; cursor: pointer; margin-bottom: -6px; }
.cal-day:nth-child(7) { border-right: 0; }
.cal-day.out { background: var(--surface-2); color: color-mix(in srgb, var(--muted) 60%, transparent); }
.cal-day.today span { color: var(--brand); font-weight: 700; }
.cal-day:hover { background: color-mix(in srgb, var(--brand-soft) 50%, transparent); }
.cal-bar { z-index: 1; margin: 0 3px; background: var(--brand); color: #fff; border-radius: 5px; padding: 0 8px; font-size: 13px; line-height: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.cal-bar.rental { background: var(--rental); }
.cal-bar.cancelled { opacity: .45; text-decoration: line-through; }
.cal-bar.cont-l { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: 0; }
.cal-bar.cont-r { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: 0; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.job { padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.job + .job { margin-top: 10px; }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person .meta { min-width: 0; }
.person .meta div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start; }
.lane { min-height: 380px; }
.lane .card-head h3 { text-transform: uppercase; letter-spacing: .03em; font-size: 14px; }
.lane-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.todo { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.todo .body { flex: 1; min-width: 0; }
.todo .title { font-weight: 600; font-size: 15px; }
.todo .link { font-size: 12px; margin-top: 6px; display: inline-flex; gap: 6px; align-items: center; }
.pri { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; }
.pri.high { background: var(--danger-soft); color: var(--danger); }
.pri.medium { background: var(--warn-soft); color: var(--warn); }
.pri.low { background: var(--ok-soft); color: var(--ok); }

/* ---------- vehicles ---------- */
.vgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.vcard { overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.vcard:hover { border-color: var(--brand); }
.vthumb { aspect-ratio: 16 / 10; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.vthumb img { width: 100%; height: 100%; object-fit: cover; }
.vthumb svg.ic { width: 48px; height: 48px; stroke-width: 1.2; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.gallery .ph { position: relative; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.gallery .ph img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.gallery .ph .x { position: absolute; top: 4px; right: 4px; background: rgba(0, 0, 0, .6); color: #fff; border: 0; border-radius: 6px; cursor: pointer; padding: 2px 7px; }
.gallery .ph .cover { position: absolute; left: 4px; bottom: 4px; }
.drop { border: 2px dashed var(--border); border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); cursor: pointer; }
.drop:hover, .drop.over { border-color: var(--brand); color: var(--brand); }
.docs { display: flex; flex-direction: column; gap: 6px; }
.doc { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.doc a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-frame { width: 100%; height: 240px; border: 0; border-radius: 8px; background: var(--surface-2); }

/* ---------- invoice ---------- */
.invoice-sheet { background: #fff; color: #1f2933; padding: 40px 44px; border-radius: var(--radius); border: 1px solid var(--border); }
.invoice-sheet .top { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.invoice-sheet .top img { width: 220px; }
.invoice-sheet h1 { font-size: 28px; letter-spacing: .06em; color: #a3474a; }
.invoice-sheet table { width: 100%; border-collapse: collapse; margin-top: 24px; }
.invoice-sheet th { text-align: left; border-bottom: 2px solid #a3474a; padding: 8px 6px; font-size: 12px; text-transform: uppercase; color: #6b7280; }
.invoice-sheet td { padding: 8px 6px; border-bottom: 1px solid #eee; }
.invoice-sheet .num { text-align: right; font-variant-numeric: tabular-nums; }
.invoice-sheet .totals { margin-left: auto; width: 300px; margin-top: 16px; }
.invoice-sheet .totals div { display: flex; justify-content: space-between; padding: 5px 6px; }
.invoice-sheet .totals .grand { border-top: 2px solid #1f2933; font-weight: 700; font-size: 16px; }
.invoice-sheet .parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 28px; }
.invoice-sheet .label { font-size: 12px; text-transform: uppercase; color: #6b7280; letter-spacing: .05em; margin-bottom: 4px; }
.paid-stamp { display: inline-block; border: 3px solid #2e7d4f; color: #2e7d4f; font-weight: 800; padding: 4px 14px; transform: rotate(-6deg); letter-spacing: .1em; }
.lines-edit td { padding: 6px; }
.lines-edit input { padding: 7px 9px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, var(--brand-soft), var(--bg)); }
.login { width: 100%; max-width: 400px; padding: 32px; }
.login img { width: 230px; display: block; margin: 0 auto 22px; }
.demo-note { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--muted); }

.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.bar.ok > span { background: var(--ok); }
.bar.warn > span { background: var(--warn); }
.bar.danger > span { background: var(--danger); }

.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .85); display: grid; place-items: center; z-index: 70; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 90vh; border-radius: 6px; }

@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .icon-btn.menu-btn { display: inline-grid; }
  .topbar .spacer, .topbar .mode-pill { display: none; }
  .main { padding: 12px 16px 40px; }
  .cols-2, .cols-3, .kanban, .form .two, .form .three { grid-template-columns: 1fr; }
  .cal-week { min-height: 86px; }
  .cal-bar { font-size: 11px; padding: 0 4px; }
  dl.facts { grid-template-columns: 120px 1fr; }
  .invoice-sheet { padding: 22px; }
  .invoice-sheet .parties { grid-template-columns: 1fr; }
  .invoice-sheet .totals { width: 100%; }
}

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .no-print, #toast-root { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .invoice-sheet { border: 0; padding: 0; }
}
