/*
 * Foundation: Design Tokens
 *
 * CSS Custom Properties - Design System
 * Character-based responsive design: 40-75 characters per line optimal reading
 *
 * Rails Convention: Foundation files define the core design system tokens
 * that are used across all components and domains.
 */

:root {
  /* OKLCH Color System - Base LCH Values - Light Mode */
  --lch-bg: 97% 0 0;
  /* Light background — white smoke neutral */
  --lch-accent-bg: 89% 0.010 165;
  /* Slightly darker accent background with green tint */
  --lch-text: 25% 0.01 155;
  /* Dark text with subtle green */
  --lch-text-light: 45% 0.01 155;
  /* Medium text with subtle green - WCAG AA compliant */
  --lch-text-lighter: 58% 0.008 155;
  /* Lighter text for secondary content */
  --lch-border: 80% 0.012 155;
  /* Light border with green tint */
  --lch-accent: 63% 0.08 153;
  /* Saturated green accent - dark enough for light backgrounds */
  --lch-valid: 62% 0.21 153;
  /* Valid green */
  --lch-invalid: 58% 0.18 29;
  /* Invalid red */
  --lch-required: 64% 0.15 68;
  /* Required amber */
  --lch-excellent: 55% 0.18 290;
  /* Excellent purple - readable contrast */

  /* Info (blue) and Warn (amber) — used by schedule tiles and status chips */
  --info: oklch(70% 0.14 250);
  --info-bg: oklch(93% 0.04 250);
  --warn: oklch(78% 0.14 65);
  --same: oklch(70% 0.01 155);

  /* Semantic Color Abstractions */
  --color-bg: oklch(var(--lch-bg));
  --color-accent-bg: oklch(var(--lch-accent-bg));
  --color-text: oklch(var(--lch-text));
  --color-text-light: oklch(var(--lch-text-light));
  --color-text-lighter: oklch(var(--lch-text-lighter));
  --color-border: oklch(var(--lch-border));
  --color-accent: oklch(var(--lch-accent));
  --color-valid: oklch(var(--lch-valid));
  --color-invalid: oklch(var(--lch-invalid));
  --color-required: oklch(var(--lch-required));
  --color-excellent: oklch(var(--lch-excellent));

  /* Legacy RGB values for compatibility */
  --bg: var(--color-bg);
  --accent-bg: var(--color-accent-bg);
  --text: var(--color-text);
  --text-light: var(--color-text-light);
  --text-lighter: var(--color-text-lighter);
  --border: var(--color-border);
  --accent: var(--color-accent);
  --valid: var(--color-valid);
  --invalid: var(--color-invalid);
  --required: var(--color-required);
  --excellent: var(--color-excellent);

  /* Modal-specific colors using OKLCH */
  --modal-backdrop: oklch(var(--lch-bg) / 0.85);
  --modal-backdrop-opaque: oklch(var(--lch-bg) / 0.92);
  /* Higher opacity for Safari without blur */
  --modal-surface: var(--color-accent-bg);
  --modal-border: var(--color-border);

  /* Spacing Scale - Based on content hierarchy, not device sizes */
  --space-xs: 0.25rem;
  /* 4px - extra small gaps */
  --space-sm: 0.5rem;
  /* 8px - small gaps */
  --space-md: 1rem;
  /* 16px - base spacing */
  --space-lg: 1.5rem;
  /* 24px - section spacing */
  --space-xl: 2rem;
  /* 32px - large sections */
  --space-2xl: 3rem;
  /* 48px - major sections */
  --space-3: 0.75rem; /* 12px */
  --space-4: 1rem;    /* 16px */

  /* Icon Size Scale */
  --icon-xs: 16px;
  /* Extra small icons */
  --icon-sm: 20px;
  /* Small icons */
  --icon-md: 24px;
  /* Medium icons (default) */
  --icon-lg: 32px;
  /* Large icons */
  --icon-2xl: 64px;
  /* 2X large icons */

  /* Fixed Typography - Consistent across all screen sizes */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1.125rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2rem;
  --text-4xl: 2.25rem;

  /* Transitions and Animations */
  /* Fast feedback - hover backgrounds, text colors, small UI changes */
  --transition-fast: 0.15s ease;
  /* Standard interactions - buttons, cards, photos, most UI elements */
  --transition-standard: 0.2s ease;
  /* Smooth transforms - complex state changes, panel slides */
  --transition-smooth: 0.25s ease;
  /* Legacy alias for compatibility */
  --transition-base: var(--transition-standard);
  /* Button easing - optimized for perceived responsiveness */
  --transition-button: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  /* Active state - instant feedback on press */
  --transition-active: 0.05s ease;
  /* iOS-inspired spring easing - feels native on mobile */
  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-decelerate: cubic-bezier(0, 0, 0.2, 1);
  --ease-accelerate: cubic-bezier(0.4, 0, 1, 1);
  /* Panel/modal duration */
  --duration-panel: 0.3s;
  --duration-panel-out: 0.2s;

  /* Safe area insets (notch/home indicator support) */
  --safe-inset-top: env(safe-area-inset-top, 0px);
  --safe-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-inset-left: env(safe-area-inset-left, 0px);
  --safe-inset-right: env(safe-area-inset-right, 0px);

  /* Scale Transforms */
  /* Zoom amount for panel/modal effects and page transitions (6% zoom) */
  --scale-zoom: 0.94;

  /* Shadows and Effects using OKLCH */
  --shadow-md:
    0 2px 8px oklch(0% 0 0 / 0.06),
    0 6px 20px oklch(0% 0 0 / 0.10);
  --shadow-lg:
    0 4px 12px oklch(0% 0 0 / 0.08),
    0 12px 32px oklch(0% 0 0 / 0.12);
  --shadow-xl:
    0 8px 20px oklch(0% 0 0 / 0.10),
    0 20px 48px oklch(0% 0 0 / 0.16);
  --shadow-mint: 0 4px 16px oklch(63% 0.08 153 / 0.40);

  /* Border Radius Scale */
  --radius-xs: 0.4rem;
  --radius-sm: 0.625rem;
  --radius-md: 1rem;
  --radius-lg: 1.375rem;
  --radius-xl: 1.75rem;
  --radius-2xl: 2.5rem;
  --radius-full: 9999px;
  --radius-logo: 25%;

  /* Component Sizes */
  --nav-height-mobile: 3.5rem;
  /* 52px - nav height */
  --touch-target-min: 2.75rem;
  /* 44px - minimum touch target */
  --touch-target-recommended: 3rem;
  /* 48px - recommended touch target */
  --sidebar-width: 16rem;
  /* 256px - desktop sidebar width */
  --topbar-height: 3.5rem;
  /* 56px - desktop topbar height */

  /* Typography aliases for compatibility */
  --text-md: var(--text-base);
  /* Alias: same as --text-base (1.125rem) */
  --font-sm: var(--text-sm);
  /* Alias: 0.875rem */
  --font-md: var(--text-base);
  /* Alias: 1.125rem */
  --font-lg: var(--text-lg);
  /* Alias: 1.25rem */
  --font-ui: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", ui-monospace, monospace;

  /* Token aliases — shorthand names used across components */
  --line: var(--border);
  --text-2: var(--text-light);
  --text-3: var(--text-lighter);
  --bg-2: var(--accent-bg);
  --surface-alt: var(--accent-bg);

  /* Background aliases */
  --bg-elevated: var(--accent-bg);
  /* Elevated surface background */
  --card-bg: var(--accent-bg);
  /* Card background */
  --surface-raised: oklch(94% 0.008 155);
  --surface-hover: oklch(91% 0.010 155);
  --card-hover: color-mix(in oklch, var(--accent) 8%, var(--accent-bg));
  /* Card hover state */
  --card-bg-pure: oklch(100% 0 0);
  /* Pure white card background */

  /* Page tints — Visual Playbook (L 55–60, C 0.10–0.13, hue only varies) */
  --tint-roster:    oklch(55% 0.12 153);   /* sage */
  --tint-today:     oklch(55% 0.13 29);    /* red */
  --tint-profile:   oklch(55% 0.10 155);   /* near-neutral sage */
  --tint-history:   oklch(55% 0.12 290);   /* purple */
  --tint-training:  oklch(60% 0.13 68);    /* amber */
  --tint-dashboard:      oklch(55% 0.12 240);   /* blue */
  --tint-announcements:  oklch(58% 0.11 195);   /* teal */

  /* Private note accent */
  --color-private:    oklch(50% 0.04 280);
  --color-private-bg: oklch(96% 0.012 280);
}


