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

/* -----------------------------------------
   DESIGN TOKENS
   ----------------------------------------- */
:root {
  /* Brand */
  --aro-blue:        #003B73;
  --aro-blue-dark:   #002952;
  --aro-blue-mid:    #1A5FA8;
  --aro-blue-light:  #2FA4FF;
  --aro-blue-tint:   #EEF5FF;
  --aro-green:       #76BA1B;
  --aro-green-dark:  #5a8e14;
  --aro-green-light: #A4DE02;
  --aro-green-tint:  #F0FAE0;
  --aro-yellow:      #FFD700;

  /* Surface */
  --bg-body:         #F2F5F8;
  --bg-sidebar:      #ffffff;
  --bg-card:         #ffffff;
  --bg-subtle:       #F8FAFB;
  --bg-hover:        #F0F4F8;

  /* Text */
  --text-primary:    #0F1F33;
  --text-secondary:  #4A5E72;
  --text-muted:      #8FA0B2;
  --text-on-dark:    #ffffff;

  /* Border */
  --border:          #DDE4EC;
  --border-focus:    var(--aro-blue);

  /* Status */
  --success:         #16a34a;
  --success-tint:    #DCFCE7;
  --danger:          #DC2626;
  --danger-tint:     #FEE2E2;
  --warning:         #D97706;
  --warning-tint:    #FEF3C7;
  --info:            var(--aro-blue-light);
  --info-tint:       #E0F2FE;

  /* Elevation */
  --shadow-xs:  0 1px 2px rgb(0 0 0 / .04);
  --shadow-sm:  0 2px 6px rgb(0 0 0 / .06);
  --shadow-md:  0 4px 16px rgb(0 0 0 / .08);
  --shadow-lg:  0 12px 32px rgb(0 0 0 / .10);

  /* Shape */
  --r-sm:  2px;
  --r-md:  4px;
  --r-lg:  6px;
  --r-xl:  8px;
  --r-pill:9999px;

  /* Sidebar */
  --sidebar-w: 268px;
  --sidebar-collapsed-w: 72px;

  /* Typography */
  --font-display: 'Plus Jakarta Sans', sans-serif;
  --font-body:    'Inter', sans-serif;

  /* Type scale */
  --text-xs:   0.75rem;   /* 12px */
  --text-sm:   0.8125rem; /* 13px */
  --text-base: 0.9375rem; /* 15px */
  --text-lg:   1.0625rem; /* 17px */
  --text-xl:   1.25rem;   /* 20px */
  --text-2xl:  1.5rem;    /* 24px */
  --text-3xl:  2rem;      /* 32px */
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

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

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--aro-blue);
  line-height: 1.25;
}

a { color: inherit; text-decoration: none; }

button,
input,
select,
textarea {
  min-width: 0;
}

:focus-visible {
  outline: 3px solid rgba(47, 164, 255, 0.45);
  outline-offset: 2px;
}

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

.mobile-header,
.sidebar-backdrop,
.sidebar-close-button {
  display: none;
}

/* -----------------------------------------
   SIDEBAR
   ----------------------------------------- */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

/* Logo */
.logo-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}
.logo-container img { height: 40px; width: auto; }
.logo-text {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}
.logo-text .blue  { color: var(--aro-blue); }
.logo-text .green { color: var(--aro-green); }

/* Nav */
.sidebar-section {
  flex: 1;
  padding: 1.25rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-section-title {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 0.625rem;
  margin-bottom: 0.5rem;
  margin-top: 0.25rem;
}

.nav-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#creator-only-nav,
#admin-nav,
#super-admin-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--r-md);
  transition: background 0.15s ease, color 0.15s ease;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}

.nav-link .nav-icon {
  font-size: 1rem;
  flex-shrink: 0;
  width: 1.25rem;
  text-align: center;
  color: var(--aro-blue-mid);
}

.nav-link:hover {
  background: var(--aro-blue-tint);
  color: var(--aro-blue);
}

/* Element actif: accent vert fonce (contraste suffisant sur fond clair) */
.nav-link.active {
  background: var(--aro-green-tint);
  color: var(--aro-green-dark);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--aro-green-dark);
}

