:root {
    --bg-color: #f7f9fc;
    --card-bg: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --primary: #0f172a;
    --accent: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
    --incompressible: #ef4444; /* Même rouge vif que danger */
    --plaisir: #f59e0b;        /* Orange vif au lieu de marron */
    --epargne: #10b981;        /* Même vert vif que success */
    --border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 16px;
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--card-bg);
    border-right: 1px solid var(--border);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 3rem;
    color: var(--primary);
    display: flex;
    align-items: center;
}

.logo span { color: var(--accent); }

.nav-links { list-style: none; }

.nav-links li { margin-bottom: 0.5rem; }

.nav-links a {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 10px;
    font-weight: 500;
    transition: all 0.2s ease-in-out;
}

.nav-links a:hover {
    background-color: var(--bg-color);
    color: var(--primary);
}

.nav-links a.active {
    background-color: #eff6ff;
    color: var(--accent);
}

.nav-links a.active svg {
    stroke: var(--accent);
}

/* Main Content */
.content {
    flex: 1;
    padding: 2.5rem 3.5rem;
    overflow-y: auto;
}

header {
    margin-bottom: 2.5rem;
}

h1 {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.025em;
}

.text-muted {
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: box-shadow 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.card .value {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.025em;
}

.card .value.success { color: var(--success); }
.card .value.danger { color: var(--danger); }

/* Charts */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    position: relative;
    height: 400px;
    display: flex;
    flex-direction: column;
}

.chart-card h3 {
    margin-bottom: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.875rem;
    font-weight: 600;
}

.chart-container {
    flex: 1;
    position: relative;
    width: 100%;
}

.sankey-card {
    grid-column: 1 / -1; /* Prend toute la largeur */
    height: 500px;
}

/* ==========================================================================
   Styles pour les Jauges Budget (50/30/20)
   ========================================================================== */
.budget-gauges {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.gauge-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.gauge-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.75rem;
}

.gauge-title {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-main);
}

.gauge-stats {
    text-align: right;
    font-size: 0.875rem;
}

.gauge-stats .spent {
    font-weight: 700;
    color: var(--primary);
}

.gauge-stats .target {
    color: var(--text-muted);
}

.gauge-track {
    width: 100%;
    height: 12px;
    background-color: #f3f4f6;
    border-radius: 999px;
    overflow: hidden;
    position: relative;
    margin-bottom: 0.5rem;
}

.gauge-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.5s ease-out, background-color 0.3s ease;
}

.gauge-footer {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 500;
}

/* Colors for gauges */
.gauge-fill.incompressible { background-color: var(--incompressible); }
.gauge-fill.plaisir { background-color: var(--plaisir); }
.gauge-fill.epargne { background-color: var(--epargne); }

