:root {
  color-scheme: light;
  --page: #f3f5fa;
  --surface: #fff;
  --subtle: #f6f7fb;
  --ink: #1a2035;
  --muted: #59637a;
  --line: #e2e6ef;
  --primary: #4936ba;
  --primary-hover: #392799;
  --primary-text: #fff;
  --accent-soft: #eeebfc;
  --side: #191b32;
  --side-text: #c1c6de;
  --side-active: #303354;
  --green: #176044;
  --green-bg: #e6f4eb;
  --amber: #7a480b;
  --amber-bg: #fff2d6;
  --red: #99393f;
  --red-bg: #fbecee;
  --grey: #4b5872;
  --grey-bg: #edf0f6;
  --shadow: 0 2px 6px #1a203507;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --page: #131522;
    --surface: #1d2032;
    --subtle: #25283e;
    --ink: #f1f0fa;
    --muted: #b7bdd3;
    --line: #333850;
    --primary: #b9aaff;
    --primary-hover: #d3cbff;
    --primary-text: #201548;
    --accent-soft: #362d59;
    --side: #191a2d;
    --green: #a4e7c2;
    --green-bg: #243f37;
    --amber: #f8d398;
    --amber-bg: #463821;
    --red: #ffb6bc;
    --red-bg: #4c2b37;
    --grey: #d2daf3;
    --grey-bg: #303650;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #131522;
  --surface: #1d2032;
  --subtle: #25283e;
  --ink: #f1f0fa;
  --muted: #b7bdd3;
  --line: #333850;
  --primary: #b9aaff;
  --primary-hover: #d3cbff;
  --primary-text: #201548;
  --accent-soft: #362d59;
  --side: #191a2d;
  --green: #a4e7c2;
  --green-bg: #243f37;
  --amber: #f8d398;
  --amber-bg: #463821;
  --red: #ffb6bc;
  --red-bg: #4c2b37;
  --grey: #d2daf3;
  --grey-bg: #303650;
  --shadow: none;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--page); font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
form, p, dl, dd, h1, h2, h3 { margin: 0; }
a { color: var(--primary); text-underline-offset: .2em; }
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #8274ee; outline-offset: 3px; }
h1 { font-size: clamp(1.9rem, 3.2vw, 2.55rem); line-height: 1.12; letter-spacing: -.042em; overflow-wrap: anywhere; }
h2 { font-size: 1.2rem; line-height: 1.25; letter-spacing: -.018em; }
h3 { font-size: 1rem; line-height: 1.3; }
.muted { color: var(--muted); font-size: .9rem; }
.skip { position: absolute; z-index: 3; left: 1rem; top: .5rem; padding: .5rem; background: var(--surface); transform: translateY(-200%); }
.skip:focus { transform: none; }