/*
 * High Contrast Mode Support
 * Enhance contrast when users prefer high contrast
 */
@media (prefers-contrast: high) {
  :root {
    /* Increase chroma for higher contrast using original hues */
    --lch-accent: 40% 0.280 155;
    --lch-valid: 38% 0.279 153;
    --lch-invalid: 55% 0.240 29;

    /* Stronger borders using original hue */
    --lch-border: 75% 0.020 155;
  }
}

/*
 * Dark Mode Support
 * Sage dark theme — same green hue family as light mode, dark base
 */
@media (prefers-color-scheme: dark) {
  :root {
    --lch-bg: 16% 0.012 153;
    /* Deep dark sage background */
    --lch-accent-bg: 22% 0.012 153;
    /* Elevated dark surface */
    --lch-text: 92% 0.005 165;
    /* Warm near-white text */
    --lch-text-light: 72% 0.008 165;
    /* Medium light text */
    --lch-text-lighter: 58% 0.008 165;
    /* Secondary text */
    --lch-border: 35% 0.012 153;
    /* Dark border with sage undertone */
    --lch-accent: 70% 0.08 153;
    /* Sage lifted slightly for dark bg contrast */
    --lch-valid: 70% 0.12 153;
    /* Valid green */
    --lch-invalid: 60% 0.15 29;
    /* Invalid red */
    --lch-required: 68% 0.12 68;
    /* Required orange */
    --lch-excellent: 72% 0.14 290;
    /* Excellent purple */

    /* Card background — elevated dark surface instead of pure white */
    --card-bg-pure: oklch(22% 0.012 153);

    /* Info and warn overrides for dark mode */
    --info: oklch(75% 0.14 250);
    --info-bg: oklch(22% 0.06 250);
    --warn: oklch(82% 0.14 65);
    --surface-raised: oklch(26% 0.015 153);
    --surface-hover: oklch(29% 0.015 153);

    /* Page tint overrides for dark mode */
    --color-private-bg: oklch(20% 0.02 280);
  }
}
