/* ============================================================================
 *  styles.css — Design system (thème clair + sombre) pour Portfolio.
 * ==========================================================================*/
:root {
  --ink: #1f2a37;
  --brand: #274060;
  --brand-2: #35597f;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f4f7fb;
  --border: #dbe2ec;
  --muted: #6b7280;
  --good: #1b7f4b;
  --good-bg: #e5f4ec;
  --bad: #c0392b;
  --bad-bg: #fbe7e5;
  --warn: #b7791f;
  --warn-bg: #fdf3e2;
  --info-bg: #e8eff7;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --radius: 14px;
  --radius-sm: 9px;
}
[data-theme="dark"] {
  --ink: #e6ebf2;
  --brand: #7ea8d8;
  --brand-2: #9cc0e6;
  --bg: #0f151d;
  --surface: #172230;
  --surface-2: #1d2a3a;
  --border: #2a3a4d;
  --muted: #93a1b3;
  --good: #4ade80; --good-bg: #10241a;
  --bad: #f87171; --bad-bg: #2a1615;
  --warn: #fbbf24; --warn-bg: #2a2110;
  --info-bg: #14202e;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---- Structure ---- */
.layout { display: grid; grid-template-columns: 200px 1fr; min-height: 100%; }
.sidebar {
  background: var(--brand); color: #fff; padding: 20px 14px;
  display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh;
}
[data-theme="dark"] .sidebar { background: #101a26; }
.brand { font-size: 17px; font-weight: 700; letter-spacing: .2px; padding: 6px 10px 18px; display: flex; align-items: center; gap: 8px; }
.brand-mark { color: #9cc0e6; display: inline-flex; align-items: center; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; border: 0; color: #cdd8e6; padding: 10px 12px;
  border-radius: 10px; font-size: 14px; cursor: pointer; transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav-ico { width: 20px; text-align: center; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  /* Hauteur constante sur tous les onglets, même sans filtres de date (Budget /
     Réglages) : alignée sur la variante avec les boutons de navigation (34px). */
  min-height: 60px;
}
.topbar-title { font-size: 20px; font-weight: 700; margin: 0; }
.topbar-tools { display: flex; align-items: center; gap: 12px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.topbar-filters { display: flex; align-items: center; }
/* Dans la barre du haut, la barre de contrôles ne pousse plus vers la droite. */
.topbar-filters .range-toolbar { margin-left: 0; }
/* Les contrôles du tableau de bord (granularité segmentée) sont ajustés pour ne
   pas dépasser la hauteur du sélecteur de mois des autres onglets : la barre du
   haut garde ainsi la MÊME hauteur (60px) sur toutes les vues. */
.topbar .segmented { padding: 2px; }
.topbar .seg { padding: 4px 12px; }
.month-nav { display: flex; align-items: center; gap: 10px; }
.month-label { font-weight: 600; min-width: 130px; text-align: center; }
.round-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 16px; line-height: 1;
}
.round-btn:hover { background: var(--surface-2); }
.view { padding: 24px; overflow: auto; }

/* ---- Titres ---- */
.view-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.view-head h1 { font-size: 22px; margin: 0; }
.view-head .muted { margin: 0; }
.view-head .btn { margin-left: auto; }
/* Bannière d'alerte placée sur la même ligne que le bouton d'action. */
.view-head .banner { flex: 1; margin-bottom: 0; }
.view-head .segmented { margin-left: auto; }

/* ---- En-tête de section + barre de contrôles de l'analyse d'évolution ---- */
.section-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 26px 0 14px; }
.section-head h2 { font-size: 17px; margin: 0; }
.section-head .muted { margin: 0; }
.range-toolbar { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.range-toolbar .sel { width: auto; padding: 6px 8px; }
.range-sep { width: 1px; align-self: stretch; background: var(--border); margin: 2px 4px; }

/* ---- Sélecteur segmenté (fenêtre temporelle) ---- */
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 13px; }
.seg:hover { color: var(--ink); }
.seg.active { background: var(--surface); color: var(--brand); font-weight: 600; box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sub { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }

/* ---- Cartes ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card-title { font-size: 14px; margin: 0 0 14px; color: var(--ink); font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 960px) { .grid-2 { grid-template-columns: 1fr; } .layout { grid-template-columns: 72px 1fr; } .brand span:last-child, .nav-item span:last-child { display: none; } }

/* ---- KPI ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 18px; align-items: stretch; }
.kpi-grid.three { grid-template-columns: repeat(3, 1fr); }
.kpi-grid.four { grid-template-columns: repeat(4, 1fr); }
.kpi-grid.five { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 1200px) { .kpi-grid, .kpi-grid.four, .kpi-grid.five { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px) { .kpi-grid, .kpi-grid.three, .kpi-grid.four, .kpi-grid.five { grid-template-columns: repeat(2, 1fr); } }
/* La pastille (.kpi) garde sa hauteur naturelle : toutes les pastilles ont la
   même taille ; la date de MàJ éventuelle se pose juste en dessous, sans
   étirer la carte. */
.kpi-cell { display: flex; flex-direction: column; align-items: stretch; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border-left: 4px solid var(--brand-2); }
.kpi.good { border-left-color: var(--good); }
.kpi.bad { border-left-color: var(--bad); }
/* Donnée manquante / non renseignée : pastille grise (ni bon, ni mauvais, ni neutre). */
.kpi.na { border-left-color: var(--muted); }
.kpi-date { font-size: 10px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); opacity: .85; margin-top: 6px; padding-left: 2px; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.kpi.good .kpi-value { color: var(--good); }
.kpi.bad .kpi-value { color: var(--bad); }
.kpi.na .kpi-value { color: var(--muted); }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---- Bannières ---- */
.banner { border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; font-size: 13px; border: 1px solid transparent; }
.banner.info { background: var(--info-bg); border-color: var(--border); }
.banner.good { background: var(--good-bg); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.banner.warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.bad { background: var(--bad-bg); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }

/* ---- Tableaux ---- */
.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 8px; border-bottom: 1px solid var(--border); }
.grid td { padding: 5px 8px; border-bottom: 1px solid var(--surface-2); }
.grid tbody tr:nth-child(even) { background: var(--surface-2); }
.grid .right, .grid th.right { text-align: right; }
.grid tfoot .total td, .grid tr.total td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border); }
.grid.kv td:first-child { color: var(--ink); }
.grid.kv tr.total td { font-weight: 700; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }

/* ---- Champs ---- */
.num, .txt, .sel {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 6px 9px; font: inherit; width: 100%;
}
.num { text-align: right; max-width: 130px; }
.num.sm { max-width: 90px; }
.txt { min-width: 90px; }
.num:focus, .txt:focus, .sel:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: var(--brand-2); }
.right .num, .right .txt { margin-left: auto; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; border-radius: 6px; padding: 3px 6px; }
.icon-btn:hover { background: var(--bad-bg); color: var(--bad); }
.add-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }

