/* ─── Variables ───────────────────────────────────────────────────────────── */
:root {
  --primary:       #1e5bb5;
  --primary-hover: #174d99;
  --primary-light: #e8f0fc;
  --bg:            #f4f5f7;
  --card:          #ffffff;
  --border:        #e1e4ea;
  --text:          #1a1e2e;
  --text-light:    #6b7280;
  --success:       #0d7a45;
  --success-light: #edfaf3;
  --warning:       #b45309;
  --warning-light: #fffbeb;
  --danger:        #b91c1c;
  --danger-light:  #fee2e2;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.07), 0 1px 8px rgba(0,0,0,.04);
  --shadow-md:     0 2px 8px rgba(0,0,0,.09), 0 4px 20px rgba(0,0,0,.06);
  --radius:        10px;
  --radius-sm:     6px;
  --font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* ─── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }

/* ─── Header ──────────────────────────────────────────────────────────────── */
.tp-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.tp-header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.tp-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 700;
  font-size: .95rem;
  letter-spacing: -.01em;
  color: var(--text);
  flex-shrink: 0;
}
.tp-brand svg { flex-shrink: 0; }
.tp-nav {
  display: flex;
  align-items: center;
  gap: .15rem;
  flex: 1;
}
.tp-nav-link {
  padding: .3rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-light);
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.tp-nav-link:hover { background: var(--bg); color: var(--text); }
.tp-nav-link.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}
.tp-header-right {
  margin-left: auto;
  font-size: .8rem;
  color: var(--text-light);
  letter-spacing: .02em;
}

/* ─── Main layout ─────────────────────────────────────────────────────────── */
.tp-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

/* ─── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}
.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.page-sub {
  font-size: .84rem;
  color: var(--text-light);
  margin-top: .2rem;
}

/* ─── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 1rem 1.25rem .75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.card-title {
  font-size: .92rem;
  font-weight: 700;
  letter-spacing: -.01em;
  text-transform: uppercase;
  color: var(--text-light);
  font-size: .75rem;
  letter-spacing: .06em;
}
.card-body { padding: 1.25rem; }

/* ─── Grid ────────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.5rem; }

/* ─── Form elements ───────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group.full { grid-column: 1 / -1; }
.form-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: .01em;
}
.form-hint {
  font-size: .78rem;
  color: var(--text-light);
  margin-top: .15rem;
}
.input {
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .875rem;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,91,181,.12);
}
textarea.input { resize: vertical; font-family: monospace; font-size: .82rem; line-height: 1.6; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .55rem 1.25rem;
  border-radius: 20px;
  font-size: .875rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
  line-height: 1;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 2px 8px rgba(30,91,181,.35);
}
.btn-ghost {
  background: transparent;
  color: var(--text-light);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-lg { padding: .7rem 2rem; font-size: .95rem; }

/* ─── Alert ───────────────────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  border: 1px solid transparent;
  margin-bottom: 1.25rem;
}
.alert-danger {
  background: var(--danger-light);
  border-color: #fca5a5;
  color: var(--danger);
}
.alert-warning {
  background: var(--warning-light);
  border-color: #fcd34d;
  color: var(--warning);
}
.alert-success {
  background: var(--success-light);
  border-color: #6ee7b7;
  color: var(--success);
}

/* ─── KPI cards ───────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}
.kpi-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-light);
  margin-bottom: .4rem;
}
.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  line-height: 1.1;
}
.kpi-sub {
  font-size: .78rem;
  color: var(--text-light);
  margin-top: .2rem;
}
.kpi-card.kpi-dist { border-top: 3px solid #1e5bb5; }
.kpi-card.kpi-liq  { border-top: 3px solid #0d7a45; }
.kpi-card.kpi-cap  { border-top: 3px solid #7c3aed; }

/* ─── Pillar bar ──────────────────────────────────────────────────────────── */
.pillar-bar {
  height: 8px;
  border-radius: 4px;
  display: flex;
  overflow: hidden;
  margin: 1rem 0;
  gap: 2px;
}
.pillar-bar-dist { background: #1e5bb5; }
.pillar-bar-liq  { background: #0d7a45; }
.pillar-bar-cap  { background: #7c3aed; }

/* ─── Status badge ────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .25rem .7rem;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }

/* ─── Table ───────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
.table th {
  padding: .6rem .85rem;
  text-align: right;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-light);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th:first-child { text-align: center; }
.table td {
  padding: .55rem .85rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.table td:first-child { text-align: center; font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.table tr.in-sanctuary { background: #fafbff; }
.table tr.in-sanctuary td:first-child { color: var(--primary); }
.table tr:hover td { background: var(--bg); }
.table .td-neg { color: var(--danger); font-weight: 600; }

/* ─── Insight block ───────────────────────────────────────────────────────── */
.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
.insight-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: .9rem 1rem;
  border-left: 3px solid var(--primary);
}
.insight-item p {
  font-size: .84rem;
  color: var(--text);
  line-height: 1.5;
}
.insight-item strong { color: var(--primary); }

/* ─── Section titles ──────────────────────────────────────────────────────── */
.section-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-light);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Action row ──────────────────────────────────────────────────────────── */
.action-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: 1.5rem;
}

