/* ==========================================================================
   Decoupix — Design System v3
   Material Design 3 · Inter · Responsive
   ========================================================================== */

/* --- Google Fonts (Inter) via @import fallback si base.html n'a pas le link --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ==========================================================================
   Reset & Custom Properties
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* MD3 Color tokens — palette indigo */
  --md-primary:            #4f46e5;
  --md-primary-hover:      #4338ca;
  --md-primary-active:     #3730a3;
  --md-primary-container:  #e0e7ff;
  --md-on-primary:         #ffffff;
  --md-secondary:          #6366f1;
  --md-error:              #ef4444;
  --md-error-hover:        #dc2626;
  --md-error-container:    #fee2e2;
  --md-warning:            #f59e0b;
  --md-warning-container:  #fef3c7;
  --md-success:            #10b981;
  --md-success-container:  #d1fae5;

  /* Surface */
  --md-surface:            #ffffff;
  --md-surface-variant:    #f8fafc;
  --md-surface-2:          #f1f5f9;
  --md-background:         #f1f5f9;
  --md-outline:            #e2e8f0;
  --md-outline-variant:    #cbd5e1;

  /* Text */
  --md-on-surface:         #0f172a;
  --md-on-surface-variant: #475569;
  --md-on-surface-muted:   #94a3b8;

  /* Sidebar (light surface) */
  --sidebar-bg:            #ffffff;
  --sidebar-border:        #e2e8f0;
  --sidebar-link:          #64748b;
  --sidebar-link-hover:    #0f172a;
  --sidebar-link-active:   #4f46e5;
  --sidebar-section:       #94a3b8;
  --sidebar-active-bg:     #eef2ff;
  --sidebar-active-border: #4f46e5;

  /* Layout dimensions */
  --sidebar-w:       228px;
  --topbar-h:        52px;
  --statusbar-h:     28px;
  --bottom-nav-h:    64px;

  /* Type */
  --font:       'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  /* Elevation (shadows) */
  --shadow-xs:   0 1px 2px rgba(15,23,42,.05);
  --shadow-sm:   0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.06);
  --shadow-md:   0 4px 6px rgba(15,23,42,.07), 0 2px 4px rgba(15,23,42,.06);
  --shadow-lg:   0 10px 15px rgba(15,23,42,.08), 0 4px 6px rgba(15,23,42,.05);
  --shadow-xl:   0 20px 25px rgba(15,23,42,.1), 0 8px 10px rgba(15,23,42,.06);

  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-pill: 9999px;

  /* Motion */
  --ease-default: cubic-bezier(0.4,0,0.2,1);
  --ease-decel:   cubic-bezier(0,0,0.2,1);
  --ease-accel:   cubic-bezier(0.4,0,1,1);
  --duration-xs:  100ms;
  --duration-sm:  150ms;
  --duration-md:  250ms;

  /* Legacy aliases (used in templates) */
  --c-bg:           var(--md-background);
  --c-surface:      var(--md-surface);
  --c-border:       var(--md-outline);
  --c-border-focus: var(--md-primary);
  --c-primary:      var(--md-primary);
  --c-primary-h:    var(--md-primary-hover);
  --c-danger:       var(--md-error);
  --c-danger-h:     var(--md-error-hover);
  --c-warning:      var(--md-warning);
  --c-success:      var(--md-success);
  --c-muted:        var(--md-on-surface-muted);
  --c-text:         var(--md-on-surface);
  --c-text-light:   var(--md-on-surface-variant);

  /* Grid cells */
  --c-cell-bg:       #fff;
  --c-cell-hover:    #f0f4ff;
  --c-cell-selected: #e0e7ff;
  --c-cell-error:    #fef2f2;
  --c-cell-error-b:  var(--md-error);

  /* Material Web theming tokens */
  --md-sys-color-primary:             var(--md-primary);
  --md-sys-color-on-primary:          var(--md-on-primary);
  --md-sys-color-primary-container:   var(--md-primary-container);
  --md-sys-color-error:               var(--md-error);
  --md-filled-button-container-color: var(--md-primary);
  --md-filled-button-label-text-color: #fff;
  --md-ref-typeface-plain:            var(--font);
  --md-ref-typeface-brand:            var(--font);
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--md-on-surface);
  background: var(--md-background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
  overflow-x: hidden; /* empêche le débordement horizontal global */
  max-width: 100vw;
  touch-action: manipulation; /* désactive le zoom double-tap, conserve le pinch-zoom */
}

/* ==========================================================================
   App Shell — Layout responsive
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr var(--statusbar-h);
  height: 100vh;
  height: 100dvh; /* suit le viewport dynamiquement (clavier mobile) */
  overflow: hidden;
}

/* --- Topbar --- */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: #0d1117;
  color: #f1f5f9;
  border-bottom: 1px solid rgba(255,255,255,.07);
  z-index: 100;
  position: relative;
}

