/* Feuille de style du backoffice PBN (Pico CSS 2 en base). Aucun style en ligne : la CSP l'interdit.
   Direction : une carte IGN « Série bleue ». Rail marine comme une couverture de carte, familles du
   menu repérées par des couleurs de légende, cartouche de page bordé d'une règle graduée. */

/* ---------- Jetons ---------- */
:root {
  --pico-font-size: 93.75%;            /* échelle fixe : pas de typographie fluide sur un outil */
  --pico-line-height: 1.5;
  --pico-border-radius: .375rem;
  --pico-spacing: 1rem;
  --pico-typography-spacing-vertical: .9rem;
  --pico-form-element-spacing-vertical: .5rem;
  --pico-form-element-spacing-horizontal: .75rem;

  --rail-largeur: 15.5rem;
  --rail: #0b2a42;
  --rail-encre: #dbe8f3;
  --rail-discret: #8fb0c9;
  --rail-survol: rgba(219, 232, 243, .08);
  --rail-courant: rgba(108, 196, 255, .16);

  /* couleurs de légende des familles */
  --g-veille: #0072b8;   /* eau */
  --g-contenu: #2f7d46;  /* forêt */
  --g-reseau: #d0482a;   /* route */
  --g-infra: #8c5518;    /* courbes de niveau */
  --g-systeme: #56616d;  /* bâti */

  --ease: cubic-bezier(.16, 1, .3, 1);
}

:root:not([data-theme=dark]), [data-theme=light] {
  --papier: #f4f7fa;
  --surface: #ffffff;
  --encre: #14181d;
  --discret: #55606b;
  --filet: #dbe4ec;
  --filet-fort: #b9c8d6;
  --accent: #0072b8;
  --accent-fort: #005b94;
  --accent-fond: #e3f0f9;
  --danger: #b3361b;
  --danger-fond: #fbe9e4;
  --vigilance: #8a4b00;
  --vigilance-fond: #fdf0dc;
  --succes: #22673a;
  --succes-fond: #e3f2e7;
  --info: #005b94;
  --info-fond: #e3f0f9;
  --neutre: #4a5560;
  --neutre-fond: #eaeff4;

  --pico-background-color: var(--papier);
  --pico-color: var(--encre);
  --pico-muted-color: var(--discret);
  --pico-muted-border-color: var(--filet);
  --pico-h1-color: var(--encre);
  --pico-h2-color: var(--encre);
  --pico-h3-color: var(--encre);
  --pico-primary: var(--accent);
  --pico-primary-background: var(--accent);
  --pico-primary-border: var(--accent);
  --pico-primary-underline: rgba(0, 114, 184, .4);
  --pico-primary-hover: var(--accent-fort);
  --pico-primary-hover-background: var(--accent-fort);
  --pico-primary-hover-border: var(--accent-fort);
  --pico-primary-hover-underline: var(--accent-fort);
  --pico-primary-focus: rgba(0, 114, 184, .35);
  --pico-primary-inverse: #fff;
  --pico-secondary: #3d4a57;
  --pico-secondary-background: #3d4a57;
  --pico-secondary-border: #3d4a57;
  --pico-secondary-hover: #2a3440;
  --pico-secondary-hover-background: #2a3440;
  --pico-secondary-hover-border: #2a3440;
  --pico-secondary-focus: rgba(61, 74, 87, .3);
  --pico-secondary-inverse: #fff;
  --pico-table-border-color: var(--filet);
  --pico-form-element-background-color: var(--surface);
  --pico-form-element-border-color: var(--filet-fort);
  --pico-form-element-focus-color: var(--accent);
  --pico-form-element-active-border-color: var(--accent);
  --pico-card-background-color: var(--surface);
  --pico-card-sectioning-background-color: #f8fafc;
  --pico-card-box-shadow: 0 1px 2px rgba(11, 42, 66, .06), 0 2px 8px rgba(11, 42, 66, .04);
  --pico-code-background-color: var(--neutre-fond);
  --pico-text-selection-color: rgba(0, 114, 184, .2);
}