.nav-link.active .nav-icon { color: var(--aro-green-dark); }

/* Sidebar footer */
.sidebar-footer {
  padding: 1rem 0.875rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  flex-shrink: 0;
}

.sidebar-user-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.875rem 1rem;
}

.sidebar-user-name {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--aro-blue);
  margin-top: 0.375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-status {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 0.125rem;
}

/* -----------------------------------------
   MAIN CONTENT
   ----------------------------------------- */
.main-content {
  padding: 2rem 2.25rem;
  background: var(--bg-body);
  min-width: 0;
  width: 100%;
  max-width: 1800px;
  margin-inline: auto;
}

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--aro-blue);
}

.page-header .page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* -----------------------------------------
   CARDS
   ----------------------------------------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
  padding: 1.5rem;
}

.card + .card { margin-top: 0; }

/* -----------------------------------------
   STAT CARDS
   ----------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.stats-grid-overview {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--aro-blue), var(--aro-blue-light));
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-value {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

/* Highlighted stat variant (admin pilotage) */
.stat-card--accent {
  background: linear-gradient(135deg, var(--aro-blue), var(--aro-blue-mid));
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(0, 59, 115, 0.25);
}
.stat-card--accent::before { display: none; }
.stat-card--accent .stat-label { color: rgba(255,255,255,0.65); }
.stat-card--accent .stat-value { color: #fff; }

/* -----------------------------------------
   TOOLBAR
   ----------------------------------------- */
.screen-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.screen-toolbar h2,
.screen-toolbar h3 {
  font-size: var(--text-lg);
  font-weight: 700;
}

.screen-toolbar .text-secondary {
  font-size: var(--text-sm);
  margin-top: 0.2rem;
}

.screen-toolbar-actions {
  display: flex;
  gap: 0.625rem;
  align-items: flex-end;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
  max-width: 100%;
}

.screen-toolbar-filters {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
  min-width: 0;
}

.screen-toolbar-filters label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  white-space: nowrap;
}

.filter-field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  min-width: 140px;
}

.filter-field-wide {
  min-width: 210px;
}

.filter-field label {
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.2;
}

.filter-field .input {
  min-height: 42px;
}

/* -----------------------------------------
   FORMS
   ----------------------------------------- */
.form-group { margin-bottom: 1.125rem; }

.form-span-full {
  grid-column: 1 / -1;
}

.license-machine-field {
  padding: 1rem;
  border: 1px solid #b8d7ee;
  border-radius: var(--r-md);
  background: #eef7fd;
  min-width: 0;
}

.license-machine-field .label { color: #073b67; }
#gen-course { border-color: #6c9fc3; }
.license-machine-input { border-color: #6c9fc3; background: #fff; }
.license-machine-input:focus { border-color: #075b98; }
.license-history-summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 1.125rem;
  font-weight: 700;
  list-style: none;
}
.license-history-summary::-webkit-details-marker { display: none; }
.license-history-summary::before { content: '+'; color: #075b98; font-size: 1.5rem; line-height: 1; }
.license-history[open] .license-history-summary::before { content: '−'; }
.license-history[open] .data-table-container { margin-top: 1rem; }
@media (max-width: 980px) {
  #licenses-history td:nth-child(4),
  #licenses-history td:nth-child(5),
  #licenses-history td:nth-child(6) { display: none; }
}

.form-help {
  display: block;
  margin-top: 0.4rem;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  line-height: 1.45;
}

.label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.4rem;
}

.input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text-primary);
  transition: border-color 0.15s, box-shadow 0.15s;
  line-height: 1.5;
}

.input:focus {
  outline: none;
  border-color: var(--aro-blue);
  box-shadow: 0 0 0 3px rgba(0, 59, 115, 0.12);
}

.input[readonly] {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  cursor: not-allowed;
}

select.input { cursor: pointer; }

/* Checkbox style */
input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--aro-blue);
  cursor: pointer;
  transform: scale(1.2);
  flex-shrink: 0;
}

