/*
    Feuille de style unique du kiosque.

    Cible : dalle 480x800 en portrait, posée verticalement. Aucune bibliothèque
    CSS : chaque classe ci-dessous est utilisée par les templates, rien de plus.
    Tout est pensé pour le tactile, donc les cibles sont larges (64 px) et les
    gestes de zoom ou de sélection sont neutralisés.
*/

:root {
    --fond: #101317;
    --surface: #1b2026;
    --surface-haute: #252c34;
    --bordure: #333c46;
    --texte: #eef2f6;
    --texte-doux: #9aa6b2;
    --accent: #4da3ff;
    --ok: #4cd48a;
    --ko: #ff6b6b;
    --danger: #e5484d;
    --rayon: 14px;
    --cible: 64px;

    /* Facteur de luminosité, piloté par le contrôleur `luminosite`. */
    --facteur: 1;
    color-scheme: dark;
}

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

html,
body {
    margin: 0;
    height: 100%;
}

body {
    background: var(--fond);
    color: var(--texte);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 34px;
    line-height: 1.35;
    overflow: hidden;
    /* Pas de zoom ni de sélection accidentelle au doigt. */
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* --- Structure générale ------------------------------------------------- */

.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    filter: brightness(var(--facteur));
    transition: filter 400ms ease;
}

.barre-haut {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: calc(env(safe-area-inset-top) + 7px) 10px 10px;
    border-bottom: 1px solid var(--bordure);
    justify-content: space-between;
}

.titre {
    margin: 0;
    font-size: 39px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.contenu {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
}

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

.btn-icone,
.btn-action,
.onglet {
    border: 1px solid var(--bordure);
    background: var(--surface);
    color: var(--texte);
    border-radius: var(--rayon);
    font: inherit;
    cursor: pointer;
}

.btn-icone {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    font-size: 48px;
    text-decoration: none;
    padding: 0;
}

.btn-action {
    min-height: var(--cible);
    padding: 0 16px;
    font-size: 34px;
}

.btn-action.principal {
    background: var(--accent);
    border-color: var(--accent);
    color: #06121f;
    font-weight: 600;
}

.btn-action.danger {
    background: var(--danger);
    border-color: var(--danger);
}

.btn-icone:active,
.btn-action:active,
.onglet:active {
    transform: scale(0.96);
}


/* --- Mode jour (8 h - 21 h) -------------------------------------------- */

body.jour {
    --fond: #eef2f6;
    --surface: #ffffff;
    --surface-haute: #e4eaf1;
    --bordure: #c3ccd6;
    --texte: #16202b;
    --texte-doux: #55636f;
    --accent: #1c6fd4;
    --ok: #1a8a52;
    --ko: #c0282d;
    --danger: #c0282d;
    color-scheme: light;
}

/* L horloge reste lisible sur les deux fonds. */
body.jour .horloge {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2px 12px;
    border-radius: 14px;
    background: rgb(240 244 248 / 92%);
    box-shadow: 0 2px 18px rgb(0 0 0 / 18%);
    color: var(--texte);
    font-size: 34px;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    text-shadow: 0 4px 24px rgb(0 0 0 / 85%);
    pointer-events: none;
    will-change: transform;
    transition: opacity 400ms ease;
}

.horloge-heure {
    display: inline-flex;
}

.horloge-soleil,
.horloge-alertes {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--texte-doux);
    white-space: wrap;
}

.horloge-alertes {
    max-width: 60vw;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ko);
}

.horloge-alertes svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

/* Icones : elles heritent de la couleur et de la taille du texte autour. */
.icone-transport {
    width: 24px;
    height: 24px;
}

tr-btn svg,
.tr-btn .icon {
    width: 22px;
    height: 22px;
}


/* --- Notification ------------------------------------------------------- */

.notification {
    position: fixed;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 70;
    max-width: calc(100% - 24px);
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 19px;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 6px 24px rgb(0 0 0 / 30%);
    pointer-events: none;
}

.notification[hidden] {
    display: none;
}

.notification.ton-info {
    background: var(--surface-haute);
    color: var(--texte);
    border: 1px solid var(--bordure);
}

.notification.ton-succes {
    background: var(--ok);
    color: #fff;
}

.notification.ton-erreur {
    background: var(--danger);
    color: #fff;
}

/* --- Horloge flottante (reprise de pods) --------------------------------

   Le calque suit son rebond : position fixe, aucun clic intercepte, contour
   noir pour rester lisible sur un fond clair comme sur un fond sombre.
   La taille est posee par le pilote ; le soleil et les alertes sont en `em`
   pour suivre cette taille. */

