/* Shared palette and foundations. Loaded before any page stylesheet. */

/*
 * RALEWAY, SERVED BY US — not by fonts.googleapis.com. Two reasons, both concrete:
 * the app is reached through the tailnet, where a machine may have no route to Google
 * at all; and the CDN would hand every visitor's IP to a third party, which is exactly
 * what the GDPR rulings on Google Fonts are about.
 *
 * SIL Open Font License 1.1 — see fonts/OFL.txt, which must travel with the files.
 *
 * One variable file per subset, `font-weight: 400 700` being the range it covers: the
 * browser interpolates 600 rather than faking a bold. The second subset only carries
 * what latin does not (Œ, Ÿ, the extra currency signs) and is fetched only if a
 * character needs it — that is what unicode-range decides.
 *
 * ⚠️ url() RELATIF, jamais /fonts/… : en production l'app est servie sous
 * /dewpoint, et un chemin depuis la racine y pointerait a cote. Le chemin relatif se
 * resout contre l'URL de CETTE feuille, donc il suit le context-path tout seul.
 */
@font-face {
    font-family: "Raleway";
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url("../fonts/raleway-latin.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
                   U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
                   U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "Raleway";
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url("../fonts/raleway-latin-ext.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
                   U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF,
                   U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/*
 * TWO THEMES, one set of names. Every rule below this block reads tokens only — no rule
 * anywhere in the app may hard-code a colour, or it will be wrong in one of the two.
 *
 * The active theme is written on <html data-theme="…"> by the boot script in
 * fragments/layout.html, BEFORE the first paint. There is deliberately no
 * prefers-color-scheme media query here: the script already resolved the system
 * preference into the attribute, so the CSS has exactly one source of truth.
 */

/*
 * Autorise les transitions VERS un mot-cle de taille — auto, min-content, fit-content.
 * Sans elle, `transition: block-size` d'un ::details-content ne produit rien : le
 * navigateur ne sait pas interpoler entre 0 et auto, il saute.
 *
 * ⚠️ N'agit que la ou une transition demande explicitement une taille en mot-cle. Aucune
 * regle existante n'en demande, donc rien d'autre ne bouge.
 */
:root {
    interpolate-size: allow-keywords;
}

:root,
:root[data-theme="light"] {
    /* The four device statuses. The MEANING is the mapping — green is healthy, red is
       broken — not the exact hex. That is why the dark theme may relight them, and why
       nothing else may repurpose them. */
    --status-online: #2e7d32;
    --status-offline: #757575;
    --status-fault: #c62828;
    --status-maintenance: #ef6c00;

    /* Blue, and it has to be: the accent must not be confusable with any of the four
       status colours above, which rules out every green, orange and red. */
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: #e6edfd;

    /* The second curve of the chart. A colour of ITS OWN, neither --accent nor a status
       token: the accent already means humidity, and the four statuses carry a meaning
       nothing else may borrow (see their comment above). Not orange or red either, which
       would read as an alert on a curve that carries none.

       ⚠️ Apple green sits closer to --status-online (#2e7d32) than the violet it replaced.
       The hues part — this one leans yellow, the status leans blue — and they never share a
       surface: the statuses live on markers and dots, this one only on a curve. Keep that
       distance in mind before relighting either. */
    --chart-temp: #4d7c0f;

    --text: #101a2b;
    --text-muted: #5a6b82;
    --border: #dbe3ec;
    --bg: #ffffff;
    --bg-soft: #f5f8fb;

    /* The ground the cards sit on, deliberately a few shades down from --bg: that gap
       is what makes a white card read as raised. Page stylesheets opt in; forms keep --bg. */
    --bg-page: #eaeff6;

    /* Light mode keeps the bar white and separates it with a hairline. */
    --header-bg: var(--bg);
    --header-border: var(--border);
    --header-brand: var(--accent);
    --header-muted: var(--text-muted);
    --header-active-bg: var(--accent-soft);
    --header-active-text: var(--accent);

    --ok-bg: #eaf4ea;
    --ok-border: #c8e0ca;
    --ok-text: #1f5c23;
    --error-bg: #fdecea;
    --error-border: #f3c9c5;
    --error-text: #8e211d;

    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);

    /* ⚠️ For the map, and only because it is the one panel that is NOT white. A card is
       white on grey, so --border is enough to say where it stops; Esri's light basemap is
       almost the colour of --bg-page, and the same hairline leaves no visible edge. Depth
       replaces the missing contrast — no darker frame, which read as heavy. */
    --shadow-raised: 0 2px 4px rgba(15, 23, 42, .08), 0 10px 24px rgba(15, 23, 42, .12);

    --shadow-pop: 0 8px 24px rgba(15, 23, 42, .14);
    --shadow-modal: 0 20px 50px rgba(15, 23, 42, .25);
    --scrim: rgba(15, 23, 42, .45);
}

:root[data-theme="dark"] {
    /* ⚠️ Relit, on purpose. The four values above were picked for white; on a #131c2e
       card the dark green and the dark red both collapse into "muddy". Same meanings,
       enough luminance to survive the background. */
    --status-online: #4ade80;
    --status-offline: #94a3b8;
    --status-fault: #f87171;
    --status-maintenance: #fb923c;

    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-soft: #1e2f4d;

    /* Relit like every other token here: #4d7c0f on this ground is a black smudge. Still
       apple green, still clear of --status-online (#4ade80), which leans mint. */
    --chart-temp: #a3e635;

    --text: #e6ecf5;
    --text-muted: #94a3b8;
    --border: #2a3750;
    --bg: #131c2e;
    --bg-soft: #1a2438;

    /* Darker than the cards, not lighter: the raised-card illusion only works one way. */
    --bg-page: #0b1220;

    --header-bg: #0e1626;
    --header-border: #223049;
    --header-brand: #93c5fd;
    --header-muted: #94a3b8;
    --header-active-bg: rgba(255, 255, 255, .09);
    --header-active-text: #ffffff;

    --ok-bg: #16301d;
    --ok-border: #285437;
    --ok-text: #86efac;
    --error-bg: #3a1a1c;
    --error-border: #6b2b2e;
    --error-text: #fca5a5;

    /* Shadows barely read on dark; the border does the separating instead. */
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);

    /* Same value as --shadow, deliberately: the dark basemap already stands clear of
       #0b1220, so there is nothing to compensate, and a deeper shadow would only smear. */
    --shadow-raised: var(--shadow);
    --shadow-pop: 0 8px 24px rgba(0, 0, 0, .5);
    --shadow-modal: 0 20px 50px rgba(0, 0, 0, .6);
    --scrim: rgba(3, 7, 15, .65);
}

:root {
    /* One red across the whole app: the one that says something is wrong. */
    --alert: var(--status-fault);

    /* TWO families, on purpose. Raleway is a display face: it carries the wordmark and
       the headings. The readings table and the .stat-value are dense columns of digits,
       and its narrow figures read worse there than the system stack — which also costs
       nothing to load and never arrives late.
       The fallbacks are not decoration: they are what the page shows during the swap. */
    --font-display: "Raleway", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    --radius: 5px;
    --radius-lg: 8px;

    /* Content column. Page stylesheets NARROW this one — the map wants 90rem, a form
       does not. It is why the two variables below are separate. */
    --page-width: 90rem;

    /* ⚠️ The app bar's own column, and it is CONSTANT. Never override it in a page
       stylesheet: the bar is the one thing on screen that must not move between two
       pages, and tying it to --page-width made the wordmark jump on every navigation. */
    --header-width: 84rem;

    /* Inline SVG, so no extra request and no file to lose. Single quotes inside,
       double outside: the reverse breaks the url() at the first attribute. */
    --icon-person: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10Zm0 2c-5 0-9 2.7-9 6v2h18v-2c0-3.3-4-6-9-6Z'/%3E%3C/svg%3E");
    /* ⚠️ Pointe vers le BAS, pas vers la droite : une pointe a droite, epaissie et fermee
       par un linejoin rond, se lit comme un bouton lecture. Le sens du deploiement (bas
       ferme, haut ouvert) est aussi celui de tous les accordeons. */
    --icon-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    --icon-pin: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a7 7 0 0 0-7 7c0 5.25 7 13 7 13s7-7.75 7-13a7 7 0 0 0-7-7Zm0 9.5a2.5 2.5 0 1 1 0-5 2.5 2.5 0 0 1 0 5Z'/%3E%3C/svg%3E");
}

/* A theme swap must be felt rather than seen. Armed ONLY while it happens: the class is
   put on <html> by the theme toggle and taken off when the fade is over.

   ⚠️ Permanently transitioning `*` would make every hover in the app feel soft, which is
   why the previous version listed four selectors instead. Scoping it to the swap is what
   lets it cover everything — text, icons, dots — without that cost.

   ⚠️ Never armed by the boot script: that one runs before the first paint, so the whole
   page would fade in on load. */
:root {
    --theme-fade: 240ms;
}

html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
    transition: background-color var(--theme-fade) ease,
                border-color var(--theme-fade) ease,
                color var(--theme-fade) ease,
                fill var(--theme-fade) ease,
                stroke var(--theme-fade) ease;
}