.app { --sidebar-width: 220px; min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); background: linear-gradient(90deg, var(--side) var(--sidebar-width), var(--page) var(--sidebar-width)); }
.sidebar { display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 27px 18px 22px; background: var(--side); color: var(--side-text); }
.brand { display: inline-flex; gap: .65rem; align-items: center; padding: 0 .45rem; color: white; font-size: 1.33rem; font-weight: 750; letter-spacing: -.04em; text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; flex: 0 0 2.15rem; width: 2.15rem; height: 2.15rem; background: #6651dc; color: #fff; border-radius: .65rem; font-size: 1.24rem; font-weight: 800; }
.sidebar nav { display: grid; gap: .35rem; margin-top: 2.2rem; }
.sidebar nav a { display: flex; align-items: center; gap: .7rem; min-height: 44px; padding: .55rem .8rem; color: inherit; border-radius: .55rem; font-size: .94rem; font-weight: 600; text-decoration: none; }
.sidebar nav a::before { content: ''; width: .45rem; height: .45rem; border: 1px solid currentColor; border-radius: 50%; }
.sidebar nav a:hover, .sidebar nav a[aria-current] { color: #fff; background: var(--side-active); }
.sidebar nav a[aria-current]::before { background: #b3a5ff; border-color: #b3a5ff; }
.sidebar-account { display: flex; align-items: center; gap: .65rem; margin-top: auto; padding: .9rem .45rem 0; border-top: 1px solid #ffffff24; font-size: .88rem; }
.account-mark { display: grid; place-items: center; width: 1.95rem; height: 1.95rem; background: var(--side-active); border-radius: 50%; color: #fff; font-weight: 700; }
.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 70px; padding: .6rem clamp(1rem, 3.3vw, 3rem); background: var(--surface); border-bottom: 1px solid var(--line); }
.workspace-label { color: var(--muted); font-size: .92rem; font-weight: 650; }
.topbar-actions, .form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.content { width: 100%; max-width: 1450px; margin-inline: auto; padding: clamp(1.1rem, 3.3vw, 3rem); flex: 1; }
.footer { display: flex; justify-content: space-between; gap: .7rem; padding: .85rem clamp(1rem, 3.3vw, 3rem); color: var(--muted); font-size: .82rem; border-top: 1px solid var(--line); }
.page-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; }
.page-heading .muted { margin-top: .35rem; font-size: 1rem; }
.button { display: inline-flex; gap: .35rem; align-items: center; justify-content: center; min-height: 44px; padding: .56rem .9rem; border: 1px solid transparent; border-radius: .55rem; font-size: .92rem; font-weight: 690; text-decoration: none; cursor: pointer; }
.primary { color: var(--primary-text); background: var(--primary); }
.primary:hover { background: var(--primary-hover); }
.secondary { color: var(--ink); background: var(--surface); border-color: var(--line); }
.secondary:hover, .quiet:hover { background: var(--subtle); }
.quiet { color: var(--muted); background: transparent; }

.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .8rem; margin-bottom: .8rem; }
.stat { min-width: 0; display: flex; flex-direction: column; gap: .4rem; padding: .89rem .95rem; border: 1px solid var(--line); border-radius: .8rem; background: var(--surface); color: var(--ink); text-decoration: none; box-shadow: var(--shadow); --status-color: var(--grey); --status-bg: var(--grey-bg); }
.stat:hover, .stat[aria-current] { border-color: var(--primary); }
.stat[aria-current] { box-shadow: inset 0 0 0 1px var(--primary); }
.stat-name { display: flex; align-items: baseline; gap: .45rem; font-size: .875rem; font-weight: 700; }
.dot { display: inline-block; flex: 0 0 .47rem; width: .47rem; height: .47rem; border-radius: 50%; background: var(--status-color); }
.stat strong { font-size: 1.95rem; line-height: 1.05; letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.stat-detail { color: var(--muted); font-size: .8rem; }
.stat.all { --status-color: var(--primary); }
.active { --status-color: var(--green); --status-bg: var(--green-bg); }
.expiring { --status-color: var(--amber); --status-bg: var(--amber-bg); }
.expired { --status-color: var(--red); --status-bg: var(--red-bg); }
.none, .archive { --status-color: var(--grey); --status-bg: var(--grey-bg); }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: .85rem; background: var(--surface); box-shadow: var(--shadow); }
.income { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 1.45rem; }
.income > div { min-width: 0; padding: .65rem 1rem; }
.income > div + div { border-left: 1px solid var(--line); }
.income dt { color: var(--muted); font-size: .85rem; font-weight: 650; }
.income dd { font-size: 1.25rem; font-weight: 750; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.records-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; padding: 1rem 1.2rem; }
.records-head h2 { margin-bottom: .12rem; }
.search { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; }
.search input[type="search"] { width: clamp(14rem, 22vw, 20rem); flex: 1; }
.search select { width: 10.5rem; }
input:not([type="checkbox"], [type="radio"]), select, textarea { min-width: 0; min-height: 44px; padding: .55rem .7rem; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: .5rem; }
select { appearance: none; padding-right: 1.6rem; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: right .89rem center, right .59rem center; background-size: .3rem .3rem; background-repeat: no-repeat; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
textarea { resize: vertical; }
.client-list { width: 100%; border-collapse: collapse; text-align: left; table-layout: fixed; }
.client-list thead { background: var(--subtle); color: var(--muted); }
.client-list th { width: 22%; padding: .65rem 1.2rem; font-size: .86rem; font-weight: 680; }
.client-list th:first-child { width: 30%; }
.client-list th:nth-child(2) { width: 32%; }
.client-list th:last-child { width: 16%; }
.client-list td { border-top: 1px solid var(--line); padding: .66rem 1.2rem; overflow-wrap: anywhere; font-size: .94rem; }
.client-list tbody tr:hover { background: var(--subtle); }
.initial { display: inline-grid; place-items: center; vertical-align: middle; width: 2.15rem; height: 2.15rem; margin-right: .55rem; border-radius: .65rem; color: var(--primary); background: var(--accent-soft); font-weight: 750; }
.cell-lines { display: inline-flex; flex-direction: column; max-width: 100%; vertical-align: middle; }
.client-cell .cell-lines { max-width: calc(100% - 3.05rem); }
.client-link { color: var(--ink); font-weight: 700; text-decoration: none; }
.client-link:hover { color: var(--primary); text-decoration: underline; }
.vin { font-family: ui-monospace, "Cascadia Mono", monospace; font-size: .85rem; }
.badge { display: inline-flex; align-items: baseline; gap: .35rem; border-radius: 1rem; padding: .23rem .55rem; background: var(--status-bg); color: var(--status-color); font-size: .82rem; font-weight: 690; line-height: 1.35; }
.badge::before { content: ''; display: inline-block; width: .37rem; height: .37rem; flex: 0 0 .37rem; border-radius: 50%; background: currentColor; }
.date-cell { font-variant-numeric: tabular-nums; }
.mobile-only { display: none; }
.empty { display: grid; gap: .35rem; padding: 2rem 1rem; border-top: 1px solid var(--line); text-align: center; }

.back-link { display: inline-flex; align-items: center; min-height: 44px; margin-bottom: .45rem; font-size: .9rem; font-weight: 650; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; align-items: start; }
.detail-panel, .form-panel { padding: clamp(1rem, 2vw, 1.5rem); }
.detail-panel > :not(:last-child), .form-panel h2 { margin-bottom: .9rem; }
.section-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; }
.details > div { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: .55rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.details dt { color: var(--muted); font-size: .9rem; }
.details dd { overflow-wrap: anywhere; }
.notes p, .preserve-lines { margin-top: .2rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.history { margin-bottom: 1rem; }
.timeline { padding-left: 1.1rem; margin: 0; }
.timeline li { padding: .2rem 0 .75rem .4rem; overflow-wrap: anywhere; }
.timeline li::marker { color: var(--primary); }
.timeline li p + p { margin-top: .22rem; }
.event-heading { display: flex; flex-wrap: wrap; justify-content: space-between; column-gap: .6rem; }
.operation { border: 1px solid var(--line); border-radius: .55rem; }
.operation summary { cursor: pointer; display: flex; align-items: center; gap: .5rem; min-height: 45px; padding: .55rem .75rem; font-size: .94rem; font-weight: 640; }
.operation summary::-webkit-details-marker { display: none; }
.operation summary::before { content: '+'; color: var(--primary); flex: 0 0 .75rem; }
.operation[open] summary::before { content: '−'; }
.operation summary strong { margin-left: auto; white-space: nowrap; }
.operation form { border-top: 1px solid var(--line); padding: .7rem .75rem; }
.tariff-choices, .tariff-config { min-width: 0; border: 1px solid var(--line); border-radius: .55rem; margin: 0; padding: .5rem .65rem .65rem; }
.tariff-choices legend, .tariff-config legend { padding-inline: .2rem; font-size: .92rem; font-weight: 700; }
.tariff-config .fields { align-items: end; }
.tariff-choice { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .5rem; min-height: 44px; padding: .35rem .15rem; cursor: pointer; }
.tariff-choice + .tariff-choice { border-top: 1px solid var(--line); }
.tariff-choice span { display: block; }
.tariff-choice input { width: 1rem; height: 1rem; margin: 0; accent-color: var(--primary); }
.tariff-choice strong { font-size: .9rem; }
.tariff-amount { white-space: nowrap; }
.archive-action { border: 0; }
.archive-action summary { padding-left: 0; }
.archive-action form { padding-inline: 0; }
.stack { display: flex; flex-direction: column; gap: .85rem; }
.stack > .button { align-self: flex-start; }
.field { display: grid; gap: .28rem; min-width: 0; font-size: .92rem; font-weight: 620; }
.field input, .field select, .field textarea { width: 100%; font-size: 1rem; font-weight: 400; }
.required { color: var(--red); }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; }
.form-panel { max-width: 56rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; width: fit-content; min-height: 44px; cursor: pointer; }
.checkbox input { width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--primary); flex: 0 0 1.15rem; }
.notice { margin-bottom: 1rem; padding: .65rem .85rem; border-radius: .55rem; }
.notice.success { color: var(--green); background: var(--green-bg); }
.notice.error { color: var(--red); background: var(--red-bg); }
.notice.warning { color: var(--amber); background: var(--amber-bg); }
.backups { padding-left: 1.1rem; overflow-wrap: anywhere; }
.backups li { margin-bottom: .6rem; }
.public .content { display: grid; place-items: center; }
.public .detail-panel h1 { font-size: 1.45rem; }
.login-panel { width: min(100%, 25rem); padding: clamp(1.15rem, 4vw, 2rem); }
.login-panel .brand { padding: 0; color: var(--ink); margin-bottom: 1.5rem; }
.login-panel h1 { font-size: 2rem; }
.login-panel .muted { margin: .4rem 0 1.25rem; }
.login-panel .button { align-self: stretch; }

@media (max-width: 1040px) {
  .app { --sidebar-width: 174px; }
  .stats { gap: .55rem; }
  .stat { padding: .75rem .65rem; }
  .client-list td, .client-list th { padding-inline: .75rem; }
}

@media (max-width: 830px) {
  .app { display: block; background: var(--page); }
  .sidebar { position: static; height: auto; padding: .7rem 1rem .5rem; }
  .sidebar nav { display: flex; flex-wrap: wrap; margin-top: .45rem; }
  .sidebar nav a { padding-inline: .62rem; }
  .sidebar-account { display: none; }
  .workspace { min-height: calc(100vh - 106px); }
  .topbar { min-height: 55px; padding: .25rem 1rem; }
}

@media (max-width: 620px) {
  .content { padding: 1rem; }
  .topbar { gap: .35rem; }
  .workspace-label { font-size: .82rem; }
  .topbar-actions { gap: .12rem; }
  .topbar .button { padding-inline: .45rem; }
  .page-heading { margin-bottom: 1rem; }
  .page-heading > .button { width: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 1rem; }
  .stat:first-child { grid-column: span 2; }
  .stat { padding: .58rem .68rem; gap: .25rem; }
  .stat strong { font-size: 1.55rem; }
  .stat-detail { font-size: .76rem; }
  .records-head { display: block; padding: .85rem; }
  .income { margin-bottom: 1rem; }
  .income > div { padding: .58rem .68rem; }
  .search { display: grid; grid-template-columns: minmax(0, 1fr) auto; margin-top: .6rem; }
  .search input[type="search"] { width: 100%; grid-column: 1 / -1; }
  .search select { width: 100%; }
  .client-list, .client-list tbody { display: block; }
  .client-list thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .client-list tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .4rem; align-items: center; border-top: 1px solid var(--line); padding: .75rem .85rem; }
  .client-list td { border: 0; padding: 0; }
  .client-cell { grid-column: 1; grid-row: 1; }
  .vehicle-cell { grid-column: 1 / -1; grid-row: 2; }
  .status-cell { grid-column: 2; grid-row: 1; }
  .date-cell { grid-column: 1 / -1; grid-row: 3; color: var(--muted); }
  .mobile-only { display: inline; }
  .missing { display: none; }
  .client-link { display: flex; align-items: center; min-height: 32px; }
  .client-cell .initial { display: none; }
  .client-cell .cell-lines { max-width: 100%; }
  .detail-grid, .fields { grid-template-columns: minmax(0, 1fr); }
}
