:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #000000;
  --muted: #6c6c70;
  --sep: rgba(60, 60, 67, 0.2);
  --accent: #b27800;
  --accent-soft: rgba(255, 184, 0, 0.16);
  --check: #f5b800;
  --on-accent: #000;
  --red: #ff3b30;
  --orange: #ff9500;
  --green: #34c759;
  --blue: #007aff;
  --fill: rgba(118, 118, 128, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --muted: #98989f;
    --sep: rgba(84, 84, 88, 0.65);
    --accent: #ffd60a;
    --accent-soft: rgba(255, 214, 10, 0.16);
    --check: #ffd60a;
    --on-accent: #000;
    --red: #ff453a;
    --orange: #ff9f0a;
    --green: #30d158;
    --blue: #0a84ff;
    --fill: rgba(118, 118, 128, 0.24);
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; overscroll-behavior-y: none; }
body.noscroll { overflow: hidden; }

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

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

/* ---------- Bara de sus ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 4px) 8px 4px;
  min-height: 48px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--sep); }
.tb-left { justify-self: start; display: flex; align-items: center; min-width: 0; }
.tb-right { justify-self: end; display: flex; align-items: center; gap: 2px; }
.tb-title { font-weight: 600; font-size: 17px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56vw; }
.tb-btn, .tb-icon {
  display: inline-flex; align-items: center; gap: 4px;
  border: 0; background: none; color: var(--accent);
  padding: 8px; font-size: 17px; cursor: pointer; min-height: 40px;
  white-space: nowrap; max-width: 30vw; overflow: hidden;
}
.tb-btn span { overflow: hidden; text-overflow: ellipsis; }
.tb-icon svg, .tb-btn svg { flex: none; }

.page { padding: 0 16px calc(48px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; }
.large-title { font-size: 34px; font-weight: 700; margin: 2px 4px 14px; letter-spacing: 0.3px; }

/* ---------- Grupuri tip iOS ---------- */
.group-title { font-size: 13px; text-transform: uppercase; color: var(--muted); margin: 0 16px 7px; letter-spacing: 0.2px; display: flex; justify-content: space-between; gap: 8px; }
.group { background: var(--card); border-radius: 12px; overflow: hidden; margin: 0 0 24px; box-shadow: var(--shadow); }
.group-title + .group { margin-top: 0; }
.group-footer { font-size: 13px; color: var(--muted); margin: -16px 16px 24px; line-height: 1.4; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; min-height: 46px; position: relative;
  width: 100%; text-align: left; background: none; border: 0;
}
.row + .row::before, .row + .field::before, .field + .row::before, .field + .field::before,
.thumbs + .row::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--sep);
}
a.row:active, button.row:active, label.row:active { background: var(--fill); }
.row.link::after { content: ""; flex: none; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-top: 2px solid var(--muted); transform: rotate(45deg); opacity: 0.55; margin-left: 2px; }
.act-row { color: var(--accent); cursor: pointer; }
.act-row.danger { color: var(--red); }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; color: var(--muted); line-height: 1.4; }
.title { font-weight: 600; }
.sub { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: pre-line; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.ico { font-size: 22px; width: 30px; text-align: center; flex: none; line-height: 1; }

.status.ok { color: var(--green); }
.status.warn { color: var(--orange); }
.status.bad { color: var(--red); }
.status span { font-size: 15px; }

/* ---------- Alerte ---------- */
.alert-row { align-items: flex-start; }
.alert-row .ico { margin-top: 1px; }
.pill { font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 10px; flex: none; letter-spacing: 0.3px; }
.pill.expired { color: var(--red); background: color-mix(in srgb, var(--red) 15%, transparent); }
.pill.soon { color: var(--orange); background: color-mix(in srgb, var(--orange) 15%, transparent); }
.lvl-expired { color: var(--red); }
.lvl-soon { color: var(--orange); }
.lvl-ok { color: var(--green); }

/* ---------- Mașini ---------- */
.car-thumb {
  width: 58px; height: 58px; border-radius: 13px; flex: none;
  background: var(--accent-soft) center / cover no-repeat;
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.car-thumb.has-photo { font-size: 0; }
.plate {
  flex: none; white-space: nowrap;
  display: inline-flex; align-items: stretch; height: 22px; border: 1px solid rgba(0,0,0,.7);
  border-radius: 4px; overflow: hidden; background: #fff; color: #000; margin-top: 4px; vertical-align: middle;
}
.plate b { background: #003399; color: #fff; font-size: 8px; width: 15px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 2px; }
.plate span { font: 700 13px/20px ui-monospace, "SF Mono", Menlo, monospace; padding: 0 6px; letter-spacing: 0.5px; }

.hero { background: var(--card); border-radius: 14px; overflow: hidden; margin-bottom: 18px; box-shadow: var(--shadow); }
.hero-photo { height: 190px; background: var(--accent-soft) center / cover no-repeat; display: none; }
.hero-photo.has-photo { display: block; }
.hero-body { padding: 14px 16px 16px; }
.hero-top { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.hero h2 { margin: 0; font-size: 24px; }
.hero .sub { font-size: 15px; }
.km-big { display: flex; align-items: baseline; gap: 6px; margin-top: 12px; }
.km-big strong { font-size: 36px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.km-big .muted { font-size: 18px; }
.km-big .upd { margin-left: auto; font-size: 13px; color: var(--muted); }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 24px; }
.quick button {
  border: 0; border-radius: 14px; background: var(--card); color: var(--accent);
  padding: 12px 4px 10px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 13px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow);
}
.quick button i { font-style: normal; font-size: 24px; }
.quick button:active { background: var(--fill); }

.empty { text-align: center; padding: 50px 24px; }
.empty .big { font-size: 64px; }
.empty h3 { margin: 10px 0 6px; font-size: 22px; }
.empty p { color: var(--muted); margin: 0 0 22px; }

.btn {
  display: block; width: 100%; padding: 14px; border-radius: 13px; border: 0;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 17px; cursor: pointer; text-align: center;
}
.btn.secondary { background: var(--card); color: var(--accent); }
.btn.danger { background: var(--card); color: var(--red); }
.btn + .btn { margin-top: 10px; }

/* ---------- Formulare ---------- */
.field { display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 46px; position: relative; }
.field-label { flex: none; max-width: 52%; }
.field input:not([type=checkbox]), .field select, .field textarea {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 17px; padding: 12px 0; outline: none; text-align: right;
  -webkit-appearance: none; appearance: none;
}
.field.solo input, .field.solo textarea { text-align: left; }
.field textarea { resize: none; min-height: 90px; line-height: 1.35; }
.field select { direction: rtl; color: var(--accent); }
.field select option { direction: ltr; }
.field input[type=date], .field input[type=datetime-local] { color: var(--accent); min-height: 46px; }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: 0.7; }
.field .unit { color: var(--muted); flex: none; }
.field.km-input input { font-size: 30px; font-weight: 600; text-align: left; font-variant-numeric: tabular-nums; }

.switch { -webkit-appearance: none; appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--fill); position: relative; flex: none; margin-left: auto; cursor: pointer; transition: background .2s; }
.switch::after { 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,.25); transition: transform .2s; }
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 16px 12px; }
.chip { border: 0; background: var(--accent-soft); color: var(--accent); padding: 6px 12px; border-radius: 16px; font-size: 15px; cursor: pointer; }
.chip.on { background: var(--accent); color: #fff; }
.hidden { display: none !important; }
.warn-box { color: var(--orange); font-size: 15px; padding: 12px 16px; }

.search { width: 100%; border: 0; border-radius: 10px; background: var(--fill); padding: 9px 12px; font: inherit; font-size: 16px; color: var(--text); margin-bottom: 16px; outline: none; -webkit-appearance: none; }

/* ---------- Atașamente ---------- */
.thumbs { display: flex; gap: 12px; overflow-x: auto; padding: 14px 16px 12px; position: relative; }
.thumbs:empty { display: none; }
.thumb-wrap { position: relative; flex: none; }
.thumb {
  width: 76px; height: 76px; border-radius: 10px; flex: none; cursor: pointer;
  background: var(--fill) center / cover no-repeat; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--muted);
}
.thumb.pdf::after { content: "PDF"; }
.thumb.missing::after { content: "lipsă"; font-weight: 400; font-size: 12px; }
.thumb-x {
  position: absolute; top: -7px; right: -7px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--card); background: rgba(60,60,67,.85); color: #fff; font-size: 15px; line-height: 18px; padding: 0; cursor: pointer;
}
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; padding: 14px 16px; }
.gallery .thumb { width: 100%; height: auto; aspect-ratio: 1; }

