/* VARIABLES DE COULEURS (CLAIR & SOMBRE) */
:root {
    --coallia-blue: #0055a4; 
    --bg-color: #f2f2f7; 
    --card-color: #ffffff;
    --text-dark: #1c1c1e; 
    --text-gray: #8e8e93;
    --input-bg: #e5e5ea;
    --border-color: #f2f2f7;
    --footer-bg: #fafafa;
    --success: #34c759; 
    --warning: #ff9500; 
    --danger: #ff3b30;
}

body.dark-mode {
    --coallia-blue: #5fa8ff;
    --bg-color: #121212;
    --card-color: #1e1e1e;
    --text-dark: #f5f5f7;
    --text-gray: #a1a1a6;
    --input-bg: #2c2c2e;
    --border-color: #333333;
    --footer-bg: #252525;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }

body, html { margin: 0; padding: 0; font-family: 'Inter', sans-serif; background-color: var(--bg-color); color: var(--text-dark); height: 100%; overflow: hidden; transition: background 0.3s; }
.view { height: 100vh; display: flex; flex-direction: column; padding: 20px; }
.hidden { display: none !important; }

/* SCROLL */
.content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.tab-content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 180px !important; }

/* AUTH */
#login-screen { justify-content: center; align-items: center; }
.auth-card { width: 100%; max-width: 360px; background: var(--card-color); padding: 40px 25px; border-radius: 28px; box-shadow: 0 10px 30px rgba(0,0,0,0.08); text-align: center; }
.logo-container { width: 100%; margin-bottom: 20px; display: flex; justify-content: center; }
.logo-coallia { height: 55px; width: auto; object-fit: contain; }
body.dark-mode .logo-container { background: white; padding: 10px; border-radius: 12px; width: fit-content; margin: 0 auto 20px auto; }

h1 { font-size: 24px; margin: 10px 0 0 0; font-weight: 700; color: var(--coallia-blue); }
.subtitle { color: var(--text-gray); margin-bottom: 25px; font-size: 15px; }

/* INPUTS ET SELECTS */
input, select { width: 100%; border: 1px solid transparent; background: var(--input-bg); color: var(--text-dark); padding: 16px; border-radius: 14px; margin-bottom: 15px; font-size: 16px; outline: none; font-family: 'Inter', sans-serif; appearance: none; -webkit-appearance: none; }
input:focus, select:focus { background: var(--card-color); border-color: var(--coallia-blue); }
input.input-error, select.input-error, textarea.input-error { border-color: var(--danger) !important; background-color: rgba(255,59,48,0.1) !important; }
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear { display: none; }
select { background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"); background-repeat: no-repeat; background-position: right 15px center; background-size: 15px; padding-right: 40px; }

#error-bubble { background-color: var(--danger); color: white; padding: 10px 15px; border-radius: 10px; font-size: 13px; font-weight: 600; margin-bottom: 15px; opacity: 0; transform: translateY(-5px); transition: all 0.3s ease; }
#error-bubble.show { opacity: 1; transform: translateY(0); }
#btn-login { width: 100%; border: none; background: var(--coallia-blue); color: white; padding: 18px; border-radius: 14px; font-weight: 600; font-size: 16px; cursor: pointer; }

/* === NOUVEAU MENU HUB === */
.menu-grid { display: flex; flex-direction: column; gap: 20px; width: 100%; max-width: 400px; margin: 0 auto; }
.hub-btn { background: var(--card-color); border: 2px solid var(--border-color); border-radius: 24px; padding: 35px 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; cursor: pointer; box-shadow: 0 5px 20px rgba(0,0,0,0.05); transition: all 0.3s; }
.hub-btn:active { transform: scale(0.98); }
.hub-btn.disabled { opacity: 0.5; filter: grayscale(1); cursor: not-allowed; }
.hub-btn-icon { font-size: 45px; margin-bottom: 5px; }
.hub-btn-title { font-size: 18px; font-weight: 800; color: var(--text-dark); }
.hub-btn-desc { font-size: 13px; color: var(--text-gray); font-weight: 600; }

/* HEADER & TABS */
.top-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-bottom: 20px; width: 100%; }
.pro-badge { justify-self: start; background: var(--card-color); padding: 8px 16px; border-radius: 20px; font-weight: 600; font-size: 14px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); white-space: nowrap; transition: background 0.3s; }
.back-btn { justify-self: start; background: var(--card-color); color: var(--text-dark); padding: 8px 15px; border-radius: 20px; font-weight: 700; font-size: 14px; border: none; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.05); transition: background 0.3s; }

