/* ===================================================
   FINANCE.COM — Thème centralisé & personnalisable
   =================================================== */

/* --- Variables CSS par défaut (Navy) --- */
:root {
    --theme-primary: #0a192f;
    --theme-secondary: #112240;
    --theme-accent: #60a5fa;
    --theme-accent-hover: #3b82f6;
    --theme-accent-light: rgba(96, 165, 250, 0.15);
}

/* --- Thème Navy (défaut) --- */
body.theme-navy,
body:not([class*="theme-"]) {
    --theme-primary: #0a192f;
    --theme-secondary: #112240;
    --theme-accent: #60a5fa;
    --theme-accent-hover: #3b82f6;
    --theme-accent-light: rgba(96, 165, 250, 0.15);
}

/* --- Thème Bordeaux --- */
body.theme-bordeaux {
    --theme-primary: #4a0011;
    --theme-secondary: #6b0019;
    --theme-accent: #f59e0b;
    --theme-accent-hover: #d97706;
    --theme-accent-light: rgba(245, 158, 11, 0.15);
}

/* --- Thème Vert --- */
body.theme-green {
    --theme-primary: #052e16;
    --theme-secondary: #14532d;
    --theme-accent: #4ade80;
    --theme-accent-hover: #22c55e;
    --theme-accent-light: rgba(74, 222, 128, 0.15);
}

/* ===================================================
   Classes utilitaires basées sur les variables
   =================================================== */

/* Background */
.bg-theme-primary   { background-color: var(--theme-primary) !important; }
.bg-theme-secondary  { background-color: var(--theme-secondary) !important; }
.bg-theme-accent     { background-color: var(--theme-accent) !important; }
.bg-theme-accent-light { background-color: var(--theme-accent-light) !important; }

/* Text */
.text-theme-primary  { color: var(--theme-primary) !important; }
.text-theme-accent   { color: var(--theme-accent) !important; }

/* Border */
.border-theme-accent { border-color: var(--theme-accent) !important; }

/* Hover */
.hover\:bg-theme-secondary:hover { background-color: var(--theme-secondary) !important; }
.hover\:bg-theme-accent:hover    { background-color: var(--theme-accent-hover) !important; }

/* ===================================================
   Sidebar — classes sémantiques
   =================================================== */
.sidebar {
    background-color: var(--theme-primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: all 0.3s;
    width: 16rem; /* w-64 */
}

.sidebar-logo-accent {
    color: var(--theme-accent);
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-radius: 0.5rem;
    transition: background-color 0.2s, color 0.2s;
}

.sidebar-link:hover {
    background-color: var(--theme-secondary);
}

.sidebar-link-active {
    background-color: var(--theme-secondary);
    color: var(--theme-accent);
}

.sidebar-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 9999px;
    background-color: var(--theme-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
}

.sidebar-login-btn {
    display: block;
    width: 100%;
    text-align: center;
    background-color: var(--theme-accent);
    color: #fff;
    font-size: 0.875rem;
    padding: 0.5rem;
    border-radius: 0.25rem;
    transition: opacity 0.2s;
}
.sidebar-login-btn:hover {
    opacity: 0.85;
}

/* ===================================================
   Héritage / rétrocompatibilité
   =================================================== */
.bg-navy { 
    background-color: var(--theme-primary) !important; 
}

.text-navy {
    color: var(--theme-primary) !important;
}

/* ===================================================
   Polices
   =================================================== */
.font-sans { 
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; 
}

/* ===================================================
   Utilitaires globaux
   =================================================== */
.custom-scrollbar::-webkit-scrollbar {
    width: 4px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background-color: rgba(156, 163, 175, 0.5);
    border-radius: 2px;
}

/* Sélecteur de thème — pastilles couleur */
.theme-swatch {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 9999px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    position: relative;
}
.theme-swatch:hover {
    transform: scale(1.1);
}
.theme-swatch.selected {
    border-color: #111827;
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px #111827;
}
.theme-swatch.selected::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* ===================================================
   Mobile Responsive — max 767px
   =================================================== */
@media (max-width: 767px) {
    /* Body & Layout */
    body {
        overflow-x: hidden;
    }

    /* Sidebar off-canvas */
    .sidebar,
    aside#sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        height: 100vh;
        width: 16rem;
        z-index: 50;
    }

    /* Main content full width */
    main {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* Cards & grids */
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4,
    .grid-cols-5 {
        grid-template-columns: 1fr !important;
    }
    .course-grid-two-col {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    /* Course sidebar */
    .course-sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        z-index: 50;
        width: 85vw !important;
        max-width: 20rem;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    .course-sidebar.open {
        transform: translateX(0);
    }

    /* Text sizing */
    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.25rem !important; }
    h3 { font-size: 1.1rem !important; }

    /* Buttons & inputs — bigger touch targets */
    button, a.btn, input[type="submit"],
    .sidebar-link {
        min-height: 44px;
    }

    input, select, textarea {
        font-size: 16px !important; /* Prevents iOS zoom */
    }

    /* Tables responsive */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Modal mobile */
    #feedbackModal > div {
        margin: 0.5rem !important;
        max-height: 95vh;
        overflow-y: auto;
    }

    /* Dashboard stats — 2 cols on mobile */
    .dashboard-stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
    }

    /* Chat area */
    .chat-messages {
        padding: 0.5rem !important;
    }
    .chat-input-area {
        padding: 0.5rem !important;
    }

    /* Fixed bottom nav in courses */
    .course-bottom-nav {
        bottom: 0.75rem !important;
        left: 0 !important;
        right: 0 !important;
        padding: 0 0.5rem !important;
        margin: 0 !important;
    }

    /* Padding adjustments */
    .p-6 { padding: 0.75rem !important; }
    .p-8 { padding: 1rem !important; }
    .px-6 { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
    .px-8 { padding-left: 1rem !important; padding-right: 1rem !important; }
}

/* ===================================================
   Small phones — max 374px
   =================================================== */
@media (max-width: 374px) {
    h1 { font-size: 1.25rem !important; }
    .text-2xl { font-size: 1.25rem !important; }
    .text-xl { font-size: 1.1rem !important; }

    .dashboard-stats {
        grid-template-columns: 1fr !important;
    }
}

/* ===================================================
   Touch & mobile UX
   =================================================== */
@media (hover: none) and (pointer: coarse) {
    /* Larger clickable areas */
    .sidebar-link,
    nav a,
    button {
        min-height: 44px;
        min-width: 44px;
    }

    /* Remove hover effects that cause sticky states on touch */
    .hover\:bg-gray-800:hover {
        background-color: inherit;
    }

    /* Active state instead */
    .sidebar-link:active {
        background-color: var(--theme-secondary);
    }
    button:active {
        opacity: 0.8;
    }
}

/* ===================================================
   Safe area for notched phones (iPhone X+)
   =================================================== */
@supports (padding: env(safe-area-inset-bottom)) {
    .course-bottom-nav {
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom)) !important;
    }
    aside#sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }
}
