/* ===========================================================
   CARMIN Design System v2.0
   Single source of truth for all design tokens.
   Import this FIRST in every page.
   =========================================================== */

/* ----- Color Palette ----- */
:root {
  --c-coral:        #FF6B6B;
  --c-coral-light:  #FF8E8E;
  --c-coral-dark:   #E05555;
  --c-coral-bg:     rgba(255, 107, 107, 0.08);
  --c-coral-10:     rgba(255, 107, 107, 0.10);
  --c-coral-20:     rgba(255, 107, 107, 0.20);

  --c-gold:         #F7B731;
  --c-gold-light:   #FFD166;
  --c-amber:        #FF9F43;
  --c-green:        #26DE81;
  --c-green-dark:   #20BF6B;
  --c-blue:         #4DA6FF;
  --c-blue-dark:    #3867D6;
  --c-purple:       #A55EEA;
  --c-red:          #FC5C65;

  --c-white:        #FFFFFF;
  --c-gray-50:      #FAFAFA;
  --c-gray-100:     #F5F5F5;
  --c-gray-200:     #EEEEEE;
  --c-gray-300:     #E0E0E0;
  --c-gray-400:     #BDBDBD;
  --c-gray-500:     #9E9E9E;
  --c-gray-600:     #757575;
  --c-gray-700:     #616161;
  --c-gray-800:     #424242;
  --c-gray-900:     #212121;
  --c-black:        #000000;

  /* ----- Semantic Colors ----- */
  --c-bg:           var(--c-white);
  --c-bg-overlay:   rgba(0, 0, 0, 0.45);
  --c-bg-panel:     rgba(255, 255, 255, 0.97);
  --c-bg-glass:     rgba(255, 255, 255, 0.85);
  --c-text:         var(--c-gray-900);
  --c-text-secondary: var(--c-gray-600);
  --c-text-muted:   var(--c-gray-400);
  --c-border:       var(--c-gray-200);
  --c-primary:      var(--c-coral);
  --c-primary-hover: var(--c-coral-dark);

  /* ----- Typography ----- */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;

  --fs-xs:   0.6875rem;  /* 11px */
  --fs-sm:   0.75rem;    /* 12px */
  --fs-base: 0.875rem;   /* 14px */
  --fs-md:   1rem;       /* 16px */
  --fs-lg:   1.125rem;   /* 18px */
  --fs-xl:   1.25rem;    /* 20px */
  --fs-2xl:  1.5rem;     /* 24px */
  --fs-3xl:  1.875rem;   /* 30px */
  --fs-4xl:  2.25rem;    /* 36px */

  --fw-normal: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  --lh-tight:  1.2;
  --lh-normal: 1.5;
  --lh-relaxed: 1.75;

  /* ----- Spacing ----- */
  --sp-1:  0.25rem;  /* 4px */
  --sp-2:  0.5rem;   /* 8px */
  --sp-3:  0.75rem;  /* 12px */
  --sp-4:  1rem;     /* 16px */
  --sp-5:  1.25rem;  /* 20px */
  --sp-6:  1.5rem;   /* 24px */
  --sp-8:  2rem;     /* 32px */
  --sp-10: 2.5rem;   /* 40px */
  --sp-12: 3rem;     /* 48px */
  --sp-16: 4rem;     /* 64px */

  /* ----- Border Radius ----- */
  --r-sm:   6px;
  --r-md:   10px;
  --r-lg:   16px;
  --r-xl:   20px;
  --r-2xl:  28px;
  --r-full: 9999px;

  /* ----- Shadows ----- */
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg:   0 8px 30px rgba(0,0,0,0.12);
  --shadow-xl:   0 12px 40px rgba(0,0,0,0.16);
  --shadow-inner: inset 0 2px 4px rgba(0,0,0,0.06);
  --shadow-glow:  0 0 20px rgba(255, 107, 107, 0.3);

  /* ----- Z-index Scale ----- */
  --z-map:     1;
  --z-controls: 100;
  --z-timeline: 500;
  --z-panels:  1000;
  --z-search:  2000;
  --z-header:  5000;
  --z-overlay: 8000;
  --z-menu:    9000;
  --z-modal:   10000;
  --z-toast:   11000;
  --z-loading: 99999;

  /* ----- Layout ----- */
  --header-h: 56px;
  --bottom-nav-h: 56px;
  --panel-w: 380px;
  --panel-max-w: 420px;
  --content-max-w: 1200px;

  /* ----- Transitions ----- */
  --ease-out:    cubic-bezier(0.0, 0.0, 0.2, 1);
  --ease-in:     cubic-bezier(0.4, 0.0, 1.0, 1);
  --ease-in-out: cubic-bezier(0.4, 0.0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast:    150ms;
  --dur-normal:  250ms;
  --dur-slow:    400ms;

  /* ----- Safe Areas (PWA/Notch) ----- */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);

  color-scheme: light;
}