.topbar__hamburger {
  display: none;
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: background var(--duration-sm) var(--ease-default);
}
.topbar__hamburger:hover { background: rgba(255,255,255,.08); color: #f1f5f9; }

.topbar__hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  background: none;
  border: none;
  color: #f1f5f9;
  cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.topbar__hamburger:active { background: rgba(255,255,255,.1); }
.topbar__hamburger .material-symbols-outlined { font-size: 22px; }

/* Affaire active dans la topbar mobile */
.topbar__affaire-m {
  display: none;
  align-items: center;
  gap: 4px;
  color: rgba(255,255,255,.75);
  font-size: 12px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.topbar__affaire-m .material-symbols-outlined { font-size: 13px; flex-shrink: 0; opacity: .6; }
.topbar__affaire-m span:last-child { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 768px) { .topbar__affaire-m { display: flex; } }

.topbar__logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: #f1f5f9;
  text-decoration: none;
  white-space: nowrap;
}
.topbar__logo-icon {
  width: 28px; height: 28px;
  background: var(--md-primary);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800;
}

.topbar__divider {
  width: 1px; height: 20px;
  background: rgba(255,255,255,.12);
  margin: 0 4px;
}

.topbar__affaire {
  font-size: 13px;
  color: #94a3b8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.topbar__affaire strong { color: #cbd5e1; }

.topbar__nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  align-items: center;
}

.topbar__btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--duration-sm) var(--ease-default);
  white-space: nowrap;
}
.topbar__btn--ghost {
  background: rgba(255,255,255,.06);
  color: #cbd5e1;
  border-color: rgba(255,255,255,.1);
}
.topbar__btn--ghost:hover {
  background: rgba(255,255,255,.12);
  color: #f1f5f9;
  border-color: rgba(255,255,255,.2);
}
.topbar__btn--save {
  background: rgba(245,158,11,.15);
  color: #f59e0b;
  border-color: rgba(245,158,11,.3);
  animation: pulse-save 2.5s ease-in-out infinite;
}
.topbar__btn--save:hover { background: rgba(245,158,11,.25); border-color: rgba(245,158,11,.5); }
@keyframes pulse-save {
  0%,100% { box-shadow: 0 0 0 0 rgba(245,158,11,.25); }
  50%      { box-shadow: 0 0 0 4px rgba(245,158,11,.0); }
}
.topbar__btn--primary {
  background: var(--md-primary);
  color: #fff;
}
.topbar__btn--primary:hover { background: var(--md-primary-hover); }
.topbar__btn--icon {
  padding: 6px 8px;
  min-width: 36px;
  justify-content: center;
}

/* --- Sidebar --- */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  color: var(--sidebar-link);
  overflow-y: auto;
  padding: 8px 0 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--md-outline) transparent;
  transition: transform var(--duration-md) var(--ease-decel);
}

.sidebar__brand {
  display: none; /* shown on mobile only */
  align-items: center;
  gap: 8px;
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--md-outline);
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--md-on-surface);
}
.sidebar__brand-icon {
  width: 26px; height: 26px;
  background: var(--md-primary);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #fff;
}

.sidebar__section {
  padding: 16px 16px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--sidebar-section);
  font-weight: 600;
}
.sidebar__section:first-child { padding-top: 8px; }

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 14px;
  color: var(--sidebar-link);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 450;
  border-left: 2.5px solid transparent;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin: 1px 8px 1px 0;
  min-height: 40px;
  transition: background var(--duration-xs) var(--ease-default),
              color var(--duration-xs) var(--ease-default);
  letter-spacing: -.01em;
}
.sidebar__link:hover {
  background: var(--md-surface-2);
  color: var(--sidebar-link-hover);
}
.sidebar__link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-link-active);
  border-left-color: var(--sidebar-active-border);
  font-weight: 600;
}
.sidebar__link .material-symbols-outlined {
  font-size: 18px;
  flex-shrink: 0;
  color: var(--md-on-surface-muted);
  transition: color var(--duration-xs);
}
.sidebar__link:hover .material-symbols-outlined {
  color: var(--md-on-surface-variant);
}
.sidebar__link.active .material-symbols-outlined {
  color: var(--sidebar-link-active);
}

/* Badges numériques étapes sidebar */
.sidebar__step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
  font-size: 11px; font-weight: 700; font-family: var(--font-mono, monospace);
  background: var(--md-primary); color: var(--md-on-primary);
  margin-right: 2px;
}
.sidebar__step--dim {
  background: var(--md-outline-variant, var(--md-outline));
  color: var(--md-on-surface-muted);
}
.sidebar__link--dim {
  opacity: 0.38;
  cursor: default;
  pointer-events: none;
}
.sidebar__link--dim:hover { background: none; }

/* Toggle section Configuration */
.sidebar__section--toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; background: none; border: none; cursor: pointer;
  color: inherit; font: inherit;
  padding: 6px 16px;
  text-transform: uppercase; letter-spacing: .06em;
  font-size: 11px; font-weight: 600; opacity: .55;
}
.sidebar__section--toggle:hover { opacity: .85; }
.sidebar__section--toggle .material-symbols-outlined { font-size: 16px; opacity: 1; }

/* --- Main content --- */
.main {
  overflow-y: auto;
  min-height: 0; /* grid item : empêche la croissance au-delà de la track, active le scroll interne */
  padding: 24px;
  background: var(--md-background);
}

