:root {
    --bg-global: #f8fafc; --bg-card: #ffffff; --bg-input: #f1f5f9;
    --text-main: #0f172a; --text-muted: #64748b; --text-light: #94a3b8;
    --btn-primary-bg: #0f172a; --btn-primary-text: #ffffff;
    --btn-secondary-border: #0f172a; --btn-secondary-text: #0f172a; --btn-secondary-hover: #f1f5f9;
    --green-perf: #10b981; --green-bg: #ecfdf5;
    --red-perf: #f43f5e; --red-bg: #fff1f2;
    --radius: 12px; --border: 1px solid #e2e8f0;
}
body.dark-theme {
    --bg-global: #0f172a; --bg-card: #1e293b; --bg-input: #334155;
    --text-main: #f8fafc; --text-muted: #94a3b8; --text-light: #64748b;
    --btn-primary-bg: #f8fafc; --btn-primary-text: #0f172a;
    --btn-secondary-border: #f8fafc; --btn-secondary-text: #f8fafc; --btn-secondary-hover: #334155;
    --green-perf: #34d399; --green-bg: rgba(16, 185, 129, 0.15);
    --red-perf: #fb7185; --red-bg: rgba(244, 63, 94, 0.15);
    --border: 1px solid #334155;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, sans-serif; background: var(--bg-global); color: var(--text-main); padding: 16px; min-height: 100vh; display: flex; flex-direction: column; overflow-y: scroll; transition: background 0.3s, color 0.3s; }
.container { max-width: 680px; margin: 0 auto; width: 100%; }

.view { display: none; animation: fadeIn 0.3s ease-in-out; }
.view.active { display: block !important; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.montant { transition: filter 0.2s ease; }
body.privacy-mode .montant { filter: blur(6px); opacity: 0.5; user-select: none; pointer-events: none; }

.header-title { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 24px; }
.header-actions-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
#btn-nav-profil { padding: 6px 14px; font-size: 0.8rem; border-radius: 20px; font-weight: bold; }
.btn-theme { background: none; border: none; font-size: 1.1rem; cursor: pointer; padding: 6px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }

.status-badge { font-size: 0.72rem; font-weight: 600; padding: 6px 12px; border-radius: 20px; display: inline-flex; align-items: center; gap: 6px; }
.status-badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.badge-local { background: var(--bg-input); color: var(--text-muted); }
.badge-local::before { background: var(--text-light); }
.badge-cloud { background: var(--green-bg); color: var(--green-perf); }
.badge-cloud::before { background: var(--green-perf); }

.main-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; background: var(--bg-card); padding: 20px; border-radius: var(--radius); border: var(--border); margin-bottom: 16px; }
.metric-box { display: flex; flex-direction: column; justify-content: center; }
.metric-box.mini { padding: 10px; border: var(--border); background: var(--bg-input); border-radius: 8px; }
.metric-box.mini .label { font-size: 0.65rem; margin-bottom: 2px; }
.metric-box.mini .value-sub { font-size: 0.95rem; }

.label { font-size: 0.7rem; text-transform: uppercase; color: var(--text-muted); font-weight: 700; margin-bottom: 4px; letter-spacing: 0.5px; }
.value { font-size: clamp(1.2rem, 4.5vw, 1.6rem); font-weight: 800; white-space: nowrap; }
.value-perf { font-size: 1.2rem; font-weight: 800; display: inline-flex; align-items: center; gap: 4px; }
.value-sub { font-size: 1.1rem; font-weight: 700; }
.perf-positive { color: var(--green-perf); } .perf-negative { color: var(--red-perf); }
.bg-positive { background: var(--green-bg); color: var(--green-perf); } .bg-negative { background: var(--red-bg); color: var(--red-perf); }

.pea-limit-container { width: 100%; height: 6px; background: var(--bg-input); border-radius: 4px; margin-top: 6px; overflow: hidden; }
.pea-limit-fill { height: 100%; background: var(--text-main); transition: width 0.4s ease; }
#pea-limit-text { font-size: 0.7rem; color: var(--text-muted); font-weight: bold; display: block; }

input, select { padding: 10px; border: var(--border); border-radius: 8px; font-size: 0.9rem; background: var(--bg-input); color: var(--text-main); width: 100%; outline: none; }
input:focus, select:focus { border-color: var(--text-muted); }
.btn-submit { background: var(--btn-primary-bg); color: var(--btn-primary-text); border: none; padding: 10px 16px; border-radius: 8px; font-weight: 700; cursor: pointer; font-size: 0.9rem; transition: opacity 0.2s; }
.btn-submit:hover:not(:disabled) { opacity: 0.9; }
.btn-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: transparent; color: var(--btn-secondary-text); border: 2px solid var(--btn-secondary-border); }
.btn-secondary:hover:not(:disabled) { background: var(--btn-secondary-hover); }
.btn-block { width: 100%; }
.form-section { background: var(--bg-card); padding: 16px; border-radius: var(--radius); border: var(--border); margin-bottom: 16px; }

/* Styles Simulations et Autocomplete */
.simulation-box { background: var(--bg-input); padding: 12px; border-radius: 8px; font-size: 0.85rem; display: flex; flex-direction: column; border: 1px solid var(--border); }
.duplicate-alert { display: none; color: #d97706; font-weight: 600; padding-top: 8px; border-top: 1px solid var(--border); margin-top: 6px; }
body.dark-theme .duplicate-alert { color: #fbbf24; }
.text-danger { color: var(--red-perf) !important; }
.autocomplete-wrapper { position: relative; }
.autocomplete-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--bg-card); border: var(--border); border-radius: 8px; max-height: 200px; overflow-y: auto; z-index: 1000; display: none; box-shadow: 0 4px 12px rgba(0,0,0,0.15); margin-top: 4px; }
.autocomplete-item { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--bg-input); font-size: 0.85rem; display: flex; justify-content: space-between; align-items: center; }
.autocomplete-item:hover { background: var(--bg-input); }
.autocomplete-item small { color: var(--text-muted); font-weight: bold; }

