@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Manrope:wght@600;700;800&display=swap');

/* ===================== Design tokens ===================== */
:root {
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Manrope', 'Inter', system-ui, sans-serif;

  --brand: #6E5AF0;
  --brand-dark: #5A46DE;
  --brand-light: #EFECFF;
  --brand-rgb: 110, 90, 240;

  --teal: #1FB6A6;
  --amber: #F0A63A;
  --rose: #E8577A;
  --blue: #3C8CE0;

  --bg: #F5F5FA;
  --surface: #FFFFFF;
  --surface-alt: #FAFAFD;
  --border: #E7E7F0;
  --border-soft: #EFEFF6;
  --text: #1B1B29;
  --text-muted: #6B6B80;
  --text-faint: #9797AC;
  --shadow-sm: 0 1px 2px rgba(20, 20, 43, 0.05);
  --shadow-md: 0 6px 20px rgba(20, 20, 43, 0.07);
  --shadow-lg: 0 16px 40px rgba(20, 20, 43, 0.14);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --success: #1DA97C;
  --success-bg: #E4F7EF;
  --warning: #C77C10;
  --warning-bg: #FDF1DD;
  --danger: #DE4C5E;
  --danger-bg: #FCE9EC;
  --info: #3C8CE0;
  --info-bg: #E9F2FC;
  --neutral-bg: #EFEFF6;
}

:root[data-theme="dark"] {
  --bg: #14141C;
  --surface: #1B1B26;
  --surface-alt: #20202C;
  --border: #2C2C3B;
  --border-soft: #26262F;
  --text: #EDEDF5;
  --text-muted: #9C9CB0;
  --text-faint: #75758A;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, 0.5);
  --brand-light: #2A2450;
  --success-bg: #133327;
  --warning-bg: #362509;
  --danger-bg: #3A1720;
  --info-bg: #122A42;
  --neutral-bg: #26262F;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
::selection { background: var(--brand); color: #fff; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid var(--bg); }
.icon { display: block; flex-shrink: 0; }

/* ===================== App shell ===================== */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
  transition: transform 0.25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 16px;
}
.sidebar-brand .logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), #9B87FF);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; font-size: 14px;
  box-shadow: 0 4px 14px rgba(var(--brand-rgb), 0.35);
}
.sidebar-brand .brand-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar-brand .brand-name { font-family: var(--font-display); font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-brand .brand-sub { font-size: 11px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-scroll { flex: 1; overflow-y: auto; padding: 6px 12px; }
.nav-section-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); font-weight: 700; padding: 16px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500; font-size: 13.5px;
  cursor: pointer; position: relative; margin-bottom: 2px;
  transition: background 0.15s, color 0.15s;
}
.nav-item .icon { color: var(--text-faint); transition: color 0.15s; }
.nav-item:hover { background: var(--surface-alt); color: var(--text); }
.nav-item:hover .icon { color: var(--text); }
.nav-item.active { background: var(--brand-light); color: var(--brand-dark); }
:root[data-theme="dark"] .nav-item.active { color: #C9BFFF; }
.nav-item.active .icon { color: var(--brand); }
.nav-item .badge-count {
  margin-left: auto; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700;
  border-radius: 999px; padding: 1px 6px; min-width: 17px; text-align: center;
}

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border-soft); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); cursor: pointer; }
.user-chip:hover { background: var(--surface-alt); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 12px; flex-shrink: 0; }
.user-chip .who { min-width: 0; }
.user-chip .who .name { font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .who .role { font-size: 11px; color: var(--text-faint); }

/* ===================== Main area ===================== */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 64px; flex-shrink: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-soft);
  position: sticky; top: 0; z-index: 10;
}
.topbar .page-title { font-size: 19px; font-weight: 800; font-family: var(--font-display); }
.topbar .page-sub { font-size: 12px; color: var(--text-faint); margin-top: 1px; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 12px; width: 260px;
  color: var(--text-faint); margin-left: auto;
}
.search-box input { border: none; outline: none; background: transparent; color: var(--text); font-size: 13px; width: 100%; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
  cursor: pointer; flex-shrink: 0; transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }
.menu-toggle { display: none; }

.content { flex: 1; padding: 22px; max-width: 1440px; width: 100%; margin: 0 auto; }

/* ===================== Buttons ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 13px; cursor: pointer;
  border: 1px solid transparent; transition: all 0.15s ease; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 2px 8px rgba(var(--brand-rgb), 0.3); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-alt); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ===================== Cards ===================== */
.card { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.card-header h3 { font-size: 15px; font-weight: 700; }
.card-header .sub { font-size: 12px; color: var(--text-faint); margin-top: 2px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
/* Variantes de colonnes. À utiliser plutôt qu'un style en ligne : un style en ligne
   l'emporterait sur les media queries ci-dessous et casserait l'affichage mobile. */
.kpi-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.kpi-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.kpi-card { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.kpi-label { color: var(--text-faint); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-family: var(--font-display); font-size: 25px; font-weight: 800; }
.kpi-delta { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; width: fit-content; padding: 2px 8px; border-radius: 999px; }
.kpi-delta.up { color: var(--success); background: var(--success-bg); }
.kpi-delta.down { color: var(--danger); background: var(--danger-bg); }
.kpi-delta.flat { color: var(--text-muted); background: var(--neutral-bg); }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
/* Un enfant de grille a min-width:auto : il refuse de descendre sous la largeur minimale
   de son contenu, si bien qu'un tableau large élargit la carte et fait déborder la page.
   min-width:0 l'autorise à rétrécir, le défilement étant assuré par .table-wrap. */
.grid-2 > *, .grid-3 > *, .kpi-grid > * { min-width: 0; }

/* ===================== Tables ===================== */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.2px; }
.data-table thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); font-weight: 700; padding: 10px 16px; border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; background: var(--surface);
}
.data-table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.data-table tbody tr { transition: background 0.12s; }
.data-table tbody tr:hover { background: var(--surface-alt); }
.data-table tbody tr:last-child td { border-bottom: none; }
.cell-strong { font-weight: 600; color: var(--text); }
.cell-muted { color: var(--text-faint); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; opacity: 0; transition: opacity 0.12s; }
tr:hover .row-actions { opacity: 1; }
.table-toolbar { display: flex; align-items: center; gap: 10px; padding: 16px 20px; flex-wrap: wrap; }
.table-toolbar .grow { flex: 1; }