/* ─── Home hero (index page) ──────────────────────────────────────────────── */
.hero {
  text-align: center;
  padding: 4rem 2rem;
}
.hero h2 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.02em;
  margin-bottom: 1rem;
  color: var(--text);
}
.hero p {
  color: var(--text-light);
  font-size: .95rem;
  margin-bottom: 2rem;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
}
.pilliers {
  list-style: none;
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 2.5rem;
  padding: 0;
}
.pilliers li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  font-weight: 600;
  font-size: .9rem;
  box-shadow: var(--shadow-sm);
}
.pilliers li:nth-child(1) { border-top: 3px solid #1e5bb5; }
.pilliers li:nth-child(2) { border-top: 3px solid #0d7a45; }
.pilliers li:nth-child(3) { border-top: 3px solid #7c3aed; }

/* ─── Needs table ─────────────────────────────────────────────────────────── */
.needs-table-wrapper { max-height: 420px; overflow-y: auto; }
.needs-table td { padding: .25rem .6rem; }
.needs-table .input-need {
  padding: .3rem .5rem;
  font-size: .875rem;
  text-align: right;
  width: 140px;
}

/* ─── Copy-down button ────────────────────────────────────────────────────── */
.btn-copy-down {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-light);
  cursor: pointer;
  font-size: .78rem;
  line-height: 1;
  padding: .2rem .45rem;
  transition: background .12s, color .12s;
}
.btn-copy-down:hover { background: var(--bg); color: var(--text); }

/* ─── Inflation block ─────────────────────────────────────────────────────── */
.inflation-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.inflation-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-light);
}
.inflation-row {
  display: flex;
  align-items: flex-end;
  gap: .75rem;
  flex-wrap: wrap;
}
.btn-inflation { padding: .45rem 1rem; font-size: .82rem; }

/* ─── Sanctuary KPI ───────────────────────────────────────────────────────── */
.sanctuary-kpi-row { display: flex; gap: 1rem; }
.sanctuary-kpi {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
  min-width: 220px;
}
.sanctuary-kpi .kpi-value { font-size: 2rem; }
.sanctuary-danger { color: var(--danger); }
.sanctuary-ok { color: var(--success); }
.sanctuary-alert { font-size: .875rem; }