@media (prefers-reduced-motion: reduce) {
    html.theme-switching *,
    html.theme-switching *::before,
    html.theme-switching *::after {
        transition: none;
    }
}

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

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

h1, h2, h3 {
    margin: 0 0 .5rem;
    line-height: 1.25;
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -.01em;
}

h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }

a {
    color: var(--accent);
    text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
    text-underline-offset: 2px;
}

/* ⚠️ Every :hover in this file lives in this block, and nowhere else.
   Hover is a MOUSE state: a touch browser fakes it after a tap and leaves it stuck
   until you tap elsewhere, so the last thing touched stays lit. The phone and the Pi
   touchscreen get :active instead — instant, and released with the finger. */
@media (hover: hover) and (pointer: fine) {
    a:hover {
        text-decoration-color: currentColor;
    }

    header nav a:hover,
    .theme-toggle:hover,
    .header-help:hover {
        color: var(--header-active-text);
        background: var(--header-active-bg);
    }

    input[type="text"]:hover,
    input[type="number"]:hover,
    input[type="password"]:hover,
    select:hover {
        border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
    }

    button:hover {
        background: var(--accent-hover);
    }

    button.subtle:hover {
        color: var(--accent);
        background: var(--accent-soft);
        border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
    }

    /* ⚠️ Obligatoire, pas cosmetique : `button:hover` ci-dessus pese 0,1,1 et l'emporte
       sur `.password-reveal` (0,1,0). Sans cette regle, l'oeil vire au bleu plein des que
       la souris le frole. */
    .password-reveal:hover {
        color: var(--accent);
        background: var(--accent-soft);
    }

    /* ⚠️ Meme raison que juste au-dessus : `button:hover` l'emporterait et peindrait
       la croix en bleu plein. */
    .overlay-close:hover {
        color: var(--accent);
        background: var(--accent-soft);
    }

    .auth-menu a:hover,
    .auth-menu button:hover {
        color: var(--accent);
        background: var(--accent-soft);
    }

    .auth-name:hover {
        color: var(--header-active-text);
        background: var(--header-active-bg);
    }
}

