/**
 * CariClub MVP - Core Design System Foundation (Updated)
 * 
 * Purpose: Establishes brand identity, typography, and foundational styles
 * Dependencies: None (foundation file)
 * Integration: Provides design tokens and base styles for all components
 * 
 * Mobile Targets:
 * - Container: max 430px width
 * - Touch targets: min 44px
 * - Performance: 60fps animations
 * 
 * @version MVP-1.0
 */

/* ===================================================================
   CSS RESET & BASE NORMALIZATION
   =================================================================== */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-text-size-adjust: none;
    -moz-text-size-adjust: none;
    -ms-text-size-adjust: none;
    text-size-adjust: none;
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #F8FAFC 0%, #F1F5F9 100%);
    min-height: 100vh;
    color: #334155;
    line-height: 1.5;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    height: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Remove default button and input styles */
button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
}

button {
    background: none;
    border: none;
    cursor: pointer;
    outline: none;
}

input, select, textarea {
    outline: none;
    border: none;
    background: none;
}

/* Remove default list styles */
ul, ol {
    list-style: none;
}

/* Remove default link styles */
a {
    color: inherit;
    text-decoration: none;
}

/* Image optimization */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ===================================================================
   DESIGN SYSTEM - CSS CUSTOM PROPERTIES
   =================================================================== */

