/**
 * CoachPro Design System Tokens
 * Mobile-First Design System for PWA
 * 
 * Breakpoints:
 * - xs: 320px (Small phones)
 * - sm: 375px (Standard phones)
 * - md: 414px (Large phones)
 * - lg: 768px (Tablets)
 * - xl: 1024px (Desktop/iPad landscape)
 * 
 * Touch targets: Minimum 48px (44px with padding)
 * Typography minimum: 14px for body, 12px for captions
 */

:root {
    /* Spacing Tokens (rem-based for accessibility) */
    --spacing-0: 0;
    --spacing-1: 0.25rem;   /* 4px */
    --spacing-2: 0.5rem;    /* 8px */
    --spacing-3: 0.75rem;   /* 12px */
    --spacing-4: 1rem;      /* 16px - Base */
    --spacing-5: 1.25rem;   /* 20px */
    --spacing-6: 1.5rem;    /* 24px */
    --spacing-8: 2rem;      /* 32px */
    --spacing-10: 2.5rem;   /* 40px */
    --spacing-12: 3rem;     /* 48px - Touch target */
    --spacing-16: 4rem;     /* 64px */
    --spacing-20: 5rem;     /* 80px */
    
    /* Layout Tokens */
    --app-bar-height: 56px;
    --bottom-nav-height: 64px;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 72px;
    --content-max-width: 1280px;
    --touch-target-min: 48px;
    --icon-touch-size: 44px;
    
    /* Safe Areas (iOS) */
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    
    /* Typography Scale */
    --text-xs: 0.75rem;     /* 12px */
    --text-sm: 0.875rem;    /* 14px - Min body */
    --text-base: 1rem;      /* 16px */
    --text-lg: 1.125rem;    /* 18px */
    --text-xl: 1.25rem;     /* 20px */
    --text-2xl: 1.5rem;     /* 24px */
    --text-3xl: 1.875rem;   /* 30px */
    --text-4xl: 2.25rem;    /* 36px */
    
    /* Line Heights */
    --leading-none: 1;
    --leading-tight: 1.25;
    --leading-snug: 1.375;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;
    
    /* Font Weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;
    
    /* Colors - Light Mode */
    --color-primary: #f97316;
    --color-primary-dark: #ea580c;
    --color-primary-light: #fb923c;
    
    --color-secondary: #ef4444;
    --color-secondary-dark: #dc2626;
    
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
    --color-info: #3b82f6;
    
    --color-background: #f3f4f6;
    --color-surface: #ffffff;
    --color-surface-elevated: #ffffff;
    
    --color-text-primary: #111827;
    --color-text-secondary: #6b7280;
    --color-text-disabled: #9ca3af;
    
    --color-border: #e5e7eb;
    --color-border-dark: #d1d5db;
    
    /* Shadows (Material Design) */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --shadow-app-bar: 0 2px 4px -1px rgba(0, 0, 0, 0.06), 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    
    /* Border Radius */
    --radius-sm: 0.25rem;   /* 4px */
    --radius-md: 0.375rem;  /* 6px */
    --radius-lg: 0.5rem;    /* 8px */
    --radius-xl: 0.75rem;   /* 12px */
    --radius-2xl: 1rem;     /* 16px */
    --radius-full: 9999px;
    
    /* Transitions */
    --transition-fast: 150ms;
    --transition-normal: 200ms;
    --transition-slow: 300ms;
    
    /* Z-index layers */
    --z-base: 0;
    --z-dropdown: 10;
    --z-sticky: 20;
    --z-fixed: 30;
    --z-backdrop: 40;
    --z-drawer: 50;
    --z-modal: 60;
    --z-popover: 70;
    --z-tooltip: 80;
    --z-toast: 90;
}

/* Dark Mode Colors */
.dark {
    --color-background: #111827;
    --color-surface: #1f2937;
    --color-surface-elevated: #374151;
    
    --color-text-primary: #f9fafb;
    --color-text-secondary: #9ca3af;
    --color-text-disabled: #6b7280;
    
    --color-border: #374151;
    --color-border-dark: #4b5563;
}