/* -----------------------------------------
   BUTTONS
   ----------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  line-height: 1.4;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--aro-blue);
  color: #fff;
  border-color: var(--aro-blue);
}
.btn-primary:hover {
  background: var(--aro-blue-dark);
  border-color: var(--aro-blue-dark);
  box-shadow: 0 4px 12px rgba(0,59,115,0.28);
}

.btn-secondary {
  background: var(--aro-green);
  color: #fff;
  border-color: var(--aro-green);
}
.btn-secondary:hover {
  background: var(--aro-green-dark);
  border-color: var(--aro-green-dark);
  box-shadow: 0 4px 12px rgba(118,186,27,0.3);
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover {
  background: var(--bg-hover);
  border-color: var(--aro-blue);
  color: var(--aro-blue);
}

.btn-danger-outline {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger-outline:hover {
  background: var(--danger-tint);
}

/* -----------------------------------------
   BADGES
   ----------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.625rem;
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.4;
}

.badge-success  { background: var(--success-tint);  color: #166534; }
.badge-warning  { background: var(--warning-tint);  color: #92400e; }
.badge-danger   { background: var(--danger-tint);   color: #991b1b; }
.badge-info     { background: var(--info-tint);     color: #075985; }
.badge-secondary{ background: #E8EDF2;              color: #374151; }

/* Mode de facturation d'une licence: mise a jour gratuite (vert), nouvelle licence payante (neutre). */
.billing-preview { display: flex; align-items: flex-start; gap: 0.6rem; padding: 0.75rem 0.9rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface, #fff); font-size: 0.9rem; }
.billing-preview[hidden] { display: none; }
.billing-preview.is-update { border-color: #16a34a55; background: var(--success-tint); }
.billing-preview.is-credit { border-color: var(--border); background: #F4F6F9; }
.billing-preview.is-reuse { border-color: #0369a155; background: var(--info-tint); }
.billing-preview .badge { white-space: nowrap; }
tr.license-superseded td { opacity: 0.55; }
.license-superseded-filter { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0.6rem 1rem; font-size: 0.85rem; }

/* -----------------------------------------
   TABLES
   ----------------------------------------- */
.data-table-container {
  overflow-x: auto;
  border-radius: var(--r-md);
  max-width: 100%;
  border: 1px solid var(--border);
  scrollbar-gutter: stable;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: var(--text-sm);
}

.data-table thead tr {
  border-bottom: 2px solid var(--border);
}

.data-table th {
  padding: 0.75rem 1rem;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}

.data-table th:first-child,
.data-table td:first-child {
  padding-left: 1.125rem;
}

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

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover td {
  background: var(--bg-subtle);
}

.data-table td .btn {
  padding: 0.375rem 0.75rem;
  font-size: var(--text-xs);
  margin: 0.15rem 0.1rem 0.15rem 0;
}

/* -----------------------------------------
   PAGINATION
   ----------------------------------------- */
.pagination-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.375rem;
  margin-top: 1.25rem;
}

/* -----------------------------------------
   IMPERSONATION BANNER
   ----------------------------------------- */
#impersonation-banner {
  display: none;
  background: var(--danger-tint);
  border: 1.5px solid #fca5a5;
  color: #991b1b;
  padding: 0.875rem 1.25rem;
  border-radius: var(--r-md);
  margin-bottom: 1.75rem;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-sm);
  font-weight: 500;
  gap: 1rem;
}

/* -----------------------------------------
   TWO-COL OVERVIEW GRID
   ----------------------------------------- */
.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

/* Account status info rows */
.account-info-row {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.account-info-row:last-of-type { border-bottom: none; }
.account-info-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}
.account-info-value {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--aro-blue);
}

