/* ═══════════════════════════════════════════════════════════════
   RidePH — Instrument Cluster design system
   Loaded after style.css; upgrades the existing components rather
   than renaming them, so every page benefits with no markup churn.

   The premise: this is a safety app read at speed, in sunlight, with
   gloves on. It borrows from road signage and vehicle instrument
   panels — semantic colour that means something, real elevation
   tiers instead of one shadow on everything, and motion with spring
   physics so every touch answers back.
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* ── Brand ── */
  --brand:        #1B6E4F;
  --brand-lift:   #2E9268;
  --brand-deep:   #0E3D2B;
  --accent:       #F2631F;
  --accent-lift:  #FF8A4C;

  /* ── Semantic: separate from the accent, because these MEAN things ── */
  --safe:     #12A150;
  --caution:  #E8A600;
  --danger:   #D93025;
  --info:     #1868DB;
  --safe-bg:    rgba(18,161,80,0.10);
  --caution-bg: rgba(232,166,0,0.12);
  --danger-bg:  rgba(217,48,37,0.10);
  --info-bg:    rgba(24,104,219,0.10);

  /* ── Surfaces: layered depth, not one grey ── */
  --canvas:   #EEF2EF;
  --surface:  #FFFFFF;
  --raised:   #FFFFFF;
  --sunken:   #E4EAE6;
  --hairline: rgba(16,32,26,0.09);
  --edge:     rgba(255,255,255,0.75);

  /* ── Ink ── */
  --ink:      #0F1A15;
  --ink-2:    #40524A;
  --ink-3:    #6F827A;
  --ink-4:    #9AABA3;

  /* ── Elevation: four real tiers ── */
  --e1: 0 1px 2px rgba(16,32,26,0.06), 0 1px 1px rgba(16,32,26,0.04);
  --e2: 0 2px 6px rgba(16,32,26,0.07), 0 4px 14px rgba(16,32,26,0.05);
  --e3: 0 6px 16px rgba(16,32,26,0.09), 0 12px 32px rgba(16,32,26,0.07);
  --e4: 0 12px 28px rgba(16,32,26,0.13), 0 24px 56px rgba(16,32,26,0.10);

  /* ── Motion ── */
  --spring: cubic-bezier(0.34, 1.46, 0.64, 1);
  --snap:   cubic-bezier(0.2, 0, 0, 1);
  --glide:  cubic-bezier(0.4, 0, 0.2, 1);

  /* ── Radii ── */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
}

[data-theme="dark"] {
  --canvas:   #090F0C;
  --surface:  #121B16;
  --raised:   #18231D;
  --sunken:   #0D1410;
  --hairline: rgba(255,255,255,0.08);
  --edge:     rgba(255,255,255,0.06);

  --ink:   #E9F0EC;
  --ink-2: #AEC0B7;
  --ink-3: #7E9188;
  --ink-4: #5C6E66;

  --brand:      #35A576;
  --brand-lift: #4FC894;
  --safe:       #2BC46B;
  --caution:    #F5BE3F;
  --danger:     #F2564B;
  --info:       #5B9CF5;

  --e1: 0 1px 2px rgba(0,0,0,0.5);
  --e2: 0 3px 10px rgba(0,0,0,0.55);
  --e3: 0 8px 24px rgba(0,0,0,0.6);
  --e4: 0 16px 44px rgba(0,0,0,0.7);
}

body { background: var(--canvas); color: var(--ink); }
.page-wrapper { background: var(--canvas); }

