/* =============================================================================
   CarbonLab SI — Design System
   Inspiré Wavestone: violet accent, vert/bleu gradients, WCAG AA compliant
   ============================================================================= */

/* ── CSS VARIABLES ────────────────────────────────────────────────────────── */
:root,
[data-theme="light"] {
  /* Primary — Violet Wavestone */
  --primary:        #7c3aed;
  --primary-hover:  #6d28d9;
  --primary-light:  #7c3aed22;
  --primary-bg:     #f3f0ff;

  /* Secondary colors */
  --green:          #16a34a;
  --green-light:    #dcfce7;
  --blue:           #2563eb;
  --blue-light:     #dbeafe;
  --orange:         #ea580c;
  --orange-light:   #ffedd5;
  --red:            #dc2626;
  --red-light:      #fee2e2;
  --yellow:         #ca8a04;
  --yellow-light:   #fef9c3;
  --teal:           #0d9488;
  --teal-light:     #ccfbf1;

  /* Backgrounds */
  --bg:             #f8f7ff;
  --surface:        #ffffff;
  --surface2:       #f4f3ff;
  --border:         #e5e3f5;
  --border-hover:   #c4b5fd;

  /* Text */
  --text1:          #1a1735;
  --text2:          #4b4870;
  --text3:          #8b87b0;

  /* Sidebar */
  --sidebar-bg:     #1a1735;
  --sidebar-text:   #c4b5fd;
  --sidebar-active: #7c3aed;
  --sidebar-hover:  #2d2750;
  --sidebar-border: #2d2750;

  /* Cards */
  --card-shadow:    0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(124,58,237,0.06);
  --card-shadow-hover: 0 4px 24px rgba(124,58,237,0.15);

  /* Gradient */
  --gradient-main:  linear-gradient(135deg, #7c3aed 0%, #2563eb 100%);
  --gradient-green: linear-gradient(135deg, #16a34a 0%, #0d9488 100%);
}

[data-theme="dark"] {
  --primary:        #a78bfa;
  --primary-hover:  #8b5cf6;
  --primary-light:  #a78bfa22;
  --primary-bg:     #1a1535;

  --green:          #4ade80;
  --green-light:    #14532d;
  --blue:           #60a5fa;
  --blue-light:     #1e3a5f;
  --orange:         #fb923c;
  --orange-light:   #431407;
  --red:            #f87171;
  --red-light:      #450a0a;
  --yellow:         #facc15;
  --yellow-light:   #422006;
  --teal:           #2dd4bf;
  --teal-light:     #042f2e;

  --bg:             #0f0d1e;
  --surface:        #1a1735;
  --surface2:       #221e3a;
  --border:         #2d2750;
  --border-hover:   #7c3aed;

  --text1:          #f3f0ff;
  --text2:          #c4b5fd;
  --text3:          #7c6faa;

  --sidebar-bg:     #110e22;
  --sidebar-text:   #a78bfa;
  --sidebar-active: #7c3aed;
  --sidebar-hover:  #1a1535;
  --sidebar-border: #2d2750;

  --card-shadow:    0 1px 3px rgba(0,0,0,0.3), 0 4px 16px rgba(124,58,237,0.1);
  --card-shadow-hover: 0 4px 24px rgba(167,139,250,0.2);
}

/* ── RESET & BASE ─────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text1);
  line-height: 1.5;
  display: flex;
  min-height: 100vh;
  overflow: hidden;
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; }
input, select, textarea { font-family: inherit; }
img { max-width: 100%; }

/* ── LAYOUT ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  transition: width 0.25s ease, min-width 0.25s ease;
  overflow: hidden;
  border-right: 1px solid var(--sidebar-border);
}

.sidebar.collapsed {
  width: 60px;
  min-width: 60px;
}

.sidebar.collapsed .sidebar-logo-title,
.sidebar.collapsed .sidebar-logo-sub,
.sidebar.collapsed .sidebar-org-name,
.sidebar.collapsed .sidebar-org-period,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed #lang-label,
.sidebar.collapsed .sidebar-footer > div:first-child {
  display: none;
}

.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }
.sidebar.collapsed .nav-icon { margin-right: 0; }
.sidebar.collapsed .sidebar-logo { justify-content: center; padding: 16px 8px; }
.sidebar.collapsed .sidebar-org { justify-content: center; padding: 8px; }
.sidebar.collapsed .sidebar-footer { justify-content: center; }

.main-content {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: margin-left 0.25s ease;
}

.main-content.sidebar-collapsed {
  margin-left: 60px;
}

/* ── SIDEBAR COMPONENTS ───────────────────────────────────────────────────── */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--gradient-main);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-logo-title {
  font-size: 15px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.sidebar-logo-sub {
  font-size: 10px;
  color: var(--sidebar-text);
  white-space: nowrap;
}

.sidebar-org {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--sidebar-hover);
  margin: 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}
.sidebar-org:hover { background: var(--sidebar-active); }

.sidebar-org-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--gradient-main);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}

.sidebar-org-name {
  font-size: 12px;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-org-period {
  font-size: 10px;
  color: var(--sidebar-text);
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 8px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 2px; }

.nav-section-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--sidebar-text);
  padding: 12px 12px 4px;
  text-transform: uppercase;
  opacity: 0.7;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  margin-bottom: 1px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #ffffff;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #ffffff;
  font-weight: 700;
}

.nav-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: white;
  font-size: 9px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-footer > div:first-child {
  font-size: 9px;
  color: var(--sidebar-text);
  opacity: 0.6;
}

.sidebar-toggle-btn {
  background: var(--sidebar-hover);
  border: none;
  border-radius: 8px;
  color: var(--sidebar-text);
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
  flex-shrink: 0;
}
.sidebar-toggle-btn:hover {
  background: var(--sidebar-active);
  color: white;
}