/* --- Skeleton loader --- */
@keyframes skeleton-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
.skeleton {
  display: block;
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
.skeleton--dark {
  display: block;
  background: linear-gradient(90deg, #1e293b 25%, #2d3f55 50%, #1e293b 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
.skeleton-cell { padding: 2px 0; }

/* --- Status bar --- */
.statusbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--sidebar-bg);
  color: #64748b;
  font-size: 11px;
  border-top: 1px solid rgba(255,255,255,.06);
  letter-spacing: .01em;
}
.statusbar__item { display: flex; align-items: center; gap: 6px; }
.statusbar__dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--md-success);
  box-shadow: 0 0 0 2px rgba(16,185,129,.2);
}
.statusbar__dot--idle { background: #334155; box-shadow: none; }
.statusbar__dot--warn { background: var(--md-warning); box-shadow: 0 0 0 2px rgba(245,158,11,.2); }

/* === Bottom navigation bar (mobile only) === */
.bottom-nav {
  display: none;
}

/* mc-body : masqué sur desktop, affiché sur mobile via media query */
.mc-body { display: none; }
.mc-actions { display: flex; gap: 4px; }

/* Bouton suppression desktop dans la dernière colonne d'une card */
.mc-desktop-del { display: inline-flex; }

/* --- Responsive --- */
/* Overlay sidebar mobile */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 80;
  backdrop-filter: blur(2px);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  /* Bloque le scroll body sur les pages app — empêche l'espace vide en bas */
  body.app-page {
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Status bar masquée sur mobile */
  .statusbar { display: none; }

  /* Topbar mobile : seulement logout reste visible */
  .topbar__hamburger { display: flex !important; }
  .topbar__logo-text { display: none; }
  .topbar__divider { display: none; }
  .topbar__affaire { display: none; }
  .topbar__btn-label { display: none; }
  .topbar__btn--ghost { padding: 6px 8px; min-width: 44px; min-height: 44px; justify-content: center; }
  .topbar__btn--desktop { display: none; }

  /* Sidebar — drawer mobile */
  .sidebar {
    display: block;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(280px, 85vw);
    z-index: 300;
    transform: translateX(-100%);
    padding-top: 0;
    box-shadow: none;
    border-right: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0,0,0,.28);
  }
  .sidebar__brand { display: flex; }
  .sidebar-overlay { display: none; z-index: 299; }
  .sidebar-overlay.visible { display: block; }

  /* Main content */
  .main {
    padding: 12px;
    max-width: 100vw;
    overflow-x: hidden;
    padding-bottom: calc(16px + var(--bottom-nav-h));
  }

  /* Cards */
  .card { max-width: 100%; }
  .card__header { flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
  .card__title { font-size: 14px; }
  .card__subtitle { display: none; }

  /* ── Tables → Cards sur mobile ─────────────────────── */
  .data-table-wrap { overflow-x: visible; }
  .data-table { display: block; }
  .data-table thead { display: none; }
  .data-table tbody { display: flex; flex-direction: column; gap: 8px; padding: 8px; }
  .data-table tbody tr {
    display: block;
    border: 1px solid var(--md-outline);
    border-radius: var(--radius-md);
    background: var(--md-surface);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
  }
  /* Masquer toutes les cellules sauf .row-actions (tables de listes uniquement) */
  .data-table:not(.data-table--grid) td { display: none; }
  /* Cellule état vide (colspan) : toujours visible */
  .data-table td[colspan] { display: block !important; }
  /* Card layout : colonne — contenu en haut, barre d'actions en bas */
  .data-table td.row-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 14px 14px 0;
  }
  /* Contenu card */
  .mc-body { display: block; flex: none; min-width: 0; margin-bottom: 12px; }
  .mc-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--md-on-surface);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 5px;
  }
  .mc-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }
  .mc-dim {
    font-size: 12px;
    color: var(--md-on-surface-muted);
    font-variant-numeric: tabular-nums;
  }
  .mc-badge { font-size: 10px; padding: 1px 6px; }
  .mc-desc {
    font-size: 12px;
    color: var(--md-on-surface-muted);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mc-meta-empty { font-size: 12px; color: var(--md-on-surface-muted); }

  /* Barre d'actions pleine largeur — chaque bouton occupe 1/N de la largeur */
  .mc-actions {
    display: flex;
    gap: 1px;
    background: var(--md-outline);
    margin: 0 -14px;
  }
  .mc-actions .btn {
    flex: 1;
    min-height: 48px !important;
    min-width: 0 !important;
    border-radius: 0 !important;
    padding: 0 !important;
    justify-content: center;
    background: var(--md-surface);
    gap: 0;
  }
  .mc-actions .btn:active { background: var(--md-surface-variant); }
  .mc-actions .material-symbols-outlined { font-size: 22px !important; }

  .col-mobile-hide { display: none !important; }

  /* Results canvas */
  .results-layout { grid-template-columns: 1fr !important; }
  #canvas-container { min-height: 320px !important; touch-action: none; }
  .mobile-only { display: block !important; }
  .desktop-only { display: none !important; }

  /* Toolbar scrollable */
  .toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 8px 10px;
    gap: 6px;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar .btn { flex-shrink: 0; min-height: 40px; }
  .toolbar .btn__label { display: none; }
  .card__actions .btn__label { display: none; }
  .toolbar__stats { display: none; }

  /* Touch targets — minimum 44px (Apple HIG) */
  .btn { min-height: 44px; font-size: 14px; }
  .btn--sm { min-height: 40px; font-size: 13px; }
  .btn--icon { min-width: 44px; min-height: 44px; }
  /* Filtres et inputs */
  .filter-bar input,
  .filter-bar select { min-height: 44px; font-size: 15px; }
  /* Card header actions */
  .card__actions .btn { min-height: 48px; }
  /* Inputs de grille */
  .cell-input { min-height: 40px; font-size: 14px; }

  /* Bottom nav — sombre pour contraste au doigt */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-h);
    background: #0d1117;
    border-top: 1px solid rgba(255,255,255,.08);
    z-index: 85;
    align-items: stretch;
    box-shadow: 0 -4px 24px rgba(0,0,0,.3);
  }
  .bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-decoration: none;
    color: #4b5563;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: .02em;
    padding: 8px 4px 10px;
    border: none;
    background: none;
    cursor: pointer;
    transition: color var(--duration-sm);
    -webkit-tap-highlight-color: transparent;
    position: relative;
  }
  .bottom-nav__item .material-symbols-outlined {
    font-size: 24px;
    transition: color var(--duration-sm);
  }
  .bottom-nav__item.active { color: #818cf8; }
  .bottom-nav__item.active::before {
    content: '';
    position: absolute;
    top: 6px; left: 50%;
    transform: translateX(-50%);
    width: 32px; height: 3px;
    background: #818cf8;
    border-radius: var(--radius-pill);
  }
  .bottom-nav__item.active .material-symbols-outlined {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  }
  .bottom-nav__item--disabled { opacity: 0.25; cursor: default; }

  /* Grilles éditables (parametres) : tableau horizontal scrollable */
  .data-table--grid { display: table !important; width: max-content; min-width: 100%; }
  .data-table--grid thead { display: table-header-group !important; }
  .data-table--grid tbody { display: table-row-group !important; padding: 0; gap: 0; }
  .data-table--grid tbody tr {
    display: table-row !important;
    border: none;
    border-bottom: 1px solid var(--md-outline);
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }
  .data-table--grid tbody tr:hover { background: var(--md-surface-variant); }
  .data-table--grid td:not(.col-mobile-hide) { display: table-cell !important; padding: 6px 8px; }
  .data-table--grid thead { display: none; }

  .mc-desktop-del { display: none !important; }  /* icône seule masquée sur mobile */

  /* Morceaux : pas de scroll interne, la page entière défile */
  /* padding-bottom compense les 2 FABs empilés (optimiser + add) qui recouvrent les dernières lignes */
  .morceaux-wrap { max-height: none !important; overflow: visible !important; padding-bottom: 140px; }

  /* Toast au-dessus du bottom nav */
  .toast-container { bottom: calc(var(--bottom-nav-h) + 12px); }
}

