/* ═══════════════════════════════════════════════════════════════
   OPM77 — Portail Facturation | portal.css
   Professional dark-sidebar / light-content theme
   ═══════════════════════════════════════════════════════════════ */

/* ── CUSTOM PROPERTIES ──────────────────────────────────────── */
:root {
  /* Brand */
  --color-primary:        #1a3a5c;
  --color-primary-light:  #234b76;
  --color-primary-dark:   #0d2540;
  --color-accent:         #3b82f6;
  --color-accent-hover:   #2563eb;

  /* Semantic */
  --color-success:        #27ae60;
  --color-success-bg:     #eafaf1;
  --color-warning:        #f39c12;
  --color-warning-bg:     #fef9e7;
  --color-danger:         #e74c3c;
  --color-danger-bg:      #fdedec;
  --color-purple:         #8b5cf6;
  --color-purple-bg:      #f5f3ff;

  /* Sidebar */
  --sidebar-bg:           #0f1923;
  --sidebar-border:       #1e2d3d;
  --sidebar-text:         #8899a6;
  --sidebar-text-active:  #ffffff;
  --sidebar-item-active:  rgba(59,130,246,0.15);
  --sidebar-width:        240px;

  /* Content */
  --bg-page:              #f0f4f8;
  --bg-card:              #ffffff;
  --bg-card-hover:        #f8fafc;
  --border-color:         #e2e8f0;
  --border-radius:        12px;
  --border-radius-sm:     8px;
  --border-radius-lg:     16px;

  /* Text */
  --text-primary:         #0f1923;
  --text-secondary:       #4a5568;
  --text-muted:           #94a3b8;
  --text-inverse:         #ffffff;

  /* Topbar */
  --topbar-height:        64px;
  --topbar-bg:            #ffffff;
  --topbar-border:        #e2e8f0;

  /* Shadows */
  --shadow-sm:   0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);
  --shadow-xl:   0 20px 60px rgba(0,0,0,.16);

  /* Transitions */
  --transition-fast:  150ms ease;
  --transition-base:  250ms ease;
  --transition-slow:  400ms ease;

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

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

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