/* ----- PWA Standalone Adjustments ----- */
@media (display-mode: standalone) {
  :root {
    --header-h: calc(56px + var(--safe-top));
  }
}

/* ===========================================================
   Base Reset & Utilities
   =========================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  color-scheme: light;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--c-text);
  background: var(--c-bg);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* GPU acceleration for fixed elements */
.windy-header,
.bottom-nav,
.search-date-row,
.side-menu,
.results-panel,
.photo-panel {
  will-change: transform;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* Smooth scrolling containers */
.scrollable {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Focus visible for accessibility */
:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* Reduced motion for accessibility */
@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;
  }
}

/* ===========================================================
   Utility Classes
   =========================================================== */

.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;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.skeleton {
  background: linear-gradient(90deg, var(--c-gray-200) 25%, var(--c-gray-100) 50%, var(--c-gray-200) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--r-sm);
}

@keyframes skeleton-pulse {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Glass morphism panel */
.glass {
  background: var(--c-bg-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Haptic-like press feedback */
.pressable {
  transition: transform var(--dur-fast) var(--ease-out);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.pressable:active {
  transform: scale(0.96);
}

/* Toast notification base */
.toast {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + var(--sp-4));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--c-gray-900);
  color: var(--c-white);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  opacity: 0;
  transition: all var(--dur-normal) var(--ease-spring);
  pointer-events: none;
}
.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ===========================================================
   Loading Screen — Premium
   =========================================================== */

.loading {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 40%, #0f3460 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: var(--z-loading);
  transition: opacity 0.6s var(--ease-out), visibility 0.6s;
}

.loading.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-text {
  margin-top: var(--sp-6);
  text-align: center;
}

.loading-stage {
  color: rgba(255, 255, 255, 0.95);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.02em;
}

.loading-subtitle {
  color: rgba(255, 255, 255, 0.5);
  font-size: var(--fs-sm);
  margin-top: var(--sp-1);
}

/* Sun loader */
.minimal-sunset-loader {
  position: relative;
  width: 100px;
  height: 100px;
}

.minimal-sun {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  background: var(--c-coral);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 40px rgba(255, 107, 107, 0.4);
  animation: sun-pulse 2s ease-in-out infinite;
}

@keyframes sun-pulse {
  0%, 100% { box-shadow: 0 0 40px rgba(255, 107, 107, 0.3); transform: translate(-50%, -50%) scale(1); }
  50%      { box-shadow: 0 0 60px rgba(255, 107, 107, 0.6); transform: translate(-50%, -50%) scale(1.08); }
}

.minimal-progress-ring {
  display: block;
}

.progress-ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 2;
}

.progress-ring-fill {
  fill: none;
  stroke: var(--c-coral);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 289;
  stroke-dashoffset: 289;
  transform-origin: 50% 50%;
  animation: ring-fill 2.5s ease-out forwards;
}

@keyframes ring-fill {
  to { stroke-dashoffset: 0; }
}

/* ===========================================================
   Header — Modern & Clean
   =========================================================== */

.windy-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--c-bg-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--sp-4);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  transition: background var(--dur-normal) var(--ease-out),
              box-shadow var(--dur-normal) var(--ease-out);
}