/* ---------- Foaie de jos (formulare) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .2s ease;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 720px;
  height: calc(100% - env(safe-area-inset-top) - 10px);
  border-radius: 14px 14px 0 0; display: flex; flex-direction: column; overflow: hidden;
  animation: up .28s cubic-bezier(.2,.8,.2,1);
}
.sheet.short { height: auto; max-height: 80%; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 10px 8px; border-bottom: 0.5px solid var(--sep); background: var(--bg); }
.sheet-head .link-btn { border: 0; background: none; color: var(--accent); font-size: 17px; padding: 6px 8px; cursor: pointer; }
.sheet-head .link-btn:first-child { justify-self: start; }
.sheet-head .link-btn.strong { justify-self: end; font-weight: 600; }
.sheet-head .link-btn:disabled { opacity: .35; }
.sheet-title { font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 20px 16px calc(40px + env(safe-area-inset-bottom)); }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Vizualizare poze ---------- */
.viewer { position: fixed; inset: 0; z-index: 80; background: #000; color: #fff; display: flex; flex-direction: column; animation: fade .15s; }
.viewer-bar { display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top) + 6px) 8px 6px; }
.viewer-bar button { border: 0; background: none; color: #fff; font-size: 17px; padding: 8px 10px; cursor: pointer; }
.viewer-body { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; touch-action: pan-x pan-y pinch-zoom; }
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-pdf { text-align: center; padding: 30px; }
.viewer-pdf .big { font-size: 72px; }
.viewer-nav { display: flex; justify-content: space-between; padding: 6px 16px calc(env(safe-area-inset-bottom) + 10px); }
.viewer-nav button { border: 0; background: rgba(255,255,255,.15); color: #fff; border-radius: 20px; padding: 8px 18px; font-size: 17px; cursor: pointer; }
.viewer-nav button:disabled { opacity: .3; }

/* ---------- Grafice ---------- */
.chart-box { padding: 12px 10px 6px; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart .grid { stroke: var(--sep); stroke-width: 0.5; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: .09; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; padding: 0 16px 12px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Toast și banner ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: rgba(30,30,32,.92); color: #fff; padding: 11px 18px; border-radius: 22px;
  font-size: 15px; max-width: calc(100% - 32px); text-align: center; transition: all .25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#update-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 90;
  background: var(--accent); color: #fff; border-radius: 14px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  max-width: 696px; margin: 0 auto;
}
#update-banner[hidden] { display: none; }
#update-banner button { border: 0; background: #fff; color: var(--accent); font-weight: 600; border-radius: 10px; padding: 8px 14px; cursor: pointer; }

.year-chips { padding: 0 0 16px; margin: 0; }
.footer-status { text-align: center; font-size: 13px; color: var(--muted); margin: -6px 0 20px; }
.footer-status a { color: var(--accent); }

/* ================= Facturi ================= */
.btn { background: var(--check); color: var(--on-accent); }
.btn.secondary { background: var(--card); color: var(--accent); }
.btn.danger { background: var(--card); color: var(--red); }
.chip.on { background: var(--check); color: var(--on-accent); }
#update-banner { background: var(--check); color: #000; }
#update-banner button { color: #000; }

.page { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--bg); background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 500; color: var(--muted); padding: 4px 0; }
.tabbar a svg { width: 26px; height: 26px; }
.tabbar a.on { color: var(--accent); }
#update-banner { bottom: calc(76px + env(safe-area-inset-bottom)); }
#toast { bottom: calc(84px + env(safe-area-inset-bottom)); }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 14px; }
.month-nav h1 { font-size: 30px; font-weight: 700; margin: 0; letter-spacing: .2px; }
.month-nav .arrows { display: flex; gap: 6px; }
.month-nav button { border: 0; background: var(--card); color: var(--accent); width: 40px; height: 40px; border-radius: 20px; font-size: 22px; cursor: pointer; box-shadow: var(--shadow); }
.month-nav .today-btn { width: auto; padding: 0 14px; font-size: 15px; font-weight: 600; }

.summary { background: var(--card); border-radius: 14px; padding: 14px 16px; margin-bottom: 22px; box-shadow: var(--shadow); }
.summary .nums { display: flex; justify-content: space-between; gap: 12px; }
.summary .nums div { display: flex; flex-direction: column; }
.summary .nums b { font-size: 21px; font-variant-numeric: tabular-nums; }
.summary .nums span { font-size: 13px; color: var(--muted); }
.progress { height: 8px; border-radius: 4px; background: var(--fill); margin-top: 12px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--check); border-radius: 4px; transition: width .3s; }
.summary .count { font-size: 13px; color: var(--muted); margin-top: 7px; display: flex; justify-content: space-between; }

.check {
  flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--muted); opacity: .75;
  background: transparent; padding: 0; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .12s;
}
.check:active { transform: scale(.88); }
.check.on { background: var(--check); border-color: var(--check); opacity: 1; }
.check.on::after { content: ""; width: 7px; height: 13px; border: solid #000; border-width: 0 2.6px 2.6px 0; transform: rotate(45deg) translate(-1px, -1px); }
.check.auto { border-style: dashed; }
.bill-row { padding-left: 14px; }
.bill-row .grow { cursor: pointer; }
.bill-row.paid .title { color: var(--muted); }
.bill-row .amt { font-variant-numeric: tabular-nums; text-align: right; flex: none; cursor: pointer; }
.bill-row.paid .amt { color: var(--muted); }
.bill-row .amt small { display: block; font-size: 11px; color: var(--muted); }
.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 8px; background: var(--fill); color: var(--muted); margin: 3px 4px 0 0; font-weight: 500; }
.tag.red { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.tag.orange { background: color-mix(in srgb, var(--orange) 16%, transparent); color: var(--orange); }
.tag.green { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.tag.yellow { background: var(--accent-soft); color: var(--accent); }
.tags { line-height: 1.2; }

.note-box { white-space: pre-wrap; font-size: 16px; line-height: 1.4; }
.note-box a, .linkish { color: var(--accent); text-decoration: underline; }
.reading-delta { color: var(--muted); font-size: 13px; }
.big-input input { font-size: 28px !important; font-weight: 600; }
