/* ==========================================================================
   FICHIER CSS CENTRALISÉ COMPLET — INTERFACES PREMIUM INTRANET
   Ferme Fernand Lachance et fils (2026)
   ========================================================================== */

/* --- THÈME ET VARIABLES ADAPTATIVES LIGHT/DARK iOS --- */
:root {
    --bg-color: #f2f2f7;
    --card-bg: #ffffff;
    --text-primary: #1c1c1e;
    --text-secondary: #8e8e93;
    --accent-color: #007aff;
    --danger-color: #ff3b30;
    --input-bg: #f2f2f7;
    --input-border: #d1d1d6;
    --border-color: #c6c6c8;
    --row-alt: #f9f9f9;
    --row-sel: #e5f1ff;
    --shadow: rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #000000;
        --card-bg: #1c1c1e;
        --text-primary: #ffffff;
                --text-secondary: #8e8e93;
        --accent-color: #0a84ff;
        --danger-color: #ff453a;
        --input-bg: #2c2c2e;
        --input-border: #3a3a3c;
        --border-color: #3a3a3c;
        --row-alt: #222224;
        --row-sel: #1a3a5f;
        --shadow: rgba(0, 0, 0, 0.4);
    }
}

/* --- RE-NIVELLAGE COMPLET DES BASES --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100vh;
    height: 100svh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden; /* Verrouille l'écran principal de l'iPhone */
}

.container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.container > form {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
    width: 100%;
    min-height: 0;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    
    /* 1. Sécurité fixe pour Chrome WebApp : 46px (nav) + 34px (encoche) + 12px (confort) = 92px */
    padding-bottom: 92px; 
    
    /* 2. Prise en compte si les variables d'environnement WebKit s'activent */
    padding-bottom: calc(46px + env(safe-area-inset-bottom, 34px) + 12px); 
    
    box-sizing: border-box;
}
main > div[id^="tab-content-"] {
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* --- UTILS & INFRASTRUCTURE --- */
.hidden { 
    display: none !important; 
}

/* --- ANIMATION DE CLIGNOTEMENT ALERTE DE RETARD --- */
@keyframes ios-pulse-alert {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.95); }
    100% { opacity: 1; transform: scale(1); }
}

.badge-overdue {
    background-color: #ff3b30 !important;
    color: #ffffff !important;
    animation: ios-pulse-alert 1.6s infinite ease-in-out !important;
    box-shadow: 0 0 10px rgba(255, 59, 48, 0.45) !important;
    font-weight: 700 !important;
}

