/* ═══════════════════════════════════════════════════════════════════════════
   CRM Appollon — feuille de style de l'application.

   Aucune dépendance externe (pas de CDN, pas de build) : servie par whitenoise,
   fonctionne hors-ligne sur le VPS. Thème clair/sombre : le système décide par
   défaut, l'utilisateur peut forcer via [data-theme] (persisté en localStorage).
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Jetons de design ─────────────────────────────────────────────────────── */
:root {
  /* Neutres — ardoise légèrement chaude */
  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #f1f3f6;
  --surface-hover: #eaeef3;
  --border:        #dde2e9;
  --border-strong: #c3ccd8;
  --text:          #161d26;
  --text-muted:    #5c6a7a;
  --text-faint:    #8a97a6;

  /* Accent — l'or d'Apollon */
  --accent:        #b7791f;
  --accent-hover:  #96610f;
  --accent-soft:   #fdf5e6;
  --accent-border: #ecd9ae;

  /* Sémantique */
  --ok:      #1b7f4d;  --ok-soft:      #e6f4ec;  --ok-border:      #b4dfc7;
  --warn:    #a86400;  --warn-soft:    #fdf1e0;  --warn-border:    #f0d3a6;
  --danger:  #b42318;  --danger-soft:  #fdeceb;  --danger-border:  #f3c2be;
  --info:    #175cd3;  --info-soft:    #eaf1fd;  --info-border:    #bcd3f7;

  /* Barre latérale — toujours sombre, dans les deux thèmes (ancre visuelle) */
  --nav-bg:       #10151c;
  --nav-bg-2:     #1a212b;
  --nav-text:     #b9c3d0;
  --nav-text-dim: #6f7d8e;
  --nav-active:   #f0b856;

  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 1px 2px rgba(16, 21, 28, .06), 0 4px 12px rgba(16, 21, 28, .05);
  --shadow-lg: 0 8px 32px rgba(16, 21, 28, .16);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-w: 236px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0d1117;
    --surface:       #161b22;
    --surface-2:     #1c232c;
    --surface-hover: #222b36;
    --border:        #2a323d;
    --border-strong: #3d4753;
    --text:          #e6edf3;
    --text-muted:    #9aa7b4;
    --text-faint:    #6e7b8a;

    --accent:        #e0a942;
    --accent-hover:  #f0bd60;
    --accent-soft:   #2a2011;
    --accent-border: #4d3c19;

    --ok:      #4ec98a;  --ok-soft:      #10251a;  --ok-border:      #1f4b34;
    --warn:    #e0a942;  --warn-soft:    #2a2011;  --warn-border:    #4d3c19;
    --danger:  #f97066;  --danger-soft:  #2c1614;  --danger-border:  #5b2620;
    --info:    #6ba6f5;  --info-soft:    #101e33;  --info-border:    #1d3a63;

    --nav-bg:   #0a0e13;
    --nav-bg-2: #131920;

    --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, .55);
  }
}

:root[data-theme="dark"] {
  --bg:            #0d1117;
  --surface:       #161b22;
  --surface-2:     #1c232c;
  --surface-hover: #222b36;
  --border:        #2a323d;
  --border-strong: #3d4753;
  --text:          #e6edf3;
  --text-muted:    #9aa7b4;
  --text-faint:    #6e7b8a;

  --accent:        #e0a942;
  --accent-hover:  #f0bd60;
  --accent-soft:   #2a2011;
  --accent-border: #4d3c19;

  --ok:      #4ec98a;  --ok-soft:      #10251a;  --ok-border:      #1f4b34;
  --warn:    #e0a942;  --warn-soft:    #2a2011;  --warn-border:    #4d3c19;
  --danger:  #f97066;  --danger-soft:  #2c1614;  --danger-border:  #5b2620;
  --info:    #6ba6f5;  --info-soft:    #101e33;  --info-border:    #1d3a63;

  --nav-bg:   #0a0e13;
  --nav-bg-2: #131920;

  --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, .55);
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

