/* ============================================================
   SESAME HSE — Thème clair & professionnel
   Palette : navy #1a2b6b · cyan #1e9de0 · green #3dab29
             orange #f47c20 · teal #00b8a0 · purple #7b3fb0
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --navy:       #1a2b6b;
  --navy-light: #2a3f8f;
  --cyan:       #1e9de0;
  --green:      #3dab29;
  --orange:     #f47c20;
  --teal:       #00b8a0;
  --purple:     #7b3fb0;
  --red:        #e53e3e;
  --amber:      #d97706;

  /* Layout */
  --bg:         #f0f4f8;
  --bg-card:    #ffffff;
  --border:     #e2e8f0;
  --border-2:   #cbd5e1;
  --shadow:     0 1px 4px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --shadow-md:  0 4px 24px rgba(0,0,0,.08);
  --radius:     12px;
  --radius-lg:  16px;
  --radius-sm:  8px;

  /* Text */
  --text:       #1e293b;
  --text-2:     #475569;
  --text-muted: #94a3b8;

  /* Sidebar */
  --sidebar-bg:    #ffffff;
  --sidebar-w:     240px;
  --sidebar-w-col: 64px;

  /* Topbar */
  --topbar-h:   60px;
  --topbar-bg:  var(--navy);
}

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

html, body { height: 100%; font-size: 14px; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden; /* desktop uniquement — mobile override ci-dessous */
  /* Safe area iOS (notch + home indicator) */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* Scroll inertiel iOS global */
  -webkit-overflow-scrolling: touch;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
select, input, textarea { font-family: inherit; }

/* ── Layout principal ─────────────────────────────────────── */
.layout-wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ──────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.25s ease;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  z-index: 100;
}

#sidebar.collapsed { width: var(--sidebar-w-col); }
#sidebar.collapsed .sidebar-app-name,
#sidebar.collapsed .sidebar-app-sub,
#sidebar.collapsed .nav-item span,
#sidebar.collapsed .nav-badge,
#sidebar.collapsed .sidebar-footer { display: none; }
#sidebar.collapsed .nav-item { justify-content: center; padding: 10px 0; }
#sidebar.collapsed .nav-icon { margin: 0; }

/* Logo zone */
.sidebar-logo {
  padding: 16px 14px 12px;
  border-bottom: 1.5px solid var(--border);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.sidebar-brand-logo {
  height: 40px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
}

.sidebar-app-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: 0.3px;
  margin-bottom: 2px;
}

.sidebar-app-icon {
  color: var(--green);
  font-size: 14px;
}

.sidebar-app-sub {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 8px 0;
}

.nav-section {
  padding: 10px 14px 4px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.nav-section-hse {
  color: var(--green);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
  cursor: pointer;
  position: relative;
}

.nav-item:hover {
  background: #f0f4f8;
  color: var(--navy);
}

.nav-item.active {
  background: #eef7ff;
  color: var(--cyan);
  border-left-color: var(--cyan);
  font-weight: 700;
}

.nav-item-hse.active {
  background: #f0fdf4;
  color: var(--green);
  border-left-color: var(--green);
}

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

.nav-item.active .nav-icon { color: var(--cyan); }
.nav-item-hse.active .nav-icon { color: var(--green); }

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--cyan);
  color: #fff;
  line-height: 1.4;
}

.nav-badge-live {
  background: var(--green);
  color: #fff;
  font-size: 9px;
  letter-spacing: 0.3px;
}

/* Sidebar footer */
.sidebar-footer {
  border-top: 1.5px solid var(--border);
  padding: 10px 14px;
  flex-shrink: 0;
}

.sidebar-portal-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--navy);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 10px;
  transition: background 0.15s;
}

.sidebar-portal-link:hover { background: var(--navy-light); }
.sidebar-portal-link i { font-size: 14px; }

.sidebar-brand-footer {
  display: flex;
  flex-direction: column;
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  gap: 2px;
}

.sidebar-brand-sub {
  font-size: 9px;
  opacity: 0.7;
}