/* ── TOPBAR ────────────────────────────────────────────────────────────────── */
.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text2);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.topbar-btn:hover { background: var(--surface2); border-color: var(--primary); color: var(--primary); }

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text1);
}

.topbar-period {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 6px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.topbar-select {
  background: none;
  border: none;
  font-size: 12px;
  color: var(--text1);
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--red);
  color: white;
  font-size: 9px;
  font-weight: 800;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient-main);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── PAGE CONTENT ─────────────────────────────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}

.page-content::-webkit-scrollbar { width: 6px; }
.page-content::-webkit-scrollbar-track { background: transparent; }
.page-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── CARDS ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--card-shadow);
  padding: 20px;
  transition: box-shadow 0.2s, border-color 0.2s;
}
.card:hover { box-shadow: var(--card-shadow-hover); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text1);
}

.card-subtitle {
  font-size: 12px;
  color: var(--text3);
  margin-top: 2px;
}

/* ── KPI CARDS ────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

@media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px)  { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--card-shadow);
  position: relative;
  overflow: hidden;
  transition: all 0.2s;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: 14px 14px 0 0;
}
.kpi-card.purple::before { background: var(--gradient-main); }
.kpi-card.green::before  { background: var(--gradient-green); }
.kpi-card.blue::before   { background: linear-gradient(90deg, var(--blue), var(--teal)); }
.kpi-card.orange::before { background: linear-gradient(90deg, var(--orange), var(--yellow)); }

.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--card-shadow-hover); }

.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 900;
  color: var(--text1);
  line-height: 1;
}

.kpi-unit {
  font-size: 13px;
  font-weight: 600;
  color: var(--text3);
  margin-left: 4px;
}

.kpi-label {
  font-size: 12px;
  color: var(--text3);
  font-weight: 500;
}

.kpi-trend {
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}
.kpi-trend.up   { color: var(--red); }
.kpi-trend.down { color: var(--green); }

.kpi-mini {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.kpi-mini-label { font-size: 11px; color: var(--text3); margin-bottom: 4px; }
.kpi-mini-value { font-size: 18px; font-weight: 800; color: var(--text1); }

/* ── BUTTONS ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--gradient-main);
  color: white;
  box-shadow: 0 2px 8px rgba(124,58,237,0.3);
}
.btn-primary:hover {
  box-shadow: 0 4px 16px rgba(124,58,237,0.4);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text2);
}
.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-bg);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text2);
}
.btn-ghost:hover { background: var(--surface2); }

.btn-danger {
  background: var(--red-light);
  border-color: var(--red);
  color: var(--red);
}
.btn-danger:hover {
  background: var(--red);
  color: white;
}

.btn-success {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green);
}
.btn-success:hover {
  background: var(--green);
  color: white;
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-icon { padding: 7px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ── BADGES ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge-purple  { background: var(--primary-bg);   color: var(--primary); }
.badge-green   { background: var(--green-light);   color: var(--green); }
.badge-blue    { background: var(--blue-light);    color: var(--blue); }
.badge-orange  { background: var(--orange-light);  color: var(--orange); }
.badge-red     { background: var(--red-light);     color: var(--red); }
.badge-yellow  { background: var(--yellow-light);  color: var(--yellow); }
.badge-gray    { background: var(--surface2);      color: var(--text3); }
.badge-teal    { background: var(--teal-light);    color: var(--teal); }

.quality-verified { background: var(--green-light);  color: var(--green);   padding: 2px 6px; border-radius: 4px; font-size: 10px; }
.quality-estimated{ background: var(--yellow-light); color: var(--yellow);  padding: 2px 6px; border-radius: 4px; font-size: 10px; }
.quality-default  { background: var(--orange-light); color: var(--orange);  padding: 2px 6px; border-radius: 4px; font-size: 10px; }
.quality-official { background: var(--blue-light);   color: var(--blue);    padding: 2px 6px; border-radius: 4px; font-size: 10px; }

/* ── FORMS ────────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: auto; } }

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

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
}

.form-input,
.form-select,
.form-textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text1);
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-input::placeholder { color: var(--text3); }

/* ── TABLES ───────────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead {
  background: var(--surface2);
  position: sticky;
  top: 0;
  z-index: 1;
}

thead th {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  text-align: left;
  white-space: nowrap;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

tbody td {
  padding: 10px 14px;
  color: var(--text1);
  vertical-align: middle;
}

.col-actions { width: 100px; text-align: right; }

/* ── PROGRESS BARS ────────────────────────────────────────────────────────── */
.progress-bar {
  background: var(--surface2);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.5s ease;
}

.progress-fill.purple { background: var(--gradient-main); }
.progress-fill.green  { background: var(--gradient-green); }
.progress-fill.blue   { background: linear-gradient(90deg, var(--blue), var(--teal)); }
.progress-fill.orange { background: linear-gradient(90deg, var(--orange), var(--yellow)); }

/* ── PERCENTILE BAND ──────────────────────────────────────────────────────── */
.percentile-container {
  position: relative;
  background: linear-gradient(90deg, #16a34a 0%, #84cc16 25%, #eab308 50%, #f97316 75%, #dc2626 100%);
  border-radius: 8px;
  overflow: visible;
}

.percentile-marker {
  position: absolute;
  width: 3px;
  background: var(--text1);
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 0 2px white;
}

/* ── MODALS ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.2);
  max-height: 92vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s ease;
  overflow-y: auto;   /* scroll instead of clip */
  overflow-x: hidden;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(-8px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text1);
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-close {
  background: var(--surface2);
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text3);
  font-size: 14px;
  transition: all 0.2s;
}
.modal-close:hover { background: var(--red-light); color: var(--red); }

