/* --- 1. VARIABLES & RESET --- */
:root {
    --bg-color: #F2F2F7; 
    --card-bg: #FFFFFF;
    --text-main: #1C1C1E; 
    --text-muted: #8E8E93;
    
    /* TOUT EST NOIR MAINTENANT (Bouton +, Checkbox, Boutons Modales...) */
    --accent-premium: #1C1C1E; 
    
    --danger-color: #FF3B30;
    --success-color: #34C759;
    --radius-sm: 14px;
    --radius-lg: 24px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: none !important; 
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    min-height: 100vh;
    overflow-x: hidden;
}

body.is-logged-out header { display: none; }
body.is-logged-out .bottom-nav { display: none; }

/* --- 2. EN-TÊTE --- */
header {
    padding: 20px 20px 10px;
    position: sticky;
    top: env(safe-area-inset-top);
    background-color: var(--bg-color);
    z-index: 10;
}

h1 {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -1px;
}

/* --- 3. STRUCTURE DES VUES --- */
main {
    padding: 0 20px 100px;
}

.view {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.view.active {
    display: block;
}

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

/* --- 4. LISTE DE COURSES --- */
.quick-suggestions-container {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 15px;
    margin-bottom: 5px;
    scrollbar-width: none; 
    -ms-overflow-style: none; 
}

.quick-suggestions-container::-webkit-scrollbar {
    display: none; 
}

.suggestion-pill {
    background-color: #E5E5EA; 
    color: #1C1C1E;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.suggestion-pill:active {
    background-color: #D1D1D6;
    transform: scale(0.95);
}

.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.input-group input {
    flex: 1;
    padding: 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 17px;
    background-color: var(--card-bg);
    box-shadow: 0 4px 12px rgba(0,0,0,0.03) !important;
    outline: none;
}

/* Bouton + Noir */
.input-group button {
    background-color: var(--accent-premium);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    width: 50px;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    transition: transform 0.1s ease;
}

.input-group button:active {
    transform: scale(0.95);
}

#grocery-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-x: hidden;
}

.grocery-item {
    position: relative;
    background: #FFFFFF;
    margin-bottom: 12px;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px rgba(0,0,0,0.02) !important;
    border: 1px solid #F2F2F7;
    overflow: hidden;
    max-height: 100px;
    transition: max-height 0.3s ease, margin-bottom 0.3s ease, opacity 0.3s ease;
}

.grocery-content {
    position: relative;
    z-index: 2;
    background: #FFFFFF;
    padding: 18px;
    display: flex;
    align-items: center;
    width: 100%;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.grocery-item.swiped .grocery-content {
    transform: translateX(-75px);
}

.grocery-delete-btn {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 75px;
    background-color: var(--danger-color);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    z-index: 1;
    cursor: pointer;
}

/* Case à cocher customisée (Carré Blanc -> Noir au clic) */
.grocery-item label {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
    font-size: 17px;
    color: #1C1C1E;
    cursor: pointer;
}

.check-item-btn {
    appearance: none;
    -webkit-appearance: none;
    width: 26px;
    height: 26px;
    border: 2px solid #E5E5EA;
    border-radius: 8px;
    cursor: pointer;
    background-color: #FFFFFF;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
}

.check-item-btn:checked {
    background-color: var(--accent-premium);
    border-color: var(--accent-premium);
}

.check-item-btn::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 12px;
    border: 2px solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    opacity: 0;
    transition: opacity 0.2s ease;
    top: 4px;
    left: 8px;
}

.check-item-btn:checked::after {
    opacity: 1;
}

.grocery-item span {
    transition: all 0.3s ease;
}

.grocery-item.checked span {
    text-decoration: line-through;
    color: var(--text-muted);
    opacity: 0.5;
}

.grocery-item.removing {
    opacity: 0;
    max-height: 0;
    margin-bottom: 0;
    border: none;
}

/* --- 5. COMPTES : Carte Noire Mat --- */
.balance-card {
    background: #1C1C1E;
    border-radius: var(--radius-lg);
    padding: 35px 20px;
    margin-bottom: 35px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.15) !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.balance-card h2 {
    font-size: 12px;
    font-weight: 600;
    color: #8E8E93;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 0;
    line-height: 1;
}

.balance-card .amount {
    font-size: 46px;
    font-weight: 700;
    letter-spacing: -2px;
    margin: 0; 
    line-height: 1;
    color: white;
}

.balance-card .subtitle {
    font-size: 14px;
    color: #EBEBF5;
    opacity: 0.6;
    margin: 0;
    line-height: 1;
}

/* --- 6. BARRE DE NAVIGATION (Boutons espacés) --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0,0,0,0.05);
    display: flex;
    justify-content: center;
    align-items: center;
    height: calc(85px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 100;
    gap: 70px; /* <--- L'ÉCARTEMENT DES BOUTONS EST ICI */
}

.nav-item {
    background: none;
    border: none;
    width: 120px;
    height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    position: relative;
    z-index: 2;
}

.nav-icon {
    font-size: 26px; 
    opacity: 0.8;
}

.nav-text {
    font-size: 14px; 
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: 0.5px;
    opacity: 0.8;
}

#nav-indicator {
    position: absolute;
    height: 65px;
    width: 120px;
    background-color: #E5E5EA; 
    border-radius: 20px;
    z-index: 1;
    left: 0;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: none;
}