/* ==========================================================================
   Component — Bottom Sheet (action sheet iOS/Android)
   ========================================================================== */

.bottom-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 400;
  display: flex;
  align-items: flex-end;
  transform: translateZ(0);        /* layer GPU permanent → pas de flash au toggle */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.bottom-sheet {
  width: 100%;
  background: var(--md-surface);
  border-radius: 20px 20px 0 0;
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 8px);
  box-shadow: 0 -8px 32px rgba(0,0,0,.2);
  transform: translateZ(0);        /* layer GPU permanent (remplace will-change) */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* Classes d'animation pour Alpine x-transition */
.bsheet-bg-enter { transition: opacity 280ms ease; }
.bsheet-bg-hidden { opacity: 0; }
.bsheet-bg-visible { opacity: 1; }
.bsheet-slide-enter { transition: transform 320ms cubic-bezier(0.32, 0.72, 0, 1); }
.bsheet-slide-hidden { transform: translate3d(0, 100%, 0); }
.bsheet-slide-visible { transform: translate3d(0, 0, 0); }

/* Icône de type dans les cards mobile */
.mc-type-icon { font-size: 15px !important; opacity: .45; vertical-align: -3px; margin-right: 4px; flex-shrink: 0; }

.bottom-sheet__handle {
  width: 40px; height: 4px;
  background: var(--md-outline);
  border-radius: 100px;
  margin: 10px auto 8px;
}

.bottom-sheet__title {
  font-size: 11px;
  font-weight: 700;
  color: var(--md-on-surface-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 4px 20px 8px;
}

.bottom-sheet__item {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 0 20px;
  min-height: 58px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  color: var(--md-on-surface);
  text-align: left;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
.bottom-sheet__item:active { background: var(--md-surface-variant); }
.bottom-sheet__item:disabled { opacity: .35; pointer-events: none; }
.bottom-sheet__item .material-symbols-outlined { font-size: 22px; color: var(--md-on-surface-muted); flex-shrink: 0; }
.bottom-sheet__item--danger { color: var(--c-danger); }
.bottom-sheet__item--danger .material-symbols-outlined { color: var(--c-danger); }

.bottom-sheet__divider { height: 1px; background: var(--md-outline); margin: 4px 0; }

.bottom-sheet__cancel {
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(100% - 32px);
  margin: 8px 16px 4px;
  min-height: 52px;
  border: none;
  background: var(--md-surface-variant);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
.bottom-sheet__cancel:active { opacity: .7; }

/* Bouton déclencheur dans la toolbar — masqué par défaut, visible sur mobile */
.toolbar__more-btn { display: none; }
/* Actions secondaires dans la toolbar — cachées sur mobile au profit du bottom sheet */
.toolbar__secondary { display: contents; }

@media (max-width: 768px) {
  .toolbar__more-btn { display: flex !important; }
  .toolbar__secondary { display: none !important; }
}

/* ==========================================================================
   Components — Card
   ========================================================================== */


.card {
  background: var(--md-surface);
  border: 1px solid var(--md-outline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.card + .card { margin-top: 16px; }
/* Dans un grid, le gap gère l'espacement — annuler le margin automatique */
.plan-cards-grid .card + .card { margin-top: 0; }
@media (max-width: 540px) {
  .plan-cards-grid { grid-template-columns: 1fr !important; }
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--md-outline);
  gap: 12px;
  flex-wrap: wrap;
  min-height: 54px;
}
.card__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--md-on-surface);
  letter-spacing: -.02em;
}
.card__subtitle {
  font-size: 13px;
  color: var(--md-on-surface-variant);
  margin-top: 1px;
}
.card__body { padding: 20px; }
.card__actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* Card metric (dashboard) */
.metric-card {
  background: var(--md-surface);
  border: 1px solid var(--md-outline);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-xs);
}
.metric-card__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.metric-card__value {
  font-size: 28px;
  font-weight: 700;
  color: var(--md-on-surface);
  letter-spacing: -.04em;
  line-height: 1.2;
  margin-top: 4px;
}
.metric-card__sub {
  font-size: 12px;
  color: var(--md-on-surface-muted);
  margin-top: 4px;
}

/* ==========================================================================
   Components — Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-sm) var(--ease-default);
  white-space: nowrap;
  line-height: 1.4;
  text-decoration: none;
  letter-spacing: .01em;
  position: relative;
  overflow: hidden;
}
.btn:focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: 2px;
}
.btn:disabled, .btn[disabled] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn .material-symbols-outlined { font-size: 16px; }

/* Ripple effect */
.btn::after {
  content: '';
  position: absolute; inset: 0;
  background: currentColor;
  opacity: 0;
  border-radius: inherit;
  transition: opacity var(--duration-sm);
}
.btn:active::after { opacity: .08; }

/* Filled (Primary) */
.btn--primary {
  background: var(--md-primary);
  color: #fff;
  box-shadow: var(--shadow-xs);
}
.btn--primary:hover:not(:disabled) {
  background: var(--md-primary-hover);
  box-shadow: var(--shadow-sm);
}

/* Tonal (Secondary/Tonal) */
.btn--secondary {
  background: #fff;
  color: var(--md-primary);
  border-color: var(--md-outline);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--md-primary-container);
  border-color: var(--md-primary);
}