/* --- BOUTON RETOUR APPLICATION SUPERIEUR --- */
.top-navbar {
    background-color: var(--card-bg);
    padding: 12px 16px 4px 16px;
    display: flex;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    flex: 0 0 auto;
}
.top-navbar a {
    color: var(--accent-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* --- EN-TÊTE FORMULAIRE FIXE (DESIGN BLOC iOS) --- */
.form-header {
    background-color: var(--card-bg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 0 0 auto;
    border-bottom: 0.5px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0,0,0,0.02);
    position: sticky;
    top: 0;
    z-index: 20;
}

@media (min-width: 600px) {
    .form-header {
        flex-direction: row;
        align-items: flex-end;
    }
    .form-group {
        flex: 1;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding-left: 2px;
}

.form-header input[type="text"], 
.form-header input[type="number"], 
.form-header select {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    background-color: var(--input-bg);
    border: 0.5px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.form-header input[type="text"]:focus,
.form-header input[type="number"]:focus,
.form-header select:focus {
    border-color: var(--accent-color);
}

/* --- BOUTONS TACTILES COMPACTS iOS --- */
.btn-action {
    width: 100%;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 38px;
    -webkit-appearance: none;
    appearance: none;
}
.btn-add { background-color: var(--accent-color); color: #ffffff; }
.btn-update { background-color: #34c759; color: #ffffff; }
.btn-action:active { opacity: 0.8; }

/* --- ALIGNEMENT DES BOUTONS CÔTE À CÔTE --- */
.buttons-row {
    display: flex;
    gap: 8px;
    width: 100%;
}

.buttons-row .btn-action,
.buttons-row button,
.buttons-row input[type="button"] {
    flex: 1;
}

@media (min-width: 600px) {
    .form-header .buttons-row {
        display: inline-flex !important;
        align-items: center !important;
        width: auto !important;
        max-width: 280px !important;  
        margin-left: auto !important; 
    }
    
    .form-header .buttons-row .btn-action,
    .form-header .buttons-row button,
    .form-header .buttons-row input[type="button"] {
        width: 120px !important;       
        flex: 0 0 120px !important;    
        height: 38px !important;       
        margin: 0 !important;
    }
}

/* --- CONTENEUR DE TABLEAUX SECONDAIRES --- */
.list-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom);
}

.list-table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--card-bg);
}

.list-table tr {
    border-bottom: 0.5px solid var(--border-color);
    transition: background-color 0.2s ease;
}

.list-table td {
    padding: 14px 12px;
    font-size: 15px;
    vertical-align: middle;
}

.list-table .cell-icon {
    width: 44px;
    text-align: center;
    padding: 0 4px;
}

.list-table .cell-type {
    color: var(--text-secondary);
    font-size: 14px;
    text-align: right;
    padding-right: 16px;
}

/* --- STYLE DES ICÔNES SVG --- */
.action-svg {
    width: 22px;
    height: 22px;
    cursor: pointer;
    display: inline-block;
    vertical-align: middle;
    transition: transform 0.1s ease;
}
.action-svg:active { transform: scale(0.9); }
.icon-edit { fill: var(--accent-color); }
.icon-delete { fill: var(--danger-color); }
.icon-disabled { fill: var(--text-secondary); opacity: 0.3; cursor: not-allowed; }

.list-table .fmline { background-color: var(--card-bg); }
.list-table .fmlineb { background-color: var(--row-alt); }
.list-table .fmlinesel { background-color: var(--row-sel) !important; }
.list-table tr:hover:not(.fmlinesel) { background-color: var(--input-bg); }

/* --- FENÊTRES MODALES PLEIN ÉCRAN iOS --- */
.modal-fullscreen {
    position: fixed;
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0;
    height: 100svh !important; /* Force la hauteur stricte de l'écran Chrome, sans les barres d'outils */
    background: rgba(0, 0, 0, 0.5);
    z-index: 2147483647 !important; 
    display: flex; 
    align-items: flex-end;
    
    /* Empêche le rebond élastique de Chrome iOS au retour de l'application */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    
    -webkit-transform: translate3d(0, 0, 10px) !important;
    transform: translate3d(0, 0, 10px) !important;
}



/* Ajustement de la hauteur interne sur iPhone en mode application pour ne pas couper le bouton Enregistrer */
.modal-inner {
    background: var(--card-bg);
    width: 100%;
    height: 85svh; /* Utilisation de la hauteur de viewport dynamique iOS */
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 0.5px solid var(--border-color);
    background: var(--card-bg);
    flex: 0 0 auto;
}

/* --- LIBÈRE LE SCROLL NATUREL DES SOUS-PAGES D'ADMINISTRATION --- */
body:not(:has(#tab-content-machines)) {
    overflow-y: auto !important;
}
body:not(:has(#tab-content-machines)) .container {
    height: auto !important;
    min-height: 100%;
}

/* ==========================================================================
   STYLES COMPLÉMENTAIRES EXCLUSIFS POUR LA PAGE LOGIN.ASP
   ========================================================================== */
.main-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.login-box {
    background-color: var(--card-bg);
    border-radius: 16px;
    padding: 28px 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 32px var(--shadow);
    border: 0.5px solid var(--input-border);
}

.brand {
    text-align: center;
    margin-bottom: 24px;
}
.brand-logo {
    font-size: 32px;
    margin-bottom: 6px;
    display: block;
}
.brand h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
}
.form-group-login {
    position: relative;
    margin-bottom: 14px;
}

.form-group-login svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    fill: var(--text-secondary);
    z-index: 5;
}

.form-group-login input {
    width: 100%;
    padding: 14px 12px 14px 40px;
    font-size: 16px; 
    background-color: var(--input-bg);
    border: 0.5px solid var(--input-border);
    border-radius: 10px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s ease, background-color 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.form-group-login input:focus {
    border-color: var(--accent-color);
    background-color: var(--card-bg);
}

.error-message-login {
    background-color: #ffe2e2;
    color: #ff3b30;
    padding: 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 18px;
    border: 0.5px solid rgba(255, 59, 48, 0.2);
}

@media (prefers-color-scheme: dark) {
    .error-message-login {
        background-color: #2c1212;
        color: #ff453a;
        border-color: rgba(255, 69, 58, 0.2);
    }
}

.footer-login {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    font-weight: 500;
    padding-top: 20px;
}

/* ==========================================================================
   MODULE COMPLÉMENTAIRE : CARTOGRAPHIE LEAFLET & LEAFLET.DRAW
   ========================================================================== */

/* --- LE CONTENEUR DE LA CARTE --- */
.map-container {
    width: 100%;
    flex: 1;                /* Remplit tout l'espace vertical restant sous le header */
    min-height: 0;          /* Empêche le conteneur de casser la structure Flexbox */
    position: relative;
    border-radius: 12px;    /* S'aligne avec le look arrondi iOS de vos boutons/inputs */
    overflow: hidden;       /* Force la carte à respecter les coins arrondis */
    box-shadow: 0 4px 16px var(--shadow);
    border: 0.5px solid var(--border-color);
}

/* --- AJUSTEMENT DES OUTILS DE DESSIN POUR LE TACTILE iOS --- */
.leaflet-touch .leaflet-draw-actions {
    left: 44px !important;  /* Décale les boutons "Sauvegarder/Annuler" pour éviter les chevauchements */
}

.leaflet-touch .leaflet-bar a {
    width: 44px !important;  /* Taille minimale recommandée par Apple pour les cibles tactiles */
    height: 44px !important;
    line-height: 44px !important;
    background-color: var(--card-bg) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* --- ADAPTATION DE LA CARTE AU MODE SOMBRE --- */
@media (prefers-color-scheme: dark) {
    /* Inverse les couleurs des tuiles de la carte standard pour ne pas aveugler la nuit */
    /* Note: Ne pas appliquer si vous utilisez exclusivement une couche Satellite */
    .leaflet-tile-container {
        filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
    }
    /* Garde les outils de dessin et contrôles lisibles en mode sombre */
    .leaflet-control {
        filter: invert(0) !important;
    }
    .leaflet-bar a {
        background-color: #2c2c2e !important;
        border-bottom: 0.5px solid #3a3a3c !important;
    }
}

/* --- POPUPS ET BULLES D'INFO STYLE APPLE --- */
.leaflet-popup-content-wrapper {
    background-color: var(--card-bg) !important;
    color: var(--text-primary) !important;
    border-radius: 12px !important;
    padding: 6px !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    box-shadow: 0 8px 24px var(--shadow) !important;
}

.leaflet-popup-tip {
    background-color: var(--card-bg) !important;
}

/* --- ADAPTATION DE LA MODALE BOTTOM-SHEET POUR LA CARTE --- */
/* Si vous mettez la carte dans votre fenêtre modale (.modal-inner) */
.modal-inner .map-container {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
}
/* ==========================================================================
   STRUCTURE ET COMPOSANTS DE L'ONGLET 4 (MENU)
   ========================================================================== */

/* Titres des sections du menu */
.menu-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    padding-left: 4px;
}

/* Titre principal Option & Administration */
.menu-header-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    padding-left: 4px;
}

/* Blocs conteneurs de listes de liens */
.menu-card-group {
    background: var(--card-bg);
    border-radius: 12px;
    border: 0.5px solid var(--border-color);
    overflow: hidden;
    box-shadow: 0 1px 3px var(--shadow);
    display: flex;
    flex-direction: column;
    margin-bottom: 16px;
}

/* Liens génériques du menu */
.menu-link-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 15px;
    font-weight: 600;
    transition: background-color 0.15s;
}

.menu-link-row:active {
    background-color: var(--row-sel) !important;
}

/* Variations de fonds pour les boutons d'action du haut */
.menu-link-dashboard { background-color: rgba(0, 122, 255, 0.02); color: var(--accent-color); border-bottom: 0.5px solid var(--border-color); }
.menu-link-danger    { background-color: rgba(255, 59, 48, 0.02); color: var(--danger-color); }
.menu-link-folder    { background: var(--input-bg); }

/* Sous-menus extensibles (Dossiers) */
.menu-folder-content {
    display: flex;
    flex-direction: column;
    background: rgba(0,0,0,0.01);
}

/* Liens à l'intérieur des dossiers extensibles */
.menu-sublink-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px 14px 44px;
    color: var(--text-primary);
    text-decoration: none;
    border-top: 0.5px solid var(--border-color);
    font-size: 14px;
    font-weight: 500;
}

