/* =========================================
   1. VARIABLES & CONFIGURATION
   ========================================= */
:root {
    /* --- COULEURS PRINCIPALES --- */
    --c-primary: #2c3e50;
    --c-primary-dark: #34495e; /* Hover state */
    --c-link: #2980b9;
    --c-link-hover: #3498db;
    --c-danger: #c0392b;
    --c-danger-hover: #e74c3c;
    
    /* --- COULEURS DE FOND & TEXTE --- */
    --c-bg: #f4f4f4;
    --c-text: #333;
    --c-white: #fff;
    
    /* --- COULEURS STATUTS (Utilisées par JS et CSS) --- */
    --c-purple: #9b59b6;
    --c-green: #2ecc71;
    --c-yellow: #f1c40f;
    --c-grey: #bdc3c7; /* "White" status visualisé en gris */
    
    /* --- VARIANTES TEXTE (Plus foncées pour lisibilité) --- */
    --t-purple: #8e44ad;
    --t-green: #27ae60;
    --t-yellow: #d35400;
    --t-grey: #7f8c8d;
}

/* =========================================
   2. GENERAL & RESET
   ========================================= */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--c-bg);
    color: var(--c-text);
    margin: 0;
    padding: 0;
    line-height: 1.6;
}

h2, h3, h4 {
    color: var(--c-primary);
    margin-top: 0;
}

a {
    text-decoration: none;
    color: var(--c-link);
    transition: color 0.2s;
}

a:hover {
    color: var(--c-link-hover);
}

/* =========================================
   3. LAYOUT (Navbar, Container, Cards)
   ========================================= */