/* Outlined Danger */
.btn--danger {
  background: var(--md-error);
  color: #fff;
}
.btn--danger:hover:not(:disabled) { background: var(--md-error-hover); }

/* Ghost / Text */
.btn--ghost {
  background: transparent;
  color: var(--md-on-surface-variant);
  border-color: transparent;
  border-radius: var(--radius-pill);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--md-surface-2);
  color: var(--md-on-surface);
}

/* Warn */
.btn--warn {
  background: var(--md-warning);
  color: #fff;
}
.btn--warn:hover:not(:disabled) { background: #d97706; }

/* Sizes */
.btn--sm { padding: 5px 12px; font-size: 12px; }
.btn--sm .material-symbols-outlined { font-size: 14px; }
.btn--lg { padding: 10px 24px; font-size: 14px; }
.btn--icon {
  padding: 7px;
  border-radius: var(--radius-pill);
  min-width: 34px;
  min-height: 34px;
  justify-content: center;
}
.btn--icon.btn--sm { padding: 5px; min-width: 28px; min-height: 28px; }

/* Material Web overrides */
md-filled-button,
md-outlined-button,
md-text-button,
md-tonal-button {
  --md-ref-typeface-plain: var(--font);
  --md-sys-color-primary: var(--md-primary);
  --md-sys-color-on-primary: #fff;
  --md-filled-button-container-height: 36px;
  --md-outlined-button-container-height: 36px;
  --md-text-button-container-height: 36px;
  font-family: var(--font);
}

/* ==========================================================================
   Components — Toolbar
   ========================================================================== */

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--md-surface-variant);
  border-bottom: 1px solid var(--md-outline);
  flex-wrap: wrap;
}
.toolbar__sep {
  width: 1px; height: 20px;
  background: var(--md-outline-variant);
  margin: 0 4px;
}
.toolbar__label {
  font-size: 12px;
  color: var(--md-on-surface-muted);
  font-weight: 500;
}
.toolbar__stats {
  margin-left: auto;
  font-size: 12px;
  color: var(--md-on-surface-muted);
  white-space: nowrap;
}

/* ==========================================================================
   Components — Forms
   ========================================================================== */

.form-row {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}
.form-row--2 { grid-template-columns: 1fr 1fr; }
.form-row--3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 600px) {
  .form-row--2, .form-row--3 { grid-template-columns: 1fr; }
}

.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  letter-spacing: .01em;
}

.form-input {
  padding: 9px 12px;
  border: 1.5px solid var(--md-outline);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: var(--font);
  color: var(--md-on-surface);
  background: var(--md-surface);
  outline: none;
  transition: border-color var(--duration-sm) var(--ease-default),
              box-shadow var(--duration-sm) var(--ease-default);
}
.form-input:hover:not(:focus) { border-color: var(--md-outline-variant); }
.form-input:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
.form-input--error {
  border-color: var(--md-error) !important;
  background: var(--md-error-container);
}
.form-input--error:focus {
  box-shadow: 0 0 0 3px rgba(239,68,68,.15) !important;
}
.form-error { font-size: 11px; color: var(--md-error); font-weight: 500; }
.form-help  { font-size: 11px; color: var(--md-on-surface-muted); }

select.form-input { cursor: pointer; }
textarea.form-input { resize: vertical; min-height: 80px; }

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--md-on-surface);
}
.toggle input[type=checkbox] { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle__track {
  width: 40px; height: 22px;
  background: var(--md-outline-variant);
  border-radius: var(--radius-pill);
  transition: background var(--duration-sm) var(--ease-default);
  flex-shrink: 0;
  position: relative;
}
.toggle__thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-sm) var(--ease-default);
}
.toggle input:checked ~ .toggle__track { background: var(--md-primary); }
.toggle input:checked ~ .toggle__track .toggle__thumb { transform: translateX(18px); }

/* ==========================================================================
   Components — Filter bar
   ========================================================================== */

/* Bouton toggle visible uniquement sur mobile */
.filter-toggle {
  display: none;
  padding: 8px 16px;
  border-bottom: 1px solid var(--md-outline);
  background: var(--md-surface-variant);
}
@media (max-width: 768px) {
  .filter-toggle { display: flex; }
}

.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  background: var(--md-surface-variant);
  border-bottom: 1px solid var(--md-outline);
  flex-wrap: wrap;
}
.filter-bar label {
  font-size: 12px;
  color: var(--md-on-surface-muted);
  font-weight: 500;
  white-space: nowrap;
}
.filter-bar input,
.filter-bar select {
  padding: 6px 10px;
  border: 1.5px solid var(--md-outline);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: var(--font);
  background: var(--md-surface);
  outline: none;
  color: var(--md-on-surface);
  transition: border-color var(--duration-sm);
  min-width: 0;
}
.filter-bar input { flex: 1; min-width: 140px; max-width: 240px; }
.filter-bar input:focus,
.filter-bar select:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.filter-bar select { cursor: pointer; }

/* ==========================================================================
   Data Table
   ========================================================================== */

.data-table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 10px 16px;
  background: var(--md-surface-variant);
  border-bottom: 1.5px solid var(--md-outline);
  text-align: left;
  font-weight: 600;
  font-size: 11.5px;
  color: var(--md-on-surface-variant);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.data-table thead th:hover { background: var(--md-surface-2); color: var(--md-on-surface); }
.data-table thead th.sorted-asc::after  { content: " ↑"; color: var(--md-primary); }
.data-table thead th.sorted-desc::after { content: " ↓"; color: var(--md-primary); }