/* ═══ Type scale ═══ */
h1 { font-size: clamp(1.7rem, 6vw, 2.1rem); font-weight: 800; letter-spacing: -0.025em; line-height: 1.12; }
h2 { font-size: 1.28rem; font-weight: 800; letter-spacing: -0.018em; line-height: 1.2; }
h3 { font-size: 1.02rem; font-weight: 700; letter-spacing: -0.01em; }
h1, h2, h3, h4 { color: var(--ink); text-wrap: balance; }
p  { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ═══ Universal press response ═══
   Everything tappable answers back. This single rule is most of what
   separates an app that feels alive from one that feels like a page. */
button, a.module-card, .card-tap, .chip-btn, .seg-btn, .list-row,
.bottom-nav .nav-item, .haz-opt, .safe-row, .day-cell, .gear-cell {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:active, a.module-card:active, .card-tap:active,
.chip-btn:active, .list-row:active, .haz-opt:active, .safe-row:active {
  transform: scale(0.965);
  transition-duration: 90ms;
}

/* ═══ Top bar ═══ */
.top-bar {
  background: linear-gradient(170deg, var(--brand-deep), var(--brand) 92%);
  box-shadow: 0 1px 0 var(--hairline), var(--e2);
  padding: 15px 20px;
}
[data-theme="dark"] .top-bar { background: linear-gradient(170deg, #0B2419, #133A28 92%); }
.top-bar .app-name { font-size: 1.04rem; font-weight: 800; letter-spacing: -0.015em; }
.top-bar .icon-btn {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px;
  width: 38px; height: 38px;
  font-weight: 700; font-size: 0.76rem;
  transition: background 0.2s var(--glide), transform 0.14s var(--spring);
}
.top-bar .icon-btn:active { transform: scale(0.9); background: rgba(255,255,255,0.26); }
.rider-badge {
  background: linear-gradient(135deg, var(--accent), var(--accent-lift));
  box-shadow: 0 2px 10px rgba(242,99,31,0.4);
  padding: 4px 12px; font-size: 0.66rem; letter-spacing: 0.06em;
}

/* ═══ Bottom nav ═══ */
.bottom-nav {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--hairline);
  box-shadow: 0 -4px 24px rgba(16,32,26,0.07);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
}
.bottom-nav .nav-item {
  color: var(--ink-4);
  font-size: 0.6rem; letter-spacing: 0.05em;
  position: relative;
  transition: color 0.22s var(--glide);
}
.bottom-nav .nav-item i { transition: transform 0.3s var(--spring); }
.bottom-nav .nav-item.active { color: var(--brand); }
.bottom-nav .nav-item.active i { transform: translateY(-2px) scale(1.08); }
/* Active marker: a signal lamp, not a underline */
.bottom-nav .nav-item.active::after {
  content: '';
  position: absolute; top: 7px; left: 50%;
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--accent);
  transform: translateX(-50%);
  box-shadow: 0 0 8px var(--accent);
  animation: lampOn 0.4s var(--spring) both;
}
.bottom-nav .nav-fab:not(.active)::after { display: none; }
@keyframes lampOn { from { opacity: 0; transform: translateX(-50%) scale(0); } }

.bottom-nav .nav-fab i {
  box-shadow: 0 6px 20px rgba(242,99,31,0.5), inset 0 1px 0 rgba(255,255,255,0.35);
  border-color: var(--surface);
  background: linear-gradient(145deg, var(--accent-lift), var(--accent));
}
.bottom-nav .nav-fab:active i { transform: translateX(-50%) scale(0.9); }

/* ═══ Cards: differentiated by role, not one stamp ═══ */
.card-base, .module-card {
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--e2);
  transition: transform 0.24s var(--spring), box-shadow 0.24s var(--glide);
}
.card-base:hover, .module-card:hover { transform: translateY(-3px); box-shadow: var(--e3); }

/* Module tiles: the icon gets real depth — gradient body, inner
   highlight, and a soft glow in its own hue so it reads as lit
   rather than as a flat swatch. */
.module-card { padding: 20px 12px 17px; gap: 11px; }
.module-card .icon-wrap {
  width: 54px; height: 54px;
  border-radius: 17px;
  position: relative;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.3), 0 6px 16px rgba(16,32,26,0.16);
  transition: transform 0.3s var(--spring);
}
.module-card .icon-wrap::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  background: linear-gradient(160deg, rgba(255,255,255,0.28), transparent 58%);
  pointer-events: none;
}
.module-card:hover .icon-wrap { transform: scale(1.07) rotate(-3deg); }
.module-card .card-label {
  font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.035em; color: var(--ink);
}

/* ═══ Section headings ═══ */
.section-title { margin-bottom: 13px; align-items: center; }
.section-title h2 {
  font-size: 0.72rem; font-weight: 800;
  letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--ink-3);
  display: flex; align-items: center; gap: 8px;
}
.section-title h2 i { font-size: 0.82rem; }
.section-title::after {
  content: ''; flex: 1; height: 1px; margin-left: 12px;
  background: linear-gradient(to right, var(--hairline), transparent);
}

