/* ============================================================
   FinishLine 2.0 – Design System
   Helles, sportliches, modernes Theme
   ============================================================ */

/* ===== CSS CUSTOM PROPERTIES ===== */
:root {
  /* Backgrounds */
  --bg-primary: #FFFFFF;
  --bg-secondary: #F8F9FA;
  --bg-tertiary: #F0F2F5;
  --bg-card: #FFFFFF;
  --bg-overlay: rgba(0, 0, 0, 0.35);

  /* Text */
  --text-primary: #1A1A2E;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --text-inverse: #FFFFFF;

  /* Accent – Warmes sportliches Orange */
  --accent: #FF6B35;
  --accent-light: #FFF0EB;
  --accent-hover: #E85A28;
  --accent-gradient: linear-gradient(135deg, #FF6B35, #FF8C61);

  /* Secondary – Sportliches Teal */
  --secondary: #4ECDC4;
  --secondary-light: #E8FAF8;

  /* Feedback */
  --success: #10B981;
  --success-light: #ECFDF5;
  --error: #EF4444;
  --error-light: #FEF2F2;
  --warning: #F59E0B;
  --warning-light: #FFFBEB;

  /* Borders & Shadows */
  --border: #E5E7EB;
  --border-focus: var(--accent);
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.15);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Typography */
  --font-display: 'Plus Jakarta Sans', 'Inter', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;
  --text-4xl: 2.5rem;

  /* Transitions */
  --ease-default: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-normal: 200ms;
  --duration-slow: 300ms;

  /* Z-Layers */
  --z-base: 1;
  --z-sticky: 100;
  --z-toolbar: 200;
  --z-panel: 300;
  --z-overlay: 400;
  --z-modal: 500;
  --z-toast: 600;
}

/* ===== DARK MODE ===== */
[data-theme="dark"] {
  --bg-primary: #1A1A2E;
  --bg-secondary: #16213E;
  --bg-tertiary: #0F3460;
  --bg-card: #1E2746;
  --bg-overlay: rgba(0, 0, 0, 0.6);

  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-tertiary: #64748B;
  --text-inverse: #1A1A2E;

  --border: #334155;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
}

/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-secondary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  min-height: 100vh;
}

/* ===== TYPOGRAPHY ===== */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }

.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-lg { font-size: var(--text-lg); }
.text-muted { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-center { text-align: center; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0 var(--space-lg);
  height: 48px;
  border: none;
  border-radius: var(--radius-full);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-default);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent-gradient);
  color: var(--text-inverse);
  box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
}
.btn-primary:hover {
  box-shadow: 0 4px 16px rgba(255, 107, 53, 0.4);
  transform: translateY(-1px);
}

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}
.btn-secondary:hover {
  background: var(--accent-light);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-sm {
  height: 36px;
  padding: 0 var(--space-md);
  font-size: var(--text-xs);
}

.btn-lg {
  height: 56px;
  padding: 0 var(--space-xl);
  font-size: var(--text-base);
}

.btn-icon {
  width: 48px;
  padding: 0;
  border-radius: var(--radius-md);
}
.btn-icon.btn-sm { width: 36px; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-xs);
  transition: all var(--duration-normal) var(--ease-default);
}

.card-interactive {
  cursor: pointer;
}
.card-interactive:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--accent);
}

.card-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.2);
}

/* ===== INPUTS ===== */
.input {
  width: 100%;
  height: 48px;
  padding: 0 var(--space-md);
  background: var(--bg-tertiary);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text-primary);
  transition: all var(--duration-fast) var(--ease-default);
  outline: none;
}