.nav-item.active .nav-icon,
.nav-item.active .nav-text {
    opacity: 1;
}

/* --- 8. HISTORIQUE DES TRANSACTIONS --- */
#expenses-list {
    list-style: none;
    padding-bottom: 20px;
}

#expenses-history h3 {
    font-size: 18px;
    margin-bottom: 15px;
    text-align: center;
}

.btn-add-expense {
    width: 100%;
    padding: 18px;
    background-color: #FFFFFF;
    color: #1C1C1E;
    border: 1px solid #F2F2F7;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05) !important; 
    transition: transform 0.1s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-add-expense:active {
    transform: scale(0.97);
    box-shadow: 0 2px 6px rgba(0,0,0,0.05) !important;
    background-color: #F2F2F7;
}

.transaction-card {
    background: #FFFFFF;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    padding: 18px;
    border: 1px solid #F2F2F7;
    box-shadow: 0 2px 8px rgba(0,0,0,0.02) !important; 
}

.transaction-card:active {
    background-color: #F2F2F7;
    transform: scale(0.99);
}

.transaction-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.transaction-title {
    font-size: 17px;
    font-weight: 600;
}

.transaction-amount {
    font-size: 17px;
    font-weight: 600;
}

.transaction-details {
    display: none;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #E5E5EA;
    font-size: 14px;
    color: var(--text-muted);
}

.transaction-card.expanded .transaction-details {
    display: block;
    animation: fadeInModal 0.2s ease-out;
}

.transaction-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed #E5E5EA;
}
.btn-edit, .btn-delete {
    padding: 8px 12px;
    border-radius: 6px;
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    flex: 1;
}
.btn-edit { background-color: #F2F2F7; color: var(--accent-premium); }
.btn-delete { background-color: #FFEEEE; color: var(--danger-color); }

/* --- 9. FENÊTRE POP-UP (MODAL) --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%; 
    height: 100dvh; 
    background-color: rgba(0, 0, 0, 0.4); 
    display: none; 
    justify-content: center;
    align-items: flex-start; 
    padding-top: 15vh; 
    z-index: 1000; 
}

.modal-overlay.active {
    display: flex;
    animation: fadeInModal 0.2s ease-out;
}

.modal {
    background-color: var(--card-bg);
    padding: 24px;
    border-radius: var(--radius-lg);
    width: 85%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2) !important;
    animation: slideUpModal 0.2s ease-out;
}

.modal h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 5px;
    text-align: center;
}

.modal-subtitle {
    font-size: 15px;
    color: var(--text-muted);
    margin-bottom: 25px;
    text-align: center;
}

.modal-input-group {
    margin-bottom: 25px;
}

.modal-input-group input {
    width: 100%;
    padding: 18px;
    border: none;
    background-color: #F2F2F7;
    border-radius: var(--radius-sm);
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    color: var(--accent-premium);
    outline: none;
}

.modal-input-group input::placeholder {
    font-size: 22px;
    opacity: 0.5;
}

.modal-actions {
    display: flex;
    gap: 15px;
}

.modal-actions button {
    flex: 1;
    padding: 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

#delete-modal-overlay {
    align-items: center;
    padding-top: 0;
}

.btn-secondary {
    background-color: #E5E5EA;
    color: var(--text-main);
}

.btn-secondary:active {
    background-color: #D1D1D6;
}

.btn-primary {
    background-color: var(--accent-premium);
    color: white;
}

.btn-primary:active {
    background-color: #000000; /* Bouton devient vraiment noir au clic */
}

@keyframes fadeInModal {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* --- 10. CONNEXION (Pavé Numérique Premium) --- */
.login-container {
    text-align: center;
    margin-top: 4vh; /* S'adapte mieux à la taille de l'écran */
    display: flex;
    flex-direction: column;
    align-items: center;
}

.login-container h2 {
    margin-bottom: 20px;
    font-size: 24px;
}

#login-user-select {
    width: 100%;
    max-width: 250px;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid #E5E5EA;
    font-size: 18px;
    font-weight: 600;
    background: #fff;
    margin-bottom: 30px;
    text-align: center;
}

.subtitle-login {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* Affichage des 8 petits points */
.pin-display {
    display: flex;
    gap: 12px;
    margin-bottom: 40px;
    justify-content: center;
}

.pin-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #1C1C1E;
    background-color: transparent;
    transition: background-color 0.1s, border-color 0.2s;
}

.pin-dot.filled {
    background-color: #1C1C1E;
}

/* Grille du pavé numérique */
.custom-keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px 25px; /* Espace vertical et horizontal */
    width: 100%;
    max-width: 280px;
}

/* Les touches noires */
.keypad-btn {
    background-color: #1C1C1E;
    color: #FFFFFF;
    border: none;
    border-radius: 50%; /* Touches parfaitement rondes */
    width: 75px;
    height: 75px;
    font-size: 28px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.1s;
    margin: 0 auto;
}

.keypad-btn:active {
    transform: scale(0.9); /* Effet d'enfoncement physique */
    background-color: #3A3A3C; /* Gris foncé au clic */
}

/* Animation d'erreur (si mauvais code) */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    50% { transform: translateX(6px); }
    75% { transform: translateX(-6px); }
}

.pin-display.error {
    animation: shake 0.4s ease;
}