:root {
  color-scheme: light;
  --bg: #f5f3ff;
  --surface: #ffffff;
  --ink: #1e1b4b;
  --muted: #475569;
  --border: #dfe5f5;
  --primary: #4338ca;
  --primary-hover: #3730a3;
  --accent: #047857;
  --danger: #b91c1c;
  --soft: #eef2ff;
  --shadow: 0 18px 50px rgba(49, 46, 129, .10);
  font-family: Outfit, Work Sans, ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5; }
button, input, select { font: inherit; }
button, .text-button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: wait; opacity: .55; }
:focus-visible { outline: 3px solid #818cf8; outline-offset: 3px; }
.shell { min-height: 100dvh; padding: 24px; }
main { max-width: 1240px; margin: 0 auto; }
.single-card-layout { min-height: calc(100dvh - 48px); display: grid; place-items: center; }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 10; background: var(--ink); color: white; padding: 10px 14px; border-radius: 8px; }
.skip-link:focus { top: 12px; }
.auth-layout { min-height: calc(100dvh - 48px); display: grid; grid-template-columns: 1.15fr .85fr; align-items: center; gap: clamp(32px, 8vw, 112px); }
.brand-panel { padding: 16px 0; max-width: 590px; }
.brand-panel h1 { max-width: 10ch; font-size: clamp(2.8rem, 6vw, 5.25rem); line-height: 1.02; letter-spacing: -.055em; margin: 18px 0; }
.brand-copy { color: var(--muted); font-size: 1.15rem; max-width: 42ch; }
.eyebrow { color: var(--accent); font-size: .73rem; font-weight: 700; letter-spacing: .12em; margin: 0 0 8px; }
h1, h2, h3, p { margin-top: 0; }
h2 { font-size: clamp(1.45rem, 3vw, 2rem); line-height: 1.15; letter-spacing: -.025em; margin-bottom: 8px; }
h3 { margin-bottom: 4px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); }
.auth-card { padding: clamp(24px, 5vw, 48px); max-width: 470px; width: 100%; justify-self: end; }
.password-card { justify-self: center; }
.muted, .optional, .vehicle-meta { color: var(--muted); }
.muted { margin-bottom: 28px; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
label { font-weight: 600; font-size: .9rem; }
input, select { width: 100%; min-height: 48px; border: 1px solid #bac5df; border-radius: 10px; padding: 10px 13px; color: var(--ink); background: white; }
input:hover, select:hover { border-color: #818cf8; }
input:focus, select:focus { border-color: var(--primary); }
.field-error { color: var(--danger); font-size: .82rem; min-height: 0; margin: 0; }
.field-error:not(:empty) { min-height: 1.25em; }
.form-message, .status-message { min-height: 1.5em; color: var(--danger); font-size: .9rem; margin: 8px 0 16px; }
.compact { margin-bottom: 12px; }
.button { border: 0; border-radius: 10px; min-height: 48px; padding: 11px 18px; font-weight: 700; transition: background-color .2s ease, transform .2s ease, box-shadow .2s ease; }
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.primary { background: var(--primary); color: white; box-shadow: 0 8px 18px rgba(67, 56, 202, .2); }
.primary:hover { background: var(--primary-hover); }
.secondary { color: var(--ink); background: var(--soft); }
.secondary:hover { background: #e0e7ff; }
.full-width { width: 100%; }
.topbar { display: flex; align-items: end; justify-content: space-between; gap: 16px; padding: 24px 0 32px; }
.topbar h1 { margin: 0; font-size: clamp(2rem, 5vw, 3rem); letter-spacing: -.04em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.app-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 24px; border-bottom: 1px solid var(--border); padding-bottom: 0; }
.app-nav a { display: inline-block; padding: 11px 16px; border-radius: 10px 10px 0 0; color: var(--muted); text-decoration: none; font-weight: 700; font-size: .95rem; border-bottom: 3px solid transparent; }
.app-nav a:hover { color: var(--primary); background: var(--soft); }
.app-nav a[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); }
.page { display: grid; gap: 0; }
.page[hidden] { display: none; }
.password-change-actions { display: grid; gap: 4px; }
.user-chip, .count-badge, .status-pill { border-radius: 999px; font-size: .8rem; font-weight: 700; }
.user-chip { color: var(--muted); background: white; border: 1px solid var(--border); padding: 9px 13px; }
.page-grid { display: grid; grid-template-columns: minmax(300px, .8fr) minmax(0, 1.2fr); gap: 24px; align-items: start; }
.form-card, .list-card { padding: clamp(20px, 3vw, 32px); }
.section-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.list-toolbar { display: flex; align-items: center; gap: 10px; }
.list-toolbar select { min-width: 170px; }
.section-heading h2 { margin: 0; }
.text-button { border: 0; background: transparent; color: var(--primary); font-weight: 700; padding: 8px 4px; min-height: 44px; }
.text-button:hover { color: var(--primary-hover); text-decoration: underline; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.field-wide { grid-column: 1 / -1; }
.count-badge { min-width: 34px; text-align: center; padding: 5px 10px; background: var(--soft); color: var(--primary); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; color: var(--muted); font-size: .73rem; text-transform: uppercase; letter-spacing: .08em; padding: 0 10px 12px; }
td { padding: 16px 10px; border-top: 1px solid var(--border); vertical-align: middle; }
td strong, .vehicle-name { display: block; }
.vehicle-meta { display: block; font-size: .78rem; margin-top: 2px; }
.status-pill { display: inline-block; background: #ecfdf5; color: #065f46; padding: 5px 9px; white-space: nowrap; }
.empty-state { border: 1px dashed #b9c4df; padding: 28px; text-align: center; color: var(--muted); border-radius: 12px; }
.empty-state h3 { color: var(--ink); }
.users-card { padding: clamp(20px, 3vw, 32px); margin-bottom: 24px; }
.users-card input { min-width: 150px; min-height: 42px; }
.inline-form { display: flex; align-items: end; gap: 14px; border-top: 1px solid var(--border); margin-top: 20px; padding-top: 20px; }
.inline-form > div { flex: 1; }
.inline-form label { display: block; margin-bottom: 6px; }
.row-actions { display: flex; align-items: center; gap: 8px; }
.row-actions .button { min-height: 40px; padding: 8px 12px; font-size: .85rem; }
.costs-card { padding: clamp(20px, 3vw, 32px); margin-top: 24px; }
.cost-form { display: grid; grid-template-columns: 1.1fr 1fr .8fr auto; align-items: end; gap: 14px; }
.cost-form .field { margin-bottom: 0; }
.cost-form-actions { display: flex; align-items: center; gap: 8px; padding-bottom: 1px; }
.cost-form-actions .button { white-space: nowrap; }
.sales-card { padding: clamp(20px, 3vw, 32px); margin-top: 24px; }
.sale-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; align-items: end; gap: 14px; }
.sale-form .field { margin-bottom: 0; }
.sale-summary { border: 1px solid #bbf7d0; background: #f0fdf4; color: #166534; border-radius: 10px; padding: 12px 14px; font-size: .9rem; }
.sale-cancel-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 12px; }
.sale-cancel-actions .status-message { flex: 1; min-width: 220px; margin: 0; }
.danger { color: white; background: var(--danger); }
.danger:hover { background: #991b1b; }
.dashboard-card { padding: clamp(20px, 3vw, 32px); margin-top: 24px; }
.dashboard-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.dashboard-item { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--soft); display: grid; gap: 4px; min-width: 0; }
.dashboard-label { color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.dashboard-value { font-size: 1.05rem; }
.installment-form { border-top: 1px solid var(--border); margin-top: 20px; padding-top: 20px; }
.exchange-form { border-top: 1px solid var(--border); margin-top: 24px; padding-top: 20px; }
.exchange-form h3 { margin: 0 0 16px; font-size: 1rem; }
.exchange-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: 14px; }
.exchange-grid .field { margin-bottom: 0; }
.installment-rows { display: grid; gap: 14px; margin-bottom: 14px; }
.installment-row { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 14px; }
.installment-row .field { margin-bottom: 0; }
.installment-actions { margin-bottom: 16px; }
.receivables-card { padding: clamp(20px, 3vw, 32px); margin-top: 24px; }
.receivable-cards { display: grid; gap: 16px; }
.receivable-card { border: 1px solid var(--border); border-radius: 14px; padding: 16px; background: var(--soft); min-width: 0; }
.receivable-summary { font-weight: 600; }
.receipt-form { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 14px; margin: 12px 0; }
.receipt-form .field { margin-bottom: 0; }
.receipt-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.receipt-item { border-top: 1px solid var(--border); padding-top: 12px; }
.receipt-status { display: block; margin-bottom: 8px; font-size: .85rem; color: var(--muted); }
.receipt-edit-form { display: grid; grid-template-columns: 1fr 1fr auto auto; align-items: end; gap: 10px; }
.receipt-edit-form .field { margin-bottom: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.status-message.compact { min-height: 20px; margin: 0 0 12px; font-size: .82rem; }

@media (max-width: 900px) {
  .auth-layout, .page-grid { grid-template-columns: 1fr; }
  .auth-layout { min-height: auto; padding: 8vh 0; }
  .auth-card { justify-self: stretch; max-width: none; }
  .brand-panel h1 { max-width: 14ch; }
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .shell { padding: 16px; }
  .auth-layout { gap: 20px; padding: 5vh 0; }
  .brand-panel h1 { font-size: clamp(2.5rem, 14vw, 4rem); }
  .topbar { align-items: start; flex-direction: column; padding-bottom: 24px; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .list-toolbar { width: 100%; }
  .list-toolbar select { flex: 1; min-width: 0; }
  .page-grid { gap: 16px; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .cost-form { grid-template-columns: 1fr 1fr; }
  .cost-form-actions { grid-column: 1 / -1; }
  .sale-form { grid-template-columns: 1fr 1fr; }
  .sale-form > .button { grid-column: 1 / -1; }
  .exchange-grid { grid-template-columns: 1fr 1fr; }
  .field-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .table-wrap { overflow: visible; }
  table, thead, tbody, tr, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tr { padding: 13px 0; border-top: 1px solid var(--border); }
  td { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 6px 0; border: 0; }
  td::before { content: attr(data-label); color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
  td:last-child { justify-content: flex-end; }
  td:last-child::before { display: none; }
  .cost-form { grid-template-columns: 1fr; }
  .cost-form-actions { grid-column: auto; }
  .sale-form { grid-template-columns: 1fr; }
  .sale-form > .button { grid-column: auto; }
  .exchange-grid { grid-template-columns: 1fr; }
  .installment-row { grid-template-columns: 1fr; }
  .receipt-form { grid-template-columns: 1fr; }
  .receipt-edit-form { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