/* ─── Table — capitalisant consommé ──────────────────────────────────────── */
.table tr.row-cap-drawn { background: #fff8f0; }
.table tr.row-cap-drawn td:first-child { color: var(--warning); }
.table .td-cap-draw { color: var(--warning); font-weight: 600; }

/* ─── Alert neutre (prorata) ──────────────────────────────────────────────── */
.alert-info-neutral {
  background: #f0f4ff;
  border-color: #c7d5f5;
  color: #1e3a8a;
}

/* ─── Légende tableau ─────────────────────────────────────────────────────── */
.legend-box {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  margin-right: .35rem;
  vertical-align: middle;
}

/* ─── Méthodologie (details repliable) ────────────────────────────────────── */
.methodology-card {
  margin-bottom: 1.25rem;
}
.methodology-summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.methodology-summary::-webkit-details-marker { display: none; }
.methodology-toggle-hint {
  font-size: .72rem;
  color: var(--text-light);
  font-weight: 400;
}
details[open] .methodology-toggle-hint::after { content: " ▲"; }
details:not([open]) .methodology-toggle-hint::after { content: " ▼"; }
details:not([open]) .methodology-toggle-hint { content: "Afficher ▼"; }
.methodology-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem 1.1rem 1rem;
}
.methodology-list {
  margin: 0;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
}
.methodology-list li {
  font-size: .84rem;
  color: var(--text);
  line-height: 1.5;
}

/* ─── Tableau résultat scrollable ────────────────────────────────────────── */
.result-table-wrapper { max-height: 520px; overflow-y: auto; }

/* ─── Entête de colonne (card title + count) ──────────────────────────────── */
.card-title-sub { font-size: .78rem; }

/* ─── Projection preview ──────────────────────────────────────────────────── */
.projection-preview {
  margin-top: .75rem;
  padding: .6rem .9rem;
  border-radius: var(--radius-sm);
  font-size: .82rem;
  font-weight: 500;
}
.projection-preview-ok {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid #c7d5f5;
}
.projection-preview-warn {
  background: var(--warning-light);
  color: var(--warning);
  border: 1px solid #fcd34d;
}

/* ─── Coverage KPI ────────────────────────────────────────────────────────── */
.coverage-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.coverage-kpi-grid .kpi-card { border-top: 3px solid var(--text-light); }
.coverage-kpi-grid .kpi-card.kpi-ok { border-top-color: var(--success); }
.coverage-kpi-grid .kpi-card.kpi-warn { border-top-color: var(--danger); }

/* ─── Badge custom ───────────────────────────────────────────────────────── */
.badge-custom {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffc107;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .03em;
}

/* ─── Custom alloc card ───────────────────────────────────────────────────── */
.custom-alloc-card { margin-bottom: 1.25rem; }
.custom-alloc-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: .75rem;
}

/* ─── Custom total hint ───────────────────────────────────────────────────── */
.custom-total-hint {
  font-size: .82rem;
  font-weight: 500;
  padding: .4rem .7rem;
  border-radius: var(--radius-sm);
  margin-bottom: .25rem;
}
.custom-total-ok  { background: var(--success-light); color: var(--success); }
.custom-total-err { background: var(--danger-light);  color: var(--danger); }

