/* Feuille de style de l'admin.
   Fichier statique (et non <style> en ligne) pour que la Content-Security-Policy
   puisse interdire tout style et script en ligne. Aucune police ni ressource
   externe : pile de polices système. Thème clair/sombre selon le système. */

:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #e5e7ec;
  --line-strong: #d4d8e0;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;

  --side: #0b1220;
  --side-2: #111a2e;
  --side-ink: #c7d0de;
  --side-muted: #6b7a93;

  --accent: #0d9488;
  --accent-strong: #0f766e;
  --accent-soft: #e6f6f4;

  --ok: #15803d;      --ok-soft: #e7f6ec;
  --warn: #b45309;    --warn-soft: #fdf3e1;
  --danger: #c8322b;  --danger-soft: #fdecea;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 6px 18px -8px rgba(15, 23, 42, .08);
  --ring: 0 0 0 3px rgba(13, 148, 136, .25);

  /* Teintes de catégories : fond / texte */
  --t0-bg: #e8efff; --t0-fg: #3151c4;
  --t1-bg: #fdecea; --t1-fg: #b42318;
  --t2-bg: #fff1e0; --t2-fg: #b54708;
  --t3-bg: #e6f6f4; --t3-fg: #0f766e;
  --t4-bg: #f3ecff; --t4-fg: #6b3fc6;
  --t5-bg: #eef2f6; --t5-fg: #475467;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1a;
    --surface: #111827;
    --surface-2: #151e2f;
    --line: #232d3f;
    --line-strong: #2f3a4f;
    --ink: #e7ecf3;
    --ink-2: #c3ccd9;
    --muted: #8793a6;
    --side: #070b14;
    --side-2: #0e1524;
    --accent: #2dd4bf;
    --accent-strong: #5eead4;
    --accent-soft: rgba(45, 212, 191, .12);
    --ok: #4ade80;      --ok-soft: rgba(74, 222, 128, .12);
    --warn: #fbbf24;    --warn-soft: rgba(251, 191, 36, .12);
    --danger: #f87171;  --danger-soft: rgba(248, 113, 113, .12);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --ring: 0 0 0 3px rgba(45, 212, 191, .3);
    --t0-bg: rgba(99, 130, 255, .16); --t0-fg: #a4b7ff;
    --t1-bg: rgba(248, 113, 113, .15); --t1-fg: #fca5a5;
    --t2-bg: rgba(251, 146, 60, .15);  --t2-fg: #fdba74;
    --t3-bg: rgba(45, 212, 191, .14);  --t3-fg: #5eead4;
    --t4-bg: rgba(167, 139, 250, .16); --t4-fg: #c4b5fd;
    --t5-bg: rgba(148, 163, 184, .15); --t5-fg: #cbd5e1;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); }
code {
  font: 12.5px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}
.icon { flex: none; display: block; }

/* ---------- Structure : barre latérale + contenu ---------- */

.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
  padding: 22px 14px 16px;
  background: linear-gradient(180deg, var(--side) 0%, var(--side-2) 100%);
  color: var(--side-ink);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 22px; text-decoration: none; color: #fff; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #14b8a6 0%, #0ea5e9 100%);
  box-shadow: 0 6px 16px -6px rgba(20, 184, 166, .7);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-text small { font-weight: 500; font-size: 12px; color: var(--side-muted); letter-spacing: 0; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--side-muted); padding: 8px 10px 6px; }
.nav a, .nav-btn {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 10px; border-radius: 9px; border: 0; background: none;
  color: var(--side-ink); font: inherit; font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav a:hover, .nav-btn:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: rgba(45, 212, 191, .14); color: #fff; box-shadow: inset 3px 0 0 #2dd4bf; }
.nav a.active .icon { color: #5eead4; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--side-muted); font-variant-numeric: tabular-nums; }

.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .07); }
.sidebar-foot .who { display: flex; align-items: center; gap: 10px; padding: 6px 10px 10px; font-size: 13px; color: var(--side-muted); }
.sidebar-foot .who b { color: var(--side-ink); font-weight: 600; display: block; }

.content { padding: 34px clamp(16px, 4vw, 52px) 72px; max-width: 1280px; width: 100%; }

