:root {
  --bg: #f3f4f7;
  --card: #ffffff;
  --text: #1b1e24;
  --muted: #6a717d;
  --line: #e3e6eb;
  --accent: #1f6feb;
  --accent-soft: #e7f0fe;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --warn: #b26a00;
  --warn-soft: #fff4e0;
  --ok: #1b7a3d;
  --ok-soft: #e6f5ec;
  --info-soft: #eef1f6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1b1e24;
    --text: #eceef2;
    --muted: #9aa1ad;
    --line: #2c3038;
    --accent: #5b9bff;
    --accent-soft: #1d2b44;
    --danger: #ff6b6b;
    --danger-soft: #3a1d1f;
    --warn: #ffb84d;
    --warn-soft: #3a2c14;
    --ok: #5cd08a;
    --ok-soft: #173023;
    --info-soft: #232831;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 24px; margin: 4px 0 12px; }
h2 { font-size: 18px; margin: 22px 0 10px; }
h3 { font-size: 16px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* Рамка */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; color: var(--text); }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.topnav { display: none; gap: 4px; margin-left: 16px; }
.topnav a { padding: 8px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; }
.topnav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar .spacer { flex: 1; }
main { max-width: 1040px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; }
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a.active { color: var(--accent); }
.bottomnav a.plus span.circle {
  width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; margin-top: -18px; box-shadow: 0 4px 12px rgba(31,111,235,.35);
}
.bottomnav a.plus span.circle svg { width: 26px; height: 26px; }

@media (min-width: 860px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
  main { padding-bottom: 40px; }
}
.desktop-only { display: none !important; }
@media (min-width: 860px) { .desktop-only { display: inline-flex !important; } }

/* Карти и решетки */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; border: 1px solid var(--line); }
.grid { display: grid; gap: 12px; }
.grid.cars { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid.stats { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .grid.stats { grid-template-columns: repeat(4, 1fr); } }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

.car-card { cursor: pointer; display: block; color: inherit; }
.car-card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.car-card .name { font-weight: 700; font-size: 17px; }
.car-card .km { font-size: 15px; font-weight: 600; margin: 8px 0 10px; font-variant-numeric: tabular-nums; }
.plate {
  display: inline-block; font-family: ui-monospace, Menlo, monospace; font-weight: 700; font-size: 13px;
  border: 1.5px solid var(--text); border-radius: 5px; padding: 1px 6px; letter-spacing: .5px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--info-soft); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.badge.sold { background: var(--info-soft); color: var(--muted); }

/* Напомняния */
.reminders { display: flex; flex-direction: column; gap: 8px; }
.rem { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); cursor: pointer; }
.rem .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.rem.danger .dot { background: var(--danger); }
.rem.warn .dot { background: var(--warn); }
.rem.info .dot { background: var(--accent); }
.rem.muted { opacity: .75; }
.rem .t { font-weight: 600; }
.rem .s { font-size: 13px; color: var(--muted); }
.rem.danger .s { color: var(--danger); }
.rem .grow { flex: 1; min-width: 0; }

/* Списъци */
.list { display: flex; flex-direction: column; }
.row { display: flex; gap: 12px; align-items: center; padding: 12px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row .ic { width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; flex: none; font-size: 18px; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; }
.row .s { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0 12px; }
.tabs { display: flex; gap: 4px; background: var(--info-soft); padding: 4px; border-radius: 12px; margin: 12px 0; overflow-x: auto; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; cursor: pointer; }
.tabs button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* Бутони и форми */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; }

form .f { margin-bottom: 12px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.typegrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
@media (min-width: 520px) { .typegrid { grid-template-columns: repeat(5, 1fr); } }
.typegrid button {
  border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 12px;
  padding: 7px 2px; font-size: 11px; line-height: 1.2; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; font-family: inherit;
}
.typegrid button .e { font-size: 18px; }
.typegrid button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Модален прозорец */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@media (min-width: 700px) { .modal-back { align-items: center; } .modal { border-radius: 18px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal .mhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal .mhead h2 { margin: 0; }
.modal .x { border: 0; background: var(--info-soft); width: 32px; height: 32px; border-radius: 50%; font-size: 18px; cursor: pointer; color: var(--text); }
.actions { display: flex; gap: 8px; margin-top: 16px; }
.actions .btn { flex: 1; }

/* Вход */
.login { max-width: 380px; margin: 10vh auto 0; }
.login .logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 12px; }
.login h1 { text-align: center; }
.err { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 12px; }

/* Справки */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 160px; margin-top: 8px; }
.bars .b { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bars .b i { display: block; width: 100%; max-width: 34px; background: var(--accent); border-radius: 5px 5px 2px 2px; min-height: 2px; }
.bars .b span { font-size: 11px; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.scroll-x { overflow-x: auto; }

.doc-card { display: flex; gap: 12px; align-items: center; }
.doc-card .ic { width: 42px; height: 42px; border-radius: 10px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none; }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom));
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 100; font-size: 14px;
}
.km-edit { cursor: pointer; border-bottom: 1px dashed var(--muted); }

.gear { color: var(--muted); display: flex; }
@media (min-width: 860px) { .gear { display: none; } }
