/* =========================================
   1. VARIABLES & THEME CONFIGURATION
   ========================================= */

:root {
    /* Primary Colors */
    --c-primary: #4564ff;
    --c-primary-75: rgba(69, 100, 255, 0.75);
    --c-primary-50: rgba(69, 100, 255, 0.5);
    --c-primary-25: rgba(69, 100, 255, 0.25);
    --c-primary-light: #638fff;
    --c-primary-light-50: rgba(99, 143, 255, 0.5);
    --c-primary-light-25: rgba(99, 143, 255, 0.5);
    --c-secondary: #EE8383;

    /* Background Colors */
    --c-bg-white: #FFF;
    --c-bg-white-75: rgba(255, 255, 255, 0.75);
    --c-bg-white-50: rgba(255, 255, 255, 0.5);
    --c-bg-white-25: rgba(255, 255, 255, 0.25);
    --c-label: #e5e5f8;
    --c-display: #9cb8ff;
    --c-body: #f6fbff;
    --c-background: #F8F8F8;
    --c-background-15: rgba(248, 248, 248, 0.15);
    --c-hover: rgb(247, 245, 255);

    /* Layout Variables */
    --sidebar-width: 300px;
    
    /* Hero Banner Variable */
    --hero-bg: #212529;

    /* Status Colors */
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f97316;
    --c-blue-500: var(--c-blue-500);

    /* Typography */
    --st-font-family: 'Manrope', sans-serif;
    --st-icon-font-family: Font Awesome 6 Free, Font Awesome 5 Free;

    /* Box Shadows */
    --bs-button: 0 4px 8px rgba(142.27, 126.66, 162.56, 0.50);
    --bs-spread: 0px 5px 25px 0px rgba(118, 103, 139, 0.25);
    --bs-spread-light: 0px 5px 25px 0px rgba(118, 103, 139, 0.15);
    --bs-smashed: 0px 2px 2px 0px rgba(142, 127, 163, 0.50);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 25px rgba(0, 0, 0, 0.12);
    --shadow-subtle: 0 4px 20px rgba(0, 0, 0, 0.05);

    /* Border Radius */
    --radius-sm: 0.5rem;
    --radius-md: 1rem;
    --radius-lg: 1.5rem;
    --radius-full: 9999px;

    /* Transitions */
    --t-all: all 300ms ease;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-transform: transform 0.2s ease;
    --transition-card: transform 0.2s ease, box-shadow 0.2s ease;

    /* Bootstrap Primary Color Override */
    --bs-primary: #4564ff;
    --bs-primary-rgb: 69, 100, 255;
}

/* Dark Mode Configuration */
[data-bs-theme="dark"] {
    /* Colors */
    --c-primary: #638fff;
    --c-primary-75: rgba(99, 143, 255, 0.75);
    
    --c-bg-white: #343a40; /* Harmonized Gray */
    --c-bg-white-75: rgba(52, 58, 64, 0.75);
    --c-bg-white-50: rgba(52, 58, 64, 0.5);
    --c-bg-white-25: rgba(52, 58, 64, 0.25);
    
    --c-label: #495057;
    --c-display: #adb5bd;
    
    --c-body: #f8fafc; /* Light text */
    --c-background: #212529; /* Main Dark Background */
    --c-background-15: rgba(33, 37, 41, 0.15);
    --c-hover: #495057;
    
    /* Hero Banner Dark Mode */
    --hero-bg: linear-gradient(180deg, #4564ff 0%, #2a43cc 100%);
    
    /* Bootstrap Overrides */
    --bs-body-bg: var(--c-background);
    --bs-body-color: var(--c-body);
    --bs-secondary-bg: #343a40;
    --bs-tertiary-bg: #495057;
}

/* =========================================
   2. BASE & BOOTSTRAP OVERRIDES
   ========================================= */

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--st-font-family), 'Poppins', sans-serif;
    color: var(--c-body);
    font-size: 14px;
    word-wrap: break-word;
    background: var(--c-background);
}