.menu-sublink-danger {
    color: var(--danger-color);
    font-weight: 600;
    background-color: rgba(255, 59, 48, 0.01);
}

/* Zone d'icône carrée iOS */
.menu-icon-square {
    color: #ffffff;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 14px;
}

/* Flèches de navigation de droite */
.menu-arrow-indicator {
    color: var(--accent-color);
    opacity: 0.4;
    font-weight: 700;
    font-size: 14px;
}

.menu-arrow-secondary {
    color: var(--border-color);
    font-size: 13px;
    opacity: 1;
}

.menu-arrow-toggle {
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 14px;
    transition: transform 0.2s;
}

/* Pied de page du menu (Session & Déconnexion) */
.menu-footer-container {
    margin-top: 24px;
    text-align: center;
    padding: 0 4px;
}

.menu-session-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 500;
}

.menu-btn-logout {
    width: 100%;
    background: #dc3545;
    color: #ffffff;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(220,53,69,0.15);
    transition: opacity 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.menu-btn-logout:active {
    opacity: 0.8;
}

.ios-settings-title {
    font-size: 26px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    padding: 12px 4px 16px 4px;
}

.ios-section-label {
    font-size: 12px;
    font-weight: 600;
    color: #8e8e93;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 6px;
    padding-left: 14px;
}

.ios-list-group {
    background: var(--card-bg);
    border-radius: 12px;
    border: 0.5px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
}

.ios-row-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    box-sizing: border-box;
    position: relative;
}

