/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    --bg: #121212;
    --card-bg: #1e1e1e;
    --text: #ffffff;
    --text-sec: #aaaaaa;
    --accent: #3498db;
    --danger: #e74c3c;
    --warning: #f39c12;
    --success: #27ae60;
    --border: #333;
    --nav-height: 60px;
    --radius: 12px;
    --radius-sm: 6px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    /* Marge augmentée pour compenser la hauteur du menu + les 5% de bas */
    padding-bottom: calc(var(--nav-height) + 60px); 
}

/* Utilitaires de texte */
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-accent { color: var(--accent); }
.hidden { display: none !important; }

/* =========================================
   2. AUTHENTIFICATION & RÉCUPÉRATION
   ========================================= */
#authScreen, #recoverScreen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 400;
}

.auth-box {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--radius);
    width: 90%;
    max-width: 350px;
    text-align: center;
    border: 1px solid var(--border);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

.auth-box h1, .auth-box h2 {
    margin-bottom: 1.5rem;
    color: var(--text);
}

.auth-box input {
    width: 100%;
    padding: 12px;
    margin: 8px 0;
    border-radius: var(--radius-sm);
    border: 1px solid #444;
    background: #333;
    color: white;
    font-size: 1rem;
}

.auth-box input:focus {
    outline: none;
    border-color: var(--accent);
}

.auth-box button.primary {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: bold;
    font-size: 1rem;
    margin-top: 10px;
    cursor: pointer;
}

.toggle-link {
    color: var(--accent);
    cursor: pointer;
    margin-top: 15px;
    display: block;
    font-size: 0.9rem;
    text-decoration: underline;
}

/* =========================================
   3. LAYOUT & NAVIGATION
   ========================================= */
.view-section {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view-section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

nav {
    position: fixed;
    bottom: 3%; /* Surélève le menu de 5% par rapport au bas */
    left: 50%;
    transform: translateX(-50%); /* Centre parfaitement le menu */
    width: 95%; /* Laisse une marge de 5% de chaque côté */
    max-width: 500px; /* Évite qu'il soit trop large sur tablette/PC */
    height: var(--nav-height);
    background: #1f1f1f;
    border: 1px solid var(--border);
    border-radius: 12px; /* Bords arrondis pour l'effet flottant */
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5); /* Ombre portée pour la profondeur */
}
.nav-item {
    background: none;
    border: none;
    color: var(--text-sec);
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    width: 100%;
    height: 100%;
    justify-content: center;
    transition: 0.2s;
}

.nav-item.active {
    color: var(--accent);
}

.nav-icon {
    font-size: 1.4rem;
}

/* =========================================
   4. HEADER & FILTRES
   ========================================= */
header {
    background: #1f1f1f;
    padding: 15px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

h1 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
}

.color-filters {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 5px;
    padding-top: 5px;
    padding-left: 5px;
    scrollbar-width: none;
}

.color-filters::-webkit-scrollbar {
    display: none;
}

.filter-btn {
    height: auto !important; /* Force le bouton à s'agrandir si le cercle est grand */
    line-height: 1.4;
    border: none;
    padding: 6px 12px;       /* Réduit un peu le padding vertical pour laisser de la place au cercle */
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    opacity: 0.6;
    transition: all 0.2s;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    
    /* IMPORTANT POUR LE CERCLE */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;        /* Hauteur minimale suffisante */
    overflow: visible !important; /* FORCE l'affichage complet du cercle même s'il dépasse */
    position: relative;      /* Nécessaire pour le z-index */
    z-index: 1;
}

.filter-btn.active {
    opacity: 1;
    transform: scale(1.1);   /* Agrandit légèrement le bouton actif */
    z-index: 10;             /* Passe le bouton actif AU-DESSUS des autres pour que le cercle ne soit pas caché */
    box-shadow: 0 0 0 2px white;
}

.filter-btn.all {
    background: #555;
}

.search-input {
    width: 100%;
    background: #2c2c2c;
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    margin-top: 10px;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* =========================================
   5. GRILLE & CARTES
   ========================================= */
.paints-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 15px;
    padding: 20px;
}

.paint-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    border: 1px solid var(--border);
    transition: transform 0.2s;
}

.paint-card:active {
    transform: scale(0.98);
}

