/* ============================================
   Base layout & tiles + S2D styles aligned with portal
   ============================================ */

/* ---------- Root variables ---------- */
:root {
  --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; /* police d'origine */
  --radius-md: 0.75rem;
  --space: 1rem;
  --tile-min: 220px;
  --tile-max: 360px; /* valeur d'origine */
}

/* ---------- Reset / basics ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin:0;
  font-family: var(--font-family);
  background:var(--bg);
  color:var(--text);
  min-height:100vh;
}

#app { min-height:100vh; display:grid; grid-template-rows:auto 1fr auto; }

/* ---------- Section titles ---------- */
.section-title-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
}
.section-title-line .flag {
  display: inline-block;
  width: 22px;
  height: 16px;
  border-radius: 2px;
  object-fit: cover;
  flex-shrink: 0;
}
.section-title-line .section-title {
  margin-top: 0 !important;
  line-height: 1.2;
}

/* ============================================
   Header / Topbar
   ============================================ */
.topbar { display:flex; justify-content:space-between; gap:1rem; align-items:center; padding:0.75rem 1rem; background:var(--surface); border-bottom:1px solid var(--border); }
.topbar-left .app-title { margin:0; font-size:1.1rem; font-weight:600; }
.topbar-left .app-subtitle { font-size:0.75rem; color:var(--muted); }
.topbar-right { display:flex; gap:0.75rem; align-items:center; }
.field-inline { display:flex; flex-direction:column; gap:0.1rem; font-size:0.7rem; }
.input { background:var(--surface-2); border:1px solid var(--border); border-radius:0.45rem; padding:0.35rem 0.5rem; color:inherit; min-width:140px; }
.input:focus { outline:2px solid var(--primary); border-color:transparent; }
.btn { border:1px solid transparent; background:var(--primary); color:#fff; border-radius:999px; padding:0.35rem 0.9rem; cursor:pointer; font-size:0.75rem; transition:0.15s ease; }
.btn.ghost { background:transparent; border-color:var(--border); color:inherit; }
.link { background:none; border:none; color:var(--primary); cursor:pointer; padding:0; font-size:.8rem; }

/* ============================================
   Page
   ============================================ */
.page { padding: 1.25rem 1rem 1.5rem 1rem; max-width: 1200px; margin: 0 auto; width: 100%; }
.section-title { margin: 0 0 0.25rem 0; }
.muted { color: var(--muted); margin-bottom: 1rem; }

/* ============================================
   Tiles (cards)
   ============================================ */
/* Desktop comme avant : pas de clamp(), pas d'effet de “saut” */
.tiles{
  display:grid;
  grid-template-columns: repeat(
    auto-fit,
    minmax(min(100%, var(--tile-min)), var(--tile-max))
  );
  justify-content: center;
  gap: 1rem;
  width: 100%;
}
.tile{
  position:relative;
  aspect-ratio: 1 / 1;    /* ratio carré conservé sur desktop */
  width: 100%;
  min-width: 0;
  max-width: var(--tile-max);
  overflow: hidden;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:1rem;
  padding:1rem;
  display:flex; flex-direction:column; gap:.5rem;
  cursor:pointer;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.tile:hover{
  transform: translateY(-2px);
  border-color: color-mix(in oklab, var(--primary) 40%, var(--border));
  box-shadow: 0 6px 18px rgba(0,0,0,.08);
}
.tile:focus-visible{
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 30%, transparent);
}
.tile-head{ display:flex; align-items:center; justify-content:space-between; gap:.75rem; }
.tile h3{ margin:0; font-size:1rem; }
.tile-tag{
  background: rgba(47,128,237,.12);
  border:1px solid rgba(47,128,237,.25);
  border-radius:999px;
  font-size:.6rem;
  white-space: nowrap;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
}
.tile-desc{
  margin:0; color:var(--muted); font-size:.85rem;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}
.tile-foot{ display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; }
.tile-actions{ margin-top:auto; }

/* ============================================
   Doc pages (privacy, legal)
   ============================================ */
.page.doc h3{
  margin: 0 0 .5rem 0;
  font-size: 1rem;
  font-weight: 700;
}
.page.doc p{
  margin: .5rem 0;
  color: var(--muted);
  font-size: .85rem;
  line-height: 1.5;
  display: block;
  -webkit-line-clamp: unset;
  -webkit-box-orient: unset;
  overflow: visible;
}

/* ============================================
   Summary (réintégré)
   ============================================ */
.summary-card-note {
  font-size:.8rem;
  color:var(--muted);
  line-height:1.4;
  margin-top:.5rem;
  max-width:700px;
}
.summary-topline {
  font-size:.8rem;
  line-height:1.4;
  color:var(--text);
  background:var(--surface-2);
  border:1px solid var(--border);
  border-radius:.6rem;
  padding:.5rem .75rem;
  display:flex;
  flex-wrap:wrap;
  gap:.5rem .75rem;
}
.summary-topline .chunk {
  display:flex;
  flex-wrap:wrap;
  gap:.4rem;
  align-items:center;
  font-weight:500;
}
.summary-topline .label {
  color:var(--muted);
  font-weight:400;
  font-size:.75rem;
}

/* ============================================
   Footer (harmonisé desktop & mobile)
   ============================================ */
.footer{
  background: var(--surface);
  border-top:1px solid var(--border);
}
.footer-inner{
  max-width:1200px;
  margin:0 auto;
  padding:.85rem 1rem;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:.75rem 1rem;
  flex-wrap:wrap;              /* évite tout débordement */
  font-size:.8rem;
  color:var(--muted);
}
.footer-left,
.footer-right{
  display:flex;
  align-items:center;
  gap:.5rem .75rem;
  flex-wrap:wrap;
  min-width:0;
}
.footer-note{ opacity:.85; }
.footer-links{
  display:flex;
  align-items:center;
  gap:.4rem .6rem;
  flex-wrap:wrap;
}
.footer-links .sep{ opacity:.45; }
.footer .link{
  padding:0;
  font-size:.8rem;
  line-height:1.2;
}

/* ============================================
   S2D layout
   ============================================ */
.s2d-wrap { display:grid; grid-template-columns: 520px 1fr; gap:18px; }
@media(max-width:1100px){ .s2d-wrap { grid-template-columns: 1fr; } }
.s2d-card { background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-md); box-shadow: none; }
.s2d-card .title { padding: 1rem; padding-bottom: .5rem; font-size: .95rem; font-weight: 700; display:flex; justify-content:space-between; align-items:flex-start; gap:.5rem; flex-wrap:wrap;}
.s2d-card .content { padding: 1rem; padding-top: 0; }
.field { margin-bottom: 14px; }
.field label { display:flex; justify-content:space-between; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
fieldset { border:1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
legend { font-size: .78rem; color: var(--muted); padding: 0 6px; }
.two-col { display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media(max-width:560px){ .two-col { grid-template-columns: 1fr; } }
.stepper { display:flex; gap:8px; flex-wrap:wrap; margin: 0 0 12px 0; }
.step { padding:8px 12px; border:1px solid var(--border); border-radius:999px; background: var(--surface-2); font-size:.85rem; color: var(--muted); cursor:pointer; user-select:none; }
.step.active { border-color: var(--primary); color: var(--text); background: transparent; }

/* ============================================
   KPIs / tables / helpers
   ============================================ */
.kpis { display:grid; grid-template-columns: repeat(5,1fr); gap: 16px; }
@media(max-width:1400px){ .kpis { grid-template-columns: repeat(3,1fr); } }
@media(max-width:900px){ .kpis { grid-template-columns: repeat(2,1fr); } }
@media(max-width:560px){ .kpis { grid-template-columns: 1fr; } }
.kpi { background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-md); padding: 12px; }
.kpi .k { font-size: .8rem; color: var(--muted); margin-bottom: 6px; display:flex; align-items:center; gap:.4rem; flex-wrap:wrap;}
.kpi .k .sub {font-size:.7rem; font-weight:400; color:var(--muted);}
.kpi .v { font-size: 1.2rem; font-weight: 800; }
.kpi .s { font-size: .8rem; color: var(--muted); }

.hr { height:1px; background: linear-gradient(90deg, transparent, var(--border), transparent); margin: 10px 0; }
.stack { display:flex; flex-direction:column; gap:8px; }
.row { display:flex; align-items:flex-start; gap:12px; justify-content:space-between; font-size: .9rem; flex-wrap:wrap;}
.row-left {display:flex; flex-direction:column; min-width:180px; max-width:60%;}
.row-right {text-align:right; font-weight:600; display:flex; flex-direction:column; align-items:flex-end;}
.bar { height: 10px; background: var(--surface-2); border:1px solid var(--border); border-radius: 999px; overflow:hidden; }
.bar>span { display:block; height:100%; background: linear-gradient(90deg, var(--primary), #7a4ff8); width:0%; }
.help { font-size: .8rem; color: var(--muted); line-height:1.4; }
.warn { color: #ffd66a; } .danger { color: #ff6b6b; } .ok { color: #1ad19b; }
.actions { display:flex; gap:10px; flex-wrap:wrap; margin-top: 12px; }
.btn.small { font-size: .72rem; padding: .3rem .6rem; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; color: var(--muted); }

.badge { background: var(--surface-2); border:1px solid var(--border); padding:.15rem .5rem; border-radius:999px; font-size:.75rem; line-height:1.2; white-space:nowrap; }
.tag { border:1px dashed var(--border); padding:.2rem .5rem; border-radius:999px; font-size:.72rem; line-height:1.2; white-space:nowrap;}
.tag.ok { border-color:#1ad19b; }
.tag.warn { border-color:#ffd66a; }
.tag.danger { border-color:#ff6b6b; }

.table-mini { width:100%; border-collapse:collapse; font-size:.8rem; }
.table-mini thead th {
  text-align:left;
  font-weight:600;
  color:var(--muted);
  border-bottom:1px solid var(--border);
  padding:4px 0 6px 0;
  white-space:nowrap;
}
.table-mini tbody td {
  border-bottom:1px solid var(--border);
  padding:6px 0;
  vertical-align:top;
  color:var(--text);
  word-break:break-word;
}
.table-mini tfoot td {
  padding:8px 0 0 0;
  font-weight:600;
  color:var(--text);
}

/* ============================================
   Slider (tooltip + ticks)
   ============================================ */
.s2d-slider { position: relative; padding-top: 26px; }
.s2d-slider-wrap { position: relative; width: 80%; margin: 0; }

/* petite pastille discrète à droite du label */
.chip{
  display:inline-flex; align-items:center; gap:.35rem;
  padding:.15rem .5rem; border-radius:999px; font-size:.75rem;
  background:var(--surface-2, rgba(255,255,255,.06));
  border:1px solid var(--line, rgba(255,255,255,.08));
  color:var(--muted);
}

/* état désactivé du slider, subtil */
.s2d-slider[data-disabled="1"] .s2d-range{ opacity:.35; cursor:not-allowed; filter:saturate(.5); }
.s2d-slider[data-disabled="1"] .s2d-slider-ticks .tick{ opacity:.45; }
.s2d-slider[data-disabled="1"] .s2d-slider-scale{ opacity:.6; }
/* on masque simplement la bulle tooltip quand désactivé (géré aussi côté template) */
.s2d-slider[data-disabled="1"] .s2d-slider-tooltip{ display:none; }


.s2d-range {
  -webkit-appearance:none; appearance:none;
  width:100%; height:12px; border-radius:999px;
  background:
    linear-gradient(90deg,
      var(--primary) 0,
      var(--primary) var(--fill,0%),
      var(--surface-2) var(--fill,0%),
      var(--surface-2) 100%);
  border:1px solid var(--border);
  outline:none; padding:0; margin:0;
  position: relative; z-index: 2;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.08);
}
/* WebKit thumb */
.s2d-range::-webkit-slider-thumb{
  -webkit-appearance:none; appearance:none;
  width:20px; height:20px; border-radius:50%;
  background: var(--surface);
  border: 3px solid var(--primary);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 20%, transparent);
  cursor:pointer; position: relative;
  transition: transform .12s ease, box-shadow .12s ease;
}
.s2d-range:hover::-webkit-slider-thumb{ transform: scale(1.05); }
.s2d-range:focus-visible::-webkit-slider-thumb{ box-shadow: 0 0 0 5px color-mix(in oklab, var(--primary) 28%, transparent); }
/* Firefox */
.s2d-range::-moz-range-track{ height:12px; border-radius:999px; background: transparent; border:none; }
.s2d-range::-moz-range-progress{ height:12px; border-radius:999px; background: var(--primary); }
.s2d-range::-moz-range-thumb{
  width:20px; height:20px; border-radius:50%;
  background: var(--surface);
  border: 3px solid var(--primary);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 20%, transparent);
  cursor:pointer; transition: transform .12s ease, box-shadow .12s ease;
}
.s2d-range:hover::-moz-range-thumb{ transform: scale(1.05); }
.s2d-range:focus-visible::-moz-range-thumb{ box-shadow: 0 0 0 5px color-mix(in oklab, var(--primary) 28%, transparent); }
/* Tooltip */
.s2d-slider-tooltip{
  position:absolute; z-index: 3; top:-6px;
  transform:translate(-50%,-100%);
  background:var(--surface); border:1px solid var(--border); color:var(--text);
  font-size:.75rem; border-radius:.6rem; padding:3px 8px; white-space:nowrap;
  box-shadow:0 2px 6px rgba(0,0,0,.06);
}
/* Scale */
.s2d-slider-scale{
  display:flex; justify-content:space-between;
  font-size:.70rem; color:var(--muted); margin-top:8px;
  width: 80%;
  margin: 0;
}

/* ============================================
   Responsive pack (mobile)
   ============================================ */
@media (max-width: 720px) {
  /* Header */
  .topbar{
    flex-direction: column;
    align-items: stretch;
    gap: .5rem;
    padding: .5rem .75rem;
  }
  .topbar-left{
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
  }
  .topbar-left .app-title{ font-size: 1rem; }
  .topbar-left .app-subtitle{ font-size: .7rem; line-height: 1.1; }

  .topbar-right{
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    width: 100%;
  }
  .field-inline{
    width: calc(50% - .25rem);
    min-width: 0;
    font-size: .68rem;
  }
  .topbar-right .input{
    min-width: 0;
    width: 100%;
  }
  .topbar-right .btn{
    min-width: 0;
    flex: 1 1 auto;
  }

  /* Tuiles */
  .tiles{
    grid-template-columns: 1fr;
    gap: .75rem;
  }
  .tile{
    aspect-ratio: auto; /* libère le ratio sur mobile */
    padding: .85rem;
  }
  .tile h3{ font-size: .95rem; }
  .tile-desc{ font-size: .85rem; -webkit-line-clamp: 4; }

  /* Page padding plus compact */
  .page{ padding: .9rem .75rem 1rem .75rem; }

  /* S2D cartes : plein écran */
  .s2d-wrap{ grid-template-columns: 1fr; }
  .s2d-card .title{ padding: .75rem; }
  .s2d-card .content{ padding: .75rem; }

  /* Tableaux compacts */
  .table-mini{ font-size: .78rem; }

  /* Footer centré et respirant */
  .footer-inner{
    flex-direction:column;
    text-align: center;
    gap:.5rem;
    padding: .85rem .75rem;
  }
  .footer-left,
  .footer-right,
  .footer-links{
    justify-content:center;
  }
}

/* Micro-breakpoint très étroit (≤ 420px) */
@media (max-width: 420px){
  .field-inline{ width: 100%; }              /* 1 input par ligne */
  .topbar-left .app-subtitle{ display:none; }/* gagne de la place */
  .tile-desc{ -webkit-line-clamp: 2; }       /* coupe plus court sur très petit écran */
}

/* ---------- Garde-fous généraux ---------- */
img,svg,video{ max-width: 100%; height: auto; display: block; }
.flag, .fi{ max-width: 100%; }
.tile, .s2d-card{ min-width: 0; }
