/* ============================================================================
 *  ██╗   ██╗██╗████████╗██╗███╗   ██╗██╗
 *  ██║   ██║██║╚══██╔══╝██║████╗  ██║██║
 *  ██║   ██║██║   ██║   ██║██╔██╗ ██║██║
 *  ╚██╗ ██╔╝██║   ██║   ██║██║╚██╗██║██║
 *   ╚████╔╝ ██║   ██║   ██║██║ ╚████║██║
 *    ╚═══╝  ╚═╝   ╚═╝   ╚═╝╚═╝  ╚═══╝╚═╝
 *
 *  Fichier  : style.css
 *  Module   : Design System — Global
 *  Rôle     : Feuille de style unique et partagée par toutes les pages de
 *             l'application (Dashboard, Viticulture, Viniculture, Historique…).
 *             Définit la palette, la typographie, les composants réutilisables
 *             et les utilitaires de mise en page.
 *  Auteur   : Thomas — Profil E1
 * ============================================================================ */


/* ============================================================================
 * §1 — VARIABLES GLOBALES (Design Tokens)
 * ============================================================================
 * Toutes les valeurs de couleur, d'ombre et de rayon sont centralisées ici.
 * Modifier une variable répercute le changement sur l'intégralité de l'UI.
 * ============================================================================ */
:root {
    /* ── Couleurs de marque ──────────────────────────────────────────────── */
    --bordeaux:        #712444; /* Couleur principale — identité viticole */
    --bordeaux-hover:  #5a1c36;
    --bordeaux-light:  #f4e8ec; /* Fond teinté pour les zones caves */

    --green:           #49684D; /* Couleur secondaire — identité viticole */
    --green-hover:     #3a533d;
    --green-light:     #eaf1eb; /* Fond teinté pour les zones vignes */

    /* ── Couleurs de surface et de texte ─────────────────────────────────── */
    --bg-body:         #f4f6f8; /* Fond général de l'application */
    --bg-card:         #ffffff; /* Fond des cartes et composants */
    --text-main:       #2c3e50; /* Texte principal */
    --text-muted:      #7f8c8d; /* Texte secondaire, libellés, sous-titres */
    --border-color:    #e2e8f0; /* Bordures des tableaux, cartes, inputs */

    /* ── Couleurs de statut (alertes, badges) ────────────────────────────── */
    --danger:          #e74c3c;
    --danger-bg:       #fdeaea;
    --warning:         #f39c12;
    --warning-bg:      #fef5e7;
    --success:         #2ecc71;
    --success-bg:      #eafaf1;
    --info:            #3498db;
    --info-bg:         #ebf5fb;

    /* ── Ombres portées ──────────────────────────────────────────────────── */
    --shadow-sm:       0 2px 4px rgba(0,0,0,0.05);  /* Navbar, éléments légers */
    --shadow-md:       0 4px 12px rgba(0,0,0,0.08); /* Cartes principales */

    /* ── Rayons d'arrondi ────────────────────────────────────────────────── */
    --radius-md:       8px;  /* Inputs, badges, boutons */
    --radius-lg:       12px; /* Cartes, modals, blocs */
}


/* ============================================================================
 * §2 — RESET ET BASE TYPOGRAPHIQUE
 * ============================================================================
 * Reset minimal : on normalise les marges/paddings et on force le modèle
 * `border-box` pour que les dimensions CSS correspondent à la réalité visuelle.
 * ============================================================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
}

a {
    text-decoration: none;
    color: inherit;
}


/* ============================================================================
 * §3 — NAVIGATION SUPÉRIEURE (Navbar)
 * ============================================================================
 * La navbar est fixée en haut de page (`sticky`) pour rester accessible lors
 * du défilement. Le `z-index: 100` la maintient au-dessus des modals et cartes.
 * ============================================================================ */
.navbar {
    background-color: var(--bg-card);
    padding: 0 24px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

/* ── Logo et nom du domaine ── */
.nav-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-brand .logo-icon {
    background-color: var(--bordeaux);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.nav-brand h2 {
    font-size: 20px;
    color: var(--bordeaux);
    margin: 0;
    line-height: 1.2;
}

.nav-brand span {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: normal;
}

/* ── Liens de navigation ── */
.nav-links {
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav-item {
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
    transition: all 0.2s;
}

.nav-item:hover {
    background-color: var(--bg-body);
}

/* L'élément actif reçoit la couleur bordeaux pour indiquer la page courante. */
.nav-item.active {
    background-color: var(--bordeaux);
    color: white;
}

/* Bouton de déconnexion : coloré en rouge pour signaler une action destructrice. */
.nav-logout {
    color: var(--danger);
    margin-left: 16px;
}


/* ============================================================================
 * §4 — LAYOUT ET CONTENEUR PRINCIPAL
 * ============================================================================
 * La largeur max de 1400px préserve la lisibilité sur les très grands écrans.
 * `.page-header` est conservé pour compatibilité bien que retiré des vues
 * principales suite à la refactorisation de l'IHM.
 * ============================================================================ */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px 24px;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    margin-bottom: 4px;
}

.page-header p {
    color: var(--text-muted);
    font-size: 14px;
}

/* ── Grilles responsives (auto-fit) ─────────────────────────────────────────
 * - `grid-4` : 4 colonnes pour les KPI admins, se replie sur 2 ou 1 en mobile.
 * - `grid-3` : 3 colonnes standard pour les cartes de résumé.
 * - `grid-2` : 2 colonnes pour les layouts Viticulture / Viniculture côte à côte.
 * ─────────────────────────────────────────────────────────────────────────── */
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 20px; margin-bottom: 24px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(500px, 1fr)); gap: 20px; margin-bottom: 24px; }