/* Buttons */
.s-button, .btn {
    text-decoration: none;
    min-width: 5rem;
    padding: .5rem 1rem;
    text-align: center;
    font-size: 1rem;
    font-family: var(--st-font-family);
    font-weight: 500;
    word-wrap: break-word;
    border-radius: var(--radius-full);
    transition: var(--t-all);
    cursor: pointer;
}

.s-button:first-letter, .btn:first-letter {
    text-transform: uppercase;
}

.btn-primary {
    --bs-btn-bg: #4564ff;
    --bs-btn-border-color: #4564ff;
    --bs-btn-hover-bg: #3754cc;
    --bs-btn-hover-border-color: #3754cc;
    --bs-btn-active-bg: #2e47b3;
    --bs-btn-active-border-color: #2e47b3;
}

.btn-outline-primary {
    --bs-btn-color: #4564ff;
    --bs-btn-border-color: #4564ff;
    --bs-btn-hover-bg: #4564ff;
    --bs-btn-hover-border-color: #4564ff;
    --bs-btn-active-bg: #4564ff;
    --bs-btn-active-border-color: #4564ff;
}

/* Inputs */
.s-input, .form-control {
    background: var(--bs-secondary-bg);
}

.s-input:focus, .form-control:focus {
    background: var(--bs-secondary-bg);
    border-color: var(--c-primary-light) !important;
    box-shadow: 0 0 0 0.2rem var(--c-primary-light-25) !important;
}

/* Nav Items */
.nav-link.active {
    background-color: var(--c-primary) !important;
    box-shadow: var(--bs-smashed);
    transition: var(--t-all);
}

.nav-link {
    color: var(--c-primary);
}

.nav-item { 
    transition: var(--t-all);
}

.nav-item:hover {
    background: var(--c-hover);
    color: var(--c-primary) !important;
}

/* Scrollbar */
.hide-scrollbar::-webkit-scrollbar {
    display: none;
}
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* =========================================
   3. UTILITIES & GLASSMORPHISM
   ========================================= */

/* Backgrounds */
.bg-white { background: var(--c-bg-white); }
.bg-white-75 { background: var(--c-bg-white-75); }
.bg-white-50 { background: var(--c-bg-white-50); }
.bg-surface { background-color: var(--c-bg-white) !important; }

/* Text Colors */
.tc-body { color: var(--c-body); }
.tc-display { color: var(--c-display); }
.tc-label { color: var(--c-label); }
.tc-primary { color: var(--c-primary); }
.tc-secondary { color: var(--c-secondary); }
.tc-green { color: #28ff56; }
.font-color { color: #625F6F; }

/* Glass Effect */
.glass {
    position: relative;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border: 0.5px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.glass-transparent {
    background: transparent !important;
}

.glass::before {
    content: '';
    position: absolute;
    top: 0; left: -50%; width: 200%; height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.25) 0%, rgba(255, 255, 255, 0.1) 50%, transparent 100%);
    pointer-events: none;
}

.glass::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%, rgba(0, 0, 0, 0.05) 100%);
    pointer-events: none;
}

/* Glass Dark Mode Adaptation */
[data-bs-theme="dark"] .glass {
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.15), inset 0 -1px 0 rgba(0, 0, 0, 0.2);
}

[data-bs-theme="dark"] .glass::before {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 50%, transparent 100%);
}

[data-bs-theme="dark"] .glass::after {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%, rgba(0, 0, 0, 0.1) 100%);
}

/* Zoom Hover Effect */
.zoom-on-hover {
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transition-delay: 0.25s;
}
.zoom-on-hover:hover {
    transform: scale(1.065);
}