.data-table tbody tr {
  border-bottom: 1px solid var(--md-outline);
  transition: background var(--duration-xs) var(--ease-default);
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: #f0f4ff; }
.data-table tbody tr.selected { background: var(--md-primary-container); }
.data-table tbody tr.deleting { opacity: .5; background: var(--md-error-container); }
.data-table tbody tr.row-current {
  background: #eff6ff;
  font-weight: 500;
}
.data-table tbody tr.row-current td:first-child::before {
  content: "▶ ";
  color: var(--md-primary);
  font-size: 9px;
}

.data-table td {
  padding: 10px 16px;
  vertical-align: middle;
  color: var(--md-on-surface);
}

/* Editable cell (morceaux grid) */
.cell-input {
  width: 100%;
  padding: 4px 8px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  background: transparent;
  outline: none;
  text-align: right;
  transition: border-color var(--duration-xs), background var(--duration-xs);
}
.cell-input:hover { border-color: var(--md-outline); background: var(--md-surface); }
.cell-input:focus {
  border-color: var(--md-primary);
  background: var(--md-surface);
  box-shadow: 0 0 0 2px rgba(79,70,229,.15);
}
.cell-input--error { border-color: var(--md-error) !important; background: var(--md-error-container) !important; }
.cell-input[type=text] { text-align: left; }

.row-dirty td:first-child::before {
  content: "●";
  color: var(--md-warning);
  margin-right: 6px;
  font-size: 8px;
}

.data-table tbody tr.row-inactive {
  opacity: .55;
}

/* ==========================================================================
   Table scroll — indicateur de défilement horizontal (mobile)
   ========================================================================== */

.table-scroll-container {
  position: relative;
}
.table-scroll-container::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 48px;
  background: linear-gradient(to left, var(--md-surface) 0%, transparent 100%);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  z-index: 5;
}
@media (max-width: 768px) {
  .table-scroll-container::after { opacity: 1; }
}

/* ==========================================================================
   Billing — Tabs mobile (sélecteur de plan sur le tableau comparatif)
   ========================================================================== */

.billing-plan-tabs {
  display: none;
  gap: 4px;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--md-outline-variant);
}
.billing-tab {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  justify-content: center;
  padding: 7px 6px;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color .15s, border-color .15s;
}
.billing-tab--active             { color: var(--md-on-surface); border-bottom-color: var(--md-on-surface); }
.billing-tab--active.billing-tab--starter { color: #6366f1; border-bottom-color: #6366f1; }
.billing-tab--active.billing-tab--pro     { color: #d97706; border-bottom-color: #d97706; }

@media (max-width: 640px) {
  .billing-plan-tabs { display: flex; }

  /* Masquer colonnes non sélectionnées sur mobile */
  #billing-compare-table[data-plan="free"] th:nth-child(3),
  #billing-compare-table[data-plan="free"] th:nth-child(4),
  #billing-compare-table[data-plan="free"] td:nth-child(3),
  #billing-compare-table[data-plan="free"] td:nth-child(4) { display: none; }

  #billing-compare-table[data-plan="starter"] th:nth-child(2),
  #billing-compare-table[data-plan="starter"] th:nth-child(4),
  #billing-compare-table[data-plan="starter"] td:nth-child(2),
  #billing-compare-table[data-plan="starter"] td:nth-child(4) { display: none; }

  #billing-compare-table[data-plan="pro"] th:nth-child(2),
  #billing-compare-table[data-plan="pro"] th:nth-child(3),
  #billing-compare-table[data-plan="pro"] td:nth-child(2),
  #billing-compare-table[data-plan="pro"] td:nth-child(3) { display: none; }

  /* Colonne feature prend plus de place quand une seule colonne plan visible */
  #billing-compare-table th:nth-child(1),
  #billing-compare-table td:nth-child(1) { width: 55%; }
}

/* ==========================================================================
   Components — Badge / Chip
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
}
.badge--ok     { background: var(--md-success-container);  color: #065f46; }
.badge--warn   { background: var(--md-warning-container);  color: #78350f; }
.badge--error  { background: var(--md-error-container);    color: #991b1b; }
.badge--info   { background: var(--md-primary-container);  color: #3730a3; }
.badge--muted  { background: var(--md-surface-2);          color: var(--md-on-surface-muted); }

/* ==========================================================================
   Components — Modal
   ========================================================================== */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(4px);
  z-index: 260;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: backdropIn var(--duration-md) var(--ease-decel);
}
@keyframes backdropIn { from { opacity: 0; } }

.modal {
  background: var(--md-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  min-width: 380px;
  max-width: 640px;
  width: 100%;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 80px);
  overflow: hidden;
  animation: modalIn var(--duration-md) var(--ease-decel);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } }

@media (max-width: 600px) {
  .modal-backdrop { padding: 12px; align-items: flex-end; }
  .modal { min-width: 0; max-width: 100%; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
  @keyframes modalIn { from { opacity: 0; transform: translateY(20px); } }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--md-outline);
  font-weight: 600;
  font-size: 16px;
  color: var(--md-on-surface);
  letter-spacing: -.02em;
}
.modal__body { padding: 20px; overflow-y: auto; flex: 1; }
.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--md-outline);
  background: var(--md-surface-variant);
}
.modal__close {
  background: none; border: none; cursor: pointer;
  color: var(--md-on-surface-muted);
  width: 32px; height: 32px;
  border-radius: var(--radius-pill);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--duration-sm), color var(--duration-sm);
  font-size: 18px;
}
.modal__close:hover { background: var(--md-surface-2); color: var(--md-on-surface); }

/* Confirmation dialog */
.msgbox .modal { max-width: 420px; }
.modal__body--center { text-align: center; padding: 28px 20px 20px; }
.msgbox__icon {
  font-size: 40px;
  margin-bottom: 12px;
  line-height: 1;
}
.msgbox p { color: var(--md-on-surface-variant); font-size: 14px; line-height: 1.6; }

/* ==========================================================================
   Components — Toast
   ========================================================================== */

