/* --- VARIABLES ET THÈMES HARMONISÉS (BLEU MINUIT) --- */
:root {
    --bg: #0f172a;           
    --card: #1e293b;         
    --text: #f8fafc;         
    --text-dim: #94a3b8;     
    --border: #334155;       
    --primary: #3b82f6;      
    --success: #10b981; 
    --danger: #ef4444;
    --wrapper-bg: #1e293b80; 
}

[data-theme="light"] {
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --text-dim: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --wrapper-bg: #e2e8f080;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.4;
}

.container { max-width: 800px; margin: 0 auto; padding: 15px; }

/* --- HEADER --- */
.sexy-header {
    background: var(--card);
    backdrop-filter: blur(10px);
    padding: 15px 20px;
    border-radius: 0 0 20px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    margin: -15px -15px 15px -15px;
    border-bottom: 1px solid var(--border);
}

.header-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.header-btns { display: flex; gap: 8px; }

.btn-circle {
    width: 38px; height: 38px; background: rgba(125,125,125,0.1);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    text-decoration: none; color: var(--text); border: 1px solid var(--border);
    font-size: 1.1em; cursor: pointer;
}

/* --- MOIS SCROLLER --- */
.month-scroller { display: flex; overflow-x: auto; gap: 8px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.month-scroller::-webkit-scrollbar { display: none; }
.month-item {
    flex: 0 0 auto; padding: 6px 14px; background: rgba(125,125,125,0.1);
    border-radius: 10px; text-decoration: none; color: var(--text-dim); text-align: center;
}
.month-item.active { background: var(--primary); color: white; font-weight: bold; }
.month-item small { display: block; font-size: 0.7em; opacity: 0.6; }

/* --- GROUPES ET CARTES --- */
.category-group-wrapper {
    background: var(--wrapper-bg);
    padding: 10px;
    border-radius: 18px;
    margin-bottom: 12px;
    border: none;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
}

.group-title {
    margin: 0 0 10px 5px !important;
    font-size: 0.8em;
    opacity: 0.8;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card {
    background: var(--card);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
}

.category-group-wrapper .card:last-child { margin-bottom: 0; }

.main-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 8px;
}

/* --- TABLEAUX --- */
table { width: 100%; border-collapse: collapse; }
.amt { text-align: right; font-weight: bold; }

/* --- MODAUX ET FORMULAIRES --- */
.modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); align-items: center; justify-content: center; z-index: 1000;
}
.modal-content { background: var(--card); padding: 25px; border-radius: 20px; width: 90%; max-width: 400px; border: 1px solid var(--border); }
.form-group { margin-bottom: 15px; }
label { display: block; font-size: 0.75em; color: var(--text-dim); margin-bottom: 6px; font-weight: bold; text-transform: uppercase; }

input, select { 
    width: 100%; 
    padding: 12px; 
    background: var(--bg) !important; 
    border: 1px solid var(--border) !important; 
    border-radius: 10px; 
    color: var(--text) !important; 
    font-size: 1rem;
    outline: none;
}

/* Correction spécifique pour les listes déroulantes */
select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

/* Forcer le fond des options pour éviter le blanc illisible */
select option {
    background-color: var(--card);
    color: var(--text);
}

select optgroup {
    background-color: var(--bg);
    color: var(--primary);
    font-weight: bold;
    font-style: normal;
}

input:focus, select:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.btn { padding: 12px; border-radius: 10px; border: none; font-weight: bold; cursor: pointer; width: 100%; font-size: 1rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-delete { background: var(--danger); color: white; margin-top: 10px; text-decoration: none; display: flex; align-items: center; justify-content: center; height: 45px; border-radius: 10px; }
.modal-footer { display: flex; gap: 10px; margin-top: 20px; }

/* Amélioration visuelle pour mobile */
@media (prefers-color-scheme: dark) {
    select { color-scheme: dark; }
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    width: 32px;
    height: 32px;
    background: var(--danger);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    z-index: 10;
}

/* On s'assure que le contenu du modal est en position relative pour le bouton */
.modal-content {
    position: relative;
    padding-top: 35px; /* Un peu plus d'espace en haut pour le bouton */
}

/* Titres de modales harmonisés */
.modal-title {
    margin: 0 0 20px 0;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary);
}

.modal-title .icon {
    background: var(--wrapper-bg);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 1rem;
}

/* Espacement du corps du formulaire */
.form-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Harmonisation des boutons en footer de modal */
.modal-footer {
    margin-top: 20px;
    display: flex;
    flex-direction: column; /* Pour mobile : boutons les uns sous les autres */
    gap: 8px;
}