/* ─── Google Fonts ───────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Rowdies&display=swap');

/* ─── Design tokens ──────────────────────────────────────────────────────── */
:root {
  --clr-primary:      #374486;
  --clr-primary-rgb:  55, 68, 134;
  --clr-secondary:    #53d2ff;
  --clr-bg:           #f4f6f8;
  --clr-surface:      #ffffff;
  --clr-text:         #262626;
  --clr-muted:        #8c8c8c;
  --clr-border:       #cfd8df;
  --clr-divider:      #ebecf3;
  --clr-success:      #009306;
  --clr-danger:       #fc2f2f;
  --clr-warning:      #f99502;
  --clr-on-time:      #388e3c;   /* Material Green 800 — readable, not neon */
  --clr-late:         #c62828;   /* Material Red 800 — clearly red, not alarming */
  --clr-pickup:       #374486;
  --clr-delivery:     #f99502;
  --clr-stop:         #8c8c8c;
  --clr-gradient:     linear-gradient(90deg, #c9b4ff, #b7cffb 50%, #b2fff9);

  --shadow-sm:  0 1px 3px rgba(0,0,0,.08);
  --shadow-md:  0 4px 12px rgba(0,0,0,.10);
  --shadow-btn: 1px 5px 10px rgba(55,68,134,.6);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 20px;

  --sidebar-w: 340px;

  --font-body: 'Roboto', sans-serif;
  --font-brand: 'Rowdies', cursive;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 62.5%; }
body {
  font-family: var(--font-body);
  font-size: 1.4rem;
  line-height: 1.6rem;
  color: var(--clr-text);
  background: var(--clr-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-width: 320px;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input { font-family: inherit; }

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: .8rem; height: .8rem; }
::-webkit-scrollbar-thumb {
  background-clip: content-box;
  background-color: #bfbcbc;
  border: 2px solid transparent;
  border-radius: .5rem;
}
::-webkit-scrollbar-thumb:hover { border-width: 0; }
::-webkit-scrollbar-track { background: transparent; }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 2.4rem;
  left: 50%;
  transform: translateX(-50%) translateY(2rem);
  background: var(--clr-text);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 500;
  padding: 1.2rem 2.4rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 9999;
  white-space: nowrap;
  pointer-events: none;
}
.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Form primitives (shared) ───────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: .6rem; }
.field__label {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--clr-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.field__input {
  height: 4rem;
  padding: 0 1.2rem;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  font-size: 1.4rem;
  color: var(--clr-text);
  background: var(--clr-surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  width: 100%;
}
.field__input:focus {
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px rgba(var(--clr-primary-rgb), .15);
}
.field--error .field__input {
  border-color: var(--clr-danger);
}
.field--error .field__input:focus {
  box-shadow: 0 0 0 3px rgba(252,47,47,.15);
}
.field__error-msg {
  font-size: 1.2rem;
  color: var(--clr-danger);
  display: none;
}
.field--error .field__error-msg { display: block; }

/* ─── Button ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .8rem;
  height: 4rem;
  padding: 0 2rem;
  border-radius: var(--radius-sm);
  font-size: 1.4rem;
  font-weight: 500;
  transition: background-color .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap;
}
.btn--primary {
  background: var(--clr-primary);
  color: #fff;
}
.btn--primary:hover  { box-shadow: var(--shadow-btn); }
.btn--primary:active { opacity: .9; }
.btn--full { width: 100%; }

/* ═══════════════════════════════════════════════════════════════════════════
   LANDING PAGE  (index.html)
═══════════════════════════════════════════════════════════════════════════ */

.landing {
  display: flex;
  min-height: 100vh;
  background: #f5f5f5;
  padding: 7vh 4.8vw;
  align-items: center;
  justify-content: center;
}

.landing__card {
  display: flex;
  flex-direction: row;
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 96rem;
  min-height: 56rem;
  overflow: hidden;
}

/* Left decorative panel */
.landing__panel {
  flex: 1;
  background: var(--clr-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 4rem;
}
.landing__panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(270deg, #fff 0 1px, transparent 1px 12rem),
    repeating-linear-gradient(0deg,   #fff 0 1px, transparent 1px 12rem);
  opacity: .25;
  pointer-events: none;
}
.landing__glass {
  position: relative;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(255,255,255,.12);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 124px rgba(0,0,0,.1);
  padding: 4rem;
  width: 100%;
  max-width: 40rem;
}
.landing__tagline {
  font-family: var(--font-brand);
  font-size: 3.6rem;
  font-weight: 400;
  line-height: 1.25;
  color: #fff;
  margin-bottom: 1.6rem;
}
.landing__sub {
  font-family: var(--font-brand);
  font-size: 1.6rem;
  font-weight: 400;
  line-height: 2.4rem;
  color: #374486;
}

/* Right form panel */
.landing__form-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5.6rem 4rem;
  width: 36rem;
  flex-shrink: 0;
}
.landing__logo {
  height: 5.6rem;
  margin-bottom: 3.2rem;
  object-fit: contain;
}
.landing__info {
  width: 100%;
  text-align: left;
}
.landing__info-heading {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--clr-text);
  margin: 0 0 1rem;
  line-height: 1.3;
}
.landing__info-body {
  font-size: 1.4rem;
  color: var(--clr-muted);
  line-height: 2.2rem;
  margin: 0;
}
.search-form { display: flex; flex-direction: column; gap: 1.6rem; width: 100%; }

/* ─── Responsive landing ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .landing { padding: 2.4rem 1.6rem; }
  .landing__card { flex-direction: column; }
  .landing__panel { min-height: 18rem; }
  .landing__glass { padding: 2.4rem; }
  .landing__tagline { font-size: 2.4rem; }
  .landing__form-panel { width: 100%; padding: 3.2rem 2.4rem; }
}
@media (max-width: 480px) {
  .landing__panel { display: none; }
  .landing__card { box-shadow: none; border-radius: 0; min-height: 100vh; }
  .landing { padding: 0; }
  .landing__form-panel { min-height: 100vh; padding: 4rem 2.4rem; justify-content: center; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   TRACKING PAGE  (share.html)
═══════════════════════════════════════════════════════════════════════════ */

.track-page {
  position: fixed;
  inset: 0;
  display: flex;
}

/* Full-viewport map */
#map {
  flex: 1;
  height: 100%;
  z-index: 1;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
#sidebar {
  position: relative;
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--clr-surface);
  box-shadow: 2px 0 16px rgba(0,0,0,.12);
  z-index: 100;
  overflow: hidden;
  transition: width .3s ease;
}