.card-color-preview {
    height: 100px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.color-swatch-large {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.2);
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.card-details {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-brand {
    font-size: 0.8rem;
    color: var(--text-sec);
    margin-bottom: 4px;
}

.card-type {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 6px;
    display: inline-block;
    background: rgba(52, 152, 219, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    width: fit-content;
}

.card-ref {
    font-family: monospace;
    background: #333;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    color: #ddd;
    display: inline-block;
    margin-bottom: 8px;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
    border-top: 1px solid #333;
    padding-top: 8px;
}

.qty-badge {
    background: var(--success);
    color: white;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
}

.actions {
    display: flex;
    gap: 5px;
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0 5px;
    color: var(--text-sec);
}

.icon-btn:hover {
    color: var(--danger);
}

/* Bouton Flottant (FAB) */
.fab {
    position: fixed !important;
    /* Calcul : 5% (bas du menu) + hauteur du menu + 20px de marge */
    bottom: calc(5% + var(--nav-height) + 20px) !important; 
    right: 20px !important;
    width: 65px !important;
    height: 65px !important;
    background: var(--accent) !important;
    color: white !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 40px !important;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5) !important;
    border: none !important;
    cursor: pointer;
    z-index: 150;
    transition: transform 0.2s;
}

.fab:hover {
    transform: scale(1.1);
    background: #2980b9 !important;
}

.fab:active {
    transform: scale(0.95);
}

/* =========================================
   6. MODALES & FORMULAIRES
   ========================================= */
.modal {
    display: none;
    position: fixed;
    z-index: 300;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: #252525;
    padding: 25px;
    border-radius: var(--radius);
    width: 90%;
    max-width: 400px;
    color: white;
    border: 1px solid var(--border);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
}

.close-modal {
    cursor: pointer;
    font-size: 24px;
    color: #aaa;
}

.close-modal:hover {
    color: white;
}

input, select {
    width: 100%;
    padding: 12px;
    margin: 8px 0;
    border-radius: var(--radius-sm);
    border: 1px solid #444;
    background: #333;
    color: white;
    font-size: 1rem;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}

button.primary {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: bold;
    font-size: 1rem;
    margin-top: 10px;
    cursor: pointer;
}

button.danger {
    background: var(--danger);
    color: white;
    border: none;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-weight: bold;
    width: 100%;
    margin-top: 10px;
    cursor: pointer;
}

button.secondary {
    background: #444;
    margin-top: 10px;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: background 0.2s;
}

button.secondary:hover {
    background: #555;
}

/* Contrôle de quantité */
.qty-control {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #333;
    padding: 5px;
    border-radius: var(--radius-sm);
    margin: 8px 0;
    width: fit-content;
}

.qty-control button {
    width: 40px;
    padding: 10px;
    background: #444;
    margin: 0;
    border: none;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.2rem;
}

.qty-control input {
    text-align: center;
    font-weight: bold;
    margin: 0;
    border: none;
    background: transparent;
    width: 50px;
    font-size: 1.1rem;
}

/* Sélecteur de tags couleur */
.color-tag-select {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 5px;
}

.color-tag-option {
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
    cursor: pointer;
    border: 2px solid transparent;
    opacity: 0.5;
    transition: 0.2s;
    font-weight: 600;
}

.color-tag-option.selected {
    opacity: 1;
    border-color: white;
    transform: scale(1.05);
}

.form-section {
    display: none;
    border-top: 1px solid #444;
    margin-top: 15px;
    padding-top: 15px;
}

.form-section.active {
    display: block;
}

/* =========================================
   7. COMPTE & GESTION UTILISATEURS (ADMIN)
   ========================================= */
.account-form {
    max-width: 500px;
    margin: 20px auto;
    padding: 20px;
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.account-form h2 {
    margin-top: 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 15px;
    color: var(--text);
}

.form-group {
    margin-bottom: 15px;
    text-align: left;
}

.form-group label {
    display: block;
    color: var(--text-sec);
    margin-bottom: 5px;
    font-size: 0.9rem;
}

/* Styles spécifiques Admin */
#adminUserManagement {
    border: 1px solid var(--danger);
    background: rgba(231, 76, 60, 0.05);
    margin-top: 30px;
}

#adminUserManagement h2 {
    color: var(--danger);
    border-color: var(--danger);
}

.user-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg);
    padding: 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 10px;
}

.user-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.user-name {
    font-weight: bold;
    font-size: 0.95rem;
    color: var(--text);
}

.user-role-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    width: fit-content;
    font-weight: bold;
    text-transform: uppercase;
}

.role-admin {
    background: var(--danger);
    color: white;
}

.role-user {
    background: var(--text-sec);
    color: black;
}

.role-select {
    padding: 5px 10px;
    background: var(--card-bg);
    color: white;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    width: auto;
    min-width: 120px;
}

.role-select:focus {
    border-color: var(--accent);
}

/* Badge Admin dans le header */
#adminBadge {
    font-size: 0.7rem;
    padding: 4px 8px;
    border-radius: 12px;
    text-transform: uppercase;
    font-weight: bold;
    background: var(--danger);
    color: white;
    display: none; /* Caché par défaut, affiché via JS si admin */
}

/* =========================================
   8. RESPONSIVE
   ========================================= */
@media (max-width: 480px) {
    .paints-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 10px;
    }
    
    .card-color-preview {
        height: 80px;
    }
    
    .color-swatch-large {
        width: 40px;
        height: 40px;
    }
    
    .header-top h1 {
        font-size: 1.1rem;
    }
    
    .filter-btn {
        padding: 6px 12px;
        font-size: 0.75rem;
    }
    
    .modal-content {
        height: 95vh;
        border-radius: 0;
        max-width: 100%;
        padding: 15px;
    }
}

@media (min-width: 768px) {
    .paints-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 20px;
        padding: 30px;
    }
    
    .card-color-preview {
        height: 120px;
    }
    
    nav {
        max-width: 600px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
    }
}

/* Accessibilité : Réduire les animations */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Styles pour les filtres dynamiques (Marque / Type) */
.dynamic-filters {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 0;
    margin-top: 5px;
    scrollbar-width: none; /* Cache la barre de défilement Firefox */
    border-bottom: 1px solid #333; /* Séparateur subtil */
}

.dynamic-filters::-webkit-scrollbar {
    display: none; /* Cache la barre de défilement Chrome/Safari */
}

.filter-tag {
    background: #2c2c2c;
    color: var(--text-sec);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0; /* Empêche l'écrasement */
}

.filter-tag:hover {
    background: #333;
    color: white;
}

.filter-tag.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

/* Force l'alignement en haut pour les images de fond des cartes */
.card-color-preview[style*="background-image"], 
div[style*="background-image"] {
    background-position: center top !important;
}

/* Alignement des images dans les étapes de projet */
#stepsList img {
    object-position: center top !important;
}
