/* ==========================================================================
   Savanna Fleet Portal — design system
   Style: Soft UI Evolution (subtle depth, WCAG AA+, no neumorphism mush).
   Mobile-first. System font stack so the PWA shell renders instantly offline
   and feels native on both iOS and Android.
   ========================================================================== */

:root {
  /* Light is the default for everyone. The system preference is deliberately
     NOT consulted — a phone set to dark must not flip the app on its own.
     Dark is opt-in only, via data-theme="dark". Declaring color-scheme also
     stops Chrome's "auto dark mode" force-darkening the painted result. */
  color-scheme: light;

  /* Brand: Savanna orange, taken from the giraffe mark.
     #FFA500 manages only 1.97:1 against white, so it is never used for text
     and never sits behind white text. It is a FILL, paired with near-black
     (9.39:1). --c-brand-ink is the darkened amber for text and icons on light
     surfaces (5.43:1). */
  --c-primary:        #FFA500;
  --c-primary-hover:  #F09600;
  --c-primary-soft:   #FFF3DE;
  --c-primary-ring:   rgba(255, 165, 0, .42);
  --c-on-primary:     #1A1205;
  --c-brand-ink:      #9A5B00;

  --c-accent:         #9A5B00;
  --c-accent-soft:    #FFF3DE;

  /* Warm neutrals, so the orange sits in a family rather than on clinical grey */
  --c-bg:             #FFFDF8;
  --c-surface:        #FFFFFF;
  --c-surface-2:      #FBF8F2;
  --c-fg:             #1B1712;
  --c-fg-muted:       #6B6155;
  --c-fg-subtle:      #938878;
  --c-border:         #EDE7DC;
  --c-border-strong:  #D9D0C1;

  /* Status hues stay distinct from the brand, so "scheduled" never reads
     as "this is the brand colour". */
  --c-live:           #0E7A54;
  --c-live-soft:      #E4F4EC;
  --c-wait:           #9A5B00;
  --c-wait-soft:      #FFF3DE;
  --c-done:           #4A5568;
  --c-done-soft:      #EEF0F4;
  --c-danger:         #C2261B;
  --c-danger-soft:    #FDECEA;

  /* Spacing — 4/8 rhythm, density 6/10 */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-full: 999px;

  /* Soft UI Evolution: layered, low-opacity shadows — depth without murk */
  --sh-1: 0 1px 2px rgba(60,42,16,.06), 0 1px 3px rgba(60,42,16,.05);
  --sh-2: 0 2px 4px rgba(60,42,16,.06), 0 4px 12px rgba(60,42,16,.07);
  --sh-3: 0 8px 24px rgba(60,42,16,.12), 0 2px 6px rgba(60,42,16,.06);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  --t-fast: 150ms; --t-base: 220ms;
  --ease: cubic-bezier(.4, 0, .2, 1);

  --nav-h: 64px;
}

/* Opt-in dark, applied only when the user asks for it. There is deliberately
   no prefers-color-scheme block: the system setting must not override the
   light default. On dark surfaces the brand orange reaches 9.46:1, so here it
   can carry text as well as fills. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --c-primary:       #FFA500;
  --c-primary-hover: #FFB733;
  --c-primary-soft:  #33240A;
  --c-primary-ring:  rgba(255,165,0,.45);
  --c-on-primary:    #1A1205;
  --c-brand-ink:     #FFB733;

  --c-accent:        #FFB733;
  --c-accent-soft:   #33240A;

  --c-bg:            #141210;
  --c-surface:       #1E1B17;
  --c-surface-2:     #262119;
  --c-fg:            #F2EFE9;
  --c-fg-muted:      #B5ABA0;
  --c-fg-subtle:     #8B8177;
  --c-border:        #322C24;
  --c-border-strong: #47402F;

  --c-live:          #3ECF95;  --c-live-soft:   #10291F;
  --c-wait:          #FFB733;  --c-wait-soft:   #33240A;
  --c-done:          #9AA5B4;  --c-done-soft:   #23262B;
  --c-danger:        #F87171;  --c-danger-soft: #2E1917;

  --sh-1: 0 1px 2px rgba(0,0,0,.40);
  --sh-2: 0 2px 6px rgba(0,0,0,.45);
  --sh-3: 0 10px 28px rgba(0,0,0,.55);
}

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--c-fg);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  /* Room for the fixed bottom nav plus the iOS home indicator */
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.011em; }
h1 { font-size: 1.5rem;  font-weight: 700; }
h2 { font-size: 1.125rem; font-weight: 650; }
h3 { font-size: 1rem;    font-weight: 600; }
p  { margin: 0; }
a  { color: var(--c-brand-ink); text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--c-brand-ink);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--c-fg-muted); }
.subtle { color: var(--c-fg-subtle); }
.small { font-size: .8125rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------- layout */

.shell { max-width: 1120px; margin: 0 auto; padding: 0 var(--s-4); }

.appbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--c-surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--c-border);
  padding-top: env(safe-area-inset-top, 0px);
}
.appbar__in {
  max-width: 1120px; margin: 0 auto;
  padding: var(--s-3) var(--s-4);
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 56px;
}
.appbar__title { font-size: 1.0625rem; font-weight: 650; }
.appbar__spacer { flex: 1; }