/* Pressed state — the only feedback a finger ever gets. */
button:active {
    transform: translateY(1px);
}

header nav a:active,
.theme-toggle:active,
.header-help:active {
    background: var(--header-active-bg);
}

/* --- Header icon buttons ------------------------------------------------ */
/* The help mark and the theme toggle: the same button, two glyphs. */

.theme-toggle,
.header-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;      /* claims the free space; .auth then sits right after it */
    padding: .35rem;
    color: var(--header-muted);
    background: none;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
}

/* ⚠️ Only the FIRST of the pair claims the space, otherwise the second pushes the
   first back against the nav and the two split the bar. */
.theme-toggle + .header-help {
    margin-left: 0;
}

.theme-toggle svg,
.header-help svg {
    width: 1.15rem;
    height: 1.15rem;
    /* Stroke, not fill: one geometry that reads at any size and follows currentColor. */
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

/* ⚠️ The icon shows the theme you would GET, not the one you are in — a sun while dark,
   a moon while light. Showing the current state is the classic mistake here: the button
   then looks like a label and nobody presses it. */
:root[data-theme="dark"] .icon-moon,
:root[data-theme="light"] .icon-sun,
:root:not([data-theme="dark"]) .icon-sun {
    display: none;
}

/* ⚠️ Le VOISIN de .auth, qui est le dernier des deux boutons — donc l'aide depuis
   qu'ils ont ete echanges. Vise le mauvais, et .auth reclame l'espace libre une
   seconde fois : les deux icones se retrouvent collees a la navigation. */
.header-help + .auth {
    margin-left: 0;
}

/* --- Page header -------------------------------------------------------- */
/* Shared by every page that carries the app bar. Page stylesheets may override. */

/* ⚠️ The bar stays full-bleed (its border must reach both edges) but its CONTENT is
   inset to a column — hence padding, not a max-width.
   That column is --header-width, never --page-width: the bar must look identical on
   the map, the admin tables and the profile, so it cannot follow content that varies. */
header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .6rem max(1rem, calc((100% - var(--header-width)) / 2));
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
}