/* Sidebar toggle button (desktop) — lives outside #sidebar to avoid overflow:hidden clip */
.sidebar-toggle {
  position: absolute;    /* relative to .track-page (position:fixed parent) */
  top: 50%;
  transform: translateY(-50%);
  width: 2.8rem;
  height: 2.8rem;
  border-radius: 50%;
  display: none;         /* shown only on desktop via media query below */
  align-items: center;
  justify-content: center;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  color: var(--clr-primary);
  box-shadow: var(--shadow-sm);
  transition: left .3s ease, background .15s, color .15s;
  z-index: 150;
}
.sidebar-toggle:hover { background: var(--clr-primary); color: #fff; }

/* Collapsed desktop state */
#sidebar.sidebar--collapsed { width: 0; min-width: 0; overflow: visible; }
#sidebar.sidebar--collapsed .sidebar-content { opacity: 0; pointer-events: none; }

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: opacity .2s ease;
}

/* Sidebar inner padding sections */
.sidebar-search {
  padding: 1.6rem 1.6rem 1.2rem;
  border-bottom: 1px solid var(--clr-divider);
}
.sidebar-search .search-form { gap: 1rem; }
.sidebar-search .field__input { height: 3.6rem; font-size: 1.3rem; }
.sidebar-search .btn { height: 3.6rem; font-size: 1.3rem; }

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.2rem 1.6rem;
  border-bottom: 1px solid var(--clr-divider);
  flex-wrap: wrap;
}
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: .4rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 1.2rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  background: var(--clr-primary);
  color: #fff;
  white-space: nowrap;
}
#mi-to-next {
  font-size: 1.3rem;
  color: var(--clr-muted);
  font-weight: 500;
}

/* Load number displayed prominently below the search form */
.sidebar-load-number {
  padding: 1.2rem 1.6rem .6rem;
  font-size: 2rem;
  font-weight: 700;
  color: var(--clr-text);
  letter-spacing: -.01em;
}

.sidebar-location {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .7rem 1.6rem;
  border-bottom: 1px solid var(--clr-divider);
  font-size: 1.2rem;
  color: var(--clr-muted);
  line-height: 1.5;
}

.info-section {
  padding: 1.4rem 1.6rem;
  border-bottom: 1px solid var(--clr-divider);
}
.info-section__heading {
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--clr-muted);
  margin-bottom: 1rem;
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .8rem;
  margin-bottom: .8rem;
}
.info-row:last-child { margin-bottom: 0; }
.info-label {
  font-size: 1.2rem;
  color: var(--clr-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.info-value {
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--clr-text);
  text-align: right;
  word-break: break-word;
}

/* ─── Stops list ─────────────────────────────────────────────────────────── */
.stops-section {
  padding: 1.4rem 1.6rem;
  flex: 1;
}
.stops-section__heading {
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--clr-muted);
  margin-bottom: 1rem;
}
#stops-list { display: flex; flex-direction: column; gap: 1rem; }

.stop-card {
  background: var(--clr-bg);
  border-radius: var(--radius-md);
  padding: 1.2rem;
  border-left: 4px solid var(--clr-stop);
}
.stop-card--pickup   { border-left-color: var(--clr-pickup); }
.stop-card--delivery { border-left-color: var(--clr-delivery); }
.stop-card--stop     { border-left-color: var(--clr-stop); }

