/* app.css — socle visuel unique du dashboard text-generator-ww.
   Spec designer UX/UI 2026-07-08 : « salle de contrôle calme » — mode sombre
   unique (color-scheme: dark), accent indigo, sémantiques type Primer dark.
   Zéro dépendance externe (pas de police web, pas de framework), zéro JS.
   Partagé par _base.html.j2 ET login.html.j2 (fin de la duplication). */

:root {
  color-scheme: dark;

  /* Fonds */
  --bg: #0e1116;            /* fond de page */
  --surface: #161b23;       /* cartes, tableaux */
  --surface-2: #1d2430;     /* thead, hover, inputs */
  --border: #2a3241;
  --border-strong: #3b4557;

  /* Texte */
  --text: #e6e9ef;
  --text-muted: #8b93a3;    /* ≈ 5.6:1 sur --bg : AA ok */
  --text-faint: #6e7681;    /* décor uniquement */

  /* Accent (marque) */
  --accent: #7c96ff;
  --accent-hover: #93a9ff;
  --accent-ink: #0b0e14;    /* texte SUR bouton accent */

  /* Sémantiques */
  --ok: #3fb950;   --ok-bg: rgba(63,185,80,.13);
  --ko: #f85149;   --ko-bg: rgba(248,81,73,.13);
  --warn: #d29922; --warn-bg: rgba(210,153,34,.13);
  --info: #58a6ff; --info-bg: rgba(88,166,255,.13);

  /* Statuts pipeline */
  --st-pending: #8b93a3;
  --st-titled: #58a6ff;
  --st-written: #a371f7;
  --st-illustrated: #39c5cf;
  --st-publishing: #d29922;
  --st-published: #3fb950;
  --st-failed: #f85149;
  --st-archived: #6e7681;

  /* Modes site */
  --mode-live: var(--ok);
  --mode-draft: var(--warn);
  --mode-off: var(--ko);

  /* Typo / rythme */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --fs-body: .9rem;
  --fs-small: .8rem;
  --fs-h1: 1.25rem;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-pill: 999px;
  --shadow: 0 1px 3px rgba(0,0,0,.35);
  --gap: 1rem;
  --pad-card: 1rem 1.15rem;
  --transition: 120ms ease;
}

/* ---------------------------------------------------------------------------
   Socle
--------------------------------------------------------------------------- */
* { box-sizing: border-box; }
body { font-family: var(--font); font-size: var(--fs-body); line-height: 1.45;
       margin: 0; background: var(--bg); color: var(--text); }
main { padding: 1.25rem 1.5rem 3rem; max-width: 1440px; margin: 0 auto; }
h1 { font-size: var(--fs-h1); font-weight: 650; margin: 0 0 .25rem; letter-spacing: -.01em; }
/* h2 = étiquette de section */
h2 { font-size: .75rem; font-weight: 600; text-transform: uppercase;
     letter-spacing: .07em; color: var(--text-muted); margin: 1.8rem 0 .5rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.muted { color: var(--text-muted); font-size: var(--fs-small); }
.hint { color: var(--text-muted); font-size: var(--fs-small); }
.ok { color: var(--ok); }
.ko { color: var(--ko); font-weight: 600; }
code { font-family: var(--mono); font-size: .85em; background: var(--surface-2);
       padding: .1em .35em; border-radius: 4px; }
form.inline { display: inline; }

/* ---------------------------------------------------------------------------
   Topbar
--------------------------------------------------------------------------- */
.topnav { position: sticky; top: 0; z-index: 10; display: flex; align-items: center;
  gap: .25rem; padding: 0 1.5rem; height: 52px; background: var(--surface);
  border-bottom: 1px solid var(--border); }
.topnav .brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; margin-right: 1rem; }
.mark { width: 24px; height: 24px; border-radius: 6px; background: var(--accent);
  color: var(--accent-ink); display: grid; place-items: center;
  font-size: .7rem; font-weight: 800; }