.brand { display: flex; align-items: center; gap: var(--s-2); font-weight: 700; }
.brand__mark {
  width: 32px; height: 32px; border-radius: 50%;
  display: block; flex: none; object-fit: cover;
}
/* Fallback tile when no logo image is used (e.g. avatar initials) */
.brand__tile {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(140deg, #FFB733, #F09600);
  display: grid; place-items: center; color: var(--c-on-primary);
  font-weight: 700; flex: none;
}

/* ------------------------------------------------------- theme toggle */

.theme-toggle {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px; border-radius: var(--r-full);
  background: var(--c-surface-2); border: 1px solid var(--c-border);
}
.theme-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.theme-toggle label {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 var(--s-3); border-radius: var(--r-full);
  font-size: .875rem; font-weight: 600; color: var(--c-fg-muted);
  cursor: pointer; transition: all var(--t-fast) var(--ease);
}
.theme-toggle input:checked + label {
  background: var(--c-primary); color: var(--c-on-primary); box-shadow: var(--sh-1);
}
.theme-toggle input:focus-visible + label { box-shadow: 0 0 0 3px var(--c-primary-ring); }

.bell { position: relative; color: var(--c-fg-muted); }
.bell__dot {
  position: absolute; top: 5px; right: 5px;
  min-width: 17px; height: 17px; padding: 0 4px;
  display: grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--c-danger); color: #fff;
  font-size: .625rem; font-weight: 700; line-height: 1;
  border: 2px solid var(--c-surface);
}

/* Compact icon-only toggle for the app bar */
.theme-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: var(--r-md);
  background: none; border: 0; color: var(--c-fg-muted); cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.theme-btn:hover { background: var(--c-surface-2); color: var(--c-fg); }
.theme-btn .icon-moon { display: none; }
:root[data-theme="dark"] .theme-btn .icon-sun  { display: none; }
:root[data-theme="dark"] .theme-btn .icon-moon { display: block; }

.page { padding: var(--s-5) 0 var(--s-10); }
.stack   { display: flex; flex-direction: column; gap: var(--s-4); }
.stack-2 { display: flex; flex-direction: column; gap: var(--s-2); }
.row { display: flex; align-items: center; gap: var(--s-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s-3); margin-bottom: var(--s-3);
}
.section-head h2 { letter-spacing: -.01em; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card__body { padding: var(--s-4); }
.card--flat { box-shadow: none; }

/* The hero "next journey" card. Text is near-black, not white: white on the
   brand orange is only 1.97:1, while #1A1205 on it reaches 9.39:1. */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(145deg, #FFB733 0%, #FFA500 55%, #EF8F00 100%);
  color: var(--c-on-primary);
  border-radius: var(--r-xl);
  padding: var(--s-5);
  box-shadow: var(--sh-3);
}
.hero::after {
  content: ""; position: absolute; inset: auto -40px -70px auto;
  width: 220px; height: 220px; border-radius: 50%;
  background: rgba(255,255,255,.16);
}
.hero > * { position: relative; z-index: 1; }
.hero__label {
  font-size: .75rem; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; opacity: .72;
}
.hero__route { margin: var(--s-3) 0 var(--s-2); font-size: 1.1875rem; font-weight: 700; }
.hero__meta { font-size: .875rem; font-weight: 550; opacity: .82; }

/* --------------------------------------------------------------- routes */

.route { display: grid; grid-template-columns: 18px 1fr; gap: 0 var(--s-3); }
.route__rail { display: flex; flex-direction: column; align-items: center; padding-top: 5px; }
.route__dot {
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid currentColor; flex: none;
}
.route__dot--fill { background: currentColor; }
.route__line { flex: 1; width: 2px; background: currentColor; opacity: .3; margin: 3px 0; min-height: 18px; }
.route__stop { min-width: 0; padding-bottom: var(--s-3); }
.route__stop:last-child { padding-bottom: 0; }
.route__place {
  font-weight: 550; overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.route__when { font-size: .8125rem; opacity: .8; }

/* -------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--r-full);
  font-size: .75rem; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
}
.badge--live   { background: var(--c-live-soft);   color: var(--c-live); }
.badge--wait   { background: var(--c-wait-soft);   color: var(--c-wait); }
.badge--done   { background: var(--c-done-soft);   color: var(--c-done); }
.badge--danger { background: var(--c-danger-soft); color: var(--c-danger); }
.badge--onhero { background: rgba(26,18,5,.14); color: var(--c-on-primary); font-weight: 700; }

/* Status is never colour-alone: the live badge also pulses. */
.pulse {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; flex: none;
  animation: pulse 1.8s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .45; transform: scale(.82); }
}

/* --------------------------------------------------------------- stats */

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-3); }
.stat {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-md); padding: var(--s-4);
}
.stat__k {
  font-size: .75rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--c-fg-muted);
}
.stat__v {
  font-size: 1.75rem; font-weight: 700; line-height: 1.1;
  margin-top: var(--s-2); font-variant-numeric: tabular-nums;
}
.stat__sub { font-size: .8125rem; color: var(--c-fg-subtle); margin-top: 2px; }