body {
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
img, svg { display: block; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }
ul { list-style: none; }

/* ── SCROLLBAR ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1cdd9; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

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

.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-base);
}

/* Collapsed sidebar */
body.sidebar-collapsed .sidebar { width: 64px; }
body.sidebar-collapsed .sidebar .brand-text,
body.sidebar-collapsed .sidebar .nav-item > span:not(.nav-icon),
body.sidebar-collapsed .sidebar .nav-badge,
body.sidebar-collapsed .sidebar .nav-section-label,
body.sidebar-collapsed .sidebar .status-info { display: none; }
body.sidebar-collapsed .main-wrapper { margin-left: 64px; }
body.sidebar-collapsed .sidebar-nav .nav-item { justify-content: center; padding: 0.75rem; }

/* ── SIDEBAR BRAND ───────────────────────────────────────────── */
.sidebar-brand {
  padding: 1.25rem 1.125rem;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #3b82f6, #1a3a5c);
  border-radius: 8px;
  font-size: 11px;
  font-weight: 800;
  color: white;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.brand-name {
  display: block;
  color: var(--text-inverse);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.3px;
}

.brand-sub {
  display: block;
  color: var(--sidebar-text);
  font-size: 11px;
  font-weight: 400;
}

/* ── SIDEBAR NAV ─────────────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--sidebar-text);
  padding: 0 0.5rem;
  margin-bottom: 0.375rem;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--border-radius-sm);
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: all var(--transition-fast);
  position: relative;
  white-space: nowrap;
}

.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-inverse);
}

.nav-item.active {
  background: var(--sidebar-item-active);
  color: var(--color-accent);
}

.nav-item.active .nav-icon { color: var(--color-accent); }

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

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

/* ── SIDEBAR FOOTER ──────────────────────────────────────────── */
.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sally-status {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.5rem;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.sally-status:hover { background: rgba(255,255,255,0.05); }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot--active {
  background: var(--color-success);
  box-shadow: 0 0 0 3px rgba(39,174,96,0.25);
  animation: pulse-green 2s infinite;
}
.status-dot--offline { background: var(--text-muted); }

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 3px rgba(39,174,96,0.25); }
  50%       { box-shadow: 0 0 0 6px rgba(39,174,96,0.1); }
}

.status-name {
  display: block;
  color: var(--text-inverse);
  font-size: 12.5px;
  font-weight: 600;
}
.status-label {
  display: block;
  color: var(--sidebar-text);
  font-size: 11px;
}

/* ── TOPBAR ──────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.topbar-left { display: flex; align-items: center; gap: 0.875rem; }
.topbar-center { flex: 1; display: flex; justify-content: center; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }

.sidebar-toggle {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.sidebar-toggle:hover { background: var(--bg-page); color: var(--text-primary); }
.sidebar-toggle svg { width: 20px; height: 20px; }

.breadcrumb-page {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  padding: 0.375rem 0.75rem;
  width: 340px;
  transition: all var(--transition-fast);
}
.topbar-search:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
  background: white;
}
.search-icon { width: 15px; height: 15px; color: var(--text-muted); flex-shrink: 0; }
.topbar-search input {
  border: none;
  background: transparent;
  font-size: 13.5px;
  color: var(--text-primary);
  flex: 1;
  outline: none;
}
.topbar-search input::placeholder { color: var(--text-muted); }
.search-kbd {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.topbar-date {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.topbar-sally-pill {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  background: rgba(39,174,96,0.1);
  border: 1px solid rgba(39,174,96,0.3);
  border-radius: 99px;
  padding: 0.25rem 0.75rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.topbar-sally-pill:hover { background: rgba(39,174,96,0.18); }
.topbar-sally-pill .pill-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--color-success);
  animation: pulse-green 2s infinite;
}
.topbar-sally-pill span { font-size: 12px; font-weight: 600; color: var(--color-success); }

.topbar-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--border-radius-sm);
  color: var(--text-muted);
  transition: all var(--transition-fast);
}
.topbar-btn:hover { background: var(--bg-page); color: var(--text-primary); }
.topbar-btn svg { width: 16px; height: 16px; }
.topbar-btn.spinning svg { animation: spin 1s linear infinite; }

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

.topbar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: white;
  font-size: 12px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

/* ── PAGE CONTENT ────────────────────────────────────────────── */
.page-content {
  padding: 1.75rem;
  flex: 1;
  max-width: 1600px;
  width: 100%;
}

/* ── FILTER BAR ──────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.filter-bar-left { flex: 1; }
.filter-bar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  display: block;
}

.filter-select {
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  padding: 0.4rem 0.75rem;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-card);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 2rem;
}
.filter-select:focus { border-color: var(--color-accent); }

/* ── KPI GRID ────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px;
  height: 100%;
  background: transparent;
  transition: background var(--transition-fast);
}
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-card:hover::before { background: var(--color-accent); }

.kpi-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.875rem;
}
.kpi-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-icon {
  width: 36px; height: 36px;
  border-radius: var(--border-radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.kpi-icon svg { width: 16px; height: 16px; }
.kpi-icon--blue   { background: rgba(59,130,246,0.12);  color: var(--color-accent); }
.kpi-icon--green  { background: var(--color-success-bg); color: var(--color-success); }
.kpi-icon--red    { background: var(--color-danger-bg);  color: var(--color-danger); }
.kpi-icon--orange { background: var(--color-warning-bg); color: var(--color-warning); }
.kpi-icon--purple { background: var(--color-purple-bg);  color: var(--color-purple); }

.kpi-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  line-height: 1.1;
  margin-bottom: 0.625rem;
  transition: all var(--transition-base);
}

.kpi-value.updated {
  animation: kpi-pop 0.4s ease;
}
@keyframes kpi-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.kpi-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.kpi-trend {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
  padding: 2px 6px;
}
.kpi-trend svg { width: 12px; height: 12px; }
.kpi-trend--up   { color: var(--color-success); background: var(--color-success-bg); }
.kpi-trend--down { color: var(--color-danger); background: var(--color-danger-bg); }
.kpi-trend--down svg { transform: rotate(180deg); }

.kpi-compare {
  font-size: 11.5px;
  color: var(--text-muted);
}

.kpi-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border-color);
  border-radius: 99px;
  overflow: hidden;
}
.kpi-progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--color-success);
  transition: width 0.8s ease, background-color var(--transition-base);
}

.kpi-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.kpi-badge--red    { background: var(--color-danger-bg);  color: var(--color-danger); }
.kpi-badge--orange { background: var(--color-warning-bg); color: var(--color-warning); }
.kpi-badge--green  { background: var(--color-success-bg); color: var(--color-success); }

/* Recouvrement color states */
.kpi-value--green { color: var(--color-success); }
.kpi-value--orange { color: var(--color-warning); }
.kpi-value--red    { color: var(--color-danger); }

/* ── CHARTS GRID ─────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 320px 280px;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ── CARDS ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.125rem 1.375rem;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.card-title-group { display: flex; flex-direction: column; gap: 2px; }
.card-title { font-size: 14.5px; font-weight: 700; color: var(--text-primary); }
.card-subtitle { font-size: 12px; color: var(--text-muted); }
.card-actions { display: flex; align-items: center; gap: 0.5rem; }

.card-body {
  padding: 1.375rem;
  flex: 1;
  overflow: auto;
}
.card-body.p-0 { padding: 0; }

.chart-card { min-height: 300px; }
.chart-card--large { grid-column: span 2; }
.chart-container { position: relative; height: 220px; }
.chart-container--donut { height: 180px; display: flex; justify-content: center; }

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}
.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
}
.legend-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 0.5rem;
  flex-shrink: 0;
}
.legend-label { display: flex; align-items: center; color: var(--text-secondary); flex: 1; }
.legend-value { font-weight: 600; color: var(--text-primary); }

/* ── ALERTS PANEL ────────────────────────────────────────────── */
.alert-count-badge {
  background: var(--color-danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}

.alerts-list { display: flex; flex-direction: column; gap: 0.625rem; }

.alert-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-page);
  border-radius: var(--border-radius-sm);
  border-left: 3px solid var(--color-danger);
  font-size: 12.5px;
  transition: background var(--transition-fast);
}
.alert-item:hover { background: #edf2f7; }
.alert-item--orange { border-left-color: var(--color-warning); }
.alert-item--yellow { border-left-color: #ecc94b; }

.alert-icon { flex-shrink: 0; margin-top: 1px; }
.alert-icon svg { width: 14px; height: 14px; color: var(--color-danger); }
.alert-item--orange .alert-icon svg { color: var(--color-warning); }

.alert-content { flex: 1; min-width: 0; }
.alert-title { font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alert-meta { color: var(--text-muted); font-size: 11px; margin-top: 1px; }

.alert-skeleton {
  height: 56px;
  background: linear-gradient(90deg, #f0f4f8 25%, #e2e8f0 50%, #f0f4f8 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--border-radius-sm);
  margin-bottom: 0.5rem;
}

/* ── TABLE ───────────────────────────────────────────────────── */
.table-card { }
.table-wrapper { overflow-x: auto; }

.table-search-wrap {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  padding: 0.375rem 0.625rem;
  background: var(--bg-page);
  transition: all var(--transition-fast);
}
.table-search-wrap:focus-within {
  border-color: var(--color-accent);
  background: white;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.table-search {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  color: var(--text-primary);
  width: 160px;
}
.table-search::placeholder { color: var(--text-muted); }

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

.data-table thead { position: sticky; top: 0; z-index: 2; }
.data-table th {
  background: var(--bg-page);
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
  user-select: none;
}
.data-table th.sortable { cursor: pointer; }
.data-table th.sortable:hover { color: var(--text-primary); }
.sort-icon { width: 12px; height: 12px; display: inline; vertical-align: middle; margin-left: 4px; }

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background var(--transition-fast);
}
.data-table tbody tr:hover { background: rgba(59,130,246,0.04); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Row urgency colors */
.data-table tbody tr.row-critique { background: rgba(231,76,60,0.05); }
.data-table tbody tr.row-critique:hover { background: rgba(231,76,60,0.09); }
.data-table tbody tr.row-urgent   { background: rgba(243,156,18,0.05); }
.data-table tbody tr.row-urgent:hover   { background: rgba(243,156,18,0.09); }
.data-table tbody tr.row-recent   { background: rgba(39,174,96,0.04); }
.data-table tbody tr.row-recent:hover   { background: rgba(39,174,96,0.07); }

/* Zebra stripe on neutral rows */
.data-table tbody tr:nth-child(even):not(.row-critique):not(.row-urgent):not(.row-recent) {
  background: #fafbfc;
}

.col-check { width: 40px; }
.checkbox {
  width: 15px; height: 15px;
  accent-color: var(--color-accent);
  cursor: pointer;
}

.facture-id {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-page);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
}

.client-name { font-weight: 600; color: var(--text-primary); max-width: 180px; }
.client-code { font-size: 11px; color: var(--text-muted); }

.service-tag {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.service-tag--REL  { background: rgba(59,130,246,0.12);  color: #1d4ed8; }
.service-tag--EC   { background: rgba(139,92,246,0.12);  color: #6d28d9; }
.service-tag--REHA { background: rgba(16,185,129,0.12);  color: #047857; }

.pilote-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.pilote-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: white;
  font-size: 9.5px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.pilote-name { font-size: 12.5px; font-weight: 500; }

.amount-cell {
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
}

.jours-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 99px;
}
.jours-badge--critique { background: var(--color-danger-bg); color: var(--color-danger); }
.jours-badge--urgent   { background: var(--color-warning-bg); color: var(--color-warning); }
.jours-badge--recent   { background: rgba(234,179,8,0.12); color: #a16207; }

/* Status badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}
.status-badge::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}
.status-badge--critique { background: var(--color-danger-bg); color: var(--color-danger); }
.status-badge--urgent   { background: var(--color-warning-bg); color: var(--color-warning); }
.status-badge--recent   { background: rgba(234,179,8,0.12); color: #a16207; }
.status-badge--paye     { background: var(--color-success-bg); color: var(--color-success); }
.status-badge--attente  { background: rgba(59,130,246,0.1); color: var(--color-accent); }

.action-btns { display: flex; gap: 0.375rem; }

/* ── BUTTONS ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: var(--border-radius-sm);
  font-size: 13px;
  font-weight: 600;
  padding: 0.5rem 1rem;
  transition: all var(--transition-fast);
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.3;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-sm { padding: 0.35rem 0.75rem; font-size: 12px; }
.btn-xs { padding: 0.25rem 0.5rem; font-size: 11.5px; }

.btn-primary {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}
.btn-primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); box-shadow: 0 4px 12px rgba(59,130,246,0.35); }

.btn-danger {
  background: var(--color-danger);
  color: white;
  border-color: var(--color-danger);
}
.btn-danger:hover { background: #c0392b; box-shadow: 0 4px 12px rgba(231,76,60,0.35); }

.btn-warning {
  background: var(--color-warning);
  color: white;
  border-color: var(--color-warning);
}
.btn-warning:hover { background: #d68910; box-shadow: 0 4px 12px rgba(243,156,18,0.35); }

.btn-success {
  background: var(--color-success);
  color: white;
  border-color: var(--color-success);
}
.btn-success:hover { background: #1e8449; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-color);
}
.btn-ghost:hover { background: var(--bg-page); color: var(--text-primary); }

.btn-ghost-red {
  background: transparent;
  color: var(--color-danger);
  border-color: rgba(231,76,60,0.3);
}
.btn-ghost-red:hover { background: var(--color-danger-bg); }

.btn-outline-primary {
  background: transparent;
  color: var(--color-accent);
  border-color: var(--color-accent);
}
.btn-outline-primary:hover { background: rgba(59,130,246,0.08); }

.btn-ghost-danger {
  background: transparent;
  color: var(--color-danger);
  border: none;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}
.btn-ghost-danger:hover { background: var(--color-danger-bg); }

/* ── TABLE FOOTER ────────────────────────────────────────────── */
.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.375rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-page);
}
.table-info { font-size: 12.5px; color: var(--text-muted); }

.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
}
.page-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--border-radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  background: white;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.page-btn:hover { border-color: var(--color-accent); color: var(--color-accent); }
.page-btn.active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: white;
}

/* ── SKELETON / LOADING ──────────────────────────────────────── */
.skeleton {
  color: transparent !important;
  background: linear-gradient(90deg, #e2e8f0 25%, #edf2f7 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: 6px;
  pointer-events: none;
  user-select: none;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.table-skeleton {
  height: 16px;
  border-radius: 4px;
  background: linear-gradient(90deg, #f0f4f8 25%, #e2e8f0 50%, #f0f4f8 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  width: 80%;
}
.skeleton-row td { padding: 1rem; }

/* ── SALLY CHAT PANEL ────────────────────────────────────────── */
.sally-panel {
  position: fixed;
  top: 0; right: 0;
  width: 380px;
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 200;
  box-shadow: var(--shadow-xl);
  transform: translateX(100%);
  transition: transform var(--transition-base);
}
.sally-panel.open { transform: translateX(0); }

.sally-panel-header {
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--sidebar-bg);
}

.sally-panel-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sally-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-accent), var(--color-primary));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sally-avatar svg { width: 18px; height: 18px; color: white; }

.sally-panel-name {
  display: block;
  color: white;
  font-weight: 700;
  font-size: 14px;
}
.sally-panel-status {
  display: block;
  font-size: 11.5px;
  color: var(--sidebar-text);
}

.sally-close {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--border-radius-sm);
  color: var(--sidebar-text);
  transition: all var(--transition-fast);
}
.sally-close:hover { background: rgba(255,255,255,0.1); color: white; }
.sally-close svg { width: 16px; height: 16px; }

.sally-quick-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.quick-action-btn {
  font-size: 11.5px;
  font-weight: 600;
  padding: 0.375rem 0.75rem;
  border-radius: 99px;
  background: rgba(59,130,246,0.1);
  color: var(--color-accent);
  border: 1px solid rgba(59,130,246,0.25);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.quick-action-btn:hover {
  background: rgba(59,130,246,0.18);
  border-color: var(--color-accent);
}

.sally-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.125rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sally-message {
  display: flex;
  gap: 0.625rem;
  align-items: flex-start;
}
.sally-message--user {
  flex-direction: row-reverse;
}

.sally-message-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-accent), var(--color-primary));
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.sally-message--user .sally-message-avatar {
  background: linear-gradient(135deg, var(--color-primary), #2d6a9f);
}

.sally-message-content {
  max-width: 80%;
}

.sally-message-content p {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
  background: var(--bg-page);
  padding: 0.625rem 0.875rem;
  border-radius: 12px;
  border-top-left-radius: 2px;
}
.sally-message--user .sally-message-content p {
  background: var(--color-accent);
  color: white;
  border-radius: 12px;
  border-top-right-radius: 2px;
  text-align: right;
}
.sally-message-content p strong {
  color: var(--text-primary);
  font-weight: 600;
}
.sally-message--user .sally-message-content p strong {
  color: white;
}

.sally-message-time {
  display: block;
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}
.sally-message--user .sally-message-time { text-align: right; }

.sally-typing {
  display: flex;
  gap: 4px;
  padding: 0.625rem 0.875rem;
  background: var(--bg-page);
  border-radius: 12px;
  border-top-left-radius: 2px;
  width: fit-content;
}
.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-6px); }
}