/* Mobile-First Base Styles */
html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}

/* Prevent horizontal overflow */
body, 
#app {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* App Bar Styles */
.app-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--app-bar-height);
    background: var(--color-surface);
    box-shadow: var(--shadow-app-bar);
    z-index: var(--z-fixed);
    display: flex;
    align-items: center;
    padding: 0 var(--spacing-4);
    padding-top: var(--safe-area-inset-top);
}

.dark .app-bar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

/* Touch Target Styles */
.touch-target {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-button {
    width: var(--icon-touch-size);
    height: var(--icon-touch-size);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-fast);
}

.icon-button:hover,
.icon-button:focus {
    background-color: rgba(0, 0, 0, 0.05);
}

.dark .icon-button:hover,
.dark .icon-button:focus {
    background-color: rgba(255, 255, 255, 0.1);
}

.icon-button:active {
    background-color: rgba(0, 0, 0, 0.1);
}

.dark .icon-button:active {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Drawer/Sidebar Styles */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-backdrop);
    opacity: 0;
    transition: opacity var(--transition-slow);
    pointer-events: none;
}

.drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(var(--sidebar-width), 85vw);
    height: 100%;
    height: 100dvh;
    background: var(--color-surface);
    z-index: var(--z-drawer);
    transform: translateX(100%);
    transition: transform var(--transition-slow) cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
}

.drawer.open {
    transform: translateX(0);
}

.drawer-left {
    right: auto;
    left: 0;
    transform: translateX(-100%);
}

.drawer-left.open {
    transform: translateX(0);
}

/* Card Styles - Mobile First */
.card {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
    width: 100%;
    margin-bottom: var(--spacing-4);
}

/* Full-width on mobile */
@media (max-width: 767px) {
    .card {
        border-radius: 0;
        border-left: none;
        border-right: none;
        margin-left: calc(-1 * var(--spacing-4));
        margin-right: calc(-1 * var(--spacing-4));
        width: calc(100% + var(--spacing-8));
    }
    
    .container-mobile {
        padding-left: var(--spacing-4);
        padding-right: var(--spacing-4);
    }
}

/* Button Styles */
.btn {
    min-height: var(--touch-target-min);
    padding: var(--spacing-3) var(--spacing-4);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    border-radius: var(--radius-lg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-2);
    transition: all var(--transition-fast);
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Input Styles */
.input {
    min-height: var(--touch-target-min);
    padding: var(--spacing-3) var(--spacing-4);
    font-size: var(--text-base);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    width: 100%;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

/* Smooth Scrolling */
.smooth-scroll {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* 60fps Scrolling Optimization */
.will-change-transform {
    will-change: transform;
}

.transform-gpu {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Responsive Typography */
@media (max-width: 374px) {
    html { font-size: 14px; }
}

@media (min-width: 768px) {
    html { font-size: 16px; }
}

@media (min-width: 1024px) {
    html { font-size: 16px; }
}

/* Landscape adjustments */
@media (orientation: landscape) and (max-height: 500px) {
    .app-bar {
        height: 48px;
    }
    
    .bottom-nav {
        height: 48px;
    }
}

/* iOS Safe Area support */
@supports (padding: env(safe-area-inset-top)) {
    .safe-top {
        padding-top: env(safe-area-inset-top);
    }
    
    .safe-bottom {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .safe-left {
        padding-left: env(safe-area-inset-left);
    }
    
    .safe-right {
        padding-right: env(safe-area-inset-right);
    }
}

/* Virtual keyboard handling */
@media (max-height: 500px) {
    .keyboard-aware {
        padding-bottom: 0 !important;
    }
}

/* Print styles */
@media print {
    .app-bar,
    .drawer,
    .bottom-nav {
        display: none !important;
    }
}
