:root {
  --surface: #ffffff;
  --text: #16211d;
  --muted: #5d6b66;
  --line: #dfe5e2;
  --accent: #0e6b5c;
  --accent-text: #ffffff;
  --gold: #c9a13b;
  --field: #f1f5f3;
  --warn-bg: #fff3df;
  --warn-text: #7a4a00;
  --shadow: 0 6px 24px rgba(10, 25, 20, 0.2);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface: #12211e;
    --text: #edf3f0;
    --muted: #a5b3ae;
    --line: #2f3c37;
    --accent: #35c2a1;
    --accent-text: #06231a;
    --gold: #e0bd62;
    --field: #1c2f2b;
    --warn-bg: #3d2d12;
    --warn-text: #ffd896;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --surface: #12211e;
  --text: #edf3f0;
  --muted: #a5b3ae;
  --line: #2f3c37;
  --accent: #35c2a1;
  --accent-text: #06231a;
  --gold: #e0bd62;
  --field: #1c2f2b;
  --warn-bg: #3d2d12;
  --warn-text: #ffd896;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--surface);
  color: var(--text);
  font: 15px/1.55 "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  overflow: hidden;
}

#map { position: fixed; inset: 0; direction: ltr; }

button, input { font: inherit; }

button {
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.card {
  position: fixed;
  z-index: 10;
  width: min(380px, calc(100vw - 24px));
  padding: 14px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.muted { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }

#search-card { top: calc(12px + env(safe-area-inset-top, 0px)); inset-inline-start: 12px; }
#search-card { padding: 8px; }
#btn-menu { flex: none; width: 46px; padding: 0; border: 0; background: transparent; font-size: 22px; }
#search-form .primary { flex: none; width: 46px; padding: 0; font-size: 18px; }
#search-card > :not(#search-form) { margin-inline: 6px; }

#search-form { display: flex; gap: 8px; }
#search-input {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--field);
  color: var(--text);
  font-size: 17px;
}

#search-status { margin: 8px 0 0; }
#results { list-style: none; margin: 8px 0 0; padding: 0; max-height: 40vh; overflow-y: auto; }
#results button {
  display: block;
  width: 100%;
  height: auto;
  padding: 10px 10px;
  font-weight: 400;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: start;
}
#results small { display: block; color: var(--muted); }

#quick-places { display: flex; gap: 8px; margin-top: 8px; }
#quick-places { margin-bottom: 4px; }
#quick-places button { flex: 1; min-height: 40px; border-radius: 999px; font-size: 14px; background: var(--field); border-color: transparent; }
#quick-places button.unset { border-style: dashed; color: var(--muted); }

#route-card { top: 196px; inset-inline-start: 12px; max-height: calc(100vh - 216px); overflow-y: auto; }
.route-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
#route-eta { font-size: 22px; font-weight: 700; }
#route-summary { color: var(--muted); font-weight: 600; }
#route-warn { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); }
#route-modes { display: flex; gap: 8px; margin-top: 10px; }
#route-modes button { flex: 1; height: auto; padding: 6px 4px; line-height: 1.3; text-align: center; }
#route-modes .mode-icon { display: block; font-size: 22px; }
#route-modes strong, #route-modes small { display: block; }
#route-modes small { color: var(--muted); font-size: 11px; }
#route-modes button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
#route-modes button:disabled { opacity: 0.5; }
#route-options { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; }
#route-options button { flex: 1; min-width: 104px; height: auto; padding: 8px 10px; text-align: start; line-height: 1.35; }
#route-options strong, #route-options small { display: block; }
#route-options small { color: var(--muted); font-size: 12px; }
#route-options button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
#btn-start { flex: 1; min-height: 54px; border-radius: 14px; font-size: 18px; }
#save-places { display: flex; gap: 8px; margin-top: 8px; }
#save-places button { flex: 1; min-height: 36px; border-radius: 999px; font-size: 13px; }
#steps-box { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
#steps-box summary { font-weight: 600; cursor: pointer; }
#steps { margin: 8px 0 0; padding-inline-start: 22px; max-height: 32vh; overflow-y: auto; }
#steps li { padding: 3px 0; }
#steps small { color: var(--muted); }