/* The wordmark. Flat, uppercase, tracked out — no logo to maintain. */
.brand {
    font-family: var(--font-display);
    font-size: .8125rem;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--header-brand);
    text-decoration: none;
}

header nav {
    display: flex;
    align-items: center;
    gap: .25rem;
}

header nav a {
    padding: .3rem .6rem;
    font-size: .875rem;
    color: var(--header-muted);
    text-decoration: none;
    border-radius: var(--radius);
}

/* ⚠️ AFTER the rules it overrides, never before. A media query adds no specificity:
   placed above .brand, its font-size would lose to the plain rule below and the bar
   would silently stay compact on desktop.
   Desktop has the room; a phone does not — the bar there costs viewport the map needs. */
@media (min-width: 48rem) {
    header {
        padding-block: 1.05rem;
        gap: 1.5rem;
    }

    .brand {
        font-size: .9375rem;
    }

    header nav a {
        padding: .4rem .7rem;
    }
}

/* --- User menu ---------------------------------------------------------- */
/* <details>, not a scripted dropdown: the browser already owns open/closed, keyboard
   focus and the Escape key. Nothing to write, nothing to get wrong on touch. */

header .auth {
    position: relative;
    margin-left: auto;
    font-size: .875rem;
}

/* ⚠️ Removes the disclosure triangle. list-item is what Safari uses, so both are needed. */
header .auth > summary {
    display: inline-block;
    list-style: none;
    cursor: pointer;
}

header .auth > summary::-webkit-details-marker {
    display: none;
}

.auth-menu {
    position: absolute;
    top: calc(100% + .4rem);
    right: 0;
    z-index: 1100;
    min-width: 11rem;
    padding: .3rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(15, 23, 42, .14);
}

.auth-menu a,
.auth-menu button {
    display: block;
    width: 100%;
    padding: .4rem .55rem;
    font: inherit;
    font-size: .875rem;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    color: var(--text);
    background: none;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
}

.auth-menu form {
    margin: 0;
}

.auth-menu hr {
    margin: .3rem 0;
    border: none;
    border-top: 1px solid var(--border);
}

/* ⚠️ Des tokens, jamais un blanc en dur : ces trois lignes etaient ecrites pour une barre
   sombre. En theme clair la barre est blanche, donc color: #fff rendait le nom ET l'icone
   invisibles — le ::before peint currentColor. */
header .auth[open] .auth-name {
    color: var(--header-active-text);
    background: var(--header-active-bg);
    border-color: transparent;
}

/* ⚠️ The person mark is a background image on ::before, not an <svg> in the markup:
   it is decoration repeated on every page, and the username next to it already says
   who this is. A screen reader gains nothing from reading it twice. */
.auth-name {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .2rem .65rem .2rem .5rem;
    font-weight: 600;
    color: var(--header-muted);
    background: var(--bg-soft);
    border: 1px solid var(--header-border);
    border-radius: 999px;
}

.auth-name::before {
    content: "";
    width: 1rem;
    height: 1rem;
    flex: none;
    background: currentColor;
    /* A mask, not a fill: the icon then follows currentColor like real text. */
    mask: var(--icon-person) center / contain no-repeat;
    -webkit-mask: var(--icon-person) center / contain no-repeat;
}

/* --- Forms -------------------------------------------------------------- */

label {
    display: block;
    margin-bottom: .3rem;
    font-size: .8125rem;
    font-weight: 600;
    letter-spacing: .01em;
    color: var(--text-muted);
}

input[type="text"],
input[type="number"],
input[type="password"],
select {
    width: 100%;
    padding: .55rem .7rem;
    font: inherit;
    color: inherit;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color .15s, box-shadow .15s;
}

/* focus-visible alone would skip the click-into-a-field case on some browsers. */
input:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

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

button {
    padding: .55rem 1.1rem;
    font: inherit;
    font-weight: 600;
    color: var(--bg);
    background: var(--accent);
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s;
}

button:hover {
    background: var(--accent-hover);
}

/* For anything that is not the main action of the screen. */
button.subtle {
    color: var(--text-muted);
    background: var(--bg);
    border-color: var(--border);
}

