/**
 * Strava Booster Design System
 *
 * Shared design tokens for consistent UI across web and console applications.
 * All custom properties defined here should be used throughout the codebase
 * to maintain visual consistency and enable easy theme updates.
 */

:root {
  /* ============================================
     COLOR SYSTEM
     ============================================ */

  /* Primary Brand Colors */
  --strava-orange: #FC4C02;
  --strava-orange-dark: #E34402;
  --strava-orange-light: #FC6B3C;
  --orange: #FC4C02; /* Alias for convenience */

  /* Grayscale System (10-step scale for granular control) */
  --gray-900: #1A1A1A; /* Darkest - primary text */
  --gray-800: #2D2D2D;
  --gray-700: #4A4A4A;
  --gray-600: #6B6B6B; /* Secondary text */
  --gray-500: #8E8E8E;
  --gray-400: #ABABAB;
  --gray-300: #D4D4D4;
  --gray-200: #E5E5E5; /* Borders */
  --gray-100: #F0F0F0;
  --gray-50: #FAFAFA;  /* Lightest - backgrounds */

  /* Semantic Colors */
  --ink: var(--gray-900);          /* Primary text color */
  --muted-ink: var(--gray-600);    /* Secondary text color */
  --bg: var(--gray-50);            /* Page background */
  --card: #FFFFFF;                 /* Card backgrounds */
  --border: var(--gray-200);       /* Standard border color */

  /* Status Colors */
  --success: #1BC96D;
  --success-light: #E8F7EF;
  --warning: #FFB74D;
  --warning-light: #FFF4E5;
  --error: #FC5200;
  --error-light: #FFEBE5;

  /* ============================================
     SHADOW SYSTEM (Elevation Levels)
     ============================================ */

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);   /* Subtle elevation */
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);   /* Standard elevation */
  --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.10);  /* Prominent elevation */
  --shadow-xl: 0 16px 32px rgba(0, 0, 0, 0.12); /* Maximum elevation */

  /* Focus Ring */
  --focus-ring: 0 0 0 3px rgba(252, 76, 2, 0.15);

  /* ============================================
     TYPOGRAPHY
     ============================================ */

  /* Font Stack - System fonts for best performance */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
                 Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";

  /* Font Sizes (using clamp for responsive typography) */
  --font-size-base: 16px;
  --font-size-sm: 14px;
  --font-size-xs: 12px;

  --font-size-h1: clamp(32px, 4vw, 48px);
  --font-size-h2: clamp(24px, 3vw, 36px);
  --font-size-h3: clamp(18px, 2vw, 24px);
  --font-size-h4: 18px;
  --font-size-h5: 16px;
  --font-size-h6: 14px;

  /* Font Weights */
  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  --font-weight-extrabold: 800;

  /* Line Heights */
  --line-height-tight: 1.2;  /* For headings */
  --line-height-base: 1.6;   /* For body text */
  --line-height-loose: 1.8;  /* For long-form content */

  /* Letter Spacing (tighter for modern look) */
  --letter-spacing-tight: -0.02em;  /* For headings */
  --letter-spacing-base: -0.01em;   /* For body text */
  --letter-spacing-normal: 0;

  /* ============================================
     SPACING SYSTEM
     ============================================ */

  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --spacing-2xl: 48px;
  --spacing-3xl: 64px;

  /* ============================================
     BORDER SYSTEM
     ============================================ */

  /* Border Widths */
  --border-width-thin: 1px;
  --border-width-medium: 2px;  /* For inputs/buttons - more substantial */
  --border-width-thick: 3px;

  /* Border Radius (modern, subtle rounding) */
  --radius-sm: 4px;
  --radius-md: 6px;   /* Standard for buttons/inputs */
  --radius-lg: 8px;   /* For cards */
  --radius-xl: 16px;  /* For large cards */
  --radius-full: 999px; /* For pills/badges */

  /* ============================================
     TRANSITIONS & ANIMATIONS
     ============================================ */

  /* Timing Functions */
  --transition-duration-fast: 100ms;    /* Snappy interactions */
  --transition-duration-base: 200ms;    /* Standard transitions */
  --transition-duration-slow: 300ms;    /* Deliberate transitions */

  /* Easing Functions */
  --ease-standard: ease;
  --ease-smooth: cubic-bezier(.19, 1, .22, 1); /* Sophisticated bounce-back */
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);

  /* ============================================
     Z-INDEX SCALE
     ============================================ */

  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;

  /* ============================================
     BREAKPOINTS (for media queries)
     ============================================ */

  --breakpoint-sm: 640px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 1024px;
  --breakpoint-xl: 1280px;
}