/* ── MAIN ─────────────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── TOPBAR ───────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-h);
  background: var(--topbar-bg);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  z-index: 50;
}

.topbar-menu-btn {
  color: rgba(255,255,255,0.8);
  font-size: 18px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  flex-shrink: 0;
}
.topbar-menu-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-brand-logo {
  height: 32px;
  width: auto;
  filter: brightness(0) invert(1);
  opacity: 0.9;
}

.topbar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.topbar-brand-name {
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.3px;
}

.topbar-brand-sub {
  font-size: 10px;
  color: rgba(255,255,255,0.6);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  margin-left: 6px;
  border-left: 1px solid rgba(255,255,255,0.2);
  padding-left: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-spacer { flex: 1; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.site-selector {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
  outline: none;
}
.site-selector option { background: var(--navy); color: #fff; }

.lang-switch {
  display: flex;
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.lang-btn {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 5px;
  color: rgba(255,255,255,0.6);
  transition: all 0.15s;
}
.lang-btn:hover { color: #fff; }
.lang-active { background: rgba(255,255,255,0.2); color: #fff !important; }

.topbar-icon-btn {
  color: rgba(255,255,255,0.7);
  font-size: 15px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.topbar-icon-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

.topbar-portal-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  transition: all 0.15s;
}
.topbar-portal-btn:hover { background: rgba(255,255,255,0.2); }

/* ── CONTENT AREA ─────────────────────────────────────────── */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  -webkit-overflow-scrolling: touch; /* scroll inertiel iOS */
}

/* ── LOADING ─────────────────────────────────────────────── */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  font-size: 15px;
  color: var(--text-muted);
  gap: 10px;
}
.loader i { animation: spin 1s linear infinite; font-size: 20px; color: var(--cyan); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── CARDS ──────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

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

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

/* ── HSE DASHBOARD ─────────────────────────────────────── */
.hse-dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.hse-dash-title {
  display: flex;
  align-items: center;
  gap: 14px;
}

.hse-dash-title > i {
  font-size: 28px;
  color: var(--green);
  background: #f0fdf4;
  padding: 10px;
  border-radius: var(--radius);
}

.page-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--navy);
}

.page-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Alertes HSE */
.hse-alert-critical {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #fff5f5;
  border: 1.5px solid #fed7d7;
  border-left: 4px solid var(--red);
  border-radius: var(--radius);
  margin-bottom: 12px;
  color: #c53030;
  font-size: 13px;
  font-weight: 600;
}

.hse-alert-warn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-left: 4px solid var(--amber);
  border-radius: var(--radius);
  margin-bottom: 12px;
  color: #92400e;
  font-size: 13px;
  font-weight: 600;
}

/* KPI Row HSE */
.hse-kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.hse-kpi-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}
.hse-kpi-card:hover { box-shadow: var(--shadow-md); }

.hse-kpi-card.kpi-red    { border-left: 4px solid var(--red);    }
.hse-kpi-card.kpi-green  { border-left: 4px solid var(--green);  }
.hse-kpi-card.kpi-amber  { border-left: 4px solid var(--amber);  }
.hse-kpi-card.kpi-blue   { border-left: 4px solid var(--cyan);   }
.hse-kpi-card.kpi-navy   { border-left: 4px solid var(--navy);   }

.hse-kpi-icon {
  font-size: 22px;
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.kpi-red   .hse-kpi-icon { background: #fff5f5; color: var(--red);   }
.kpi-green .hse-kpi-icon { background: #f0fdf4; color: var(--green); }
.kpi-amber .hse-kpi-icon { background: #fffbeb; color: var(--amber); }
.kpi-blue  .hse-kpi-icon { background: #eff8ff; color: var(--cyan);  }
.kpi-navy  .hse-kpi-icon { background: #eef0f9; color: var(--navy);  }

.hse-kpi-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}
.hse-kpi-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  margin-top: 3px;
}
.hse-kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Quick nav */
.hse-quick-nav {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}

.hse-qnav-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hse-qnav-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 8px;
}

.hse-qnav-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 6px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  transition: all 0.15s;
  cursor: pointer;
}
.hse-qnav-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: currentColor;
}

.hse-qnav-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.hse-qnav-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-2);
  text-align: center;
  line-height: 1.3;
}

/* Incidents list */
.hse-incident-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.hse-incident-row:last-child { border-bottom: none; }

.hse-incident-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.hse-incident-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.hse-incident-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.hse-empty {
  text-align: center;
  padding: 24px;
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
}
.hse-empty i { margin-right: 6px; font-size: 16px; }

/* HSE Platform button */
.btn-hse-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--navy);
  color: #fff;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-hse-primary:hover { background: var(--navy-light); }

/* ── HSE PLATFORM (hse_modules.js host) ──────────────────── */
.hse-platform-wrapper {
  background: var(--bg);
  min-height: 100%;
}

