/* ==========================================================================
   RESET & GLOBAL
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
}

:root {
    --bg: #0b1120;
    --panel: #111827;
    --panel2: #1f2937;
    --border: #334155;
    --text: #f8fafc;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --green: #22c55e;
    --orange: #f59e0b;
    --red: #ef4444;
    --purple: #8b5cf6;
    --radius: 16px;
    --shadow: 0 10px 35px rgba(0, 0, 0, 0.35);
}

/* ==========================================================================
   LAYOUT
   ========================================================================== */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
}

.main-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    background: var(--panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 18px;
}

.content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
}

/* ==========================================================================
   COMPONENTS: PANELS, BUTTONS, INPUTS
   ========================================================================== */
.panel {
    background: var(--panel2);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.panel h3 {
    margin-bottom: 12px;
    font-size: 15px;
}

.btn, .btn-primary, .add-btn, .danger-btn {
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: 0.2s;
    padding: 10px 16px;
    font-weight: 500;
}

.btn { background: var(--panel2); color: white; }
.btn:hover { background: var(--border); }
.btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 10px rgba(59,130,246,0.4);
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }

.add-btn { background: var(--green); color: white; width: 100%; }
.danger-btn { background: var(--red); color: white; padding: 5px 10px; }

input, select {
    width: 100%;
    background: #0f172a;
    color: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    outline: none;
}

input:focus, select:focus { border-color: var(--primary); }

/* ==========================================================================
   TABLES
   ========================================================================== */
table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    border: 1px solid var(--border);
    padding: 8px;
    text-align: center;
}

th { background: #0f172a; }

.pricing-table input { width: 70px; padding: 5px; }

/* ==========================================================================
   HEADER
   ========================================================================== */
.header {
    min-height: 115px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;          /* Anchor pour le titre centré */
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

/* Logo gauche */
.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
    z-index: 1;
}

/* Titre centré en absolu par rapport au header */
.header-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    pointer-events: none;   /* ne capture pas les clics */
}

.header-center h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.3px;
    background: linear-gradient(135deg, #f8fafc 30%, #93c5fd);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-center p {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

/* Boutons droite */
.header-right {
    display: flex;
    gap: 8px;
    align-items: center;
    z-index: 1;
}

/* Logo — plus grand, fond transparent, ombre portée */
.logo-container {
    width: 110px;
    height: 110px;
    border-radius: 14px;
    overflow: hidden;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: filter 0.2s, transform 0.2s;
}

.logo-container:hover {
    transform: scale(1.05);
    filter: brightness(1.15);
}

.logo-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Supprime le fond blanc de l'image PNG avec mix-blend-mode */
    mix-blend-mode: screen;
    filter: drop-shadow(0 2px 8px rgba(59,130,246,0.4));
}

/* ==========================================================================
   MAP & DASHBOARD
   ========================================================================== */
.map-wrapper { position: relative; flex: 1; }

#gmap { width: 100%; height: 400px; }

.address-bar {
    display: flex;
    gap: 15px; /* Plus d'espace entre les éléments */
    padding: 20px; /* Plus d'espace autour */
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    align-items: center; /* Aligne tout verticalement */
}

.address-bar input {
    flex: 1;
    height: 50px; /* Force une hauteur visible */
    padding: 10px 15px;
    font-size: 16px; /* Texte plus lisible */
}

/* Optionnel : pour styliser le bouton "Calculer" et "Réinitialiser" */
.address-bar button {
    height: 50px;
    padding: 0 20px;
    white-space: nowrap; /* Empêche le texte de se couper */
}

/* Chart & Dashboard */
.dashboard-row { display: flex; gap: 20px; align-items: stretch; margin-top: 15px; }
.chart-col { flex: 2; padding: 15px; background: var(--panel); }
.controls-col { flex: 1; background: var(--panel2); padding: 15px; border-radius: 8px; }

#totalFare { font-size: 42px; font-weight: 800; color: var(--green); text-align: center; }