.input:focus {
  border-color: var(--accent);
  background: var(--bg-primary);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.input::placeholder { color: var(--text-tertiary); }

/* ===== PILL NAVIGATION ===== */
.pill-nav {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-xs) 0;
}
.pill-nav::-webkit-scrollbar { display: none; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.pill:hover { background: var(--border); color: var(--text-primary); }
.pill.active {
  background: var(--accent);
  color: var(--text-inverse);
}

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.4;
}
.badge-new { background: var(--success-light); color: var(--success); }
.badge-popular { background: var(--accent-light); color: var(--accent); }
.badge-animated { background: #EDE9FE; color: #7C3AED; }

/* ===== STEPPER / PROGRESS ===== */
.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: var(--space-md) var(--space-lg);
}

.step {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-default);
  user-select: none;
}

.step-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 700;
  border: 2px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-tertiary);
  transition: all var(--duration-normal) var(--ease-default);
  flex-shrink: 0;
}

.step.active .step-circle {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--text-inverse);
  box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
}

.step.done .step-circle {
  border-color: var(--success);
  background: var(--success);
  color: var(--text-inverse);
}

.step-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-tertiary);
  transition: color var(--duration-fast);
}
.step.active .step-label { color: var(--text-primary); font-weight: 600; }
.step.done .step-label { color: var(--success); }

.step-connector {
  width: 40px;
  height: 2px;
  background: var(--border);
  margin: 0 var(--space-sm);
  flex-shrink: 0;
  transition: background var(--duration-normal);
}
.step-connector.done { background: var(--success); }

/* ===== BOTTOM TOOLBAR ===== */
.toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 0 var(--space-md);
  z-index: var(--z-toolbar);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.toolbar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  border: none;
  background: none;
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 500;
  min-width: 56px;
  -webkit-tap-highlight-color: transparent;
}

.toolbar-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.toolbar-item.active { color: var(--accent); }
.toolbar-item .toolbar-icon { font-size: 22px; line-height: 1; }

/* ===== BOTTOM SHEET (Mobile Panels) ===== */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: var(--z-panel);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-slow) var(--ease-default);
}
.sheet-overlay.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 80vh;
  background: var(--bg-primary);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: calc(var(--z-panel) + 1);
  transform: translateY(100%);
  transition: transform var(--duration-slow) var(--ease-default);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-full);
  margin: var(--space-sm) auto var(--space-md);
}

.sheet-header {
  padding: 0 var(--space-lg) var(--space-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
}

.sheet-body {
  padding: 0 var(--space-lg) var(--space-lg);
}

/* Desktop: Sheet wird zum Side-Panel */
@media (min-width: 1024px) {
  .sheet {
    top: 0;
    bottom: 0;
    left: auto;
    right: 0;
    max-height: 100vh;
    width: 360px;
    border-radius: 0;
    transform: translateX(100%);
    box-shadow: var(--shadow-xl);
  }
  .sheet.open { transform: translateX(0); }
  .sheet.sheet-left { left: 0; right: auto; transform: translateX(-100%); }
  .sheet.sheet-left.open { transform: translateX(0); }
}

/* ===== PREVIEW CONTAINER ===== */
.preview-area {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  padding: var(--space-lg);
  background: linear-gradient(135deg, #f0f2f5, #e8eaed);
  min-height: 400px;
}

.preview-frame {
  aspect-ratio: 9 / 16;
  max-height: 70vh;
  width: auto;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  background: #000;
  position: relative;
}

.preview-frame canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ===== ACTIVITY CARD ===== */
.activity-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-default);
}
.activity-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.activity-card.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.15);
}

