:root {
  --unaf-primary: #005391;
  --unaf-accent: #b2302c;
  --unaf-light: #e8f1f8;
  --sidebar-width: 240px;
  --topbar-height: 64px;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Raleway', Arial, sans-serif;
  font-size: 15px;
  color: #333;
  background: #f4f6fa;
}

/* ---- Layout ---- */
.layout { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--unaf-primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.sidebar-logo { height: 40px; width: auto; background: #fff; padding: 4px 6px; border-radius: 6px; }

.sidebar-title { font-size: 16px; font-weight: 700; letter-spacing: 0.5px; }

.sidebar-menu {
  list-style: none;
  flex: 1;
  padding: 12px 0;
}

.sidebar-menu li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: rgba(255,255,255,0.82);
  text-decoration: none;
  font-size: 14px;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}

.sidebar-menu li a:hover,
.sidebar-menu li.active a {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border-left-color: #fff;
}

.sidebar-menu li a i { width: 18px; text-align: center; }

/* ---- Sidebar section titles ---- */
.sidebar-section-title {
  padding: 14px 20px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.4);
  pointer-events: none;
}

/* ---- Form builder ---- */
.field-card {
  background: #fff;
  border: 2px solid #e8ecf0;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: border-color var(--transition);
}
.field-card:hover { border-color: var(--unaf-primary); }
.field-card .field-drag { cursor: move; color: #bbb; padding-top: 4px; }
.field-card .field-body { flex: 1; display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: start; }
.field-card .field-remove { color: var(--unaf-accent); cursor: pointer; background: none; border: none; font-size: 16px; padding: 4px; }
.field-card .field-remove:hover { color: #8a1f1c; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: rgba(255,255,255,0.8);
}

.logout-btn { color: rgba(255,255,255,0.7); text-decoration: none; font-size: 16px; }
.logout-btn:hover { color: #fff; }

/* ---- Main ---- */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: #fff;
  height: var(--topbar-height);
  padding: 0 24px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #e8ecf0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.page-title { font-size: 20px; font-weight: 700; color: var(--unaf-primary); }

.content-area { padding: 24px; flex: 1; }

/* ---- Cards ---- */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--unaf-light);
}

.card-title { font-size: 16px; font-weight: 700; color: var(--unaf-primary); }