/* Progress Bar */
.progress-bar {
    background: linear-gradient(90deg, #4564ff 0%, #8a9eff 100%);
    box-shadow: inset 0 1px 2px var(--bs-spread)
}

/* Logo Inversion */
[data-bs-theme="dark"] .sidebar-logo-img,
[data-bs-theme="dark"] .navbar-logo {
    filter: invert(1) brightness(200%);
}

/* =========================================
   4. COMPONENTS & LAYOUT (Desktop Default)
   ========================================= */

/* Layout Helpers */
.sidebar-container {
    width: var(--sidebar-width) !important;
}

.layout-main {
    margin-left: var(--sidebar-width) !important;
    transition: margin-left 0.3s ease;
}

/* Hero Banner */
.area-banner {
    background: var(--hero-bg) !important;
}

/* Providers Panel Animation */
.providers-panel-transition {
    transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.4s ease, visibility 0.4s, width 0.4s ease, left 0.4s ease, margin 0.4s ease, bottom 0.4s ease, border-radius 0.4s ease;
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.providers-panel-visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

.providers-panel-transition {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.providers-panel-centered {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: 380px;
    max-width: 95%;
    bottom: 1rem;
    border-radius: 1.5rem !important;
}

.providers-panel-expanded {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: 100% !important;
    height: 85vh !important;
    max-height: 85vh !important;
    bottom: 0 !important;
    border-radius: 2rem 2rem 0 0 !important;
    display: flex;
    flex-direction: column;
}

.providers-panel-centered .search-zone,
.providers-panel-centered #providers-list {
    display: none;
}

.providers-panel-expanded .search-zone {
    display: flex;
}

.providers-panel-expanded #providers-list {
    display: block;
}

.providers-panel-expanded #panel-metadata {
    display: none !important;
}

/* Masquer la recherche globale si le panel est ouvert */
.providers-panel-visible ~ .translate-middle-x {
    display: none !important;
}

/* Animation fluide pour les nouveaux éléments */
#panel-metadata {
    transition: all 0.3s ease;
}

/* Map Zoom Controls (Desktop Position) */
.map-zoom-controls {
    top: 0;
}

/* Category Chips Container (3 rows horizontal scroll on mobile) */
@media (max-width: 991.98px) {
    .category-chips-container {
        flex-direction: column;
        flex-wrap: wrap;
        height: 160px; /* Increased from 140px to fit 3 rows comfortably */
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
        gap: 0.5rem !important;
        align-content: flex-start; /* Ensure items start from the left */
    }
    
    .category-chips-container::-webkit-scrollbar {
        display: none;
    }
    
    .category-chips-container .btn {
        white-space: nowrap;
        width: auto;
        flex-shrink: 0;
    }
}

/* Dashboard Layout Base (Mobile Flex Fallback) */
.dashboard-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.providers-panel-expanded {
    left: 0;
    right: 0;
    width: 100% !important;
    height: 85vh !important;
    max-height: 85vh !important;
    bottom: 0 !important;
    margin-bottom: 0;
    border-radius: 2rem 2rem 0 0 !important;
    display: flex;
    flex-direction: column;
}

.providers-panel-expanded #providers-list,
.providers-panel-expanded #provider-details {
    max-height: none !important;
    flex: 1;
}

.btn-halo {
    cursor: pointer;
}

.btn-halo:hover {
    border-color: var(--bs-primary);
    background-color: var(--c-primary-25);
}

/* =========================================
   5. RESPONSIVE MEDIA QUERIES
   ========================================= */

/* Mobile & Tablet (< 992px) */
@media (max-width: 991.98px) {
    /* Reset Sidebar Width on Mobile */
    :root {
        --sidebar-width: 0px;
    }
    
    .sidebar-container {
        padding: 0 !important;
        width: 300px !important;
    }

    .sidebar-content {
        border-radius: 0 !important;
    }
    
    .layout-main {
        margin-left: 0 !important;
    }

    /* Map Zoom Controls Mobile Position */
    .map-zoom-controls {
        top: auto !important;
        bottom: 20px !important;
    }
    
    /* Dashboard Mobile Layout Order */
    .area-header { order: 0; }
    .area-products { order: 1; }
    .area-banner { 
        order: 2; 
        min-height: 400px; 
        display: flex; 
        flex-direction: column; 
    }
    .area-bp { order: 3; }
    .area-ebooks { order: 4; }
    .area-map { order: 5; height: 400px; }
    
    /* Ebooks Grid Mobile */
    /* Slider handled in template with d-flex for better stability */

    .bg-power-box {
        transform: scale(0.5);
        transform-origin: bottom right;
        bottom: -150px !important;
        right: -150px !important;
   }

    .bg-power-eclair {
        top: -350px !important;
        right: -350px !important;
   }
}