.activity-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.activity-icon.run { background: #DBEAFE; color: #2563EB; }
.activity-icon.ride { background: #FEF3C7; color: #D97706; }
.activity-icon.swim { background: #CFFAFE; color: #0891B2; }
.activity-icon.gravel { background: #FEE2E2; color: #DC2626; }
.activity-icon.hike { background: #D1FAE5; color: #059669; }

.activity-info { flex: 1; min-width: 0; }
.activity-name {
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.activity-date { font-size: var(--text-xs); color: var(--text-tertiary); }

.activity-stats {
  text-align: right;
  flex-shrink: 0;
}
.activity-distance {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}
.activity-duration { font-size: var(--text-xs); color: var(--text-tertiary); }

.activity-check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.activity-card.selected .activity-check { display: flex; }

/* ===== TEMPLATE GRID ===== */
.template-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

@media (min-width: 768px) {
  .template-grid { grid-template-columns: repeat(3, 1fr); }
}

.template-card {
  position: relative;
  aspect-ratio: 9 / 16;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all var(--duration-normal) var(--ease-default);
  background: var(--bg-tertiary);
}

.template-card:hover {
  transform: scale(1.03);
  box-shadow: var(--shadow-md);
}

.template-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.2);
}

.template-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.template-card-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space-sm) var(--space-md);
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  color: white;
  font-size: var(--text-xs);
  font-weight: 600;
  opacity: 0;
  transition: opacity var(--duration-fast);
}
.template-card:hover .template-card-overlay { opacity: 1; }

.template-badge {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
}

/* ===== EXPORT CARDS ===== */
.export-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg);
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-default);
}
.export-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.export-card-primary {
  background: var(--accent-gradient);
  border-color: transparent;
  color: white;
}
.export-card-primary:hover {
  box-shadow: 0 8px 24px rgba(255, 107, 53, 0.3);
}

.export-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.export-info { flex: 1; }
.export-title { font-weight: 700; font-size: var(--text-base); }
.export-desc { font-size: var(--text-sm); opacity: 0.8; margin-top: 2px; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  transform: translateX(120%);
  transition: transform var(--duration-slow) var(--ease-bounce);
}
.toast.show { transform: translateX(0); }
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--error); }

/* ===== LOADING SPINNER ===== */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  background: rgba(255,255,255,0.9);
  z-index: 10;
  border-radius: inherit;
}

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-center { align-items: center; justify-content: center; }
.flex-between { align-items: center; justify-content: space-between; }
.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.w-full { width: 100%; }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-md { margin-bottom: var(--space-md); }

/* ===== RESPONSIVE ===== */
@media (max-width: 767px) {
  h1 { font-size: var(--text-2xl); }
  h2 { font-size: var(--text-xl); }
  h3 { font-size: var(--text-lg); }

  .stepper { gap: 0; padding: var(--space-sm) var(--space-md); }
  .step-label { display: none; }
  .step-connector { width: 24px; }

  .preview-area { padding: var(--space-sm); min-height: 280px; }
  .preview-frame { max-height: 50vh; }

  /* Touch-friendlier buttons */
  .btn { min-height: 48px; }
  .pill { min-height: 40px; padding: var(--space-sm) var(--space-md); }

  /* Better activity cards on mobile */
  .activity-card { padding: var(--space-sm) var(--space-md); }
  .activity-card .activity-sport-icon { width: 40px; height: 40px; font-size: var(--text-lg); }

  /* Template grid: 2 columns on mobile */
  .template-grid { grid-template-columns: repeat(2, 1fr) !important; gap: var(--space-sm); }

  /* Sheets: full width, taller */
  .sheet { max-height: 80vh; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }

  /* Export cards stack */
  .export-card { padding: var(--space-md); }

  /* Step content padding */
  .step-content { padding: var(--space-md); }

  /* Pill nav horizontal scroll */
  .pill-nav { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; scrollbar-width: none; }
  .pill-nav::-webkit-scrollbar { display: none; }

  /* Login */
  .login-card { padding: var(--space-lg); }
  .login-title { font-size: var(--text-3xl); }

  body { padding-bottom: 0; }
}

/* ===== SAFE AREAS (notch/home-indicator) ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .customize-toolbar { padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom)); }
  .step-nav { padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom)); }
}

@media (min-width: 1024px) {
  .toolbar {
    position: fixed;
    bottom: auto;
    top: 0;
    height: auto;
    border-top: none;
    border-bottom: 1px solid var(--border);
    padding: var(--space-sm) var(--space-lg);
    box-shadow: var(--shadow-sm);
    /* On desktop, toolbar is top-right area */
  }
}
