/* ================================================================
   GMS — Design System Principal
   Style : SaaS Pro — Minimaliste & Raffiné — Dark-first
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

/* ─── VARIABLES ──────────────────────────────────────────────── */
:root {
  /* Couleurs primaires */
  --primary: #5b6af5;
  --primary-hover: #4a58e8;
  --primary-light: rgba(91, 106, 245, 0.12);
  --primary-glow: rgba(91, 106, 245, 0.35);

  /* Sémantiques */
  --success: #22c55e;
  --success-light: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.12);
  --info: #06b6d4;
  --info-light: rgba(6, 182, 212, 0.12);

  /* Layout sombre (défaut) */
  --bg: #0f1117;
  --bg-secondary: #161b27;
  --bg-card: #1a2035;
  --bg-elevated: #1f2640;
  --border: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(91, 106, 245, 0.5);

  /* Texte */
  --text: #e8eaf0;
  --text-secondary: #8b92a9;
  --text-muted: #555e7a;
  --text-inverse: #0f1117;

  /* Sidebar */
  --sidebar-w: 240px;
  --sidebar-bg: #111420;
  --sidebar-border: rgba(255,255,255,0.04);

  /* Typographie */
  --font: 'DM Sans', -apple-system, sans-serif;
  --font-mono: 'DM Mono', monospace;

  /* Espacements */
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
  --transition: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mode clair */
[data-theme="light"] {
  --bg: #f4f5f9;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-elevated: #f8f9fc;
  --border: rgba(0, 0, 0, 0.07);
  --text: #1a2035;
  --text-secondary: #5a6478;
  --text-muted: #9aa0b4;
  --sidebar-bg: #ffffff;
  --sidebar-border: rgba(0,0,0,0.06);
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.05);
}

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ─── LAYOUT APP ─────────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

/* ─── SIDEBAR ────────────────────────────────────────────────── */
.sidebar {
  grid-row: 1 / -1;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

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

.sidebar-logo .logo-icon {
  width: 34px;
  height: 34px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  box-shadow: 0 0 20px var(--primary-glow);
  flex-shrink: 0;
}

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

.sidebar-nav { flex: 1; padding: 12px 10px; }

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 12px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  text-decoration: none;
  position: relative;
}

.nav-item:hover { background: var(--bg-elevated); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.nav-item .nav-icon { width: 18px; text-align: center; font-size: 14px; flex-shrink: 0; }
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
  line-height: 1.6;
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--sidebar-border);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}
.user-pill:hover { background: var(--bg-elevated); }

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-pill-info { flex: 1; min-width: 0; }
.user-pill-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-pill-role { font-size: 11px; color: var(--text-muted); }

/* ─── HEADER ─────────────────────────────────────────────────── */
.app-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 90;
}

.header-title h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.header-title p { font-size: 12px; color: var(--text-secondary); }

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

.btn-icon-header {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.btn-icon-header:hover { background: var(--bg-elevated); color: var(--text); }
.btn-icon-header .notif-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 7px; height: 7px;
  background: var(--danger);
  border-radius: 50%;
  border: 1.5px solid var(--bg-secondary);
}

/* ─── MAIN CONTENT ───────────────────────────────────────────── */
.main-content {
  padding: 24px 28px;
  overflow-y: auto;
  min-height: calc(100vh - 58px);
}

/* ─── CARDS & KPIs ───────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: border-color var(--transition), transform var(--transition);
  position: relative;
  overflow: hidden;
}
.kpi-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent-color, var(--primary));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.kpi-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
.kpi-label { font-size: 12px; font-weight: 500; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  background: var(--accent-light, var(--primary-light));
  color: var(--accent-color, var(--primary));
}

.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 6px; line-height: 1.1; }
.kpi-change {
  font-size: 12px;
  display: flex; align-items: center; gap: 4px;
}
.kpi-change.positive { color: var(--success); }
.kpi-change.negative { color: var(--danger); }
.kpi-change.neutral { color: var(--text-muted); }

/* ─── CONTENT CARDS ──────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title { font-size: 15px; font-weight: 600; }
.card-subtitle { font-size: 12px; color: var(--text-secondary); }
.card-body { padding: 20px 22px; }

/* ─── TABLES ─────────────────────────────────────────────────── */
.table-toolbar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.table-wrapper { overflow-x: auto; }

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