.windy-header.scrolled {
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow-sm);
}

.windy-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  text-decoration: none;
  color: var(--c-text);
}

.windy-logo-text {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  letter-spacing: 0.08em;
  color: var(--c-coral);
}

/* ===========================================================
   Search Bar — Elevated & Inviting
   =========================================================== */

.search-floating {
  background: var(--c-white);
  border-radius: var(--r-full);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--c-border);
  transition: box-shadow var(--dur-normal) var(--ease-out),
              border-color var(--dur-normal) var(--ease-out);
}

.search-floating:focus-within {
  box-shadow: var(--shadow-lg), 0 0 0 3px var(--c-coral-20);
  border-color: var(--c-coral);
}

/* ===========================================================
   Score Badge — The Hero Element
   =========================================================== */

.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  color: var(--c-white);
  box-shadow: var(--shadow-md);
  transition: transform var(--dur-normal) var(--ease-spring);
}

.score-badge:hover {
  transform: scale(1.05);
}

/* Score color variants */
.score-badge.score-low    { background: linear-gradient(135deg, #636e72, #b2bec3); }
.score-badge.score-medium { background: linear-gradient(135deg, #f7b731, #ffc048); }
.score-badge.score-high   { background: linear-gradient(135deg, #ff6b6b, #ff8e53); }
.score-badge.score-epic   { background: linear-gradient(135deg, #e05555, #ff6b6b); box-shadow: var(--shadow-glow); }

/* ===========================================================
   Panels — Slide-in Overlays
   =========================================================== */

.panel-left,
.panel-right {
  position: fixed;
  top: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--c-bg-panel);
  z-index: var(--z-panels);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ===========================================================
   Bottom Navigation — Mobile
   =========================================================== */

@media (max-width: 768px) {
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--c-bg-glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: var(--z-controls);
  }
}

/* ===========================================================
   Touch & Interaction — Mobile-first UX
   =========================================================== */

@media (pointer: coarse) {
  button,
  a,
  [role="button"],
  .pressable,
  .mobile-nav-item,
  .menu-item,
  .btn-panel-left,
  .btn-panel-right,
  .btn-spots,
  .btn-my-spots,
  .btn-my-location,
  .btn-add-spot {
    min-height: 44px;
    min-width: 44px;
  }

  input,
  select,
  textarea {
    font-size: max(var(--fs-md), 16px);
    min-height: 44px;
  }
}

/* Smooth momentum scrolling for all panels */
.panel-left,
.panel-right,
.side-menu,
.spots-list,
.panel-content {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 107, 107, 0.45) transparent;
}

.panel-left::-webkit-scrollbar,
.panel-right::-webkit-scrollbar,
.side-menu::-webkit-scrollbar {
  width: 5px;
}

.panel-left::-webkit-scrollbar-thumb,
.panel-right::-webkit-scrollbar-thumb,
.side-menu::-webkit-scrollbar-thumb {
  background: rgba(255, 107, 107, 0.38);
  border-radius: var(--r-full);
}

.panel-left::-webkit-scrollbar-thumb:hover,
.panel-right::-webkit-scrollbar-thumb:hover,
.side-menu::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 107, 107, 0.55);
}

/* ===========================================================
   Tablet-specific Layout — 768-1024px
   =========================================================== */

@media (min-width: 769px) and (max-width: 1024px) {
  :root {
    --panel-w: 340px;
  }

  .panel-left,
  .panel-right {
    max-width: var(--panel-w);
  }

  .search-date-row {
    max-width: 700px;
  }
}

/* ===========================================================
   Offline Indicator
   =========================================================== */

.is-offline .windy-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--c-amber);
  animation: offline-pulse 2s ease-in-out infinite;
}

@keyframes offline-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===========================================================
   Print
   =========================================================== */

@media print {
  .windy-header,
  .bottom-nav,
  .side-menu,
  .loading,
  .toast { display: none !important; }

  body { overflow: visible !important; }
}
