/* ============================================================================
   BOUTIQUE MANAGER - STYLE (mobile-first, responsive, zéro framework)
   Cibles : 380px → 768px → 1024px+
   ============================================================================ */

:root {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #dbeafe;
  --success:        #16a34a;
  --success-light:  #d1fae5;
  --warning:        #ea580c;
  --warning-light:  #fed7aa;
  --danger:         #dc2626;
  --danger-light:   #fee2e2;
  --text:           #1f2937;
  --text-muted:     #6b7280;
  --bg:             #f9fafb;
  --surface:        #ffffff;
  --border:         #e5e7eb;
  --border-strong:  #d1d5db;

  --radius:         0.5rem;
  --radius-lg:      0.75rem;
  --shadow:         0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg:      0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -2px rgba(0,0,0,.04);

  --font:           system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 0.5em 0; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.125rem; }

/* ----------------------------------------------------------------------------
   LAYOUT
   ---------------------------------------------------------------------------- */

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

.page-header h1 {
  font-size: 1.125rem;
  margin: 0;
}

.page-header .user-info {
  font-size: 0.875rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-content {
  flex: 1;
  padding: 1rem;
}

/* ----------------------------------------------------------------------------
   CARDS
   ---------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.card-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.card-stat .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.card-stat .stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.card-stat .stat-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.card-stat.success .stat-value { color: var(--success); }
.card-stat.danger  .stat-value { color: var(--danger); }
.card-stat.warning .stat-value { color: var(--warning); }

/* ----------------------------------------------------------------------------
   BUTTONS (taille tactile mobile : min 50px)
   ---------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 50px;
  padding: 0.625rem 1.25rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--primary);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
  text-decoration: none;
}
.btn:hover:not(:disabled) { background: var(--primary-dark); text-decoration: none; }
.btn:disabled            { opacity: 0.5; cursor: not-allowed; }
.btn:focus               { outline: 2px solid var(--primary-light); outline-offset: 2px; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg); }

.btn-danger  { background: var(--danger); }
.btn-danger:hover:not(:disabled)  { background: #b91c1c; }

.btn-success { background: var(--success); }
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover:not(:disabled) { background: #c2410c; }

.btn-block { width: 100%; }
.btn-sm    { min-height: 38px; padding: 0.375rem 0.75rem; font-size: 0.875rem; }

/* ----------------------------------------------------------------------------
   FORMS
   ---------------------------------------------------------------------------- */

.form-group {
  margin-bottom: 1rem;
}
.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.375rem;
  color: var(--text);
}
.form-control {
  display: block;
  width: 100%;
  min-height: 50px;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

select.form-control { padding-right: 2rem; }

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

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

/* ----------------------------------------------------------------------------
   ALERTS / MESSAGES
   ---------------------------------------------------------------------------- */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  margin-bottom: 1rem;
  font-size: 0.9375rem;
}
.alert-error    { background: var(--danger-light);  color: #991b1b; border-color: #fca5a5; }
.alert-success  { background: var(--success-light); color: #14532d; border-color: #86efac; }
.alert-warning  { background: var(--warning-light); color: #7c2d12; border-color: #fdba74; }
.alert-info     { background: var(--primary-light); color: #1e3a8a; border-color: #93c5fd; }

.alert.hidden { display: none; }

/* ----------------------------------------------------------------------------
   TABLES
   ---------------------------------------------------------------------------- */

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 0.9375rem;
}
.table th, .table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.table th {
  background: var(--bg);
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg); }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-danger  { background: var(--danger-light);  color: #991b1b; }
.badge-warning { background: var(--warning-light); color: #7c2d12; }
.badge-success { background: var(--success-light); color: #14532d; }
.badge-info    { background: var(--primary-light); color: #1e3a8a; }

/* ----------------------------------------------------------------------------
   LOGIN page
   ---------------------------------------------------------------------------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow-lg);
}
.login-card h1 {
  text-align: center;
  margin-bottom: 0.25rem;
  color: var(--primary);
}
.login-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
}

/* ----------------------------------------------------------------------------
   UTILITIES
   ---------------------------------------------------------------------------- */

.text-muted   { color: var(--text-muted); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-bold    { font-weight: 700; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.flex            { display: flex; }
.flex-between    { display: flex; justify-content: space-between; align-items: center; }
.flex-wrap       { flex-wrap: wrap; }
.gap-1           { gap: 0.5rem; }
.gap-2           { gap: 1rem; }
.flex-1          { flex: 1; }

.hidden { display: none !important; }

.spinner {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

/* ----------------------------------------------------------------------------
   MODAL (Phase 2 — approve/reject rabais, etc.)
   ---------------------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.hidden { display: none !important; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.25rem;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  z-index: 1;
  animation: modalPop 0.15s ease-out;
}

@keyframes modalPop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* Onglets actifs (.tab-btn) : style par défaut quand non sélectionné = btn-secondary */
.tab-btn        { white-space: nowrap; }
.tab-btn .badge { margin-left: 0.25rem; }

/* ----------------------------------------------------------------------------
   RESPONSIVE
   ---------------------------------------------------------------------------- */

@media (min-width: 768px) {
  h1 { font-size: 1.875rem; }
  h2 { font-size: 1.5rem; }
  .container       { padding: 1.5rem; }
  .form-row        { grid-template-columns: 1fr 1fr; }
  .form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
}

@media (min-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

/* ----------------------------------------------------------------------------
   HEADER NOTIFICATIONS (Tâche 2.5 + F2.d)
   Chips injectés par js/notifications.js dans .page-header .user-info.
   Variantes : --rabais / --besoins / --anniv (propriétaire),
               --pending / --resolved (employé).
   Aliases sémantiques : .header-notif-chip.danger / .warning / .info / .success.
   Mobile-first : sous 480px, l'icône reste seule (compteur en sr-only).
   ---------------------------------------------------------------------------- */

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

.header-notif {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: nowrap;
}

.header-notif:empty { display: none; }

.header-notif-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.55rem;
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: 9999px;
  background: var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.header-notif-chip:hover,
.header-notif-chip:focus-visible {
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.header-notif-chip:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.header-notif-chip:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

.header-notif-icon {
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}

.header-notif-count {
  font-variant-numeric: tabular-nums;
  min-width: 1ch;
  text-align: center;
}

/* Variantes sémantiques (urgence) */
.header-notif-chip.danger,
.header-notif-chip--rabais {
  background: var(--danger-light);
  color: #991b1b;
  border-color: rgba(220, 38, 38, 0.22);
}
.header-notif-chip.warning,
.header-notif-chip--besoins,
.header-notif-chip--pending {
  background: var(--warning-light);
  color: #7c2d12;
  border-color: rgba(234, 88, 12, 0.22);
}
.header-notif-chip.info,
.header-notif-chip--resolved {
  background: var(--primary-light);
  color: #1e3a8a;
  border-color: rgba(37, 99, 235, 0.22);
}
.header-notif-chip.success,
.header-notif-chip--anniv {
  background: var(--success-light);
  color: #14532d;
  border-color: rgba(22, 163, 74, 0.22);
}
/* 3.1.d — chip 🛡️ backup KO/stale (variante warning marquée) */
.header-notif-chip--backup {
  background: var(--warning-light);
  color: #7c2d12;
  border-color: rgba(234, 88, 12, 0.35);
}
/* 3.2.d — chip 📦 stock critique (variante danger — perte de vente potentielle) */
.header-notif-chip--stock {
  background: var(--danger-light);
  color: #991b1b;
  border-color: rgba(220, 38, 38, 0.22);
}

/* 3.2.c — wrappers + SVG graphes analytics (vanilla, responsive) */
.chart-wrapper {
  width: 100%;
  min-height: 6rem;
  overflow-x: auto;
}
.chart-svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Mobile (< 480px) : icône seule, compteur masqué visuellement
   (l'info reste accessible via le tooltip [title] et l'aria-label). */
@media (max-width: 479px) {
  .header-notif { gap: 0.25rem; }
  .header-notif-chip {
    padding: 0.25rem 0.4rem;
    min-width: 32px;
    justify-content: center;
  }
  .header-notif-count {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
  }
}

/* Tablet/desktop : pas de changement (icône + compteur) */
@media (min-width: 480px) {
  .header-notif-chip { padding: 0.3rem 0.65rem; }
}

/* ============================================================================
   AUDIT LOG VIEWER (Phase 4.2.b/c)
   ============================================================================ */

/* Grille des filtres responsive */
.audit-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  align-items: end;
}

/* Tableau dense */
.audit-table th,
.audit-table td {
  font-size: 0.875rem;
  vertical-align: top;
}
.audit-table td:first-child {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Liens drill-down (action / utilisateur) */
.audit-drill {
  color: #0a5;
  text-decoration: none;
  border-bottom: 1px dotted #0a5;
}
.audit-drill:hover { background: rgba(10, 92, 50, 0.08); }

/* Badges de statut */
.audit-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.audit-badge.badge-success { background: #d1fae5; color: #065f46; }
.audit-badge.badge-error   { background: #fee2e2; color: #991b1b; }
.audit-badge.badge-warning { background: #fef3c7; color: #92400e; }
.audit-badge.badge-default { background: #e5e7eb; color: #374151; }

/* Bouton toggle détails */
.audit-toggle-details {
  white-space: nowrap;
}

/* Ligne détails (expand inline) */
.audit-details-row > td {
  background: #f9fafb;
  border-top: 0;
  padding: 0.75rem 1rem 1rem;
}
.audit-details {
  display: grid;
  gap: 0.5rem;
  font-size: 0.8125rem;
}
.audit-details strong { color: #374151; }
.audit-json {
  background: #1f2937;
  color: #e5e7eb;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-family: ui-monospace, "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  margin: 0.25rem 0 0;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.audit-ua {
  font-size: 0.75rem;
  color: #6b7280;
  word-break: break-all;
}

/* Mobile : filtres en colonne pleine largeur */
@media (max-width: 479px) {
  .audit-filters { grid-template-columns: 1fr; }
  .audit-table th,
  .audit-table td { font-size: 0.8125rem; padding: 0.4rem 0.5rem; }
}