@media (max-width: 880px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky; z-index: 10; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
    padding: 10px 16px; gap: 8px;
  }
  .brand { padding: 0; margin-right: auto; }
  .brand-mark { width: 32px; height: 32px; }
  .brand-text small, .nav-label, .sidebar-foot .who, .nav .count { display: none; }
  .nav { order: 3; flex-direction: row; width: 100%; overflow-x: auto; }
  .nav a { width: auto; white-space: nowrap; }
  .nav a.active { box-shadow: inset 0 -2px 0 #2dd4bf; }
  /* Déconnexion sur la première ligne, à droite du logo ; la navigation passe dessous. */
  .sidebar-foot { order: 2; margin: 0; padding: 0; border: 0; width: auto; }
  .sidebar-foot .nav-btn span { display: none; }
  .content { padding-top: 22px; }
}

/* ---------- En-tête de page et indicateurs ---------- */

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { margin: 0; font-size: 28px; line-height: 1.15; letter-spacing: -.025em; }
.page-head p { margin: 6px 0 0; color: var(--muted); max-width: 62ch; }
.crumb { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); text-decoration: none; margin-bottom: 8px; }
.crumb:hover { color: var(--ink); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); }
.stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; }
.stat-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-strong); }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -.03em; margin-top: 6px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-value small { font-size: 15px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.stat-hint { font-size: 13px; color: var(--muted); margin-top: 2px; }
.stat.is-alert .stat-icon { background: var(--danger-soft); color: var(--danger); }
.stat.is-alert .stat-value { color: var(--danger); }
.stat.is-ok .stat-icon { background: var(--ok-soft); color: var(--ok); }

/* ---------- Panneaux et tableaux ---------- */

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel + .panel, .panel + details, details + .panel { margin-top: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 15.5px; letter-spacing: -.01em; }
.panel-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.panel-body { padding: 20px; }
.panel.danger-zone { border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }
.panel.danger-zone .panel-body { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; white-space: nowrap; padding: 10px 14px;
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tr.is-off .fade { opacity: .5; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions-cell { text-align: right; white-space: nowrap; }

.cell-main { display: flex; align-items: center; gap: 12px; min-width: 220px; }
/* URL sur une ligne, tronquée : le tableau des sources tient sans défilement horizontal. */
.cell-sub.url { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 210px; }
.pill.mini { padding: 0 7px; font-size: 11px; margin-left: 4px; vertical-align: 1px; }
.cell-main > div { min-width: 0; }
.cell-title { font-weight: 600; color: var(--ink); }
.cell-sub { font-size: 12.5px; color: var(--muted); word-break: break-all; max-width: 440px; }
.favicon {
  width: 34px; height: 34px; border-radius: 9px; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; text-transform: uppercase;
}

.big-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.sub-num { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }

.error-line {
  display: inline-flex; align-items: flex-start; gap: 6px; margin-top: 6px; max-width: 280px;
  font-size: 12.5px; line-height: 1.4; color: var(--danger); background: var(--danger-soft);
  padding: 4px 9px; border-radius: 7px; word-break: break-word;
}
.error-line .icon { margin-top: 1px; }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty .icon { margin: 0 auto 10px; opacity: .6; }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

/* ---------- Pastilles ---------- */

.pill {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.4;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.pill .icon { width: 13px; height: 13px; }
.pill.rss { background: #fff4e8; color: #c2410c; border-color: #fcdcbc; }
.pill.scraping { background: #f3efff; color: #6d28d9; border-color: #e0d6fe; }
@media (prefers-color-scheme: dark) {
  .pill.rss { background: rgba(251, 146, 60, .12); color: #fdba74; border-color: rgba(251, 146, 60, .25); }
  .pill.scraping { background: rgba(167, 139, 250, .12); color: #c4b5fd; border-color: rgba(167, 139, 250, .25); }
}
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.off { background: var(--surface-2); color: var(--muted); }
.pill.err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

.cat { border-color: transparent; }
.t0 { background: var(--t0-bg); color: var(--t0-fg); }
.t1 { background: var(--t1-bg); color: var(--t1-fg); }
.t2 { background: var(--t2-bg); color: var(--t2-fg); }
.t3 { background: var(--t3-bg); color: var(--t3-fg); }
.t4 { background: var(--t4-bg); color: var(--t4-fg); }
.t5 { background: var(--t5-bg); color: var(--t5-fg); }

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-size: 14px; font-weight: 600; line-height: 1.2; text-decoration: none; white-space: nowrap;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(13, 148, 136, .3); }
.btn-primary:hover { background: var(--accent-strong); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #04201d; } }
.btn-ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-icon { padding: 7px; }

/* Interrupteur actif/inactif (bouton de formulaire, sans JavaScript) */
.switch {
  position: relative; flex: none; width: 40px; height: 23px; padding: 0; border: 0; border-radius: 999px;
  background: var(--line-strong); cursor: pointer; transition: background .18s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .18s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(17px); }
.switch:focus-visible { outline: none; box-shadow: var(--ring); }

/* Même rendu pour une case à cocher de formulaire */
input[type="checkbox"].toggle {
  appearance: none; -webkit-appearance: none; margin: 0;
  position: relative; flex: none; width: 40px; height: 23px; border-radius: 999px;
  background: var(--line-strong); cursor: pointer; transition: background .18s;
}
input[type="checkbox"].toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .18s;
}
input[type="checkbox"].toggle:checked { background: var(--accent); }
input[type="checkbox"].toggle:checked::after { transform: translateX(17px); }
input[type="checkbox"].toggle:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---------- Formulaires ---------- */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px 18px; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 560px) { .form-grid .span-2 { grid-column: auto; } }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field > small { font-size: 12.5px; color: var(--muted); }
input[type="text"], input[type="url"], input[type="email"], input[type="password"], input:not([type]), select, textarea {
  width: 100%; font: inherit; font-size: 14px; color: var(--ink);
  padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.help { font-size: 13px; color: var(--muted); margin: 14px 0 0; }

/* Panneau d'ajout repliable (<details>) */
details.adder { background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }
details.adder[open] { border-style: solid; box-shadow: var(--shadow); }
details.adder > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 15px 20px; font-weight: 600; color: var(--ink-2);
}
details.adder > summary::-webkit-details-marker { display: none; }
details.adder > summary:hover { color: var(--accent-strong); }
details.adder > summary .plus { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-strong); }
details.adder[open] > summary { border-bottom: 1px solid var(--line); }
details.adder .panel-body { padding: 20px; }

/* Contrôle segmenté (fréquence) */
.segmented { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: block; padding: 7px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }
.segmented input:focus-visible + span { box-shadow: var(--ring); }

/* Choix multiples en cartes */
.pref-block + .pref-block { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }
.pref-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.pref-head h3 { margin: 0; font-size: 15px; }
.pref-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.inline-toggle { display: inline-flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; cursor: pointer; }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; transition: opacity .2s; }
.choice {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; font-size: 14px; background: var(--surface);
  transition: border-color .15s, background .15s;
}
.choice:hover { border-color: var(--line-strong); }
.choice input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); flex: none; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice small { color: var(--muted); margin-left: auto; font-size: 12px; }
/* Quand « toutes » est coché, la liste détaillée est sans effet : on l'estompe. */
.pref-block:has(.all-toggle:checked) .choices { opacity: .4; pointer-events: none; }

/* ---------- Messages ---------- */

.flash {
  display: flex; align-items: center; gap: 10px; margin-bottom: 18px; padding: 11px 15px;
  border-radius: 11px; font-size: 14px; font-weight: 500; border: 1px solid transparent;
  animation: flash-in .25s ease-out;
}
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 20%, transparent); }
.flash.error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 20%, transparent); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------- Page de connexion ---------- */

