/**
 * theme.css — MonPermisIA Design System v5.0
 * Source unique de vérité pour toutes les variables CSS
 * Remplace les :root éparpillés dans les 4 modules
 * 2026-05-22
 */

/* ══════════════════════════════════════════════════════════
   TOKEN LAYER 1 — Couleurs primitives
   ══════════════════════════════════════════════════════════ */
:root {

  /* ── Brand ── */
  --mp-blue:        #2563EB;
  --mp-blue-dark:   #1D4ED8;
  --mp-blue-light:  #EFF6FF;
  --mp-blue-mid:    #DBEAFE;
  --mp-blue-alpha:  rgba(37,99,235,.15);

  /* ── Neutrals (light surfaces) ── */
  --mp-white:       #FFFFFF;
  --mp-bg:          #F8FAFC;
  --mp-bg2:         #F1F5F9;
  --mp-bg3:         #E2E8F0;

  /* ── Dark surfaces (canvas/editor) ── */
  --mp-dark:        #0D1117;
  --mp-dark2:       #111214;
  --mp-panel:       #15181f;
  --mp-panel2:      #1a1d23;

  /* ── Ink / Text ── */
  --mp-ink:         #0F172A;
  --mp-ink2:        #334155;
  --mp-ink3:        #64748B;
  --mp-ink4:        #94A3B8;

  /* ── Dark text ── */
  --mp-txt:         rgba(255,255,255,.85);
  --mp-txt2:        rgba(255,255,255,.50);
  --mp-txt3:        rgba(255,255,255,.30);
  --mp-txt4:        rgba(255,255,255,.15);

  /* ── Borders ── */
  --mp-border:      rgba(255,255,255,.07);
  --mp-border2:     rgba(255,255,255,.12);
  --mp-border-l:    rgba(0,0,0,.08);
  --mp-border-l2:   rgba(0,0,0,.14);

  /* ── Semantic ── */
  --mp-green:       #10B981;
  --mp-green-dark:  #059669;
  --mp-green-lo:    rgba(16,185,129,.08);
  --mp-amber:       #F59E0B;
  --mp-amber-dark:  #D97706;
  --mp-red:         #EF4444;
  --mp-red-dark:    #DC2626;
  --mp-purple:      #A855F7;
  --mp-purple-dark: #7C3AED;

  /* ── Shadows ── */
  --mp-shadow-sm:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --mp-shadow:      0 4px 16px rgba(0,0,0,.08);
  --mp-shadow-lg:   0 12px 40px rgba(0,0,0,.10);
  --mp-shadow-dark: 0 8px 32px rgba(0,0,0,.35);

  /* ── Radii ── */
  --mp-r:    8px;
  --mp-r2:   14px;
  --mp-r3:   20px;
  --mp-r4:   28px;

  /* ── Layout ── */
  --mp-nav-h:       60px;
  --mp-topbar-h:    52px;
  --mp-tools-w:     50px;
  --mp-panel-w:     268px;
  --mp-panel-w-sm:  220px;
  --mp-infobar-h:   26px;
  --mp-sidebar-w:   280px;

  /* ── Touch ── */
  --mp-hit:         10px;   /* pointer hit zone radius */
  --mp-hit-touch:   22px;   /* touch hit zone radius   */
  --mp-tap-min:     44px;   /* minimum tap target size */

  /* ── Transitions ── */
  --mp-ease:        cubic-bezier(.25,.46,.45,.94);
  --mp-fast:        .12s var(--mp-ease);
  --mp-med:         .22s var(--mp-ease);

  /* ── Compat aliases (garder compatibilité fichiers existants) ── */
  --yellow:         var(--mp-blue);
  --yellow-h:       var(--mp-blue-dark);
  --yellow-l:       var(--mp-blue-light);
  --yellow-m:       var(--mp-blue-mid);
  --ink:            var(--mp-ink);
  --ink2:           var(--mp-ink2);
  --ink3:           var(--mp-ink3);
  --ink4:           var(--mp-ink4);
  --bg:             var(--mp-white);
  --bg2:            var(--mp-bg);
  --bg3:            var(--mp-bg2);
  --border:         var(--mp-border);
  --border2:        var(--mp-border2);
  --green:          var(--mp-green-dark);
  --red:            var(--mp-red-dark);
  --amber:          var(--mp-amber-dark);
  --shadow:         var(--mp-shadow-sm);
  --shadow-md:      var(--mp-shadow);
  --shadow-lg:      var(--mp-shadow-lg);
  --r: var(--mp-r); --r2: var(--mp-r2); --r3: var(--mp-r3);
  --accent:         var(--mp-blue);
  --accent-lo:      var(--mp-blue-light);
  --accent-border:  var(--mp-blue-mid);
  --surf:           var(--mp-white);
  --ok:             var(--mp-green-dark);
  --blue:           var(--mp-blue);
  --blue-d:         var(--mp-blue-dark);
  --blue-l:         var(--mp-blue-light);
  --panel:          var(--mp-panel);
  --panel2:         var(--mp-panel2);
  --txt:            var(--mp-txt);
  --txt2:           var(--mp-txt2);
  --txt3:           var(--mp-txt3);
}