/* -----------------------------------------
   AUTH PAGES (Login / Register)
   ----------------------------------------- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 60% 50% at 85% 5%, rgba(47,164,255,0.12), transparent),
    radial-gradient(ellipse 50% 60% at 10% 90%, rgba(118,186,27,0.1), transparent),
    var(--bg-body);
}

.auth-card .logo-container {
  border: 0;
  padding: 0;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  padding: 2.75rem 2.5rem;
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo img { height: 52px; }

.auth-card h1 {
  font-size: var(--text-2xl);
  text-align: center;
  margin-bottom: 0.375rem;
}

.auth-card .auth-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 2rem;
}

.auth-footer {
  margin-top: 1.75rem;
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.auth-footer a {
  color: var(--aro-blue);
  font-weight: 600;
}
.auth-footer a:hover { text-decoration: underline; }

/* -----------------------------------------
   MODALS
   ----------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 40, 0.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.25s ease;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
  opacity: 1;
}

body.modal-open {
  overflow: hidden;
}

.modal-content {
  background: var(--bg-card);
  padding: 2rem 2rem 1.75rem;
  border-radius: var(--r-xl);
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 2rem);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  position: relative;
  display: flex;
  flex-direction: column;
  transform: translateY(16px) scale(0.99);
  transition: transform 0.25s ease;
  overflow: hidden;
}

.modal-overlay.active .modal-content {
  transform: translateY(0) scale(1);
}

#modal-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  min-height: 0;
  overscroll-behavior: contain;
}

.modal-header {
  margin-bottom: 1.25rem;
  padding-right: 2rem;
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--aro-blue);
}

.modal-close {
  position: absolute;
  top: 1.375rem;
  right: 1.375rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  width: 2rem; height: 2rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.125rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--danger-tint); color: var(--danger); }

.modal-footer {
  margin-top: 1.75rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
}

/* -----------------------------------------
   TOASTS
   ----------------------------------------- */
#toast-container {
  position: fixed;
  bottom: 1.75rem;
  right: 1.75rem;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  pointer-events: none;
}

.toast {
  pointer-events: all;
  padding: 0.875rem 1.25rem;
  background: var(--text-primary);
  color: #fff;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 280px;
  max-width: 420px;
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  font-size: var(--text-sm);
  font-weight: 500;
  border-left: 4px solid rgba(255,255,255,0.3);
}

.toast-success { border-left-color: var(--aro-green-light); }
.toast-error   { border-left-color: #f87171; }
.toast-warning { border-left-color: var(--aro-yellow); }

@keyframes toastIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes toastOut {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(120%); opacity: 0; }
}

.toast.fade-out { animation: toastOut 0.3s ease forwards; }

/* -----------------------------------------
   UTILITY CLASSES
   ----------------------------------------- */
.grid       { display: grid; }
.col-2      { grid-template-columns: repeat(2, 1fr); }
.gap-4      { gap: 1rem; }
.gap-6      { gap: 1.5rem; }
.mb-2       { margin-bottom: 0.5rem; }
.mb-4       { margin-bottom: 1rem; }
.mb-6       { margin-bottom: 1.5rem; }
.mt-4       { margin-top: 1rem; }
.mb-8       { margin-bottom: 2rem; }
.text-center{ text-align: center; }
.text-secondary { color: var(--text-secondary); font-size: var(--text-sm); }
.text-light { color: var(--text-muted); font-size: var(--text-sm); }
.text-danger{ color: var(--danger); }
.w-full     { width: 100%; }
.py-8       { padding-top: 2rem; padding-bottom: 2rem; }

/* Settings form toggle row */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

/* -----------------------------------------
   RESPONSIVE - 1280px
   ----------------------------------------- */