button.subtle:hover {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

/* --- Password reveal ---------------------------------------------------- */
/* Shared by the login form and the three fields of the profile dialog. */

.password-field {
    position: relative;
    display: flex;
    align-items: center;
}

/* min-width: 0 — a flex item refuses to shrink below its content otherwise.
   The right padding is what keeps the last character clear of the eye. */
.password-field input {
    flex: 1;
    min-width: 0;
    padding-right: 2.5rem;
}

/* ⚠️ Overrides the app's button styling (accent background, white text): this one is an
   icon sitting inside a field, not an action of the screen. See also the :hover block. */
/* ⚠️ top/bottom a 0 plutot qu'un translateY(-50%) pour centrer : `button:active` pose
   deja `transform: translateY(1px)`, qui remplacerait le centrage et ferait sauter l'oeil
   en haut du champ au moment du clic. Etire sur la hauteur, l'icone se centre seule. */
.password-reveal {
    position: absolute;
    top: 0;
    bottom: 0;
    right: .4rem;
    width: auto;
    display: inline-flex;
    align-items: center;
    padding: 0 .4rem;
    color: var(--text-muted);
    background: none;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
}

.password-reveal svg {
    width: 1.1rem;
    height: 1.1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Both icons are always in the DOM, aria-pressed picks one — the same technique as the
   theme toggle. The icon shows the ACTION: an open eye while hidden, a struck-out eye
   while shown. */
.password-reveal[aria-pressed="false"] .icon-eye-off,
.password-reveal[aria-pressed="true"] .icon-eye {
    display: none;
}

/* ⚠️ Edge draws its OWN reveal button inside every password field. Without this, there
   are two eyes side by side, and only one of them is ours. */
input[type="password"]::-ms-reveal {
    display: none;
}

/* --- Overlay ------------------------------------------------------------ */
/* Shared by the device sheet on the map and the password dialog on the profile. */

/* ⚠️ 1200, and the reason matters. Leaflet's CONTROLS stop at z-index 800, but the
   .leaflet-top / .leaflet-bottom containers that hold them sit at 1000 — the same value
   an overlay would naturally take. At equal z-index the DOM decides, and #map comes
   after #overlay, so the attribution printed straight through the scrim. */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--scrim);

    /* ⚠️ -webkit- en PLUS, pas a la place : Safari ne connait toujours que le prefixe.
       Le voile derriere reste indispensable — un navigateur qui ignore backdrop-filter
       n'afficherait plus aucune separation entre la fiche et la carte. */
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

/* ⚠️ An explicit display on .overlay would override the display:none the browser
   applies to [hidden] — the overlay would stay visible for good. This rule outranks
   the flex above on specificity, which is the only reason the pair works. */
.overlay[hidden] {
    display: none;
}

/* ⚠️ Le fond ne defile plus tant qu'un overlay est ouvert — les trois du site partagent
   .overlay et l'attribut hidden, la regle vaut donc pour la fiche capteur, l'aide et le
   mot de passe.

   scrollbar-gutter AVEC overflow: hidden, et les deux comptent : masquer le defilement
   fait disparaitre la barre, et le contenu sautait lateralement de sa largeur a chaque
   ouverture. La gouttiere reprend exactement la place que la barre occupait. */
html:has(.overlay:not([hidden])) {
    overflow: hidden;
    scrollbar-gutter: stable;
}

.overlay-card {
    position: relative;
    overscroll-behavior: contain;
    width: min(32rem, 100%);
    max-height: min(85vh, 44rem);
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--bg);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
}

/* .overlay-close is out of flow, so the real first line of the card follows it. */
.overlay-card > :first-child,
.overlay-close + * {
    margin-top: 0;
}

/* The help dialog runs to several sections; nothing else in a card does. */
.overlay-card h3 {
    margin: 1.25rem 0 .35rem;
    font-size: .9375rem;
}

/* One rhythm for the whole dialog. The browser's 1em on <p> against the .35rem under a
   heading left every section at a different distance from its own title. Scoped to the
   help dialog on purpose: the device sheet and the password dialog space themselves. */
#help-overlay p,
#help-overlay ul {
    margin: 0 0 .5rem;
    font-size: .875rem;
}

/* ⚠️ :not(), because #help-overlay ul (1,0,1) would outrank .status-legend (0,1,0)
   whatever the order — the legend would keep an indent it does not want. */
#help-overlay ul:not(.status-legend) {
    padding-left: 1.15rem;
}

#help-overlay li + li {
    margin-top: .35rem;
}

/* No rule between the sections: the size gap does the separating instead. The heading
   is bigger than the .9375rem of the other cards, the running text smaller — that
   contrast is what makes the four blocks read apart. */
#help-overlay h3 {
    margin-top: 1.1rem;
    font-size: 1.0625rem;
}

