/* ==========================================================================
   OPOSSUM 2030 — 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 (dark surface) */
  --sidebar-bg:            #0f172a;
  --sidebar-link:          #94a3b8;
  --sidebar-link-hover:    #f1f5f9;
  --sidebar-link-active:   #a5b4fc;
  --sidebar-section:       #475569;
  --sidebar-active-bg:     rgba(99,102,241,.15);
  --sidebar-active-border: #6366f1;

  /* Layout dimensions */
  --sidebar-w:       240px;
  --topbar-h:        56px;
  --statusbar-h:     28px;

  /* 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;
}

/* ==========================================================================
   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;
  overflow: hidden;
}

/* --- Topbar --- */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: #0f172a;
  color: #f1f5f9;
  box-shadow: 0 1px 0 rgba(255,255,255,.06);
  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__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--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);
  color: var(--sidebar-link);
  overflow-y: auto;
  padding: 12px 0 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) 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 rgba(255,255,255,.06);
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 700;
  color: #f1f5f9;
}
.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: 12px 16px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--sidebar-section);
  font-weight: 600;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--sidebar-link);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 450;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 1px 8px 1px 0;
  transition: background var(--duration-xs) var(--ease-default),
              color var(--duration-xs) var(--ease-default);
  letter-spacing: -.01em;
}
.sidebar__link:hover {
  background: rgba(255,255,255,.06);
  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: 500;
}
.sidebar__link .material-symbols-outlined {
  font-size: 18px;
  flex-shrink: 0;
  opacity: .7;
  transition: opacity var(--duration-xs);
}
.sidebar__link:hover .material-symbols-outlined,
.sidebar__link.active .material-symbols-outlined {
  opacity: 1;
}

/* --- Main content --- */
.main {
  overflow-y: auto;
  padding: 24px;
  background: var(--md-background);
}

/* --- 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); }

/* 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) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr var(--statusbar-h);
  }
  .topbar__hamburger { display: flex; }
  .topbar__divider { display: none; }
  .topbar__affaire { display: none; }
  /* Nav links → icon-only on mobile (sidebar provides full navigation) */
  .topbar__btn-label { display: none; }
  .topbar__btn--ghost { padding: 6px 8px; min-width: 36px; justify-content: center; }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar-w);
    z-index: 90;
    transform: translateX(-100%);
    padding-top: 0;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar__brand { display: flex; }
  .sidebar-overlay.visible { display: block; }
  .main { padding: 12px; }
  /* Results canvas: stack vertically on mobile */
  .results-layout { grid-template-columns: 1fr !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; }

.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-sm);
}
.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;
}

/* ==========================================================================
   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;
}

/* ==========================================================================
   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: 200;
  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-variant);
  border: 1px solid var(--md-outline);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: center;
}
.stat-card__value {
  font-size: 24px;
  font-weight: 700;
  color: var(--md-on-surface);
  letter-spacing: -.04em;
  line-height: 1.2;
}
.stat-card__label {
  font-size: 11px;
  color: var(--md-on-surface-muted);
  margin-top: 4px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.stat-card__note { font-size: 10px; color: var(--md-on-surface-muted); margin-top: 2px; }
.stat-card__value--warn { color: var(--md-warning) !important; }
.stat-card__value--ok   { color: var(--md-success) !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; }

/* ==========================================================================
   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;
}