@media (max-width: 1280px) {
  :root { --sidebar-w: 240px; }

  .stats-grid-overview {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* -----------------------------------------
   RESPONSIVE - 1024px
   ----------------------------------------- */
@media (max-width: 1024px) {
  .main-content { padding: 1.5rem 1.75rem; }

  .overview-grid { grid-template-columns: 1fr; }

  .stats-grid-overview {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .screen-toolbar {
    align-items: flex-start;
  }

  .screen-toolbar-actions {
    justify-content: flex-start;
  }
}

/* -----------------------------------------
   RESPONSIVE - 980px (sidebar collapses)
   ----------------------------------------- */
@media (max-width: 980px) {
  body {
    padding-top: 64px;
  }

  body.mobile-menu-open {
    overflow: hidden;
  }

  .dashboard-layout {
    display: block;
    min-height: calc(100vh - 64px);
  }

  .mobile-header {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1200;
    height: 64px;
    padding: 0 1rem;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
    backdrop-filter: blur(12px);
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
  }

  .mobile-brand img {
    width: 30px;
    height: 30px;
    object-fit: contain;
  }

  .mobile-brand .logo-text {
    font-size: 1.05rem;
  }

  .mobile-section-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 600;
  }

  .mobile-menu-button,
  .sidebar-close-button {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--bg-card);
    color: var(--aro-blue);
    cursor: pointer;
  }

  .mobile-menu-button {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }

  .mobile-menu-button span {
    width: 19px;
    height: 2px;
    border-radius: var(--r-pill);
    background: currentColor;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 64px 0 0;
    z-index: 1090;
    border: 0;
    background: rgba(15, 31, 51, 0.46);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
  }

  body.mobile-menu-open .sidebar-backdrop {
    display: block;
    opacity: 1;
    visibility: visible;
  }

  .sidebar {
    position: fixed;
    inset: 64px auto 0 0;
    z-index: 1100;
    width: min(86vw, 320px);
    height: calc(100dvh - 64px);
    border-right: 1px solid var(--border);
    border-bottom: 0;
    flex-direction: column;
    flex-wrap: nowrap;
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
  }

  body.mobile-menu-open .sidebar {
    transform: translateX(0);
  }

  .logo-container {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    border-right: 0;
  }

  .logo-container img { height: 34px; }
  .logo-container .logo-text { font-size: 1.25rem; }

  .sidebar-close-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    font-size: 1.55rem;
    line-height: 1;
  }

  .sidebar-section {
    flex: 1;
    padding: 1rem 0.75rem;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0.25rem;
  }

  .sidebar-section-title { display: block; }

  .nav-menu,
  #creator-only-nav,
  #admin-nav,
  #super-admin-nav {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 2px;
  }

  .nav-link {
    min-height: 46px;
    width: 100%;
    padding: 0.7rem 0.8rem;
    font-size: var(--text-sm);
  }

  .sidebar-footer {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 0.875rem;
    border-top: 1px solid var(--border);
    background: var(--bg-subtle);
  }

  .sidebar-user-card {
    padding: 0.75rem;
  }

  .sidebar-footer .btn { min-height: 44px; }

  .col-2 { grid-template-columns: 1fr; }

  .col-2 > [style*="grid-column: span 2"],
  .col-2 > .form-span-full {
    grid-column: 1 / -1 !important;
  }
}

/* -----------------------------------------
   RESPONSIVE - 768px
   ----------------------------------------- */
@media (max-width: 768px) {
  .main-content { padding: 1rem 0.75rem 2rem; }

  .page-header {
    margin-bottom: 1.25rem;
    gap: 0.5rem;
  }

  .stats-grid,
  .stats-grid-overview {
    grid-template-columns: 1fr 1fr;
    gap: 0.875rem;
  }

  .card {
    padding: 1rem;
    border-radius: var(--r-md);
  }

  .data-table th,
  .data-table td {
    padding: 0.625rem 0.75rem;
    font-size: var(--text-xs);
    white-space: nowrap;
  }

  .data-table { min-width: 600px; }

  .screen-toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.875rem;
  }

  .screen-toolbar-actions {
    width: 100%;
    justify-content: flex-start;
    align-items: stretch;
    flex-direction: column;
  }

  .screen-toolbar-filters {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--bg-subtle);
  }

  .screen-toolbar-filters .input { width: 100%; min-width: 0 !important; }

  .filter-field,
  .filter-field-wide {
    width: 100%;
    min-width: 0;
  }

  .modal-content {
    padding: 1.5rem 1.25rem;
    border-radius: var(--r-lg);
    max-height: calc(100svh - 1rem);
  }

  .modal-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .btn { width: 100%; justify-content: center; }

  /* Keep table action buttons compact */
  .data-table td .btn { width: auto; }

  .screen-toolbar-actions .btn,
  .screen-toolbar-filters .btn { width: 100%; }

  .pagination-controls {
    justify-content: space-between;
    flex-wrap: wrap;
    row-gap: 0.75rem;
  }

  .pagination-controls > span {
    width: 100%;
    margin-right: 0 !important;
  }

  .pagination-controls .btn {
    width: auto;
    min-height: 42px;
  }

  .auth-card {
    padding: 1.75rem 1.25rem;
    border-radius: var(--r-lg);
    max-width: calc(100vw - 1.5rem);
    margin-block: auto;
  }

  .auth-page {
    align-items: flex-start;
    padding: 0.75rem;
  }

  #toast-container {
    right: 0.75rem;
    left: 0.75rem;
    bottom: 0.75rem;
  }

  .toast { min-width: 0; max-width: 100%; }

  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header h1 { font-size: var(--text-xl); }
}