.topnav a { color: var(--text-muted); text-decoration: none; padding: .3rem .65rem;
  border-radius: var(--radius-sm); transition: background var(--transition), color var(--transition); }
.topnav a:hover { background: var(--surface-2); color: var(--text); }
.topnav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.topnav .who { margin-left: auto; color: var(--text-muted); font-size: var(--fs-small);
  display: flex; align-items: center; gap: .45rem; white-space: nowrap; }
.topnav .who strong { color: var(--text); }

/* ---------------------------------------------------------------------------
   Cartes KPI
--------------------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
        gap: var(--gap); margin: 1rem 0 .5rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
       padding: var(--pad-card); box-shadow: var(--shadow); display: flex;
       flex-direction: column; gap: .15rem; }
.kpi-label { font-size: .72rem; font-weight: 600; text-transform: uppercase;
             letter-spacing: .06em; color: var(--text-muted); }
.kpi-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi-value small { font-size: .85rem; font-weight: 400; color: var(--text-muted); }
.kpi-sub { font-size: var(--fs-small); color: var(--text-muted); }
.kpi-alert { border-color: var(--ko); background: linear-gradient(var(--ko-bg), var(--ko-bg)) var(--surface); }
.kpi-alert .kpi-value { color: var(--ko); }
.kpi form { margin-top: .5rem; }
.meter { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: .45rem; }
.meter span { display: block; height: 100%; background: var(--ok); border-radius: 3px;
              transition: width var(--transition); }
.meter span.warn { background: var(--warn); }
.meter span.ko { background: var(--ko); }

/* ---------------------------------------------------------------------------
   Pastille orchestrateur
--------------------------------------------------------------------------- */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%;
       vertical-align: baseline; margin-right: .15rem; }
.dot.run { background: var(--ok); animation: pulse 2s ease-in-out infinite; }
.dot.pause { background: var(--warn); }
.dot.stop { background: var(--ko); }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(63,185,80,.18); } }
@media (prefers-reduced-motion: reduce) { .dot.run { animation: none; } }

/* ---------------------------------------------------------------------------
   Pills — statuts pipeline & modes site
--------------------------------------------------------------------------- */
.pill { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem;
        border-radius: var(--radius-pill); font-size: .75rem; font-weight: 500;
        border: 1px solid transparent; white-space: nowrap; margin: .1rem .25rem .1rem 0; }
.pill b { font-variant-numeric: tabular-nums; }
.st-pending     { color: var(--st-pending);     background: rgba(139,147,163,.13); border-color: rgba(139,147,163,.35); }
.st-titled      { color: var(--st-titled);      background: rgba(88,166,255,.13);  border-color: rgba(88,166,255,.35); }
.st-written     { color: var(--st-written);     background: rgba(163,113,247,.13); border-color: rgba(163,113,247,.35); }
.st-illustrated { color: var(--st-illustrated); background: rgba(57,197,207,.13);  border-color: rgba(57,197,207,.35); }
.st-publishing  { color: var(--st-publishing);  background: rgba(210,153,34,.13);  border-color: rgba(210,153,34,.35); }
.st-published   { color: var(--st-published);   background: rgba(63,185,80,.13);   border-color: rgba(63,185,80,.35); }
.st-failed      { color: var(--st-failed);      background: rgba(248,81,73,.13);   border-color: rgba(248,81,73,.35); }
.st-archived    { color: var(--st-archived);    background: rgba(110,118,129,.10); border-color: rgba(110,118,129,.30); }
.mode-live  { color: var(--mode-live);  background: var(--ok-bg);   border-color: rgba(63,185,80,.4); }
.mode-draft { color: var(--mode-draft); background: var(--warn-bg); border-color: rgba(210,153,34,.4); }
.mode-off, .mode-inactive { color: var(--mode-off); background: var(--ko-bg); border-color: rgba(248,81,73,.4); }

