/* ==========================================================================
   🛡️ FONDATIONS & DESIGN COCOONING PREMIUM - LIFEBUDGET
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; position: relative; width: 100vw; margin: 0; padding: 0; }

:root { 
    --primary: #D4A373;   
    --secondary: #CCD5AE; 
    --bg: #FAF6F0;        
    --text: #5C5346;      
    --card-bg: #FFFFFF;   
    --border: #EAE4D9;    
    --sidebar-bg: #F4ECE1;
    --sidebar-text: #5C5346;
    --danger: #E07A5F;    
    --success: #81B29A;   
}

body.theme-dark { --primary: #A3B18A; --secondary: #DAD7CD; --bg: #2C2A29; --text: #EAE4D9; --card-bg: #3A3635; --border: #4A4543; --sidebar-bg: #242221; --sidebar-text: #EAE4D9; }
body.theme-cosy { --primary: #D4A373; --secondary: #A9AF7E; --bg: #FAEDCD; --text: #5E503F; --card-bg: #FEFAE0; --border: #E9EDC9; --sidebar-bg: #5E503F; --sidebar-text: #FEFAE0; }
body.theme-panda-geant { --primary: #52796F; --secondary: #CAD2C5; --bg: #E8F5E9; --text: #2F3E46; --card-bg: #FFF; --border: #C8E6C9; --sidebar-bg: #354F52; --sidebar-text: #FFF; }
body.theme-panda-roux { --primary: #E07A5F; --secondary: #F4F1DE; --bg: #FDF8F5; --text: #3D405B; --card-bg: #FFF; --border: #F2E8CF; --sidebar-bg: #81B29A; --sidebar-text: #FFF; }

body::before { content: ''; position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: -1; opacity: 0; transition: opacity 0.8s ease-in-out; background-size: cover; background-position: center; pointer-events: none; }
.sidebar-footer { position: relative; }
.sidebar-footer::before { content: ''; display: block; height: 120px; margin-bottom: 10px; background-size: contain; background-repeat: no-repeat; background-position: center bottom; opacity: 0; transition: opacity 0.5s ease-in-out; }

body.theme-panda-geant::before { opacity: 1; background-image: linear-gradient(rgba(242,244,242,0.85), rgba(242,244,242,0.85)), url('panda-geant.jpg'); }
body.theme-panda-geant .sidebar-footer::before { opacity: 1; background-image: url('bb-panda-menu.png'); }
body.theme-panda-roux::before { opacity: 1; background-image: linear-gradient(rgba(250,243,232,0.85), rgba(250,243,232,0.85)), url('fond-roux.jpg'); }
body.theme-panda-roux .sidebar-footer::before { opacity: 1; background-image: url('icone-roux.png'); }

body { font-family: 'Nunito', sans-serif; background-color: var(--bg); color: var(--text); transition: background-color 0.5s, color 0.5s; display: flex; min-height: 100vh; line-height: 1.5; }

/* --- SIDEBAR --- */
.sidebar { width: 270px; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; padding: 25px 20px; position: fixed; top: 0; bottom: 0; transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); z-index: 1001; overflow-y: auto; border-right: 1px solid var(--border); }
.sidebar.collapsed { transform: translateX(-270px); }
.main-content { flex: 1; margin-left: 270px; padding: 30px; transition: margin-left 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); width: 100%; max-width: 100%; }
.main-content.expanded { margin-left: 0; }
.sidebar h2 { font-size: 1.6em; font-weight: 800; margin-bottom: 40px; text-align: center; color: var(--primary); white-space: nowrap; letter-spacing: 1px; }
.nav-menu { list-style: none; padding: 0; flex: 1; margin: 0; }
.nav-item { padding: 14px 18px; border-radius: 16px; margin-bottom: 10px; cursor: pointer; display: flex; align-items: center; gap: 12px; transition: 0.3s ease; font-weight: 700; color: var(--sidebar-text); opacity: 0.7; }
.nav-item:hover { opacity: 1; background: rgba(0,0,0,0.03); transform: translateX(5px); }
.nav-item.active { background: var(--card-bg); color: var(--primary); opacity: 1; box-shadow: 0 4px 15px rgba(0,0,0,0.02); }
.sidebar-footer { border-top: 2px dashed var(--border); padding-top: 25px; }

.mobile-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.3); backdrop-filter: blur(3px); z-index: 1000; opacity: 0; transition: opacity 0.4s ease; }
.mobile-overlay.active { display: block; opacity: 1; }