/* Navbar */
.navbar {
    background-color: var(--c-primary);
    padding: 1rem 20px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.navbar .brand {
    font-size: 1.2rem;
    font-weight: bold;
    letter-spacing: 1px;
}

.navbar .links a {
    color: #ecf0f1;
    margin-left: 20px;
    font-weight: 500;
}

.navbar .links a:hover {
    color: var(--c-link-hover);
}

/* --- STATUS BAR STYLES --- */
.status-wrapper {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Badge du Mode (Training/Racing) */
.mode-badge {
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: white;
    min-width: 80px;
    text-align: center;
    transition: background-color 0.3s;
}

.mode-training { background-color: #27ae60; } /* Vert */
.mode-racing { background-color: #e67e22; }   /* Orange */
.mode-disconnected { background-color: #7f8c8d; } /* Gris */

/* Indicateurs AMB / RCM */
.status-indicators {
    display: flex;
    gap: 15px;
    font-size: 0.8rem;
    color: #ecf0f1;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Le point lumineux */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #c0392b; /* Rouge par défaut */
    box-shadow: 0 0 2px rgba(0,0,0,0.5);
    transition: background-color 0.3s, box-shadow 0.3s;
}

.status-dot.connected {
    background-color: #2ecc71; /* Vert fluo */
    box-shadow: 0 0 8px #2ecc71; /* Effet Glow */
}

/* Container */
.container {
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

/* Card générique */
.card {
    background: var(--c-white);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

/* Classes utilitaires d'espacement */
.mb-20 { margin-bottom: 20px; }
.mt-20 { margin-top: 20px; }
.d-flex { display: grid; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.text-right { text-align: right; }
.w-100 { width: 100%; }

/* =========================================
   4. UI ELEMENTS (Buttons, Forms, Badges)
   ========================================= */
/* Boutons */
.btn {
    display: inline-block;
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    text-align: center;
    transition: background 0.2s;
    color: white;
}

.btn-primary { background-color: var(--c-primary); }
.btn-primary:hover { background-color: var(--c-primary-dark); }

.btn-danger { background-color: var(--c-danger); }
.btn-danger:hover { background-color: var(--c-danger-hover); }

.btn-small {
    padding: 4px 8px;
    font-size: 0.8rem;
}

.btn-save {
    height: 42px; /* Hauteur ajustée pour matcher les inputs */
    padding: 0 30px;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.9rem;
}

/* Formulaires */
input[type="text"], 
input[type="number"], 
select {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: inherit;
    box-sizing: border-box;
}

.config-card {
    background: white;
    border-radius: 8px;
    padding: 25px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    margin-bottom: 30px;
}
.config-form-grid {
    display: grid;
    grid-template-columns: 2fr 1fr auto; /* Nom large, Catégorie moyenne, Bouton auto */
    gap: 20px;
    align-items: end; /* Aligner le bouton avec les inputs */
}
.input-group label {
    text-transform: uppercase;
    font-size: 0.75rem;
    color: #7f8c8d;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}
.input-modern {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 1rem;
    background: #fcfcfc;
    transition: border-color 0.3s;
}
.input-modern:focus {
    border-color: var(--c-accent);
    outline: none;
    background: white;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: bold;
}

/* Badges de statut (utilisés dans Header Transpondeur) */
.badge-dark { background: var(--c-primary); color: white; }
.badge-yellow-stat { background: var(--c-yellow); color: #333; }

/* Badges de Catégorie (Dashboard & Listes) */
.badge-cat {
    background: #95a5a6;
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 5px;
    text-transform: uppercase;
    vertical-align: middle;
}

.badge-cat-small {
    font-size: 0.65rem;
    background: #ecf0f1;
    color: #7f8c8d;
    padding: 1px 4px;
    border-radius: 2px;
    margin-left: 5px;
    vertical-align: middle;
}

/* =========================================
   5. DASHBOARD & TABLES
   ========================================= */
.dashboard-grid {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 20px;
    align-items: start;
}

@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}

.table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    overflow: hidden;
}

.table-header {
    background: var(--c-primary);
    color: white;
    padding: 15px;
    font-size: 1.1rem;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-header .subtitle {
    font-size: 0.8rem;
    font-weight: normal;
    opacity: 0.8;
}

/* Tables Standards */
table { 
    width: 100%; 
    border-collapse: collapse; 
}

th { 
    background: var(--c-primary-dark); 
    color: #ecf0f1; 
    text-transform: uppercase; 
    font-size: 0.75rem; 
    letter-spacing: 1px; 
    padding: 12px 10px; 
    text-align: left; 
}

td { 
    padding: 10px; 
    border-bottom: 1px solid #eee; 
    vertical-align: middle;
}

.empty-message {
    text-align: center; 
    padding: 30px; 
    color: #999;
    font-style: italic;
}

/* Typographie Spécifique Tableaux */
.font-mono { 
    font-family: 'Consolas', 'Monaco', monospace; 
    font-size: 1.1rem; 
    letter-spacing: -0.5px;
}

.font-bold { font-weight: bold; }

.pilot-name { 
    font-weight: 600; 
    font-size: 1.05rem; 
    color: var(--c-primary);
    display: inline-block;
}

.rank-pos {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--c-primary);
    text-align: center;
    width: 40px;
}

/* --- LIENS PILOTES --- */
.pilot-link {
    text-decoration: none;
    color: inherit; /* Garde la couleur noire/grise du texte parent */
    cursor: pointer;
    transition: color 0.2s;
}

.pilot-link:hover {
    color: #3498db; /* Bleu au survol */
    text-decoration: underline;
}

/* Classes texte couleur */
.text-purple { color: var(--t-purple);  }
.text-green  { color: var(--t-green);  }
.text-yellow { color: var(--t-yellow); }
.text-white  { color: var(--t-grey); }

.row-top3 {
    background-color: #fff9c4 !important; /* Fond jaune très pâle */
    border-left: 4px solid #f1c40f !important; /* Bordure Or à gauche */
}

.top3-icon {
    font-size: 1.3em;
    font-weight: bold;
}

/* =========================================
   6. ANIMATIONS (LIVE)
   ========================================= */
.live-row, .rank-row {
    transition: transform 0.5s ease, background-color 0.3s;
    background: white;
    position: relative; 
    z-index: 1;
    will-change: transform;
}

.col-center {
    text-align: center;
}

/* Keyframes Flash */
@keyframes flashPurple { 0% { background-color: #e1bee7; } 100% { background-color: white; } }
@keyframes flashGreen  { 0% { background-color: #a5d6a7; } 100% { background-color: white; } }
@keyframes flashYellow { 0% { background-color: #fff59d; } 100% { background-color: white; } }
@keyframes flashWhite  { 0% { background-color: #f5f5f5; } 100% { background-color: white; } }

/* Classes Flash appliquées via JS */
.flash-purple { animation: flashPurple 2s ease-out;}
.flash-green  { animation: flashGreen 2s ease-out;}
.flash-yellow { animation: flashYellow 2s ease-out;}
.flash-white  { animation: flashWhite 2s ease-out;}

/* --- COULEURS DE TEXTE (Pour les temps) --- */
.text-purple { color:var(--t-purple); } /* Violet */
.text-green { color:var(--t-green); }  /* Vert foncé */
.text-yellow { color:var(--t-yellow); } /* Orange (pour remplacer le jaune illisible sur blanc) */
.text-white { color:var(--t-white); }  /* Par défaut (Gris foncé/Noir), car blanc sur blanc est invisible */


/* =========================================
   7. SESSION DETAILS & CHARTS
   ========================================= */
.session-anchor { scroll-margin-top: 80px; }

.session-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    border-bottom: 1px solid #eee; 
    padding-bottom: 15px; 
    margin-bottom: 15px; 
}

.session-meta strong { margin-left: 15px; color: #333; }

/* Styles Barres Graphiques */
.chart-cell { 
    display: flex; 
    align-items: center; 
    width: 100%; 
    max-width: 250px;
    height: 20px; 
    position: relative; 
    background: #f0f0f0; 
    border-radius: 4px; 
    overflow: hidden; 
}

.center-line { 
    position: absolute; 
    left: 50%; 
    width: 1px; 
    height: 100%; 
    background: #999; 
    z-index: 2; 
}

.bar { 
    height: 100%; 
    position: absolute; 
    z-index: 1; 
    transition: width 0.3s; 
}

/* Couleurs de fond (background) */
.bg-purple { background-color: var(--c-purple); }
.bg-green  { background-color: var(--c-green); }
.bg-yellow { background-color: var(--c-yellow); }
.bg-white  { background-color: var(--c-grey); }

/* Tooltip Graphique ApexCharts */
.custom-tooltip {
    padding: 8px 12px;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* =========================================
   8. RANKING (PODIUMS)
   ========================================= */
.podium-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.podium-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    overflow: hidden;
}

.podium-header {
    background: var(--c-primary);
    color: white;
    padding: 10px 15px;
    text-align: center;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 1.1rem;
}

.podium-list { list-style: none; padding: 0; margin: 0; }
.podium-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
}
.podium-item:last-child { border-bottom: none; }

.rank-badge {
    width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-weight: bold; color: white; font-size: 0.8rem; margin-right: 10px;
}
.rank-1 { background-color: var(--c-yellow); box-shadow: 0 2px 4px rgba(241, 196, 15, 0.4); }
.rank-2 { background-color: #95a5a6; }
.rank-3 { background-color: #cd7f32; }

.pilot-details { text-align: right; font-size: 0.85rem; color: #666; }

.profile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.profile-title h2 { margin: 0; font-size: 1.8rem; color: var(--c-primary); }
.profile-id { font-size: 1rem; color: #7f8c8d; font-weight: normal; background: #eee; padding: 2px 8px; border-radius: 4px; }

/* Grille de statistiques */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    text-align: center;
    border-top: 4px solid transparent; /* Bordure colorée au top */
}

.stat-card.purple { border-color: var(--c-purple); }
.stat-card.yellow { border-color: var(--c-yellow); }

.stat-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--c-dark);
    margin: 10px 0;
    font-family: 'Segoe UI', monospace;
}
.stat-label {
    text-transform: uppercase;
    color: #95a5a6;
    font-size: 0.85rem;
    letter-spacing: 1px;
    font-weight: 600;
}
.stat-icon { font-size: 1.5rem; margin-bottom: 5px; display: block; }

/* =========================================
   9. ADMIN SECTION
   ========================================= */
.admin-grid { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 20px; 
    margin-bottom: 20px; 
}

.admin-config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.admin-config-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.add-cat-form { 
    background: #f4f4f4; 
    padding: 10px; 
    border-radius: 4px; 
    display: flex; 
    gap: 10px; 
}

/* Modale */
.modal { 
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0; 
    top: 0; 
    width: 100%; 
    height: 100%; 
    background-color: rgba(0,0,0,0.5); 
}

.modal-content { 
    background-color: white; 
    margin: 10% auto; 
    padding: 25px; 
    border-radius: 8px; 
    width: 90%; 
    max-width: 450px; 
    position: relative; 
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.close { 
    position: absolute; 
    right: 15px; 
    top: 10px; 
    font-size: 24px; 
    font-weight: bold;
    cursor: pointer; 
    color: #aaa;
}
.close:hover { color: #333; }

.modal-actions { margin-top: 20px; text-align: right; }

/* =========================================
   10. GRID.JS OVERRIDES
   ========================================= */
.gridjs-container {
    font-family: inherit;
    color: inherit;
}
.gridjs-wrapper {
    border-radius: 8px;
    box-shadow: none;
    border: 1px solid #eee;
}
.gridjs-table-wrapper table {
    table-layout: auto !important;
    width: 100%; /* optionnel, pour remplir le conteneur */
}
.gridjs-th, .gridjs-td {
    width: auto !important;
}
.gridjs-th {
    background: var(--c-primary-dark) !important;
    color: #ecf0f1 !important;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 1px;
    padding: 12px 10px;
    text-align: left;
    border: none !important;
}
.gridjs-tr:hover {
    background-color: #fafafa;
}
.gridjs-td{
    border: none !important;
}
.gridjs-footer {
    background-color: #fff;
    border-top: 1px solid #eee;
}
.gridjs-pagination .gridjs-pages button {
    background-color: white;
    border: 1px solid #ddd;
    outline: none;
}
.gridjs-pagination .gridjs-pages button:hover {
    background-color: #eee;
}
.gridjs-pagination .gridjs-pages button.gridjs-currentPage {
    background-color: var(--c-primary) !important;
    color: white;
    border-color: var(--c-primary);
}
button.gridjs-sort-neutral, button.gridjs-sort-desc, button.gridjs-sort-asc {
    background-image: none!important;
}

/* 2. Style de base pour l'icône de tri (Pseudo-élément) */
button.gridjs-sort::after {
    font-family: Arial, sans-serif; /* Police standard pour symboles propres */
    font-size: 12px;
    font-weight: bold;
    content: '⇅'; /* Icône par défaut (neutre) */
    color: #ccc;  /* Gris clair par défaut */
    transition: color 0.2s ease;
}

/* 3. État : Tri Ascendant (A-Z ou Croissant) */
button.gridjs-sort.gridjs-sort-asc::after {
    content: '▲'; /* Flèche haut */
    color: var(--c-primary); /* Utilise la couleur principale du thème */
}

/* 4. État : Tri Descendant (Z-A ou Décroissant) */
button.gridjs-sort.gridjs-sort-desc::after {
    content: '▼'; /* Flèche bas */
    color: var(--c-primary);
}

/* 5. Ajustement de l'entête pour aligner le texte et la flèche */
th.gridjs-th {
    position: relative;
}
.gridjs-th-content {
    display: inline-block;
    vertical-align: middle;
}
/* =========================================
   10.VUE RACING (RCM)
   ========================================= */
#racing-view {
    display: none; /* Masqué par défaut */
    padding: 20px;
    background: white;
    text-align: center;
}