/* Activity bars. Heights are computed in PHP and set inline in px — a
   percentage height on a flex child has no definite parent to resolve
   against here, which silently flattened every bar to the same sliver. */
.spark { display: flex; gap: 6px; margin-top: var(--s-3); }
.spark__col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.spark__slot { width: 100%; height: 68px; display: flex; align-items: flex-end; }
.spark__bar {
  width: 100%; border-radius: 5px 5px 2px 2px;
  background: var(--c-primary);
  transition: height var(--t-base) var(--ease);
}
.spark__bar--empty { background: var(--c-border-strong); }
.spark__n { font-size: .6875rem; font-weight: 700; color: var(--c-fg); font-variant-numeric: tabular-nums; }
.spark__lbl { font-size: .6875rem; color: var(--c-fg-subtle); }

/* -------------------------------------------------------------- trips */

.trip {
  display: block; background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: var(--r-md);
  padding: var(--s-4); color: inherit;
  transition: box-shadow var(--t-base) var(--ease),
              border-color var(--t-base) var(--ease),
              transform var(--t-fast) var(--ease);
}
a.trip:hover { box-shadow: var(--sh-2); border-color: var(--c-border-strong); }
a.trip:active { transform: scale(.995); }   /* no layout shift */

.trip__top { display: flex; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-3); }
.trip__date { font-size: .8125rem; color: var(--c-fg-muted); font-weight: 550; }
.trip__foot {
  display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4);
  margin-top: var(--s-3); padding-top: var(--s-3);
  border-top: 1px solid var(--c-border);
  font-size: .8125rem; color: var(--c-fg-muted);
}
.trip__fact { display: inline-flex; align-items: center; gap: 6px; }

.plate {
  font-family: var(--font-num); font-weight: 600; font-size: .8125rem;
  letter-spacing: .02em; padding: 2px 7px; border-radius: 6px;
  background: var(--c-surface-2); border: 1px solid var(--c-border);
  white-space: nowrap;
}

/* -------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px; padding: 0 var(--s-5);
  border-radius: var(--r-md); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .9375rem;
  cursor: pointer; text-align: center;
  transition: background var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease),
              opacity var(--t-fast) var(--ease);
}
.btn:active { opacity: .88; }
.btn--primary { background: var(--c-primary); color: var(--c-on-primary); box-shadow: var(--sh-1); }
.btn--primary:hover { background: var(--c-primary-hover); box-shadow: var(--sh-2); }
.btn--ghost { background: var(--c-surface); color: var(--c-fg); border-color: var(--c-border-strong); }
.btn--ghost:hover { background: var(--c-surface-2); }
.btn--danger { background: var(--c-danger-soft); color: var(--c-danger); border-color: transparent; }
.btn--danger:hover { background: var(--c-danger); color: #fff; }
.btn--block { width: 100%; }
.btn--lg { min-height: 52px; font-size: 1rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ---------------------------------------------------------------- forms */

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: .875rem; font-weight: 600; }
.field .hint { font-size: .8125rem; color: var(--c-fg-subtle); }

.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 12px var(--s-3);
  font: inherit; color: var(--c-fg);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  -webkit-appearance: none; appearance: none;
}
.textarea { min-height: 96px; resize: vertical; padding-top: var(--s-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-ring);
}
.select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%235B6B66' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 8 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 40px;
}
.field--error .input, .field--error .select, .field--error .textarea { border-color: var(--c-danger); }
.field__err { font-size: .8125rem; color: var(--c-danger); font-weight: 550; }

