:root {
    --bg: #0f1115;
    --card: #181b22;
    --line: #262b35;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --accent: #4f8cff;
    --map-empty: #232733;
}

/* ── Light mode ───────────────────────────────────────────────────────────── */
[data-theme="light"] {
    --bg: #f6f7f9;
    --card: #ffffff;
    --line: #e2e6ec;
    --text: #1a1d24;
    --muted: #5b6472;
    --accent: #2f6df0;
    --map-empty: #e6eaf0;
}
[data-theme="light"] .mode-switch { background: #eef1f5; }
[data-theme="light"] .theme-toggle,
[data-theme="light"] .lang-switch button,
[data-theme="light"] .view-switch button { background: #eef1f5; }
[data-theme="light"] .preset { background: #f1f3f7; }
[data-theme="light"] .preset.active { background: #e2ecff; }
[data-theme="light"] .slider-track { background: #cfd6e0; }
[data-theme="light"] .slider-track::before { background: #ffffff; }
[data-theme="light"] tbody tr.main:hover { background: #eef1f5; }
[data-theme="light"] .detail td { background: #eef1f5; }
[data-theme="light"] .detail-item,
[data-theme="light"] .fiscal { background: #ffffff; }
[data-theme="light"] .detail-item.regime-on { background: #fdf6e3; }
[data-theme="light"] .map-box { background: #e9eef5; }
[data-theme="light"] #map .ocean { fill: #e9eef5; }
[data-theme="light"] #map .country { stroke: #ffffff; }
[data-theme="light"] #map .marker { stroke: #ffffff; }
[data-theme="light"] #map .country.selected,
[data-theme="light"] #map .marker.selected { stroke: #1a1d24; }
[data-theme="light"] .country-panel { background: #ffffff; }
* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 960px; margin: 0 auto; padding: 32px 20px 64px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar-ctrls { display: flex; align-items: center; gap: 10px; }
.theme-toggle {
    background: #20242d; border: 1px solid var(--line); border-radius: 8px;
    padding: 6px 10px; font-size: 15px; line-height: 1; cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); }
.lang-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lang-switch button {
    background: #20242d;
    color: var(--muted);
    border: none;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.lang-switch button + button { border-left: 1px solid var(--line); }
.lang-switch button.active { background: var(--accent); color: #10131a; }
h1 { margin: 0 0 6px; font-size: 28px; }
.sub { color: var(--muted); margin: 0 0 18px; max-width: 70ch; }

/* ── Switch de comparateur (Liberté / Immobilier) ────────────────────────── */
.mode-switch { display: inline-flex; gap: 6px; background: #14171e; border: 1px solid var(--line); border-radius: 10px; padding: 4px; margin-bottom: 24px; flex-wrap: wrap; }
.mode-switch button {
    background: transparent; color: var(--muted); border: none;
    padding: 8px 16px; font-size: 14px; font-weight: 600; cursor: pointer; border-radius: 7px;
    transition: background .15s, color .15s;
}
.mode-switch button:hover { color: var(--text); }
.mode-switch button.active { background: var(--accent); color: #10131a; }
#re-table { width: 100%; border-collapse: collapse; }
.re-ownership { font-size: 13px; color: var(--text); margin: -6px 0 14px; }
.re-excluded { font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.re-excluded .excl-item { color: #d98a8a; cursor: help; border-bottom: 1px dotted #d98a8a; }
.re-sources { font-size: 11px; color: var(--muted); margin-top: 14px; }
.re-sources a { color: var(--accent); text-decoration: none; }
.re-sources a:hover { text-decoration: underline; }
.detail-item .src { color: var(--accent); text-decoration: none; font-size: 11px; }
.detail-item .src-est { color: var(--muted); font-size: 10px; font-style: italic; }
.re-portal { padding: 0 16px 14px; }
.re-portal a { display: inline-block; background: var(--accent); color: #10131a; font-weight: 600; font-size: 13px; padding: 7px 14px; border-radius: 8px; text-decoration: none; }
.re-portal a:hover { filter: brightness(1.1); }
em { color: var(--text); font-style: italic; }

.panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 28px;
}
@media (max-width: 720px) { .panel { grid-template-columns: 1fr; } }
.block-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 12px; }
.total { color: var(--accent); margin-left: 6px; letter-spacing: 0; }

.presets {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}
.preset {
    position: relative;
    text-align: left;
    background: #20242d;
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 8px;
    padding: 12px 14px;
    min-height: 56px;
    cursor: pointer;
    user-select: none;            /* un glissé ne sélectionne plus le texte */
    transition: border-color .15s, background .15s;
}
.preset:hover { border-color: var(--accent); }
.preset.active { border-color: var(--accent); background: #1c2740; }
/* les clics visent toujours le bouton, jamais les <span> internes */
.preset .pname,
.preset .pdesc,
.preset .ptip { display: block; pointer-events: none; }
.preset .pname { font-weight: 600; font-size: 13px; }
.preset .pdesc { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Infobulle au survol */
.preset .ptip {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translateX(-50%);
    width: 240px;
    max-width: 80vw;
    background: #0b0d11;
    border: 1px solid var(--accent);
    color: var(--text);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.45;
    text-align: left;
    padding: 9px 11px;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
    opacity: 0;
    visibility: hidden;
    transition: opacity .15s;
    z-index: 20;
}
.preset .ptip::after {           /* petite flèche */
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--accent);
}
.preset:hover .ptip { opacity: 1; visibility: visible; }

.sliders { display: flex; flex-direction: column; gap: 14px; }
.slider-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.slider-row label { font-size: 13px; font-weight: 600; }
.slider-row .val { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; min-width: 42px; text-align: right; }
.slider-desc { grid-column: 1 / -1; margin: 2px 0 2px; font-size: 11px; line-height: 1.4; color: var(--muted); }
.slider-row input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); cursor: pointer; user-select: none; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.main { cursor: pointer; }
tbody tr.main:hover { background: #1d212a; }
.score-pill { display: inline-block; min-width: 48px; padding: 2px 8px; border-radius: 6px; color: #10131a; font-weight: 700; font-variant-numeric: tabular-nums; }

.detail td { background: #14171e; padding: 0; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; padding: 14px 16px; }
.detail-item { background: #1b1f27; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.detail-item .dlabel { font-size: 11px; color: var(--muted); }
.detail-item .drow { display: flex; justify-content: space-between; margin-top: 4px; font-size: 13px; }
.detail-item .contrib { color: var(--accent); font-variant-numeric: tabular-nums; }
.detail-item.regime-on { border-color: #d9a441; background: #241f15; }
.detail-item.regime-on .dlabel { color: #e0b84f; }
.muted { color: var(--muted); }
footer { margin-top: 32px; color: var(--muted); font-size: 12px; }

/* ── Toggle régimes spéciaux ─────────────────────────────────────────────── */
.regime-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 20px;
}
.regime-text { display: flex; flex-direction: column; }
.regime-name { font-weight: 600; font-size: 14px; }
.regime-help { font-size: 12px; color: var(--muted); margin-top: 2px; max-width: 70ch; }

/* interrupteur (checkbox stylé) */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: 0 0 auto; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.slider-track {
    position: absolute; inset: 0;
    background: #2a2f3a; border: 1px solid var(--line); border-radius: 999px;
    transition: background .15s;
}
.slider-track::before {
    content: ''; position: absolute; left: 3px; top: 50%; transform: translateY(-50%);
    width: 18px; height: 18px; border-radius: 50%; background: #c9ced8; transition: transform .15s;
}
.switch input:checked + .slider-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider-track::before { transform: translate(20px, -50%); background: #fff; }

/* ── Badge régime dans le tableau ────────────────────────────────────────── */
.regime-badge {
    position: relative;
    display: inline-block;
    margin-left: 8px;
    padding: 1px 7px;
    font-size: 11px; font-weight: 600;
    color: #1a1407; background: #e0b84f; border-radius: 999px;
    cursor: help;
}
.regime-badge .rtip {
    position: absolute;
    left: 0; bottom: calc(100% + 8px);
    width: 260px; max-width: 70vw;
    background: #0b0d11; border: 1px solid #e0b84f; color: var(--text);
    font-size: 12px; font-weight: 400; line-height: 1.45; text-align: left;
    padding: 9px 11px; border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
    opacity: 0; visibility: hidden; transition: opacity .15s; z-index: 30;
}
.regime-badge:hover .rtip { opacity: 1; visibility: visible; }

/* ── Barre de vue (Liste / Carte) ────────────────────────────────────────── */
.view-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.view-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.view-switch button {
    background: #20242d; color: var(--muted); border: none;
    padding: 7px 18px; font-size: 13px; font-weight: 600; cursor: pointer;
    transition: background .15s, color .15s;
}
.view-switch button + button { border-left: 1px solid var(--line); }
.view-switch button.active { background: var(--accent); color: #10131a; }
.count-info { font-size: 12px; color: var(--muted); }

/* ── Carte ───────────────────────────────────────────────────────────────── */
.map-box { background: #0c0e13; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
#map { display: block; width: 100%; height: auto; }
#map .ocean { fill: #0c0e13; }
#map .country {
    stroke: #0c0e13; stroke-width: .4;
    fill: var(--map-empty);
    cursor: pointer; transition: opacity .1s;
}
#map .country:hover { opacity: .8; }
#map .country.selected { stroke: #fff; stroke-width: 1.1; }
#map .marker { stroke: #0c0e13; stroke-width: 1; cursor: pointer; }
#map .marker:hover { stroke: #fff; }
#map .marker.selected { stroke: #fff; stroke-width: 1.5; }

/* ── Panneau d'avantages ─────────────────────────────────────────────────── */
.country-panel {
    position: relative;
    margin-top: 14px;
    background: var(--card); border: 1px solid var(--line); border-radius: 12px;
    padding: 16px 18px; min-height: 60px;
}
.map-hint { color: var(--muted); font-size: 13px; margin: 4px 0; }
.panel-close {
    position: absolute; top: 10px; right: 12px;
    background: none; border: none; color: var(--muted);
    font-size: 22px; line-height: 1; cursor: pointer;
}
.panel-close:hover { color: var(--text); }
.panel-title { margin: 0 0 12px; font-size: 18px; padding-right: 24px; }
.tcard { border-top: 1px solid var(--line); padding: 12px 0; }
.tcard:first-of-type { border-top: none; }
.tcard-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tcard-head .tname { font-weight: 600; }
.adv-regime { margin-top: 8px; font-size: 12px; color: #e0b84f; }
.adv-list { margin: 8px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }
.adv-list li { font-size: 13px; }
.adv-list li.muted { list-style: none; margin-left: -18px; }

/* ── Bloc fiscal (personnel vs entreprise) ───────────────────────────────── */
.fiscal { margin-top: 10px; background: #1b1f27; border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; font-size: 12px; }
.fiscal .frow { margin: 2px 0; }
.fiscal .flabel { display: inline-block; min-width: 74px; color: var(--muted); text-transform: uppercase; font-size: 10px; letter-spacing: .04em; }
.fiscal b { color: var(--text); font-weight: 600; }
.fiscal .fnote { margin-top: 4px; font-size: 10px; color: var(--muted); font-style: italic; }
.fiscal-na { color: var(--muted); font-style: italic; }
.detail .fiscal { margin: 10px 16px 14px; }
