/* ==========================================================================
   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;
}

/* --- L'ÉLÉMENT CHARNIÈRE DE CONTENU (FIXE LE NAV EN BAS) --- */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px 20px 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;
    background: rgba(0, 0, 0, 0.4);
    z-index: 100;
    display: flex; 
    align-items: flex-end;
}

.modal-inner {
    background: var(--card-bg);
    width: 100%;
    height: 85%;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom);
}

.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;
}
