/* =====================================================
   VARIABLES
   ===================================================== */
:root {
  --sidebar-w: 248px;
  --navbar-h: 58px;
  --sidebar-bg: #0f172a;
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-active: #2563eb;
  --primary: #2563eb;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0891b2;
  --purple: #7c3aed;
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --body-bg: #f1f5f9;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(0,0,0,0.07);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.12);
}

/* =====================================================
   BASE
   ===================================================== */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--body-bg);
  color: var(--text-main);
  margin: 0;
  overflow-x: hidden;
  font-size: 14px;
}

/* =====================================================
   SPLASH SCREEN
   ===================================================== */
#splashScreen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s;
}

.splash-inner {
  text-align: center;
  padding: 2rem;
}

.splash-hint {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-top: 1rem;
  color: rgba(255,255,255,0.75);
  font-size: 0.82rem;
  max-width: 380px;
  line-height: 1.6;
}
.splash-hint code {
  background: rgba(255,255,255,0.15);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.splash-logo {
  width: 80px; height: 80px;
  background: rgba(37,99,235,0.3);
  border: 2px solid rgba(37,99,235,0.6);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto;
  font-size: 2.2rem;
  color: #60a5fa;
  box-shadow: 0 0 30px rgba(37,99,235,0.4);
}

/* =====================================================
   LAYOUT
   ===================================================== */
#mainWrapper {
  display: flex;
  min-height: 100vh;
}

/* =====================================================
   SIDEBAR
   ===================================================== */
#sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  color: #e2e8f0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 1050;
  transition: transform 0.28s ease;
  overflow-y: auto;
}

.sidebar-header {
  padding: 1.1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.sidebar-icon-wrap {
  width: 38px; height: 38px;
  background: rgba(255,255,255,0.1);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  padding: 1.1rem 1rem 0.3rem;
}

.sidebar-nav { padding: 0 0.5rem; }

.sidebar-nav .nav-link {
  color: rgba(255,255,255,0.62);
  padding: 0.62rem 0.85rem;
  border-radius: 8px;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-weight: 500;
  transition: background 0.18s, color 0.18s;
}

.sidebar-nav .nav-link i {
  width: 18px;
  text-align: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.sidebar-nav .nav-link:hover {
  color: #fff;
  background: var(--sidebar-hover);
}

.sidebar-nav .nav-link.active {
  color: #fff;
  background: var(--sidebar-active);
  box-shadow: 0 2px 8px rgba(37,99,235,0.4);
}

.sidebar-footer {
  margin-top: auto;
  padding: 0.85rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.online  { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.status-dot.loading { background: #f59e0b; }
.status-dot.error   { background: #ef4444; }

.opacity-60 { opacity: 0.6; }

/* =====================================================
   MAIN CONTENT
   ===================================================== */
#mainContent {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* =====================================================
   TOP NAVBAR
   ===================================================== */
.top-navbar {
  height: var(--navbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  gap: 1rem;
}

/* =====================================================
   LOADING BAR
   ===================================================== */
#loadingBar {
  position: sticky;
  top: var(--navbar-h);
  z-index: 99;
}

/* =====================================================
   KPI CARDS
   ===================================================== */
.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  border-left: 4px solid var(--kpi-color, var(--primary));
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: -18px; right: -18px;
  width: 70px; height: 70px;
  background: var(--kpi-color, var(--primary));
  opacity: 0.06;
  border-radius: 50%;
}

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

.kpi-icon {
  width: 40px; height: 40px;
  border-radius: 9px;
  background: var(--kpi-color, var(--primary));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}

.kpi-value {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* =====================================================
   DASH CARDS
   ===================================================== */
.dash-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.dash-card-header {
  padding: 0.85rem 1.2rem;
  border-bottom: 1px solid var(--card-border);
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-main);
  background: #fafbfc;
  display: flex;
  align-items: center;
}

.dash-card-body {
  padding: 1.2rem;
}

/* =====================================================
   PAGE TRANSITIONS
   ===================================================== */
.page-view {
  animation: fadeUp 0.25s ease both;
}

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

/* =====================================================
   DATATABLES OVERRIDES
   ===================================================== */
.dt-buttons .btn {
  border-radius: 6px !important;
  font-size: 0.8rem !important;
  padding: 0.3rem 0.65rem !important;
}

#dataTable_wrapper .dataTables_filter input {
  border-radius: 6px;
  border: 1px solid var(--card-border);
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
}

table.dataTable tbody td {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
}

table.dataTable thead th {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* =====================================================
   MAP
   ===================================================== */
#map { z-index: 1; }

.leaflet-popup-content {
  font-size: 13px;
  min-width: 190px;
  line-height: 1.5;
}

/* =====================================================
   CHARTS
   ===================================================== */
canvas { max-width: 100%; }

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 767px) {
  #sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  #sidebar.show {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.25);
  }
  #mainContent {
    margin-left: 0;
  }
  .kpi-value { font-size: 1.5rem; }
  .top-navbar { padding: 0 0.85rem; }
}

/* =====================================================
   SCROLLBAR
   ===================================================== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* =====================================================
   UTILITIES
   ===================================================== */
.font-monospace { font-family: 'Consolas', 'Courier New', monospace !important; font-size: 0.82rem; }

.badge.rounded-pill { font-size: 0.78rem; font-weight: 600; }

.form-select-sm { font-size: 0.82rem; }

.text-truncate-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: middle;
}

/* Cluster map legend */
.map-legend {
  background: white;
  padding: 8px 12px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 12px;
  line-height: 1.8;
}

/* =====================================================
   OPERATIONAL DASHBOARD
   ===================================================== */

/* Banner */
.ops-banner {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  border-radius: var(--radius);
  padding: 1.1rem 1.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;
  gap: 1rem;
  flex-wrap: wrap;
}

.ops-banner-title {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: white;
  margin: 0;
  text-transform: uppercase;
}

.ops-banner-subtitle {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.65);
  margin: 0.2rem 0 0;
}

