/* Knight Bus styles. Mobile first. */
:root {
  --purple: #3c096c;
  --purple-2: #5a189a;
  --accent: #ffd60a;
  --bg: #f6f3fa;
  --card: #ffffff;
  --text: #1b0a2e;
  --muted: #6b6280;
  --line: #e4ddef;
  --danger: #c1121f;
  --ok: #2a9d8f;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12081f;
    --card: #1e1230;
    --text: #f1eaf9;
    --muted: #a99bbd;
    --line: #34244a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Hebrew", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
#app, .view { height: 100%; }
h1, h2 { margin: 0; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small, small { font-size: 0.85rem; }
.error { color: var(--danger); margin: 0; min-height: 1em; }
.notice { background: color-mix(in srgb, var(--accent) 25%, var(--card)); padding: 12px; border-radius: 10px; margin: 0; }

/* Screens */
.screen { min-height: 100%; padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.screen.center { justify-content: center; align-items: stretch; }
.loading { position: fixed; inset: 0; z-index: 2000; background: var(--bg); max-width: none; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row > .primary { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.brand img { border-radius: 22px; box-shadow: 0 6px 20px rgb(60 9 108 / 0.35); }
.topbar { display: flex; align-items: center; gap: 10px; }
.topbar img { border-radius: 9px; }
.topbar h1 { flex: 1; }
.footer { margin-top: auto; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }

/* Controls */
button, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 12px 16px; cursor: pointer; min-height: 44px;
}
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--purple); color: #fff; border-color: var(--purple); font-weight: 600; }
button.link { background: none; border: none; padding: 6px 4px; min-height: 0; color: var(--purple-2); text-decoration: underline; }
@media (prefers-color-scheme: dark) { button.link { color: #c8a8ff; } }
button.danger, .danger { color: var(--danger); }
button.google { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 600; }
button.google .g { font-weight: 800; color: #4285f4; font-size: 1.2rem; }
button.choice { display: flex; justify-content: space-between; text-align: start; }
input[type="email"], input[type="password"], input[type="text"], input[type="search"] {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.field input { color: var(--text); font-size: 1rem; }
.divider { text-align: center; color: var(--muted); font-size: 0.85rem; }

/* Favorites */
.fav { display: flex; gap: 8px; }
.fav-main {
  flex: 1; display: flex; gap: 14px; align-items: center; text-align: start;
  padding: 16px; background: var(--purple); color: #fff; border: none; border-radius: var(--radius);
  box-shadow: 0 4px 14px rgb(60 9 108 / 0.25);
}
.fav.empty .fav-main { background: var(--card); color: var(--text); border: 2px dashed var(--line); box-shadow: none; }
.fav-num {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent); color: var(--purple); font-weight: 800; font-size: 1.2rem;
}
.fav-text { display: flex; flex-direction: column; min-width: 0; }
.fav-text small { opacity: 0.85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-edit { width: 56px; font-size: 1.3rem; border-radius: var(--radius); }

/* The installed iPhone app draws under the status bar (clock, battery). Keep a solid strip
   there so nothing is blurred behind it, and start map screens below it so the map key
   and zoom buttons can be tapped. @req REQ-COMM-9 */
body::before {
  content: ''; position: fixed; top: 0; left: 0; right: 0; height: var(--safe-top);
  background: var(--purple); z-index: 2500; pointer-events: none;
}

/* Map screens: map on top, sheet below */
.map-screen { height: 100%; display: flex; flex-direction: column; padding-top: var(--safe-top); }
.map { flex: 1 1 50%; min-height: 220px; }
.sheet {
  flex: 1 1 50%; overflow-y: auto; background: var(--bg); padding: 14px 16px calc(14px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgb(0 0 0 / 0.12); position: relative; z-index: 500;
}
.sheet h2 { font-size: 1.05rem; }
.sheet p { margin: 0; }
.row.sticky { position: sticky; bottom: calc(-14px - var(--safe-bottom)); background: var(--bg); padding: 10px 0; margin-top: auto; }
.results { display: flex; flex-direction: column; gap: 6px; }
.result { text-align: start; }
.line-list { display: flex; flex-direction: column; gap: 6px; }
.line-row {
  display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line);
}
.line-row.on { border-color: var(--purple-2); }
.line-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--purple); flex: none; }
.line-text { display: flex; flex-direction: column; min-width: 0; }
.line-badge {
  --c: #8d86a0; min-width: 44px; padding: 4px 8px; border-radius: 8px; text-align: center; flex: none;
  background: var(--c); color: #fff; font-weight: 800;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.live-next { color: var(--ok); font-weight: 600; }
.live-passed { color: var(--muted); }
.stop-section { display: flex; flex-direction: column; gap: 6px; }
.stop-title { text-align: start; font-weight: 700; border: none; background: none; padding: 4px 0; min-height: 0; }

/* Bus markers on the map */
.bus-marker {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c); color: #fff; font: 800 12px/1 system-ui, sans-serif;
  border: 3px solid #fff; box-shadow: 0 2px 6px rgb(0 0 0 / 0.4);
}
.bus-passed { opacity: 0.55; border-style: dashed; }
.bus-next { animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgb(255 214 10 / 0.45); } }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); z-index: 3000;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 0.9rem;
}
.spinner {
  width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--purple);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Stop and line names are mostly Hebrew: let each text block pick its own direction. */
.line-text, .result, .stop-title, .fav-text, .sheet h2 { unicode-bidi: plaintext; }

/* Version handling (docs/release-process.md) */
.update-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-bottom)); z-index: 3000;
  display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: var(--radius);
  background: var(--card); border: 2px solid var(--purple); box-shadow: 0 6px 20px rgb(0 0 0 / 0.25);
}
.update-banner span { flex: 1; }
.update-banner button.primary { min-height: 36px; padding: 6px 14px; }
.channel-badge {
  position: fixed; bottom: calc(4px + var(--safe-bottom)); right: 8px; z-index: 3000;
  padding: 2px 10px; border-radius: 999px; font: 700 11px/1.6 ui-monospace, monospace; letter-spacing: 0.05em;
  background: #e85d04; color: #fff; pointer-events: none; opacity: 0.92;
}
.channel-badge.local { background: #495057; }

/* Commute view: the panel shrinks as you scroll it, the map grows (REQ-COMM-8) */
.map-screen.dynamic .map { flex: 1 1 auto; }
.map-screen.dynamic .sheet { flex: 0 0 var(--sheet-h, 50%); border-top: none; box-shadow: none; padding-top: 4px; }
.map-screen.snapping .sheet { transition: flex-basis 0.2s ease-out; }
.sheet-handle {
  flex: none; height: 24px; display: grid; place-items: center; cursor: grab; touch-action: none;
  background: var(--bg); border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
  margin-top: -12px; position: relative; z-index: 501; box-shadow: 0 -6px 20px rgb(0 0 0 / 0.12);
}
.sheet-handle::after { content: ''; width: 44px; height: 5px; border-radius: 3px; background: var(--muted); opacity: 0.6; }
.line-row.off { opacity: 0.6; border-style: dashed; }

/* Start point / destination flags */
.flag-marker { filter: drop-shadow(0 2px 2px rgb(0 0 0 / 0.35)); }
.flag-inline svg { vertical-align: -4px; }
.place-card .place-label { display: block; margin-top: 4px; unicode-bidi: plaintext; }

/* Map key, top-left (REQ-COMM-6) */
.map-legend {
  background: color-mix(in srgb, var(--card) 92%, transparent); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 2px 8px rgb(0 0 0 / 0.2);
  max-width: min(46vw, 180px); max-height: 34vh; overflow-y: auto; font-size: 11px; line-height: 1.25;
}
.legend-head {
  min-height: 0; padding: 4px 10px; width: 100%; text-align: start; border: none; background: none;
  font-weight: 800; font-size: 12px;
}
.legend-head::after { content: ' ▾'; }
.map-legend.closed .legend-head::after { content: ' ▸'; }
.map-legend.closed .legend-body { display: none; }
.legend-body { padding: 0 8px 6px; display: flex; flex-direction: column; gap: 3px; }
.legend-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend-dest { overflow: hidden; text-overflow: ellipsis; unicode-bidi: plaintext; min-width: 0; max-width: 100px; color: var(--muted); }
.legend-swatch {
  flex: none; width: 22px; height: 5px; border-radius: 3px;
  background: linear-gradient(90deg, var(--in) 0 50%, color-mix(in srgb, var(--out) 60%, transparent) 50% 100%);
}
.legend-swatch.demo { --in: #7b2cbf; --out: #b080d9; }
.legend-flag svg { display: block; }
.legend-help { color: var(--muted); display: flex; align-items: center; gap: 4px; white-space: nowrap; border-top: 1px solid var(--line); padding-top: 4px; }
.legend-help + .legend-help { border-top: none; padding-top: 0; }
.legend-bus { width: 12px; height: 12px; border-radius: 50%; background: #7b2cbf; border: 2px solid #fff; box-shadow: 0 0 0 1px #0003; }
.legend-bus.passed { opacity: 0.55; border-style: dashed; }

/* Usage-sharing question and privacy screen */
.consent { border-color: var(--purple-2); }
.consent small.notice { padding: 8px; }
ul.plain { margin: 0; padding-inline-start: 18px; display: flex; flex-direction: column; gap: 6px; }

/* Admin commute report */
.report { max-width: 720px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-grid div { display: flex; flex-direction: column; }
.stat-grid b { font-size: 1.8rem; line-height: 1.1; color: var(--purple-2); }
@media (prefers-color-scheme: dark) { .stat-grid b { color: #c8a8ff; } }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px auto; gap: 4px 8px; align-items: center; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: plaintext; }
.bar-track { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--purple-2); border-radius: 5px; }
.bar-count { min-width: 2ch; text-align: end; }
.bar-row small { grid-column: 1 / -1; margin-top: -4px; }
