:root {
  --bg: #0b0f14;
  --panel: rgba(16, 21, 28, 0.82);
  --panel-solid: #121820;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef2f6;
  --muted: #8b97a6;
  --faint: #5b6674;
  --accent: #3ee0a1;
  --warn: #ffb547;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --stop-fill: #0b0f14;
  --stop-ring: #e7edf3;
  --font: "Outfit", system-ui, sans-serif;
  --thaana: "Noto Sans Thaana", "MV Faseyha", sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #eef1f4;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --line: rgba(10, 20, 30, 0.08);
  --text: #121820;
  --muted: #5d6a78;
  --faint: #93a0ae;
  --accent: #0fa56b;
  --shadow: 0 20px 50px rgba(20, 30, 40, 0.18);
  --stop-fill: #ffffff;
  --stop-ring: #1c2530;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
button { font: inherit; color: inherit; }

#map { position: fixed; inset: 0; background: var(--bg); }
.leaflet-container { background: var(--bg); font-family: var(--font); }
.leaflet-control-attribution { background: var(--panel) !important; color: var(--faint) !important; font-size: 10px; backdrop-filter: blur(8px); }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-control-zoom { border: none !important; box-shadow: var(--shadow) !important; }
.leaflet-control-zoom a { background: var(--panel) !important; color: var(--text) !important; border-color: var(--line) !important; backdrop-filter: blur(12px); }

/* ---------- panel ---------- */
.panel {
  position: fixed; top: 16px; left: 16px; bottom: 16px; width: 360px; z-index: 1000;
  display: flex; flex-direction: column; gap: 14px; padding: 18px;
  background: var(--panel); backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow);
}
.grab { display: none; }
.brand { display: flex; justify-content: space-between; align-items: center; }
.brand-mark { display: flex; gap: 12px; align-items: center; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.clock { font-size: 26px; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.brand-right { display: flex; align-items: center; gap: 8px; }
.hide-btn { display: none; }
.sheet-fab { display: none; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--faint); position: relative; flex: none; }
.pulse.live { background: var(--accent); }
.pulse.live::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid var(--accent); animation: ping 2s ease-out infinite; }
.pulse.err { background: #ff5d5d; }
@keyframes ping { from { transform: scale(0.5); opacity: 0.9; } to { transform: scale(1.6); opacity: 0; } }

.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn {
  border: 1px solid var(--line); background: transparent; padding: 7px 12px; border-radius: 999px;
  font-size: 13px; color: var(--muted); cursor: pointer; transition: 0.15s;
}
.chip-btn:hover { color: var(--text); }
.chip-btn.active { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 500; }

h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--faint); margin: 0 0 8px; font-weight: 600; }