/* Modals dynamiques — taille adaptative + scroll fiable */
#modal-container .modal {
  overflow-y: auto;
  height: auto;       /* s'adapte au contenu */
}
#modal-container .modal > form {
  overflow-y: visible;
  flex: 1;
}
/* Scrollbar slim pour les modals */
#modal-container .modal::-webkit-scrollbar { width: 5px; }
#modal-container .modal::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#modal-container .modal::-webkit-scrollbar-track { background: transparent; }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* ── LINEAGE STEPS ────────────────────────────────────────────────────────── */
.lineage-steps { display: flex; flex-direction: column; gap: 10px; }

.lineage-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  background: var(--surface2);
  border-radius: 10px;
  border-left: 3px solid var(--primary);
}

.lineage-step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lineage-step-label { font-size: 12px; font-weight: 700; color: var(--text2); margin-bottom: 2px; }
.lineage-step-value { font-size: 14px; font-weight: 800; color: var(--text1); }
.lineage-step-source { font-size: 11px; color: var(--text3); margin-top: 4px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.lineage-step-url {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--primary);
  margin-top: 4px;
}
.lineage-step-url:hover { text-decoration: underline; }

/* ── NOTIFICATIONS ────────────────────────────────────────────────────────── */
.notifications-panel {
  position: absolute;
  top: 56px;
  right: 20px;
  width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--card-shadow-hover);
  z-index: 100;
  overflow: hidden;
}

.notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-size: 13px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}

.notif-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--surface2); }

/* ── TOASTS ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  min-width: 280px;
  max-width: 380px;
  transform: translateX(120%);
  transition: transform 0.3s ease;
}
.toast.show { transform: translateX(0); }

/* ── DROPDOWN ─────────────────────────────────────────────────────────────── */
.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--card-shadow-hover);
  min-width: 200px;
  z-index: 200;
  display: none;
  overflow: hidden;
  animation: menuIn 0.15s ease;
}

.dropdown-menu.open { display: block; }

@keyframes menuIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text1);
  cursor: pointer;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  transition: background 0.15s;
}
.dropdown-item:hover { background: var(--surface2); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── CHARTS ───────────────────────────────────────────────────────────────── */
.chart-container {
  position: relative;
  width: 100%;
}

.chart-wrap {
  position: relative;
  padding: 4px;
}

/* ── ANIMATIONS ───────────────────────────────────────────────────────────── */
.fade-in {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── LOADING ──────────────────────────────────────────────────────────────── */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── EMPTY STATE ─────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text3);
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
  color: var(--border);
}

.empty-state h3 { font-size: 16px; font-weight: 700; color: var(--text2); margin-bottom: 8px; }
.empty-state p  { font-size: 13px; color: var(--text3); }

/* ── PAGE SECTIONS ────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 22px;
  font-weight: 900;
  color: var(--text1);
  letter-spacing: -0.5px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text3);
  margin-top: 4px;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── FILTER BAR ───────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filter-bar .form-input,
.filter-bar .form-select {
  max-width: 200px;
  padding: 7px 12px;
}

.filter-bar .form-input[type="search"] { max-width: 240px; }

/* ── GRID LAYOUTS ─────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 16px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.grid-3-1 { display: grid; grid-template-columns: 3fr 1fr; gap: 16px; }

@media (max-width: 1024px) {
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-1-2, .grid-2-1, .grid-3-1 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ── EMISSION LEVEL COLORS ────────────────────────────────────────────────── */
.emission-critical { color: var(--red); }
.emission-high     { color: var(--orange); }
.emission-medium   { color: var(--yellow); }
.emission-low      { color: var(--green); }

/* ── WATERFALL CHART ──────────────────────────────────────────────────────── */
.waterfall-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.waterfall-label { font-size: 11px; color: var(--text2); width: 120px; flex-shrink: 0; text-align: right; }
.waterfall-track { flex: 1; height: 20px; background: var(--surface2); border-radius: 4px; overflow: visible; position: relative; }
.waterfall-fill  { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.waterfall-value { font-size: 11px; font-weight: 700; color: var(--text1); width: 80px; flex-shrink: 0; }

/* ── METHODOLOGY TAB ──────────────────────────────────────────────────────── */
.methodology-source {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}
.methodology-source-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text1);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.methodology-source-meta {
  font-size: 11px;
  color: var(--text3);
  margin-bottom: 6px;
}
.methodology-source-url {
  font-size: 11px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 4px;
}
.methodology-source-url:hover { text-decoration: underline; }

/* ── SERVICE CHAIN ────────────────────────────────────────────────────────── */
.service-chain-viz {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 20px;
}

.chain-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  min-width: 100px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.chain-node:hover, .chain-node.selected {
  border-color: var(--primary);
  background: var(--primary-bg);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.chain-arrow { font-size: 18px; color: var(--text3); }
.chain-node-icon { font-size: 20px; }
.chain-node-name { font-size: 11px; font-weight: 700; color: var(--text1); }
.chain-node-emit { font-size: 10px; color: var(--primary); font-weight: 800; }

/* ── WORLD MAP ────────────────────────────────────────────────────────────── */
#world-map-canvas {
  width: 100%;
  height: 480px;
  border-radius: 14px;
  background: linear-gradient(180deg, #0a0a2e 0%, #1a1a4a 100%);
}

.map-dot {
  position: absolute;
  border-radius: 50%;
  background: var(--primary);
  transform: translate(-50%, -50%);
  animation: pulse 2s ease-in-out infinite;
  cursor: pointer;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(124,58,237,0.4); }
  50%       { box-shadow: 0 0 0 12px rgba(124,58,237,0); }
}

/* ── IMPORT ZONE ──────────────────────────────────────────────────────────── */
.import-dropzone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 48px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--surface2);
}
.import-dropzone:hover,
.import-dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-bg);
}
.import-dropzone i { font-size: 48px; color: var(--primary); margin-bottom: 16px; }
.import-dropzone h3 { font-size: 16px; font-weight: 700; color: var(--text1); margin-bottom: 8px; }
.import-dropzone p  { font-size: 13px; color: var(--text3); }