/**
 * Dark Mode Support (Optional - for future implementation)
 */
@media (prefers-color-scheme: dark) {
  :root {
    /* Override colors for dark mode if needed */
    /* Currently not implemented */
  }
}

/**
 * Reduced Motion Support (Accessibility)
 */
@media (prefers-reduced-motion: reduce) {
  :root {
    --transition-duration-fast: 0ms;
    --transition-duration-base: 0ms;
    --transition-duration-slow: 0ms;
  }

  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   LOADING SPINNER COMPONENT
   ============================================ */

/**
 * Orange Strava-themed loading spinner
 * Usage: <div class="spinner"></div>
 * Sizes: .spinner--sm (14px), default (20px), .spinner--lg (32px)
 */

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

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border, #E5E5E5);
  border-top-color: var(--strava-orange, #FC4C02);
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
  flex-shrink: 0;
}

.spinner--sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

.spinner--lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

/* Centered spinner with optional text */
.spinner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm, 8px);
  padding: var(--spacing-lg, 24px);
}

.spinner-container .spinner-text {
  font-size: var(--font-size-sm, 14px);
  color: var(--muted-ink, #6B6B6B);
}

/* ============================================
   STEPPER COMPONENT
   ============================================ */

/**
 * Strava Booster Stepper Input
 * Usage:
 * <div class="sb-stepper">
 *   <button type="button" class="sb-stepper-btn sb-stepper-decrement" aria-label="Decrease">−</button>
 *   <input type="number" class="sb-stepper-input" value="1.00" step="0.01" min="0.01" max="99.99">
 *   <button type="button" class="sb-stepper-btn sb-stepper-increment" aria-label="Increase">+</button>
 * </div>
 *
 * Sizes: .sb-stepper--sm (compact), default (standard), .sb-stepper--lg (large)
 */

.sb-stepper {
  display: inline-flex;
  align-items: stretch;
  border: 2px solid var(--border, #E5E5E5);
  border-radius: var(--radius-md, 6px);
  overflow: hidden;
  background: var(--card, #FFFFFF);
  transition: border-color var(--transition-duration-base, 200ms) var(--ease-standard, ease),
              box-shadow var(--transition-duration-base, 200ms) var(--ease-standard, ease);
}

.sb-stepper:hover {
  border-color: var(--gray-300, #D4D4D4);
}

.sb-stepper:focus-within {
  border-color: var(--strava-orange, #FC4C02);
  box-shadow: var(--focus-ring, 0 0 0 3px rgba(252, 76, 2, 0.15));
}

.sb-stepper-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  padding: 0;
  border: none;
  background: var(--gray-50, #FAFAFA);
  color: var(--gray-600, #6B6B6B);
  font-size: 20px;
  font-weight: var(--font-weight-medium, 500);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--transition-duration-fast, 100ms) var(--ease-standard, ease),
              color var(--transition-duration-fast, 100ms) var(--ease-standard, ease);
}

.sb-stepper-btn:hover {
  background: var(--strava-orange, #FC4C02);
  color: white;
}

.sb-stepper-btn:active {
  background: var(--strava-orange-dark, #E34402);
  color: white;
}

.sb-stepper-btn:disabled {
  background: var(--gray-100, #F0F0F0);
  color: var(--gray-400, #ABABAB);
  cursor: not-allowed;
}

.sb-stepper-decrement {
  border-right: 1px solid var(--border, #E5E5E5);
}

.sb-stepper-increment {
  border-left: 1px solid var(--border, #E5E5E5);
}

.sb-stepper-input {
  width: 80px;
  padding: 10px 12px;
  border: none;
  background: var(--card, #FFFFFF);
  color: var(--ink, #1A1A1A);
  font-size: var(--font-size-base, 16px);
  font-weight: var(--font-weight-semibold, 600);
  text-align: center;
  -moz-appearance: textfield;
  appearance: textfield;
}

.sb-stepper-input::-webkit-outer-spin-button,
.sb-stepper-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.sb-stepper-input:focus {
  outline: none;
}

/* Size variants */
.sb-stepper--sm .sb-stepper-btn {
  width: 36px;
  font-size: 16px;
}

.sb-stepper--sm .sb-stepper-input {
  width: 60px;
  padding: 6px 8px;
  font-size: var(--font-size-sm, 14px);
}

.sb-stepper--lg .sb-stepper-btn {
  width: 52px;
  font-size: 24px;
}

.sb-stepper--lg .sb-stepper-input {
  width: 100px;
  padding: 14px 16px;
  font-size: 18px;
}

/* With prefix/suffix labels */
.sb-stepper-wrapper {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-sm, 8px);
}

.sb-stepper-prefix,
.sb-stepper-suffix {
  font-size: var(--font-size-sm, 14px);
  color: var(--muted-ink, #6B6B6B);
  font-weight: var(--font-weight-medium, 500);
}

.sb-stepper-prefix {
  padding-right: var(--spacing-xs, 4px);
}

/* ============================================
   MODAL / DIALOG COMPONENT
   ============================================ */

/**
 * Custom modal dialogs to replace native confirm/alert
 * Usage: sb.confirm('Are you sure?', { onConfirm: () => {} })
 */

.sb-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9998;
  opacity: 0;
  transition: opacity var(--transition-duration-base, 200ms) var(--ease-standard, ease);
  backdrop-filter: blur(2px);
}

.sb-modal-backdrop.active {
  opacity: 1;
}

.sb-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  background: var(--card, #fff);
  border-radius: var(--radius-lg, 8px);
  box-shadow: var(--shadow-xl, 0 16px 32px rgba(0, 0, 0, 0.12));
  z-index: 9999;
  max-width: 400px;
  width: calc(100% - 32px);
  opacity: 0;
  transition: opacity var(--transition-duration-base, 200ms) var(--ease-standard, ease),
              transform var(--transition-duration-base, 200ms) var(--ease-smooth, cubic-bezier(.19, 1, .22, 1));
}

.sb-modal.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.sb-modal__header {
  padding: var(--spacing-lg, 24px) var(--spacing-lg, 24px) 0;
}

.sb-modal__title {
  font-size: var(--font-size-h4, 18px);
  font-weight: var(--font-weight-semibold, 600);
  color: var(--ink, #1A1A1A);
  margin: 0;
}

.sb-modal__body {
  padding: var(--spacing-md, 16px) var(--spacing-lg, 24px);
  color: var(--muted-ink, #6B6B6B);
  font-size: var(--font-size-base, 16px);
  line-height: var(--line-height-base, 1.6);
}

.sb-modal__footer {
  padding: 0 var(--spacing-lg, 24px) var(--spacing-lg, 24px);
  display: flex;
  justify-content: flex-end;
  gap: var(--spacing-sm, 8px);
}

.sb-modal__btn {
  padding: var(--spacing-sm, 8px) var(--spacing-md, 16px);
  border-radius: var(--radius-md, 6px);
  font-size: var(--font-size-sm, 14px);
  font-weight: var(--font-weight-medium, 500);
  cursor: pointer;
  transition: all var(--transition-duration-fast, 100ms) var(--ease-standard, ease);
  border: none;
}

.sb-modal__btn--cancel {
  background: var(--gray-100, #F0F0F0);
  color: var(--gray-700, #4A4A4A);
}

.sb-modal__btn--cancel:hover {
  background: var(--gray-200, #E5E5E5);
}

.sb-modal__btn--confirm {
  background: var(--strava-orange, #FC4C02);
  color: #fff;
}

.sb-modal__btn--confirm:hover {
  background: var(--strava-orange-dark, #E34402);
}

.sb-modal__btn--danger {
  background: var(--error, #FC5200);
  color: #fff;
}

.sb-modal__btn--danger:hover {
  background: #E04800;
}

/* ============================================
   TOAST NOTIFICATION COMPONENT
   ============================================ */

/**
 * Toast notifications for non-blocking alerts
 * Usage: sb.toast('Message here', 'success')
 * Types: success, error, warning, info
 */

.sb-toast-container {
  position: fixed;
  top: var(--spacing-lg, 24px);
  right: var(--spacing-lg, 24px);
  z-index: var(--z-tooltip, 1070);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm, 8px);
  pointer-events: none;
}

@media (max-width: 480px) {
  .sb-toast-container {
    top: var(--spacing-md, 16px);
    right: var(--spacing-md, 16px);
    left: var(--spacing-md, 16px);
  }
}

.sb-toast {
  background: var(--card, #fff);
  border-radius: var(--radius-md, 6px);
  box-shadow: var(--shadow-lg, 0 8px 16px rgba(0, 0, 0, 0.10));
  padding: var(--spacing-md, 16px);
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-sm, 8px);
  max-width: 360px;
  pointer-events: auto;
  opacity: 0;
  transform: translateX(100%);
  transition: opacity var(--transition-duration-base, 200ms) var(--ease-standard, ease),
              transform var(--transition-duration-slow, 300ms) var(--ease-smooth, cubic-bezier(.19, 1, .22, 1));
  border-left: 3px solid var(--gray-400, #ABABAB);
}

@media (max-width: 480px) {
  .sb-toast {
    max-width: 100%;
    transform: translateY(-20px);
  }
}

.sb-toast.active {
  opacity: 1;
  transform: translateX(0);
}

@media (max-width: 480px) {
  .sb-toast.active {
    transform: translateY(0);
  }
}

.sb-toast--success {
  border-left-color: var(--success, #1BC96D);
}

.sb-toast--error {
  border-left-color: var(--error, #FC5200);
}

.sb-toast--warning {
  border-left-color: var(--warning, #FFB74D);
}

.sb-toast--info {
  border-left-color: var(--strava-orange, #FC4C02);
}

.sb-toast__icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.sb-toast--success .sb-toast__icon {
  color: var(--success, #1BC96D);
}

.sb-toast--error .sb-toast__icon {
  color: var(--error, #FC5200);
}

.sb-toast--warning .sb-toast__icon {
  color: var(--warning, #FFB74D);
}

.sb-toast--info .sb-toast__icon {
  color: var(--strava-orange, #FC4C02);
}

.sb-toast__content {
  flex: 1;
  min-width: 0;
}

.sb-toast__title {
  font-weight: var(--font-weight-semibold, 600);
  color: var(--ink, #1A1A1A);
  font-size: var(--font-size-sm, 14px);
  margin-bottom: 2px;
}

.sb-toast__message {
  color: var(--muted-ink, #6B6B6B);
  font-size: var(--font-size-sm, 14px);
  line-height: 1.4;
}

.sb-toast__close {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  background: none;
  border: none;
  color: var(--gray-400, #ABABAB);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-duration-fast, 100ms);
}

.sb-toast__close:hover {
  color: var(--gray-600, #6B6B6B);
}