/* -----------------------------------------
   RESPONSIVE - 480px
   ----------------------------------------- */
@media (max-width: 480px) {
  .stats-grid,
  .stats-grid-overview {
    grid-template-columns: 1fr;
  }

  .col-2 { grid-template-columns: 1fr; }

  .mobile-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding-inline: 0.75rem;
    gap: 0.5rem;
  }

  .mobile-brand .logo-text {
    display: none;
  }

  .mobile-section-title {
    text-align: left;
    padding-left: 0.25rem;
  }

  .modal-overlay {
    padding: 0.5rem;
    align-items: flex-end;
  }

  .modal-content {
    max-height: calc(100svh - 0.5rem);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: 1.25rem 1rem 1rem;
  }
}

/* -----------------------------------------
   SECTION: #section-courses, etc., keep
   card headers from stacking poorly
   ----------------------------------------- */
@media (max-width: 768px) {
  #section-courses .card > div:first-child,
  #section-clients .card > div:first-child,
  #section-creators-mgmt .card > div:first-child,
  #section-admins .card > div:first-child {
    flex-direction: column;
    align-items: flex-start !important;
  }

  #section-courses .card > div:first-child > div:last-child,
  #section-clients .card > div:first-child > div:last-child,
  #section-creators-mgmt .card > div:first-child > div:last-child,
  #section-admins .card > div:first-child > div:last-child {
    width: 100%;
  }

  #section-courses #super-admin-courses-filters {
    width: 100%;
    flex-wrap: wrap;
  }

  #section-courses .data-table-container,
  #section-clients .data-table-container,
  #section-creators-mgmt .data-table-container,
  #section-admins .data-table-container,
  #section-support .data-table-container {
    overflow-x: auto;
  }

  #section-courses .data-table,
  #section-clients .data-table,
  #section-creators-mgmt .data-table,
  #section-admins .data-table,
  #section-support .data-table {
    min-width: 700px;
  }
}

/* -----------------------------------------
   REDUCED MOTION
   ----------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}


/* Icones SVG (sprite dans dashboard.html) : aucun emoji dans la plateforme */
.icon {
    width: 1.15em;
    height: 1.15em;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -0.2em;
    flex: none;
}
.nav-icon .icon { width: 1.2em; height: 1.2em; }
/* Menu lateral groupe par categories */
.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 0.875rem;
}

.nav-group-title {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 0.75rem;
  margin-bottom: 0.25rem;
}

.nav-group + .nav-group { padding-top: 0.5rem; border-top: 1px solid var(--border); }

.nav-label { overflow: hidden; text-overflow: ellipsis; }

.language-select { width: 100%; padding: 0.5rem 0.75rem; }

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

/* Selecteur de langue: compact, en haut a droite de l'en-tete de page (sous l'en-tete mobile sur petit ecran) */
[hidden] { display: none !important; }

.header-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.5rem 0.125rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--bg-card);
  color: var(--aro-blue-mid);
}

.lang-switch select {
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  min-height: 32px;
  padding: 0 0.25rem;
  cursor: pointer;
}

.lang-switch:focus-within { outline: 2px solid var(--aro-blue-light); outline-offset: 2px; }