/* ---- Stats cards ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }

.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 50px; height: 50px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  color: #fff;
}

.stat-icon.blue { background: var(--unaf-primary); }
.stat-icon.red  { background: var(--unaf-accent); }
.stat-icon.green { background: #4caf50; }
.stat-icon.orange { background: #ff9800; }

.stat-value { font-size: 28px; font-weight: 700; color: #222; line-height: 1; }
.stat-label { font-size: 12px; color: #888; margin-top: 4px; }

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: #555; margin-bottom: 6px; }

.form-control, textarea.form-control, select.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #e8ecf0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--transition);
  background: #fff;
}

.form-control:focus {
  outline: none;
  border-color: var(--unaf-primary);
}

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

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary { background: var(--unaf-primary); color: #fff; }
.btn-primary:hover { background: #004070; }

.btn-danger { background: var(--unaf-accent); color: #fff; }
.btn-danger:hover { background: #8a1f1c; }

.btn-secondary { background: #6c757d; color: #fff; }
.btn-secondary:hover { background: #545b62; }

.btn-success { background: #4caf50; color: #fff; }
.btn-success:hover { background: #388e3c; }

.btn-info { background: #1976d2; color: #fff; }
.btn-info:hover { background: #115293; }

.btn-warning { background: #ef6c00; color: #fff; }
.btn-warning:hover { background: #c75800; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { padding: 7px 10px; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { background: var(--unaf-light); color: var(--unaf-primary); font-size: 12px; font-weight: 700;
     text-transform: uppercase; padding: 12px 14px; text-align: left; }
td { padding: 12px 14px; border-bottom: 1px solid #f0f0f0; font-size: 14px; }
tr:hover td { background: #fafbfc; }

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.badge-success { background: #e8f5e9; color: #2e7d32; }
.badge-danger  { background: #ffebee; color: #c62828; }
.badge-warning { background: #fff8e1; color: #ef6c00; }
.badge-info    { background: var(--unaf-light); color: var(--unaf-primary); }

/* ---- Alerts ---- */
.alert {
  padding: 14px 20px;
  border-radius: var(--radius);
  margin: 16px 24px;
  font-size: 14px;
}
.alert-success { background: #e8f5e9; color: #2e7d32; border-left: 4px solid #4caf50; }
.alert-error   { background: #ffebee; color: #c62828; border-left: 4px solid #b2302c; }
.alert-warning { background: #fff8e1; color: #ef6c00; border-left: 4px solid #ff9800; }

/* ---- Color picker preview ---- */
.color-row { display: flex; align-items: center; gap: 12px; }
.color-preview { width: 36px; height: 36px; border-radius: 6px; border: 2px solid #ddd; }

/* ---- Toggle / Switch ---- */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: #ccc; border-radius: 24px; cursor: pointer;
  transition: background var(--transition);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: #fff; border-radius: 50%;
  transition: transform var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--unaf-primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ---- Drag handle ---- */
.drag-handle { cursor: move; color: #ccc; font-size: 18px; }
.drag-handle:hover { color: #888; }

/* ---- Upload zone ---- */
.upload-zone {
  border: 2px dashed var(--unaf-primary);
  border-radius: var(--radius);
  padding: 30px;
  text-align: center;
  color: var(--unaf-primary);
  cursor: pointer;
  transition: background var(--transition);
}
.upload-zone:hover { background: var(--unaf-light); }
.upload-zone input[type="file"] { display: none; }

/* ---- Checksum display ---- */
.checksum {
  font-family: monospace;
  font-size: 11px;
  color: #888;
  word-break: break-all;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-title, .sidebar-menu li a span, .sidebar-footer span { display: none; }
  .main-content { margin-left: 60px; }
}

/* ---- Login page ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #005391 0%, #003a6e 100%);
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  text-align: center;
}

.login-logo { height: 60px; margin-bottom: 20px; }
.login-title { font-size: 22px; font-weight: 700; color: var(--unaf-primary); margin-bottom: 6px; }
.login-subtitle { font-size: 13px; color: #888; margin-bottom: 28px; }

/* ============================================================
   MODE SOMBRE (suit la préférence système de l'OS / navigateur)
   ------------------------------------------------------------
   Problème signalé : en mode sombre, les <select> et la valeur choisie
   étaient illisibles. Cause : la page imposait des fonds blancs aux champs
   mais la liste déroulante native du <select> suivait la palette sombre de
   l'OS -> texte sombre sur fond sombre. Correctif : on déclare une vraie
   palette sombre cohérente ET on aligne color-scheme pour que la liste
   d'options native soit rendue en sombre lisible.
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;            /* options natives du <select> en sombre lisible */
    --unaf-light: #14304a;         /* fond clair de marque -> variante sombre */
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  }

  body {
    color: #f1f5f9;                /* texte quasi blanc, ratio > 12:1 */
    background: #0a1421;           /* fond global très sombre */
  }

  /* ---- Surfaces ---- */
  .topbar { background: #14253a; border-bottom-color: #29445f; box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
  .card, .stat-card { background: #16293e; box-shadow: var(--shadow); }
  .field-card { background: #16293e; border-color: #29445f; }

  /* ---- Textes secondaires : remontés au-dessus du seuil AA (>= 4.5:1) ---- */
  .stat-value { color: #f1f5f9; }
  .stat-label, .login-subtitle { color: #aebfd0; }
  .form-group label { color: #cdd9e5; }
  .checksum { color: #9fb0c2; }

  /* ---- CHAMPS DE FORMULAIRE + SELECTS (point critique) ---- */
  .form-control,
  textarea.form-control,
  select.form-control,
  input[type="text"], input[type="email"], input[type="password"],
  input[type="url"], input[type="number"], input[type="date"],
  input[type="search"], textarea, select {
    background: #1c3047;           /* fond du champ : surface élevée */
    color: #f1f5f9;                /* valeur saisie / choisie : claire et lisible */
    border-color: #34516e;
  }
  .form-control::placeholder,
  input::placeholder, textarea::placeholder { color: #8aa0b5; }

  .form-control:focus,
  select.form-control:focus,
  select:focus, input:focus, textarea:focus {
    border-color: #4a90d9;         /* focus bleu clair bien visible */
  }

  /* Les <option> de la liste déroulante : fond sombre + texte clair explicites
     (certains navigateurs ne suivent pas color-scheme pour les <option>). */
  select.form-control option,
  select option {
    background: #1c3047;
    color: #f1f5f9;
  }

  /* ---- Tableaux ---- */
  th { background: #14304a; color: #cfe2f5; }
  td { color: #e2e9f0; border-bottom-color: #243a52; }
  tr:hover td { background: #1b3148; }

  /* ---- Badges & alertes : on assombrit le fond, on éclaircit le texte ---- */
  .badge-success { background: #14361c; color: #7ee0a0; }
  .badge-danger  { background: #3a1518; color: #ff9ba3; }
  .badge-warning { background: #3a2c0f; color: #ffce7a; }
  .badge-info    { background: #14304a; color: #8fc4f5; }
  .alert-success { background: #14361c; color: #9be7b6; }
  .alert-error   { background: #3a1518; color: #ffb0b6; }
  .alert-warning { background: #3a2c0f; color: #ffd791; }

  /* ---- Divers ---- */
  .color-preview { border-color: #34516e; }
  .upload-zone:hover { background: #14304a; }
  .toggle-slider { background: #4a5b6e; }

  /* ---- Focus clavier visible partout (accessibilité) ---- */
  a:focus-visible, button:focus-visible, .btn:focus-visible,
  input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid #7cc0ff;
    outline-offset: 2px;
  }
}

/* ---- Focus clavier visible aussi en mode clair (accessibilité) ---- */
a:focus-visible, button:focus-visible, .btn:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--unaf-primary);
  outline-offset: 2px;
}

/* ---- Cibles tactiles >= 44px pour les boutons d'action (accessibilité) ---- */
.btn { min-height: 44px; }
.btn-sm, .btn-icon { min-height: 36px; }   /* actions secondaires en tableau */