#nav-banner {
  top: calc(12px + env(safe-area-inset-top, 0px));
  inset-inline-start: 12px;
  width: min(420px, calc(100vw - 24px));
  background: linear-gradient(135deg, #0a4038, #0f6b5c);
  border: 1px solid rgba(224, 189, 98, 0.45);
  color: #ffffff;
}
#nav-banner p { margin: 0; }
.nav-turn { display: flex; align-items: center; gap: 12px; }
#nav-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.16);
  color: #f3d98c;
  font-size: 30px;
}
#nav-icon svg { width: 42px; height: 42px; }
#nav-distance { color: #d3ebe5; }
#nav-instruction { font-size: 21px; font-weight: 700; line-height: 1.35; }
#nav-alert { margin-top: 8px !important; padding: 8px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); font-weight: 600; }

#nav-bar {
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  inset-inline-start: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-stats { flex: 1; min-width: 0; }
#nav-eta { display: block; font-size: 21px; }
#btn-voice { padding: 0 12px; font-size: 20px; }
#btn-stop { background: #c0392b; border-color: #c0392b; color: #ffffff; min-width: 84px; }

#speedo {
  position: fixed;
  z-index: 10;
  bottom: calc(var(--nav-h, 70px) + 24px + env(safe-area-inset-bottom, 0px));
  inset-inline-start: 12px;
  display: grid;
  place-content: center;
  width: 78px;
  height: 78px;
  border: 5px solid var(--accent);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  line-height: 1.1;
}
#speed-value { font-size: 27px; font-weight: 800; }
#speedo small { color: var(--muted); font-size: 11px; font-weight: 600; }

#btn-recenter {
  position: fixed;
  z-index: 12;
  left: 50%;
  bottom: calc(var(--nav-h, 70px) + 28px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow);
  white-space: nowrap;
}

#confirm-card { bottom: calc(var(--nav-h, 70px) + 128px + env(safe-area-inset-bottom, 0px)); }
#confirm-card p { margin: 0; font-size: 18px; font-weight: 700; }
#confirm-card button { flex: 1; min-height: 52px; font-size: 17px; }

#fabs {
  position: fixed;
  z-index: 10;
  bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  inset-inline-end: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#fabs button { width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%; box-shadow: var(--shadow); font-size: 23px; }
#btn-report { background: var(--gold) !important; }
body[data-mode="nav"] #fabs { bottom: calc(var(--nav-h, 70px) + 56px + env(safe-area-inset-bottom, 0px)); }
body[data-mode="nav"] #btn-locate { display: none; }

/* شعار الخريطة وحقوقها وأزرار التكبير تبقى ظاهرة فوق البطاقة السفلية. */
body[data-mode="nav"] :is(.mapboxgl-ctrl-bottom-left, .mapboxgl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right) {
  bottom: calc(var(--nav-h, 70px) + 12px + env(safe-area-inset-bottom, 0px));
}
body[data-mode="nav"] :is(.mapboxgl-ctrl-group, .maplibregl-ctrl-group) { display: none; }

#pilot-card h2 { margin: 0 0 6px; font-size: 17px; }
#pilot-form { display: flex; gap: 8px; margin-top: 8px; }
#pilot-input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
}
#pilot-error { margin: 8px 0 0; color: var(--warn-text); }

#report-sheet, #place-bar, #pilot-card, #confirm-card {
  inset-inline-start: 50%;
  transform: translateX(50%);
  z-index: 20;
}
#report-sheet, #place-bar, #pilot-card { bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
#report-sheet h2 { margin: 0 0 10px; font-size: 17px; }
#report-sheet { max-height: 80vh; overflow-y: auto; }
.report-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.note { margin: 0 0 4px; font-size: 13px; }
#report-types button { height: 72px; padding: 4px; line-height: 1.3; }
#report-types span { display: block; font-size: 22px; }
#report-sheet > button { width: 100%; }
#place-bar p { margin: 0; }