@media only screen and (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --papier: #0c1620;
    --surface: #111e2a;
    --encre: #e3edf6;
    --discret: #9fb2c3;
    --filet: #22364a;
    --filet-fort: #33506a;
    --accent: #4fb0ee;
    --accent-fort: #7cc6f5;
    --accent-fond: #12324b;
    --danger: #ff8a70;
    --danger-fond: #3a1a13;
    --vigilance: #f2b65c;
    --vigilance-fond: #33240f;
    --succes: #7fd49a;
    --succes-fond: #12301d;
    --info: #7cc6f5;
    --info-fond: #12324b;
    --neutre: #b4c3d0;
    --neutre-fond: #1c2b39;
    --rail: #07141f;

    --pico-background-color: var(--papier);
    --pico-color: var(--encre);
    --pico-muted-color: var(--discret);
    --pico-muted-border-color: var(--filet);
    --pico-h1-color: var(--encre);
    --pico-h2-color: var(--encre);
    --pico-h3-color: var(--encre);
    --pico-primary: var(--accent);
    --pico-primary-background: #1f7fc0;
    --pico-primary-border: #1f7fc0;
    --pico-primary-underline: rgba(79, 176, 238, .45);
    --pico-primary-hover: var(--accent-fort);
    --pico-primary-hover-background: #2b92d8;
    --pico-primary-hover-border: #2b92d8;
    --pico-primary-focus: rgba(79, 176, 238, .4);
    --pico-primary-inverse: #fff;
    --pico-secondary: #a9bccd;
    --pico-secondary-background: #2c4256;
    --pico-secondary-border: #2c4256;
    --pico-secondary-hover: #c9d7e3;
    --pico-secondary-hover-background: #375169;
    --pico-secondary-hover-border: #375169;
    --pico-secondary-inverse: #e3edf6;
    --pico-table-border-color: var(--filet);
    --pico-form-element-background-color: #0e1a25;
    --pico-form-element-border-color: var(--filet-fort);
    --pico-form-element-focus-color: var(--accent);
    --pico-form-element-active-border-color: var(--accent);
    --pico-card-background-color: var(--surface);
    --pico-card-sectioning-background-color: #152433;
    --pico-card-box-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 10px rgba(0, 0, 0, .2);
    --pico-code-background-color: var(--neutre-fond);
    --pico-text-selection-color: rgba(79, 176, 238, .3);
  }
}

/* ---------- Socle ---------- */
html { scroll-padding-top: 1rem; }
body { background: var(--papier); color: var(--encre); font-variant-numeric: tabular-nums; }
::selection { background: var(--pico-text-selection-color); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { text-underline-offset: .18em; }
h1, h2, h3 { letter-spacing: -.01em; text-wrap: balance; }
h2 { font-size: 1.2rem; margin-top: 2rem; }
h3 { font-size: 1.05rem; margin-top: 1.5rem; }
code { font-size: .85em; padding: .1em .35em; }

.evitement { position: absolute; left: -999px; top: .5rem; z-index: 10; padding: .5rem .75rem;
  background: var(--surface); border-radius: var(--pico-border-radius); }
.evitement:focus { left: .5rem; }

/* ---------- Ossature : rail + zone de travail ---------- */
body:has(> .rail) { display: grid; grid-template-columns: var(--rail-largeur) minmax(0, 1fr); min-height: 100vh; }
body > main.travail { padding: 1.75rem 2.25rem 4rem; width: 100%; max-width: 92rem; }

.rail { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--rail); color: var(--rail-encre); }
.rail-tete { display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: 1.1rem 1rem .9rem 1.1rem; }
.marque { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; font-weight: 700;
  font-size: 1.05rem; letter-spacing: .01em; }