/* ============================================================================
 * §5 — CARTES (Cards)
 * ============================================================================ */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 24px;
    border: 1px solid rgba(0,0,0,0.02);
}

/* ── Cartes de statistiques KPI ──────────────────────────────────────────── */
.stat-card {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.stat-info h3 {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 8px;
}

.stat-info .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 8px;
}

/* Icône colorée en forme de cercle, placée à droite de la valeur. */
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.stat-icon.green   { background-color: var(--green-light);    color: var(--green); }
.stat-icon.bordeaux { background-color: var(--bordeaux-light); color: var(--bordeaux); }
.stat-icon.gray    { background-color: var(--bg-body);         color: var(--text-muted); }

/* ── En-têtes de zone colorés (intégrés dans les cartes) ─────────────────── */
.zone-header {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 16px 24px;
    color: white;
    margin: -24px -24px 24px -24px; /* Étend le header jusqu'aux bords de la carte parente. */
}
.zone-header.viticulture { background-color: var(--green); }
.zone-header.viniculture { background-color: var(--bordeaux); }


/* ============================================================================
 * §6 — BADGES (Pilules d'état)
 * ============================================================================
 * Les badges indiquent le statut d'une entité (capteur, alerte, utilisateur).
 * Chaque variante a sa propre couleur sémantique cohérente avec les variables.
 * ============================================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success { background-color: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.badge-warning { background-color: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning); }
.badge-danger  { background-color: var(--danger-bg);  color: var(--danger);  border: 1px solid var(--danger);  }
.badge-info    { background-color: var(--info-bg);    color: var(--info);    border: 1px solid var(--info);    }
.badge-outline { background-color: transparent; border: 1px solid var(--border-color); color: var(--text-muted); }


/* ============================================================================
 * §7 — TABLEAUX DE DONNÉES
 * ============================================================================
 * Le `overflow-x: auto` sur `.table-container` assure le défilement horizontal
 * sur mobile sans casser la mise en page des lignes.
 * ============================================================================ */
.table-container {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    padding: 16px;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

td {
    padding: 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

/* Supprime la ligne sous la dernière ligne pour éviter le double-bord avec la carte. */
tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: rgba(0,0,0,0.01);
}


/* ============================================================================
 * §8 — BARRES DE PROGRESSION (Cuves de vinification)
 * ============================================================================
 * Utilisées dans la vue Viniculture pour visualiser le niveau de remplissage
 * et la progression de la fermentation alcoolique de chaque cuve.
 * ============================================================================ */
.progress-container {
    margin: 12px 0;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.progress-track {
    width: 100%;
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: var(--text-main);
    border-radius: 4px;
    transition: width 0.5s ease;
}


/* ============================================================================
 * §9 — BOUTONS ET FORMULAIRES
 * ============================================================================ */

/* ── Boutons ── */
.btn {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary  { background-color: var(--green);    color: white; }
.btn-primary:hover { background-color: var(--green-hover); }

.btn-bordeaux { background-color: var(--bordeaux); color: white; }

.btn-outline  { background-color: transparent; border: 1px solid var(--border-color); color: var(--text-main); }
.btn-outline:hover { background-color: var(--bg-body); }

/* ── Champs de formulaire ── */
input[type="text"],
input[type="email"],
select {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-main);
    width: 100%;
    outline: none;
}

/* Focus visible : la bordure bordeaux guide l'utilisateur vers le champ actif. */
input:focus,
select:focus {
    border-color: var(--bordeaux);
} /* <-- VOICI L'ACCOLADE MANQUANTE */

/* ============================================================================
 * AJOUTS RESPONSIVE (Mobiles & Tablettes)
 * ============================================================================ */

/* Cacher le bouton hamburger sur grand écran */
.hamburger {
    display: none;
    font-size: 24px;
    color: var(--bordeaux);
    cursor: pointer;
}

@media (max-width: 768px) {
    /* ── Navigation Mobile ── */
    .navbar {
        flex-direction: column;
        height: auto;
        padding: 15px 24px;
    }
    
    .nav-brand {
        width: 100%;
        justify-content: space-between; /* Espace entre le logo et le hamburger */
    }

    .hamburger {
        display: block; /* Afficher le menu burger */
    }

    .nav-links {
        display: none; /* Cacher les liens par défaut sur mobile */
        flex-direction: column;
        width: 100%;
        gap: 0;
        margin-top: 15px;
    }

    .nav-links.active {
        display: flex; /* Afficher quand le bouton burger est cliqué */
    }

    .nav-item {
        padding: 12px;
        width: 100%;
        justify-content: flex-start;
        border-radius: 0;
        border-bottom: 1px solid var(--border-color);
    }
    
    .nav-item:last-child {
        border-bottom: none;
    }

    .nav-logout {
        margin-left: 0;
        color: white;
        background-color: var(--danger);
        justify-content: center;
        border-radius: var(--radius-md);
        margin-top: 10px;
    }

    /* ── Ajustement du contenu ── */
    .main-content {
        padding: 20px 15px;
    }

    /* ── Forcer les grilles sur 1 colonne sur petits écrans ── */
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }

    /* ── Modals ── */
    .modal-container {
        padding: 20px;
        width: 95%;
    }
    .form-grid-2x2, .form-row {
        grid-template-columns: 1fr;
        flex-direction: column;
        gap: 10px;
    }
}