.gauge-fill.warning { background-color: #f97316; } /* Orange */
.gauge-fill.danger { background-color: var(--danger); }

/* ==========================================================================
   Styles pour la page Transactions
   ========================================================================== */

/* Tableaux */
.table-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow-x: auto;
    margin-top: 1.5rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th, td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

th {
    background-color: #f9fafb;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background-color: #f9fafb;
}

/* Badges (Catégories / Types) */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge.expense { background-color: #fee2e2; color: #b91c1c; }
.badge.income { background-color: #d1fae5; color: #047857; }
.badge.category { background-color: #e0e7ff; color: #4338ca; }

/* Badges pour Groupes principaux */
.badge.incompressible { background-color: #fee2e2; color: var(--incompressible); }
.badge.plaisir { background-color: #fef3c7; color: var(--plaisir); }
.badge.epargne { background-color: #d1fae5; color: var(--epargne); }

/* Boutons Actions (Icones) */
.action-buttons {
    display: flex;
    gap: 0.5rem;
}
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    border: none;
}
.btn-icon.edit { color: var(--accent); background-color: #eff6ff; }
.btn-icon.edit:hover { background-color: #dbeafe; transform: scale(1.05); }
.btn-icon.delete { color: var(--danger); background-color: #fef2f2; }
.btn-icon.delete:hover { background-color: #fee2e2; transform: scale(1.05); }

/* Boutons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    gap: 0.5rem;
}
.btn-primary {
    background-color: var(--primary);
    color: white;
}
.btn-primary:hover {
    background-color: #1f2937;
    box-shadow: var(--shadow-md);
}
.btn-danger {
    background-color: #fee2e2;
    color: #ef4444;
    padding: 0.375rem 0.75rem;
}
.btn-danger:hover {
    background-color: #fca5a5;
    color: #b91c1c;
}
.btn-outline {
    background-color: white;
    border: 1px solid var(--border);
    color: var(--text-main);
}
.btn-outline:hover {
    background-color: #f9fafb;
}

/* Header Action (Titre + Bouton) */
.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

/* Modal Alpine.js */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(17, 24, 39, 0.5);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem 1rem;
    z-index: 100;
    backdrop-filter: blur(4px);
    overflow-y: auto;
}
.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    margin: auto;
}
.modal h2 { margin-bottom: 1.5rem; font-size: 1.5rem; }

/* Formulaires */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.875rem;
}
.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s;
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
}

/* ==========================================================================
   Design Responsif (Mobile Premium)
   ========================================================================== */

@media (max-width: 768px) {
    /* 1. Body & Layout : suppression de la disposition flex row */
    body {
        flex-direction: column;
        padding-bottom: 80px; /* Espace pour la Bottom Nav */
    }

    /* 2. Main Content : réduction des marges */
    .content {
        padding: 1.5rem 1rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    /* 3. Transformation Sidebar -> Bottom Navigation Bar */
    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 80px;
        background-color: var(--card-bg);
        border-right: none;
        border-top: 1px solid var(--border);
        padding: 0;
        z-index: 90;
        flex-direction: row;
        justify-content: space-around;
        box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.05);
    }

    .logo {
        display: none; /* On cache le logo sur mobile pour laisser la place aux icones */
    }

    .nav-links {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
        padding: 0 0.5rem;
        margin: 0;
    }

    .nav-links li {
        margin: 0;
        flex: 1;
        display: flex;
        justify-content: center;
    }

    /* On annule le padding-top automatique du bouton Paramètres */
    .nav-links li[style*="margin-top: auto"] {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }

    .nav-links a {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 0.5rem;
        font-size: 0.65rem;
        border-radius: 0;
        gap: 4px;
        color: var(--text-muted);
    }

    .nav-links a svg {
        margin-right: 0 !important;
        width: 24px;
        height: 24px;
    }

    .nav-links a.active {
        background-color: transparent;
        color: var(--accent);
    }
    .nav-links a.active svg {
        stroke: var(--accent);
        fill: rgba(59, 130, 246, 0.1);
    }

    /* 4. Tableau de bord : Empilement des éléments */
    .header-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    
    .header-actions > div:last-child {
        width: 100%;
        flex-direction: column;
        align-items: stretch !important;
        gap: 1rem;
    }
    
    .header-actions .date-controls {
        width: 100%;
        justify-content: space-between;
    }

    .header-actions .btn-primary {
        width: 100%;
        justify-content: center;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .sankey-card {
        height: 400px; /* Réduire la hauteur du sankey sur mobile */
    }
    
    /* 5. Tableaux : Cacher les colonnes secondaires sur mobile */
    .hide-on-mobile {
        display: none !important;
    }

    th, td {
        padding: 0.75rem 0.5rem;
        font-size: 0.875rem;
    }
    
    .btn-icon {
        padding: 0.5rem; /* Plus gros sur mobile pour les doigts */
    }

    /* 6. Modales */
    .modal-overlay {
        padding: 1rem 0.5rem;
    }
    .modal {
        padding: 1.5rem;
        border-radius: 12px;
    }
    
    .modal-actions {
        flex-direction: column;
    }
    
    .modal-actions .btn {
        width: 100%;
    }
}

.bg-incompressible { background-color: var(--incompressible) !important; }
.bg-plaisir { background-color: var(--plaisir) !important; }
.bg-epargne { background-color: var(--epargne) !important; }
