/**
 * ================================================================
 * Crowdaa Advent Calendar - Base & WebView Styles
 * Version: 3.14.0
 * ================================================================
 *
 * Fondations CSS pour WebView Cordova mobile-first
 * - Reset mobile-friendly
 * - Touch optimizations
 * - GPU acceleration
 * - Safe areas iOS complètes
 * - Navigation WebView (InAppBrowser)
 */

/* ================================================================
   1. CSS VARIABLES - Design Tokens Globaux
   ================================================================ */
:root {
    /* ===== Colors - Injectées dynamiquement par calendar-template.php (v3.9.4) ===== */
    /* Les variables --cal-* sont définies dans <style id="crowdaa-calendar-colors"> */
    /* Fallback uniquement si calendar-template n'est pas chargé */
    --cal-primary: #667eea;
    --cal-secondary: #764ba2;
    --cal-gold: #FFD700;
    --cal-success: #7ED957;
    --cal-danger: #ff4757;
    --cal-locked: #95a5a6;
    --cal-unlocked: #ffffff;
    --cal-completed: #d4edda;

    /* Colors - Complémentaires fixes */
    --cal-dark-blue: #2B3674;
    --cal-light-blue: #E8ECFF;
    --cal-warning: #FFAB00;
    --cal-white: #FFFFFF;
    --cal-snow: #F0F4FF;
    --cal-text: #2B3674;
    --cal-text-light: #A3AED0;
    --cal-text-muted: #6B7280;

    /* ===== Typography ===== */
    --cal-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --cal-font-size-xs: 12px;
    --cal-font-size-sm: 14px;
    --cal-font-size-base: 16px;
    --cal-font-size-lg: 18px;
    --cal-font-size-xl: 24px;
    --cal-font-size-2xl: 32px;
    --cal-font-size-3xl: 48px;
    --cal-font-size-4xl: 64px;
    --cal-font-weight-normal: 400;
    --cal-font-weight-medium: 500;
    --cal-font-weight-semibold: 600;
    --cal-font-weight-bold: 700;
    --cal-line-height-tight: 1.2;
    --cal-line-height-normal: 1.5;
    --cal-line-height-relaxed: 1.75;

    /* ===== Spacing - Mobile-first (cohérent) ===== */
    --cal-spacing-xs: 8px;
    --cal-spacing-sm: 12px;
    --cal-spacing-md: 16px;
    --cal-spacing-lg: 24px;
    --cal-spacing-xl: 32px;
    --cal-spacing-2xl: 48px;
    --cal-spacing-3xl: 64px;

    /* Legacy spacing (rétrocompatibilité) */
    --spacing-xs: var(--cal-spacing-sm);
    --spacing-sm: var(--cal-spacing-lg);
    --spacing-md: 30px;
    --spacing-lg: 40px;
    --spacing-xl: 60px;
    --spacing-2xl: 80px;

    /* ===== Shadows - Multi-niveaux ===== */
    --cal-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --cal-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --cal-shadow-md: 0 2px 10px rgba(0, 0, 0, 0.1);
    --cal-shadow-lg: 0 4px 20px rgba(79, 91, 213, 0.1);
    --cal-shadow-xl: 0 10px 40px rgba(79, 91, 213, 0.2);
    --cal-shadow-2xl: 0 20px 60px rgba(0, 0, 0, 0.3);

    /* Legacy shadow */
    --crowdaa-shadow: var(--cal-shadow-lg);

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

    /* Legacy radius */
    --crowdaa-radius: var(--cal-radius-lg);

    /* ===== Transitions ===== */
    --cal-transition-fast: 0.15s ease;
    --cal-transition-base: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --cal-transition-slow: 0.5s ease;
    --cal-transition-bounce: 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);

    /* Legacy transition */
    --crowdaa-transition: var(--cal-transition-base);

    /* ===== Z-Index System ===== */
    --cal-z-base: 1;
    --cal-z-overlay: 10;
    --cal-z-dropdown: 1000;
    --cal-z-sticky: 5000;
    --cal-z-modal-overlay: 9999;
    --cal-z-modal: 10000;
    --cal-z-toast: 15000;

    /* ===== Breakpoints (pour référence JS) ===== */
    --cal-breakpoint-sm: 480px;
    --cal-breakpoint-md: 768px;
    --cal-breakpoint-lg: 1024px;
    --cal-breakpoint-xl: 1280px;

    /* ===== WebView specific ===== */
    --webview-header-height: 60px;
    --webview-header-height-mobile: 55px;
    --webview-button-size: 40px;
    --webview-button-size-mobile: 36px;
}

