/* ------------------------------------------------------------------
   Thème clair (par défaut) et thème sombre.
   L'attribut data-theme est posé sur <html> par le script de index.html
   (avant le rendu, pour éviter tout clignotement) et piloté depuis app.js.
   La préférence est propre à chaque navigateur (localStorage) : chacun a
   donc son réglage, sans besoin d'authentification.
   ------------------------------------------------------------------ */
:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #5b6472;        /* assombri : #6b7280 tombait sous le seuil AA sur --bg */
  --border: #e5e7eb;
  --primary: #2563eb;      /* fonds (boutons, filtres) : porte du texte blanc */
  --primary-ink: #ffffff;
  --accent: #2563eb;       /* texte d'accent (onglet actif) sur fond de panneau */

  --surface-alt: #f9fafb;   /* en-têtes de tableau, survol de bouton */
  --row-line: #f1f5f9;      /* séparateurs de lignes du Gantt */
  --version-bg: #e6ebf2;    /* bandeau de version */
  --version-line: #64748b;
  --event-bg: #fbfcfe;      /* lignes d'événement */
  --note-bg: #f8fafc;       /* notes des sujets */
  --toast-bg: #111827;
  --shadow: rgba(0, 0, 0, .2);

  --st-a_venir: #9ca3af;
  --st-en_cours: #2563eb;
  --st-fait: #16a34a;
  --st-livre: #0d9488;
  --st-en_retard: #dc2626;
  --st-annule: #6b7280;
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --primary: #2563eb;      /* conservé foncé : blanc dessus = contraste AA */
  --primary-ink: #ffffff;
  --accent: #93c5fd;       /* bleu clair : lisible sur panneau sombre */

  --surface-alt: #263449;
  --row-line: #263449;
  --version-bg: #273449;
  --version-line: #64748b;
  --event-bg: #1a2537;
  --note-bg: #172033;
  --toast-bg: #020617;
  --shadow: rgba(0, 0, 0, .5);

  /* Statuts : versions plus lumineuses, lisibles sur fond sombre */
  --st-a_venir: #94a3b8;
  --st-en_cours: #3b82f6;
  --st-fait: #22c55e;
  --st-livre: #14b8a6;
  --st-en_retard: #ef4444;
  --st-annule: #94a3b8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}
h1, h2, h3 { margin: 0; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 30px; }
.topbar h1 { font-size: 19px; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.topbar-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: flex-end; }
.planning-bar { display: flex; align-items: center; gap: 6px; }
.planning-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.planning-bar select { width: auto; min-width: 200px; font-weight: 600; }
.mode-badge { padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 12px; }
.mode-preview { background: #fef3c7; color: #92400e; }
.mode-send { background: #dcfce7; color: #166534; }

/* Tabs */
.tabs { display: flex; gap: 4px; padding: 0 24px; background: var(--panel); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  border: none; background: none; padding: 12px 16px; cursor: pointer;
  font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 25px 100px; }
.panel { display: none; }
.panel.active { display: block; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.panel-head h2 { font-size: 17px; }
.hint { color: var(--muted); font-size: 12.5px; margin: -6px 0 16px; }

/* Buttons */
.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.btn:hover { background: var(--surface-alt); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--st-en_retard); border-color: #fecaca; }
.btn.small { padding: 4px 9px; font-size: 12px; }

/* Cards / tables */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface-alt); font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

/* Status pill + select */
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; }
select, input[type=text], input[type=date], input[type=datetime-local], input[type=email], input[type=number], input[type=password], textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit; width: 100%;
  background: var(--panel); color: var(--ink);
}
textarea { resize: vertical; min-height: 90px; }
.status-select { width: auto; font-weight: 600; }

