:root{
    --paper:#FAFAF7;
    --ink:#22221E;
    --ink-soft:#5B5C55;
    --line:#DEDED4;
    --card:#FFFFFF;

    --bordeaux:#7A2E2E;
    --bordeaux-soft:#9A4A4A;

    --lvl0:#3C3568; --lvl0-bg:#EEECF9; --lvl0-line:#8E85C4;
    --lvl1:#1F5C73; --lvl1-bg:#E6F2F5; --lvl1-line:#5FA6BC;
    --lvl3:#7A5A1E; --lvl3-bg:#F8F1E1; --lvl3-line:#C7A45A;
    --lvlPA:#8A3B2B; --lvlPA-bg:#FAEBE5; --lvlPA-line:#C97F65;

    --coral:#B5502E; --coral-bg:#F5E1D6;
    --amber:#A3781B; --amber-bg:#F4EAC9;
    --teal:#276B58; --teal-bg:#DBEFE7;

    --tip-bg:#22221E; --tip-ink:#F4F4EE;
  }
  @media (prefers-color-scheme: dark){
    :root:not([data-theme="light"]){
      --paper:#1B1C17; --ink:#EEEEE6; --ink-soft:#B7B8AD; --line:#3A3B33; --card:#25261F;
      --bordeaux:#D98C8C; --bordeaux-soft:#E0A3A3;
      --lvl0:#B7AEF0; --lvl1:#8CCBE0; --lvl3:#E0C07A; --lvlPA:#E9A58E;
      --lvl0-bg:#292648; --lvl1-bg:#1A3238; --lvl3-bg:#3A2F14; --lvlPA-bg:#3A2119;
      --coral:#E59373; --amber:#DDB35A; --teal:#72C2A6;
      --coral-bg:#3C2317; --amber-bg:#382D0F; --teal-bg:#173028;
      --tip-bg:#EEEEE6; --tip-ink:#22221E;
    }
  }
  :root[data-theme="dark"]{
    --paper:#1B1C17; --ink:#EEEEE6; --ink-soft:#B7B8AD; --line:#3A3B33; --card:#25261F;
    --bordeaux:#D98C8C; --bordeaux-soft:#E0A3A3;
    --lvl0:#B7AEF0; --lvl1:#8CCBE0; --lvl3:#E0C07A; --lvlPA:#E9A58E;
    --lvl0-bg:#292648; --lvl1-bg:#1A3238; --lvl3-bg:#3A2F14; --lvlPA-bg:#3A2119;
    --coral:#E59373; --amber:#DDB35A; --teal:#72C2A6;
    --coral-bg:#3C2317; --amber-bg:#382D0F; --teal-bg:#173028;
    --tip-bg:#EEEEE6; --tip-ink:#22221E;
  }

  *{box-sizing:border-box;}
  html,body{margin:0;padding:0;}
  body{
    background:var(--paper); color:var(--ink); font-family:'Nunito', sans-serif;
    min-height:100vh; padding:18px 20px 24px;
  }
  button{font-family:'Nunito', sans-serif;}
  button:focus-visible, input:focus-visible, .term:focus-visible{outline:2px solid var(--bordeaux); outline-offset:2px;}
  .page{max-width:1040px; margin:0 auto;}

  /* En-tête */
  header{margin-bottom:12px;}
  .eyebrow{font-weight:800; color:var(--bordeaux); font-size:0.74rem; letter-spacing:0.04em; margin:0 0 4px;}
  h1{font-size:clamp(1.25rem, 2vw, 1.6rem); font-weight:900; margin:0 0 4px; line-height:1.15;}
  .subtitle{color:var(--ink-soft); font-size:0.86rem; max-width:70ch; margin:0 0 8px;}
  .legend{display:flex; flex-wrap:wrap; gap:12px; align-items:center;}
  .legend-item{display:inline-flex; align-items:center; gap:6px; font-size:0.76rem; font-weight:700; color:var(--ink-soft);}
  .dot{width:10px; height:10px; border-radius:50%; flex:none;}
  .dot.coral{background:var(--coral);} .dot.amber{background:var(--amber);} .dot.teal{background:var(--teal);}
  .topbar{display:flex; justify-content:space-between; align-items:flex-end; gap:16px; flex-wrap:wrap; border-bottom:2px solid var(--line); padding-bottom:12px;}
  .toggle-all{
    padding:8px 14px; border-radius:8px; border:none; background:var(--bordeaux);
    color:#fff; font-weight:800; font-size:0.8rem; cursor:pointer; white-space:nowrap;
  }
  .toggle-all:hover{background:var(--bordeaux-soft);}
  .top-actions{display:flex; gap:8px; flex-wrap:wrap; align-items:center;}
  .page-link{
    padding:7px 14px; border-radius:8px; border:1.5px solid var(--bordeaux); color:var(--bordeaux);
    font-weight:800; font-size:0.8rem; text-decoration:none; white-space:nowrap;
  }
  .page-link:hover{background:var(--bordeaux); color:#fff;}

  /* Mise en page */
  .layout{display:grid; grid-template-columns:220px 1fr; gap:16px; align-items:start; margin-top:14px;}
  @media (max-width:620px){ .layout{grid-template-columns:1fr;} }

  /* Données */
  .panel{background:var(--card); border:1px solid var(--line); border-radius:12px; padding:14px 16px; box-shadow:0 1px 3px rgba(0,0,0,0.04);}
  .panel h2{font-size:0.82rem; font-weight:800; margin:0 0 10px; color:var(--bordeaux);}
  .field{margin-bottom:12px;}
  .field label{display:flex; justify-content:space-between; font-size:0.78rem; font-weight:700; margin-bottom:4px;}
  .field label span.val{color:var(--bordeaux-soft); font-variant-numeric:tabular-nums;}
  .field input[type="range"]{width:100%; accent-color:var(--bordeaux);}
  .field .num input[type="number"]{
    width:100%; font-family:'Nunito', sans-serif; font-weight:700; font-size:0.84rem;
    padding:5px 8px; border:1px solid var(--line); border-radius:7px; background:var(--paper); color:var(--ink);
  }
  .hint{margin:3px 0 0; font-size:0.72rem; color:var(--ink-soft); line-height:1.3;}
  .alert{
    display:flex; gap:7px; align-items:flex-start; margin:6px 0 0; padding:7px 9px; border-radius:8px;
    background:var(--coral-bg); border:1px solid var(--coral); color:var(--ink);
    font-size:0.74rem; font-weight:700; line-height:1.35;
  }
  .alert[hidden]{display:none;}
  .alert svg{width:16px; height:16px; flex:none; color:var(--coral); margin-top:1px;}
  .tva-group{display:grid; grid-template-columns:1fr 1fr; gap:6px;}
  .tva-btn{
    padding:7px 5px; border-radius:7px; border:1px solid var(--line); background:var(--paper);
    color:var(--ink); font-weight:800; font-size:0.8rem; cursor:pointer;
  }
  .tva-btn:hover{border-color:var(--teal);}
  .tva-btn.active{background:var(--teal-bg); border-color:var(--teal); color:var(--teal);}
  .reset-btn{
    margin-top:4px; width:100%; padding:8px; border-radius:7px; border:1px solid var(--line);
    background:var(--paper); color:var(--ink); font-weight:700; font-size:0.8rem; cursor:pointer;
  }
  .reset-btn:hover{border-color:var(--bordeaux-soft); color:var(--bordeaux);}

  /* Structure du prix */
  .stage{background:var(--card); border:1px solid var(--line); border-radius:12px; padding:16px; box-shadow:0 1px 3px rgba(0,0,0,0.04); min-width:0;}
  .nest{
    border-radius:18px; border:2px solid var(--accent-line); background:var(--accent-bg);
    padding:14px; width:100%; margin:0 auto;
    transition:width .4s cubic-bezier(.4,0,.2,1), background .25s ease;
  }
  #nest-PVTTC{--accent:var(--lvl0); --accent-bg:var(--lvl0-bg); --accent-line:var(--lvl0-line);}
  #nest-PVHT{--accent:var(--lvl1); --accent-bg:var(--lvl1-bg); --accent-line:var(--lvl1-line);}
  #nest-CA{--accent:var(--lvl3); --accent-bg:var(--lvl3-bg); --accent-line:var(--lvl3-line);}

  .nest-head{display:flex; align-items:center; gap:12px; cursor:pointer; -webkit-tap-highlight-color:transparent;}
  .flap{
    width:30px; height:30px; flex:none; border-radius:9px; background:var(--card);
    display:flex; align-items:center; justify-content:center; transition:transform .3s cubic-bezier(.34,1.56,.64,1);
    border:1px solid var(--accent-line);
  }
  .nest.open > .nest-head .flap{transform:rotate(90deg);}
  .flap svg{width:16px; height:16px;}
  .flap-path{fill:none; stroke:var(--accent); stroke-width:2; stroke-linecap:round; stroke-linejoin:round;}
  .head-text{flex:1; display:flex; flex-direction:column; gap:2px; min-width:0;}
  .nest-head .title{font-weight:900; font-size:1.05rem; color:var(--accent); align-self:flex-start;}
  .calc{font-size:0.78rem; font-weight:700; color:var(--ink-soft); font-variant-numeric:tabular-nums;}
  .nest-head .amount{font-weight:900; font-size:1.05rem; color:var(--ink); background:var(--card); padding:5px 14px; border-radius:999px; border:1px solid var(--accent-line); font-variant-numeric:tabular-nums; white-space:nowrap;}

  .contents{display:grid; grid-template-rows:0fr; transition:grid-template-rows .35s ease;}
  .nest.open > .contents{grid-template-rows:1fr;}
  .contents-inner{overflow:hidden;}
  .contents-pad{padding-top:14px;}

  /* Sans frais d'achat : le niveau "coût d'achat" se confond avec le prix d'achat */
  .nest.flat{border:none; background:none; padding:0; width:100% !important;}
  .nest.flat > .nest-head, .nest.flat .addend{display:none;}
  .nest.flat > .contents{grid-template-rows:1fr;}
  .nest.flat .contents-pad{padding-top:0;}

  .addend{display:flex; justify-content:flex-end; margin-bottom:14px;}
  .pill{
    display:inline-flex; align-items:center; gap:8px; padding:6px 14px 6px 10px; border-radius:14px;
    font-size:0.84rem; font-weight:800;
  }
  .pill svg{width:15px; height:15px; flex:none;}
  .pill-text{display:flex; flex-direction:column; line-height:1.25;}
  .pill-main b{color:var(--ink); font-variant-numeric:tabular-nums;}
  .pill-calc{font-size:0.72rem; font-weight:700; color:var(--ink-soft); font-variant-numeric:tabular-nums;}
  .pill.coral{background:var(--coral-bg); color:var(--coral);}
  .pill.amber{background:var(--amber-bg); color:var(--amber);}
  .pill.teal{background:var(--teal-bg); color:var(--teal);}

  .base-box{
    background:var(--lvlPA-bg); border:2px solid var(--lvlPA-line);
    border-radius:14px; padding:12px 16px; display:flex; align-items:center; justify-content:space-between; gap:10px;
    width:100%; margin:0 auto; transition:width .4s cubic-bezier(.4,0,.2,1);
  }
  .base-box .title{font-weight:900; color:var(--lvlPA);}
  .base-box .title small{display:block; font-size:0.72rem; font-weight:700; color:var(--ink-soft);}
  .base-box .amount{font-weight:900; color:var(--ink); font-variant-numeric:tabular-nums;}

  .term{cursor:help;}
  .title.term{border-bottom:1.5px dotted currentColor;}

  /* Savoirs */
  .savoirs{min-width:0;}
  .sec-title{font-size:1.02rem; font-weight:900; color:var(--bordeaux); margin:22px 0 10px; padding-bottom:6px; border-bottom:2px solid var(--line);}
  .sec-title:first-child{margin-top:0;}
  .tabs{display:flex; flex-wrap:wrap; gap:4px; border-bottom:2px solid var(--line); margin-bottom:14px;}
  .tab{
    padding:9px 14px; border:none; border-radius:9px 9px 0 0; background:transparent; color:var(--ink-soft);
    font-weight:800; font-size:0.86rem; cursor:pointer; margin-bottom:-2px; border-bottom:3px solid transparent;
  }
  .tab:hover{color:var(--bordeaux);}
  .tab.active{color:var(--bordeaux); border-bottom-color:var(--bordeaux); background:var(--card);}
  .tab-panel[hidden]{display:none;}
  .cards{display:grid; grid-template-columns:repeat(auto-fit, minmax(300px, 1fr)); gap:14px;}
  .savoir{background:var(--card); border:1px solid var(--line); border-radius:12px; padding:14px 16px; box-shadow:0 1px 3px rgba(0,0,0,0.04);}
  .savoir h3{margin:0 0 4px; font-size:1rem; font-weight:900;}
  .def{margin:0 0 10px; font-size:0.86rem; color:var(--ink-soft); line-height:1.4;}
  .formula{margin:0 0 6px; padding:7px 10px; border-radius:8px; background:var(--paper); border-left:3px solid var(--bordeaux); font-weight:900; font-size:0.88rem; color:var(--bordeaux);}
  .appli{margin:10px 0; font-size:0.9rem; font-weight:700; font-variant-numeric:tabular-nums; line-height:1.6;}
  .appli b, .ways b, .why b{color:var(--bordeaux); font-weight:900;}
  .way-t{display:block; font-size:0.72rem; font-weight:800; color:var(--ink-soft);}
  .ways{display:grid; grid-template-columns:1fr 1fr; gap:8px; margin:10px 0;}
  @media (max-width:420px){ .ways{grid-template-columns:1fr;} }
  .way, .why{padding:8px 10px; border-radius:8px; border:1px solid var(--line); font-size:0.84rem; font-weight:700; font-variant-numeric:tabular-nums; line-height:1.5;}
  .why{margin:10px 0 0;}
  .read{margin:6px 0 0; font-size:0.84rem; line-height:1.4;}
  .note{margin:10px 0 0; font-size:0.8rem; line-height:1.4; padding:7px 10px; border-radius:8px; background:var(--coral-bg);}
  .note b{color:var(--coral);}

  .mini{width:100%; border-collapse:collapse; font-size:0.8rem; font-variant-numeric:tabular-nums;}
  .mini th{text-align:left; font-weight:800; color:var(--ink-soft); padding:4px 6px; border-bottom:1px solid var(--line);}
  .mini td{padding:4px 6px; border-bottom:1px solid var(--line); font-weight:700;}
  .mini tr.on td{background:var(--teal-bg); color:var(--teal); font-weight:900;}

  /* Comparaison des taux */

  footer{margin-top:20px; font-size:0.8rem; color:var(--ink-soft); text-align:center;}

  /* Info-bulle */
  #tooltip{
    position:fixed; z-index:50; max-width:260px; background:var(--tip-bg); color:var(--tip-ink);
    border-radius:10px; padding:12px 14px; font-size:0.86rem; line-height:1.4; font-weight:600;
    display:flex; gap:10px; align-items:flex-start; opacity:0; transform:translateY(4px) scale(0.98);
    transition:opacity .12s ease, transform .12s ease; pointer-events:none; box-shadow:0 6px 18px rgba(0,0,0,0.18);
  }
  #tooltip.show{opacity:1; transform:translateY(0) scale(1);}
  #tooltip .tip-icon{
    width:30px; height:30px; flex:none; border-radius:8px; display:flex; align-items:center; justify-content:center;
    background:rgba(255,255,255,0.14);
  }
  #tooltip .tip-icon svg{width:17px; height:17px; stroke:var(--tip-ink); fill:none; stroke-width:2; stroke-linecap:round; stroke-linejoin:round;}
  #tooltip .tip-name{font-weight:900; margin-bottom:2px; display:block;}

  @media (prefers-reduced-motion: reduce){
    .flap, .contents, .nest, .base-box{transition:none !important;}
  }