/* ── SCORE GAUGE ──────────────────────────────────────────────────────────── */
.score-gauge-wrapper { position: relative; }
.score-gauge-value {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ── MISC ─────────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.text-muted  { color: var(--text3) !important; }
.text-small  { font-size: 11px !important; }
.font-mono   { font-family: 'Courier New', monospace !important; }
.font-bold   { font-weight: 700 !important; }
.text-center { text-align: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

/* ── EQUIVALENCES DISPLAY ─────────────────────────────────────────────────── */
.equiv-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
@media (max-width: 1024px) { .equiv-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px)  { .equiv-grid { grid-template-columns: 1fr 1fr; } }

.equiv-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  transition: all 0.2s;
}
.equiv-card:hover { border-color: var(--primary); background: var(--primary-bg); }
.equiv-icon { font-size: 28px; margin-bottom: 8px; }
.equiv-value { font-size: 20px; font-weight: 900; color: var(--text1); }
.equiv-label { font-size: 10px; color: var(--text3); margin-top: 4px; }

/* ── RSE LABELS ───────────────────────────────────────────────────────────── */
.rse-label-card {
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  text-align: center;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.rse-label-card.achieved {
  border-color: var(--green);
  background: var(--green-light);
}
.rse-label-card.in-progress {
  border-color: var(--yellow);
  background: var(--yellow-light);
}
.rse-label-card.not-achieved {
  border-color: var(--red-light);
}

/* ── RESPONSIVE ADJUSTMENTS ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { flex-direction: column; overflow: auto; }
  .sidebar { position: fixed; width: 60px; min-width: 60px; }
  .main-content { margin-left: 60px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 16px; }
  .topbar { padding: 0 12px; }
  .topbar-period { display: none; }
  #export-dropdown { display: none; }
}

/* ── SCROLL UTILITIES ─────────────────────────────────────────────────────── */
.overflow-hidden { overflow: hidden; }
.overflow-auto   { overflow: auto; }
.overflow-x-auto { overflow-x: auto; }

/* ── PRINT STYLES ─────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .toast-container, .notifications-panel { display: none !important; }
  .main-content { margin: 0; }
  .page-content { overflow: visible; }
}

/* ══ TABS — Bandeau de navigation amélioré ══════════════════════════════════ */
.tabs {
  display: flex;
  gap: 4px;
  padding: 5px;
  background: var(--bg3);
  border-radius: 14px;
  border: 1px solid var(--border);
  flex-wrap: wrap;
  position: relative;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  position: relative;
}

.tab-btn i { font-size: 12px; }

.tab-btn:hover {
  background: var(--bg2);
  color: var(--text1);
}

.tab-btn.active {
  background: var(--bg1);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  font-weight: 700;
}

[data-theme="dark"] .tab-btn.active {
  background: rgba(var(--primary-rgb, 16,185,129), 0.15);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  background: var(--primary);
  border-radius: 2px;
}

/* Badge sur tab */
.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--primary);
  color: white;
  font-size: 9px;
  font-weight: 800;
  border-radius: 10px;
  margin-left: 2px;
}

/* ══ RESPONSIVE MOBILE COMPLET ══════════════════════════════════════════════ */
@media (max-width: 900px) {
  /* Grilles 2-colonnes → 1-colonne */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns:1.5fr 1fr"],
  [style*="grid-template-columns:1.6fr 1fr"],
  [style*="grid-template-columns:1fr 1.5fr"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
  }
  /* KPI cards en 2 colonnes */
  #kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  /* Navigation labels cachés */
  .nav-label { display: none; }
}

@media (max-width: 640px) {
  /* Sidebar icon-only ultra-compacte */
  .sidebar { width: 52px !important; min-width: 52px !important; }
  .sidebar .nav-label,
  .sidebar .org-info,
  .sidebar .sidebar-footer,
  .sidebar .logo-text { display: none !important; }
  .main-content { margin-left: 52px !important; }
  .page-content { padding: 12px !important; }

  /* KPI 1 colonne */
  #kpi-grid { grid-template-columns: 1fr !important; }

  /* Grilles toutes en 1 col */
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

  /* Tables défilables */
  .overflow-x-auto, table { overflow-x: auto; display: block; max-width: 100%; }

  /* Topbar compacte */
  .topbar-period, .topbar-export, #export-dropdown { display: none !important; }
  .topbar-title { font-size: 14px !important; }

  /* Boutons flex-wrap */
  [style*="display:flex;gap:8px"],
  [style*="display: flex; gap: 8px"] { flex-wrap: wrap !important; }

  /* Modals plein écran sur mobile */
  .modal-overlay { padding: 8px !important; align-items: flex-end !important; }
  .modal {
    max-width: 100% !important;
    max-height: 92vh !important;
    border-radius: 16px 16px 0 0 !important;
    width: 100% !important;
  }

  /* Charts réduites */
  [style*="height:240px"] { height: 180px !important; }
  [style*="height:220px"] { height: 160px !important; }
  [style*="height:300px"] { height: 200px !important; }

  /* Tabs scrollables */
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tab-btn { white-space: nowrap; flex-shrink: 0; }
}

/* ══ MODALS REDIMENSIONNABLES ══════════════════════════════════════════════ */
.modal[style*="resize:both"],
.modal[style*="resize: both"] {
  resize: both;
  overflow: auto;
  min-width: 300px;
  min-height: 200px;
}

/* Handle de redimensionnement visuel */
.modal[style*="resize"] {
  position: relative;
}
.modal[style*="resize"]::after {
  content: '⤡';
  position: absolute;
  bottom: 6px;
  right: 8px;
  font-size: 14px;
  color: var(--text3);
  opacity: 0.5;
  cursor: se-resize;
  pointer-events: none;
}

