:root {
    --bg-app: #000000;
    --bg-card: #141414;
    --bg-sidebar: #0a0a0a;
    --text-main: #ffffff;
    --text-muted: #8b8d96;
    --accent: #c89a74;
    --green: #22c55e;
    --red: #ef4444;
    --border: rgba(255,255,255,0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; scroll-behavior: smooth; }
body { background-color: var(--bg-app); color: var(--text-main); display: flex; height: 100vh; overflow: hidden; }

/* Menu Latéral */
.sidebar { 
    width: 250px; 
    background-color: var(--bg-sidebar); 
    border-right: 1px solid var(--border); 
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    overflow-y: auto; /* Active le défilement vertical */
}

/* Masque visuellement la barre de défilement tout en gardant le scroll actif */
.sidebar::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

.logo { font-size: 1.5rem; font-weight: bold; margin-bottom: 40px; color: var(--accent); }
nav a { display: block; color: var(--text-muted); text-decoration: none; padding: 12px 15px; border-radius: 8px; margin-bottom: 5px; font-weight: 500; transition: 0.2s; }
nav a.active, nav a:hover { background-color: var(--bg-card); color: var(--text-main); }

/* Formulaire Ajout */
.add-asset-box { margin-top: auto; background: var(--bg-card); padding: 15px; border-radius: 12px; border: 1px solid var(--border); }
.add-asset-box input { width: 100%; background: #1f1f1f; border: 1px solid var(--border); color: white; padding: 10px; border-radius: 6px; margin-bottom: 10px; outline: none; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }
input::placeholder { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; color: #555; }
.add-asset-box button { width: 100%; background: var(--accent); color: black; border: none; padding: 10px; border-radius: 6px; font-weight: bold; cursor: pointer; }

/* Dashboard Central */
.dashboard { flex: 1; padding: 30px; overflow-y: auto; display: flex; flex-direction: column; gap: 30px; }
.dashboard > * { flex-shrink: 0; } /* empêche les blocs d'être écrasés/superposés dans la colonne flex */
.top-grid { display: grid; grid-template-columns: 2.5fr 1fr; grid-template-rows: minmax(0, 1fr); gap: 20px; height: 540px; }
.top-grid > .card { min-height: 0; min-width: 0; overflow: hidden; }
.top-grid.savings-grid { height: auto; min-height: 380px; grid-template-rows: auto; }
.top-grid.savings-grid > .card { overflow: visible; }
.card { background-color: var(--bg-card); border-radius: 16px; padding: 20px; border: 1px solid var(--border); display: flex; flex-direction: column; }
.card-header h2 { font-size: 1rem; font-weight: 500; color: var(--text-muted); }

/* Statistiques Globales & Plus-Value */
.portfolio-stats { display: flex; gap: 15px; align-items: baseline; margin: 8px 0; flex-wrap: wrap; }
.total-value { font-size: 2.5rem; font-weight: 600; margin: 0; font-variant-numeric: tabular-nums; white-space: nowrap; }
.gain-loss-badge { font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.portfolio-details { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.detail-pill { font-variant-numeric: tabular-nums; white-space: nowrap; background: rgba(255,255,255,0.03); border: 1px solid var(--border); padding: 5px 10px; border-radius: 8px; font-size: 0.8rem; color: var(--text-muted); }
.detail-pill strong { color: var(--text-main); margin-left: 4px; }

.main-chart-wrapper { position: relative; width: 100%; min-height: 0; overflow: hidden; }
.top-grid .main-chart-wrapper { flex: 1 1 0; } /* uniquement dans le bloc du haut ; ailleurs la hauteur inline est respectée */
.main-chart-wrapper canvas, .doughnut-wrapper canvas { position: absolute; inset: 0; }
.doughnut-wrapper { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; overflow: hidden; }

/* Cartes Actifs */
.assets-section h2, .news-section h2 { font-size: 1.2rem; font-weight: 500; margin-bottom: 15px; }
.assets-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 18px; }

.asset-card { 
    background-color: var(--bg-card); 
    border-radius: 12px; 
    padding: 20px; 
    border: 1px solid var(--border); 
    display: flex; 
    flex-direction: column; 
    cursor: pointer; 
    transition: transform 0.2s ease, background-color 0.2s; 
}
.asset-card:hover { transform: translateY(-4px); background-color: #1a1a1a; border-color: var(--accent); }
.color-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; flex-shrink: 0; }
.asset-info { width: 100%; }
.asset-name { font-size: 0.95rem; font-weight: 600; display: flex; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-ticker { font-size: 0.75rem; color: var(--text-muted); margin-left: 18px; margin-top: 2px; }
.asset-value { font-size: 1.2rem; font-weight: 600; margin-top: 8px; }
.asset-invested { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.asset-perf { font-size: 0.82rem; font-weight: 600; margin-top: 4px; }
.perf-pos { color: var(--green) !important; }
.perf-neg { color: var(--red) !important; }
.mini-chart { 
    width: 100%; 
    height: 45px; 
    margin-top: 15px; 
    margin-bottom: 5px; 
    flex-shrink: 0; 
}

/* Actualités */
.news-section { margin-top: 10px; padding-bottom: 30px; }
.news-grid { display: flex; flex-direction: column; gap: 10px; }
.news-item { background: var(--bg-card); border: 1px solid var(--border); padding: 15px; border-radius: 10px; }
.news-item a { color: var(--text-main); text-decoration: none; font-weight: 600; display: block; margin-bottom: 5px; }
.news-item a:hover { color: var(--accent); }
.news-meta { font-size: 0.8rem; color: var(--text-muted); }
.news-badge { background: #2a2a2a; padding: 2px 6px; border-radius: 4px; color: var(--accent); margin-right: 5px; font-weight: bold;}

/* Fenêtre Modale */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.7); backdrop-filter: blur(4px); align-items: center; justify-content: center; }
.modal-content { background-color: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; width: 90%; max-width: 600px; max-height: 90vh; overflow-y: auto; padding: 25px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.modal-header h2 { font-size: 1.4rem; color: var(--text-main); }
.close-btn { background: none; border: none; color: var(--text-muted); font-size: 2rem; cursor: pointer; line-height: 1; }
.close-btn:hover { color: white; }
.modal-price-zone { display: flex; align-items: baseline; gap: 15px; margin-bottom: 20px; }
.modal-price { font-size: 2.2rem; font-weight: bold; }
.modal-perf { font-size: 1rem; font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 25px; background: #0a0a0a; padding: 15px; border-radius: 12px; border: 1px solid var(--border); }
.stat-box { display: flex; flex-direction: column; }
.stat-box span { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 5px; }
.stat-box strong { font-size: 1.05rem; color: var(--text-main); }
.modal-chart-wrapper { height: 250px; width: 100%; margin-bottom: 25px; }
.modal-summary h3 { font-size: 1.1rem; margin-bottom: 10px; color: var(--text-main); }
.modal-summary p { font-size: 0.85rem; color: var(--text-muted); line-height: 1.6; text-align: justify; background: #0a0a0a; padding: 15px; border-radius: 12px; border: 1px solid var(--border); }

/* Filtres Temporels */
.chart-filters { display: flex; gap: 8px; margin-bottom: 15px; background: #0a0a0a; padding: 6px; border-radius: 10px; width: fit-content; border: 1px solid var(--border); }
.filter-btn { background: transparent; color: var(--text-muted); border: none; padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: 0.2s; }
.filter-btn:hover { color: var(--text-main); }
.filter-btn.active { background: #2a2a2a; color: var(--text-main); box-shadow: 0 2px 4px rgba(0,0,0,0.2); }

/* Bouton de Suppression (Modale) */
.btn-delete { background-color: transparent; color: var(--red); border: 1px solid rgba(239, 68, 68, 0.3); padding: 10px 20px; border-radius: 8px; font-weight: bold; cursor: pointer; transition: 0.2s; width: 100%; }
.btn-delete:hover { background-color: rgba(239, 68, 68, 0.1); border-color: var(--red); }

/* --- PAGE COMPOSITION (TOP 20 / 10) --- */
.holdings-container { padding: 30px; max-width: 1200px; margin: 0 auto; overflow-y: auto; height: 100vh;}
.holdings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 25px; padding-bottom: 50px; }
.holdings-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; }

.holdings-table { width: 100%; border-collapse: collapse; table-layout: fixed; margin-top: 5px; }
.holdings-table th { padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.05); color: var(--text-muted); font-size: 0.8rem; font-weight: normal; }
.holdings-table td { padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.02); font-size: 0.9rem; vertical-align: middle; }
.holdings-table tr:last-child td { border-bottom: none !important; }

.col-name { width: 50%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 15px; color: var(--text-main); }
.col-percent { width: 20%; text-align: right; font-weight: bold; color: var(--accent); }
.col-value { width: 30%; text-align: right; font-weight: bold; color: var(--text-main); }

.empty-holdings { text-align: center; padding: 30px 10px; background: rgba(255,255,255,0.02); border-radius: 8px; color: var(--text-muted); font-size: 0.9rem; margin-top: 15px; }

/* --- AMÉLIORATIONS : RESPONSIVE MOBILE & ACTUALITÉS --- */
@media (max-width: 768px) {
    body { flex-direction: column; overflow-y: auto; height: auto; }
    .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 15px; }
    .dashboard { padding: 15px; overflow-y: visible; }
    .top-grid { grid-template-columns: 1fr; grid-template-rows: none; height: auto; }
    .main-chart-wrapper { flex: none; height: 300px; }
    .doughnut-wrapper { flex: none; height: 300px; }
    .assets-grid { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: 1fr; }
    .modal-content { width: 95%; margin: 10px; }
    .holdings-grid { grid-template-columns: 1fr; }
    .cash-box { flex-direction: column; align-items: flex-start; }
}

.sentiment-badge { font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; font-weight: bold; margin-left: 8px; }
.sentiment-pos { background: rgba(34,197,94,0.1); color: var(--green); }
.sentiment-neg { background: rgba(239,68,68,0.1); color: var(--red); }
.sentiment-neu { background: rgba(255,255,255,0.05); color: var(--text-muted); }
.drift-alert { background: rgba(239, 68, 68, 0.15); border: 1px solid var(--red); color: white; padding: 10px; border-radius: 8px; margin-bottom: 15px; font-size: 0.85rem; display: none; }

/* --- Compte, répartition, connexion --- */
.user-box { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--text-muted); font-size: 0.85rem; }
.btn-mini { background: #1f1f1f; color: var(--text-main); border: 1px solid var(--border); padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; }
.btn-mini:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #000; border: none; padding: 8px 16px; border-radius: 6px; font-weight: bold; cursor: pointer; }
.field { width: 100%; background: #1f1f1f; border: 1px solid var(--border); color: white; padding: 10px; border-radius: 6px; margin-bottom: 10px; outline: none; }
.notice { margin-top: 12px; font-size: 0.9rem; line-height: 1.5; word-break: break-word; }
.account-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; align-items: start; }
.user-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.targets-editor { margin-top: 12px; padding: 14px; background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: 10px; }
.target-row { display: grid; grid-template-columns: 1.1fr 2fr 1.2fr 0.7fr auto; gap: 8px; margin-bottom: 8px; }
.target-row input { background: #1f1f1f; border: 1px solid var(--border); color: white; padding: 8px; border-radius: 6px; outline: none; min-width: 0; }
@media (max-width: 768px) { .target-row { grid-template-columns: 1fr 1fr; } }

.auth-wrap { min-height: 100vh; width: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; overflow-y: auto; }
.auth-card { width: 100%; max-width: 440px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 28px; }
.auth-card h1 { color: var(--accent); font-size: 1.6rem; margin-bottom: 6px; }
.auth-tabs { display: flex; gap: 6px; margin: 18px 0; }
.auth-tabs button { flex: 1; background: #0a0a0a; color: var(--text-muted); border: 1px solid var(--border); padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.auth-tabs button.active { background: #2a2a2a; color: var(--text-main); }
.auth-card .btn-primary { width: 100%; padding: 11px; }
.auth-error { color: var(--red); font-size: 0.88rem; margin: 10px 0; min-height: 1.2em; }
.recovery-key { font-family: ui-monospace, monospace; font-size: 1.15rem; letter-spacing: 1px; background: #0a0a0a; border: 1px dashed var(--accent); border-radius: 10px; padding: 14px; text-align: center; margin: 14px 0; word-break: break-all; user-select: all; }


/* --- Titres des cartes (pages Compte et Crypto & Matières) : même style discret que le reste du tableau de bord --- */
#view-alt .card h2, #view-account .card h2 { font-size: 1.05rem; font-weight: 500; color: var(--text-muted); margin-bottom: 14px; }
#view-alt h1, #view-account h1 { font-size: 1.8rem; }

/* Formulaire d'ajout : une rangée de champs qui se replie selon la largeur */
.alt-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: center; }
.alt-form .field { margin-bottom: 0; min-width: 0; }
.alt-form .btn-primary { width: 100%; }

/* Espacement régulier (30 px) entre toutes les cartes, à la verticale comme à l'horizontale */
#view-alt .top-grid, #view-alt .account-grid, #view-account .account-grid { gap: 30px; }
#view-alt .assets-section h2 { margin-bottom: 15px; }
.assets-grid .alt-empty { grid-column: 1 / -1; }

/* --- Notes Explicatives (Post-it) --- */
.post-it {
    background: rgba(200, 154, 116, 0.1);
    border-left: 3px solid var(--accent);
    padding: 12px 15px;
    border-radius: 0 8px 8px 0;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.post-it strong {
    color: var(--accent);
    display: block;
    margin-bottom: 4px;
    font-size: 0.85rem;
}
.post-it-sidebar {
    padding: 8px 10px;
    margin: 6px 0 12px 0;
    font-size: 0.75rem;
}

/* --- Notifications (Toasts) --- */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { background: var(--bg-card); border-left: 4px solid var(--accent); color: var(--text-main); padding: 15px 20px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.6); opacity: 0; transform: translateX(100%); animation: slideIn 0.3s forwards; pointer-events: auto; font-size: 0.9rem; max-width: 350px; line-height: 1.4; }
@keyframes slideIn { to { opacity: 1; transform: translateX(0); } }
.toast.fade-out { animation: fadeOut 0.3s forwards; }
@keyframes fadeOut { to { opacity: 0; transform: translateX(100%); } }
.toast-error { border-left-color: var(--red); }
.toast-success { border-left-color: var(--green); }