.stop-card__header {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin-bottom: .8rem;
}
.stop-seq {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  background: var(--clr-primary);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stop-card--delivery .stop-seq { background: var(--clr-delivery); }
.stop-card--stop     .stop-seq { background: var(--clr-stop); }

.stop-type-chip {
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .2rem .7rem;
  border-radius: var(--radius-sm);
  background: rgba(var(--clr-primary-rgb), .12);
  color: var(--clr-primary);
}
.stop-type-chip--delivery { background: rgba(249,149,2,.12); color: var(--clr-delivery); }
.stop-type-chip--stop     { background: rgba(140,140,140,.12); color: var(--clr-stop); }

.stop-facility {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--clr-text);
  margin-bottom: .4rem;
}
.stop-address {
  font-size: 1.2rem;
  color: var(--clr-muted);
  margin-bottom: .8rem;
  line-height: 1.7rem;
}
.stop-times { display: flex; flex-direction: column; gap: .4rem; }
.stop-time-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .8rem;
}
.stop-time-label {
  font-size: 1.1rem;
  color: var(--clr-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.stop-time-value {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--clr-text);
  text-align: right;
}
.stop-time-row--ontime .stop-time-label,
.stop-time-row--ontime .stop-time-value { color: var(--clr-on-time); }

.stop-time-row--late .stop-time-label,
.stop-time-row--late .stop-time-value   { color: var(--clr-late); }

/* ─── Sidebar footer ─────────────────────────────────────────────────────── */
.sidebar-footer {
  padding: 1rem 1.6rem;
  border-top: 1px solid var(--clr-divider);
  font-size: 1.1rem;
  color: var(--clr-muted);
  text-align: center;
  flex-shrink: 0;
}

/* ─── Leaflet popup overrides ────────────────────────────────────────────── */
.map-popup { display: flex; flex-direction: column; gap: .4rem; font-family: var(--font-body); }
.map-popup strong { font-size: 1.3rem; color: var(--clr-text); }
.map-popup span   { font-size: 1.2rem; color: var(--clr-muted); }
.leaflet-popup-content { margin: 1rem 1.4rem; font-size: 1.4rem; }
.leaflet-popup-content-wrapper { border-radius: var(--radius-md) !important; box-shadow: var(--shadow-md) !important; }
.leaflet-popup-tip-container { display: none; }

/* ─── Mobile sheet header (handle + controls) ─────────────────────────────── */
.sheet-header { display: none; }

.sheet-handle-bar {
  width: 4rem;
  height: .4rem;
  background: var(--clr-border);
  border-radius: 2px;
  margin: 1rem auto .6rem;
}

.sheet-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.6rem .8rem;
  font-size: 1.1rem;
  color: var(--clr-muted);
}

.sheet-toggle-btn {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: var(--clr-bg);
  border: 1px solid var(--clr-border);
  color: var(--clr-primary);
  font-size: 1.6rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.sheet-toggle-btn:hover { background: var(--clr-primary); color: #fff; }

/* ─── Desktop reset — overrides any mobile state left on the element ──────── */
@media (min-width: 769px) {
  /* Always force position back to normal flow — prevents mobile fixed from sticking */
  #sidebar {
    position: relative !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    border-radius: 0 !important;
    box-shadow: 2px 0 16px rgba(0,0,0,.12) !important;
  }
  /* Width/height only when not collapsed — let .sidebar--collapsed keep width:0 */
  #sidebar:not(.sidebar--collapsed) {
    width: var(--sidebar-w);
    height: 100%;
  }
  .sheet-header   { display: none !important; }
  .sidebar-toggle { display: flex !important; }
}

/* ─── Responsive tracking page ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .track-page { flex-direction: column; }

  #map {
    position: absolute;
    inset: 0;
    z-index: 1;
  }

  #sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100% !important;
    height: 16rem;            /* minimized — enough to show the search form */
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.15);
    z-index: 200;
    overflow: hidden;
    /* transition only applies on snap (not during drag) */
    transition: height .3s cubic-bezier(.4,0,.2,1), border-radius .3s;
  }

  /* Expanded via button — snap to comfortable reading height */
  #sidebar[data-mobile-state="expanded"] {
    height: 72vh;
  }

  /* When dragged to near-full, remove top rounding */
  #sidebar[data-mobile-state="fullscreen"] {
    height: 100vh;
    border-radius: 0;
  }

  /* Sheet header visible on mobile */
  .sheet-header {
    display: block;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
  }
  .sheet-header:active { cursor: grabbing; }

  /* Hide desktop toggle on mobile */
  .sidebar-toggle { display: none; }

  /* Sidebar content always opaque on mobile regardless of desktop collapsed state */
  #sidebar.sidebar--collapsed .sidebar-content { opacity: 1; pointer-events: auto; }

  .sidebar-search { padding: .8rem 1.6rem 1rem; }
  .sidebar-search .search-form {
    flex-direction: row;
    gap: .8rem;
    align-items: flex-end;
  }
  .sidebar-search .field { flex: 1; min-width: 0; }
  .sidebar-search .btn   { flex-shrink: 0; }

}

@media (max-width: 480px) {
  .sidebar-search .search-form { flex-wrap: wrap; }
  .sidebar-search .btn { width: 100%; }
  /* Extra height so the Track button fits when the form wraps to two rows */
  #sidebar[data-mobile-state="minimized"] { height: 20rem; }
}
