/* Supervision graphique (synoptique) - editeur admin + vue tactile (docs/15).
   Reutilise les tokens de v5.css (--navy/--green/--red/--amber/--accent/--border...). */

/* ============================ Etats d'element (icones) ============================ */
.sv-elem { position: absolute; transform: translate(-50%, -50%);
    display: flex; flex-direction: column; align-items: center; gap: 2px; }
.sv-elem img { display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.sv-elem-label { font-size: .72rem; font-weight: 600; line-height: 1.1; white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0,0,0,.7); max-width: 130px; overflow: hidden; text-overflow: ellipsis; }

/* Pastille de couleur d'etat autour de l'icone. */
.sv-view-elem { cursor: pointer; border-radius: 50%; }
.sv-view-elem img { border-radius: 50%; padding: 3px; box-sizing: content-box;
    background: rgba(148,163,184,.25); outline: 2px solid transparent; }
.sv-st-normal  img { background: rgba(22,163,74,.22);  outline-color: #16a34a; }
.sv-st-active  img { background: rgba(22,163,74,.30);  outline-color: #16a34a; }
.sv-st-libre   img { background: rgba(37,99,235,.25);  outline-color: #2563eb; }
.sv-st-armed   img { background: rgba(180,83,9,.28);   outline-color: #b45309; }
.sv-st-bypass  img { background: rgba(202,138,4,.30);  outline-color: #ca8a04; }
.sv-st-alarm   img { background: rgba(220,38,38,.32);  outline-color: #dc2626;
    animation: sv-pulse 1.1s ease-in-out infinite; }
.sv-st-offline img { background: rgba(107,118,137,.30); outline-color: #6b7689; opacity: .8; }
.sv-st-unknown img { background: rgba(107,118,137,.18); outline-color: #cbd5e1; }
.sv-st-action  img { background: rgba(37,99,235,.18);  outline-color: #6366f1; }
.sv-st-cam     img { background: rgba(107,118,137,.20); outline-color: #94a3b8; }
@keyframes sv-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,.5); } 50% { box-shadow: 0 0 0 7px rgba(220,38,38,0); } }

/* Libelle texte libre pose sur le plan (incr. 4) */
.sv-elem-text { font-weight: 700; line-height: 1.15; white-space: nowrap; text-shadow: 0 1px 2px rgba(0,0,0,.7); }

/* ============================ VUE tactile ============================ */
.sv-toolbar { display: flex; align-items: center; gap: 12px; }
.sv-plan-chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; flex: 1 1 auto;
    -webkit-overflow-scrolling: touch; }

/* Reglages des sons (incr. 2) : bouton + popover de cases a cocher */
.sv-sound-wrap { position: relative; flex: 0 0 auto; }
.sv-sound-toggle { cursor: pointer; font: inherit; font-size: .85rem; font-weight: 600;
    padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--card); color: var(--muted); white-space: nowrap; }
.sv-sound-toggle[aria-expanded="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }
.sv-sound-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
    background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,.15); min-width: 200px; display: flex; flex-direction: column; gap: 8px; }
/* L'attribut HTML `hidden` doit l'emporter sur le display:flex ci-dessus (sinon le cadre reste visible). */
.sv-sound-pop[hidden] { display: none; }
.sv-sound-pop label { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--text); cursor: pointer; }

/* Bouton Acquitter (incr. 2) : apparait pendant une alarme, coupe la boucle sonore */
.sv-ack-btn { display: block; width: 100%; margin: 0 0 10px; padding: 12px 14px; cursor: pointer;
    border: none; border-radius: 10px; font: inherit; font-size: .95rem; font-weight: 700;
    background: var(--red); color: #fff; box-shadow: 0 2px 8px rgba(220,38,38,.35);
    animation: sv-pulse 1.1s ease-in-out infinite; }
/* `hidden` doit l'emporter sur le display:block (sinon le bandeau reste affiche en permanence). */
.sv-ack-btn[hidden] { display: none; }
.sv-ack-btn:active { filter: brightness(.92); }
.sv-chip { flex: 0 0 auto; cursor: pointer; font: inherit; font-size: .85rem; font-weight: 600;
    padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--card); color: var(--muted); white-space: nowrap; }
.sv-chip.is-active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ===== Mise en page 3 colonnes (calque v4) : options | plan | journal ===================
   Desktop : options a gauche, plan au centre, journal a droite.
   Mobile/tablette (<=900px, plus bas) : une colonne -> options, plan, PUIS journal sous le plan.
   Les classes .sv-toolbar/.sv-chip/.sv-sound-* restent (utilisees par la DEMO supervision). */
/* Pleine largeur : on « casse » le conteneur centre .app-shell (full-bleed) pour occuper tout l'ecran. */
.sv-fullpage { width: 100vw; margin-left: calc(50% - 50vw); margin-right: calc(50% - 50vw); padding: 0 18px; box-sizing: border-box; }

/* Grille 5 colonnes : [options] [poignee] [plan] [poignee] [journal]. Largeurs des colonnes laterales
   pilotees par des variables -> redimensionnables + memorisees (cf. superviseur_view.js). Hauteur reglee
   en JS pour remplir l'ecran ; 72vh = repli si le JS n'a pas encore tourne. */
.sv-layout { display: grid;
    grid-template-columns: var(--sv-left, 260px) 8px minmax(0, 1fr) 8px var(--sv-right, 340px);
    gap: 0; align-items: stretch; height: 72vh; }
.sv-main { min-width: 0; }  /* autorise le viewer a retrecir dans la grille (sinon debordement) */

/* Poignee de redimensionnement entre deux colonnes (barre discrete, surlignee au survol/drag) */
.sv-gutter { cursor: col-resize; background: transparent; align-self: stretch; position: relative; touch-action: none; }
.sv-gutter::before { content: ""; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 4px; height: 46px; border-radius: 3px; background: var(--border); }
.sv-gutter:hover::before, .sv-gutter.is-drag::before { background: var(--accent); }

/* En-tete supervision sur UNE seule ligne (titre + site/org) -> gagne de la place en haut. */
.sv-header .page-title { font-size: 1.35rem; }
.sv-header .sv-sub { font-weight: 400; font-size: .92rem; color: var(--muted); margin-left: 8px; }

/* Cartes repliables (options + journal). Bouton-fleche `.sv-fold-sum` avec caret ▸ pivotant = le meme
   ressort que « Tout deplier » de la fiche site (evite la fragilite de <details> avec flexbox/hauteur).
   Desktop : bouton masque, cartes toujours deroulees. Mobile : repliables, REPLIEES par defaut (JS). */
.sv-fold-sum { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
    background: none; border: none; cursor: pointer; font-family: inherit; font-weight: 700;
    font-size: .74rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 4px 0; }
.sv-fold-sum:hover { color: var(--accent); }
.sv-fold-sum .caret { display: inline-block; transition: transform .15s ease; }
.sv-fold:not(.is-collapsed) .sv-fold-sum .caret { transform: rotate(90deg); }  /* deplie -> fleche vers le bas */
.sv-fold.is-collapsed .sv-fold-body { display: none; }
.sv-fold-body { display: flex; flex-direction: column; gap: 16px; }
.sv-jr-body { flex: 1 1 auto; min-height: 0; gap: 8px; }
@media (min-width: 901px) {
    /* Desktop : pas de fleche, cartes toujours deroulees (JS retire .is-collapsed). */
    .sv-fold-sum { display: none; }
    /* La ligne de la grille remplit EXACTEMENT la hauteur imposee (JS) : sans ca, la ligne `auto`
       grandit avec le contenu du journal -> les events debordent au lieu de scroller. minmax(0,1fr)
       autorise le retrecissement pour que l'ascenseur interne de .sv-journal reprenne la main. */
    .sv-layout { grid-template-rows: minmax(0, 1fr); }
}

.sv-options { background: var(--card); border: 1px solid var(--border); border-radius: 12px;
    padding: 12px 14px; display: flex; flex-direction: column; gap: 16px; min-height: 0; overflow-y: auto; }
.sv-opt-section { display: flex; flex-direction: column; gap: 8px; }
.sv-opt-title { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.sv-opt-hint { font-size: .74rem; color: var(--muted); margin: 2px 0 0; line-height: 1.3; }

/* Liste des plans de la VUE (classes distinctes de l'editeur .sv-plan-list/.sv-plan-item -> pas de collision) */
.sv-vplans { display: flex; flex-direction: column; gap: 6px; }
.sv-vplan { text-align: left; cursor: pointer; font: inherit; font-size: .86rem; font-weight: 600;
    padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: #fafbfe; color: var(--text); }
.sv-vplan.is-active { background: #dbeafe; color: var(--navy); border-color: var(--accent); }

/* Vues enregistrees (localStorage) : 3 emplacements = rappel (taper) + enregistrement (disquette) */
.sv-views { display: flex; flex-direction: column; gap: 6px; }
.sv-view-slot { display: flex; gap: 6px; align-items: stretch; }
.sv-view-go { flex: 1 1 auto; text-align: left; cursor: pointer; font: inherit; font-size: .84rem; font-weight: 600;
    padding: 7px 11px; border-radius: 8px; border: 1px solid var(--border); background: #fff; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sv-view-go:hover:not(:disabled) { border-color: var(--accent); }
.sv-view-go:disabled { color: var(--muted); background: #f4f6fa; cursor: default; }
.sv-view-save { flex: 0 0 auto; width: 38px; cursor: pointer; font-size: .95rem; line-height: 1;
    border: 1px solid var(--border); border-radius: 8px; background: #eef2fa; color: var(--navy); }
.sv-view-save:hover { background: #dbe4f5; }
.sv-view-save.is-flash { background: var(--green); color: #fff; border-color: var(--green); }

/* Sons (cases integrees a la carte options au lieu du popover) */
.sv-snd-row { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--text); cursor: pointer; }

/* Colonne journal (droite en desktop, sous le plan en mobile) */
/* Pas de height:100% ici : la grille (align-items:stretch) dimensionne deja la carte a la hauteur
   de la ligne EN BORDER-BOX. Un height:100% donnerait 100% en CONTENT-box -> +padding = debordement. */
.sv-journal-col { background: var(--card); border: 1px solid var(--border); border-radius: 12px;
    padding: 12px 14px; display: flex; flex-direction: column; min-height: 0; }
.sv-jr-head { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 6px; }
.sv-jr-status { font-size: .76rem; color: var(--muted); margin-bottom: 8px; }
.sv-journal { flex: 1 1 auto; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
    min-height: 80px; -webkit-overflow-scrolling: touch; }
/* Events en TEXTE BRUT (pas de bulle/cadre, decision Al) : simple separateur entre lignes. */
.sv-jr-row { padding: 5px 2px; font-size: .8rem; line-height: 1.3; border-bottom: 1px solid var(--border); }
.sv-jr-row:last-child { border-bottom: none; }
.sv-jr-row.is-alarm .sv-jr-label { color: var(--red); font-weight: 600; }
.sv-jr-time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 6px; }
.sv-jr-cu { font-weight: 600; color: var(--text); }
.sv-jr-sia { color: var(--muted); font-size: .72rem; }
.sv-jr-label { display: block; margin-top: 2px; color: var(--text); }
.sv-jr-empty { color: var(--muted); font-size: .8rem; font-style: italic; }
/* Acquitter, deplace dans la colonne journal (au lieu de pleine largeur au-dessus du plan) */
.sv-journal-col .sv-ack-btn { margin: 10px 0 0; }

.sv-viewer { position: relative; width: 100%; height: 72vh; overflow: hidden;
    background: #0c1626; border: 1px solid var(--border); border-radius: 12px;
    touch-action: none; user-select: none; }
/* Dans la grille supervision, le plan remplit la hauteur de la colonne (reglee en JS). */
.sv-main .sv-viewer { height: 100%; }
.sv-stage { position: absolute; top: 0; left: 0; width: 100%; transform-origin: 0 0; }
.sv-stage-img { display: block; width: 100%; height: auto; pointer-events: none; }
.sv-elements { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

.sv-zoom-fab { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
.sv-zoom-fab button { width: 40px; height: 40px; border-radius: 10px; border: none; cursor: pointer;
    background: rgba(15,30,51,.85); color: #fff; font-size: 1.3rem; line-height: 1;
    display: flex; align-items: center; justify-content: center; }
.sv-zoom-fab button:active { background: var(--navy); }

/* Bottom-sheet (feuille d'action) */
.sv-sheet-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 60; }
.sv-sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
    background: var(--card); border-radius: 18px 18px 0 0; padding: 10px 18px 22px;
    box-shadow: 0 -8px 30px rgba(0,0,0,.22); max-width: 720px; margin: 0 auto;
    animation: sv-sheet-up .18s ease-out; }
@keyframes sv-sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sv-sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: #cbd5e1; margin: 2px auto 12px; }
.sv-sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sv-sheet-name { font-weight: 700; font-size: 1.05rem; color: var(--text);
    display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.sv-sheet-state { font-size: .85rem; color: var(--muted); margin-top: 2px; padding: 2px 0; }
.sv-sheet-state.sv-st-alarm { color: var(--red); font-weight: 600; animation: none; }
.sv-sheet-close { background: none; border: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); }
.sv-sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.sv-sheet-actions .btn { width: 100%; text-align: center; padding: 13px 10px; font-size: .95rem;
    background: #eef2fa; color: var(--navy); border: 1px solid var(--border); }
.sv-sheet-actions .btn.is-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.sv-sheet-actions .btn:disabled { opacity: .5; }
.sv-sheet-empty { grid-column: 1 / -1; color: var(--muted); font-size: .85rem; font-style: italic; margin: 4px 0 0; }
.sv-sheet-verdict { min-height: 18px; margin-top: 10px; font-size: .85rem; text-align: center; }
.sv-sheet-verdict.is-pending { color: var(--muted); }
.sv-sheet-verdict.is-ok { color: var(--green); }
.sv-sheet-verdict.is-ko { color: var(--red); }

/* ============================ EDITEUR admin ============================ */
.sv-editor { display: grid; grid-template-columns: 210px 1fr 240px; gap: 14px; align-items: start; }
.sv-ed-left { display: flex; flex-direction: column; gap: 14px; }
.sv-ed-block { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.sv-ed-block-head { display: flex; align-items: center; justify-content: space-between;
    font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .4px;
    color: var(--muted); margin-bottom: 10px; }
.sv-ed-hint { font-size: .78rem; color: var(--muted); margin: 0 0 8px; }

.sv-plan-list { display: flex; flex-direction: column; gap: 6px; }
.sv-plan-item { display: flex; align-items: center; justify-content: space-between; gap: 6px;
    padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: #fafbfe; }
.sv-plan-item.is-active { border-color: var(--accent); background: #eef2fa; }
.sv-plan-item-name { font-size: .86rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sv-plan-del { background: none; border: none; cursor: pointer; color: var(--muted); font-size: .9rem; padding: 2px 4px; }
.sv-plan-del:hover { color: var(--red); }

.sv-palette { display: flex; flex-direction: column; gap: 10px; max-height: 64vh; overflow-y: auto; }
.sv-pal-section-title { font-size: .74rem; font-weight: 600; color: var(--muted); margin: 2px 0 4px; }
.sv-pal-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border);
    border-radius: 8px; background: #fff; cursor: grab; margin-bottom: 4px; }
.sv-pal-item:hover { border-color: var(--accent); }
.sv-pal-icon { width: 22px; height: 22px; flex: 0 0 auto; }
.sv-pal-label { font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sv-pal-label em { color: var(--muted); font-style: normal; font-size: .76rem; }

.sv-ed-center { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.sv-ed-toolbar { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.sv-zoom-btn { width: 30px; height: 30px; border: 1px solid var(--border); background: #fff; border-radius: 7px;
    cursor: pointer; font-size: 1rem; line-height: 1; color: var(--text); }
.sv-zoom-btn:hover { border-color: var(--accent); }
#sv-zoom-level { min-width: 44px; text-align: center; font-size: .82rem; font-weight: 600; color: var(--muted); }
.sv-ed-canvas-wrap { position: relative; overflow: auto; background: #0c1626; border-radius: 8px; min-height: 74vh; max-height: 86vh; }
.sv-no-plan { padding: 40px 16px; text-align: center; color: #94a3b8; font-size: .9rem; }
.sv-canvas { position: relative; display: inline-block; }
.sv-canvas-img { display: block; max-width: 100%; }
.sv-editor-elements { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.sv-editor-elem { cursor: grab; }
.sv-editor-elem.is-selected img { outline: 2px solid var(--accent); border-radius: 6px; }

.sv-ed-right { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.sv-form-row { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.sv-form-row > label { font-size: .78rem; font-weight: 600; color: var(--muted); }
.sv-input { font: inherit; padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; background: #fff; color: var(--text); width: 100%; box-sizing: border-box; }
.sv-ro { font-size: .85rem; color: var(--text); background: #f4f6fa; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }
.sv-color-choice { display: flex; gap: 12px; flex-wrap: wrap; font-size: .82rem; }
.sv-color-choice label { display: inline-flex; align-items: center; gap: 4px; }
.sv-pos-row { display: flex; gap: 8px; }
.sv-btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; width: 100%; margin-top: 4px; }
.sv-btn-danger:hover { background: #fecaca; }
.sv-badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .76rem; font-weight: 600; margin-bottom: 12px;
    background: #eef2fa; color: var(--navy); }
.sv-badge-access { background: #dbeafe; color: #1e40af; }
.sv-badge-group  { background: #ede9fe; color: #5b21b6; }
.sv-badge-input  { background: #fef3c7; color: #92600c; }
.sv-badge-output { background: #dcfce7; color: #166534; }
.sv-badge-action { background: #e0e7ff; color: #3730a3; }
.sv-badge-camera { background: #e2e8f0; color: #334155; }
.sv-badge-label  { background: #f1f5f9; color: #475569; }

.sv-save-status { font-size: .82rem; }
.sv-save-status.is-saving { color: var(--muted); }
.sv-save-status.is-saved { color: var(--green); }
.sv-save-status.is-error { color: var(--red); }

/* Modale d'ajout de plan */
.sv-modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 70; display: flex; align-items: center; justify-content: center; padding: 16px; }
.sv-modal { background: var(--card); border-radius: 12px; padding: 20px; width: 100%; max-width: 420px; }
.sv-modal h3 { margin: 0 0 14px; }
.sv-modal-error { color: var(--red); font-size: .85rem; margin: 8px 0; }
.sv-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ============================ Responsive (mobile) ============================ */
@media (max-width: 900px) {
    .sv-editor { grid-template-columns: 1fr; }
    .sv-ed-right { position: sticky; bottom: 0; }
    /* Vue : une colonne empilee (ordre DOM = options, plan, journal -> journal sous le plan).
       On annule le full-bleed, les poignees et la hauteur imposee en JS (colonnes empilees). */
    .sv-fullpage { width: auto; margin-left: 0; margin-right: 0; padding: 0; }
    .sv-layout { grid-template-columns: 1fr; height: auto !important; }
    .sv-gutter { display: none; }
    .sv-main .sv-viewer { height: 64vh; }
    .sv-journal-col { height: auto; max-height: 46vh; }
}
@media (max-width: 640px) {
    .sv-viewer { height: 64vh; }
    .sv-sheet-actions { grid-template-columns: 1fr; }
}
