:root {
  --bg: #f3f5f7; --card: #fff; --ink: #18232b; --muted: #6b7780; --line: #e3e8ec;
  --pri: #0f4c5c; --pri2: #1b7a8c; --priInk: #fff;
  --over: #c2410c; --overBg: #fff1ea; --soon: #a16207; --soonBg: #fff8e1; --ok: #15803d; --okBg: #eaf7ee;
  --svc: #1b7a8c; --fuel: #e08a1e; --oth: #8b5cf6;
  --r: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418; --card: #172128; --ink: #e8eef2; --muted: #93a1ab; --line: #26333c;
    --pri: #2b8fa3; --pri2: #48aabd; --overBg: #3a1d12; --over: #ff8a5c; --soonBg: #33290f; --soon: #f2c14e; --okBg: #12301f; --ok: #5fd48a;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.55 system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
small { display: block; color: var(--muted); font-size: .84rem; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }

#app { max-width: 720px; margin: 0 auto; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--pri); color: var(--priInk); }
.brand { display: flex; gap: 8px; align-items: center; font-size: 1.1rem; }
.sync { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.12); border: 0; border-radius: 99px; padding: 6px 10px; cursor: pointer; color: #fff; }
.sync small { color: #fff; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #7ee2a1; display: inline-block; }
.dot.warn { background: #ffc857; }
.dot.spin { border: 2px solid #fff; border-top-color: transparent; background: none; width: 14px; height: 14px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { padding: 8px 14px; }
.h { margin: 20px 4px 10px; font-size: 1.05rem; }
.row-h { display: flex; align-items: center; justify-content: space-between; }
.row-h h2 { font-size: 1.05rem; }

.card { background: var(--card); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 10px; }
.card h3 { font-size: .95rem; margin-bottom: 10px; }
.okbox { display: flex; gap: 8px; align-items: center; color: var(--ok); background: var(--okBg); border-color: transparent; }

.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: start; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow); }
.row b { display: block; font-weight: 600; }
.row .amt { font-weight: 600; white-space: nowrap; }
.row .chev { color: var(--muted); }
.row.lvl-over { border-inline-start: 4px solid var(--over); }
.row.lvl-soon { border-inline-start: 4px solid var(--soon); }
.badge { font-size: .78rem; padding: 3px 8px; border-radius: 99px; white-space: nowrap; background: var(--line); }
.lvl-over .badge { background: var(--overBg); color: var(--over); }
.lvl-soon .badge { background: var(--soonBg); color: var(--soon); }
.lvl-ok .badge { background: var(--okBg); color: var(--ok); }
.ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.ico.svc { background: color-mix(in srgb, var(--svc) 15%, transparent); color: var(--svc); }
.ico.fuel { background: color-mix(in srgb, var(--fuel) 15%, transparent); color: var(--fuel); }
.ico.exp { background: color-mix(in srgb, var(--oth) 15%, transparent); color: var(--oth); }
.ico.doc { background: color-mix(in srgb, var(--pri2) 15%, transparent); color: var(--pri2); }
.bar { display: block; height: 4px; background: var(--line); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.lvl-soon .bar i { background: var(--soon); }
.lvl-over .bar i { background: var(--over); }
.mark { width: 38px; height: 38px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; color: var(--muted); flex: none; }
.mark:hover { color: var(--ok); border-color: var(--ok); }

.cars { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.carcard { display: block; margin: 0; border-top: 4px solid var(--c); }
.carhead { display: flex; gap: 10px; align-items: center; }
.swatch { width: 14px; height: 14px; border-radius: 50%; background: var(--c); border: 1px solid rgba(0,0,0,.15); }
.carmeta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; color: var(--muted); font-size: .88rem; }
.carmeta span { display: flex; align-items: center; gap: 4px; }
.pill { font-size: .78rem; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--ink); display: inline-flex; align-items: center; }
.pill.warn { background: var(--overBg); color: var(--over); font-weight: 700; }
.pill.ok { background: var(--okBg); color: var(--ok); }

.cartop { display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; padding-bottom: 10px; border-bottom: 3px solid var(--c); }
.cartop h2 { font-size: 1.25rem; }
.back, .icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; border: 0; background: transparent; cursor: pointer; color: inherit; }
.icon:hover, .back:hover { background: var(--line); }
.odo { display: flex; width: 100%; align-items: center; gap: 12px; cursor: pointer; text-align: start; }
.odo b { font-size: 1.3rem; }
.link { color: var(--pri2); font-weight: 600; }
.subtabs { display: flex; gap: 4px; background: var(--line); padding: 4px; border-radius: 12px; margin: 6px 0 12px; }
.subtabs a { flex: 1; text-align: center; padding: 8px 4px; border-radius: 9px; font-size: .92rem; color: var(--muted); }
.subtabs a.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 12px; padding: 11px 16px; cursor: pointer; font-weight: 600; background: var(--line); }
.btn.primary { background: var(--pri); color: #fff; }
.btn.primary:disabled { opacity: .6; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--pri2); }
.btn.danger { background: var(--overBg); color: var(--over); }
.btn.danger.ghost { background: transparent; border-color: var(--over); }
.btn.small { padding: 6px 12px; font-size: .88rem; }
main > .btn.danger { width: 100%; margin-top: 18px; }
main > .btn.ghost { width: 100%; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.btns .btn { flex: 1; }

.fab { position: fixed; z-index: 6; inset-inline-start: max(18px, calc(50% - 342px)); bottom: calc(80px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--pri); color: #fff; box-shadow: 0 6px 18px rgba(15,76,92,.35); cursor: pointer; display: grid; place-items: center; }
.fab svg { width: 28px; height: 28px; }
.tabs { position: fixed; z-index: 5; bottom: 0; inset-inline: 0; display: flex; justify-content: center; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; max-width: 180px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 9px; color: var(--muted); font-size: .78rem; }
.tab.on { color: var(--pri2); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.stats .main { grid-column: 1 / -1; background: var(--pri); color: #fff; border: 0; }
.stats .main small { color: rgba(255,255,255,.8); }
.stat { margin: 0; }
.stat b { font-size: 1.15rem; display: block; }
.stats .main b { font-size: 1.6rem; }
.filters { display: flex; gap: 8px; margin-bottom: 10px; }
select { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; min-width: 110px; }
.filters select:last-child { flex: 1; }
main > select { margin-bottom: 10px; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 6px; }
.chart .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; }
.chart .stack { display: flex; flex-direction: column; border-radius: 5px 5px 0 0; overflow: hidden; min-height: 2px; }
.chart small { text-align: center; font-size: .64rem; margin-top: 4px; }
.chart i, .legend i { display: block; }
i.s { background: var(--svc); } i.f { background: var(--fuel); } i.o { background: var(--oth); }
.legend { display: flex; gap: 14px; justify-content: center; margin-top: 10px; font-size: .82rem; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.hbar { display: grid; grid-template-columns: 7rem 1fr auto; gap: 10px; align-items: center; margin: 8px 0; font-size: .9rem; }
.hbar span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track { height: 10px; background: var(--line); border-radius: 6px; overflow: hidden; }
.track i { display: block; height: 100%; border-radius: 6px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.code { letter-spacing: 2px; font-family: ui-monospace, Consolas, monospace; }
.hint { color: var(--muted); font-size: .88rem; margin: 8px 0; }
.empty { text-align: center; padding: 40px 20px; }
.empty svg, .hero svg { color: var(--pri2); }
.empty h2 { margin: 10px 0; }
.empty p { color: var(--muted); }

/* الترحيب */
.welcome { padding: calc(30px + env(safe-area-inset-top)) 18px 30px; max-width: 460px; margin: 0 auto; }
.hero { text-align: center; margin-bottom: 20px; }
.hero h1 { margin: 6px 0; font-size: 1.6rem; }
.hero p { color: var(--muted); margin: 0; }
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* النماذج */
.form, .fields { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: .9rem; color: var(--muted); }
input, textarea, select { width: 100%; }
input:not([type=checkbox]), textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; color: var(--ink); font-size: 1rem; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--pri2); outline-offset: -1px; }
.form label input { background: var(--bg); }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: start; }
.two label { white-space: nowrap; }
.two label > input { min-width: 0; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.check input { width: 20px; height: 20px; accent-color: var(--pri); }
.hijri { min-height: 1em; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { flex-direction: row; }
.chip input { position: absolute; opacity: 0; width: 1px; }
.chip span { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); color: var(--ink); cursor: pointer; font-size: .9rem; }
.chip input:checked + span { background: var(--pri); border-color: var(--pri); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--pri2); }
.chipadd { width: 130px !important; padding: 6px 12px !important; border-radius: 99px !important; font-size: .9rem !important; }
.err { color: var(--over); margin: 6px 0 0; font-size: .9rem; }

dialog#sheet { border: 0; padding: 0; width: 100%; max-width: 560px; max-height: 92vh; border-radius: 20px 20px 0 0; margin: auto auto 0; background: var(--card); color: var(--ink); }
@media (min-width: 640px) { dialog#sheet { border-radius: 20px; margin: auto; } }
dialog::backdrop { background: rgba(10,20,25,.45); }
.sheetform { display: flex; flex-direction: column; max-height: 92vh; }
.sheethead { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.sheetform .fields { padding: 4px 16px 10px; overflow-y: auto; }
.sheetform > .list { padding: 0 16px 20px; }
.sheetform > .err { padding: 0 16px; }
.sheetfoot { display: flex; gap: 10px; padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 6px 16px calc(22px + env(safe-area-inset-bottom)); }
.quick button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 6px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; }
.quick svg { width: 26px; height: 26px; color: var(--pri2); }
.stats .stat:not(.main) { padding: 12px 10px; }
.stats .stat:not(.main) b { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.okline { color: var(--ok); display: flex; gap: 6px; align-items: flex-start; }