/* Desktop (>= 992px) */
@media (min-width: 992px) {
    /* Dashboard Grid Layout */
    .dashboard-container {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .area-header { grid-column: 1 / -1; }
    .area-banner { grid-column: 1 / -1; min-height: auto; }
    .area-products { grid-column: span 1; }
    .area-map { grid-column: span 2; height: auto; }
    .area-bp { grid-column: span 1; }
    .area-ebooks { grid-column: 1 / -1; }
}

/* =========================================
   7. QA POPUP & MODAL
   ========================================= */

/* Petit popup discret */
.qa-nudge{
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 2000;
}
.qa-nudge__card{
    width: min(360px, calc(100vw - 36px));
    background: #fff;
    border: 1px solid rgba(0,0,0,.08);
    border-radius: 16px;
    box-shadow: 0 18px 55px rgba(0,0,0,.18);
    overflow: hidden;
}
.qa-nudge__head{
    display:flex; align-items:center; justify-content:space-between;
    gap:12px; padding: 12px 12px;
    background: linear-gradient(135deg, rgba(108,77,255,.10), rgba(143,107,255,.08));
    border-bottom: 1px solid rgba(0,0,0,.06);
}
.qa-nudge__badge{
    font-size: 11px; font-weight: 900; letter-spacing:.08em;
    color:#6C4DFF; text-transform:uppercase;
}
.qa-nudge__dismiss{
    border:none; background: rgba(0,0,0,.06);
    width:34px; height:34px; border-radius: 12px; cursor:pointer;
}
.qa-nudge__body{ padding: 12px; }
.qa-nudge__q{
    margin: 0 0 10px;
    font-weight: 900;
    color: #0b1220;
    line-height: 1.25;
}
.qa-nudge__btn{
    width: 100%;
    background: linear-gradient(135deg, #6C4DFF, #8F6BFF);
    border: none;
    color: #fff;
    font-weight: 800;
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: 0 10px 25px rgba(108,77,255,.35);
    cursor:pointer;
}

/* container global */
.qa-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
}

.qa-modal.is-open {
    display: block;
}

/* overlay */
.qa-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(10,14,25,.35);
    backdrop-filter: blur(4px);
}

/* === LE CHAT À DROITE === */
.qa-modal__panel {
    position: absolute;
    top: 12px;
    right: 12px;
    bottom: 12px;

    width: min(420px, calc(100vw - 24px));
    background: rgba(255,255,255,.96);
    border-radius: 18px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);

    display: flex;
    flex-direction: column;
    overflow: hidden;

    animation: slideInRight 0.2s ease-out;
}

