/* =========================================================
   Ebike Finder — design system
   Palette roles from the spec:
   #208B3A primary · #155D27 header/nav · #132A13 dark text
   #B7EFC5 / #ECF39E soft backgrounds · #2DC653 "ebikes available"
   #22577A blue for pins/links/info · #ECF39E + #31572C alert banner
   ========================================================= */
:root {
  color-scheme: light; /* app is designed light-first; keep it consistent + readable */
  /* Greens */
  --g-900: #132A13;  --g-800: #155D27;  --g-700: #1A7431;
  --g-600: #208B3A;  --g-500: #25A244;  --g-450: #2DC653;
  --g-400: #4AD66D;  --g-300: #6EDE8A;  --g-200: #92E6A7;  --g-100: #B7EFC5;
  /* Earthy */
  --e-900: #132A13;  --e-700: #31572C;  --e-500: #4F772D;  --e-300: #90A955;  --e-100: #ECF39E;
  /* Teal / blue */
  --blue: #22577A;   --teal: #38A3A5;   --teal-300: #57CC99;  --teal-200: #80ED99;  --teal-100: #C7F9CC;

  --primary: var(--g-600);
  --header: var(--g-800);
  --ink: var(--g-900);
  --ink-soft: #3d5a3d;
  --avail: var(--g-450);
  --info: var(--blue);
  --bg: #f5faf3;
  --card: #ffffff;
  --soft: var(--g-100);
  --highlight: var(--e-100);
  /* Semantic, theme-aware roles (overridden in dark below) */
  --on-soft: var(--g-800);   /* text/icons sitting on a --soft surface */
  --brand: var(--g-800);     /* headings + active-tab text */
  --stat-num: var(--g-600);  /* big number text */
  --pick-bg: #e7f7ea;        /* selected onboarding row */
  --border: #e3efe3;         /* subtle card borders */
  --map-bg: #e8efe6;         /* map placeholder while tiles load */

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 4px 16px rgba(19, 42, 19, 0.10);
  --shadow-lg: 0 10px 34px rgba(19, 42, 19, 0.22);
  --nav-h: 64px;
  --header-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Dark theme ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e9f5ea;
  --ink-soft: #a8c4ab;
  --bg: #0f1712;
  --card: #182a1d;
  --soft: #223a2a;
  --on-soft: #b7efc5;
  --brand: #6EDE8A;
  --stat-num: #6EDE8A;
  --pick-bg: #1f3a29;
  --border: #24402c;
  --map-bg: #0f1712;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --ink: #e9f5ea;
    --ink-soft: #a8c4ab;
    --bg: #0f1712;
    --card: #182a1d;
    --soft: #223a2a;
    --on-soft: #b7efc5;
    --brand: #6EDE8A;
    --stat-num: #6EDE8A;
    --pick-bg: #1f3a29;
    --border: #24402c;
    --map-bg: #0f1712;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* The HTML `hidden` attribute must always win over class-based display rules. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }
body {
  font-family: "Bai Jamjuree", system-ui, -apple-system, sans-serif;
  font-weight: 400;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .btn, .nav-btn__label, .segmented__btn { font-weight: 500; }
button { font-family: inherit; cursor: pointer; }

/* ===== Header ===== */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 500;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--header); color: #fff;
  box-shadow: var(--shadow);
}
.app-header__title { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 600; }
.app-header__title .bolt { color: var(--e-100); }
.app-header__right { display: flex; align-items: center; gap: 7px; }
.pill { border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 500; }
.pill--count { background: var(--g-450); color: var(--g-900); }
.icon-btn {
  background: rgba(255,255,255,0.15); color: #fff; border: 0; border-radius: 10px;
  width: 32px; height: 32px; font-size: 17px; line-height: 1; display: grid; place-items: center;
}
.icon-btn--light { background: rgba(255,255,255,0.2); }