/* Map Controls */
.map-type-menu {
    position: absolute; top: 15px; left: 15px; z-index: 1000;
    background: var(--panel); padding: 8px; border-radius: 12px;
    display: flex; gap: 8px; box-shadow: var(--shadow);
}

.map-type-item { cursor: pointer; text-align: center; font-size: 10px; }
.map-type-item img { width: 60px; height: 60px; border-radius: 8px; border: 2px solid var(--border); }
.map-type-item:hover img { border-color: var(--primary); }

/* ==========================================================================
   MOBILE TABS & NAVIGATION (Caché sur desktop)
   ========================================================================== */
.mobile-tabs {
    display: none;
    background: var(--panel2);
    border-bottom: 1px solid var(--border);
    width: 100%;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--muted);
    font-weight: 600;
    font-size: 14px;
    padding: 14px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease-in-out;
}

.tab-btn:hover {
    color: var(--text);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: rgba(59, 130, 246, 0.08);
}

/* ==========================================================================
   RESPONSIVE DESIGN (Premium Mobile First Refactor)
   ========================================================================== */
@media (max-width: 1024px) {
    /* 1. Affichage des onglets mobiles */
    .mobile-tabs {
        display: flex;
    }

    /* 2. Layout principal empilé */
    .main-layout {
        display: flex;
        flex-direction: column;
        flex: 1;
        overflow: hidden;
    }

    /* 3. Alternance entre Paramètres (sidebar) et Simulation (content) */
    .main-layout.show-settings .sidebar {
        display: block;
        flex: 1;
        overflow-y: auto;
        border-right: none;
    }

    .main-layout.show-settings .content {
        display: none;
    }

    .main-layout:not(.show-settings) .sidebar {
        display: none;
    }

    .main-layout:not(.show-settings) .content {
        display: flex;
        flex-direction: column;
        flex: 1;
        overflow-y: auto;
    }

    /* 4. Header adaptatif (Fin du chevauchement absolu) */
    .header {
        flex-direction: column;
        height: auto;
        min-height: auto;
        padding: 16px;
        gap: 12px;
        text-align: center;
    }

    .header-left, .header-center, .header-right {
        position: relative;
        left: auto;
        transform: none;
        width: 100%;
        justify-content: center;
        align-items: center;
    }

    .header-center {
        pointer-events: auto;
    }

    .logo-container {
        width: 95px;
        height: 95px;
    }

    .header-center h1 {
        font-size: 18px;
    }

    .header-right {
        flex-wrap: wrap;
        gap: 8px;
    }

    .header-right button {
        font-size: 12px;
        padding: 8px 12px;
        height: auto;
        flex: 1;
        min-width: 110px;
        max-width: 150px;
    }

    /* 5. Barre d'adresse optimisée avec grille 2 colonnes pour les boutons */
    .address-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 12px;
    }

    .address-bar input {
        grid-column: span 2;
        width: 100%;
        height: 44px;
    }

    .address-bar button {
        grid-column: span 1;
        width: 100%;
        height: 44px;
    }

    .drawing-toolbar {
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
    }

    .drawing-toolbar .tool-btn {
        flex: 1;
        min-width: 80px;
        text-align: center;
        font-size: 12px;
        padding: 6px 10px;
    }

    .toolbar-separator {
        display: none; /* Masqué pour l'empilement */
    }

    /* 6. Grille de résultats optimisée en 2 colonnes */
    .route-card {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
        padding: 10px;
    }
    
    /* 7. Taille de carte optimisée */
    #gmap {
        height: 320px;
    }

    .dashboard-row {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .header-right button {
        max-width: none;
        width: 47%;
    }
    
    .route-card {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .route-card > div:nth-child(3) {
        grid-column: span 2; /* Le Trafic prend toute la largeur au milieu */
    }
    
    #totalFare {
        font-size: 32px;
    }
    
    .fare-breakdown {
        gap: 3px;
    }
    .breakdown-item {
        padding: 5px 6px;
        min-width: 50px;
    }
    .breakdown-label {
        font-size: 9px;
    }
    .breakdown-value {
        font-size: 11px;
    }
    .breakdown-sep {
        font-size: 10px;
        margin: 0 -2px;
    }
}