/* ══ MODALS - FOND & TEXTE ADAPTATIF ══════════════════════════════════════ */
.modal {
  font-size: 13px;
  line-height: 1.5;
}
.modal h2 { font-size: clamp(14px, 2.5vw, 18px); }
.modal .form-label { font-size: clamp(11px, 1.5vw, 13px); }
.modal .form-input { font-size: clamp(12px, 1.5vw, 14px); }
.modal p, .modal div { max-width: 100%; word-break: break-word; }

/* Assure que la scrollbar de modal est toujours visible */
.modal::-webkit-scrollbar { width: 6px; }
.modal::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.modal-overlay .modal { scrollbar-gutter: stable; }

/* ══ AMÉLIORATION TYPOGRAPHIE FENÊTRES ══════════════════════════════════= */
.card-title {
  font-size: clamp(12px, 1.8vw, 14px);
  font-weight: 700;
  display: flex;
  align-items: center;
}
.kpi-card-v3 .value,
.kpi-card-v3 > div:nth-child(2) {
  font-size: clamp(18px, 3vw, 24px) !important;
}

/* ══ TOOLTIP UNIVERSEL ══════════════════════════════════════════════════= */
[title]:hover::after {
  content: attr(title);
  position: absolute;
  background: var(--bg1);
  color: var(--text1);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  white-space: nowrap;
  z-index: 999;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-width: 250px;
  white-space: normal;
}

/* Span-2 pour grilles dans modals */
.span-2 { grid-column: span 2; }
@media (max-width: 640px) { .span-2 { grid-column: span 1; } }

/* ══ MODALS REDIMENSIONNABLES AMÉLIORÉES ════════════════════════════════ */
.modal {
  resize: both;
  overflow: auto;
  min-width: 320px;
  min-height: 200px;
  max-height: 92vh;
  position: relative;
}
.modal::after {
  content: '';
  position: absolute;
  bottom: 4px; right: 4px;
  width: 12px; height: 12px;
  border-right: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
  border-radius: 0 0 4px 0;
  pointer-events: none;
  opacity: 0.4;
}

/* ══ RESPONSIVE MOBILE ÉTENDU ═══════════════════════════════════════════ */
@media (max-width: 640px) {
  .modal-overlay .modal {
    resize: none !important;
    max-width: 100vw !important;
    max-height: 95vh !important;
    border-radius: 16px 16px 0 0;
    margin: auto 0 0 0;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100% !important;
  }

  /* Tables scrollables horizontalement */
  table { min-width: 500px; }
  .overflow-x-auto, [style*="overflow-x:auto"] { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }

  /* Grilles → colonnes uniques */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:auto 1fr"],
  [style*="grid-template-columns:1fr 280px"],
  [style*="grid-template-columns:repeat(auto-fill,minmax(340px"] {
    grid-template-columns: 1fr !important;
  }

  /* Charts plus petits sur mobile */
  canvas { max-height: 240px !important; }

  /* Header compact */
  .topbar { padding: 0 10px !important; }
  .topbar-actions { gap: 4px !important; }
  .topbar-actions .btn span { display: none; }

  /* Sidebar cachée, toggle visible */
  .sidebar { transform: translateX(-100%); transition: transform 0.3s; }
  .sidebar.open { transform: translateX(0); }

  /* KPIs 2 colonnes */
  .kpi-row, [style*="grid-template-columns:repeat(auto-fill,minmax(17"],
  [style*="grid-template-columns:repeat(auto-fill,minmax(16"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Tabs scrollables */
  .tabs { overflow-x: auto; flex-wrap: nowrap; }
  .tab-btn { flex-shrink: 0; white-space: nowrap; font-size: 11px; padding: 7px 10px; }
}

@media (max-width: 480px) {
  .kpi-row, [style*="grid-template-columns:repeat(auto-fill,minmax(17"],
  [style*="grid-template-columns:repeat(auto-fill,minmax(16"] {
    grid-template-columns: 1fr !important;
  }
}

/* ══ TOOLTIPS CORRECTEMENT DIMENSIONNÉS ═════════════════════════════════ */
[data-tooltip] { position: relative; cursor: help; }
[data-tooltip]:hover::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 6px;
  background: var(--bg1);
  color: var(--text1);
  font-size: 11px;
  line-height: 1.4;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  white-space: normal;
  max-width: 220px;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  pointer-events: none;
}

/* ══ CANVAS NETWORK MAP INTERACTIF ══════════════════════════════════════ */
#network-map-canvas { cursor: grab; user-select: none; touch-action: none; }
#network-map-canvas:active { cursor: grabbing; }

/* ══ CATALOGUE ÉQUIPEMENTS ══════════════════════════════════════════════ */
.eq-catalog-row td { vertical-align: middle; }
.eq-catalog-row:hover td { background: var(--bg3); }

/* ══ SCORING LABELS ═════════════════════════════════════════════════════ */
.label-card-achieved { border-color: rgba(16,185,129,0.4) !important; }
.label-card-partial  { border-color: rgba(245,158,11,0.4) !important; }
.label-card-not      { border-color: var(--border) !important; }

/* ══ FIX FORM INPUTS POUR MOBILE ════════════════════════════════════════ */
@media (max-width: 640px) {
  .form-input, .form-select { font-size: 16px !important; } /* Empêche le zoom iOS */
}