.theme-toggle-btn { justify-self: center; background: var(--card-color); border: none; font-size: 20px; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 5px rgba(0,0,0,0.05); cursor: pointer; outline: none; transition: transform 0.2s, background 0.3s; padding: 0; }
.theme-toggle-btn:active { transform: scale(0.85); }

.logout-link { justify-self: end; background: var(--card-color); color: var(--danger); padding: 8px 15px; border-radius: 20px; font-weight: 700; font-size: 14px; border: none; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.05); transition: background 0.3s; }

.tabs-nav { display: flex; background: var(--input-bg); padding: 4px; border-radius: 14px; margin-bottom: 15px; transition: background 0.3s; }
.tab-btn { flex: 1; border: none; padding: 12px; border-radius: 10px; font-weight: 600; font-size: 14px; cursor: pointer; background: none; color: var(--text-gray); }
.tab-btn.active { background: var(--card-color); color: var(--text-dark); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.scan-main-btn { width: 100%; background: var(--card-color); color: var(--coallia-blue); border: 2px solid var(--coallia-blue); padding: 16px; border-radius: 16px; font-weight: 700; font-size: 16px; margin-bottom: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: background 0.3s; }

/* PANIER & SELECTION */
.actions-header { display: flex; justify-content: flex-end; margin-bottom: 15px; }
.btn-panier { background: var(--input-bg); color: var(--text-dark); border: none; padding: 10px 15px; border-radius: 12px; font-weight: 600; font-size: 13px; cursor: pointer; transition: background 0.3s; }
.btn-panier.active, .btn-panier:active { background: var(--coallia-blue); color: white; }
.floating-bar { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--card-color); padding: 12px 18px; border-radius: 20px; box-shadow: 0 10px 40px rgba(0,0,0,0.3); display: flex; align-items: center; justify-content: space-between; gap: 10px; z-index: 1000; width: 92%; max-width: 340px; border: 1px solid var(--border-color); transition: background 0.3s; }
.floating-bar span { font-weight: 600; color: var(--coallia-blue); font-size: 15px; }
.floating-bar button { padding: 10px 20px; border-radius: 12px; font-weight: 600; font-size: 14px; border: none; cursor: pointer; }

/* ACCORDÉONS */
.section-title { font-size: 16px; color: var(--text-dark); margin: 25px 0 10px 5px; font-weight: 700; }
.accordion-header { background: var(--card-color); padding: 16px 20px; border-radius: 18px; margin-bottom: 10px; font-weight: 600; font-size: 15px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,0.03); cursor: pointer; color: var(--text-dark); transition: background 0.3s; }
.accordion-content { display: none; padding-left: 10px; border-left: 3px solid var(--coallia-blue); margin-bottom: 20px; margin-top: 10px; }
.accordion-content.open { display: block; animation: slideDown 0.2s ease; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

/* TITRE JEUNE */
.resident-title { background: var(--coallia-blue); color: white; padding: 12px 15px; border-radius: 12px; font-size: 15px; font-weight: 700; margin: 25px 0 12px 0; text-transform: uppercase; box-shadow: 0 4px 10px rgba(0,85,164,0.2); display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; }
.resident-title:first-child { margin-top: 5px; }

/* CARTES MATÉRIEL */
.items-grid { display: flex; flex-direction: column; gap: 12px; }
.item-card { background: var(--card-color); border-radius: 20px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.04); cursor: pointer; border: 2px solid transparent; transition: background 0.3s; }
.item-card.selected-panier { border-color: var(--coallia-blue); background-color: rgba(0, 85, 164, 0.1); }
.status-line { height: 6px; width: 100%; }
.card-body { padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; }
.info h3 { margin: 0 0 5px 0; font-size: 16px; color: var(--text-dark); }
.status-text { margin: 0; font-size: 13px; font-weight: 600; }
.dot-indicator { width: 12px; height: 12px; border-radius: 50%; }
.card-footer { border-top: 1px solid var(--border-color); padding: 12px 20px; font-size: 12px; background: var(--footer-bg); transition: background 0.3s; }
.row { display: flex; justify-content: space-between; margin-bottom: 4px; color: var(--text-gray); }
.row b { color: var(--text-dark); }

.available .status-line, .available .dot-indicator { background: var(--success); }
.available .status-text { color: var(--success); }
.borrowed .status-line, .borrowed .dot-indicator { background: var(--warning); }
.borrowed .status-text { color: var(--warning); }
.overdue .status-line, .overdue .dot-indicator { background: var(--danger); }
.overdue .status-text, .overdue .info h3 { color: var(--danger); }
.generic .status-line, .generic .dot-indicator { background: var(--coallia-blue); }
.generic .status-text { color: var(--coallia-blue); }

