/* SOS KEY — design tokens. Brand: yellow #F8C800 + chrome silver + black. Light (white) is the default. */
:root {
  --brand: #f8c800;          /* brand yellow: fills, primary buttons, accents */
  --brand-2: #ffd633;
  --brand-ink: #8a6e00;      /* yellow-family TEXT on white (readable) */
  --on-brand: #111114;       /* text on yellow */
  --ok: #15803d;
  --ok-soft: rgba(21, 128, 61, .11);
  --warn: #b45309;
  --warn-soft: rgba(217, 119, 6, .12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, .10);
  --info: #1d4ed8;
  --info-soft: rgba(37, 99, 235, .10);

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --line: #e4e6ea;
  --text: #111114;
  --muted: #646a73;
  --shadow: 0 1px 2px rgba(17, 17, 20, .04), 0 6px 20px rgba(17, 17, 20, .06);
  --car-shade: #aeb3bb;
  --car-light: #f4f5f7;
  --glass: #2b2f38;
  --chrome: linear-gradient(145deg, #f7f8fa, #cfd3d9 55%, #eef0f2);
  --radius: 20px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e0f12; --surface: #17181c; --surface-2: #212228; --line: #2b2c33; --text: #f3f3f1; --muted: #9a9ca6;
  --brand-ink: #f8c800;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  --car-shade: #4a4e58; --car-light: #9aa0ab; --glass: #0b0c10;
  --chrome: linear-gradient(145deg, #3a3d45, #24262c 55%, #34373e);
  --ok: #22c55e; --danger: #ef4444; --warn: #f59e0b; --info: #60a5fa;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg:not(.leaflet-zoom-animated) { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
code, pre { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; direction: ltr; unicode-bidi: isolate; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h3 { font-size: 16px; font-weight: 600; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.dev-switch { display: flex; align-items: center; gap: 10px; text-align: start; min-width: 0; }
.logo { width: 40px; height: 40px; border-radius: 50%; box-shadow: 0 2px 8px rgba(17,17,20,.18); }
.brand-name { font-weight: 800; letter-spacing: .3px; }
.brand-name em { font-style: normal; color: var(--brand-ink); }
.dev-text { display: flex; flex-direction: column; min-width: 0; }
.dev-text strong { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev-text small { color: var(--muted); display: flex; align-items: center; gap: 6px; font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.top-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.icon-btn:hover { background: var(--surface-2); }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-inline-end: 6px; }
.conn.live { background: var(--ok); }

main { flex: 1; width: 100%; max-width: 620px; margin: 0 auto; padding: 14px 16px calc(96px + env(safe-area-inset-bottom)); }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid color-mix(in srgb, var(--line) 50%, transparent); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.link { color: var(--brand-ink); font-weight: 600; text-decoration: none; font-size: 14px; }

/* alarm banner */
.alarm-banner {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin-bottom: 14px; border-radius: var(--radius);
  background: linear-gradient(135deg, #c40018, #8a0011); color: #fff; box-shadow: 0 10px 30px rgba(196, 0, 24, .35);
}
.alarm-banner strong { display: block; font-size: 17px; }
.alarm-banner span { opacity: .92; font-size: 14px; }
.alarm-time { margin-inline-start: auto; font-size: 12px !important; white-space: nowrap; }
.pulse { width: 14px; height: 14px; border-radius: 50%; background: #fff; flex: none; animation: pulse 1.1s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.7); } 100% { box-shadow: 0 0 0 16px rgba(255,255,255,0); } }

/* hero */
.hero { padding: 14px 14px 6px; overflow: hidden; position: relative; }
.hero-status { display: flex; align-items: center; gap: 14px; }
.hero h1 { font-size: 22px; font-weight: 700; }
.status-ring { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); transition: .3s; }
.status-ring svg { width: 28px; height: 28px; stroke-width: 2; }
.status-ring.armed { background: var(--brand); color: var(--on-brand); }
.status-ring.disarmed { background: var(--warn-soft); color: var(--warn); }
.status-ring.alarm { background: var(--danger); color: #fff; animation: shake .6s infinite; }
@keyframes shake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }

.car-wrap { position: relative; display: flex; justify-content: center; align-items: center; gap: 16px; padding: 8px 0 4px; }
svg.car { width: 72px; height: 144px; overflow: visible; stroke: none; }
.car .car-shade { stop-color: var(--car-shade); }
.car .car-light { stop-color: var(--car-light); }
.car .glass { fill: var(--glass); opacity: .85; }
.car .roof { fill: var(--car-shade); opacity: .55; }
.car .door, .car .lid { fill: transparent; transition: fill .3s; }
.car .door.open, .car .lid.open { fill: var(--danger); filter: drop-shadow(0 0 6px var(--danger)); }
.car .lamp { fill: #fff6c8; opacity: .25; transition: .3s; }
.car .lamp.rear { fill: #ff5a5a; }
.car .lamp.on { opacity: 1; filter: drop-shadow(0 0 6px #ffd76a); }
.car .lamp.rear.on { filter: drop-shadow(0 0 6px #ff3030); }
.car .glow { fill: transparent; transition: fill .4s; }
.car.armed .glow { fill: rgba(248, 200, 0, .16); }
.car.alarm .glow { fill: var(--danger-soft); animation: blink .8s infinite; }
.car.alarm .lamp { opacity: 1; animation: blink .5s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.car-tags { display: flex; flex-direction: column; gap: 6px; max-inline-size: 55%; }
.car-tags:empty { display: none; }
.tag { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--danger-soft); color: var(--danger); }
.tag.info { background: var(--surface-2); color: var(--text); }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border-radius: 16px; padding: 12px; box-shadow: none; display: flex; flex-direction: column; gap: 2px; min-width: 0; border: 1px solid color-mix(in srgb, var(--line) 50%, transparent); }
.tile small { color: var(--muted); font-size: 13px; }
.tile b { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.t-ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); margin-bottom: 6px; }
.t-ico svg { width: 18px; height: 18px; }
.tile.ok .t-ico { background: var(--ok-soft); color: var(--ok); }
.tile.warn .t-ico { background: var(--warn-soft); color: var(--warn); }
.tile.bad .t-ico { background: var(--danger-soft); color: var(--danger); }
.tile.info .t-ico { background: var(--surface-2); color: var(--text); }

/* commands */
.cmd-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cmd { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px 2px; font-size: 13px; font-weight: 500; text-align: center; border-radius: 16px; transition: transform .1s; }
.cmd:active { transform: scale(.95); }
.cmd:disabled { opacity: .45; }
.cmd-ico { width: 58px; height: 58px; border-radius: 20px; display: grid; place-items: center; color: #111114; box-shadow: 0 4px 14px rgba(17,17,20,.10), inset 0 0 0 1px rgba(17,17,20,.06); }
.cmd-ico svg { width: 26px; height: 26px; stroke-width: 2; }
.cmd-ico.arm { background: var(--brand); }
.cmd-ico.disarm, .cmd-ico.find { background: linear-gradient(145deg, #f7f8fa, #cdd1d7 55%, #eceef1); }
.cmd-ico.siren { background: linear-gradient(145deg, #2a2b31, #111114); color: #f8c800; }
.ghost-btn { width: 100%; margin-top: 12px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 11px; border-radius: 14px; background: var(--surface-2); font-weight: 600; font-size: 14px; }
.ghost-btn svg { width: 18px; height: 18px; }
.cmd-log { list-style: none; margin: 10px 0 0; padding: 0; }
.cmd-log li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 2px; border-top: 1px solid var(--line); font-size: 13.5px; }
.st { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.st.queued { background: var(--surface-2); color: var(--muted); }
.st.delivered { background: var(--info-soft); color: var(--info); }
.st.done { background: var(--ok-soft); color: var(--ok); }
.st.failed, .st.expired { background: var(--danger-soft); color: var(--danger); }
.spin { width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

.loc-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.loc-row code { font-size: 13px; color: var(--muted); }

/* empty state */
.empty-state { text-align: center; padding: 40px 16px; }
.empty-state img { width: 104px; height: 104px; border-radius: 50%; margin-bottom: 16px; box-shadow: var(--shadow); }
.empty-state p { color: var(--muted); }
.empty-state code { display: block; margin-top: 12px; font-size: 12px; padding: 10px; border-radius: 12px; background: var(--surface-2); word-break: break-all; }

/* map */
#view-map.active { position: fixed; inset: 0; top: calc(env(safe-area-inset-top) + 61px); bottom: calc(68px + env(safe-area-inset-bottom)); padding: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); direction: ltr; }
.dark-tiles .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.7); }
.map-tools { position: absolute; inset-inline-end: 14px; top: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 450; }
.fab { width: 44px; height: 44px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; }
.fab.on { background: var(--brand); color: var(--on-brand); }
.map-chip { position: absolute; bottom: 14px; left: 14px; right: 14px; z-index: 450; background: var(--surface); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; align-items: center; }
.map-chip:empty { display: none; }
.map-chip .x { font-weight: 700; padding: 4px 10px; border-radius: 10px; background: var(--surface-2); }
.car-marker { width: 40px; height: 40px; display: grid; place-items: center; }
.car-marker .arrow { width: 34px; height: 34px; border-radius: 50%; background: #111114; border: 3px solid #fff; box-shadow: 0 4px 12px rgba(0,0,0,.35); display: grid; place-items: center; transition: transform .4s; }
.car-marker .arrow svg { width: 16px; height: 16px; fill: #f8c800; stroke: none; }
.car-marker.armed .arrow { background: var(--ok); }
.car-marker.alarm .arrow { background: var(--danger); animation: pulseRed 1s infinite; }
@keyframes pulseRed { 0% { box-shadow: 0 0 0 0 rgba(239,68,68,.7); } 100% { box-shadow: 0 0 0 18px rgba(239,68,68,0); } }
.pin { width: 14px; height: 14px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.pin.start { background: var(--ok); } .pin.end { background: #111114; }

/* events */
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 4px; scrollbar-width: none; }
.chip { min-height: 40px; display: inline-flex; align-items: center; padding: 7px 14px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); font-size: 13.5px; white-space: nowrap; }
.chip.active { background: var(--brand); color: var(--on-brand); border-color: var(--brand); font-weight: 600; }
.day { font-size: 13px; color: var(--muted); font-weight: 600; margin: 16px 4px 8px; }
.ev { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; background: var(--surface); border-radius: 16px; margin-bottom: 8px; box-shadow: var(--shadow); }
.ev-ico { width: 36px; height: 36px; flex: none; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.ev-ico svg { width: 18px; height: 18px; }
.ev.alarm .ev-ico { background: var(--danger); color: #fff; }
.ev.ok .ev-ico { background: var(--ok-soft); color: var(--ok); }
.ev.warn .ev-ico { background: var(--warn-soft); color: var(--warn); }
.ev.info .ev-ico { background: var(--info-soft); color: var(--info); }
.ev-body { flex: 1; min-width: 0; }
.ev-body b { font-weight: 600; display: block; }
.ev-body small { color: var(--muted); }
.ev-time { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.ev.new { animation: flash 1.2s ease; }
@keyframes flash { from { background: var(--warn-soft); } }

/* trips */
.trip-summary { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; gap: 8px; }
.trip-summary b { display: block; font-size: 20px; }
.trip-summary small { color: var(--muted); }
.trip { display: flex; gap: 12px; align-items: center; padding: 14px; background: var(--surface); border-radius: 16px; margin-bottom: 8px; box-shadow: var(--shadow); width: 100%; text-align: start; }
.trip-line { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: none; }
.trip-line i { width: 10px; height: 10px; border-radius: 50%; }
.trip-line i:first-child { background: var(--ok); } .trip-line i:last-child { background: var(--brand); box-shadow: 0 0 0 2px var(--text) inset; }
.trip-line span { width: 2px; height: 22px; background: var(--line); }
.trip-main { flex: 1; min-width: 0; }
.trip-main b { display: block; font-weight: 600; }
.trip-stats { display: flex; gap: 12px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.trip-km { font-size: 18px; font-weight: 700; white-space: nowrap; }
.trip-km small { font-size: 12px; color: var(--muted); font-weight: 500; }
.empty-list { text-align: center; color: var(--muted); padding: 40px 10px; }

/* tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 600;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 11.5px; color: var(--muted); position: relative; border-radius: 14px; }
.tab.active { color: var(--text); font-weight: 600; }
.tab.active svg { stroke-width: 2.2; background: var(--brand); color: var(--on-brand); border-radius: 12px; padding: 3px 14px; width: 52px; box-sizing: border-box; }
.tab svg { padding: 3px 14px; width: 52px; height: 28px; box-sizing: border-box; }
.badge { position: absolute; top: 2px; inset-inline-end: calc(50% - 22px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-style: normal; display: grid; place-items: center; }

/* sheets */
.sheet-bg { position: fixed; inset: 0; z-index: 1000; background: rgba(10, 10, 14, .5); display: flex; align-items: flex-end; justify-content: center; animation: fadeBg .2s; }
@keyframes fadeBg { from { opacity: 0; } }
.sheet { width: 100%; max-width: 520px; background: var(--surface); border-radius: 24px 24px 0 0; padding: 22px 20px calc(20px + env(safe-area-inset-bottom)); animation: up .25s ease; text-align: center; }
.sheet.tall { text-align: start; max-height: 88dvh; overflow-y: auto; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: -8px auto 14px; }
.sheet h3 { font-size: 19px; margin-bottom: 6px; }
.sheet-ico { width: 64px; height: 64px; border-radius: 22px; margin: 0 auto 14px; display: grid; place-items: center; color: #fff; }
.sheet-ico svg { width: 30px; height: 30px; stroke-width: 2; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.btn { padding: 13px 16px; border-radius: 14px; font-weight: 600; }
.btn.primary { background: var(--brand); color: var(--on-brand); width: 100%; }
.btn.primary.danger { background: var(--danger); color: #fff; }
.btn.secondary { background: var(--surface-2); }
.btn.sm { padding: 9px 14px; }
.field { display: block; margin: 16px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field select, .field input { width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
pre.info { margin: 0; padding: 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; white-space: pre-wrap; word-break: break-all; text-align: left; }

/* toasts */
.toasts { position: fixed; top: calc(env(safe-area-inset-top) + 70px); left: 50%; transform: translateX(-50%); z-index: 1200; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: #111114; color: #fff; padding: 12px 16px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-weight: 500; font-size: 14px; animation: up .25s; }
.toast.alarm { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

@media (min-width: 900px) {
  .tiles { grid-template-columns: repeat(6, 1fr); }
  main { max-width: 760px; }
}
@media (max-width: 360px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .cmd-ico { width: 50px; height: 50px; }
}

/* splash */
.splash { position: fixed; inset: 0; z-index: 2000; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; transition: opacity .35s; }
.splash img { width: 132px; height: 132px; border-radius: 50%; box-shadow: 0 10px 40px rgba(17,17,20,.18); animation: pop .5s ease; }
.splash b { font-size: 26px; font-weight: 800; letter-spacing: .5px; }
.splash b em { font-style: normal; color: var(--brand-ink); }
.splash small { color: var(--muted); letter-spacing: .4px; }
.splash.gone { opacity: 0; pointer-events: none; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.tagline { color: var(--muted); font-size: 12.5px; text-align: center; margin: 8px 0 0; }
.hero { border-top: 4px solid var(--brand); }

/* review pass (Codex, 2026-10-05) */
.controls-card, .hero { box-shadow: var(--shadow); }
:lang(ar) h1, :lang(ar) h3 { line-height: 1.5; }
:lang(ar) .splash small { letter-spacing: 0; }
.alarm-time, .ev-time, .trip-km, .trip-summary b { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; border-radius: 8px; }
.icon-btn, .ghost-btn, .fab, .chip, .trip { transition: transform .12s ease; }
.icon-btn:active, .ghost-btn:active, .fab:active, .trip:active { transform: scale(.97); }
.cmd.busy .cmd-ico { opacity: .6; }
.status-sub-stale { color: var(--warn); }
:root[data-theme="dark"] .toast.ok { background: #166534; }
:root[data-theme="dark"] .toast.alarm, :root[data-theme="dark"] .btn.primary.danger { background: #b91c1c; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
