:root {
  color-scheme: light dark;
  --accent: #0e6b6f;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1f1;
  --bg: #f2f2f6;
  --card: #ffffff;
  --ink: #141416;
  --muted: #6c6c73;
  --line: #e2e2e7;
  --danger: #c62828;
  --warn: #a15c00;
  --warn-soft: #fff3df;
  --switch-off: #e4e4e9;
  --switch-on: #22a35a;
  --tabs-bg: rgba(250, 250, 252, 0.92);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #13878c;
    --accent-soft: #10393b;
    --bg: #000000;
    --card: #1c1c1e;
    --ink: #f3f3f5;
    --muted: #9b9ba3;
    --line: #2e2e31;
    --danger: #ff6b6b;
    --warn: #ffb547;
    --warn-soft: #3a2a10;
    --switch-off: #39393d;
    --switch-on: #30c46b;
    --tabs-bg: rgba(22, 22, 24, 0.92);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}

a { color: inherit; }
small { font-weight: 400; color: var(--muted); font-size: 0.8em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none;
}

.boot { padding: 40px 16px; text-align: center; color: var(--muted); }

.icon { width: 22px; height: 22px; flex: none; }

/* Горна лента */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--accent); color: var(--accent-ink);
  padding-top: var(--safe-top);
}
.bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  min-height: 48px; padding: 0 8px; max-width: 680px; margin: 0 auto;
}
.bar h1 {
  margin: 0; font-size: 17px; font-weight: 600; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62vw;
}
.bar-btn {
  display: inline-flex; align-items: center; gap: 2px; text-decoration: none;
  font-size: 17px; color: var(--accent-ink); min-height: 44px;
}
.bar-btn.right { justify-self: end; }
.cars {
  display: flex; gap: 6px; padding: 0 16px 10px; max-width: 680px; margin: 0 auto; overflow-x: auto;
}
.car {
  flex: 1; min-width: 0; border: 0; border-radius: 9px; padding: 7px 10px;
  font-weight: 600; font-size: 15px; line-height: 1.2; font-family: inherit;
  background: rgba(255, 255, 255, 0.16); color: var(--accent-ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.car.on { background: #ffffff; color: #0e6b6f; }

/* Съдържание */
.content { max-width: 680px; margin: 0 auto; padding: 12px 16px 28px; }
.content.with-tabs { padding-bottom: calc(84px + var(--safe-bottom)); }

/* Долни раздели */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--tabs-bg); border-top: 0.5px solid var(--line);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  padding-bottom: var(--safe-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 0 6px; font-size: 11px; text-decoration: none; color: var(--muted);
}
.tabs a.on { color: var(--accent); }
@media (prefers-color-scheme: dark) { .tabs a.on { color: #4cc3c8; } }

/* Карти със статистика */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 11px 13px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.stat.wide { grid-column: span 2; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 21px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.wide .value { font-size: 34px; letter-spacing: -0.5px; }
.stat.wide .value small { font-size: 17px; letter-spacing: 0; }
.stat .note { font-size: 12px; color: var(--muted); }

/* Бутони */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; min-height: 48px; margin: 10px 0; padding: 0 16px;
  border: 0; border-radius: 12px; text-decoration: none; cursor: pointer;
  font-weight: 600; font-size: 17px; line-height: 1; font-family: inherit;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: var(--card); color: var(--accent); }
@media (prefers-color-scheme: dark) { .btn.secondary { color: #4cc3c8; } }
.btn.danger { background: transparent; color: var(--danger); }
.btn .icon { width: 20px; height: 20px; }

/* Списъци */
.group-title {
  display: flex; justify-content: space-between; gap: 8px;
  margin: 20px 4px 6px; font-size: 13px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.3px;
}
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 9px 14px;
  text-decoration: none; color: var(--ink); border-bottom: 0.5px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--line); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex: none; }
.row-amount { font-size: 16px; font-weight: 600; white-space: nowrap; }
.row.upcoming .row-amount { color: var(--muted); }
.row.add { color: var(--accent); gap: 8px; font-weight: 500; }
@media (prefers-color-scheme: dark) { .row.add { color: #4cc3c8; } }
.chev { width: 16px; height: 16px; color: var(--muted); }

.badge {
  display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .badge { color: #7fd6d9; } }
.badge.muted { background: var(--line); color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; margin: 0; }
.empty.small { padding: 8px 0; font-size: 14px; text-align: left; }

.notice {
  display: block; margin-bottom: 12px; padding: 10px 13px; border-radius: 12px;
  background: var(--warn-soft); color: var(--warn); font-size: 14px; text-decoration: none;
}

/* Форми */
.form-car { margin: 4px 4px -4px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; }
.form .group { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-top: 12px; }
.field {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 4px 14px;
  border-bottom: 0.5px solid var(--line);
}
.field:last-child { border-bottom: 0; }
.field-label { flex: none; max-width: 60%; }
.field.check .field-label { flex: 1; max-width: none; }
.field input:not([type="checkbox"]), .field select {
  flex: 1; min-width: 0; width: 100%; border: 0; background: transparent; color: var(--ink);
  font-size: 17px; line-height: 1.3; font-family: inherit; text-align: right; padding: 8px 0; outline: none;
}
.field input::placeholder { color: var(--muted); opacity: 0.7; }
.field input[type="date"] { -webkit-appearance: none; appearance: none; min-height: 34px; display: flex; justify-content: flex-end; }
.field input[type="date"]::-webkit-date-and-time-value { text-align: right; }
.field select { -webkit-appearance: none; appearance: none; direction: ltr; text-align-last: right; }
.field input.calc { color: var(--accent); }
@media (prefers-color-scheme: dark) { .field input.calc { color: #4cc3c8; } }
.unit { font-style: normal; color: var(--muted); flex: none; min-width: 26px; }

.switch {
  -webkit-appearance: none; appearance: none; flex: none; margin: 0;
  width: 51px; height: 31px; border-radius: 31px; background: var(--switch-off);
  position: relative; transition: background 0.2s; cursor: pointer;
}
.switch::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); transition: transform 0.2s;
}
.switch:checked { background: var(--switch-on); }
.switch:checked::before { transform: translateX(20px); }

.hint { font-size: 13px; color: var(--muted); margin: 6px 14px 4px; }
.live {
  margin-top: 12px; padding: 0 14px; font-size: 14px; color: var(--accent); min-height: 18px;
}
@media (prefers-color-scheme: dark) { .live { color: #4cc3c8; } }
.live.warn { color: var(--warn); font-weight: 600; }

/* Обобщено */
.controls { display: flex; gap: 8px; align-items: stretch; margin-bottom: 4px; flex-wrap: wrap; }
.controls select {
  flex: 1 1 140px; min-height: 40px; border: 0; border-radius: 10px; padding: 0 12px;
  background: var(--card); color: var(--ink); font-size: 16px; font-family: inherit;
}
.seg { display: flex; flex: 1 1 200px; background: var(--line); border-radius: 10px; padding: 2px; }
.seg button {
  flex: 1; min-width: 0; border: 0; border-radius: 8px; background: transparent; color: var(--ink);
  font-weight: 500; font-size: 14px; font-family: inherit; padding: 8px 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); font-weight: 600; }
.card { background: var(--card); border-radius: var(--radius); padding: 6px 14px 8px; margin-top: 12px; }
.card h2 { font-size: 15px; margin: 8px 0 4px; }
.card .hint { margin: 6px 0; }
.kv {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 9px 0; border-bottom: 0.5px solid var(--line);
}
.kv:last-child { border-bottom: 0; }
.kv strong { font-weight: 600; white-space: nowrap; text-align: right; }
.kv.total { font-weight: 700; font-size: 17px; }
.kv.total strong { font-weight: 700; }

.welcome { background: var(--card); border-radius: var(--radius); padding: 6px 16px; margin: 8px 0 14px; }

.footer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 28px; }

#banner { position: fixed; left: 16px; right: 16px; bottom: calc(70px + var(--safe-bottom)); z-index: 20; }
.update {
  display: block; width: 100%; max-width: 640px; margin: 0 auto; padding: 13px; border: 0; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 15px; font-family: inherit;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