.top-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 35px; gap: 15px; flex-wrap: wrap; width: 100%; }
.toggle-sidebar-btn { background: var(--card-bg); color: var(--text); border: 1px solid var(--border); width: 48px !important; height: 48px !important; border-radius: 14px; cursor: pointer; font-size: 1.4em; display: flex; align-items: center; justify-content: center; transition: 0.3s; box-shadow: 0 4px 10px rgba(0,0,0,0.02); margin: 0 !important; padding: 0 !important; }
.toggle-sidebar-btn:hover { background: var(--primary); color: white; border-color: var(--primary); }

.action-bar { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; align-items: center; width: 100%; }

.fullscreen-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--bg); display: flex; justify-content: center; align-items: center; z-index: 2000; padding: 20px; }
#custom-dialog-overlay, #modal-expense, #modal-onboarding, #modal-wrapup { background: rgba(0,0,0,0.4); backdrop-filter: blur(5px); }
.auth-box { background: var(--card-bg); padding: 40px; border-radius: 28px; box-shadow: 0 20px 50px rgba(0,0,0,0.05); width: 100%; max-width: 450px; text-align: center; border: 1px solid var(--border); position: relative; max-height: 90vh; overflow-y: auto;}

.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 25px; margin-bottom: 35px; width: 100%; align-items: start; }
.layout-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 25px; align-items: start; width: 100%; }

.card { background: var(--card-bg); padding: 28px; border-radius: 24px; box-shadow: 0 8px 24px rgba(0,0,0,0.03); width: 100%; border: 1px solid rgba(0,0,0,0.02); transition: 0.3s; }
.card:hover { box-shadow: 0 12px 32px rgba(0,0,0,0.05); }

.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.card-header h3 { margin: 0 !important; font-size: 1.25em; font-weight: 800; color: var(--text); }

.toggle-card-btn, .toggle-section-btn { background: var(--bg) !important; color: var(--text) !important; border: none !important; border-radius: 50% !important; width: 36px !important; height: 36px !important; display:flex; align-items:center; justify-content:center; padding: 0 !important; margin: 0 !important; cursor: pointer; transition: 0.3s; font-size: 1.1em; }
.toggle-card-btn:hover, .toggle-section-btn:hover { background: var(--primary) !important; color: white !important; transform: scale(1.1); }

.card-content { transition: opacity 0.3s; width: 100%; }

.balance { font-size: 2.2em; font-weight: 800; margin: 10px 0; display: block; color: var(--text); letter-spacing: -0.5px; }

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea { width: 100%; padding: 14px 18px; margin-top: 8px; border: 1px solid var(--border); border-radius: 16px; background: #FDFBF7; color: var(--text); font-family:inherit; font-size: 1em; transition: 0.3s; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(212, 163, 115, 0.1); background: var(--card-bg); }

button { background: var(--primary); color: white; border: none; padding: 16px; border-radius: 18px; cursor: pointer; font-weight: 800; font-size: 1.05em; width: 100%; margin-top: 20px; transition: 0.3s; font-family: inherit; box-shadow: 0 4px 15px rgba(212, 163, 115, 0.3); }
button:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(212, 163, 115, 0.4); }
button:active { transform: translateY(0); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-small { width: auto !important; margin: 0 !important; padding: 10px 20px !important; font-size: 0.9em; background: var(--card-bg); color: var(--text); border: 1px solid var(--border); box-shadow: 0 2px 8px rgba(0,0,0,0.02); border-radius: 14px; cursor:pointer;}
.btn-small:hover { background: var(--bg); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.05); color: var(--primary); border-color: var(--primary); }

.transaction-type-toggle { display: flex; gap: 12px; margin-bottom: 20px; width: 100%; }
.radio-label { flex: 1; cursor: pointer; }
.radio-label input { display: none; } 
.radio-btn { display: block; text-align: center; padding: 14px; border-radius: 16px; font-weight: 800; transition: 0.3s; background: var(--bg); border: 2px solid transparent; color: var(--text); opacity: 0.7; }
.radio-label input[value="expense"]:checked + .radio-btn { background: rgba(224, 122, 95, 0.1); border-color: var(--danger); color: var(--danger); opacity: 1; }
.radio-label input[value="income"]:checked + .radio-btn { background: rgba(129, 178, 154, 0.1); border-color: var(--success); color: var(--success); opacity: 1; }