/* Gantt */
.gantt { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; overflow-x: auto; }
.gantt-inner { min-width: 900px; }
.gantt-header { display: flex; margin-left: 220px; border-bottom: 1px solid var(--border); position: relative; }
.gantt-month { text-align: center; font-size: 11.5px; color: var(--muted); padding: 4px 0; border-left: 1px solid var(--border); }
.gantt-row { display: flex; align-items: stretch; border-bottom: 1px solid var(--row-line); }
.gantt-row.version-head { background: var(--version-bg); border-top: 3px solid var(--version-line); margin-top: 10px; }
.gantt-body .gantt-row.version-head:first-child { margin-top: 0; }
.gantt-row.version-head .gantt-label.version { font-size: 14px; padding: 10px 12px; }
.gantt-row.event-row { background: var(--event-bg); }
.gantt-row.event-row .gantt-label { font-size: 12px; }
.gantt-label { width: 220px; flex-shrink: 0; padding: 8px 12px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.gantt-label.version { font-weight: 700; }
.gantt-track { position: relative; flex: 1; height: 30px; margin: 5px 0; }
.gantt-bar {
  position: absolute; top: 4px; height: 22px; border-radius: 6px; color: #fff;
  font-size: 11px; line-height: 22px; padding: 0 8px; overflow: hidden; white-space: nowrap;
  cursor: pointer; box-shadow: inset 0 -1px 0 rgba(0,0,0,.12);
}
.gantt-milestone { position: absolute; top: 2px; font-size: 15px; transform: translateX(-50%); cursor: pointer; }
.today-line { position: absolute; top: 0; bottom: 0; width: 2px; background: #ef4444; z-index: 5; }
.today-flag { position: absolute; top: -18px; transform: translateX(-50%); background: #ef4444; color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 4px; white-space: nowrap; }
.gantt-body { position: relative; }
.event-marker { position: absolute; font-size: 13px; transform: translateX(-50%); cursor: pointer; z-index: 4; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* Filters */
.filters { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 12.5px; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-overlay.hidden { display: none; }
.modal { background: var(--panel); border-radius: 14px; width: 560px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-close { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.checkbox-list { display: flex; flex-wrap: wrap; gap: 10px; }
.checkbox-list label { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--ink); font-weight: 500; }
.checkbox-list input { width: auto; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--toast-bg); color: #fff; padding: 11px 20px; border-radius: 10px; z-index: 60; font-size: 13px; box-shadow: 0 8px 24px var(--shadow); }
.toast.hidden { display: none; }
.toast.error { background: #991b1b; }

.muted { color: var(--muted); }
.email-body-preview { font-size: 12px; color: var(--muted); white-space: pre-wrap; max-height: 60px; overflow: hidden; }
.tag { display: inline-block; background: #eef2ff; color: #4338ca; border-radius: 6px; padding: 2px 7px; font-size: 11px; margin: 1px; }
.status-tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; font-weight: 600; }
.status-draft { background: #f3f4f6; color: #374151; }
.status-validated { background: #dbeafe; color: #1e40af; }
.status-sent { background: #dcfce7; color: #166534; }
.status-preview { background: #fef3c7; color: #92400e; }
.status-failed { background: #fee2e2; color: #991b1b; }
.status-cancelled { background: #f3f4f6; color: #9ca3af; text-decoration: line-through; }
.status-perime { background: #ede9fe; color: #5b21b6; }

/* Notes des sujets ouverts */
.note-item {
  background: var(--note-bg); border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; font-size: 13px; white-space: pre-wrap;
}

/* ------------------------------------------------------------------
   Thème sombre : pastilles et badges.
   Ces couleurs sont « sémantiques » (vert = envoyé, rouge = échec...) :
   on ne les remplace pas par des variables, on en donne une déclinaison
   sombre lisible (fond profond + texte clair).
   ------------------------------------------------------------------ */
:root[data-theme="dark"] .mode-preview  { background: #78350f; color: #fde68a; }
:root[data-theme="dark"] .mode-send     { background: #14532d; color: #bbf7d0; }

:root[data-theme="dark"] .status-draft     { background: #334155; color: #cbd5e1; }
:root[data-theme="dark"] .status-validated { background: #1e3a8a; color: #bfdbfe; }
:root[data-theme="dark"] .status-sent      { background: #14532d; color: #bbf7d0; }
:root[data-theme="dark"] .status-preview   { background: #78350f; color: #fde68a; }
:root[data-theme="dark"] .status-failed    { background: #7f1d1d; color: #fecaca; }
:root[data-theme="dark"] .status-cancelled { background: #334155; color: #7c8ba1; }
:root[data-theme="dark"] .status-perime    { background: #4c1d95; color: #ddd6fe; }

:root[data-theme="dark"] .tag           { background: #312e81; color: #c7d2fe; }
:root[data-theme="dark"] .btn.danger    { border-color: #7f1d1d; }
:root[data-theme="dark"] .toast.error   { background: #7f1d1d; }
/* Les icônes natives des champs date/heure sont noires par défaut */
:root[data-theme="dark"] input[type=date]::-webkit-calendar-picker-indicator { filter: invert(1) opacity(.7); }

/* Bouton de bascule du thème */
.theme-btn { min-width: 92px; text-align: center; }

/* ------------------------------------------------------------------
   Page de connexion (login.html)
   ------------------------------------------------------------------ */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px;
  box-shadow: 0 10px 30px var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.login-brand h1 { font-size: 19px; }
.login-card label {
  display: block; margin-bottom: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
}
.login-card input { margin-bottom: 16px; }
.login-submit { width: 100%; padding: 10px; font-size: 14px; font-weight: 600; }
.login-error {
  margin: 0 0 14px; padding: 9px 12px; border-radius: 8px; font-size: 12.5px;
  background: #fee2e2; color: #991b1b;
}
.login-error.hidden { display: none; }
.login-foot { margin: 18px 0 0; text-align: center; font-size: 12px; color: var(--muted); }

:root[data-theme="dark"] .login-error { background: #7f1d1d; color: #fecaca; }

/* Session (barre supérieure) */
.session-bar { display: flex; align-items: center; gap: 8px; }
.session-bar.hidden { display: none; }
.session-user { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ------------------------------------------------------------------
   Déploiement : couleur de ligne (mêmes teintes que les badges de statut).
   La couleur porte sur les <td> car <tr> n'accepte pas de fond fiable partout.
   ------------------------------------------------------------------ */
tr.depl-vert   td { background: #dcfce7; color: #166534; }
tr.depl-orange td { background: #fef3c7; color: #92400e; }
tr.depl-rouge  td { background: #fee2e2; color: #991b1b; }
tr.depl-vert td .muted, tr.depl-orange td .muted, tr.depl-rouge td .muted { color: inherit; opacity: .6; }

:root[data-theme="dark"] tr.depl-vert   td { background: #14532d; color: #bbf7d0; }
:root[data-theme="dark"] tr.depl-orange td { background: #78350f; color: #fde68a; }
:root[data-theme="dark"] tr.depl-rouge  td { background: #7f1d1d; color: #fecaca; }

/* En-têtes de colonnes triables (Historique déploiement) */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--ink); }

/* Barre de filtres + pagination (Historique déploiement) */
.filters-bar { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters-bar .field { flex: 0 0 auto; }
.filters-bar label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.filters-bar select, .filters-bar input { width: auto; min-width: 160px; }
.filters-bar #hf-reset { align-self: flex-end; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; }
.pager-info { font-size: 12.5px; color: var(--muted); }
.btn[disabled] { opacity: .45; cursor: default; }
:root[data-theme="dark"] input[type=datetime-local]::-webkit-calendar-picker-indicator { filter: invert(1) opacity(.7); }