/* ===========================
   ROUTE CARD (La grille des résultats)
=========================== */
.route-card {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 15px;
    background: var(--panel);
    border-radius: 12px;
    margin: 15px 0;
}

.route-card div {
    background: var(--panel2);
    padding: 14px;
    border-radius: 12px;
    text-align: center;
}

.route-card span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 4px;
}

.route-card strong {
    font-size: 18px;
    color: var(--text);
}

/* ===========================
   FARE CARD (Le prix total)
=========================== */
.fare-card {
    background: var(--panel);
    padding: 20px;
    text-align: center;
    border-radius: 12px;
    margin-bottom: 15px;
}

/* ===========================
   FARE BREAKDOWN
=========================== */
.fare-breakdown {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.breakdown-item {
    background: var(--panel2);
    border-radius: 10px;
    padding: 8px 14px;
    text-align: center;
    min-width: 70px;
}

.breakdown-label {
    display: block;
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 2px;
}

.breakdown-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.breakdown-sep {
    color: var(--muted);
    font-weight: bold;
    font-size: 16px;
}

/* ===========================
   CHART CARD
=========================== */
.chart-card {
    background: var(--panel);
    border-radius: 16px;
    padding: 20px;
    margin: 0 15px 15px;
}

/* ===========================
   PANEL HELPERS
=========================== */
.panel-hint {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 10px;
    line-height: 1.4;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
}

.field-hint {
    display: block;
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 400;
}

/* ===========================
   TOAST NOTIFICATIONS
=========================== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1e293b;
    color: var(--text);
    padding: 12px 24px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    border: 1px solid var(--border);
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
    transition: opacity 0.25s, transform 0.25s;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--red); color: #fca5a5; }

/* ===========================
   MAP CUSTOM CONTROLS
=========================== */
.custom-map-control-button {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow);
    transition: 0.2s;
}

.custom-map-control-button:hover {
    background: var(--panel2);
    border-color: var(--primary);
}

/* ===========================
   DRAWING TOOLBAR
=========================== */
.drawing-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    padding: 10px;
    background: var(--panel);
    border-radius: 8px;
    align-items: center;
}

.tool-btn {
    background: var(--panel2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    font-size: 13px;
}

.tool-btn:hover {
    border-color: var(--primary);
}

.tool-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.danger-tool {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
}

.danger-tool:hover {
    background: #fecaca;
    border-color: #f87171;
}

/* ===========================
   TRAFFIC BADGE
=========================== */
.traffic-badge {
    padding: 4px 8px;
    border-radius: 12px;
    color: white;
    font-size: 12px;
    font-weight: bold;
    text-transform: uppercase;
}

.toolbar-separator {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 5px;
}

/* ===========================
   FLOATING CHART PANEL
=========================== */
.fab-chart {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 30px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 10px 25px rgba(59, 130, 246, 0.4);
    cursor: pointer;
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 8px;
}

.fab-chart:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 14px 30px rgba(59, 130, 246, 0.5);
}

.fab-chart:active {
    transform: translateY(2px) scale(0.95);
}

.offcanvas-bottom {
    position: fixed;
    bottom: -100%;
    left: 0;
    width: 100%;
    max-height: 85vh;
    background: var(--bg);
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    z-index: 2000;
    transition: bottom 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

.offcanvas-bottom.active {
    bottom: 0;
}

.offcanvas-header {
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    border-radius: 20px 20px 0 0;
}

.offcanvas-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.btn-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text);
    font-size: 20px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-close:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.offcanvas-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.offcanvas-chart-card {
    border: none;
    background: transparent;
    padding: 0;
    margin: 0;
}

/* On desktop, maybe show it normally or still use the FAB?
   The user asked to reduce scroll, FAB makes sense globally. */
@media (min-width: 1024px) {
    .offcanvas-bottom {
        width: 500px;
        left: auto;
        right: 20px;
        bottom: -100%;
        border-radius: 16px;
        border: 1px solid var(--border);
    }
    .offcanvas-bottom.active {
        bottom: 20px;
    }
}