/* ══════════════════════════════════════════════════════════
   NAV PARTAGÉE — remplace les inline styles sur <nav>
   ══════════════════════════════════════════════════════════ */
.mp-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  height: var(--mp-nav-h);
  background: rgba(255,255,255,.97);
  border-bottom: 1px solid #E2E8F0;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: .75rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  font-family: 'DM Sans', sans-serif;
}

.mp-nav-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  flex-shrink: 0;
}

.mp-nav-logo-text {
  font-family: 'Syne', sans-serif;
  font-weight: 900;
  font-size: 15px;
  color: var(--mp-ink);
  letter-spacing: -.02em;
  white-space: nowrap;
}

.mp-nav-logo-text span { color: var(--mp-blue); }

.mp-nav-links {
  display: flex;
  gap: .25rem;
  margin-left: .5rem;
}

.mp-nav-link {
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--mp-ink3);
  text-decoration: none;
  transition: var(--mp-fast);
  font-weight: 500;
  white-space: nowrap;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
}

.mp-nav-link:hover  { color: var(--mp-ink); background: var(--mp-bg2); }
.mp-nav-link.active { color: var(--mp-blue); background: var(--mp-blue-light); }

.mp-nav-right {
  margin-left: auto;
  display: flex;
  gap: .375rem;
  align-items: center;
  flex-shrink: 0;
}

.mp-nav-cta {
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--mp-blue);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  transition: var(--mp-fast);
  text-decoration: none;
  white-space: nowrap;
}

.mp-nav-cta:hover { background: var(--mp-blue-dark); }

/* Hamburger */
.mp-nav-burger {
  display: none;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 6px;
  border-radius: 8px;
  min-width: var(--mp-tap-min);
  min-height: var(--mp-tap-min);
  align-items: center;
  justify-content: center;
}

.mp-nav-burger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--mp-ink);
  border-radius: 2px;
  transition: var(--mp-med);
}

/* Mobile menu drawer */
.mp-nav-mobile {
  display: none;
  position: fixed;
  top: var(--mp-nav-h);
  left: 0; right: 0;
  background: #fff;
  border-bottom: 1px solid #E2E8F0;
  padding: .875rem 1.25rem 1.25rem;
  flex-direction: column;
  gap: .25rem;
  z-index: 199;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
}

.mp-nav-mobile.open { display: flex; }
.mp-nav-mobile .mp-nav-link { padding: 10px 12px; font-size: 14px; }
.mp-nav-mobile .mp-nav-cta  { text-align: center; margin-top: .375rem; display: block; padding: 11px; }

/* ══════════════════════════════════════════════════════════
   LAYOUT ÉDITEUR — grille principale (plan/3d/insertion)
   ══════════════════════════════════════════════════════════ */
.mp-workspace {
  display: grid;
  grid-template-columns: var(--mp-tools-w) 1fr var(--mp-panel-w);
  grid-template-rows: 1fr;
  height: calc(100vh - var(--mp-nav-h) - var(--mp-topbar-h));
  margin-top: calc(var(--mp-nav-h) + var(--mp-topbar-h));
  overflow: hidden;
}