.horloge-flottante {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 60;
    max-width: 60%;
    margin: 0;
    padding: 0 6px;
    line-height: 1;
    font-family: "DejaVu Sans Mono", ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    letter-spacing: -0.02em;
    white-space: nowrap;
    color: var(--texte);
    -webkit-text-stroke: 0.04em var(--fond);
    paint-order: stroke fill;
    text-shadow: 0 0 4px var(--fond), 0 2px 8px rgb(0 0 0 / 35%);
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.4s ease;
    will-change: transform, opacity;
}

.horloge-flottante.horloge-masquee {
    opacity: 0;
}

.horloge-heure {
    display: inline-flex;
}

/* Sous le cadran, dans le meme calque : le soleil puis les plantes suivent
   son rebond et son effacement. */
.horloge-soleil,
.horloge-alertes {
    display: block;
    text-align: center;
    font-size: 17px;
    line-height: 1.25;
    letter-spacing: 0;
    font-weight: 500;
    color: var(--texte-doux);
}

.horloge-alertes {
    color: var(--ko);
}

.horloge-alertes svg {
    width: 0.9em;
    height: 0.9em;
    vertical-align: -0.1em;
}

/* Icones des barres de pilotage. */
.icone-transport {
    width: 24px;
    height: 24px;
}

.tr-btn svg {
    width: 24px;
    height: 24px;
}

/* --- Bandeau agenda ----------------------------------------------------- */

.agenda-bandeau {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--rayon);
    background: var(--surface-haute);
    border: 1px solid var(--bordure);
    font-size: 31px;
}

.agenda-titre {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agenda-heure {
    color: var(--texte-doux);
    white-space: nowrap;
}

/* --- Bandeau solaire ---------------------------------------------------- */

.solaire {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 0.9fr) minmax(0, 1fr) minmax(0, 1.35fr);
    align-items: center;
    gap: 4px;
    padding: 7px 6px;
    border-radius: var(--rayon);
    background: var(--surface-haute);
    border: 1px solid var(--bordure);
}

.solaire-chiffre {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    min-width: 0;
}

.solaire-libelle {
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--texte-doux);
}

.solaire-valeur {
    font-size: 15px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.solaire-valeur small,
.solaire-sous small {
    font-size: 15px;
    font-weight: 400;
    color: var(--texte-doux);
    margin-left: 1px;
}

.solaire-sous {
    font-size: 15px;
    color: var(--texte-doux);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.solaire-valeur.ok {
    color: var(--ok);
}

.solaire-valeur.alerte {
    color: var(--ko);
}

/* Les trois SOC côte à côte, séparés par un point discret. */
.solaire-zens {
    display: flex;
    gap: 2px;
    justify-content: center;
    font-size: 15px;
}

.zens-soc+.zens-soc::before {
    content: '·';
    margin-right: 3px;
    color: var(--bordure);
}

.solaire-appareils {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--bordure);
    color: var(--texte-doux);
    font-size: 36px;
}

/* --- Boutons des relais ------------------------------------------------- */

.relais {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 0.9fr) minmax(0, 1fr) minmax(0, 1.35fr);
    overflow: visible;
    grid-auto-rows: min-content;
    gap: 5px;
    align-content: start;
}

.btn-relais {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 3px 1px;
    border: 1px solid var(--bordure);
    border-radius: 10px;
    background: var(--surface);
    color: var(--texte-doux);
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.btn-relais:active {
    transform: scale(0.95);
}

/* Allumé : le fond entier porte l'information, lisible de loin. */
.btn-relais.allume {
    background: var(--ok);
    border-color: var(--ok);
    color: #06210f;
    font-weight: 600;
}

.btn-relais.refuse {
    border-color: var(--ko);
    animation: refus 320ms ease 2;
}

/* Jamais vu : contour pointillé, ni allumé ni éteint. */
.btn-relais[data-etat='inconnu'] {
    border-style: dashed;
}

.relais-nom {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@keyframes refus {
    50% {
        background: rgb(255 107 107 / 18%);
    }
}

/* --- Tuiles de capteurs ------------------------------------------------- */

.tuiles {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(0, auto);
    gap: 5px;
}

/* Format « ruban » : le nom tient sur une ligne et les deux mesures suivent,
   ce qui divise la hauteur par deux sur une dalle de 480 px. */
.tuile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 4px 6px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--bordure);
    min-width: 0;
    overflow: hidden;
}

/* Valeur vieille de plus de 3 h : la carte s'eteint, on ne lit pas un
   chiffre perime comme s'il etait d'aujourd'hui. */
.tuile.perimee {
    opacity: 0.42;
    border-style: dashed;
}

.tuile-nom {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
    font-weight: 500;
    text-transform: capitalize;
    color: var(--texte-doux);
}

.tuile-mesures {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: center;
    gap: 2px 7px;
    max-width: 100%;
}