/* ═══ Hero ═══ */
.hero-banner {
  background:
    radial-gradient(120% 90% at 88% 4%, rgba(242,99,31,0.20), transparent 56%),
    linear-gradient(162deg, var(--brand-deep) 0%, var(--brand) 62%, #2E9268 100%);
  border-radius: 0 0 var(--r-xl) var(--r-xl);
  box-shadow: var(--e3);
  padding: 22px 20px 30px;
}
[data-theme="dark"] .hero-banner {
  background:
    radial-gradient(120% 90% at 88% 4%, rgba(242,99,31,0.16), transparent 56%),
    linear-gradient(162deg, #071B12 0%, #0E3D2B 62%, #145539 100%);
}
/* Faint contour lines — a road, not a decoration */
.hero-banner::after {
  content: '';
  position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(115deg, transparent 0 22px, rgba(255,255,255,0.028) 22px 23px);
  pointer-events: none;
}
.stat-pill {
  background: rgba(255,255,255,0.13);
  border: 1px solid rgba(255,255,255,0.17);
  backdrop-filter: blur(8px);
  padding: 7px 14px;
  font-variant-numeric: tabular-nums;
  transition: transform 0.2s var(--spring);
}
.stat-pill:active { transform: scale(0.94); }

/* ═══ Buttons ═══ */
.btn-primary-green, .submit-btn, .start-routine-btn {
  background: linear-gradient(145deg, var(--brand-lift), var(--brand));
  box-shadow: 0 6px 18px rgba(27,110,79,0.36), inset 0 1px 0 rgba(255,255,255,0.22);
  border: none; letter-spacing: 0.005em;
  transition: transform 0.16s var(--spring), box-shadow 0.22s var(--glide), filter 0.2s;
}
.btn-primary-green:hover, .submit-btn:hover { box-shadow: 0 10px 26px rgba(27,110,79,0.45); filter: brightness(1.06); }
.btn-primary-green:active, .submit-btn:active { transform: scale(0.97); }
.btn-orange {
  background: linear-gradient(145deg, var(--accent-lift), var(--accent));
  box-shadow: 0 6px 18px rgba(242,99,31,0.38), inset 0 1px 0 rgba(255,255,255,0.25);
}

/* ═══ Tip card ═══ */
.tip-card {
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--brand);
  border-radius: var(--r-md);
  box-shadow: var(--e1);
  padding: 15px 17px;
}
.tip-card .tip-label { color: var(--brand); letter-spacing: 0.1em; }
.tip-card p { color: var(--ink-2); }

/* ═══ Skeleton loading — never show an empty box ═══ */
.skel {
  background: linear-gradient(100deg, var(--sunken) 30%, var(--hairline) 50%, var(--sunken) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: 8px;
  color: transparent !important;
  pointer-events: none;
}
@keyframes shimmer { to { background-position: -220% 0; } }

/* ═══ Semantic chips ═══ */
.chip-s {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.02em;
  padding: 5px 11px; border-radius: 100px;
  border: 1px solid transparent;
}
.chip-s.safe    { background: var(--safe-bg);    color: var(--safe);    border-color: color-mix(in srgb, var(--safe) 28%, transparent); }
.chip-s.caution { background: var(--caution-bg); color: var(--caution); border-color: color-mix(in srgb, var(--caution) 32%, transparent); }
.chip-s.danger  { background: var(--danger-bg);  color: var(--danger);  border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.chip-s.info    { background: var(--info-bg);    color: var(--info);    border-color: color-mix(in srgb, var(--info) 28%, transparent); }

/* ═══ Stat tiles ═══ */
.stat-card {
  background: var(--raised) !important;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md) !important;
  box-shadow: var(--e1) !important;
  padding: 16px 12px !important;
  position: relative; overflow: hidden;
  transition: transform 0.24s var(--spring), box-shadow 0.24s var(--glide);
}
.stat-card:active { transform: scale(0.97); }
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 16px; right: 16px; height: 2px;
  background: linear-gradient(to right, var(--brand), transparent);
  opacity: 0.5;
}
.stat-card .sv {
  font-size: 1.72rem !important; font-weight: 800; letter-spacing: -0.03em;
  color: var(--ink) !important;
  font-variant-numeric: tabular-nums;
}
.stat-card .sl { color: var(--ink-3) !important; font-size: 0.62rem !important; letter-spacing: 0.09em; }

/* ═══ Form fields ═══ */
.form-group input, .form-group select, .form-group textarea,
.safe-field, .fg input, .fg textarea {
  background: var(--sunken) !important;
  border: 1.5px solid transparent !important;
  border-radius: var(--r-sm) !important;
  color: var(--ink);
  transition: border-color 0.2s var(--glide), background 0.2s, box-shadow 0.2s;
}
.form-group input:focus, .form-group textarea:focus,
.safe-field:focus, .fg input:focus, .fg textarea:focus {
  background: var(--surface) !important;
  border-color: var(--brand) !important;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 14%, transparent);
  outline: none;
}
.form-group label, .fg label { color: var(--ink-3); letter-spacing: 0.02em; }

/* ═══ List rows ═══ */
.ride-item, .safety-card, .exercise-card, .route-card, .bike-card {
  background: var(--raised) !important;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md) !important;
  box-shadow: var(--e1) !important;
  transition: transform 0.22s var(--spring), box-shadow 0.22s var(--glide);
}
.ride-item:active, .route-card:active, .bike-card:active { transform: scale(0.985); }
.ride-name, .bike-title, .route-name { color: var(--ink) !important; }
.ride-meta, .bike-sub, .route-region { color: var(--ink-3) !important; }
.ride-km { color: var(--brand) !important; font-variant-numeric: tabular-nums; }
.ride-icon { background: var(--safe-bg) !important; color: var(--brand) !important; }