/* ---- Cases à cocher « chips » (sélection de produits à comparer) ---- */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 4px 11px 4px 9px; font-size: 12px; user-select: none;
}
.chip:hover { background: var(--surface-2); }
.chip.on { color: var(--ink); border-color: var(--brand-2); background: var(--surface-2); font-weight: 600; }
.chip input { margin: 0; accent-color: var(--brand); }
.chip .dot { margin-right: 0; }

/* Menu déroulant à cases à cocher (filtre « Performance par produit ») */
.dropdown { position: relative; display: inline-block; margin-bottom: 12px; }
.dropdown > summary {
  cursor: pointer; list-style: none; user-select: none;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 6px 12px; font-size: 12px; font-weight: 600;
}
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown > summary::after { content: '▾'; color: var(--muted); font-size: 10px; }
.dropdown[open] > summary::after { content: '▴'; }
.dropdown > summary:hover { background: var(--surface-2); }
.dropdown-panel {
  position: absolute; z-index: 20; margin-top: 6px; min-width: 220px; max-width: 340px;
  max-height: 280px; overflow: auto; padding: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
}
.dropdown-panel .chip-row { margin-bottom: 8px; }
.linklike {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--brand); font-size: 12px; text-decoration: underline;
}

.btn { border: 1px solid var(--border); background: var(--surface); color: var(--ink); border-radius: 9px; padding: 8px 14px; cursor: pointer; font: inherit; }
.btn:hover { background: var(--surface-2); }
.btn.sm { padding: 6px 10px; }
.btn.ghost { border-style: dashed; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger:hover { background: var(--bad-bg); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 4px; }

/* ---- Formulaires ---- */
.form-block { margin-bottom: 8px; }
.form-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.form-row label { flex: 1; display: flex; align-items: center; gap: 6px; }
.form-row.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; font-weight: 700; }
/* Séparateur entre deux sous-réglages d'une même carte (ex. cible + seuil de dérive). */
.settings-divider { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 12px; }
.unit { color: var(--muted); }

/* ---- Titres de section mis en évidence ---- */
.card.section-lead > .card-title { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; padding-bottom: 10px; margin-bottom: 12px; border-bottom: 2px solid var(--border); }

/* ---- Encart guide repliable ---- */
.guide-details > summary { cursor: pointer; font-weight: 600; color: var(--brand); list-style: none; padding: 4px 0; }
.guide-details > summary::-webkit-details-marker { display: none; }
.guide-details > summary::before { content: '▸ '; }
.guide-details[open] > summary::before { content: '▾ '; }
.guide-details .grid { margin-top: 10px; }