.routes { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px; scrollbar-width: thin; }
#route-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.route {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  padding: 9px 10px; border-radius: 14px; cursor: pointer; transition: background 0.15s, opacity 0.15s;
  border: 1px solid transparent;
}
.route:hover { background: var(--line); }
.route.off { opacity: 0.38; }
.route.selected { border-color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); }
.badge {
  min-width: 40px; height: 28px; padding: 0 8px; border-radius: 9px; display: grid; place-items: center;
  background: var(--c); color: #fff; font-weight: 700; font-size: 14px; letter-spacing: -0.01em;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--c) 45%, transparent);
}
.route .name { font-size: 14px; font-weight: 500; line-height: 1.2; }
.route .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.count { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.count b { color: var(--text); font-weight: 600; font-size: 15px; }
.count .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.count.none .dot { background: var(--faint); }

/* ---------- detail (selected route / bus / stop) ---------- */
.detail { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 14px 0; max-height: 46%; overflow-y: auto; scrollbar-width: thin; }
.detail-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.detail-head .title { font-size: 16px; font-weight: 600; line-height: 1.2; }
.detail-head .dv { font-family: var(--thaana); direction: rtl; font-size: 13px; color: var(--muted); }
.detail-head .close { margin-left: auto; background: var(--line); border: none; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; color: var(--muted); flex: none; }
.detail-head .close:hover { color: var(--text); }

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--c); opacity: 0.85; }
.timeline li { display: grid; grid-template-columns: 17px 1fr auto; gap: 12px; align-items: center; padding: 6px 0; position: relative; cursor: pointer; }
.timeline li:hover .stop-name { color: var(--text); }
.timeline .node { width: 17px; height: 17px; border-radius: 50%; background: var(--stop-fill); border: 3px solid var(--c); z-index: 1; }
.timeline li.term .node { width: 17px; height: 17px; background: var(--c); }
.stop-name { font-size: 13px; color: var(--muted); line-height: 1.25; }
.timeline li.term .stop-name { color: var(--text); font-weight: 500; }
.eta { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--faint); white-space: nowrap; }
.eta.soon { color: var(--accent); font-weight: 600; }
.eta.here { color: #fff; background: var(--accent); padding: 2px 8px; border-radius: 999px; font-weight: 600; }
:root[data-theme="light"] .eta.here { color: #fff; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; margin-bottom: 10px; }
.kv dt { color: var(--faint); }
.kv dd { margin: 0; }
.note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

.foot { font-size: 11px; color: var(--faint); }

/* ---------- my stop ---------- */
:root { --ok: var(--accent); --soon: #ffb547; --now: #ff5d5d; }
.mystop { flex: none; }
.mystop-empty {
  display: flex; gap: 10px; align-items: flex-start; font-size: 12.5px; line-height: 1.4; color: var(--muted);
  padding: 10px 12px; border: 1px dashed var(--line); border-radius: 14px;
}
.mystop-empty b { color: var(--text); font-weight: 600; display: block; }
.mystop-empty .star { font-size: 18px; color: var(--soon); line-height: 1.1; }

.mystop-card {
  --u: var(--ok);
  position: relative; padding: 12px 14px 10px; border-radius: 16px;
  background: color-mix(in srgb, var(--u) 11%, transparent);
  border: 1px solid color-mix(in srgb, var(--u) 35%, transparent);
  transition: background 0.4s, border-color 0.4s;
}
.mystop-card[data-urgency="soon"] { --u: var(--soon); }
.mystop-card[data-urgency="now"], .mystop-card[data-urgency="late"] { --u: var(--now); }
.mystop-card[data-urgency=""] { --u: var(--faint); }
.mystop-card.flash { animation: flash 0.9s ease-in-out 3; }
@keyframes flash { 50% { background: color-mix(in srgb, var(--u) 35%, transparent); } }

.ms-stop { all: unset; cursor: pointer; display: flex; gap: 8px; align-items: baseline; max-width: 100%; }
.ms-label { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--u); white-space: nowrap; }
.ms-name { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-name small { font-size: 12px; color: var(--faint); }
.ms-big { font-size: 26px; font-weight: 300; letter-spacing: -0.02em; margin: 4px 0 2px; }
.ms-big b { font-weight: 700; color: var(--u); font-size: 32px; }
.ms-big.muted { font-size: 18px; color: var(--muted); }
.ms-sub { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.badge.sm { min-width: 30px; height: 20px; font-size: 11px; border-radius: 6px; padding: 0 5px; box-shadow: none; }
.ms-list { list-style: none; margin: 8px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); display: grid; gap: 5px; }
.ms-list li { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; font-size: 12.5px; color: var(--muted); }
.ms-leave { font-variant-numeric: tabular-nums; color: var(--faint); }

.ms-routes { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.ms-route {
  border: 1.5px solid var(--c); background: transparent; color: var(--muted); cursor: pointer;
  font-size: 11.5px; font-weight: 700; height: 24px; min-width: 36px; padding: 0 7px; border-radius: 7px; opacity: 0.55;
}
.ms-route.on { background: var(--c); color: #fff; opacity: 1; }
.ms-controls { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.walk { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.walk b { color: var(--text); min-width: 16px; text-align: center; font-variant-numeric: tabular-nums; }
.walk button, .bell {
  border: 1px solid var(--line); background: var(--panel-solid); color: var(--text); cursor: pointer;
  height: 28px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.walk button { width: 28px; font-size: 16px; line-height: 1; padding: 0; }
.walk .locate { margin-left: 2px; }
.walk svg, .bell svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bell { padding: 0 11px; font-size: 12.5px; }
.bell.on { background: var(--u); border-color: var(--u); color: #fff; }
.ms-note { margin: 6px 0 0; font-size: 12px; color: var(--muted); min-height: 0; }
.ms-note:empty { display: none; }

/* alerts panel */
.alerts { margin-top: 8px; border: 1px solid var(--line); border-radius: 16px; padding: 4px 14px; background: var(--line); }
.al-section { padding: 10px 0; }
.al-section + .al-section { border-top: 1px solid var(--line); }
.al-toggle { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: 13px; }
.al-toggle input { margin-top: 2px; width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.al-toggle small, .al-sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; line-height: 1.35; }
.al-title { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.al-on { font-size: 11px; font-weight: 700; color: #fff; background: var(--accent); border-radius: 999px; padding: 2px 8px; }
.al-row { display: grid; grid-template-columns: 62px 1fr; align-items: center; gap: 8px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.al-days, .al-lead, .al-times { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.al-day, .al-chip {
  border: 1px solid var(--line); background: var(--panel-solid); color: var(--muted); cursor: pointer;
  height: 28px; border-radius: 999px; font-size: 12px;
}
.al-day { width: 28px; padding: 0; font-weight: 600; }
.al-chip { padding: 0 10px; }
.al-day.on, .al-chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.al-times input {
  font: inherit; font-size: 13px; color: var(--text); background: var(--panel-solid); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 6px; color-scheme: inherit;
}
.al-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.al-primary, .al-secondary { height: 32px; border-radius: 999px; padding: 0 14px; font-size: 13px; cursor: pointer; font-weight: 500; }
.al-primary { background: var(--accent); color: #062015; border: none; }
.al-secondary { background: transparent; color: var(--text); border: 1px solid var(--line); }
.al-help { font-size: 12.5px; color: var(--text); background: color-mix(in srgb, var(--soon) 14%, transparent); border-radius: 10px; padding: 8px 10px; margin: 10px 0 0; line-height: 1.4; }
.al-status { font-size: 12px; color: var(--accent); margin: 8px 0 0; }
.al-status:empty { display: none; }

.mystop-pick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: -2px 0 12px; }
.mystop-pick.is-set { justify-content: space-between; font-size: 13px; color: var(--soon); font-weight: 500; }
.mystop-pick .note { width: 100%; margin: 0; }
.star-btn {
  border: 1px solid color-mix(in srgb, var(--soon) 50%, transparent); background: color-mix(in srgb, var(--soon) 12%, transparent);
  color: var(--text); border-radius: 999px; padding: 7px 12px; font-size: 13px; cursor: pointer;
}
.star-btn:hover { background: color-mix(in srgb, var(--soon) 22%, transparent); }
.link-btn { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 12.5px; text-decoration: underline; }

#status[data-urgency="ok"] { color: var(--ok); font-weight: 500; }
#status[data-urgency="soon"] { color: var(--soon); font-weight: 600; }
#status[data-urgency="now"], #status[data-urgency="late"] { color: var(--now); font-weight: 600; }
.sheet-fab[data-urgency="soon"] { border-color: var(--soon); }
.sheet-fab[data-urgency="now"] { border-color: var(--now); color: var(--now); }

.mystop-pin { background: none; border: none; }
.mystop-pin .pin {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%);
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; rotate: -45deg; margin-top: -4px;
  background: var(--soon); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45); display: grid; place-items: center; cursor: pointer;
}
.mystop-pin .pin span { rotate: 45deg; color: #1a1300; font-size: 15px; font-weight: 700; }

/* ---------- map furniture ---------- */
.map-controls { position: fixed; right: 16px; top: calc(16px + env(safe-area-inset-top)); z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.map-controls button {
  width: 42px; height: 42px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel);
  backdrop-filter: blur(12px); box-shadow: var(--shadow); cursor: pointer; display: grid; place-items: center;
}
.map-controls svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.stop-dot { border-radius: 50%; background: var(--stop-fill); border: 2.5px solid var(--stop-ring); box-sizing: border-box; }
.stop-dot.term { border-width: 3.5px; }
.leaflet-tooltip.stop-tip {
  background: var(--panel-solid); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); font-family: var(--font); font-size: 12px; padding: 5px 9px;
}
.leaflet-tooltip.stop-tip::before { display: none; }

/* ---------- bus marker ---------- */
.bus-marker { background: none; border: none; }
.bus {
  --size: 34px; position: relative; width: var(--size); height: var(--size); cursor: pointer;
  transition: filter 0.3s, opacity 0.3s;
}
.bus .halo {
  position: absolute; inset: 8%; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--c) 70%, transparent) 0%, transparent 70%);
  animation: halo 2.4s ease-in-out infinite;
}
@keyframes halo { 50% { transform: scale(1.35); opacity: 0.55; } }
.bus .body { position: absolute; inset: 0; display: grid; place-items: center; transform: rotate(var(--rot, 0deg)); transition: transform 0.8s ease; }
.bus .body img, .bus .body svg { height: var(--size); width: auto; max-width: none; filter: drop-shadow(0 3px 4px rgba(0,0,0,0.55)); }
.bus-marker .bus { position: absolute; left: 0; top: 0; transform: translate(-50%, -50%); --size: var(--bus-size, 34px); }
.stop-cm { stroke: var(--stop-ring); fill: var(--stop-fill); }
.bus .tag {
  position: absolute; left: 50%; top: -12px; transform: translate(-50%, -50%);
  background: var(--c); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.4); white-space: nowrap; pointer-events: none;
}
.bus.idle { filter: saturate(0.2) brightness(0.8); opacity: 0.75; }
.bus.idle .halo { animation: none; opacity: 0.25; }
.bus.picked .halo { inset: -20%; }
.bus.dim { opacity: 0.22; filter: saturate(0); }
.bus.dim .halo { animation: none; }
.small-zoom .bus .tag { display: none; }

/* ---------- mobile: bottom sheet ---------- */
@media (max-width: 720px) {
  /* Draggable sheet: fixed height, slid down so only --sheet px shows (set by app.js). */
  .panel {
    --sheet: 46vh;
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 88vh; border-radius: 22px 22px 0 0;
    padding: 0 16px calc(12px + env(safe-area-inset-bottom)); gap: 10px;
    transform: translateY(calc(88vh - var(--sheet)));
    transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
  }
  .panel.dragging { transition: none; }
  .grab {
    display: block; width: 100%; height: 22px; margin-bottom: -8px; cursor: grab; touch-action: none; flex: none;
    background: none; position: relative;
  }
  .grab::after { content: ""; position: absolute; left: 50%; top: 9px; width: 40px; height: 5px; margin-left: -20px; border-radius: 5px; background: var(--faint); opacity: 0.7; }
  .brand { touch-action: none; cursor: grab; flex: none; }
  .clock { font-size: 20px; }
  .brand h1 { font-size: 19px; }
  .map-controls { top: calc(12px + env(safe-area-inset-top)); right: 12px; }
  .detail { max-height: 50%; }
  .leaflet-bottom { bottom: var(--sheet-px, 46vh); transition: bottom 0.32s cubic-bezier(0.2, 0.8, 0.2, 1); }
  .dragging-sheet .leaflet-bottom { transition: none; }
  .leaflet-bottom { margin-bottom: env(safe-area-inset-bottom); }

  /* hide button next to the clock */
  .hide-btn {
    display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
    border: none; background: var(--line); cursor: pointer; padding: 0;
  }
  .hide-btn svg, .sheet-fab svg { width: 18px; height: 18px; fill: none; stroke: var(--text); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

  /* fully hidden: panel off-screen, a small pill brings it back */
  .sheet-hidden .panel { pointer-events: none; box-shadow: none; }
  .sheet-fab {
    display: flex; align-items: center; gap: 8px;
    position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 1001;
    transform: translate(-50%, 140%); opacity: 0; pointer-events: none;
    padding: 10px 14px 10px 16px; border-radius: 999px; border: 1px solid var(--line);
    background: var(--panel); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow); font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer;
    transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s;
  }
  .sheet-hidden .sheet-fab { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
  .sheet-hidden .leaflet-bottom { bottom: 64px; }
}