/* animation douce */
@keyframes slideInRight {
    from {
        transform: translateX(20px);
        opacity: 0.6;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* header */
.qa-modal__header {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

/* body scrollable */
.qa-modal__body {
    flex: 1;
    padding: 14px 16px;
    overflow-y: auto;
}

/* footer */
.qa-modal__footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    background: rgba(255, 255, 255, 0.85);
}

/* bulles chat */
.qa-msg{ display:flex; margin: 10px 0; }
.qa-msg.user{ justify-content:flex-end; }
.qa-bubble{
    max-width: 84%;
    padding: 10px 12px;
    border-radius: 14px;
    line-height: 1.6;
    font-size: 14px;
    border: 1px solid rgba(0,0,0,.06);
    background: rgba(0,0,0,.03);
    color:#0b1220;
    white-space: pre-wrap;
}
.qa-msg.user .qa-bubble{
    background: linear-gradient(135deg, rgba(108,77,255,.18), rgba(143,107,255,.14));
    border-color: rgba(108,77,255,.22);
}
/* Croix stylée */
.qa-close{
    border: none;
    background: rgba(0,0,0,.06);
    width: 40px;
    height: 40px;
    border-radius: 14px;
    cursor: pointer;

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

    transition: background .15s ease, transform .15s ease;
}

.qa-close i{
    font-size: 16px;
    color: #0b1220;
    opacity: .7;
}

.qa-close:hover{
    background: rgba(108,77,255,.15);
    transform: scale(1.05);
}

.qa-close:hover i{
    color: #6C4DFF;
    opacity: 1;
}

.qa-close:active{
    transform: scale(.96);
}
/* Forcer le texte important en noir */
.qa-title{
    color: #0b1220 !important;
    background: none !important;
}

.qa-meta{
    color: rgba(11,18,32,.65) !important;
    background: none !important;
}

/* ===================================
   AI ANALYSIS PANEL STYLES (Restored & Themed)
   =================================== */

.ai-panel {
    width: 480px !important;
    border: none;
    background: transparent;
}

.ai-panel-inner {
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    border-radius: var(--radius-lg);
    margin: 1rem;
    padding: 0; /* On déplace le padding dans le scrollable */
    height: calc(100vh - 2rem);
    position: relative;
    overflow: hidden; /* Fixe tout ce qui n'est pas dans le scrollable */
    box-shadow: var(--shadow-lg);
}

.ai-panel-scrollable {
    height: 100%;
    overflow-y: auto;
    padding: 2rem;
    position: relative;
    z-index: 2; /* Devant l'image */
}

.ai-panel-close {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--bs-body-color);
    opacity: 0.5;
    cursor: pointer;
    z-index: 10; /* Toujours visible et fixe */
    transition: opacity 0.2s ease;
}

.ai-panel-close:hover {
    opacity: 1;
}

.ai-panel-header {
    text-align: center;
    margin-bottom: 1.5rem;
    padding-top: 1rem;
}

.ai-panel-company {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--bs-body-color);
    margin-bottom: 0.25rem;
}

.ai-panel-meta {
    font-size: 0.875rem;
    color: var(--bs-secondary-color);
    margin: 0;
}

.ai-panel-meta a {
    color: var(--c-primary);
    text-decoration: underline;
}

.ai-panel-meta a:hover {
    text-decoration: none;
}

/* AI Badge */
.ai-panel-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1.5rem;
}

.ai-badge-dot {
    width: 8px;
    height: 8px;
    background: var(--c-primary);
    border-radius: 50%;
    animation: ai-pulse 2s infinite;
}

@keyframes ai-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* AI Panel Content */
.ai-panel-content {
    padding-bottom: 140px;
}

.ai-section {
    margin-bottom: 1.25rem;
}

.ai-section-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--bs-secondary-color);
    opacity: 0.8;
    font-style: italic;
    margin-bottom: 0.25rem;
}

.ai-section-value {
    font-size: 0.875rem;
    color: var(--bs-body-color);
    line-height: 1.5;
}

.ai-section-value a {
    color: var(--c-primary);
    text-decoration: underline;
}

/* Decorative Graphic */
.ai-panel-graphic {
    position: absolute;
    bottom: -150px;
    right: -300px;
    width: 600px;
    height: 600px;
    pointer-events: none;
    opacity: 0.4;
    z-index: 1; /* Derrière le contenu scrollable */
}

.ai-panel-graphic img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Loading State */
.ai-panel-loading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--bs-secondary-color);
    font-size: 0.875rem;
    padding: 1rem 0;
}

/* Responsive AI Panel */
@media (max-width: 576px) {
    .ai-panel {
        width: 100% !important;
    }

    .ai-panel-inner {
        margin: 0.5rem;
        padding: 1.5rem;
        border-radius: var(--radius-md);
        min-height: calc(100vh - 1rem);
    }

    .ai-panel-graphic {
        width: 150px;
        height: 150px;
    }
}