.switch-container { display: flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.switch { position: relative; display: inline-block; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { display: none; }
.slider { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border); transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 22px; width: 22px; left: 4px; bottom: 4px; background-color: white; transition: .4s cubic-bezier(0.25, 0.8, 0.25, 1); border-radius: 50%; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(22px); }
.switch-important input:checked + .slider { background-color: var(--danger); }

.progress-bar { width: 100%; background: var(--bg); border-radius: 20px; height: 14px; overflow: hidden; margin-top: 12px; box-shadow: inset 0 1px 3px rgba(0,0,0,0.05); }
.progress-fill { height: 100%; transition: width 0.8s cubic-bezier(0.25, 0.8, 0.25, 1); border-radius: 20px; }
.green { background: var(--success); } .orange { background: #F2CC8F; } .red { background: var(--danger); }

/* --- TABLEAUX & TRI --- */
.table-container { padding: 0; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 20px; background: var(--card-bg); box-shadow: 0 8px 24px rgba(0,0,0,0.03); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th { padding: 18px 15px; text-align: left; border-bottom: 2px solid var(--border); font-size: 0.85em; text-transform: uppercase; letter-spacing: 1px; color: var(--text); opacity: 0.6; font-weight: 800; }
.sortable { cursor: pointer; user-select: none; transition: 0.2s; }
.sortable:hover { background: rgba(0,0,0,0.02); opacity: 1; color: var(--primary); }
td { padding: 15px; text-align: left; border-bottom: 1px solid var(--bg); font-size: 0.95em; font-weight: 600; color: var(--text); vertical-align: middle;}
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: rgba(0,0,0,0.01); }

.quick-filters { display:flex; gap:10px; overflow-x:auto; padding-bottom:10px; margin-bottom:10px; -webkit-overflow-scrolling:touch; }
.qf-btn { background:var(--bg); border:1px solid var(--border); color:var(--text); padding:8px 15px; border-radius:20px; font-size:0.85em; font-weight:700; cursor:pointer; transition:0.2s; white-space:nowrap; }
.qf-btn:hover { background:var(--card-bg); border-color:var(--primary); color:var(--primary); }
.qf-btn.active { background:var(--primary); color:white; border-color:var(--primary); box-shadow:0 2px 8px rgba(212, 163, 115, 0.3); }

.calendar-header-days { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-weight: 800; margin-bottom: 10px; font-size: 0.9em; color: var(--primary); width: 100%; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; width: 100%; }
.calendar-day { min-height: 90px; padding: 6px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); font-size: 0.8em; display: flex; flex-direction: column; gap: 4px; transition: 0.2s; }
.calendar-day:hover { transform: scale(1.02); box-shadow: 0 4px 10px rgba(0,0,0,0.05); z-index: 2; position: relative;}
.calendar-day.empty { background: transparent; border: none; box-shadow: none; pointer-events: none;}
.calendar-day .day-num { font-weight: 800; margin-bottom: 4px; text-align: right; color: var(--text); opacity: 0.5; font-size: 1.1em;}
.calendar-day.today { border: 2px solid var(--primary); background: var(--card-bg); box-shadow: 0 4px 15px rgba(212, 163, 115, 0.15); }
.calendar-day.today .day-num { color: var(--primary); opacity: 1; }
.badge { padding: 4px 8px; border-radius: 8px; color: #fff; font-size: 0.85em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; transition:0.2s; font-weight: 700; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.badge:hover { opacity: 0.9; transform: translateY(-1px); }

.fab-btn { position: fixed; bottom: 35px; right: 35px; width: 65px; height: 65px; border-radius: 22px; background: var(--primary); color: white; font-size: 2.2em; display: flex; align-items: center; justify-content: center; box-shadow: 0 10px 25px rgba(212, 163, 115, 0.4); cursor: pointer; z-index: 900; border: none; transition: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); }
.fab-btn:hover { transform: translateY(-5px) scale(1.05); box-shadow: 0 15px 35px rgba(212, 163, 115, 0.5); }

#global-announcement { display:none; background:var(--danger); color:white; padding:15px; text-align:center; font-weight:800; width:100%; border-radius:16px; margin-bottom:25px; animation: slideDown 0.5s cubic-bezier(0.25, 0.8, 0.25, 1); box-shadow: 0 4px 15px rgba(224, 122, 95, 0.3); }

.view-section { animation: fadeIn 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.bottom-nav { display: none; position: fixed; bottom: 0; left: 0; right: 0; background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(10px); box-shadow: 0 -5px 30px rgba(0,0,0,0.05); z-index: 800; justify-content: space-around; padding: 12px 10px; border-top: 1px solid rgba(0,0,0,0.03); padding-bottom: calc(12px + env(safe-area-inset-bottom)); border-radius: 30px 30px 0 0; }
.bottom-nav-item { display: flex; flex-direction: column; align-items: center; color: var(--text); text-decoration: none; font-size: 0.75em; gap: 6px; cursor: pointer; opacity: 0.4; transition: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); font-weight: 700; }
.bottom-nav-item.active { opacity: 1; color: var(--primary); transform: translateY(-3px); }
.bottom-nav-item span { font-size: 1.6em; transition: 0.3s; }
.bottom-nav-item.active span { transform: scale(1.15); }

/* 📱 MOBILE - TABLEAU BLINDÉ */
@media (max-width: 850px) {
    .sidebar { transform: translateX(-100%); width: 280px; box-shadow: 10px 0 30px rgba(0,0,0,0.1); border-right:none; border-radius: 0 30px 30px 0; }
    .sidebar.mobile-open { transform: translateX(0); }
    .main-content { margin-left: 0 !important; padding: 20px; width: 100vw; max-width: 100vw; overflow-x: hidden; padding-bottom: 160px; } 
    .grid-stats { display: flex; flex-direction: column; gap: 20px; width: 100%; align-items: stretch; } 
    .layout-split { display: flex; flex-direction: column; gap: 20px; width: 100%; }
    .card { padding: 20px; width: 100%; box-sizing: border-box; }
    .action-bar { flex-direction: column; align-items: stretch; gap: 10px; }
    .action-bar > select, .action-bar > button { width: 100% !important; margin-bottom: 0 !important; margin-top:0 !important; }
    .calendar-day { min-height: 70px; font-size: 0.75em; }
    .fab-btn { bottom: 95px; right: 20px; width: 60px; height: 60px; border-radius: 20px; } 
    .bottom-nav { display: flex; } 
    .balance { font-size: 1.8em; }
    h2 { font-size: 1.4em; }

    /* Correction affichage Tableau Mobile */
    .table-container { background: transparent !important; box-shadow: none !important; border: none !important; padding:0 !important; overflow: visible !important; }
    table, tbody, tr, th, td { display: block; width: 100%; }
    thead { display: none; }
    
    tr { 
        position: relative; background: var(--card-bg); border-radius: 16px; 
        margin-bottom: 15px; padding: 15px; box-shadow: 0 4px 10px rgba(0,0,0,0.03); 
        border: 1px solid var(--border); box-sizing: border-box; touch-action: pan-y; z-index:2;
    }
    td { 
        display: flex !important; justify-content: space-between; align-items: center; 
        padding: 8px 0; border: none !important; border-bottom: 1px dashed var(--bg) !important;
        font-size: 0.95em; text-align: right; gap:10px;
    }
    td:last-child { border-bottom: none !important; padding-bottom: 0; justify-content: flex-end; }
    td::before { 
        content: attr(data-label); font-weight: 800; opacity: 0.6; 
        font-size: 0.85em; text-transform: uppercase; color: var(--primary); 
        text-align: left; flex-shrink: 0; margin-right: 15px;
    }
    td > * { max-width: 100%; }
}

.section-header { display:flex; justify-content:space-between; align-items:center; border-bottom: 2px solid var(--border); padding-bottom:10px; margin-bottom: 20px; }
.section-title { font-size:1.3em; font-weight:800; color:var(--text); margin:0; padding:0; border:none; }

.trophy-card { background: linear-gradient(135deg, #F2CC8F, #E07A5F); color: white; padding: 20px; border-radius: 20px; text-align: center; box-shadow: 0 5px 15px rgba(224, 122, 95, 0.3); transition: 0.3s; }
.trophy-card:hover { transform: translateY(-5px) scale(1.02); }
.trophy-icon { font-size: 3em; margin-bottom: 10px; filter: drop-shadow(0 4px 4px rgba(0,0,0,0.2)); }

.shopping-item { transition: 0.2s; }
.shopping-item:hover { background: rgba(0,0,0,0.01); }
.quick-item-input::placeholder { color: var(--text); opacity: 0.4; }
.quick-item-input:focus::placeholder { opacity: 0.2; }