/* ---- Popup de suppression d'un objet (croix ✕) ---- */
.modal-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(16,24,40,.5); }
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,.6); }
.modal { background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; width: 100%; max-width: 420px; }
.modal h3 { margin: 0 0 6px; font-size: 17px; }
.modal p.muted { margin: 0 0 16px; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.modal-actions .btn { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 11px 14px; }
.modal-actions .btn.ghost { text-align: center; align-items: center; }
.modal-btn-sub { font-size: 11px; color: var(--muted); font-weight: 400; }
.modal-actions .btn.danger .modal-btn-sub { color: color-mix(in srgb, var(--bad) 70%, var(--muted)); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
[data-theme="dark"] .btn.primary { color: #0f151d; }

/* ---- Formulaire du prêt immobilier (modal « calcul auto du CRD ») ---- */
.loan-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.loan-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.loan-form input { max-width: none; width: 100%; text-align: left; }
.modal .banner { margin-bottom: 16px; }
.modal .banner div + div { margin-top: 3px; }

/* ---- Table du budget récurrent (colonnes serrées) ---- */
.budget-grid th, .budget-grid td { padding: 5px 5px; }
.budget-grid .txt { min-width: 0; }
.budget-grid .num { max-width: 74px; padding: 6px 6px; }
.budget-grid .sel { padding: 6px 4px; }
.budget-grid td.muted { white-space: nowrap; }

/* ---- Groupes par établissement (Investissements) ---- */
.inst-group { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 8px; background: var(--surface-2); }
.inst-head { display: flex; align-items: center; gap: 8px; }
.inst-name { flex: 1; border: 1px solid transparent; background: transparent; color: var(--ink); font-size: 14px; font-weight: 700; border-radius: 8px; padding: 3px 6px; }
.inst-name:hover { border-color: var(--border); }
.inst-name:focus { outline: 2px solid var(--brand-2); border-color: var(--brand-2); background: var(--surface); }
.inst-total { font-weight: 700; color: var(--brand); white-space: nowrap; }
.inst-group .grid.compact { background: var(--surface); border-radius: 8px; margin-top: 6px; }
.grid.compact th { padding: 5px 8px; }
.grid.compact td { padding: 3px 8px; }
.grid.compact tbody tr:nth-child(even) { background: var(--surface-2); }
.grid.compact .sel { max-width: 160px; }
.grid.compact .num { padding: 4px 8px; }
.grid.compact .txt { padding: 4px 8px; }
.inst-group .empty { padding: 6px 4px; margin: 0; }
.inst-group .add-row { margin-top: 6px; }
.inst-grandtotal { display: flex; justify-content: space-between; font-weight: 700; padding: 10px 12px; border-top: 2px solid var(--border); font-size: 15px; }
.inst-grandtotal span:last-child { color: var(--brand); }

/* ---- Sous-sections des biens immobiliers (locatif / résidence) ---- */
.prop-group { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--surface-2); margin-bottom: 16px; }
.prop-group:last-child { margin-bottom: 0; }
.prop-group-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; color: var(--ink); margin: 0 0 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.prop-group .grid.compact { background: var(--surface); border-radius: 8px; }
.prop-group .empty { padding: 4px 2px; margin: 0; }
.prop-group .add-row { margin-top: 8px; }

/* ---- Répartition hiérarchique (Immobilier parent + sous-catégories) ---- */
.alloc-parent td { font-weight: 600; }
.alloc-sub td:first-child { padding-left: 24px; font-size: 12px; color: var(--muted); }
.alloc-sub td { border-bottom-color: transparent !important; background: transparent !important; }

/* ---- Patrimoine global : actifs / passifs ---- */
.patri-split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 620px) { .patri-split { grid-template-columns: 1fr; } }
.patri-split .sub { margin-top: 0; }
.patri-net { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--info-bg); border: 1px solid var(--border); font-weight: 700; font-size: 15px; }
.patri-net span:last-child { color: var(--brand); }

/* ---- Graphiques ---- */
.chart { width: 100%; }
.chart.donut { max-width: 240px; margin: 0 auto; }
.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; font-size: 12px; color: var(--muted); }
.legend-item { display: flex; align-items: center; gap: 6px; }

/* ---- Jauge épargne ---- */
.gauge { position: relative; height: 30px; background: var(--surface-2); border-radius: 16px; overflow: hidden; border: 1px solid var(--border); margin-bottom: 14px; }
.gauge-fill { height: 100%; background: var(--good); transition: width .3s; }
.gauge-fill.ko { background: var(--bad); }
.gauge-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }

/* ---- Pastilles d'action ---- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.ok { background: var(--surface-2); color: var(--muted); }
.pill.up { background: var(--good-bg); color: var(--good); }
.pill.down { background: var(--bad-bg); color: var(--bad); }
.warn-text { color: var(--warn); font-weight: 600; }

/* ---- Synchronisation multi-appareils (Réglages) ---- */
.sync-toggle { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.sync-field { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; }
.sync-field > label { font-size: 12px; color: var(--muted); }
.sync-input { width: 100%; max-width: none; text-align: left; }
.sync-backups { margin-top: 8px; }
.sync-backups-list { border-top: 1px solid var(--border); margin-top: 4px; }
.sync-backups-list .form-row label { font-size: 13px; }

/* ---- Toast ---- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