/* ─── Two-tab navigation ──────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.25rem;
}
.tab-btn {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-light);
  padding: .65rem 1.35rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color .15s, border-color .15s, background .15s;
}
.tab-btn:hover { color: var(--text); background: var(--bg); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); background: none; }

/* ─── Frame selection cards ───────────────────────────────────────────────── */
.frame-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem;
  margin-bottom: .75rem;
}
.frame-card {
  display: block;
  cursor: pointer;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: .85rem 1rem;
  background: #fff;
  transition: border-color .15s, background .15s;
  position: relative;
}
.frame-card:hover { border-color: #a0b4d9; }
.frame-card input[type=radio] { position: absolute; opacity: 0; width: 0; height: 0; }
.frame-card.selected { border-color: var(--primary); background: #f0f5ff; }
.frame-card.disabled { cursor: not-allowed; opacity: .6; }
.frame-card-title { font-weight: 600; font-size: .9rem; }
.frame-card-desc { margin-top: .35rem; font-size: .78rem; color: var(--text-light); line-height: 1.4; }
.badge-soon {
  display: inline-block;
  margin-left: .4rem;
  padding: .1rem .45rem;
  font-size: .7rem;
  font-weight: 600;
  background: #f3f4f6;
  color: var(--text-light);
  border-radius: 4px;
  vertical-align: middle;
}

/* ─── Comparison table ────────────────────────────────────────────────────── */
.comparison-table th:first-child { text-align: left; }
.comparison-table td:first-child { text-align: left; }
.comparison-table td:not(:first-child) { text-align: right; }
.cmp-pct { font-size: .78rem; color: var(--text-light); margin-left: .3rem; }

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .coverage-kpi-grid { grid-template-columns: 1fr 1fr; }
  .insight-grid { grid-template-columns: 1fr; }
  .grid-form { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .custom-alloc-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .tp-header-inner { padding: 0 1rem; }
  .tp-main { padding: 1.25rem 1rem 2rem; }
}

/* ─── Investissements complémentaires — colonne conditionnelle ───────────── */
.needs-table .col-addinv { display: none; }
.needs-table.show-addinv .col-addinv { display: table-cell; }

/* ─── Projection view switch ──────────────────────────────────────────────── */
.proj-switch { display: flex; gap: .375rem; margin-bottom: .75rem; align-items: center; }
.proj-switch-btn {
  padding: .3rem .85rem;
  font-size: .82rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-light);
  cursor: pointer;
  font-weight: 500;
  font-family: inherit;
  transition: background .15s, border-color .15s, color .15s;
}
.proj-switch-btn:hover { background: var(--bg); color: var(--text); }
.proj-switch-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

/* ─── Utilitaires impression ──────────────────────────────────────────────── */
.print-only { display: none; }

@media print {
  /* ── Masqués à l'impression ── */
  .no-print,
  .tp-header,
  .methodology-card,
  .proj-switch,
  #projection-chart-view,
  #projection-chart-data,
  .custom-alloc-card,
  #av-tab-bar                { display: none !important; }

  /* ── Visibles seulement à l'impression ── */
  .print-only                { display: block !important; }
  .print-section             { display: block !important; }

  /* ── Onglets AV : tous affichés en impression ── */
  .av-contract-detail        { display: block !important; }
  #av-pane-synthese          { display: block !important; }

  /* ── Layout ── */
  body                       { background: #fff; }
  .tp-main                   { max-width: 100%; padding: .5cm 1cm; }

  /* ── Tableaux ── */
  .result-table-wrapper      { max-height: none !important; overflow: visible !important; }
  .table-wrapper             { overflow: visible !important; border: 1px solid #e1e4ea; }
  .table                     { font-size: .69rem; }
  .table th                  { padding: .35rem .55rem; position: static !important; }
  .table td                  { padding: .3rem .55rem; white-space: normal; }

  /* ── Sauts de page ── */
  .print-page-break          { page-break-before: always; break-before: always; }
  .kpi-card                  { page-break-inside: avoid; break-inside: avoid; }
  .coverage-kpi-grid         { page-break-inside: avoid; break-inside: avoid; }
  .kpi-grid                  { page-break-inside: avoid; break-inside: avoid; }
  .av-tax-summary            { page-break-inside: avoid; break-inside: avoid; }
  .card                      { page-break-inside: avoid; break-inside: avoid; }
  .section-title             { page-break-after: avoid; break-after: avoid; }

  /* ── Grilles ── */
  .insight-grid              { grid-template-columns: repeat(3, 1fr); }
  .coverage-kpi-grid         { grid-template-columns: repeat(4, 1fr); }

  /* ── En-tête d'impression ── */
  .print-header {
    text-align: center;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #1e5bb5;
  }
  .print-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: #1a1e2e;
    margin-bottom: .25rem;
  }
  .print-subtitle {
    font-size: .85rem;
    color: #6b7280;
  }

  /* ── Note méthodologique ── */
  .print-note {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid #e1e4ea;
    font-size: .78rem;
    color: #6b7280;
    font-style: italic;
  }
}