/* CONTROLES QUANTITÉ */
.qty-controls { display: flex; align-items: center; gap: 12px; background: var(--card-color); padding: 4px; border-radius: 12px; border: 1px solid var(--border-color); transition: background 0.3s; }
.qty-btn { background: var(--bg-color); color: var(--text-dark); border: none; width: 32px; height: 32px; border-radius: 8px; font-weight: bold; font-size: 18px; cursor: pointer; transition: background 0.3s; }
.qty-controls span { font-weight: 700; font-size: 15px; width: 20px; text-align: center; }
.qty-controls-large { display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 10px; }
.qty-btn-large { background: var(--input-bg); color: var(--text-dark); border: none; width: 45px; height: 45px; border-radius: 12px; font-weight: bold; font-size: 24px; cursor: pointer; transition: background 0.3s; }
#modal-qty-display { font-weight: 700; font-size: 22px; width: 30px; text-align: center; }

/* === STYLES FORMULAIRE MÉDICAMENTS === */
.med-form-card { background: var(--card-color); padding: 25px 20px; border-radius: 20px; box-shadow: 0 4px 15px rgba(0,0,0,0.04); transition: background 0.3s; overflow-y: auto; }
.form-label { display: block; font-size: 13px; font-weight: 700; color: var(--text-gray); margin-bottom: 8px; margin-left: 5px; text-transform: uppercase; }

/* BADGE HORLOGE EN DIRECT */
.clock-badge {
    display: inline-block;
    background: var(--card-color);
    color: var(--coallia-blue);
    padding: 8px 18px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 16px;
    letter-spacing: 1px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    transition: background 0.3s;
}

/* MODALS */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); display: flex; justify-content: center; align-items: center; z-index: 2000; padding: 20px; transition: background 0.3s; }
.modal-card { background: var(--card-color); color: var(--text-dark); width: 100%; max-width: 320px; padding: 30px 20px; border-radius: 28px; text-align: center; animation: slideUp 0.3s ease-out; transition: background 0.3s; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-card h3 { margin: 0 0 8px 0; font-size: 20px; }
.modal-subtitle { color: var(--text-gray); margin-bottom: 20px; font-size: 14px; }
.error-text { color: var(--danger); font-size: 12px; margin-top: 5px; text-align: left; padding-left: 5px; }
.modal-buttons { display: flex; gap: 12px; margin-top: 25px; }
.modal-buttons button { flex: 1; padding: 15px; border-radius: 14px; font-weight: 600; border: none; cursor: pointer; font-size: 15px; transition: background 0.3s; }
.btn-primary { 
    background: var(--coallia-blue); 
    color: white; 
    border: none; 
    border-radius: 14px; 
    font-weight: 600; 
    cursor: pointer; 
}
.btn-secondary { 
    background: var(--input-bg); 
    color: var(--text-dark); 
    border: none; 
    border-radius: 14px; 
    font-weight: 600; 
    cursor: pointer; 
}
.btn-danger { background: var(--danger); color: white; }

.shake { animation: shake 0.4s ease-in-out; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }

/* MENTION LÉGALE LOGIN */
.copyright-text {font-size: 11px;color: var(--text-gray);margin-top: 20px;margin-bottom: 0;font-weight: 500;line-height: 1.4;}

/* Animation de pulsation pour la synchro */
.pulse-orange {
    animation: pulseSync 1.5s infinite;
}

@keyframes pulseSync {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
    100% { opacity: 1; transform: scale(1); }
}

/* ========================================== */
/* ANIMATION PLUIE DE COEURS (EASTER EGG) */
/* ========================================== */
.coeur-tombant {
    position: fixed;
    top: -10%;
    z-index: 9999;
    pointer-events: none; /* Pour ne pas gêner les clics */
    animation: fall linear forwards;
    user-select: none;
}

@keyframes fall {
    to {
        transform: translateY(110vh) rotate(360deg);
    }
}

/* === STYLE TIMELINE TRANSMISSION === */
.timeline {
    position: relative;
    padding-left: 20px;
    margin-top: 10px;
    padding-bottom: 50px;
}

/* La ligne verticale */
.timeline::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}

.timeline-item {
    position: relative;
    margin-bottom: 25px;
    animation: slideUp 0.3s ease-out;
}

/* Le point sur la ligne */
.timeline-dot {
    position: absolute;
    left: -19px;
    top: 15px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--coallia-blue);
    border: 3px solid var(--card-color);
    box-shadow: 0 0 0 1px var(--border-color);
}