/* ── PAGE HEADER ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

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

/* ── STAT CARDS ─────────────────────────────────────────── */
.stat-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  font-weight: 500;
}

/* ── BADGES ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  line-height: 1.6;
}

.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-teal   { background: #ccfbf1; color: #115e59; }

/* ── TABLES ─────────────────────────────────────────────── */
.table-container {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

td {
  padding: 10px 14px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
  color: var(--text);
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: #f8fafc; }

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.btn-primary:hover { background: var(--navy-light); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-2);
  border-color: var(--border-2);
}
.btn-secondary:hover { background: #f1f5f9; border-color: var(--navy); color: var(--navy); }

.btn-success {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.btn-success:hover { background: #2e8a20; }

.btn-danger {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.btn-danger:hover { background: #c53030; }

.btn-xs { padding: 4px 8px; font-size: 11px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-link {
  background: none;
  border: none;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-link:hover { color: var(--navy); text-decoration: underline; }

/* ── FORMS ───────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: var(--bg-card);
  outline: none;
  transition: border-color 0.15s;
}
.form-control:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(30,157,224,0.1); }

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

/* ── TABS ────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 14px;
}

.tab-btn {
  flex: 1;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.15s;
  background: transparent;
  border: none;
  cursor: pointer;
}
.tab-btn.active {
  background: var(--bg-card);
  color: var(--navy);
  box-shadow: var(--shadow);
}
.tab-btn:hover:not(.active) { color: var(--text); background: rgba(255,255,255,0.5); }

/* ── ALERTS ─────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 500;
}

.alert-danger {
  background: #fff5f5;
  border: 1.5px solid #fed7d7;
  border-left: 4px solid var(--red);
  color: #c53030;
}

.alert-warning {
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-left: 4px solid var(--amber);
  color: #92400e;
}

.alert-info {
  background: #eff8ff;
  border: 1.5px solid #bfdbfe;
  border-left: 4px solid var(--cyan);
  color: #1e40af;
}

.alert-success {
  background: #f0fdf4;
  border: 1.5px solid #bbf7d0;
  border-left: 4px solid var(--green);
  color: #166534;
}

/* ── PROGRESS BAR ───────────────────────────────────────── */
.progress-bar {
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ── EMPTY STATE ─────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state i { font-size: 40px; margin-bottom: 12px; opacity: 0.4; }
.empty-state h3 { font-size: 16px; font-weight: 700; color: var(--text-2); margin-bottom: 6px; }
.empty-state p { font-size: 13px; }

/* ── MODAL ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

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

.modal-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--navy);
}

.modal-close {
  color: var(--text-muted);
  font-size: 18px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}
.modal-close:hover { background: #f1f5f9; color: var(--text); }

.modal-body { padding: 20px; flex: 1; overflow-y: auto; }
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1.5px solid var(--border);
  background: #f8fafc;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ── TOAST ───────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 240px;
  max-width: 380px;
  pointer-events: auto;
  animation: slideIn 0.25s ease;
}

.toast.success { border-left: 4px solid var(--green); }
.toast.error   { border-left: 4px solid var(--red);   }
.toast.info    { border-left: 4px solid var(--cyan);   }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── CHART ───────────────────────────────────────────────── */
.chart-container {
  position: relative;
  height: 220px;
}

/* ── UTILITIES ───────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }

.text-primary { color: var(--cyan); }
.text-success { color: var(--green); }
.text-danger  { color: var(--red); }
.text-warning { color: var(--amber); }
.text-muted   { color: var(--text-muted); }
.text-navy    { color: var(--navy); }

/* ── RESPONSIVITÉ ────────────────────────────────────────── */
@media (max-width: 1200px) {
  .hse-qnav-grid { grid-template-columns: repeat(5, 1fr); }
  .hse-kpi-row   { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 220px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .hse-qnav-grid { grid-template-columns: repeat(4, 1fr); }
  .topbar-brand { display: none; }
}

@media (max-width: 640px) {
  :root { --sidebar-w: 200px; }
  #content { padding: 12px; }
  .hse-qnav-grid { grid-template-columns: repeat(3, 1fr); }
  .hse-kpi-row   { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE RESPONSIVE — Android & iPhone (≤ 768px)
   Sidebar en tiroir overlay, contenu pleine largeur
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Body mobile : scroll vertical autorisé ── */
  html, body {
    overflow: auto !important;
    height: auto !important;
    min-height: 100%;
  }

  /* ── Layout : vertical, hauteur auto ── */
  .layout-wrapper {
    flex-direction: column;
    height: auto !important;
    min-height: 100vh;
    overflow: visible !important;
  }

  /* ── Main content : pleine largeur, hauteur auto ── */
  #main-content {
    width: 100% !important;
    margin-left: 0 !important;
    min-width: 0;
    overflow: visible !important;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  /* ── Sidebar : hors écran par défaut, glisse en tiroir ── */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100% !important;
    height: 100dvh !important; /* dynamic viewport height — iOS Safari */
    width: 280px !important;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    z-index: 500;
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #sidebar.mobile-open {
    transform: translateX(0);
  }
  /* Arrêter le collapse desktop sur mobile */
  #sidebar.collapsed {
    width: 280px !important;
    transform: translateX(-100%);
  }
  #sidebar.collapsed.mobile-open {
    transform: translateX(0);
  }
  /* Réafficher les labels cachés par collapsed */
  #sidebar.collapsed .sidebar-app-name,
  #sidebar.collapsed .sidebar-app-sub,
  #sidebar.collapsed .nav-item span,
  #sidebar.collapsed .nav-badge,
  #sidebar.collapsed .sidebar-footer { display: flex !important; }
  #sidebar.collapsed .nav-item { justify-content: flex-start; padding: 10px 16px; }
  #sidebar.collapsed .nav-icon { margin-right: 10px; }

  /* ── Overlay backdrop semi-transparent ── */
  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 499;
    -webkit-tap-highlight-color: transparent;
    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);
  }
  #sidebar-overlay.active { display: block; }

  /* ── Topbar mobile : sticky en haut ── */
  #topbar {
    height: 52px;
    min-height: 52px;
    padding: 0 12px;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 200;
    flex-shrink: 0;
  }
  .topbar-menu-btn {
    font-size: 20px;
    padding: 8px 10px;
    min-width: 44px; /* zone tactile iOS minimum */
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .topbar-title {
    font-size: 13px;
    max-width: calc(100vw - 170px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar-brand { display: none; }
  .topbar-actions { gap: 4px; }
  .topbar-icon-btn { padding: 8px; min-width: 40px; min-height: 40px; }
  .topbar-portal-btn span { display: none; }
  .topbar-portal-btn { padding: 7px 10px; }

  /* ── Zone de contenu principale ── */
  #content {
    padding: 10px;
    overflow-y: visible;
    flex: 1;
  }

  /* ── Grilles → colonne unique ── */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .hse-qnav-grid { grid-template-columns: repeat(3, 1fr); }
  .hse-kpi-row   { grid-template-columns: 1fr; }
  .form-grid-2   { grid-template-columns: 1fr !important; }

  /* ── Tables : scroll horizontal natif ── */
  .table-wrapper, .table-container, div[class*="table-wrap"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Modals : bottom sheet sur mobile ── */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
    /* Fixer l'overlay sur toute la page */
    position: fixed;
    inset: 0;
    z-index: 600;
  }
  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    width: 100%;
    border-bottom: 0;
  }
  .modal-body {
    padding: 14px 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal-header { padding: 14px 16px; }
  .modal-footer { padding: 10px 16px; }

  /* ── Toasts ── */
  #toast-container { bottom: env(safe-area-inset-bottom, 16px); right: 10px; left: 10px; }
  .toast { max-width: 100%; min-width: 0; }

  /* ── Cards / KPI ── */
  .hse-kpi-card { padding: 12px 14px; gap: 10px; }
  .hse-kpi-val  { font-size: 22px; }
  .hse-kpi-icon { width: 38px; height: 38px; font-size: 16px; }

  /* ── Boutons : zones tactiles minimum ── */
  .btn { min-height: 40px; }
  .btn-sm { min-height: 36px; }

  /* ── Charts ── */
  canvas { max-width: 100% !important; touch-action: pan-y; }
}

/* ── Très petit écran (≤ 390px — iPhone SE, Galaxy A) ── */
@media (max-width: 390px) {
  .topbar-title { display: none; }
  #content, #hse-content { padding: 8px; }
  .hse-kpi-grid { grid-template-columns: 1fr; }
  .hse-qnav-grid { grid-template-columns: repeat(2, 1fr); }
  .modal-body { padding: 10px 12px; }
  .btn { padding: 8px 12px; font-size: 12px; }
  .topbar-menu-btn { min-width: 40px; min-height: 40px; }
}