.toast-container {
  position: fixed;
  bottom: 36px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #1e293b;
  color: #f1f5f9;
  border-radius: var(--radius-lg);
  font-size: 13.5px;
  font-weight: 450;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  min-width: 260px;
  max-width: 420px;
  animation: toastIn .25s var(--ease-decel);
  border: 1px solid rgba(255,255,255,.08);
}
@keyframes toastIn { from { transform: translateX(16px) translateY(4px); opacity: 0; } }

.toast--ok    { border-left: 3px solid var(--md-success); }
.toast--warn  { border-left: 3px solid var(--md-warning); }
.toast--error { border-left: 3px solid var(--md-error); }

.toast__icon {
  font-size: 18px;
  flex-shrink: 0;
}
.toast--ok   .toast__icon { color: var(--md-success); }
.toast--warn .toast__icon { color: var(--md-warning); }
.toast--error .toast__icon { color: var(--md-error); }

/* ==========================================================================
   Optimisation — Progress
   ========================================================================== */

.progress-bar-wrap {
  height: 8px;
  background: var(--md-surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  border-radius: inherit;
  transition: width .4s var(--ease-default);
  background: linear-gradient(90deg, var(--md-primary), #818cf8);
}
.progress-bar--running {
  background: linear-gradient(90deg, var(--md-primary), #818cf8);
  animation: progressPulse 1.5s ease-in-out infinite alternate;
}
.progress-bar--done { background: linear-gradient(90deg, var(--md-success), #34d399); }
.progress-bar--error { background: var(--md-error); }
@keyframes progressPulse {
  from { opacity: .85; }
  to   { opacity: 1; }
}

/* md-linear-progress theming */
md-linear-progress {
  --md-linear-progress-track-height: 8px;
  --md-linear-progress-active-indicator-height: 8px;
  --md-sys-color-primary: var(--md-primary);
  --md-linear-progress-track-shape: 9999px;
  border-radius: var(--radius-pill);
  overflow: hidden;
}

/* Grille de tuiles statistiques — 2 colonnes min */
.optim-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 600px) {
  .optim-stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

.stat-card {
  background: var(--md-surface);
  border: 1px solid var(--md-outline);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--duration-sm) var(--ease-default),
              transform var(--duration-sm) var(--ease-default);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--md-primary), var(--md-secondary));
  opacity: 0.6;
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.stat-card__value {
  font-size: 28px;
  font-weight: 700;
  color: var(--md-on-surface);
  letter-spacing: -.04em;
  line-height: 1.15;
  margin-top: 4px;
}
.stat-card__label {
  font-size: 10px;
  color: var(--md-on-surface-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.stat-card__note { font-size: 10px; color: var(--md-on-surface-muted); margin-top: 3px; opacity: .7; }
.stat-card__value--warn { color: var(--md-warning) !important; }
.stat-card__value--ok   { color: var(--md-success) !important; }

/* ==========================================================================
   Modals — Grille comparatif plans (Free / Starter / Pro)
   ========================================================================== */

.modal-plans-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  align-items: stretch;
}

/* Sur mobile : une colonne, Starter mis en avant en premier */
@media (max-width: 520px) {
  .modal-plans-grid {
    grid-template-columns: 1fr;
  }
  .modal-plans-grid > :nth-child(2) { order: -1; } /* Starter en tête */
  .modal-plans-grid > :nth-child(1) { order:  0; } /* Free */
  .modal-plans-grid > :nth-child(3) { order:  1; } /* Pro */

  /* Réduire le padding latéral des modals sur mobile */
  .modal-content-pad { padding: 14px 14px !important; }
}

/* ==========================================================================
   Canvas — Plan de découpe
   ========================================================================== */

.canvas-container {
  overflow: auto;
  background: #e8ecf0;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.canvas-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--md-surface-variant);
  border-bottom: 1px solid var(--md-outline);
  font-size: 13px;
  flex-wrap: wrap;
}
.canvas-nav__label { font-weight: 600; }

/* ==========================================================================
   Paramètres — table style
   ========================================================================== */

.param-group-row td {
  padding: 8px 16px;
  background: var(--md-surface-variant);
  border-top: 2px solid var(--md-outline);
  border-bottom: 1px solid var(--md-outline);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--md-on-surface-variant);
}
.param-group-row:first-child td { border-top: none; }
.param-group-icon {
  font-size: 14px !important;
  vertical-align: middle;
  margin-right: 6px;
  color: var(--md-primary);
}
.param-row--modified td { background: #f0fdf4; }
.param-row--error td   { background: var(--md-error-container); }

/* ==========================================================================
   Empty State
   ========================================================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 20px;
  color: var(--md-on-surface-muted);
  gap: 12px;
  text-align: center;
}
.empty-state .material-symbols-outlined {
  font-size: 48px;
  opacity: .35;
}
.empty-state h3 {
  font-size: 16px;
  color: var(--md-on-surface-variant);
  font-weight: 600;
  letter-spacing: -.01em;
}
.empty-state p { font-size: 13px; max-width: 280px; line-height: 1.5; }

/* ==========================================================================
   Onboarding Hero
   ========================================================================== */

.onboarding-hero {
  background: linear-gradient(135deg, color-mix(in srgb, var(--md-primary) 8%, var(--md-surface)) 0%, var(--md-surface-variant) 100%);
  border-radius: var(--radius-lg);
  border: 1px solid var(--md-outline);
  margin-bottom: 20px;
  padding: 48px 24px;
  text-align: center;
}
.onboarding-hero__inner { max-width: 700px; margin: 0 auto; }

.onboarding-hero__title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--md-on-surface);
  margin-bottom: 8px;
}
.onboarding-hero__sub {
  font-size: 15px;
  color: var(--md-on-surface-muted);
  margin-bottom: 36px;
}

.onboarding-steps {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
  margin-bottom: 36px;
  flex-wrap: wrap;
}

.onboarding-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 120px;
  padding: 16px 12px;
  background: var(--md-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--md-outline);
}
.onboarding-step__icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--md-primary) 12%, var(--md-surface));
  display: flex; align-items: center; justify-content: center;
}
.onboarding-step__icon .material-symbols-outlined { font-size: 24px; color: var(--md-primary); }
.onboarding-step__num { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--md-primary); }
.onboarding-step__label { font-size: 13px; font-weight: 700; color: var(--md-on-surface); }
.onboarding-step__desc { font-size: 11px; color: var(--md-on-surface-muted); line-height: 1.4; text-align: center; }