body.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(20, 184, 166, .28), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, rgba(14, 165, 233, .22), transparent 60%),
    #0b1220;
}
.login-card {
  width: 100%; max-width: 400px; padding: 34px 32px 30px;
  background: var(--surface); border-radius: 20px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255, 255, 255, .04);
}
.login-card .brand { color: var(--ink); padding: 0 0 26px; }
.login-card .brand-text small { color: var(--muted); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.02em; }
.login-card > p { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card .btn { width: 100%; padding: 11px; margin-top: 6px; }
.login-foot { margin-top: 20px; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }

/* ---------- Mises en page complémentaires ---------- */

.stack { display: flex; flex-direction: column; gap: 20px; }
.stack .panel + .panel { margin-top: 0; }
.section-gap { margin-top: 20px; }
.title-row { display: flex; align-items: center; gap: 16px; }
.title-row p { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.avatar-lg { width: 52px; height: 52px; font-size: 21px; border-radius: 14px; }
.avatar.avatar-lg { border-radius: 50%; }
.muted-num { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 16px; }
.card-grid .panel + .panel { margin-top: 0; }
.cat-card { display: flex; flex-direction: column; }
.cat-card .panel-body { display: flex; flex-direction: column; gap: 14px; flex: 1; }
.cat-card .form-actions { margin-top: auto; justify-content: space-between; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 4px; }
.kv span { display: block; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.kv b { font-size: 16px; }