/* ══ SIDEBAR MOBILE ══════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0,0,0,0.3);
  }
  .sidebar.collapsed { transform: translateX(-100%); }
  .main-content { margin-left: 0 !important; }
  .main-content.sidebar-collapsed { margin-left: 0 !important; }
}

/* ══ MODAL CONTENT FIX — Évite le text crop ════════════════════════════════ */
.modal-overlay .modal {
  padding: 20px 24px;
  box-sizing: border-box;
}
.modal-overlay .modal > * {
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: break-word;
}
/* Empêche les labels de se couper */
.modal .form-label {
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: unset !important;
}
/* Empêche les boutons d'action de se couper */
.modal [style*="display:flex"][style*="gap"] {
  flex-wrap: wrap;
}
/* Fixe les overlays d'édition pour qu'ils n'overflow pas */
.modal [style*="overflow:hidden"],
.modal [style*="overflow: hidden"] {
  overflow: visible !important;
}
/* Exceptions légitimes pour les barres de progression etc. */
.modal .impact-bar,
.modal [class*="progress"],
.modal canvas {
  overflow: hidden !important;
}
/* Titres dans les modals — pas de coupure */
.modal h2, .modal h3, .modal h4 {
  overflow: visible !important;
  white-space: normal !important;
  text-overflow: unset !important;
}
/* Texte de description — wrap correctement */
.modal p, .modal .form-label, .modal [style*="font-size:11px"], .modal [style*="font-size:12px"] {
  overflow: visible !important;
  white-space: normal !important;
  text-overflow: unset !important;
  line-height: 1.5;
}
/* Grilles dans les modals — adaptatif */
.modal [style*="grid-template-columns"] {
  overflow: visible !important;
}
/* Conteneur de formulaire dans modal */
.modal form {
  overflow-y: visible;
  overflow-x: hidden;
}
/* Fix textarea resize dans les modals */
.modal textarea.form-input {
  resize: vertical;
  min-height: 60px;
}

/* ══ FIX TOPBAR PERIODE ═════════════════════════════════════════════════ */
.topbar-period select {
  max-width: 130px;
}

/* ══ SERVICE CHAIN LAYOUT ═══════════════════════════════════════════════ */
@media (max-width: 768px) {
  #servicechain-page [style*="grid-template-columns:240px 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   AI PANEL — CarbonLab AI Assistant
   ═══════════════════════════════════════════════════════════════════════════ */

/* FAB Button */
.ai-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: white;
  border: none;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4);
  z-index: 9998;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: ai-fab-pulse 3s ease-in-out infinite;
}
.ai-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(124, 58, 237, 0.6);
}
.ai-fab.hidden { display: none; }

@keyframes ai-fab-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4); }
  50% { box-shadow: 0 4px 30px rgba(124, 58, 237, 0.7); }
}

/* Panel Container */
#ai-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 420px;
  height: 100vh;
  z-index: 9999;
  transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}
#ai-panel.open {
  right: 0;
  pointer-events: all;
}

.ai-panel-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 40px rgba(0,0,0,0.15);
}

/* Header */
.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: white;
  flex-shrink: 0;
}
.ai-panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.ai-title-text {
  font-weight: 700;
  font-size: 14px;
}
.ai-subtitle {
  font-size: 11px;
  opacity: 0.8;
}
.ai-panel-actions {
  display: flex;
  gap: 4px;
}
.ai-action-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: background 0.2s;
}
.ai-action-btn:hover { background: rgba(255,255,255,0.3); }

/* Settings */
.ai-settings {
  padding: 10px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text2);
}
.ai-settings-row:last-child { margin-bottom: 0; }
.ai-settings-row label { min-width: 70px; font-weight: 500; }
.ai-settings-row select {
  flex: 1;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text1);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.ai-settings-row select:hover {
  border-color: var(--primary);
}
.ai-settings-row select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* Messages */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
}

/* Welcome */
.ai-welcome {
  text-align: center;
  padding: 30px 10px;
}
.ai-welcome-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: linear-gradient(135deg, #7c3aed22, #2563eb22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--primary);
}
.ai-welcome-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text1);
  margin-bottom: 8px;
}
.ai-welcome-text {
  font-size: 13px;
  color: var(--text2);
  line-height: 1.5;
  margin-bottom: 20px;
}
.ai-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.ai-quick-btn {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-quick-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* Messages */
.ai-message {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  animation: ai-msg-appear 0.3s ease;
}
@keyframes ai-msg-appear {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.ai-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.ai-msg-avatar.user {
  background: var(--primary-light);
  color: var(--primary);
}
.ai-msg-avatar.assistant {
  background: linear-gradient(135deg, #7c3aed33, #2563eb33);
  color: var(--primary);
}
.ai-msg-avatar.error {
  background: var(--red-light);
  color: var(--red);
}
.ai-msg-avatar.analysis {
  background: var(--green-light);
  color: var(--green);
}
.ai-msg-content {
  flex: 1;
  min-width: 0;
}
.ai-msg-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.ai-msg-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text1);
  word-break: break-word;
}
.ai-msg-text h2, .ai-msg-text h3, .ai-msg-text h4 {
  font-size: 14px;
  font-weight: 700;
  margin: 12px 0 6px;
  color: var(--text1);
}
.ai-msg-text code {
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'SF Mono', monospace;
  color: var(--primary);
}
.ai-msg-text pre {
  background: var(--surface2);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
  color: var(--text1);
}
.ai-msg-text ul {
  padding-left: 16px;
  margin: 6px 0;
}
.ai-msg-text li {
  margin-bottom: 4px;
}
.ai-msg-text strong {
  color: var(--primary);
  font-weight: 700;
}
.ai-error-text {
  color: var(--red) !important;
}
.ai-msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.ai-msg-action {
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text3);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}
.ai-msg-action:hover {
  background: var(--primary-light);
  color: var(--primary);
}

/* Typing indicator */
.ai-typing-dots {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}
.ai-typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.4;
  animation: ai-typing 1.2s ease-in-out infinite;
}
.ai-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-typing {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* Input area */
.ai-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.ai-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.ai-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text1);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  transition: border-color 0.2s;
}
.ai-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.ai-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.ai-send-btn:hover { transform: scale(1.05); }
.ai-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-input-hint {
  font-size: 10px;
  color: var(--text3);
  margin-top: 6px;
  display: flex;
  gap: 4px;
}