/* ---------------------------------------------------------------------------
   Tableaux
--------------------------------------------------------------------------- */
.table-card { background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: var(--fs-body); }
th, td { padding: .5rem .75rem; text-align: left; vertical-align: top;
         border-bottom: 1px solid var(--border); }
thead th { background: var(--surface-2); font-size: .72rem; text-transform: uppercase;
           letter-spacing: .05em; color: var(--text-muted); position: sticky; top: 0;
           white-space: nowrap; /* pas de « PUBLIÉS 24 / H » coupé — le table-card scrolle */ }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-2); }

/* Colonne « Derniers échecs » : étape en mini-pill, raison ellipsée (title=). */
.fail { margin-bottom: .3rem; }
.fail .reason { display: block; color: var(--text-muted); font-size: var(--fs-small);
                max-width: 26ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Sections repliables (jobs du scheduler, pool de maillage) */
details { margin-top: 1.8rem; }
summary { cursor: pointer; font-size: .75rem; font-weight: 600; text-transform: uppercase;
          letter-spacing: .07em; color: var(--text-muted); }
summary:hover { color: var(--text); }
details .table-card { margin-top: .5rem; }

/* ---------------------------------------------------------------------------
   Boutons
--------------------------------------------------------------------------- */
button, .btn { font: inherit; font-weight: 500; padding: .4rem .85rem; min-height: 32px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); cursor: pointer;
  transition: background var(--transition), border-color var(--transition); }
button:hover, .btn:hover { background: var(--border); }
.btn { display: inline-flex; align-items: center; justify-content: center;
       text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: transparent; border-color: var(--ko); color: var(--ko); }
.btn-danger:hover { background: var(--ko-bg); }

/* ---------------------------------------------------------------------------
   Toggle on/off (checkbox réelle habillée — aucun JS)
--------------------------------------------------------------------------- */
.switch { appearance: none; width: 36px; height: 20px; border-radius: 10px;
  background: var(--border-strong); position: relative; cursor: pointer;
  transition: background var(--transition); vertical-align: middle;
  margin: 0; padding: 0; min-height: 0; border: none; flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--text); transition: transform var(--transition); }
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(16px); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------------------
   Formulaires
--------------------------------------------------------------------------- */
fieldset { background: var(--surface); border: 1px solid var(--border);
           border-radius: var(--radius); padding: 1rem 1.15rem; margin-top: 1rem; }
legend { font-weight: 600; font-size: .85rem; padding: 0 .4rem; }
input, select, textarea { font: inherit; padding: .4rem .6rem; min-height: 32px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); transition: border-color var(--transition); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
input[readonly] { opacity: .6; }
textarea { min-height: 5.5rem; }
textarea.prompt { width: 100%; max-width: 70rem; min-height: 28rem;
                  font-family: var(--mono); font-size: .85rem; }
input.val { width: 6.5rem; }

/* Grille des fiches site (dans les fieldsets thématiques) */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .6rem 1.2rem; }
.grid label { display: flex; flex-direction: column; gap: .15rem; font-size: var(--fs-body); }
.grid label.check { flex-direction: row; align-items: center; gap: .5rem; }
.grid .full { grid-column: 1 / -1; }
fieldset.themed { max-width: 62rem; }

/* ---------------------------------------------------------------------------
   Login (première impression)
--------------------------------------------------------------------------- */
body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center;
  background: radial-gradient(600px 300px at 50% 30%, rgba(124,150,255,.08), transparent), var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 2rem; width: min(21rem, 90vw); box-shadow: 0 8px 30px rgba(0,0,0,.45); }
.login-card .mark { width: 40px; height: 40px; font-size: 1rem; margin: 0 auto .75rem; }
.login-card h1 { text-align: center; font-size: 1.05rem; }
.login-card input, .login-card button { width: 100%; margin-bottom: .7rem; }
.login-card .muted { text-align: center; margin: .3rem 0 0; }