code, pre, .mono { font-family: var(--mono); font-size: .92em; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

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

.nav {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(255, 255, 255, .06);
}

.nav__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.nav__mark {
  width: 30px; height: 30px;
  flex: 0 0 30px;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--nav-active), #b7791f);
  color: #10151c;
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px;
}
.nav__title { color: #fff; font-weight: 650; font-size: 14.5px; letter-spacing: .01em; }
.nav__sub { color: var(--nav-text-dim); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }

.nav__menu { flex: 1; overflow-y: auto; padding: 12px 10px; }
.nav__group {
  color: var(--nav-text-dim);
  font-size: 10.5px; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase;
  padding: 14px 10px 6px;
}
.nav__link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  margin-bottom: 1px;
  border-radius: var(--radius-sm);
  color: var(--nav-text);
  font-size: 13.5px;
  transition: background .12s, color .12s;
}
.nav__link:hover { background: var(--nav-bg-2); color: #fff; text-decoration: none; }
.nav__link--active { background: var(--nav-bg-2); color: var(--nav-active); font-weight: 550; }
.nav__link--active .nav__icon { opacity: 1; }
.nav__icon { width: 18px; text-align: center; opacity: .75; font-size: 14px; }
.nav__count {
  margin-left: auto;
  background: rgba(255, 255, 255, .09);
  color: var(--nav-text);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px; font-weight: 600;
}
.nav__count--alert { background: var(--danger); color: #fff; }

.nav__foot {
  border-top: 1px solid rgba(255, 255, 255, .07);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
}
.nav__user { flex: 1; min-width: 0; }
.nav__user b { color: #fff; display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav__user span { color: var(--nav-text-dim); }
.nav__iconbtn {
  background: transparent; border: 1px solid rgba(255, 255, 255, .12);
  color: var(--nav-text); border-radius: var(--radius-sm);
  padding: 5px 8px; cursor: pointer; font-size: 13px; line-height: 1;
}
.nav__iconbtn:hover { background: var(--nav-bg-2); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
.topbar__titles { min-width: 0; }
.topbar__sub { color: var(--text-muted); font-size: 12.5px; margin-top: 1px; }
.topbar__actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.content { padding: 24px 28px 56px; flex: 1; }
.content--narrow { max-width: 880px; }

.navtoggle { display: none; }

/* ── Cartes ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.card__head {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card__head h2 { font-size: 13.5px; }
.card__head .spacer { margin-left: auto; }
.card__body { padding: 18px; }
.card__body--flush { padding: 0; }
.card__foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex; gap: 8px; align-items: center;
}

/* ── Tuiles de statistiques ───────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow);
  display: block;
  color: inherit;
}
a.stat:hover { text-decoration: none; border-color: var(--border-strong); }
.stat__label {
  color: var(--text-muted);
  font-size: 11px; font-weight: 650;
  letter-spacing: .06em; text-transform: uppercase;
  display: flex; align-items: center; gap: 6px;
}
.stat__value { font-size: 27px; font-weight: 680; letter-spacing: -.02em; margin-top: 6px; }
.stat__hint { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.stat--ok     .stat__value { color: var(--ok); }
.stat--warn   .stat__value { color: var(--warn); }
.stat--danger .stat__value { color: var(--danger); }

/* ── Tableaux ─────────────────────────────────────────────────────────────── */
.tablewrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th {
  text-align: left;
  padding: 10px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  white-space: nowrap;
}
table.grid td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover { background: var(--surface-hover); }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.actions { text-align: right; white-space: nowrap; }
.t-strong { font-weight: 600; }
.t-muted { color: var(--text-muted); }
.t-faint { color: var(--text-faint); }
.t-right { text-align: right; }
.t-nowrap { white-space: nowrap; }

.empty { padding: 44px 20px; text-align: center; color: var(--text-muted); }
.empty__icon { font-size: 30px; opacity: .5; display: block; margin-bottom: 10px; }
.empty h3 { margin-bottom: 4px; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge--ok     { background: var(--ok-soft);     color: var(--ok);     border-color: var(--ok-border); }
.badge--warn   { background: var(--warn-soft);   color: var(--warn);   border-color: var(--warn-border); }
.badge--danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.badge--info   { background: var(--info-soft);   color: var(--info);   border-color: var(--info-border); }
.badge--accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }
.badge--muted  { background: var(--surface-2);   color: var(--text-muted); border-color: var(--border); }

/* ── Boutons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 550;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn--danger { color: var(--danger); border-color: var(--danger-border); background: var(--danger-soft); }
.btn--danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn--sm { padding: 4px 9px; font-size: 12px; }
.btn--block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Formulaires ──────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-size: 12.5px; font-weight: 600;
  margin-bottom: 5px;
  color: var(--text);
}
.field__help { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.field__error { color: var(--danger); font-size: 12px; margin-top: 4px; font-weight: 550; }
.field--check { display: flex; align-items: flex-start; gap: 8px; }
.field--check > label { margin: 0; font-weight: 500; }
.field--check input { margin-top: 3px; }

input[type="text"], input[type="email"], input[type="url"], input[type="number"],
input[type="password"], input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit; font-size: 13.5px;
}
textarea { min-height: 84px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: right 14px center, right 9px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

.formgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 18px; }
.formgrid .span2 { grid-column: 1 / -1; }
fieldset { border: none; margin: 0 0 8px; padding: 0; }
fieldset > legend {
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-muted); padding: 0 0 10px;
}

/* Barre de filtres */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.filters .field { margin: 0; }
.filters input, .filters select { min-width: 150px; }
.filters .grow { flex: 1; min-width: 200px; }

/* ── Messages ─────────────────────────────────────────────────────────────── */
.msgs { margin-bottom: 18px; display: flex; flex-direction: column; gap: 10px; }
.msg {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13.5px;
}
.msg--success { background: var(--ok-soft);     border-color: var(--ok-border);     border-left-color: var(--ok); }
.msg--warning { background: var(--warn-soft);   border-color: var(--warn-border);   border-left-color: var(--warn); }
.msg--error   { background: var(--danger-soft); border-color: var(--danger-border); border-left-color: var(--danger); }
.msg--info    { background: var(--info-soft);   border-color: var(--info-border);   border-left-color: var(--info); }

/* ── Liste de définitions (fiches) ────────────────────────────────────────── */
.dl { display: grid; grid-template-columns: minmax(130px, auto) 1fr; gap: 9px 18px; font-size: 13.5px; }
.dl dt { color: var(--text-muted); font-weight: 550; }
.dl dd { margin: 0; overflow-wrap: anywhere; }

/* ── Secrets copiables ────────────────────────────────────────────────────── */
.secret {
  display: flex; align-items: stretch; gap: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.secret code {
  flex: 1; min-width: 0;
  padding: 7px 11px;
  overflow-x: auto; white-space: nowrap;
  font-size: 12.5px;
}
/* Masqué : pas de barre de défilement sous une rangée de points. */
.secret code.masked { letter-spacing: .12em; overflow: hidden; text-overflow: clip; }
.secret button {
  flex: 0 0 auto;
  border: none; border-left: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  padding: 0 11px; cursor: pointer; font-size: 13px;
}
.secret button:hover { background: var(--surface-hover); color: var(--text); }

.codeblock {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.codeblock pre {
  margin: 0; padding: 14px 16px;
  overflow-x: auto;
  font-size: 12.5px; line-height: 1.6;
  color: var(--text);
  white-space: pre;
}
.codeblock__copy { position: absolute; top: 8px; right: 8px; }

/* ── Grille de fiche (2 colonnes) ─────────────────────────────────────────── */
.cols { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
.cols > * { min-width: 0; }

/* ── Barre de progression (agents licenciés) ──────────────────────────────── */
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; margin-top: 6px; }
.meter__fill { height: 100%; background: var(--accent); }
.meter__fill--full { background: var(--danger); }

/* ── Étapes de génération du kit ──────────────────────────────────────────── */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.steps li { display: flex; gap: 9px; align-items: flex-start; font-size: 13.5px; }
.steps li .mark { flex: 0 0 auto; }

/* ── Page de connexion ────────────────────────────────────────────────────── */
.loginpage {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(1000px 500px at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}
.loginbox { width: 100%; max-width: 384px; }
.loginbox__brand { text-align: center; margin-bottom: 22px; }
.loginbox__mark {
  width: 46px; height: 46px; margin: 0 auto 12px;
  border-radius: 12px;
  background: linear-gradient(140deg, #f0b856, #b7791f);
  color: #10151c;
  display: grid; place-items: center;
  font-weight: 800; font-size: 21px;
}

/* ── Utilitaires ──────────────────────────────────────────────────────────── */
.stack   { display: flex; flex-direction: column; gap: 14px; }
.row     { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread  { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.hr { height: 1px; background: var(--border); border: none; margin: 16px 0; }
.small { font-size: 12.5px; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1000px) { .cols { grid-template-columns: 1fr; } }

@media (max-width: 780px) {
  .navtoggle { display: inline-flex; }
  .nav {
    position: fixed; z-index: 60; left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .nav.open { transform: none; }
  .content { padding: 18px 16px 48px; }
  .topbar { padding: 13px 16px; }
  h1 { font-size: 19px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
}

@media print {
  .nav, .topbar__actions, .btn { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