/* ================================================================
   2. RESET - Mobile-First
   ================================================================ */

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    font-family: var(--cal-font-family);
    font-size: var(--cal-font-size-base);

    /* WebView iOS - Empêche zoom automatique sur focus input */
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;

    /* Scroll fluide natif */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    overscroll-behavior-x: none;

    /* Typography améliorée */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Box-sizing global */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* ================================================================
   3. TOUCH INTERACTIONS - Optimisations globales
   ================================================================ */

/* Supprime le flash bleu au tap sur iOS WebView */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none; /* Désactive le menu contextuel long-press */
}

/* Optimise les éléments interactifs pour le touch */
button,
a,
input,
textarea,
select,
[role="button"],
[onclick],
.interactive,
.clickable {
    /* Désactive le double-tap zoom */
    touch-action: manipulation;

    /* Empêche la sélection de texte accidentelle */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;

    /* Minimum touch target iOS Human Interface Guidelines */
    min-width: 44px;
    min-height: 44px;
}

/* Autorise la sélection pour les inputs */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="number"],
textarea {
    user-select: text;
    -webkit-user-select: text;
}

/* Touch feedback pour les devices tactiles */
@media (hover: none) {
    button:active,
    a:active,
    .interactive:active,
    .clickable:active {
        opacity: 0.7;
        transform: scale(0.97) translate3d(0, 0, 0);
        transition: all var(--cal-transition-fast);
    }
}

/* ================================================================
   4. SCROLL CONTAINERS - Optimisation WebView
   ================================================================ */

/* Tous les conteneurs avec scroll */
.scrollable,
.modal-content,
.overlay-content,
[data-scrollable="true"] {
    /* Momentum scrolling iOS */
    -webkit-overflow-scrolling: touch;

    /* Empêche pull-to-refresh accidentel */
    overscroll-behavior: contain;
}

/* ================================================================
   5. MODALS & OVERLAYS - Position fixed optimisée
   ================================================================ */