/* ---------------------------------------------------------------------------
   Messages flash
--------------------------------------------------------------------------- */
.flash { padding: .55rem .9rem; border-radius: var(--radius-sm); font-size: var(--fs-body);
         border: 1px solid; margin: .8rem 0; }
.flash-ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.flash-error { background: var(--ko-bg); border-color: var(--ko); color: var(--ko); }
/* Mot de passe affiché UNE fois (bootstrap/reset) : flash ambre, code en mono. */
.onetime { padding: .55rem .9rem; border-radius: var(--radius-sm); font-size: var(--fs-body);
           border: 1px solid var(--warn); background: var(--warn-bg); color: var(--warn);
           margin: .8rem 0; }
.onetime code { font-family: var(--mono); font-size: 1.05rem; user-select: all;
                background: transparent; color: var(--text); }

/* ---------------------------------------------------------------------------
   États vides (onboarding)
--------------------------------------------------------------------------- */
.empty { text-align: center; padding: 2.5rem 1rem; border: 1px dashed var(--border-strong);
         border-radius: var(--radius); color: var(--text-muted); background: var(--surface); }
.empty .btn { margin-top: .6rem; }

/* ---------------------------------------------------------------------------
   Prévisualisation d'article (generate_test_watch) — cadre « papier » clair
--------------------------------------------------------------------------- */
.preview-frame { background: #fdfdfb; color: #1c1e21; border: 1px solid var(--border);
  border-radius: var(--radius); max-width: 42rem; padding: 2rem 2.5rem;
  line-height: 1.65; font-size: 1.02rem; margin-top: .6rem; }
.preview-frame h2 { font-size: 1.25rem; text-transform: none; letter-spacing: 0; color: inherit; }
.preview-frame a { color: #2f5cc8; }
.preview-frame img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }

/* Métadonnées de l'article de test (dl au-dessus de la préview) */
.meta dt { font-weight: 600; margin-top: .5rem; }
.meta dd { margin: 0 0 .2rem; }

/* Barre de progression indéterminée (génération en cours) */
.progress { height: 3px; background: var(--surface-2); border-radius: 2px;
            overflow: hidden; margin: .6rem 0; max-width: 42rem; }
.progress span { display: block; height: 100%; width: 35%; background: var(--accent);
                 border-radius: 2px; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
@media (prefers-reduced-motion: reduce) { .progress span { animation: none; width: 100%; } }

/* ---------------------------------------------------------------------------
   Analyse GSC (G3/G4) — SVG serveur, cellules neutralisées, rapports
--------------------------------------------------------------------------- */
/* n < 30 : la ligne est NEUTRALISÉE (aucune conclusion, SPEC-GSC §2) */
tr.low-n td { color: var(--text-faint); }
tr.low-n .pill { opacity: .55; }
/* Libellé « données provisoires » (latence de consolidation GSC) */
.pill.provisional { color: var(--warn); background: var(--warn-bg); border-color: rgba(210,153,34,.4); }
/* Cartes de graphiques SVG (sparklines / barres) — currentColor pilote la teinte */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
          gap: var(--gap); margin: .5rem 0 1rem; }
.chart { background: var(--surface); border: 1px solid var(--border);
         border-radius: var(--radius); padding: .6rem .9rem; box-shadow: var(--shadow); }
.chart svg { display: block; width: 100%; height: auto; margin-top: .3rem; }
.spark-web { color: var(--info); }
.spark-discover { color: var(--ok); }
/* Recommandations du rapport hebdo : texte multi-lignes tel quel */
.reco { white-space: pre-wrap; margin-top: .35rem; }
.report-card { margin-bottom: 1.2rem; }

/* Rapport d'étapes : timeline verticale (puce ok/ko + trait) */
.timeline { list-style: none; margin: .6rem 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 .9rem 1.4rem; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 1em; bottom: -.1em;
                       width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 0; top: .35em;
                      width: 10px; height: 10px; border-radius: 50%; background: var(--ok); }
.timeline li.ko::after { background: var(--ko); }