.marque:hover { color: #fff; }
.marque img { display: block; border-radius: 7px; }
.marque small { display: block; font-weight: 400; font-size: .75rem; color: var(--rail-discret); letter-spacing: 0; }
.rail-bouton { display: none; }

.rail-menu { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.rail nav { display: block; flex: 1; overflow-y: auto; padding: .25rem .6rem 1rem; scrollbar-width: thin;
  scrollbar-color: #2a4a66 transparent; }
.rail nav ul { display: block; margin: 0 0 .4rem; padding: 0; }
.rail nav li { display: block; padding: 0; margin: 0; list-style: none; }
.rail nav ul:first-of-type, .rail nav ul:last-of-type { margin-left: 0; margin-right: 0; }
.rail-groupe { display: flex; align-items: center; gap: .5rem; margin: .9rem .5rem .3rem; font-size: .75rem;
  font-weight: 600; color: var(--rail-discret); letter-spacing: .02em; }
.pastille { width: .6rem; height: .6rem; border-radius: 2px; flex: none; background: currentColor;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .25); }
.rail nav a { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin: 0;
  padding: .38rem .6rem .38rem 1.6rem; border-radius: .375rem; color: var(--rail-encre); font-size: .9rem;
  text-decoration: none; transition: background-color .15s var(--ease), color .15s var(--ease); }
.rail nav a:hover { background: var(--rail-survol); color: #fff; }
.rail nav a[aria-current=page] { background: var(--rail-courant); color: #fff; font-weight: 600; }
.rail nav ul { --fam: #6cc4ff; }
.rail nav ul[aria-labelledby=g-veille] { --fam: #2f9be0; }
.rail nav ul[aria-labelledby=g-contenu] { --fam: #4fb36b; }
.rail nav ul[aria-labelledby=g-reseau] { --fam: #ff5a36; }
.rail nav ul[aria-labelledby=g-infra] { --fam: #d08b3c; }
.rail nav ul[aria-labelledby=g-systeme] { --fam: #9aa7b4; }
.rail nav a[aria-current=page] { background: color-mix(in srgb, var(--fam) 16%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--fam) 75%, transparent); }
.rail nav a:focus-visible { outline-color: #6cc4ff; outline-offset: -2px; }
.compteur { min-width: 1.4rem; padding: 0 .4rem; border-radius: 1rem; background: #c43a1c; color: #fff;
  font-size: .72rem; font-weight: 700; line-height: 1.35rem; text-align: center; }

.rail-pied { margin: 0; padding: .75rem 1rem 1rem; border-top: 1px solid rgba(219, 232, 243, .1); }
.rail-deconnexion { width: 100%; margin: 0; padding: .4rem .6rem; font-size: .85rem; background: transparent;
  border: 1px solid rgba(219, 232, 243, .25); color: var(--rail-encre); }
.rail-deconnexion:hover, .rail-deconnexion:focus { background: var(--rail-survol); border-color: rgba(219, 232, 243, .45);
  color: #fff; }

/* couleurs de légende */
.legende-veille { color: var(--g-veille); }
.legende-contenu { color: var(--g-contenu); }
.legende-reseau { color: var(--g-reseau); }
.legende-infra { color: var(--g-infra); }
.legende-systeme { color: var(--g-systeme); }
@media only screen and (prefers-color-scheme: dark) {
  :root:not([data-theme]) .legende-veille { color: #4fb0ee; }
  :root:not([data-theme]) .legende-contenu { color: #5cc27a; }
  :root:not([data-theme]) .legende-reseau { color: #f27b5c; }
  :root:not([data-theme]) .legende-infra { color: #dc9a4c; }
  :root:not([data-theme]) .legende-systeme { color: #a9b6c2; }
  :root:not([data-theme]) .rail { border-right: 1px solid #16283a; }
}
.rail .legende-veille { color: #2f9be0; }
.rail .legende-contenu { color: #4fb36b; }
.rail .legende-reseau { color: #ef6a4a; }
.rail .legende-infra { color: #d08b3c; }
.rail .legende-systeme { color: #9aa7b4; }

/* ---------- Cartouche de page ---------- */
.cartouche { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end;
  gap: .5rem 2rem; margin-bottom: 1.75rem; padding-bottom: 1.1rem; }
/* bordure graduée, comme le cadre d'une carte topographique */
.cartouche::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 5px;
  border: 1px solid var(--encre);
  background: repeating-linear-gradient(90deg, var(--encre) 0 3rem, var(--surface) 3rem 6rem); }
.cartouche h1 { margin: 0; font-size: 1.75rem; line-height: 1.2; font-weight: 700; }
.cartouche-role { margin: .35rem 0 0; max-width: 72ch; color: var(--discret); }
.cartouche-legende { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; margin: 0;
  font-size: .82rem; white-space: nowrap; }
.legende { display: inline-flex; align-items: center; gap: .45rem; font-weight: 600; padding: .15rem .55rem;
  border: 1px solid currentColor; border-radius: 2px; background: color-mix(in srgb, currentColor 8%, transparent); }
.legende::before { content: ""; width: .65rem; height: .65rem; border-radius: 2px; background: currentColor; }
.cartouche-aide { color: var(--accent); }
.retour { margin: 0 0 .6rem; font-size: .85rem; }
.retour a { color: var(--discret); text-decoration: none; }
.retour a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- Composants ---------- */
.travail > p:has(> [role=button]) { display: flex; flex-wrap: wrap; gap: .75rem; }
.htmx-indicator { opacity: 0; transition: opacity 150ms ease-in; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

.badge { display: inline-block; padding: .05em .55em; border-radius: 1em; font-size: .75rem; font-weight: 600;
  line-height: 1.6; white-space: nowrap; background: var(--neutre-fond); color: var(--neutre); }
.badge-red { background: var(--danger-fond); color: var(--danger); }
.badge-orange { background: var(--vigilance-fond); color: var(--vigilance); }
.badge-green { background: var(--succes-fond); color: var(--succes); }
.badge-blue { background: var(--info-fond); color: var(--info); }
.badge-grey { background: var(--neutre-fond); color: var(--neutre); }

/* Tableaux : enveloppés dans .tableau, qui défile horizontalement si le tableau est plus large */
.tableau { margin-bottom: var(--pico-spacing); overflow-x: auto; background: var(--surface);
  border: 1px solid var(--filet); border-radius: .5rem; }
.tableau > table { margin: 0; }
table { font-size: .875rem; }
th, td { vertical-align: top; padding: .5rem .75rem; border-bottom: 1px solid var(--filet); background: transparent; }
thead th { font-size: .78rem; font-weight: 600; color: var(--discret); background: var(--pico-card-sectioning-background-color);
  border-bottom-color: var(--filet-fort); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 4%, transparent); }
td form, td details { margin: 0; }
td form button, td form input, td form select,
td form [type=submit], td form [type=button] { margin: 0 0 .25rem; padding: .25rem .6rem; font-size: .85rem; width: auto; }
td textarea { font-size: .85rem; margin-bottom: .25rem; }
td.url { word-break: break-all; }
details summary { font-size: .85rem; }

article { border: 1px solid var(--filet); }
article > header { font-weight: 600; font-size: .95rem; }

.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; margin-bottom: 1.25rem; }
.filters > * { flex: 0 1 12rem; margin-bottom: 0; }
.filters .wide { flex: 1 1 18rem; }
.filters label { font-size: .85rem; color: var(--discret); }
.filters > button { flex: 0 0 auto; width: auto; }
.filters select, .filters input:not([type=checkbox], [type=radio]) { margin-bottom: 0; }
.filters fieldset { margin-bottom: 0; }
.pager { display: flex; justify-content: space-between; margin: 1rem 0; }

[role=button], button, input[type=submit] { font-weight: 600; }
label { font-size: .9rem; }
fieldset legend { font-weight: 600; }

.muted { color: var(--discret); }
.small { font-size: .82rem; }
.evidence { margin: 0; padding-left: 1.1rem; font-size: .8rem; }
.row-done { opacity: .6; }
.notice { color: var(--vigilance); font-size: .85rem; }
.error { color: var(--danger); font-weight: 600; }
.result { margin-top: 1rem; }
.alert-banner { padding: .6rem 1rem; margin-bottom: 1rem; font-size: .9rem; border-radius: .5rem;
  background: var(--vigilance-fond); color: var(--vigilance); border: 1px solid color-mix(in srgb, var(--vigilance) 30%, transparent); }
.alert-banner a { color: inherit; font-weight: 600; }
.persona-photo { max-width: 200px; height: auto; border-radius: .5rem; }
.check-group { display: flex; flex-wrap: wrap; gap: .5rem 1rem; margin-bottom: var(--pico-spacing); }
.check-group label { margin-bottom: 0; }
.link-row { display: flex; gap: .5rem; }
.link-row input { flex: 1 1 12rem; }
.actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; }
.actions form { margin: 0; display: flex; gap: .5rem; align-items: end; }
.actions button, .actions input { margin: 0; width: auto; }
.preview { border: 1px solid var(--filet); border-radius: .5rem; padding: 1rem; }

/* Analyse de SERP : capture CAPTCHA à sa taille réelle (coordonnées du clic = pixels du viewport) */
.captcha-box { overflow: auto; max-width: 100%; border: 1px solid var(--filet); margin-bottom: 1rem; }
input[type=image].captcha-shot { max-width: none; width: auto; height: auto; padding: 0; margin: 0; border: 0; border-radius: 0; cursor: crosshair; }

/* ---------- Notice (/aide) ---------- */
.notice-page { display: grid; grid-template-columns: 14rem minmax(0, 1fr); gap: 2.5rem; align-items: start; }
.notice-sommaire, .notice-sommaire ul { display: block; }
.notice-sommaire ul:first-of-type, .notice-sommaire ul:last-of-type { margin: 0; }
.notice-sommaire li a { margin: 0; }
.notice-sommaire { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; font-size: .85rem; }
.notice-sommaire p { margin: 0 0 .4rem; font-weight: 600; color: var(--discret); font-size: .78rem; }
.notice-sommaire ul { margin: 0; padding: 0; }
.notice-sommaire li { display: block; list-style: none; margin: 0; padding: 0; }
.notice-sommaire a { display: block; padding: .2rem .5rem; border-radius: .25rem; color: var(--encre); text-decoration: none; }
.notice-sommaire a:hover { background: var(--accent-fond); color: var(--accent-fort); }
.notice-texte { max-width: 74ch; }
.notice-texte h2 { margin-top: 2.75rem; padding-top: .9rem; border-top: 1px solid var(--filet-fort); font-size: 1.35rem; }
.notice-texte h2:first-child { margin-top: 0; }
.notice-texte h3 { margin-top: 1.75rem; font-size: 1.05rem; }
.notice-texte h2:target, .notice-texte h3:target { color: var(--accent); }
.notice-texte li { margin-bottom: .25rem; }
.notice-texte table { font-size: .85rem; }

/* ---------- Connexion ---------- */
body:not(:has(> .rail)) > main.travail { max-width: 26rem; margin: 12vh auto 0; }
.connexion { padding: 0; overflow: hidden; }
.connexion-tete { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.25rem; background: var(--rail); color: #fff;
  font-weight: 700; }
.connexion-tete small { display: block; font-weight: 400; font-size: .75rem; color: var(--rail-discret); }
.connexion-tete img { display: block; border-radius: 7px; }
.connexion-corps { padding: 1.25rem; }
.connexion .cartouche { margin-bottom: 1.25rem; }

/* ---------- Petits écrans ---------- */
@media (max-width: 64rem) {
  body:has(> .rail) { display: block; }
  .rail { position: sticky; top: 0; z-index: 5; height: auto; }
  .rail-tete { padding: .6rem 1rem; }
  .rail-bouton { display: inline-block; width: auto; margin: 0; padding: .35rem .8rem; font-size: .85rem;
    background: transparent; border: 1px solid rgba(219, 232, 243, .35); color: var(--rail-encre); }
  .rail-menu { display: none; max-height: calc(100vh - 3.5rem); overflow-y: auto; }
  .rail.ouvert .rail-menu { display: flex; }
  body > main.travail { padding: 1.25rem 1rem 3rem; }
  .cartouche { grid-template-columns: minmax(0, 1fr); }
  .cartouche-legende { flex-direction: row; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; white-space: normal; }
  .notice-page { grid-template-columns: minmax(0, 1fr); }
  .notice-sommaire { position: static; max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
