/* Campus Rick shared design system. Each app sets --accent / --accent-ink / --accent-soft. */
:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #f6f8f7;
  --text: #15201b;
  --muted: #5b6862;
  --line: #dde3e0;
  --danger: #c62828;
  --danger-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --ok: #1f7a36;
  --ok-soft: #e7f5ea;
  --info: #1e5aa8;
  --info-soft: #e8f0fb;
  --accent: #2e7d32;
  --accent-ink: #ffffff;
  --accent-soft: #e6f2e7;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px rgba(16, 32, 24, 0.12);
  --shadow-sm: 0 2px 8px rgba(16, 32, 24, 0.1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Helvetica, Arial, sans-serif;
  --overlay: rgba(0, 0, 0, .4);
  --toast-bg: #1d2a23;
  --skeleton-a: #eceff0;
  --skeleton-b: #f6f8f8;
  --sim: #6a1b9a;
  --sim-soft: #f6ecf8;
  --sim-ink: #4a148c;
  --map-bg: #e8ece9;
  color-scheme: light;
}

/* Dark theme: set on <html data-theme="dark"> by shared/js/theme-init.js. Apps override --accent* below. */
:root[data-theme="dark"] {
  --bg: #0f1512;
  --surface: #18211c;
  --surface-2: #202b25;
  --text: #e4ebe7;
  --muted: #9aaaa2;
  --line: #2f3c35;
  --danger: #ef6b6b;
  --danger-soft: #3a1c1c;
  --warn: #f2b347;
  --warn-soft: #3a2c12;
  --ok: #5fcf7a;
  --ok-soft: #173322;
  --info: #7fb0f0;
  --info-soft: #172a40;
  --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .45);
  --overlay: rgba(0, 0, 0, .6);
  --toast-bg: #2b3a32;
  --skeleton-a: #202b25;
  --skeleton-b: #2a362f;
  --sim: #ab47bc;
  --sim-soft: #2d1a33;
  --sim-ink: #e1bee7;
  --map-bg: #1b2420;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, white); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--surface-2); color: var(--text);
  font-weight: 600; cursor: pointer; text-decoration: none; transition: background .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: var(--surface); border-color: var(--line); }