.lang-row { display: flex; justify-content: flex-end; margin-bottom: 0.5rem; }
.lang-row select { width: auto; min-height: 36px; padding: 0.25rem 0.75rem; }

@media (max-width: 980px) {
  .page-header { flex-wrap: wrap; }
  .header-tools { width: 100%; justify-content: flex-start; }
  .lang-switch select { min-height: 40px; }
}

/* Quota de licences par client: masque tant que Features:LicenseQuota est desactive (attribut pose sur body) */
body[data-license-quota="off"] [data-feature="license-quota"] { display: none !important; }

/* Systeme visuel AroKey: couleurs et images de marque conservees. */
@media (max-width: 980px) {
  .main-content .data-table-container { overflow: visible; border: 0; background: transparent; }
  .main-content .data-table {
    display: block;
    width: 100%;
    min-width: 0 !important;
    table-layout: auto;
  }
  .main-content .data-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .main-content .data-table tbody { display: grid; gap: 1rem; width: 100%; }
  .main-content .data-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--bg-card);
    padding: 0.5rem 1rem;
    min-width: 0;
  }
  .main-content .data-table tbody td {
    display: block;
    min-width: 0;
    width: auto;
    max-width: 100%;
    padding: 0.75rem 0 !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
    border-bottom: 1px solid var(--border);
    text-align: start;
  }
  .main-content .data-table tbody td:last-child { border-bottom: 0; }
  .main-content .data-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 0.375rem;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0;
  }
  .main-content .data-table td.mobile-table-message::before,
  .main-content .data-table td[data-label=""]::before { display: none; }
  .main-content .data-table td .btn {
    min-height: 44px;
    max-width: 100%;
    white-space: normal;
    margin: 0.25rem 0.375rem 0.25rem 0 !important;
  }
  .main-content .data-table td.mobile-table-actions { line-height: 2; }
}

@media (min-width: 600px) and (max-width: 980px) {
  .main-content .data-table tbody tr { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1.25rem; }
  .main-content .data-table td.mobile-table-actions,
  .main-content .data-table td.mobile-table-message { grid-column: 1 / -1; }
}