.data-table th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th.sortable { cursor: pointer; }
.data-table th.sortable:hover { color: var(--text); }

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

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--bg-elevated); }

.sort-icon { margin-left: 4px; opacity: 0.4; font-size: 10px; }

.pagination-bar {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pagination-info { font-size: 12px; color: var(--text-secondary); }
.pagination-controls { display: flex; gap: 4px; }

.btn-page {
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.btn-page:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text); }
.btn-page.active { background: var(--primary); border-color: var(--primary); color: white; }
.btn-page:disabled { opacity: 0.35; cursor: not-allowed; }

/* ─── FORMS ──────────────────────────────────────────────────── */
.form-grid { display: grid; gap: 16px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.form-label span.required { color: var(--danger); margin-left: 2px; }

.form-control {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13.5px;
  padding: 8px 12px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-control::placeholder { color: var(--text-muted); }

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

.input-group { position: relative; }
.input-group .form-control { padding-right: 36px; }
.input-group-icon {
  position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 13px;
  pointer-events: none;
}

/* ─── BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); box-shadow: 0 4px 14px var(--primary-glow); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text); }

.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #dc2626; box-shadow: 0 4px 14px rgba(239,68,68,0.3); }

.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover:not(:disabled) { background: #16a34a; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }

.btn-icon {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 13px;
}
.btn-icon:hover { background: var(--bg-elevated); color: var(--text); }
.btn-icon.btn-icon-danger:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }
.btn-icon.btn-icon-primary:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

/* ─── BADGES ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-secondary { background: var(--bg-elevated); color: var(--text-secondary); }

/* ─── MODAL ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.25s ease;
  padding: 20px;
}
.modal-overlay.show { opacity: 1; }
.modal-overlay.show .modal-dialog { transform: translateY(0); opacity: 1; }

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 25px 60px rgba(0,0,0,0.4);
}
.modal-sm { max-width: 380px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }

.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  border: none; background: transparent;
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg-elevated); color: var(--text); }

.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  flex-shrink: 0;
}

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

.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  min-width: 280px;
  max-width: 380px;
  box-shadow: var(--shadow);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  pointer-events: all;
  transform: translateX(120%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
  opacity: 0;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast button { margin-left: auto; background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0; font-size: 12px; }
.toast-success { border-color: var(--success); }
.toast-success i { color: var(--success); }
.toast-error { border-color: var(--danger); }
.toast-error i { color: var(--danger); }
.toast-warning { border-color: var(--warning); }
.toast-warning i { color: var(--warning); }
.toast-info i { color: var(--info); }

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

/* ─── MISC UTILITIES ─────────────────────────────────────────── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.d-block { display: block; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mt-4 { margin-top: 1rem; }
.gap-2 { gap: 0.5rem; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.grid { display: grid; }
.page-grid { display: grid; gap: 20px; }
.col-2 { grid-template-columns: 1fr 1fr; }
.col-3 { grid-template-columns: 1fr 1fr 1fr; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.section-title { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.section-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.actions-cell { display: flex; gap: 4px; align-items: center; }
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state i { font-size: 2.5rem; margin-bottom: 12px; display: block; opacity: 0.5; }
.empty-state p { font-size: 14px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.stock-critical { color: var(--danger); font-weight: 600; }
.stock-low { color: var(--warning); font-weight: 600; }
.mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── SCROLLBAR ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .col-2, .col-3 { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }
}

/* ─── ANIMATIONS ─────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.5;} }
@keyframes spin { to { transform: rotate(360deg); } }

.animate-in { animation: fadeIn 0.3s ease forwards; }
.loading { animation: pulse 1.5s ease infinite; }
.spin { animation: spin 1s linear infinite; }