.mp-tools-col {
  background: var(--mp-panel2);
  border-right: 1px solid var(--mp-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .5rem 0;
  gap: 2px;
  flex-shrink: 0;
  z-index: 10;
  overflow: hidden;
}

.mp-canvas-col {
  position: relative;
  overflow: hidden;
  background: var(--mp-dark2);
}

.mp-canvas-col canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.mp-panel-col {
  width: var(--mp-panel-w);
  background: var(--mp-panel);
  border-left: 1px solid var(--mp-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

/* ── Panneau latéral bottom-sheet sur mobile ── */
.mp-panel-col {
  transition: transform var(--mp-med);
}

/* Bouton d'ouverture du panneau sur mobile */
.mp-panel-toggle {
  display: none;
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 300;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--mp-blue);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(37,99,235,.4);
  align-items: center;
  justify-content: center;
  transition: var(--mp-fast);
}

/* Overlay pour fermer le panneau (mobile) */
.mp-panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 298;
  backdrop-filter: blur(2px);
}

/* ══════════════════════════════════════════════════════════
   CANVAS WRAPPER — positionnement DPR-aware
   ══════════════════════════════════════════════════════════ */
.mp-canvas-wrap {
  position: absolute;
  inset: 0;
}

.mp-canvas-wrap canvas {
  position: absolute;
  top: 0; left: 0;
  /* width/height gérés par JS via resizeCanvas() */
}

/* ══════════════════════════════════════════════════════════
   TOPBAR / TOOLBAR
   ══════════════════════════════════════════════════════════ */
.mp-topbar {
  position: fixed;
  top: var(--mp-nav-h);
  left: 0; right: 0;
  z-index: 100;
  height: var(--mp-topbar-h);
  background: var(--mp-panel2);
  border-bottom: 1px solid var(--mp-border);
  display: flex;
  align-items: center;
  padding: 0 .875rem;
  gap: .25rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.mp-topbar::-webkit-scrollbar { display: none; }

/* ══════════════════════════════════════════════════════════
   TOOL BUTTONS — taille tactile garantie
   ══════════════════════════════════════════════════════════ */
.mp-tool {
  min-width: 36px;
  min-height: 36px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--mp-fast);
  position: relative;
  border: 1px solid transparent;
  background: transparent;
  color: var(--mp-txt2);
  /* Zone de tap étendue via padding invisible */
  padding: 4px;
}

.mp-tool:hover  { background: rgba(255,255,255,.08); color: var(--mp-txt); }
.mp-tool.active { background: rgba(37,99,235,.2); border-color: rgba(37,99,235,.4); color: #93C5FD; }

/* ══════════════════════════════════════════════════════════
   INFOBAR
   ══════════════════════════════════════════════════════════ */
.mp-infobar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--mp-infobar-h);
  background: var(--mp-panel2);
  border-top: 1px solid var(--mp-border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 1.5rem;
  font-size: 10px;
  font-family: 'DM Mono', monospace;
  color: var(--mp-txt3);
  z-index: 100;
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ══════════════════════════════════════════════════════════ */

/* ── Tablettes (< 1024px) ── */
@media (max-width: 1024px) {
  :root {
    --mp-panel-w: var(--mp-panel-w-sm);
  }

  .mp-nav-links { display: none; }
  .mp-nav-burger { display: flex; }
}

/* ── Mobile (< 768px) ── */
@media (max-width: 768px) {
  :root {
    --mp-tools-w: 42px;
  }

  .mp-nav-links { display: none; }
  .mp-nav-burger { display: flex; }

  /* Workspace : outils + canvas full-width, panel caché */
  .mp-workspace {
    grid-template-columns: var(--mp-tools-w) 1fr;
    grid-template-rows: 1fr;
  }

  /* Panel devient bottom-sheet */
  .mp-panel-col {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100% !important;
    height: 65vh;
    border-radius: var(--mp-r3) var(--mp-r3) 0 0;
    border-left: none;
    border-top: 1px solid var(--mp-border);
    z-index: 300;
    transform: translateY(100%);
    box-shadow: 0 -8px 40px rgba(0,0,0,.4);
  }

  .mp-panel-col.open {
    transform: translateY(0);
  }

  /* Poignée drag du panneau */
  .mp-panel-col::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,.2);
    margin: .75rem auto .25rem;
    flex-shrink: 0;
  }

  /* Bouton flottant visible */
  .mp-panel-toggle {
    display: flex;
    bottom: calc(var(--mp-infobar-h) + .875rem);
  }

  /* Overlay visible quand panneau ouvert */
  .mp-panel-overlay.open { display: block; }

  /* Infobar masquée sur très petit */
  .mp-infobar { display: none; }

  /* Topbar scrollable sur mobile */
  .mp-topbar {
    padding: 0 .5rem;
    gap: .1rem;
  }
}

/* ── Très petit (< 480px) ── */
@media (max-width: 480px) {
  :root {
    --mp-tools-w: 0px;
  }

  /* Outils en bas du topbar sur mobile */
  .mp-tools-col { display: none; }
}

/* ══════════════════════════════════════════════════════════
   B-4 — BOTTOM-SHEET UNIFIÉ (.mp-sheet)
   Source unique pour le panneau-éditeur en mode mobile.
   Appliqué sur le panneau props des pages éditeur
   (editeur-plan : .panel ; editeur-3d : .props-panel).
   Les pages-assistant (plan-masse / insertion) NE l'utilisent
   PAS : leur formulaire reste empilé en pleine largeur.
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .mp-sheet {
    position: fixed !important;
    left: 0; right: 0; bottom: 0;
    top: auto !important;
    width: 100% !important;
    height: 40vh;
    min-height: 240px;
    max-height: 72vh;
    border-radius: var(--mp-r3) var(--mp-r3) 0 0;
    border-left: none !important;
    border-top: 1px solid var(--mp-border);
    z-index: 300;
    transform: translateY(100%);
    transition: transform var(--mp-med);
    box-shadow: 0 -8px 40px rgba(0,0,0,.45);
    /* Le scroll est délégué au corps interne (.panel-body / .pb)
       pour garder la poignée de drag épinglée en haut. */
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
    overscroll-behavior: contain;
  }

  .mp-sheet.open { transform: translateY(0); }

  /* Poignée de drag (premier enfant flex, reste épinglée en haut) */
  .mp-sheet::before {
    content: '';
    flex-shrink: 0;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,.25);
    margin: .6rem auto .4rem;
  }
}
