/* ---------------------------------------------------------------------------
   Console de supervision. Parti pris : sombre, dense, lisible de loin.
   L'information qui compte a 3 h du matin est l'etat du systeme - il occupe
   donc la moitie superieure de l'ecran et change de couleur, pas de taille.
   --------------------------------------------------------------------------- */

:root {
    --bg: #0a0c10;
    --bg-panel: #12151c;
    --bg-panel-alt: #171b24;
    --border: #242a36;
    --text: #e6e9ef;
    --text-dim: #8b94a7;
    --text-faint: #5a6273;

    --green: #34d399;
    --green-dim: #0f3f33;
    --amber: #fbbf24;
    --amber-dim: #4a3708;
    --red: #f43f5e;
    --red-dim: #4a0f1d;
    --blue: #60a5fa;

    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Grain de moniteur de surveillance. Discret : 3 % d'opacite. */
.scanlines {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    background: repeating-linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.03) 0px,
        rgba(255, 255, 255, 0.03) 1px,
        transparent 1px,
        transparent 3px
    );
}

/* ----------------------------- Barre du haut ----------------------------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-panel);
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 12px var(--green);
    flex-shrink: 0;
}

.topbar h1 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.subtitle {
    margin: 2px 0 0;
    font-size: 12.5px;
    color: var(--text-dim);
}

.subtitle code {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--blue);
    background: rgba(96, 165, 250, 0.1);
    padding: 1px 5px;
    border-radius: 4px;
}

.link-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-dim);
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
}

.link-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--text-faint);
}

.link-status[data-state="connected"] .link-dot {
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
}
.link-status[data-state="connected"] { color: var(--green); }

.link-status[data-state="connecting"] .link-dot {
    background: var(--amber);
    animation: pulse 1.2s ease-in-out infinite;
}
.link-status[data-state="connecting"] { color: var(--amber); }

.link-status[data-state="down"] .link-dot { background: var(--red); }
.link-status[data-state="down"] { color: var(--red); }

/* ------------------------------- Contenu -------------------------------- */

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* --------------------------- Bandeau d'etat ----------------------------- */

.status-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 32px;
    flex-wrap: wrap;
    padding: 32px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-panel);
    transition: background 240ms ease, border-color 240ms ease, box-shadow 240ms ease;
}

.status-eyebrow {
    margin: 0 0 6px;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.status-value {
    margin: 0;
    font-size: clamp(34px, 6vw, 52px);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.05;
    font-family: var(--mono);
}

.status-detail {
    margin: 10px 0 0;
    font-size: 14px;
    color: var(--text-dim);
    max-width: 52ch;
}

/* Desarmee : neutre. Rien ne se passe, rien n'attire l'oeil. */
.status-panel[data-state="DISARMED"] .status-value { color: var(--text-dim); }

/* Armee : vert. Le systeme veille. */
.status-panel[data-state="ARMED"] {
    border-color: var(--green-dim);
    background: linear-gradient(180deg, rgba(52, 211, 153, 0.05), var(--bg-panel));
}
.status-panel[data-state="ARMED"] .status-value { color: var(--green); }

/* Intrusion : rouge, et le panneau entier pulse. */
.status-panel[data-state="TRIGGERED"] {
    border-color: var(--red);
    background: linear-gradient(180deg, rgba(244, 63, 94, 0.14), var(--bg-panel));
    animation: alarm 1.1s ease-in-out infinite;
}
.status-panel[data-state="TRIGGERED"] .status-value {
    color: var(--red);
    text-shadow: 0 0 24px rgba(244, 63, 94, 0.5);
}
.status-panel[data-state="TRIGGERED"] .status-detail { color: #fca5b5; }

@keyframes alarm {
    0%, 100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0); }
    50%      { box-shadow: 0 0 36px 2px rgba(244, 63, 94, 0.3); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.35; }
}

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

.controls { display: flex; gap: 12px; flex-wrap: wrap; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 13px 22px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 120ms ease, background 160ms ease, opacity 160ms ease;
    white-space: nowrap;
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled {
    opacity: 0.32;
    cursor: not-allowed;
}

.btn-icon { font-size: 10px; }

.btn-arm {
    background: var(--green);
    color: #05231a;
}
.btn-arm:hover:not(:disabled) { background: #4ade9f; }

.btn-disarm {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}
.btn-disarm:hover:not(:disabled) {
    background: var(--bg-panel-alt);
    border-color: var(--text-faint);
}

.btn-ghost {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 12.5px;
    cursor: pointer;
    font-family: var(--sans);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-faint); }

/* ------------------------------ Metriques ------------------------------- */

.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
}

.metric {
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--bg-panel);
}