.tuile-valeur {
    font-size: 17px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.tuile-valeur small {
    font-size: 10px;
    font-weight: 400;
    color: var(--texte-doux);
    margin-left: 1px;
}

.absente {
    color: var(--bordure);
}

.vide {
    color: var(--texte-doux);
    text-align: center;
    padding: 24px 0;
}

/* --- Lignes de pilotage (diapo, musique) -------------------------------- */

.barres {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 4px 8px calc(env(safe-area-inset-bottom) + 4px);
    background: var(--surface);
    border-top: 1px solid var(--bordure);
}

.barre-transport {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    width: 100%;
    overflow: hidden;
}

.transport-libelle {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 26px;
    font-size: 18px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--texte-doux);
}

/* Cible tactile de 40 px : le minimum tenable au doigt sur cette dalle. */
.tr-btn {
    flex: 0 1 auto;
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    min-width: 0;
    border: 1px solid var(--bordure);
    border-radius: 10px;
    background: var(--surface-haute);
    color: var(--texte);
    font-size: 36px;
    cursor: pointer;
    padding: 0;
}

.tr-btn:active {
    transform: scale(0.94);
}

.tr-btn.danger {
    color: var(--ko);
}

/* Un bouton qui attend confirmation : fond rouge plein, libelle court.
   Deux appuis valent confirmation, pas de fenetre systeme sur la dalle. */
.tr-btn.confirmer {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
    animation: clignote 700ms ease infinite alternate;
}

.tr-btn.confirmer svg {
    display: none;
}

.confirmer-texte {
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
}

@keyframes clignote {
    from {
        opacity: 1;
    }

    to {
        opacity: 0.55;
    }
}

.transport-titre {
    flex: 1 1 0;
    min-width: 0;
    font-size: 19px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 24px;
    color: var(--texte-doux);
}

/* Selecteur de dossier : occupe la place liberee par « aleatoire » disparu. */
.tr-select {
    flex: 1 1 auto;
    min-width: 0;
    height: 42px;
    padding: 0 6px;
    border: 1px solid var(--bordure);
    border-radius: 10px;
    background: var(--surface-haute);
    color: var(--texte);
    font: inherit;
    font-size: 16px;
}

.transport-reponse {
    flex: 0 1 auto;
    max-width: 30%;
    font-size: 17px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 21px;
    color: var(--texte-doux);
}

.transport-reponse.erreur {
    color: var(--ko);
}

/* --- Panneaux (musique, diaporama) -------------------------------------- */

.panneau {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    background: var(--fond);
    padding-top: env(safe-area-inset-top);
}

.panneau[hidden] {
    display: none;
}

.panneau-entete {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--bordure);
}

.panneau-entete h2 {
    margin: 0;
    font-size: 37px;
}

.panneau-entete .btn-icone {
    width: auto;
    padding: 0 14px;
    font-size: 29px;
}

.panneau-corps {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.grille-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.musique-titre {
    margin: 0;
    text-align: center;
    font-size: 36px;
    color: var(--texte-doux);
    min-height: 3em;
    display: grid;
    place-items: center;
    word-break: break-word;
}

.panneau-reponse {
    margin: 0;
    min-height: 1.2em;
    text-align: center;
    font-size: 30px;
    color: var(--texte-doux);
}

.panneau-reponse.erreur {
    color: var(--ko);
}

/* --- Voile d'extinction ------------------------------------------------- */

.voile {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: #000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 48px;
    cursor: pointer;
}

.voile[hidden] {
    display: none;
}

.voile-aide {
    font-size: 27px;
    color: #2a2a2a;
}

/* --- Page état des appareils -------------------------------------------- */

.retour {
    color: var(--accent);
    text-decoration: none;
    font-size: 31px;
}

.liste-appareils {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ligne-appareil {
    padding: 12px;
    border-radius: var(--rayon);
    background: var(--surface);
    border: 1px solid var(--bordure);
}

.ligne-appareil.muet {
    opacity: 0.6;
}

.ligne-entete {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ligne-nom {
    font-weight: 600;
    text-transform: capitalize;
}

.ligne-etat {
    font-size: 26px;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid currentcolor;
}

.ligne-etat.ok {
    color: var(--ok);
}

.ligne-etat.ko {
    color: var(--ko);
}

.ligne-mesures {
    display: flex;
    gap: 16px;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

.ligne-vue {
    margin: 4px 0 0;
    font-size: 27px;
    color: var(--texte-doux);
}

/* --- Grand écran (même page, quatre colonnes) --------------------------- */

@media (min-width: 900px) {
    .tuiles {
        grid-template-columns: minmax(0, 0.9fr) minmax(0, 0.9fr) minmax(0, 1fr) minmax(0, 1.35fr);
    }

    .contenu {
        padding: 20px;
    }
}