.sally-input-area {
  padding: 1rem 1.125rem;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}
.sally-input-wrap {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  padding: 0.375rem 0.375rem 0.375rem 0.875rem;
  transition: all var(--transition-fast);
}
.sally-input-wrap:focus-within {
  border-color: var(--color-accent);
  background: white;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.sally-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13.5px;
  color: var(--text-primary);
}
.sally-input::placeholder { color: var(--text-muted); }

.sally-send {
  width: 34px; height: 34px;
  background: var(--color-accent);
  color: white;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}
.sally-send:hover { background: var(--color-accent-hover); box-shadow: 0 4px 12px rgba(59,130,246,0.4); }
.sally-send svg { width: 14px; height: 14px; }

/* Sally FAB */
.sally-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, var(--color-accent), var(--color-primary));
  color: white;
  border-radius: 99px;
  padding: 0.75rem 1.25rem;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(59,130,246,0.45);
  z-index: 150;
  transition: all var(--transition-base);
}
.sally-fab:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(59,130,246,0.55); }
.sally-fab svg { width: 18px; height: 18px; }
.sally-fab .fab-label { font-weight: 700; }

/* ── MODAL ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,25,35,0.55);
  backdrop-filter: blur(4px);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow: auto;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--border-radius-sm);
  color: var(--text-muted);
  transition: all var(--transition-fast);
}
.modal-close:hover { background: var(--bg-page); color: var(--text-primary); }
.modal-close svg { width: 16px; height: 16px; }

.modal-body { padding: 1.5rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-page);
  border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.detail-item { display: flex; flex-direction: column; gap: 4px; }
.detail-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; }
.detail-value { font-size: 14px; font-weight: 600; color: var(--text-primary); }

/* ── TOAST NOTIFICATIONS ─────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: white;
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  padding: 0.875rem 1rem;
  min-width: 280px;
  max-width: 360px;
  pointer-events: all;
  animation: toast-in 0.3s ease forwards;
  border-left: 4px solid var(--color-accent);
}
.toast--success { border-left-color: var(--color-success); }
.toast--error   { border-left-color: var(--color-danger); }
.toast--warning { border-left-color: var(--color-warning); }

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}
.toast-out { animation: toast-out 0.25s ease forwards; }
@keyframes toast-out {
  from { transform: translateX(0);   opacity: 1; }
  to   { transform: translateX(100%); opacity: 0; }
}

.toast-icon svg { width: 18px; height: 18px; }
.toast--success .toast-icon svg { color: var(--color-success); }
.toast--error   .toast-icon svg { color: var(--color-danger); }
.toast--warning .toast-icon svg { color: var(--color-warning); }
.toast--info    .toast-icon svg { color: var(--color-accent); }

.toast-body { flex: 1; }
.toast-title  { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.toast-message { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ── UTILITY CLASSES ─────────────────────────────────────────── */
.btn-ghost-sm { padding: 0.2rem 0.5rem; font-size: 11.5px; }
.text-right { text-align: right; }
.font-mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.d-flex { display: flex; }
.gap-2 { gap: 0.5rem; }