.dashboard-layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
.main-content { min-width: 0; padding: clamp(1.25rem, 3vw, 2.75rem); }
.page-header { gap: 1rem; margin-bottom: 1.75rem; }
.page-header h1 { letter-spacing: -0.035em; font-size: clamp(1.5rem, 2.5vw, 2rem); }
.page-header .page-subtitle { margin-top: 0.5rem; max-width: 65ch; }
.card { padding: clamp(1.125rem, 2vw, 1.75rem); box-shadow: var(--shadow-xs); }
.card h2, .card h3 { letter-spacing: -0.025em; }
.card > h2, .card > h3 { margin-bottom: 0.75rem; }
.stats-grid { gap: 1rem; }
.stat-card { min-width: 0; padding: 1.5rem; }
.stat-value { font-variant-numeric: tabular-nums; letter-spacing: -0.04em; }
.nav-link { min-height: 44px; }
.nav-group-title { margin-bottom: 0.5rem; }
.input { min-height: 46px; border-radius: var(--r-md); }
textarea.input { min-height: 110px; resize: vertical; line-height: 1.6; }
.input:focus { outline-offset: 3px; }
:focus-visible { outline: 3px solid var(--aro-blue); outline-offset: 3px; }
.filter-field { min-width: 0; }
.filter-field label { line-height: 1.4; }
.btn { min-height: 44px; gap: 0.5rem; justify-content: center; line-height: 1.35; }
.btn:disabled { cursor: not-allowed; opacity: 0.55; }
.data-table-container { max-width: 100%; border-radius: var(--r-md); overscroll-behavior-x: contain; }
.data-table th { padding-block: 1rem; white-space: nowrap; }
.data-table td { padding-block: 1rem; vertical-align: middle; line-height: 1.5; }
.data-table td .btn { margin-block: 0.2rem; }
.data-table tbody tr:focus-within { background: var(--aro-blue-tint); }
.auth-card { width: min(100%, 460px); padding: clamp(1.5rem, 4vw, 2.5rem); box-shadow: var(--shadow-lg); }
.auth-card h1 { letter-spacing: -0.035em; }
.auth-card .btn { min-height: 48px; }
.modal-content { overscroll-behavior: contain; }
.modal-header { padding-bottom: 1rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
.modal-footer { padding-top: 1.25rem; border-top: 1px solid var(--border); gap: 0.75rem; }

.page-header {
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.screen-toolbar { align-items: flex-start; gap: 1.25rem; }
.screen-toolbar-actions { gap: 0.75rem; }
.screen-toolbar-filters { gap: 0.75rem; }
.screen-toolbar h2, .screen-toolbar h3 { font-size: var(--text-xl); }
.screen-toolbar-filters .filter-field { flex: 1 1 140px; }
.screen-toolbar-filters .filter-field-wide { flex-basis: 210px; }
.screen-toolbar-filters label { white-space: normal; }
.card { border-radius: 0; }
.card .data-table-container { margin-top: 0.5rem; }
.data-table th {
  color: var(--text-secondary);
  font-size: 0.6875rem;
  letter-spacing: 0.075em;
}
.data-table td { font-size: var(--text-sm); }
.data-table tbody tr { transition: background-color 160ms ease; }
.stat-card { min-height: 136px; justify-content: space-between; }
.stat-label { color: var(--text-secondary); letter-spacing: 0.035em; }
.stat-card--accent .stat-label { color: var(--text-on-dark); }
.stat-card::before { height: 3px; }
.stat-card[onclick], .stat-card[role="button"] {
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease;
}
.sidebar .logo-container { padding-block: 1.75rem; }
.sidebar-section { padding: 1.25rem 1rem; }
.nav-group + .nav-group { margin-top: 1.125rem; padding-top: 1rem; }
.nav-link { border-radius: 0 4px 4px 0; padding-block: 0.75rem; }
.sidebar-user-card { border-radius: 0; }
.btn { border-radius: var(--r-md); font-weight: 600; transition: background-color 160ms ease, box-shadow 160ms ease, transform 160ms ease; }
.label { display: block; margin-bottom: 0.5rem; line-height: 1.4; }
.input { padding: 0.75rem 0.875rem; background-color: var(--bg-card); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--aro-blue); }
.form-help { max-width: 65ch; }
.auth-page {
  background: linear-gradient(145deg, var(--aro-blue-tint), var(--bg-body) 55%, var(--aro-green-tint));
}
.auth-card { border-top: 4px solid var(--aro-green); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.auth-card .logo-container { border: 0; }
.auth-card .text-center.mb-8 { margin-bottom: 2rem; }
.auth-card .form-group { margin-bottom: 1.5rem; }
.auth-footer { margin-top: 1.75rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.modal-content { border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-lg); }
.modal-title { padding-right: 2rem; letter-spacing: -0.025em; }

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .btn:hover:not(:disabled) { transform: translateY(-1px); }
  .btn:active:not(:disabled) { transform: translateY(1px); }
  .stat-card[onclick]:hover, .stat-card[role="button"]:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
}

@media (max-width: 980px) {
  .dashboard-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 768px) {
  .main-content { padding-inline: 1rem; }
  .page-header { margin-bottom: 1.25rem; }
  .card { padding: 1.125rem; border-radius: 0; }
  .stat-card { padding: 1.125rem; }
  .input { font-size: 16px; }
  .modal-content { padding-inline: 1rem; }
  .modal-footer .btn { flex: 1 1 100%; }
  .auth-page { padding-inline: 1rem; }
  .screen-toolbar { gap: 1rem; }
  .screen-toolbar-actions, .screen-toolbar-filters { width: 100%; }
  .screen-toolbar-filters .filter-field { flex-basis: 100%; }
  .screen-toolbar-actions > .btn { flex: 1 1 auto; }
  .stat-card { min-height: 116px; }
  .page-header { padding-bottom: 1rem; }
  .auth-card { border-radius: 0 0 var(--r-md) var(--r-md); }
}