.ios-row-item:not(:last-child)::after {
    content: "";
    position: absolute;
    bottom: 0;
    right: 0;
    left: 54px; /* Aligne le séparateur parfaitement après l'icône */
    height: 0.5px;
    background-color: var(--border-color);
}

.ios-row-item:active {
    background-color: var(--row-sel);
}

.ios-icon-box {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    color: #ffffff;
}

.ios-chevron {
    color: #c4c4c6;
    font-size: 13px;
    font-weight: 600;
    padding-left: 8px;
}

/* Badge de notification discret style iOS */
.ios-badge-count {
    background-color: #ff3b30;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: auto;
}
/* ==========================================================================
   EXTENSION ACCORDÉONS : CONFIGURATION GMAO & REGISTRE AGRICOLE
   ========================================================================== */

/* Conteneur pour masquer/afficher les sous-menus */
.ios-submenu {
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color); /* Effet de profondeur sous la ligne */
    overflow: hidden;
}

/* Classe d'état pour masquer le menu */
.hidden-submenu {
    display: none !important;
}

/* Indentation des sous-items pour marquer la hiérarchie */
.ios-submenu .submenu-item {
    padding-left: 24px;
}

/* Masque la ligne de séparation pour le dernier élément du sous-menu */
.ios-submenu .submenu-item:last-child::after {
    display: none;
}

/* Chevron d'en-tête rotatif */
.ios-chevron-toggle {
    color: #c4c4c6;
    font-size: 13px;
    font-weight: 600;
    padding-left: 8px;
    transition: transform 0.2s ease;
    display: inline-block;
}

/* Rotation du chevron vers le bas à l'ouverture */
.ios-chevron-toggle.rotated {
    transform: rotate(90deg);
}