/* ── CA SERVICE CARDS ────────────────────────────────────────── */
.ca-service-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.ca-service-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.25rem 1.5rem 1rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s cubic-bezier(0.4,0,0.2,1), transform 0.15s cubic-bezier(0.4,0,0.2,1);
  cursor: default;
  position: relative;
  overflow: hidden;
}
.ca-service-card:hover {
  box-shadow: 0 0 0 1px rgba(59,130,246,0.25), 0 8px 24px rgba(59,130,246,0.08);
  transform: translateY(-1px);
}
.ca-service-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}
.ca-service-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  margin-bottom: 0.5rem;
}
.ca-delta-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
}
.ca-delta-badge--up   { background: rgba(39,174,96,0.12); color: #27ae60; }
.ca-delta-badge--down { background: rgba(231,76,60,0.12); color: #e74c3c; }
.ca-delta-badge--neutral { background: rgba(148,163,184,0.12); color: var(--text-muted); }
.ca-service-sparkline {
  position: absolute;
  bottom: 0; right: 0;
  width: 80px; height: 40px;
  opacity: 0.25;
}

/* ── AGING BUCKETS ───────────────────────────────────────────── */
.aging-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}
.aging-bar-track {
  height: 10px;
  border-radius: 99px;
  overflow: hidden;
  display: flex;
  margin: 0.75rem 0;
  background: var(--bg-page);
}
.aging-seg { height: 100%; transition: width 0.6s cubic-bezier(0.4,0,0.2,1); }
.aging-counts { display: flex; gap: 0; }
.aging-count { flex: 1; text-align: center; }
.aging-count-val {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  display: block;
}
.aging-count-lbl {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

/* ── TABULAR NUMS & PREMIUM TRANSITIONS ──────────────────────── */
.kpi-value, .amount-cell, .ca-service-value { font-variant-numeric: tabular-nums; }
.kpi-card {
  transition: box-shadow 0.15s cubic-bezier(0.4,0,0.2,1), transform 0.15s cubic-bezier(0.4,0,0.2,1);
}
.kpi-card:hover {
  box-shadow: 0 0 0 1px rgba(59,130,246,0.2), 0 8px 24px rgba(59,130,246,0.06);
  transform: translateY(-1px);
}
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mb-1 { margin-bottom: 0.25rem; }

/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 1400px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .charts-grid { grid-template-columns: 1fr 300px; }
  .alerts-card { grid-column: 1 / -1; }
}
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .topbar-search { width: 240px; }
}
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  .sidebar { transform: translateX(-100%); width: 240px; }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .topbar-center { display: none; }
  .page-content { padding: 1rem; }
  .filter-bar { flex-direction: column; }
  .filter-bar-right { width: 100%; justify-content: flex-start; }
  .sally-panel { width: 100%; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ── PRINT STYLES ────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .sally-fab, .sally-panel, .filter-bar-right,
  .action-btns, .card-actions, .toast-container { display: none !important; }
  body { background: white; }
  .main-wrapper { margin-left: 0; }
  .page-content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}