#menu {
  top: calc(12px + env(safe-area-inset-top, 0px));
  inset-inline-end: 12px;
  z-index: 40;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
}
.menu-head { display: flex; align-items: center; justify-content: space-between; }
.menu-head h2 { margin: 0; font-size: 17px; }
#menu h3, #report-types h3 { margin: 12px 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.options { display: flex; flex-wrap: wrap; gap: 8px; }
.options button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-text); font-weight: 600; }
#color-options button { width: 42px; padding: 0; border-radius: 50%; border-width: 2px; }
#color-options button[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
#traffic-legend { margin: 0; font-size: 13px; }
.swatch { display: inline-block; width: 18px; height: 6px; margin-inline-start: 8px; border-radius: 3px; vertical-align: middle; }
.swatch.moderate { background: #ff8c1a; }
.swatch.heavy { background: #ff0015; }
.swatch.severe { background: #981b25; }
#route-traffic { margin: 8px 0 0; color: var(--warn-text); font-weight: 600; }
#menu details { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
#menu summary { font-weight: 600; cursor: pointer; }
#menu ol { margin: 8px 0; padding-inline-start: 20px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 42px; margin-top: 12px; }
#btn-clear-places { width: 100%; margin-top: 8px; }

#crosshair {
  position: fixed;
  z-index: 5;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  background: rgba(47, 177, 141, 0.25);
  pointer-events: none;
}

#hint, #toast, #gps-chip {
  position: fixed;
  z-index: 30;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  padding: 8px 14px;
  border-radius: 999px;
  background: #16211d;
  color: #ffffff;
  box-shadow: var(--shadow);
  text-align: center;
}
#hint { bottom: 96px; }
#toast { bottom: 140px; }
#gps-chip { top: calc(12px + env(safe-area-inset-top, 0px)); background: #7a4a00; }

.pin {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  min-height: 0;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.pin.from { background: #0b7a5c; color: #ffffff; font-size: 13px; }
.pin.to { background: #c0392b; color: #ffffff; font-size: 13px; }
.vehicle { width: 48px; height: 84px; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.5)); pointer-events: none; }
.vehicle svg { display: block; width: 100%; height: 100%; }

.maplibregl-popup-content, .mapboxgl-popup-content { direction: rtl; color: #16211d; font: 14px/1.5 "Segoe UI", Tahoma, sans-serif; border-radius: 10px; min-width: 170px; }
/* علامة الإغلاق: دائرة حمراء واضحة على زاوية النافذة، بحجم يناسب الإصبع. */
.maplibregl-popup-close-button {
  top: -14px;
  right: -14px;
  width: 34px;
  height: 34px;
  min-height: 0;
  padding: 0;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #c0392b;
  color: #ffffff;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.maplibregl-popup-close-button:hover { background: #a93226; }
.popup-title { font-weight: 700; margin-bottom: 2px; }
.popup-meta { color: #5d6b66; font-size: 13px; }
.popup-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.popup-actions button { min-height: 34px; padding: 0 10px; background: #ffffff; color: #16211d; border-color: #dfe5e2; }

@media (max-width: 560px) {
  .card { width: calc(100vw - 20px); }
  #search-card, #nav-banner { inset-inline-start: 10px; }
  #route-card, #nav-bar {
    top: auto;
    bottom: 0;
    inset-inline: 0;
    width: 100%;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    border-radius: 22px 22px 0 0;
  }
  #route-card { max-height: 64vh; padding-top: 20px; }
  #route-card::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    width: 40px;
    height: 4px;
    margin-left: -20px;
    border-radius: 2px;
    background: var(--line);
  }
  #menu { inset-inline: 10px; max-height: calc(100vh - 20px); }
  #steps { max-height: 22vh; }
  #results { max-height: 30vh; }
  body[data-mode="route"] #fabs { bottom: calc(var(--route-h, 46vh) + 56px + env(safe-area-inset-bottom, 0px)); }
  body[data-mode="route"] :is(.mapboxgl-ctrl-bottom-left, .mapboxgl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right) {
    bottom: calc(var(--route-h, 46vh) + 12px + env(safe-area-inset-bottom, 0px));
  }
  body[data-mode="route"] :is(.mapboxgl-ctrl-group, .maplibregl-ctrl-group) { display: none; }
}

#splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #0d4a42 url(splash.jpg) center / cover no-repeat;
  animation: splash-out 0.5s ease 2.2s forwards;
}
@keyframes splash-out { to { opacity: 0; visibility: hidden; } }

#account-box { margin-top: 10px; padding: 12px; border-radius: 14px; background: var(--field); }
#account-out p { margin: 0 0 10px; font-size: 13px; }
#btn-google { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; background: #ffffff; color: #1f1f1f; border-color: #dadce0; }
#btn-google span { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #4285f4; color: #ffffff; font-weight: 700; }
#btn-google:disabled { opacity: 0.55; }
#google-web-button:not(:empty) { display: flex; justify-content: center; }
#account-note { margin: 8px 0 0 !important; }
.account-row { display: flex; align-items: center; gap: 12px; }
#account-avatar { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 20px; font-weight: 700; }
.account-row strong, .account-row small { display: block; }
.account-row small { color: var(--muted); text-align: start; }
#account-in .actions button { flex: 1; }
#btn-delete-account { color: #c0392b; }
#privacy-link { display: inline-block; margin-top: 10px; color: var(--muted); font-size: 13px; }