.ops-banner-right {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.ops-stat-box {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  text-align: center;
  min-width: 76px;
}
.ops-stat-box.highlight {
  background: #2563eb;
  border-color: #3b82f6;
}
.ops-stat-box.date-box { min-width: 90px; }

.ops-stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: white;
  line-height: 1;
}
.ops-stat-label {
  font-size: 0.63rem;
  color: rgba(255,255,255,0.65);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 0.18rem;
}

/* 8-column KPI cards */
@media (min-width: 1200px) {
  .row-cols-xl-8 > * { flex: 0 0 auto; width: 12.5%; }
}

.kpi8-card {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 0.8rem 0.9rem;
  border-top: 3px solid var(--kpi-color, var(--primary));
  box-shadow: var(--shadow);
  height: 100%;
  transition: transform 0.18s, box-shadow 0.18s;
}
.kpi8-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.kpi8-value {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--kpi-color, var(--primary));
  line-height: 1.1;
  margin: 0.15rem 0;
}
.kpi8-label {
  font-size: 0.63rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.kpi8-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Alertes header */
.dash-card-header.alertes-header {
  background: #dc2626;
  color: white;
  border-bottom-color: #b91c1c;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.78rem;
}

/* Appréciation bars */
.apprec-bar-item { margin-bottom: 0.8rem; }

.apprec-bar-label {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.22rem;
  display: flex;
  justify-content: space-between;
}
.apprec-bar-track {
  height: 20px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}
.apprec-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.7s ease;
}

/* Alert items */
.alert-badge {
  display: inline-block;
  padding: 0.18rem 0.42rem;
  border-radius: 4px;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  flex-shrink: 0;
  white-space: nowrap;
}
.alert-badge.critique { background: #dc2626; color: white; }
.alert-badge.urgent   { background: #d97706; color: white; }
.alert-badge.excep    { background: #7c3aed; color: white; }

.alert-item {
  border-left: 3px solid;
  padding: 0.55rem 0.75rem;
  border-radius: 0 6px 6px 0;
  margin-bottom: 0.45rem;
}
.alert-item.critique { border-color: #dc2626; background: #fff5f5; }
.alert-item.urgent   { border-color: #d97706; background: #fffbf0; }
.alert-item.excep    { border-color: #7c3aed; background: #faf5ff; }

.alert-item-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.18rem;
  flex-wrap: wrap;
}
.alert-item-title  { font-size: 0.8rem; font-weight: 700; color: var(--text-main); }
.alert-item-detail { font-size: 0.7rem; color: var(--text-muted); }

.total-np-note {
  background: #fff3cd;
  border: 1px dashed #d97706;
  border-radius: 4px;
  padding: 0.38rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: #92400e;
}

/* ZC Progress table */
.zc-table { width: 100%; border-collapse: collapse; font-size: 0.77rem; }

.zc-table th {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  padding: 0.38rem 0.7rem;
  border-bottom: 1px solid var(--card-border);
  background: #fafbfc;
}
.zc-table td {
  padding: 0.32rem 0.7rem;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  vertical-align: middle;
}

.zc-region-lbl {
  font-size: 0.62rem;
  color: var(--text-muted);
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.zc-progress {
  height: 13px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
  min-width: 70px;
}
.zc-progress-fill { height: 100%; border-radius: 3px; transition: width 0.6s ease; }

.zc-np-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.12rem 0.38rem;
  border-radius: 4px;
  border: 1px solid;
  white-space: nowrap;
}
.zc-np-badge.has-np { color: #dc2626; border-color: #fca5a5; background: #fff5f5; }
.zc-np-badge.ok     { color: #16a34a; border-color: #86efac; background: #f0fdf4; }

/* Actions requises */
.ops-section-title {
  background: #1e293b;
  color: white;
  padding: 0.45rem 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: 6px;
}

.action-card {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 0.9rem;
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--action-color, var(--primary));
  box-shadow: var(--shadow);
  height: 100%;
}
.action-card-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}
.action-number {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--action-color, var(--primary));
  color: white;
  font-size: 0.72rem;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.action-priority { font-size: 0.62rem; font-weight: 700; text-transform: uppercase; color: var(--action-color, var(--primary)); }
.action-title    { font-size: 0.85rem; font-weight: 700; color: var(--text-main); margin-bottom: 0.2rem; }
.action-desc     { font-size: 0.73rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.action-footer   { font-size: 0.68rem; color: var(--action-color, var(--primary)); font-weight: 600; }

/* Footer note */
.ops-footer-note {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 0.4rem;
}