.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; }
.btn-max { background: var(--text-main); color: var(--bg-card); border: none; padding: 0 16px; border-radius: 8px; font-weight: bold; cursor: pointer; font-size: 0.8rem; transition: 0.2s; }
.btn-max:hover { opacity: 0.8; }
.sim-text { font-size: 0.8rem; color: var(--text-muted); margin-top: -6px; margin-left: 4px; display: block; font-style: italic; font-weight: 600; }

.positions-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.card { background: var(--bg-card); padding: 14px; border-radius: var(--radius); border: var(--border); display: flex; justify-content: space-between; align-items: center; cursor: pointer; transition: border-color 0.2s, transform 0.2s; }
.card:hover { border-color: var(--text-muted); transform: translateY(-1px); }
.card-info, .card-values { display: flex; flex-direction: column; gap: 2px; }
.card-values { align-items: flex-end; }
.ticker-wrap { display: flex; align-items: center; gap: 6px; }
.ticker { font-weight: 800; font-size: 0.95rem; }
.type-badge { font-size: 0.6rem; font-weight: bold; padding: 2px 5px; border-radius: 4px; color: white; display: inline-block; }
.type-badge.action { background: #3b82f6; } .type-badge.etf { background: #8b5cf6; }
.allocation-badge { font-size: 0.65rem; background: var(--bg-input); padding: 2px 6px; border-radius: 4px; color: var(--text-muted); font-weight: bold; }
.nom-actif { font-size: 0.8rem; color: var(--text-muted); }
.valeur-actuelle { font-weight: 700; font-size: 1rem; }
.perf-badge { font-size: 0.75rem; font-weight: bold; padding: 2px 6px; border-radius: 4px; margin-top: 2px; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.2s ease; z-index: 100; padding: 16px; }
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-content { background: var(--bg-card); width: 100%; max-width: 440px; padding: 20px; border-radius: var(--radius); border: var(--border); transform: translateY(12px); transition: transform 0.2s ease; max-height: 90vh; overflow-y: auto; }
.modal-overlay.active .modal-content { transform: translateY(0); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.btn-close { background: var(--bg-input); border: none; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; color: var(--text-main); display: flex; align-items: center; justify-content: center; }
.modal-tabs { display: flex; gap: 4px; margin-bottom: 16px; background: var(--bg-input); padding: 4px; border-radius: 8px; }
.tab-btn { flex: 1; background: none; border: none; padding: 6px; font-size: 0.8rem; font-weight: bold; color: var(--text-muted); cursor: pointer; border-radius: 6px; transition: all 0.2s; }
.tab-btn.active { background: var(--bg-card); color: var(--text-main); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.modal-form { display: flex; flex-direction: column; gap: 12px; }
.btn-danger { background: none; border: none; color: var(--red-perf); font-weight: bold; cursor: pointer; width: 100%; padding: 8px; border-radius: 6px; transition: background 0.2s; }
.btn-danger:hover { background: var(--red-bg); }

.history-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.history-table th, .history-table td { padding: 10px 6px; text-align: left; border-bottom: 1px solid var(--bg-input); vertical-align: middle; }
.history-table th { color: var(--text-muted); font-weight: 700; }
.tx-badge-in { background: var(--green-bg); color: var(--green-perf); padding: 2px 6px; border-radius: 4px; font-weight: bold; }
.tx-badge-out { background: var(--red-bg); color: var(--red-perf); padding: 2px 6px; border-radius: 4px; font-weight: bold; }

.chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 10px; }
.chart-main-tabs { display: flex; background: var(--bg-input); padding: 4px; border-radius: 8px; gap: 2px; }
.chart-tab-btn { background: none; border: none; padding: 6px 12px; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); cursor: pointer; border-radius: 6px; }
.chart-tab-btn.active { background: var(--bg-card); color: var(--text-main); box-shadow: 0 1px 2px rgba(0,0,0,0.1); }
#btn-toggle-chart { font-size: 0.75rem; padding: 6px 12px; border-radius: 20px; background: var(--bg-input); border: none; cursor: pointer; color: var(--text-main); font-weight: bold; }
.chart-container { width: 100%; margin: 0 auto; display: none; position: relative; }

#toast-container { position: fixed; bottom: 20px; right: 20px; left: 20px; max-width: 320px; margin-left: auto; display: flex; flex-direction: column; gap: 10px; z-index: 9999; }
.toast { background: var(--bg-card); border: var(--border); border-left: 4px solid var(--text-main); color: var(--text-main); padding: 12px 16px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.08); font-size: 0.85rem; font-weight: 600; animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.toast.success { border-left-color: var(--green-perf); }
.toast.error { border-left-color: var(--red-perf); }
.toast.fade-out { animation: fadeOut 0.2s ease-in forwards; }
@keyframes slideInRight { from { transform: translateX(30px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(6px); } }

body.app-loading main { opacity: 0; pointer-events: none; }
body.app-loading::after { content: "⏳ Chargement de l'application..."; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); font-weight: bold; color: var(--text-muted); font-size: 0.95rem; }

@media (min-width: 640px) { 
    .border-desktop { border-left: var(--border) !important; padding-left: 16px; } 
    .border-top { border-top: none !important; } 
}