:root {
    /* CariClub Brand Colors (from Style Guide) */
    --cariclub-blue: #0084D6;
    --cariclub-green: #49D2C9;
    --cariclub-red: #F37A7C;
    --deep-blue: #132A5D;
    --cerulean: #005C95;
    
    /* Extended Brand Palette */
    --deep-off-red: #D56164;
    --mute-green: #71CCC6;
    --canary: #FDBD41;
    --peach: #FFC996;
    --peach-alt: #EF9580;
    --bark: #B78467;
    --chestnut: #AD674B;
    --turquoise: #4AABAB;
    --magenta: #D44E76;
    --fuschia: #B660C7;
    --spring: #4AAD7E;
    
    /* Context-Specific Colors */
    --professional-primary: #0084D6;
    --professional-secondary: #005C95;
    --professional-gradient: linear-gradient(135deg, #0084D6 0%, #005C95 100%);
    
    --representative-primary: #D44E76;
    --representative-secondary: #B660C7;
    --representative-gradient: linear-gradient(135deg, #D44E76 0%, #B660C7 100%);
    
    --social-primary: #4AABAB;
    --social-secondary: #71CCC6;
    --social-gradient: linear-gradient(135deg, #4AABAB 0%, #71CCC6 100%);
    
    /* Typography Colors (from Style Guide) */
    --off-indigo-1: #49516D;
    --off-indigo-2: #535C77;
    --off-indigo-3: #7E8599;
    --off-indigo-4: #A9ADBB;
    
    /* Neutral Grays */
    --light-warm-gray: #F5F5F7;
    --medium-warm-gray: #E6E6E6;
    --deep-warm-gray: #B3B3B3;
    --slate-50: #F8FAFC;
    --slate-100: #F1F5F9;
    --slate-200: #E2E8F0;
    --slate-300: #CBD5E1;
    --slate-400: #94A3B8;
    --slate-500: #64748B;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1E293B;
    --slate-900: #0F172A;
    
    /* Status Colors */
    --success: #10B981;
    --success-light: #059669;
    --warning: #F59E0B;
    --warning-light: #D97706;
    --error: #EF4444;
    --error-light: #DC2626;
    --info: #3B82F6;
    --info-light: #2563EB;
    
    /* Typography System (CariClub Style Guide) */
    --font-primary: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-secondary: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-system: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    /* Typography Scale */
    --text-title: 500 20px var(--font-primary);
    --text-subheader-1: 500 14px var(--font-primary);
    --text-subheader-2: 500 14px var(--font-primary);
    --text-subheader-3: 400 14px var(--font-primary);
    --text-subheader-4: 600 10px var(--font-primary);
    --text-body-1: 400 14px var(--font-secondary);
    --text-body-2: 400 14px var(--font-secondary);
    --text-caption-1: 600 10px var(--font-secondary);
    --text-caption-2: 400 12px var(--font-secondary);
    --text-caption-3: 600 10px var(--font-primary);
    
    /* Layout Constraints */
    --container-max-width: 430px;
    --header-min-height: 120px;
    --nav-height: 60px;
    --touch-target: 44px;
    --border-radius: 12px;
    --border-radius-small: 8px;
    --border-radius-large: 16px;
    
    /* Spacing System (8px base) */
    --space-0: 0;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;
    --space-20: 80px;
    
    /* Legacy Spacing (for compatibility) */
    --space-xs: var(--space-1);
    --space-sm: var(--space-2);
    --space-md: var(--space-4);
    --space-lg: var(--space-6);
    --space-xl: var(--space-8);
    
    /* Animation Timing */
    --transition-fast: 0.2s ease;
    --transition-standard: 0.3s ease;
    --transition-slow: 0.4s ease;
    --transition-context: 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --transition-spring: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition-smooth: 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
    
    /* Shadows */
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-modal: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --shadow-header: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-button: 0 2px 8px rgba(14, 165, 233, 0.25);
    --shadow-button-hover: 0 4px 12px rgba(14, 165, 233, 0.35);
    --shadow-toast: 0 4px 12px rgba(16, 185, 129, 0.3);
    
    /* Z-Index Hierarchy */
    --z-content: 1;
    --z-nav: 100;
    --z-header: 150;
    --z-modal: 1000;
    --z-loading: 1500;
    --z-toast: 9999;
    
    /* Safe Area Insets */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* ===================================================================
   TYPOGRAPHY SYSTEM
   =================================================================== */

body {
    font: var(--text-body-1);
    color: var(--slate-700);
    line-height: 1.5;
}

/* Typography Classes */
.text-title {
    font: var(--text-title);
    color: var(--off-indigo-1);
    letter-spacing: -0.01em;
}

.text-subheader-1 {
    font: var(--text-subheader-1);
    color: var(--off-indigo-1);
}

.text-subheader-2 {
    font: var(--text-subheader-2);
    color: var(--cariclub-blue);
}

.text-subheader-3 {
    font: var(--text-subheader-3);
    color: var(--off-indigo-2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.text-subheader-4 {
    font: var(--text-subheader-4);
    color: var(--cariclub-blue);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.text-body-1 {
    font: var(--text-body-1);
    color: var(--off-indigo-2);
}

.text-body-2 {
    font: var(--text-body-2);
    color: var(--off-indigo-3);
}

.text-caption-1 {
    font: var(--text-caption-1);
    color: var(--off-indigo-3);
}

.text-caption-2 {
    font: var(--text-caption-2);
    color: var(--off-indigo-3);
    font-style: italic;
}

.text-caption-3 {
    font: var(--text-caption-3);
    color: var(--cariclub-blue);
}

/* ===================================================================
   CORE APP STRUCTURE & LAYOUT
   =================================================================== */

.app-container {
    max-width: var(--container-max-width);
    width: 100%;
    margin: 0 auto;
    background: #FFFFFF;
    min-height: 100vh;
    height: auto;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05), var(--shadow-modal);
    position: relative;
    transition: var(--transition-context);
    overflow-x: hidden;
    overflow-y: visible;
    padding-top: 0;
}

/* Container States */
.app-container.context-switching {
    opacity: 0.8;
    transform: scale(0.99);
}

.app-container.context-switching .content-area {
    filter: blur(1px);
}

/* Top Context Bar - Fixed Navigation */
.top-context-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    margin: 0 auto;
    max-width: 430px;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--slate-200);
    display: flex;
    justify-content: center;
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-area-top));
    padding-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    z-index: 200;
    height: calc(60px + var(--safe-area-top));
    box-sizing: border-box;
}

.executive-header {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    color: white;
    padding: 16px 20px;
    position: fixed;
    width: var(--container-max-width);
    left: 50%;
    transform: translateX(-50%);
    top: calc(60px + var(--safe-area-top));
    cursor: pointer;
    transition: all 0.4s ease;
    z-index: 150;
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    margin-top: 0;
    box-sizing: border-box;
    padding-bottom: 20px;
    height: auto;
    min-height: 120px;
}

.executive-header.expanded {
    padding-bottom: 24px;
    height: auto;
    min-height: 0;
}

.executive-header * {
    color: white;
}

/* Context-specific header colors */
.professional { 
    background: linear-gradient(135deg, #0084D6 0%, #005C95 100%) !important; 
}
.representative { 
    background: linear-gradient(135deg, #D44E76 0%, #B660C7 100%) !important; 
}
.social { 
    background: linear-gradient(135deg, #4AABAB 0%, #71CCC6 100%) !important; 
}

/* Main Content Area - Properly Spaced */
.content-area {
    padding: 20px;
    padding-bottom: 120px;
    background: #FFFFFF;
    transition: all 0.4s ease;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: visible;
    box-sizing: border-box;
    position: relative;
    z-index: var(--z-content);
    min-height: calc(100vh - 60px);
    /* Better default spacing - accounts for typical header heights */
    /* Context bar (60px) + Header min (120px) + Safe area + buffer = ~200px */
    margin-top: 0;
}

/* Bottom Navigation - Fixed at Bottom */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    max-width: var(--container-max-width);
    width: 100%;
    background: white;
    border-top: 1px solid var(--slate-200);
    display: flex;
    justify-content: space-around;
    padding: 8px 16px;
    padding-bottom: calc(8px + var(--safe-area-bottom));
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

/* ===================================================================
   LAYOUT UTILITIES
   =================================================================== */

/* Flex Utilities */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.flex-row {
    flex-direction: row;
}

.items-center {
    align-items: center;
}

.items-start {
    align-items: flex-start;
}

.items-end {
    align-items: flex-end;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-start {
    justify-content: flex-start;
}

.justify-end {
    justify-content: flex-end;
}

.flex-1 {
    flex: 1;
}

/* Grid Utilities */
.grid {
    display: grid;
}

.grid-cols-1 {
    grid-template-columns: repeat(1, 1fr);
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-cols-auto {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}

/* Gap Utilities */
.gap-1 {
    gap: var(--space-1);
}

.gap-2 {
    gap: var(--space-2);
}

.gap-3 {
    gap: var(--space-3);
}

.gap-4 {
    gap: var(--space-4);
}

.gap-6 {
    gap: var(--space-6);
}

/* ===================================================================
   BUTTON FOUNDATION
   =================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--border-radius);
    font-weight: 600;
    font-size: 14px;
    border: none;
    cursor: pointer;
    transition: var(--transition-standard);
    min-height: var(--touch-target);
    position: relative;
    text-align: center;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn:not(:disabled):active {
    transform: translateY(0) scale(0.98);
}

/* Button Variants */
.btn-primary {
    background: var(--professional-gradient);
    color: #FFFFFF;
    box-shadow: var(--shadow-button);
}

.btn-primary:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-button-hover);
}

.btn-secondary {
    background: #FFFFFF;
    color: var(--slate-500);
    border: 1.5px solid var(--slate-200);
}

.btn-secondary:not(:disabled):hover {
    background: var(--slate-50);
    border-color: var(--slate-300);
}

/* ===================================================================
   FORM FOUNDATION
   =================================================================== */

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--slate-300);
    border-radius: var(--border-radius-small);
    font-size: 14px;
    transition: var(--transition-fast);
    min-height: var(--touch-target);
    background: #FFFFFF;
    color: var(--slate-700);
}

.form-input:focus {
    outline: none;
    border-color: var(--cariclub-blue);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.form-input::placeholder {
    color: var(--slate-400);
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--slate-700);
    margin-bottom: var(--space-2);
}

.form-group {
    margin-bottom: var(--space-5);
}

/* ===================================================================
   LOADING STATES
   =================================================================== */

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--slate-200);
    border-top: 3px solid var(--cariclub-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-loading);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-standard);
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* ===================================================================
   TOAST NOTIFICATIONS
   =================================================================== */

.toast {
    position: fixed;
    top: calc(70px + var(--safe-area-top));
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: white;
    padding: 12px 24px;
    border-radius: var(--border-radius-small);
    font-size: 14px;
    font-weight: 600;
    z-index: var(--z-toast);
    opacity: 0;
    transition: var(--transition-standard);
    box-shadow: var(--shadow-toast);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    background: var(--error);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* ===================================================================
   ANIMATION KEYFRAMES
   =================================================================== */

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes contextSwitch {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes contextTransition {
    0% {
        opacity: 1;
        transform: scale(1);
        filter: blur(0px);
    }
    50% {
        opacity: 0.8;
        transform: scale(0.99);
        filter: blur(1px);
    }
    100% {
        opacity: 1;
        transform: scale(1);
        filter: blur(0px);
    }
}

@keyframes slideInFromBottom {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Context switching animation effect */
.context-pill.switching {
    animation: contextSwitch 0.5s ease;
}

.context-transitioning {
    animation: contextTransition 0.5s ease;
}

/* ===================================================================
   UTILITY CLASSES
   =================================================================== */

/* Spacing */
.m-0 { margin: 0; }
.m-1 { margin: var(--space-1); }
.m-2 { margin: var(--space-2); }
.m-3 { margin: var(--space-3); }
.m-4 { margin: var(--space-4); }
.m-6 { margin: var(--space-6); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.p-0 { padding: 0; }
.p-1 { padding: var(--space-1); }
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

/* Display */
.block { display: block; }
.inline-block { display: inline-block; }
.inline { display: inline; }
.hidden { display: none; }

/* Position */
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }

/* Width & Height */
.w-full { width: 100%; }
.h-full { height: 100%; }
.min-h-screen { min-height: 100vh; }

/* Border Radius */
.rounded { border-radius: var(--border-radius-small); }
.rounded-lg { border-radius: var(--border-radius); }
.rounded-xl { border-radius: var(--border-radius-large); }
.rounded-full { border-radius: 50%; }

/* Text Alignment */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Opacity */
.opacity-0 { opacity: 0; }
.opacity-50 { opacity: 0.5; }
.opacity-75 { opacity: 0.75; }
.opacity-100 { opacity: 1; }

/* Cursor */
.cursor-pointer { cursor: pointer; }
.cursor-not-allowed { cursor: not-allowed; }

/* User Select */
.select-none {
    -webkit-user-select: none;
    user-select: none;
}

/* ===================================================================
   RESPONSIVE DESIGN
   =================================================================== */

/* Small Mobile Optimizations */
@media (max-width: 430px) {
    .app-container {
        max-width: 100vw;
        border-radius: 0;
    }
    
    .top-context-bar {
        left: 0;
        transform: none;
        max-width: 100vw;
    }
    
    .executive-header {
        width: 100vw;
        left: 0;
        transform: none;
    }
    
    .bottom-nav {
        left: 0;
        transform: none;
        max-width: 100vw;
    }
    
    .btn {
        padding: var(--space-3) var(--space-4);
        font-size: 13px;
    }
    
    .text-title {
        font-size: 18px;
    }
}

/* Tablet and up */
@media (min-width: 431px) {
    .app-container {
        border-radius: var(--border-radius-large);
    }
}

/* Desktop */
@media (min-width: 769px) {
    .app-container {
        max-width: 430px;
    }
}

/* ===================================================================
   ACCESSIBILITY ENHANCEMENTS
   =================================================================== */

/* Focus visible for keyboard navigation */
.btn:focus-visible,
.form-input:focus-visible {
    outline: 2px solid var(--cariclub-blue);
    outline-offset: 2px;
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn-primary {
        border: 2px solid currentColor;
    }
    
    .form-input {
        border-width: 2px;
    }
}