/* Base pour tous les éléments en position fixed */
.modal,
.overlay,
.popup,
[data-modal="true"],
[style*="position: fixed"] {
    /* Force GPU acceleration pour éviter glitches WebView */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;

    /* Scroll optimisé si le modal a du contenu scrollable */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* ================================================================
   6. ANIMATIONS - GPU Acceleration
   ================================================================ */

/* Force GPU pour tous les éléments animés */
.animated,
.transition,
[class*="animate-"],
[class*="fade"],
[class*="slide"] {
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* ================================================================
   7. VIEWPORT HEIGHT - Fallbacks pour WebView
   ================================================================ */

/* Classe helper pour full viewport height */
.full-height,
.vh-100 {
    height: 100vh;
    /* Modern browsers - Dynamic viewport (inclut/exclut barres selon scroll) */
    height: 100dvh;
    /* iOS Safari WebView fallback */
    height: -webkit-fill-available;
}

.min-full-height,
.min-vh-100 {
    min-height: 100vh;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
}

/* ================================================================
   8. INPUTS - Optimisations WebView
   ================================================================ */

/* Empêche le zoom automatique sur focus (iOS) */
input,
textarea,
select {
    /* Si font-size < 16px, iOS zoome automatiquement */
    font-size: 16px;
}

/* Focus visible amélioré (accessibilité) */
input:focus,
textarea:focus,
select:focus,
button:focus {
    outline: 2px solid var(--cal-primary);
    outline-offset: 2px;
}

/* Supprime outline pour les clics souris (garde pour clavier) */
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
select:focus:not(:focus-visible),
button:focus:not(:focus-visible) {
    outline: none;
}

/* ================================================================
   9. IMAGES - Optimisations
   ================================================================ */

img {
    /* Empêche débordement */
    max-width: 100%;
    height: auto;

    /* Désactive le menu contextuel long-press iOS */
    -webkit-touch-callout: none;

    /* Désactive la sélection */
    user-select: none;
    -webkit-user-select: none;
}

/* ================================================================
   10. CANVAS - Optimisations Touch
   ================================================================ */

canvas {
    /* Empêche scroll quand on dessine */
    touch-action: none;

    /* Désactive la sélection */
    user-select: none;
    -webkit-user-select: none;

    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
}

/* ================================================================
   11. PERFORMANCE - Will-change hints
   ================================================================ */

/* Éléments qui changeront fréquemment */
.will-animate {
    will-change: transform, opacity;
}

/* Retirer will-change après animation (à gérer en JS si besoin) */
.animation-complete {
    will-change: auto;
}

/* ================================================================
   12. SAFE AREAS iOS - Support complet
   ================================================================ */

@supports (padding: max(0px)) {
    /* Body avec safe areas optionnelles (non forcées) */
    body.with-safe-areas {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* Utility classes */
.safe-area-top {
    padding-top: env(safe-area-inset-top);
}

.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom);
}

.safe-area-left {
    padding-left: env(safe-area-inset-left);
}

.safe-area-right {
    padding-right: env(safe-area-inset-right);
}

.safe-area-all {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ================================================================
   13. NAVIGATION WEBVIEW (Cordova/InAppBrowser)
   ================================================================ */

/* Template wrapper */
.crowdaa-webview-template {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    max-width: 100vw;
    -webkit-overflow-scrolling: touch;
}

/* Avec navigation - Base mobile */
.crowdaa-webview-template.crowdaa-webview-styles {
    padding-top: var(--webview-header-height-mobile);
}

/* iOS Safe Area sur wrapper */
@supports (padding: max(0px)) {
    .crowdaa-webview-template.crowdaa-webview-styles {
        padding-top: calc(var(--webview-header-height-mobile) + env(safe-area-inset-top));
    }
}

/* Tablet/Desktop (768px+) */
@media (min-width: 768px) {
    .crowdaa-webview-template.crowdaa-webview-styles {
        padding-top: var(--webview-header-height);
    }

    @supports (padding: max(0px)) {
        .crowdaa-webview-template.crowdaa-webview-styles {
            padding-top: calc(var(--webview-header-height) + env(safe-area-inset-top));
        }
    }
}

/* Désactiver scroll horizontal strict */
.crowdaa-webview-template * {
    max-width: 100%;
}

/* ================================================================
   14. BOUTONS NAVIGATION WEBVIEW - Mobile-first
   ================================================================ */

/* Header navigation - Base mobile */
.crowdaa-webview-buttons {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--webview-header-height-mobile);
    background: linear-gradient(135deg, var(--cal-primary) 0%, var(--cal-secondary) 100%);
    box-shadow: var(--cal-shadow-md);
    z-index: var(--cal-z-modal);

    display: none; /* Par défaut, affiché par JS */

    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
}

/* iOS Safe Areas sur header */
@supports (padding: max(0px)) {
    .crowdaa-webview-buttons {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--webview-header-height-mobile) + env(safe-area-inset-top));
    }
}

/* Affiché par JS */
.crowdaa-webview-template.crowdaa-webview-styles .crowdaa-webview-buttons {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: var(--cal-spacing-md);
    padding-right: var(--cal-spacing-md);
}

/* Safe areas horizontal sur boutons */
@supports (padding: max(0px)) {
    .crowdaa-webview-template.crowdaa-webview-styles .crowdaa-webview-buttons {
        padding-left: max(var(--cal-spacing-md), env(safe-area-inset-left));
        padding-right: max(var(--cal-spacing-md), env(safe-area-inset-right));
    }
}

/* Tablet/Desktop (768px+) */
@media (min-width: 768px) {
    .crowdaa-webview-buttons {
        height: var(--webview-header-height);
    }

    @supports (padding: max(0px)) {
        .crowdaa-webview-buttons {
            height: calc(var(--webview-header-height) + env(safe-area-inset-top));
        }
    }
}