/* La bulle de contenu */
.timeline-content {
    background: var(--card-color);
    border-radius: 18px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.03);
    border: 1px solid var(--border-color);
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.timeline-time {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-gray);
}

.timeline-tag {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.timeline-desc {
    font-size: 15px;
    color: var(--text-dark);
    line-height: 1.5;
    white-space: pre-wrap; /* Garde les retours à la ligne */
}

.timeline-author {
    font-size: 11px;
    color: var(--text-gray);
    margin-top: 8px;
    font-style: italic;
    text-align: right;
}

/* COULEURS DES TAGS */
.tag-info { background: #e5f1ff; color: #0055a4; }
.tag-passage { background: #e0f8e0; color: #2e7d32; }
.tag-tel { background: #f3e5f5; color: #7b1fa2; }
.tag-consommation { background: #fff3e0; color: #ef6c00; }
.tag-nuisance { background: #fff8e1; color: #fbc02d; }
.tag-incident { background: #ffebee; color: #c62828; }
.tag-intrusion { background: #37474f; color: #eceff1; }
.tag-urgence { background: #d32f2f; color: white; animation: pulseRed 2s infinite; }

@keyframes pulseRed { 0% { box-shadow: 0 0 0 0 rgba(211, 47, 47, 0.4); } 70% { box-shadow: 0 0 0 10px rgba(211, 47, 47, 0); } 100% { box-shadow: 0 0 0 0 rgba(211, 47, 47, 0); } }

/* ========================================== */
/* ADAPTATION ORDINATEUR (RESPONSIVE CLASSIQUE) */
/* ========================================== */
@media screen and (min-width: 768px) {
    /* 1. On libère l'espace pour scroller naturellement */
    body, html { 
        height: auto; 
        overflow: auto; 
    }
    .view { 
        height: auto; 
        min-height: 100vh; 
        padding: 40px; 
    }
    .content { 
        overflow: visible; 
    }

    /* 2. Le Menu Principal s'aligne à l'horizontale */
    .menu-grid {
        flex-direction: row;
        max-width: 1000px;
        gap: 30px;
    }
    .hub-btn {
        flex: 1;
        padding: 50px 20px;
    }

    /* 3. Le matériel s'affiche en grille type Dashboard */
    .items-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: 20px;
        align-items: start;
    }

    /* 4. Les formulaires (Médicaments et Transmissions) sont centrés */
    .med-form-card {
        max-width: 600px;
        margin: 0 auto 30px auto;
        padding: 40px; 
        overflow: visible;
    }

    /* 5. La Timeline est centrée et bien large pour le confort de lecture */
    .timeline {
        max-width: 700px;
        margin: 0 auto;
        padding-bottom: 60px;
    }

    /* 6. L'écran de connexion est centré élégamment */
    .auth-card {
        max-width: 450px;
        padding: 50px 40px;
        margin: 10vh auto; 
    }
    
    /* 7. Les boutons "Voir la Timeline" et "Copier" s'alignent avec le formulaire */
    #trans-app .content > div:first-of-type {
        max-width: 600px;
        margin: 0 auto 20px auto;
    }

    /* 8. Le bouton "Traçabilité" des médicaments prend la même largeur que le formulaire */
    #med-app .content > button,
    #med-app .content > div:not(.med-form-card) {
        max-width: 600px;
        width: 100%;
        margin: 0 auto;
        display: block;
    }
}

/* ========================================== */
/* SPLASH SCREEN (ÉCRAN DE DÉMARRAGE ÉLÉGANT) */
/* ========================================== */
#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color); /* S'adapte tout seul au mode sombre/clair */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.8s ease, visibility 0.8s;
}

.splash-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: fadeInSplash 1s ease-out;
}

.splash-logo {
    height: 100px; /* Un peu plus grand pour mieux occuper l'espace */
    width: auto;
    margin-bottom: 25px;
    animation: breathe 2.5s infinite ease-in-out; /* L'effet de respiration */
}

.splash-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-gray);
    letter-spacing: 4px; /* Espace élégant entre les lettres */
    opacity: 0.7;
}

/* L'animation de respiration (Zoom doux + Ombre subtile) */
@keyframes breathe {
    0% { transform: scale(0.95); filter: drop-shadow(0 0 0 rgba(0,85,164,0)); }
    50% { transform: scale(1.02); filter: drop-shadow(0 10px 20px rgba(0,85,164,0.15)); }
    100% { transform: scale(0.95); filter: drop-shadow(0 0 0 rgba(0,85,164,0)); }
}

@keyframes fadeInSplash { from { opacity: 0; } to { opacity: 1; } }

#splash-screen.hidden-splash {
    opacity: 0;
    visibility: hidden;
}