/* ===================== Badges / pills ===================== */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--neutral-bg); color: var(--text-muted); }
.tag-chip { background: var(--brand-light); color: var(--brand-dark); font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; }
:root[data-theme="dark"] .tag-chip { color: #C9BFFF; }

/* ===================== Forms ===================== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field .hint { font-size: 11px; color: var(--text-faint); }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-alt); color: var(--text);
  font-size: 13.5px; font-family: inherit; outline: none; transition: border-color 0.15s, background 0.15s;
}
.input:focus, select.input:focus, textarea.input:focus { border-color: var(--brand); background: var(--surface); }
textarea.input { resize: vertical; min-height: 70px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }

/* ===================== Modal ===================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 15, 25, 0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 20px; z-index: 100; overflow-y: auto;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; animation: slideUp 0.18s ease;
  border: 1px solid var(--border-soft);
}
.modal.modal-lg { max-width: 780px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border-soft); }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px 22px; max-height: 70vh; overflow-y: auto; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border-soft); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ===================== Toasts ===================== */
.toast-stack { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  border-radius: var(--radius-sm); padding: 12px 15px; font-size: 13px; font-weight: 500;
  min-width: 260px; animation: toastIn 0.2s ease;
}
.toast .icon-wrap { width: 26px; height: 26px; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ===================== Empty state ===================== */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; text-align: center; color: var(--text-faint); }
.empty-state .icon-wrap { width: 56px; height: 56px; border-radius: 16px; background: var(--surface-alt); display: flex; align-items: center; justify-content: center; margin-bottom: 14px; color: var(--text-faint); }
.empty-state h4 { color: var(--text); font-size: 15px; margin-bottom: 4px; }
.empty-state p { font-size: 12.5px; max-width: 320px; }

/* ===================== Misc ===================== */
.divider { height: 1px; background: var(--border-soft); margin: 16px 0; }
.pill-tabs { display: flex; gap: 4px; background: var(--surface-alt); padding: 4px; border-radius: 10px; width: fit-content; }
.pill-tab { padding: 7px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); cursor: pointer; }
.pill-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.progress-bar { height: 6px; border-radius: 999px; background: var(--neutral-bg); overflow: hidden; }
.progress-bar > span { display: block; height: 100%; border-radius: 999px; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -8px; border: 2px solid var(--surface); }
.avatar-stack .avatar:first-child { margin-left: 0; }
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  min-width: 190px; padding: 6px; z-index: 60; animation: fadeIn 0.12s ease;
}
.dropdown-item { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--text); cursor: pointer; }
.dropdown-item:hover { background: var(--surface-alt); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-sep { height: 1px; background: var(--border-soft); margin: 6px 0; }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; }
.pagination .info { font-size: 12px; color: var(--text-faint); }
.pagination .controls { display: flex; gap: 6px; }

.stock-bar { width: 90px; }
.list-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--border-soft); }
.list-row:last-child { border-bottom: none; }

.section-title { font-size: 13px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; margin: 22px 0 10px; }
.section-title:first-child { margin-top: 0; }

/* #app est un conteneur flex (barre latérale + contenu). Sans flex:1, cet écran se
   réduirait à la largeur de la carte et resterait plaqué à gauche au lieu d'être centré. */
.login-screen { flex: 1; width: 100%; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(circle at top left, var(--brand-light), var(--bg) 55%); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 34px; border: 1px solid var(--border-soft); }

.chart-tooltip { position: absolute; background: var(--text); color: var(--bg); font-size: 11.5px; padding: 6px 10px; border-radius: 7px; pointer-events: none; white-space: nowrap; transform: translate(-50%, -115%); font-weight: 600; box-shadow: var(--shadow-md); z-index: 30; }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-faint); margin-bottom: 4px; }
.breadcrumb a:hover { color: var(--text); }

.detail-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; gap: 16px; flex-wrap: wrap; }
.detail-title { display: flex; align-items: center; gap: 12px; }
.stat-inline { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.stat-inline .item { display: flex; flex-direction: column; gap: 2px; }
.stat-inline .item .v { font-weight: 700; font-size: 15px; font-family: var(--font-display); }
.stat-inline .item .l { font-size: 11px; color: var(--text-faint); }

/* ===================== Responsive ===================== */
@media (max-width: 1180px) {
  .kpi-grid, .kpi-grid.cols-3, .kpi-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: flex; }
  .search-box { display: none; }
  .kpi-grid, .kpi-grid.cols-3, .kpi-grid.cols-2 { grid-template-columns: 1fr; }
  /* Les groupes d'onglets et barres d'outils doivent pouvoir passer à la ligne */
  .pill-tabs { flex-wrap: wrap; width: 100%; }
  .table-toolbar { gap: 8px; }
  .detail-header { gap: 12px; }
  .grid-3 { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .content { padding: 14px; }
}