.seg { display: grid; grid-auto-flow: column; gap: var(--s-2); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  display: flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 48px; padding: 0 var(--s-3); cursor: pointer;
  border: 1px solid var(--c-border-strong); border-radius: var(--r-md);
  background: var(--c-surface); font-weight: 550; font-size: .9375rem;
  transition: all var(--t-fast) var(--ease);
}
.seg input:checked + label {
  border-color: var(--c-primary); background: var(--c-primary-soft);
  color: var(--c-brand-ink); font-weight: 650;
}
.seg input:focus-visible + label { box-shadow: 0 0 0 3px var(--c-primary-ring); }

/* --------------------------------------------------------------- alerts */

.alert {
  display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md); font-size: .9375rem;
  border: 1px solid transparent;
}
.alert svg { flex: none; margin-top: 1px; }
.alert--ok   { background: var(--c-primary-soft); color: var(--c-brand-ink); }
.alert--warn { background: var(--c-wait-soft);    color: var(--c-wait); }
.alert--info { background: var(--c-done-soft);    color: var(--c-done); }

/* ---------------------------------------------------------------- empty */

.empty { text-align: center; padding: var(--s-10) var(--s-4); }
.empty__art {
  width: 64px; height: 64px; margin: 0 auto var(--s-4);
  border-radius: 20px; display: grid; place-items: center;
  background: var(--c-primary-soft); color: var(--c-brand-ink);
}
.empty h3 { margin-bottom: 6px; }
.empty p { color: var(--c-fg-muted); max-width: 34ch; margin: 0 auto var(--s-5); }

/* ------------------------------------------------------------ bottom nav */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--c-surface) 94%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--c-border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar__item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: var(--nav-h); padding: var(--s-2) 4px;
  color: var(--c-fg-subtle); font-size: .6875rem; font-weight: 600;
  transition: color var(--t-fast) var(--ease);
}
.tabbar__item[aria-current="page"] { color: var(--c-brand-ink); }
.tabbar__item:active { background: var(--c-surface-2); }

/* --------------------------------------------------------------- misc */

.map {
  width: 100%; height: 320px; border-radius: var(--r-lg);
  overflow: hidden; background: var(--c-surface-2);
  border: 1px solid var(--c-border);
}
.map--tall { height: min(60vh, 520px); }

.divider { height: 1px; background: var(--c-border); border: 0; margin: var(--s-5) 0; }

.chip-row { display: flex; gap: var(--s-2); overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 38px; display: inline-flex; align-items: center;
  padding: 0 var(--s-4); border-radius: var(--r-full); font-size: .875rem; font-weight: 550;
  background: var(--c-surface); border: 1px solid var(--c-border-strong); color: var(--c-fg-muted);
  cursor: pointer; transition: all var(--t-fast) var(--ease); white-space: nowrap;
}
.chip[aria-pressed="true"] {
  background: var(--c-primary); border-color: var(--c-primary);
  color: var(--c-on-primary); font-weight: 650;
}

/* ---------------------------------------------------------- reveal-in */

/* Content is visible by default and only hidden once we know JS is running,
   so a blocked or slow script can never leave the page blank below the fold. */
.reveal { opacity: 1; }
.js .reveal { opacity: 0; transform: translateY(10px); }
.js .reveal.is-in {
  opacity: 1; transform: none;
  transition: opacity 320ms var(--ease), transform 320ms var(--ease);
}

/* -------------------------------------------------------- larger screens */

@media (min-width: 720px) {
  :root { --nav-h: 0px; }
  body { padding-bottom: 0; }
  .tabbar { display: none; }
  .appbar__nav { display: flex !important; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .page { padding: var(--s-8) 0 var(--s-12); }
  h1 { font-size: 1.875rem; }
  .hero { padding: var(--s-8); }
  .hero__route { font-size: 1.375rem; }
  .grid-2 { display: grid; grid-template-columns: 1.15fr .85fr; gap: var(--s-5); align-items: start; }
}

.appbar__nav { display: none; gap: var(--s-1); }
.appbar__link {
  display: inline-flex; align-items: center; gap: var(--s-2);
  height: 40px; padding: 0 var(--s-3); border-radius: var(--r-md);
  color: var(--c-fg-muted); font-weight: 600; font-size: .9375rem;
  transition: all var(--t-fast) var(--ease);
}
.appbar__link:hover { background: var(--c-surface-2); color: var(--c-fg); }
.appbar__link[aria-current="page"] { background: var(--c-primary-soft); color: var(--c-brand-ink); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
  .js .reveal, .reveal { opacity: 1; transform: none; }
}