/* ================================================================
   15. BOUTONS BACK/CLOSE - Mobile-first
   ================================================================ */

/* Base mobile */
.crowdaa-btn-back,
.crowdaa-btn-close {
    position: relative;
    width: var(--webview-button-size-mobile);
    height: var(--webview-button-size-mobile);
    min-width: var(--webview-button-size-mobile);
    min-height: var(--webview-button-size-mobile);

    border-radius: var(--cal-radius-sm);
    background: rgba(255, 255, 255, 0.2);
    border: none;

    display: flex;
    align-items: center;
    justify-content: center;

    color: var(--cal-white);
    text-decoration: none;
    cursor: pointer;

    transition: all var(--cal-transition-base);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);

    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;

    /* Touch */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

/* Tablet/Desktop */
@media (min-width: 768px) {
    .crowdaa-btn-back,
    .crowdaa-btn-close {
        width: var(--webview-button-size);
        height: var(--webview-button-size);
        min-width: var(--webview-button-size);
        min-height: var(--webview-button-size);
    }
}

/* Hover pour devices avec souris */
@media (hover: hover) {
    .crowdaa-btn-back:hover {
        background: rgba(255, 255, 255, 0.3);
        transform: translate3d(0, -2px, 0);
    }

    .crowdaa-btn-close:hover {
        background: var(--cal-danger);
        transform: translate3d(0, -2px, 0);
    }
}

/* Touch feedback */
.crowdaa-btn-back:active,
.crowdaa-btn-close:active {
    transform: scale(0.95) translate3d(0, 0, 0);
}

/* SVG icons - Base mobile */
.crowdaa-btn-back svg,
.crowdaa-btn-close svg {
    width: 20px;
    height: 20px;
}

/* Tablet/Desktop */
@media (min-width: 768px) {
    .crowdaa-btn-back svg,
    .crowdaa-btn-close svg {
        width: 24px;
        height: 24px;
    }
}

/* Ripple effect tactile */
.crowdaa-btn-back::after,
.crowdaa-btn-close::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    transform: translate(-50%, -50%);
    transition: width var(--cal-transition-base), height var(--cal-transition-base);
    pointer-events: none;
}

.crowdaa-btn-back:active::after,
.crowdaa-btn-close:active::after {
    width: 100%;
    height: 100%;
}

/* ================================================================
   16. CONTENU WEBVIEW - Mobile-first
   ================================================================ */

.crowdaa-webview-content {
    min-height: 100vh;
    padding: var(--cal-spacing-lg);
    background: #f8f9fa;

    /* Slide-in animation via transition */
    opacity: 0;
    transform: translateX(100%) translate3d(0, 0, 0);
    transition: opacity var(--cal-transition-base),
                transform var(--cal-transition-base);
}

/* Avec navigation active */
.crowdaa-webview-template.crowdaa-webview-styles .crowdaa-webview-content {
    padding-top: 0; /* Le padding-top est sur body */
    opacity: 1;
    transform: translateX(0) translate3d(0, 0, 0);
}

/* iOS Safe Area bottom */
@supports (padding: max(0px)) {
    .crowdaa-webview-content {
        padding-bottom: max(var(--cal-spacing-lg), env(safe-area-inset-bottom));
    }
}

/* ================================================================
   17. MASQUER ÉLÉMENTS DU THÈME
   ================================================================ */

.crowdaa-webview-template #masthead,
.crowdaa-webview-template .site-header,
.crowdaa-webview-template #site-navigation,
.crowdaa-webview-template .site-footer,
.crowdaa-webview-template #colophon,
.crowdaa-webview-template .sidebar,
.crowdaa-webview-template .breadcrumb {
    display: none !important;
}

/* ================================================================
   18. UTILITY CLASSES
   ================================================================ */

/* WebView only */
.crowdaa-webview-only {
    display: none;
}

.crowdaa-webview-template.crowdaa-webview-styles .crowdaa-webview-only {
    display: flex;
}

/* Scrollable */
.scrollable {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