/* The legend shows the four colours it names, so the dot replaces the bullet.
   ⚠️ baseline, not center: an item that wraps must keep its dot against the FIRST
   line, not floating halfway down the paragraph. */
.status-legend {
    padding-left: 0;
    list-style: none;
}

.status-legend li {
    display: flex;
    align-items: baseline;
    gap: .5rem;
}

/* Room for the cross — a long title would otherwise run underneath it. */
.overlay-card > h2 {
    padding-right: 2rem;
}

/* ⚠️ Overrides the app's button styling (accent background, white text): a cross in a
   corner, not an action of the screen. See also the :hover block at the top. */
.overlay-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: inline-flex;
    padding: .35rem;
    color: var(--text-muted);
    background: none;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
}

.overlay-close svg {
    width: 1.15rem;
    height: 1.15rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

/*
 * Visible pour un lecteur d'ecran, invisible a l'oeil. Pour les <label> qu'un controle n'a
 * pas besoin d'afficher parce que son contexte le dit deja.
 *
 * ⚠️ Ni display: none ni visibility: hidden : les deux retirent l'element de l'arbre
 * d'accessibilite, soit exactement l'inverse du but. Il faut le sortir du champ tout en le
 * laissant rendu, d'ou le carre d'un pixel decoupe a zero.
 */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* --- Status dot --------------------------------------------------------- */
/* Shared by the admin table and the map tiles. The four colours come from the tokens
   above and mean something — the dot is the only place they appear outside the map. */

.status-dot {
    display: inline-block;
    width: .6rem;
    height: .6rem;
    flex: none;
    border-radius: 50%;
    background: var(--status-offline);
}

.status-dot.status-ONLINE { background: var(--status-online); }
.status-dot.status-OFFLINE { background: var(--status-offline); }
.status-dot.status-FAULT { background: var(--status-fault); }
.status-dot.status-MAINTENANCE { background: var(--status-maintenance); }

/* The admin table puts it inline before a word; the tiles use flex and want no margin. */
.admin .status-dot {
    margin-right: .4rem;
}

/* --- Notifications ------------------------------------------------------ */
/* ⚠️ z-index 1300 : au-dessus de l'overlay (1200), lui-meme au-dessus des conteneurs
   Leaflet (1000). Une confirmation cachee derriere une fiche ouverte ne confirme rien. */

.toasts {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1300;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    /* La pile ne doit pas intercepter les clics destines a la page en dessous ; chaque
       toast les reprend pour lui-meme. */
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    width: min(22rem, calc(100vw - 2rem));
    padding: .7rem .8rem;
    font-size: .875rem;
    border: 1px solid;
    border-left-width: 3px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-pop);
    pointer-events: auto;
    animation: toast-in .18s ease-out;
}

.toast-ok {
    color: var(--ok-text);
    background: var(--ok-bg);
    border-color: var(--ok-border);
    border-left-color: var(--status-online);
}

.toast-error {
    color: var(--error-text);
    background: var(--error-bg);
    border-color: var(--error-border);
    border-left-color: var(--alert);
}

.toast-close {
    flex: none;
    margin-left: auto;
    padding: 0 .2rem;
    font-size: 1.1rem;
    line-height: 1;
    color: inherit;
    background: none;
    border: none;
    opacity: .6;
    cursor: pointer;
}

.toast-close:hover {
    background: none;
    opacity: 1;
}

/* La classe posee juste avant le retrait : c'est sa transition qui declenche
   transitionend, donc le remove(). */
.toast-leaving {
    opacity: 0;
    transform: translateX(1rem);
    transition: opacity .18s ease, transform .18s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(1rem); }
}

@media (prefers-reduced-motion: reduce) {
    .toast {
        animation: none;
    }

    /* ⚠️ Une transition NULLE ne declenche jamais transitionend : sans ce garde-fou, le
       toast resterait a l'ecran pour toujours. On garde une duree minimale, invisible. */
    .toast-leaving {
        transition-duration: .01s;
    }
}

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

.message {
    margin: 0 0 1rem;
    padding: .65rem .85rem;
    font-size: .9rem;
    border-radius: var(--radius);
    border: 1px solid;
    /* The colour bar carries the meaning for anyone who reads shape before hue. */
    border-left-width: 3px;
}

.message-error {
    color: #8e211d;
    background: #fdecea;
    border-color: #f3c9c5;
    border-left-color: var(--alert);
}

.message-ok {
    color: #1f5c23;
    background: #eaf4ea;
    border-color: #c8e0ca;
    border-left-color: var(--status-online);
}