/* Inline AI components (panel scope) */
.ai-panel-inline-btn {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.ai-panel-inline-btn:hover {
  background: var(--primary);
  color: white;
}

/* AI Insight Cards (in-panel) */
.ai-messages .ai-insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
  animation: ai-msg-appear 0.3s ease;
}
.ai-messages .ai-insight-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.ai-messages .ai-insight-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text1);
  flex: 1;
}
.ai-messages .ai-insight-content {
  font-size: 13px;
  color: var(--text2);
  line-height: 1.6;
}
.ai-messages .ai-insight-content strong { color: var(--text1); }

.ai-loading-inline.ai-panel-loading {
  padding: 16px;
  text-align: center;
  color: var(--text3);
  font-size: 13px;
}
.ai-error-inline.ai-panel-error {
  padding: 12px;
  text-align: center;
  color: var(--red);
  font-size: 12px;
}

/* Referential Selector in topbar */
.referential-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--primary-light);
  border-radius: 8px;
  border: 1px solid var(--primary);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  transition: all 0.2s;
}
.referential-selector:hover {
  background: var(--primary);
  color: white;
}
.referential-selector i {
  font-size: 12px;
}

/* ── AI Topbar Selector ────────────────────────────────────────────────── */
.ai-topbar-selector {
  display: flex;
  align-items: center;
}
.ai-topbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: linear-gradient(135deg, rgba(124,58,237,0.10), rgba(37,99,235,0.10));
  border: 1px solid rgba(124,58,237,0.3);
  border-radius: 8px;
  font-size: 12px;
  transition: all 0.2s;
}
.ai-topbar-group:hover {
  border-color: rgba(124,58,237,0.6);
  background: linear-gradient(135deg, rgba(124,58,237,0.18), rgba(37,99,235,0.18));
}
.ai-topbar-select {
  background: transparent;
  border: none;
  color: var(--text1);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  padding: 2px 4px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: auto;
}
.ai-topbar-model-select {
  max-width: 140px;
  font-weight: 500;
  color: var(--text2);
}
@media (max-width: 900px) {
  .ai-topbar-selector { display: none; }
}

/* Referential Comparison Modal */
.referential-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: ai-msg-appear 0.2s ease;
}
.referential-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
  max-width: 800px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  color: var(--text1);
}
.referential-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.referential-modal-body {
  padding: 24px;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #ai-panel {
    width: 100%;
    right: -100%;
  }
  .ai-fab {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
    font-size: 18px;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   AI PAGE INTEGRATIONS — Inline insights, action bars, badges
   FULLY THEME-AWARE: uses only CSS variables from :root / [data-theme="dark"]
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── AI Insights Container ────────────────────────────────────────────────── */
.ai-insights-container {
  margin: 16px 0;
  min-height: 0;
  transition: all 0.3s ease;
}

.ai-insights-container:empty {
  display: none;
}

/* ── AI Insight Card ──────────────────────────────────────────────────────── */
.ai-insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
  animation: ai-card-in 0.4s ease-out;
}

.ai-insight-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, transparent 50%, var(--primary-light));
  border-radius: 0 12px 0 0;
}

@keyframes ai-card-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-insight-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.ai-insight-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text1);
  flex: 1;
}

.ai-badge {
  font-size: 9px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ai-insight-content {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text2);
}

.ai-insight-content strong { color: var(--text1); font-weight: 700; }
.ai-insight-content ul { padding-left: 18px; margin: 8px 0; }
.ai-insight-content li { margin-bottom: 5px; color: var(--text2); }
.ai-insight-content code {
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--primary);
}

/* ── AI Action Bar ────────────────────────────────────────────────────────── */
.ai-action-bar {
  margin: 12px 0 16px;
  animation: ai-card-in 0.3s ease-out;
}

.ai-action-bar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--primary-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-wrap: wrap;
}

.ai-action-bar-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-action-bar-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.ai-action-bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.ai-action-bar-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(124,58,237,0.25);
}

.ai-action-bar-btn:active {
  transform: translateY(0);
}

/* ── AI Loading Card ──────────────────────────────────────────────────────── */
.ai-loading-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  background: var(--primary-bg);
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  animation: ai-pulse 1.5s ease-in-out infinite;
}

@keyframes ai-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.ai-loading-card i {
  font-size: 16px;
}

/* ── AI Error Card ────────────────────────────────────────────────────────── */
.ai-error-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--red-light);
  border: 1px solid var(--red);
  border-radius: 12px;
  color: var(--red);
  font-size: 12px;
}

/* ── Referential Active Badge ──────────────────────────────────────────────── */
.ref-active-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--primary-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12px;
  color: var(--text2);
  margin: 8px 0 4px;
}

.ref-active-badge strong {
  color: var(--primary);
  font-weight: 700;
}

.ref-active-badge i {
  color: var(--primary);
  font-size: 13px;
}

.ref-change-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  margin-left: 6px;
  transition: all 0.2s;
}

.ref-change-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ── AI Inline Button (used in tables/cards) ──────────────────────────────── */
.ai-inline-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.ai-inline-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(124,58,237,0.3);
}

/* ── AI Loading Inline ────────────────────────────────────────────────────── */
.ai-loading-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
}

.ai-error-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px;
  color: var(--red);
  font-size: 13px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   AI OPTIMIZATION MODAL
   ═══════════════════════════════════════════════════════════════════════════ */
.ai-opt-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.3s;
  padding: 20px;
}
.ai-opt-overlay.open { opacity: 1; }