.onboarding-step__arrow { display: flex; align-items: center; padding-top: 24px; color: var(--md-on-surface-muted); }
.onboarding-step__arrow .material-symbols-outlined { font-size: 20px; }

.onboarding-hero__cta { font-size: 15px; min-height: 52px; padding: 0 32px; }

@media (max-width: 768px) {
  .onboarding-hero { padding: 28px 16px; }
  .onboarding-hero__title { font-size: 20px; }
  .onboarding-steps { gap: 8px; }
  .onboarding-step__arrow { display: none; }
  .onboarding-step { min-width: calc(50% - 8px); flex: 1 1 calc(50% - 8px); }
}

/* ==========================================================================
   Component — FAB (Floating Action Button) — mobile only
   ========================================================================== */

.fab-wrap {
  position: fixed;
  bottom: calc(var(--bottom-nav-h, 64px) + 16px);
  right: 16px;
  z-index: 250;
  display: none;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 10px;
}
@media (max-width: 768px) { .fab-wrap { display: flex; } }

.fab {
  width: 56px; height: 56px;
  border-radius: 28px;
  background: var(--md-primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.28);
  -webkit-tap-highlight-color: transparent;
}
.fab:active { transform: scale(.92); }
.fab .material-symbols-outlined { font-size: 24px; transition: transform 220ms; }
.fab-wrap.is-open .fab:not(.fab--solo) .material-symbols-outlined { transform: rotate(45deg); }

.fab-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  opacity: 0;
  transform: translateY(8px) scale(.92);
  pointer-events: none;
  transition: opacity 200ms, transform 200ms;
}
.fab-wrap.is-open .fab-items { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

.fab-item { display: flex; align-items: center; gap: 10px; }
.fab-item__label {
  background: var(--md-surface);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--md-on-surface);
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  white-space: nowrap;
}
.fab-item__btn {
  width: 40px; height: 40px;
  border-radius: 20px;
  background: var(--md-surface);
  border: 1px solid var(--md-outline);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  color: var(--md-primary);
  -webkit-tap-highlight-color: transparent;
}
.fab-item__btn:active { background: var(--md-surface-variant); }
.fab-item__btn .material-symbols-outlined { font-size: 20px; }

/* ==========================================================================
   Component — Filter Chips
   ========================================================================== */

.filter-chips {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
  border-bottom: 1px solid var(--md-outline);
}
.filter-chips::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 100px;
  border: 1.5px solid var(--md-outline);
  background: var(--md-surface);
  color: var(--md-on-surface);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  transition: background 150ms, color 150ms, border-color 150ms;
}
.chip:active { opacity: .7; }
.chip--active { background: var(--md-primary); border-color: var(--md-primary); color: white; }
.chip .material-symbols-outlined { font-size: 15px; }

/* ── Bouton "···" dans mc-body (mobile uniquement) ── */
.mc-ctx-btn {
  display: none;
  position: absolute;
  top: -2px; right: -4px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: none;
  border: none;
  color: var(--md-on-surface-muted);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.mc-ctx-btn .material-symbols-outlined { font-size: 20px; }
.mc-ctx-btn:active { background: rgba(0,0,0,.06); }

@media (max-width: 768px) {
  .mc-ctx-btn { display: flex; }
  .mc-body { position: relative; padding-right: 40px; }
  .mc-actions { display: none !important; }
  .data-table td.row-actions { padding-bottom: 12px; }
  .card__header-action--mobile-hide { display: none !important; }
}

/* Responsive helpers */
.mobile-only { display: none; }
.desktop-only { display: block; }

/* Barre d'actions rapides sur le canvas mobile */
.canvas-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 12px 4px;
  background: var(--md-surface);
  border: none;
  cursor: pointer;
  color: var(--md-on-surface);
  font-size: 10px;
  font-family: var(--font);
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
  transition: background 120ms;
}
.canvas-action-btn:active { background: var(--md-surface-variant); }
.canvas-action-btn:disabled { opacity: .4; pointer-events: none; }
.canvas-action-btn .material-symbols-outlined { font-size: 22px; color: var(--md-primary); }

/* ==========================================================================
   Utilities
   ========================================================================== */

.text-right    { text-align: right; }
.text-center   { text-align: center; }
.text-muted    { color: var(--md-on-surface-muted); }
.text-danger   { color: var(--md-error); }
.text-success  { color: var(--md-success); }
.text-warn     { color: var(--md-warning); }
.font-mono     { font-family: var(--font-mono); }
.font-bold     { font-weight: 600; }
.nowrap        { white-space: nowrap; }

.flex          { display: flex; }
.flex-center   { display: flex; align-items: center; }
.flex-between  { display: flex; align-items: center; justify-content: space-between; }
.gap-4         { gap: 4px; }
.gap-8         { gap: 8px; }
.gap-12        { gap: 12px; }
.gap-16        { gap: 16px; }
.mt-4   { margin-top: 4px; }
.mt-8   { margin-top: 8px; }
.mt-12  { margin-top: 12px; }
.mt-16  { margin-top: 16px; }
.mt-24  { margin-top: 24px; }
.mb-8   { margin-bottom: 8px; }
.mb-12  { margin-bottom: 12px; }
.mb-16  { margin-bottom: 16px; }

/* HTMX indicators */
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-indicator { display: none; }
.spin { animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

[x-cloak] { display: none !important; }

/* Material Symbols optimization */
.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 350, 'GRAD' 0, 'opsz' 20;
  line-height: 1;
  vertical-align: middle;
  user-select: none;
}