/* ===== Banner ===== */
.banner {
  position: fixed; left: 12px; right: 12px; z-index: 480;
  top: calc(var(--header-h) + var(--safe-top) + 8px);
  background: var(--e-100); color: var(--e-700);
  border: 1px solid var(--e-300); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 14px; box-shadow: var(--shadow);
}
.banner--error { background: #fde8e8; color: #8a1c1c; border-color: #f5b5b5; }

/* ===== Tabs ===== */
.tab { display: none; }
.tab.is-active { display: block; }
.tab--map, .tab--list {
  position: fixed; left: 0; right: 0;
  top: calc(var(--header-h) + var(--safe-top));
  bottom: calc(var(--nav-h) + var(--safe-bottom));
}
#map { width: 100%; height: 100%; background: var(--map-bg); }
/* Subtle, theme-aware map attribution + zoom controls */
.leaflet-control-attribution {
  font-size: 10px !important; padding: 0 6px !important;
  background: color-mix(in srgb, var(--card) 78%, transparent) !important;
  color: var(--ink-soft) !important;
}
.leaflet-control-attribution a { color: var(--on-soft) !important; }
.leaflet-bar a {
  background: var(--card) !important; color: var(--ink) !important;
  border-bottom-color: var(--border) !important;
}

/* Floating buttons on map */
.fab {
  position: absolute; z-index: 450; border: 0; border-radius: 14px;
  box-shadow: var(--shadow-lg); font-weight: 500;
}
.fab--recenter {
  right: 14px; bottom: 84px; width: 46px; height: 46px; font-size: 22px;
  background: #fff; color: var(--info);
}
.fab--scan {
  left: 14px; bottom: 84px; height: 46px; padding: 0 16px;
  background: var(--info); color: #fff; font-size: 15px;
}

/* ===== List ===== */
.tab--list { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.list-toolbar { padding: 12px 14px 4px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.segmented { display: flex; background: var(--soft); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented__btn {
  flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px;
  color: var(--on-soft); font-size: 14px; font-weight: 500;
}
.segmented__btn.is-active { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }

.station-list { padding: 6px 14px 20px; display: flex; flex-direction: column; gap: 10px; }
.station-card {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 12px;
}
.station-card:active { transform: scale(0.99); }
.station-card__badge {
  flex: 0 0 auto; width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center; font-weight: 600; font-size: 20px;
  background: var(--soft); color: var(--ink-soft);
}
.station-card__badge.has-ebikes { background: var(--avail); color: var(--g-900); }
.station-card__main { flex: 1; min-width: 0; }
.station-card__name { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.station-card__sub { font-size: 13px; color: var(--ink-soft); margin-top: 2px; display: flex; gap: 8px; }
.station-card__star { border: 0; background: transparent; font-size: 22px; color: var(--e-300); padding: 4px; }
.station-card__star.is-fav { color: #f0b400; }
.list-empty { text-align: center; color: var(--ink-soft); padding: 40px 20px; }

/* ===== Bottom nav ===== */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 500;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--header); display: flex; align-items: center; justify-content: space-around;
}
.nav-btn {
  background: transparent; border: 0; color: rgba(255,255,255,0.82);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; flex: 1; padding: 6px 0;
}
.nav-btn.is-active { color: #fff; }
.nav-btn__icon { font-size: 20px; }
.nav-btn--scan { flex: 0 0 auto; }
.nav-btn__scan-circle {
  width: 54px; height: 54px; margin-top: -22px; border-radius: 50%;
  background: var(--info); color: #fff; display: grid; place-items: center;
  font-size: 24px; box-shadow: var(--shadow-lg); border: 4px solid var(--header);
}

/* ===== Buttons ===== */
.btn { border: 0; border-radius: 12px; padding: 13px 16px; font-size: 15px; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--info { background: var(--info); color: #fff; }
.btn--ghost { background: transparent; color: var(--ink-soft); }
.btn--block { display: block; width: 100%; margin-top: 10px; }

/* ===== Scrim + sheet ===== */
.scrim { position: fixed; inset: 0; background: rgba(19,42,19,0.45); z-index: 600; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 610;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow-lg);
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
}
.sheet.is-open { transform: translateY(0); }
.sheet__handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 6px auto 10px; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet__name { font-size: 20px; margin: 0; }
.star-btn { border: 0; background: transparent; font-size: 28px; color: var(--e-300); }
.star-btn.is-fav { color: #f0b400; }
.sheet__stats { display: flex; gap: 10px; margin: 16px 0 6px; }
.stat {
  flex: 1; background: var(--soft); border-radius: var(--radius-sm);
  padding: 12px; text-align: center;
}
.stat__num { display: block; font-size: 24px; font-weight: 600; color: var(--stat-num); }
.stat__label { font-size: 12px; color: var(--ink-soft); }
.sheet__stats .stat:first-child .stat__num { color: var(--stat-num); }
.sheet__updated { font-size: 12px; color: var(--ink-soft); text-align: center; margin: 8px 0 14px; }
.sheet__actions { display: flex; flex-direction: column; gap: 10px; }

/* ===== Onboarding ===== */
.onboard {
  position: fixed; inset: 0; z-index: 800; background: var(--g-800);
  display: grid; place-items: center; padding: 20px;
  padding-top: calc(20px + var(--safe-top)); padding-bottom: calc(20px + var(--safe-bottom));
}
.onboard__card {
  background: var(--card); border-radius: 24px; width: 100%; max-width: 440px;
  max-height: 100%; overflow-y: auto; padding: 26px 22px; text-align: center;
}
.onboard h1 { font-size: 26px; margin: 6px 0 8px; color: var(--brand); }
.onboard p { color: var(--ink-soft); font-size: 15px; line-height: 1.5; }
.onboard__emoji { font-size: 44px; }
.onboard__fine { font-size: 12.5px; color: var(--ink-soft); margin-top: 14px; }
.onboard__stations { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; text-align: left; }
.onboard-station {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border: 2px solid var(--border); border-radius: var(--radius-sm); background: var(--card);
}
.onboard-station.is-picked { border-color: var(--brand); background: var(--pick-bg); }
.onboard-station__main { flex: 1; min-width: 0; }
.onboard-station__name { font-weight: 500; font-size: 14px; color: var(--ink); }
.onboard-station__sub { font-size: 12px; color: var(--ink-soft); }
.onboard-station__check { font-size: 20px; color: var(--brand); }

/* ===== Scanner ===== */
.scanner {
  position: fixed; inset: 0; z-index: 850; background: #0b1a0b; color: #fff;
  display: flex; flex-direction: column; align-items: center;
  padding-top: calc(14px + var(--safe-top));
}
.scanner__head {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px 14px; font-weight: 500;
}
.scanner__reader { width: 100%; flex: 1; overflow: hidden; }
.scanner__reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
.scanner__frame {
  position: absolute; top: 50%; left: 50%; width: 62vw; height: 62vw; max-width: 300px; max-height: 300px;
  transform: translate(-50%, -50%); border: 3px solid var(--teal-200); border-radius: 22px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,0.45);
}
.scanner__hint { padding: 16px; color: rgba(255,255,255,0.75); font-size: 14px; }
.scanner__result {
  position: absolute; left: 16px; right: 16px; bottom: calc(24px + var(--safe-bottom));
  background: #fff; color: var(--ink); border-radius: var(--radius); padding: 16px; text-align: center;
}
.scanner__result p { margin: 0 0 12px; word-break: break-all; font-size: 14px; }

/* ===== Map pins ===== */
.pin {
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.4); border: 2px solid #fff;
}
.pin span { transform: rotate(45deg); }
.pin--none { background: #9bb59b; }
.pin--some { background: var(--info); }
.pin--lots { background: var(--g-500); }
.pin--fav { box-shadow: 0 0 0 3px #f0b400, 0 2px 6px rgba(0,0,0,0.4); }

.leaflet-me {
  width: 18px; height: 18px; border-radius: 50%; background: var(--info);
  border: 3px solid #fff; box-shadow: 0 0 0 4px rgba(34,87,122,0.3);
}

/* Dark-mode overrides removed: they flipped text to light while backgrounds
   stayed light, causing unreadable text. The app is locked to its light theme. */