.btn-ghost { background: transparent; }
.btn-ghost-danger { background: transparent; color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-icon { min-width: 44px; min-height: 44px; padding: 0; border-radius: 50%; }
.btn .spinner { width: 18px; height: 18px; border-width: 2px; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.code { letter-spacing: .5em; font-size: 24px; text-align: center; font-variant-numeric: tabular-nums; }
.hint { font-size: 13px; color: var(--muted); }
.error-text { font-size: 14px; color: var(--danger); min-height: 1.2em; }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: grid; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 700; }
.num { font-variant-numeric: tabular-nums; }
.divider { height: 1px; background: var(--line); margin: 12px 0; border: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .02em; background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-sim { background: var(--sim); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.banner { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.banner-warn { background: var(--warn-soft); color: var(--warn); }
.banner-danger { background: var(--danger-soft); color: var(--danger); }
.banner-info { background: var(--info-soft); color: var(--info); }
.banner-ok { background: var(--ok-soft); color: var(--ok); }
.banner-sim { background: var(--sim-soft); color: var(--sim-ink); border: 1px dashed var(--sim); }

/* ---------- App shell ---------- */
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.topbar {
  position: absolute; z-index: 600; top: calc(10px + var(--safe-top)); left: 10px; right: 10px;
  display: flex; align-items: center; gap: 8px; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 999px;
  padding: 6px 14px 6px 8px; box-shadow: var(--shadow-sm); font-weight: 800; min-height: 44px;
}
.brand-mark { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 15px; }
.brand > span:last-child { white-space: nowrap; }
@media (max-width: 420px) {
  /* Narrow phones: connection pill shows only its coloured dot (label stays available to screen readers). */
  .topbar .pill-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .topbar { gap: 6px; }
  .topbar .pill { padding: 0 10px; }
}
.brand small { display: block; font-weight: 600; color: var(--muted); font-size: 11px; line-height: 1; }
.topbar .spacer { flex: 1; }
.pill { background: var(--surface); border-radius: 999px; box-shadow: var(--shadow-sm); min-height: 44px;
  display: inline-flex; align-items: center; gap: 8px; padding: 0 12px; font-size: 13px; font-weight: 600; border: 0; cursor: pointer; }
.conn-online { color: var(--ok); }
.conn-connecting { color: var(--warn); }
.conn-offline { color: var(--danger); }

#map { position: absolute; inset: 0; z-index: 1; background: var(--map-bg); }
.map-fabs { position: absolute; z-index: 500; right: 12px; display: grid; gap: 10px; }
.fab { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--surface); box-shadow: var(--shadow);
  display: grid; place-items: center; cursor: pointer; font-size: 20px; }
.map-notice { position: absolute; z-index: 550; left: 50%; transform: translateX(-50%); top: calc(64px + var(--safe-top));
  max-width: min(92vw, 520px); box-shadow: var(--shadow-sm); }

/* Bottom sheet (mobile) / side panel (desktop) */
.sheet {
  position: absolute; z-index: 700; left: 0; right: 0; bottom: 0; max-height: 72vh;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: 0 -6px 28px rgba(16, 32, 24, .16);
  display: flex; flex-direction: column; transition: max-height .25s ease;
}
.sheet.collapsed { max-height: 132px; }
.sheet-handle { border: 0; background: transparent; padding: 10px 0 4px; cursor: pointer; display: grid; place-items: center; }
.sheet-handle span { width: 42px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet-body { overflow-y: auto; padding: 4px 18px calc(18px + var(--safe-bottom)); overscroll-behavior: contain; }
.sheet h2 { font-size: 20px; margin: 4px 0 12px; }
.sheet h3 { font-size: 16px; margin: 0 0 8px; }
@media (min-width: 900px) {
  .sheet { left: 16px; right: auto; top: calc(70px + var(--safe-top)); bottom: 16px; width: 400px; max-height: none;
    border-radius: var(--radius); }
  .sheet.collapsed { max-height: none; }
  .sheet-handle { display: none; }
  .sheet-body { padding-top: 16px; }
}

/* Drawer (history, settings) */
.drawer-backdrop { position: fixed; inset: 0; background: var(--overlay); z-index: 900; }
.drawer {
  position: fixed; z-index: 901; top: 0; bottom: 0; right: 0; width: min(440px, 100vw); background: var(--bg);
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer-head { display: flex; align-items: center; gap: 8px; padding: calc(12px + var(--safe-top)) 12px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 18px; margin: 0; flex: 1; }
.drawer-body { overflow-y: auto; padding: 14px; display: grid; gap: 12px; align-content: start; padding-bottom: calc(24px + var(--safe-bottom)); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: var(--overlay); z-index: 1000; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; width: min(420px, 100%); }
.modal h2 { margin: 0 0 8px; font-size: 19px; }

/* Toasts */
.toasts { position: fixed; z-index: 1100; left: 50%; transform: translateX(-50%); top: calc(64px + var(--safe-top));
  display: grid; gap: 8px; width: min(92vw, 440px); pointer-events: none; }
.toast { background: var(--toast-bg); color: #fff; padding: 12px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: 14px; animation: toast-in .2s ease; pointer-events: auto; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* Loading */
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--skeleton-a) 25%, var(--skeleton-b) 37%, var(--skeleton-a) 63%); background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite; border-radius: 8px; min-height: 14px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty .icon { font-size: 30px; margin-bottom: 6px; }

/* Lists */
.list { display: grid; gap: 8px; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--surface); border-radius: var(--radius-sm);
  border: 1px solid var(--line); text-align: left; width: 100%; cursor: pointer; }
.list-item:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { display: grid; grid-template-columns: 14px 1fr; gap: 10px; font-size: 14px; }
.timeline li::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-top: 6px; }

/* Leaflet markers */
.pin { width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.pin-pickup { background: #1f7a36; }
.pin-dropoff { background: #c62828; }
.pin-offer { background: var(--sim); }
.vehicle-marker { width: 38px; height: 38px; border-radius: 50%; background: #1565c0; color: #fff; display: grid; place-items: center;
  font-size: 19px; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.vehicle-marker.stale { background: #7b8a83; }
.vehicle-marker.sim { background: var(--sim); }
.available-dot { width: 14px; height: 14px; border-radius: 50%; background: #1565c0; opacity: .75; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(26,115,232,.35); }
.landmark-dot { width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid #4b5b53; }
.landmark-dot.pickup-point { border-color: var(--accent); background: var(--accent-soft); }
.leaflet-container { font-family: var(--font); background: var(--map-bg); }

/* Dark map: OSM only publishes light tiles, so they are inverted and re-hued; markers are unaffected. */
[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9) saturate(.6); }
[data-theme="dark"] .leaflet-bar a, [data-theme="dark"] .leaflet-bar a:hover { background: var(--surface); color: var(--text); border-color: var(--line); }
[data-theme="dark"] .leaflet-control-attribution { background: rgba(24, 33, 28, .85); color: var(--muted); }
[data-theme="dark"] .leaflet-control-attribution a { color: var(--info); }
[data-theme="dark"] .leaflet-tooltip { background: var(--surface); color: var(--text); border-color: var(--line); }
[data-theme="dark"] .leaflet-tooltip-top::before { border-top-color: var(--surface); }
[data-theme="dark"] .landmark-dot { background: var(--surface); border-color: #9aaaa2; }
.theme-toggle { font-size: 18px; justify-content: center; min-width: 44px; padding: 0 10px; }

/* Auth screen */
.auth-screen { position: fixed; inset: 0; z-index: 1200; display: grid; place-items: center; padding: 18px; color: var(--text);
  background: linear-gradient(160deg, var(--accent-soft), var(--bg) 55%); overflow-y: auto; }
.auth-card { width: min(420px, 100%); }
.auth-card h1 { font-size: 24px; margin: 8px 0 4px; }
.dev-otp { font-family: ui-monospace, Consolas, monospace; font-size: 20px; letter-spacing: .2em; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