/* ═══ Challenge calendar ═══ */
.day-cell {
  background: var(--sunken);
  color: var(--ink-4);
  border-radius: 12px;
  font-variant-numeric: tabular-nums;
  transition: transform 0.2s var(--spring), background 0.24s, color 0.24s;
}
.day-cell:active { transform: scale(0.9); }
.day-cell.done {
  background: linear-gradient(145deg, var(--brand-lift), var(--brand));
  color: #fff;
  box-shadow: 0 3px 10px rgba(27,110,79,0.34), inset 0 1px 0 rgba(255,255,255,0.2);
}
.day-cell.today {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
  animation: todayPulse 2.4s var(--glide) infinite;
}
@keyframes todayPulse {
  0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
  50%      { box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent) 5%, transparent); }
}
.day-cell.locked { background: var(--sunken); color: var(--ink-4); opacity: 0.55; }

/* ═══ Gear grid ═══ */
.gear-cell {
  border-radius: 10px;
  transition: transform 0.2s var(--spring), box-shadow 0.2s;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18);
}
.gear-cell:active { transform: scale(0.92); }
.gear-cell.selected {
  transform: scale(1.16);
  box-shadow: 0 0 0 2px var(--ink), 0 6px 16px rgba(16,32,26,0.28);
  z-index: 2; position: relative;
}
.gear-easy   { background: linear-gradient(145deg, #2FA76E, #18794E); }
.gear-medium { background: linear-gradient(145deg, #F5C451, var(--caution)); color: #3A2B00; }
.gear-hard   { background: linear-gradient(145deg, var(--accent-lift), var(--accent)); }
.gear-danger { background: linear-gradient(145deg, #E8574C, var(--danger)); }

/* ═══ Chatbot ═══ */
.chatbot-btn {
  background: linear-gradient(145deg, var(--brand-lift), var(--brand));
  box-shadow: 0 8px 22px rgba(27,110,79,0.45), inset 0 1px 0 rgba(255,255,255,0.25);
  transition: transform 0.24s var(--spring);
}
.chatbot-btn:active { transform: scale(0.88); }
.chatbot-window {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--e4);
}
.chat-msg.bot  { background: var(--sunken); color: var(--ink); }
.chat-msg.user { background: linear-gradient(145deg, var(--brand-lift), var(--brand)); }
.chatbot-input-row { border-top: 1px solid var(--hairline); }
.chatbot-input-row input { background: var(--sunken); border: 1.5px solid transparent; color: var(--ink); }
.chatbot-input-row input:focus { border-color: var(--brand); background: var(--surface); }

/* ═══ Empty states with personality ═══ */
.empty-state, .empty {
  color: var(--ink-4) !important;
  padding: 44px 24px !important;
}
.empty-state i, .empty i {
  font-size: 2.4rem !important;
  opacity: 0.35;
  animation: floatIdle 3.2s ease-in-out infinite;
}
@keyframes floatIdle {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-7px); }
}

/* ═══ Staggered entrance ═══
   Children arrive in sequence rather than all at once, which reads
   as the screen assembling itself instead of simply appearing. */
.stagger > * { animation: riseIn 0.5s var(--spring) both; }
.stagger > *:nth-child(1) { animation-delay: 0.02s; }
.stagger > *:nth-child(2) { animation-delay: 0.06s; }
.stagger > *:nth-child(3) { animation-delay: 0.10s; }
.stagger > *:nth-child(4) { animation-delay: 0.14s; }
.stagger > *:nth-child(5) { animation-delay: 0.18s; }
.stagger > *:nth-child(6) { animation-delay: 0.22s; }
@keyframes riseIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* ═══ Focus visibility — keyboard users are users ═══ */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ═══ Respect reduced motion ═══ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ═══ Pull-to-refresh indicator ═══ */
.ptr-indicator {
  position: fixed;
  top: 6px; left: 50%;
  transform: translateX(-50%);
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--hairline);
  box-shadow: var(--e3);
  display: flex; align-items: center; justify-content: center;
  color: var(--brand);
  font-size: 0.92rem;
  opacity: 0;
  z-index: 2000;
  pointer-events: none;
  transition: transform 0.32s var(--spring), opacity 0.24s var(--glide);
}
.ptr-indicator.spinning i { animation: ptrSpin 0.7s linear infinite; }
@keyframes ptrSpin { to { transform: rotate(360deg); } }