.metric-label {
    margin: 0 0 8px;
    font-size: 11px;
    font-family: var(--mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.metric-value {
    margin: 0;
    font-size: 26px;
    font-weight: 600;
    font-family: var(--mono);
    letter-spacing: -0.02em;
}

.metric-value.small { font-size: 15px; font-weight: 500; color: var(--text-dim); }

/* -------------------------------- Journal ------------------------------- */

.feed-section {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-panel);
    overflow: hidden;
}

.feed-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.feed-header h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.feed {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 420px;
    overflow-y: auto;
}

.feed-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    animation: slide-in 320ms ease;
}

.feed-item:last-child { border-bottom: none; }
.feed-item.acked { opacity: 0.45; }

@keyframes slide-in {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.sev {
    flex-shrink: 0;
    margin-top: 3px;
    width: 8px; height: 8px;
    border-radius: 50%;
}
.sev-LOW      { background: var(--text-faint); }
.sev-MEDIUM   { background: var(--amber); }
.sev-HIGH     { background: var(--red); }
.sev-CRITICAL { background: var(--red); box-shadow: 0 0 10px var(--red); }

.feed-body { flex: 1; min-width: 0; }

.feed-msg {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
}

.feed-meta {
    margin: 4px 0 0;
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--text-faint);
}

.feed-ack {
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 4px 11px;
    border-radius: 7px;
    font-size: 11.5px;
    cursor: pointer;
    font-family: var(--sans);
}
.feed-ack:hover { color: var(--text); border-color: var(--text-faint); }

.feed-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-faint);
    font-size: 13.5px;
}

/* ---------------------------------- Pied -------------------------------- */

footer {
    max-width: 1100px;
    margin: 0 auto;
    padding: 28px 24px 44px;
    text-align: center;
    color: var(--text-faint);
    font-size: 12px;
    line-height: 1.9;
}

footer a { color: var(--text-dim); text-decoration: none; }
footer a:hover { color: var(--blue); }

/* ------------------------------- Mobile --------------------------------- */

@media (max-width: 640px) {
    main { padding: 16px; }
    .status-panel { padding: 24px 20px; }
    .controls { width: 100%; }
    .btn { flex: 1; justify-content: center; }
}

/* ---------------------------------------------------------------------------
   Flux video
   --------------------------------------------------------------------------- */

.video-panel {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-panel);
    overflow: hidden;
}

.video-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    /* Le fond noir doit rester visible meme si la video n'a pas ce ratio :
       une camera de surveillance verticale ne doit pas etre deformee. */
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-frame video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #000;
}

/* --- Voile d'attente, masque des que l'image arrive --- */

.video-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
    padding: 24px;
    background: linear-gradient(180deg, #0d1016, #05070a);
    transition: opacity 400ms ease;
}

.video-panel[data-state="live"] .video-overlay {
    opacity: 0;
    pointer-events: none;
}

.video-overlay-title {
    margin: 0;
    font-family: var(--mono);
    font-size: 14px;
    color: var(--text-dim);
    letter-spacing: 0.02em;
}

.video-overlay-hint {
    margin: 0;
    font-size: 12.5px;
    color: var(--text-faint);
    max-width: 46ch;
    line-height: 1.6;
}

.video-overlay-hint code {
    font-family: var(--mono);
    color: var(--blue);
    background: rgba(96, 165, 250, 0.1);
    padding: 1px 5px;
    border-radius: 4px;
}

.video-panel[data-state="offline"] .video-overlay-title { color: var(--amber); }
.video-panel[data-state="error"]   .video-overlay-title { color: var(--red); }

/* --- Pastille "EN DIRECT" --- */

.video-badge {
    position: absolute;
    top: 14px;
    left: 14px;
    display: none;
    align-items: center;
    gap: 7px;
    padding: 5px 11px;
    border-radius: 999px;
    background: rgba(10, 12, 16, 0.78);
    backdrop-filter: blur(8px);
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: 0.1em;
    color: var(--text);
}

.video-panel[data-state="live"] .video-badge { display: flex; }

.video-badge-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--red);
    box-shadow: 0 0 9px var(--red);
    animation: pulse 1.6s ease-in-out infinite;
}

/* --- Transport reellement utilise (WebRTC ou HLS) --- */

.video-transport {
    position: absolute;
    bottom: 12px;
    right: 14px;
    margin: 0;
    padding: 4px 9px;
    border-radius: 6px;
    background: rgba(10, 12, 16, 0.7);
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--text-faint);
}

.video-transport:empty { display: none; }

/* --- Legende sous l'image --- */

.video-caption {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
}

.video-caption-title {
    margin: 0;
    font-size: 13.5px;
    font-weight: 600;
}

.video-caption-title code {
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--blue);
}

.video-caption-sub {
    margin: 3px 0 0;
    font-size: 12px;
    color: var(--text-faint);
}

/* Quand une intrusion est en cours, le cadre video se souligne en rouge :
   c'est l'image qu'on veut regarder a ce moment precis. */
.status-panel[data-state="TRIGGERED"] ~ .video-panel {
    border-color: var(--red);
    box-shadow: 0 0 28px rgba(244, 63, 94, 0.18);
}