.ai-opt-modal {
  background: var(--surface, #fff); border-radius: 16px;
  width: 95%; max-width: 900px; max-height: 90vh;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform: translateY(20px); transition: transform 0.3s;
}
.ai-opt-overlay.open .ai-opt-modal { transform: translateY(0); }

.ai-opt-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px; border-bottom: 3px solid #6366f1;
  background: var(--surface, #fff);
  flex-shrink: 0;
}
.ai-opt-header-left { display: flex; align-items: center; gap: 14px; }
.ai-opt-icon {
  width: 42px; height: 42px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 18px;
}
.ai-opt-title { font-weight: 800; font-size: 17px; color: var(--text1, #1a1735); }
.ai-opt-subtitle { font-size: 12px; color: var(--text3, #94a3b8); margin-top: 2px; }
.ai-opt-header-right { display: flex; gap: 8px; }
.ai-opt-refresh, .ai-opt-close {
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--border, #e2e8f0); background: transparent;
  color: var(--text2, #64748b); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.ai-opt-refresh:hover, .ai-opt-close:hover {
  background: var(--surface2, #f1f5f9); color: var(--text1, #1a1735);
}

.ai-opt-body {
  flex: 1; overflow-y: auto; padding: 24px;
  scrollbar-width: thin;
}

/* Loading */
.ai-opt-loading {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; gap: 16px;
}
.ai-opt-loading-spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid var(--border, #e2e8f0);
  border-top-color: var(--primary, #6366f1);
  animation: ai-opt-spin 0.8s linear infinite;
}
@keyframes ai-opt-spin { to { transform: rotate(360deg); } }
.ai-opt-loading-text { font-weight: 700; font-size: 15px; color: var(--text1, #1a1735); text-align: center; }
.ai-opt-loading-sub { font-size: 12px; color: var(--text3, #94a3b8); }

/* Summary */
.ai-opt-summary {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 16px; border-radius: 12px;
  background: var(--surface2, #f1f5f9);
  margin-bottom: 20px; font-size: 14px; line-height: 1.6;
  color: var(--text1, #1a1735);
}

/* Section titles */
.ai-opt-section-title {
  font-weight: 800; font-size: 14px; color: var(--text1, #1a1735);
  margin-bottom: 12px; margin-top: 6px;
  display: flex; align-items: center; gap: 8px;
}
.ai-opt-section-title i { color: var(--primary, #6366f1); }

/* KPI Grid */
.ai-opt-kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px; margin-bottom: 24px;
}
.ai-opt-kpi-card {
  padding: 16px; border-radius: 12px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e2e8f0);
  display: flex; flex-direction: column; gap: 8px;
}
.ai-opt-kpi-icon { font-size: 20px; }
.ai-opt-kpi-label { font-size: 12px; font-weight: 700; color: var(--text2, #64748b); text-transform: uppercase; letter-spacing: 0.5px; }
.ai-opt-kpi-values { display: flex; align-items: center; gap: 8px; }
.ai-opt-kpi-current, .ai-opt-kpi-optimized { display: flex; flex-direction: column; gap: 2px; }
.ai-opt-kpi-tag {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  color: var(--text3, #94a3b8); letter-spacing: 0.5px;
}
.ai-opt-kpi-tag.opt { color: var(--green, #10b981); }
.ai-opt-kpi-val { font-size: 15px; font-weight: 800; color: var(--text1, #1a1735); }
.ai-opt-kpi-val.opt { color: var(--green, #10b981); }
.ai-opt-kpi-arrow { color: var(--text3, #94a3b8); font-size: 12px; }
.ai-opt-kpi-gain {
  font-size: 14px; font-weight: 800; padding: 4px 10px;
  border-radius: 8px; text-align: center; margin-top: 4px;
}
.ai-opt-kpi-gain.negative { background: rgba(16,185,129,0.12); color: #059669; }
.ai-opt-kpi-gain.positive { background: rgba(16,185,129,0.12); color: #059669; }

/* Actions */
.ai-opt-actions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.ai-opt-action-row {
  display: flex; gap: 14px; padding: 14px;
  border-radius: 10px; background: var(--surface, #fff);
  border: 1px solid var(--border, #e2e8f0);
  align-items: flex-start;
}
.ai-opt-action-num {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  background: var(--primary, #6366f1); color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px;
}
.ai-opt-action-content { flex: 1; }
.ai-opt-action-text { font-size: 13px; font-weight: 600; color: var(--text1, #1a1735); line-height: 1.4; }
.ai-opt-action-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.ai-opt-action-badge {
  font-size: 10px; font-weight: 700; padding: 2px 8px;
  border-radius: 5px; color: white; text-transform: uppercase;
}
.ai-opt-action-detail { font-size: 11px; color: var(--text3, #94a3b8); display: flex; align-items: center; gap: 4px; }

/* Table */
.ai-opt-table-wrap { overflow-x: auto; margin-bottom: 24px; border-radius: 10px; border: 1px solid var(--border, #e2e8f0); }
.ai-opt-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ai-opt-table th {
  background: var(--primary, #6366f1); color: white;
  padding: 10px 12px; text-align: left; font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.ai-opt-table td { padding: 10px 12px; border-bottom: 1px solid var(--border, #e2e8f0); color: var(--text1, #1a1735); }
.ai-opt-table tr.even td { background: var(--surface2, #f8fafc); }
.ai-opt-td-name { font-weight: 700; }
.ai-opt-td-change { font-size: 11px; color: var(--green, #10b981); font-style: italic; }

/* Methodology */
.ai-opt-methodology {
  padding: 14px; border-radius: 10px;
  background: var(--surface2, #f1f5f9);
  font-size: 13px; color: var(--text2, #64748b); line-height: 1.6;
  margin-bottom: 20px;
}

/* Footer */
.ai-opt-footer { margin-top: 8px; }
.ai-opt-footer-note {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 12px; border-radius: 8px;
  background: rgba(99,102,241,0.06);
  font-size: 11px; color: var(--text3, #94a3b8);
}
.ai-opt-footer-note i { color: var(--primary, #6366f1); margin-top: 1px; }

/* Error */
.ai-opt-error {
  display: flex; flex-direction: column; align-items: center;
  padding: 40px; text-align: center; color: var(--red, #ef4444);
}
.ai-opt-error i { font-size: 32px; margin-bottom: 12px; }


