/* =====================================================================
   Supervisor — éditeur admin + vue exploitation
   ===================================================================== */

/* === Layout éditeur === */

.sv-editor {
    display: flex;
    height: calc(100vh - 230px);
    min-height: 520px;
    border-radius: var(--admin-radius);
    overflow: hidden;
    border: 1px solid rgba(147, 180, 245, 0.45);
    box-shadow: var(--admin-shadow);
}

.sv-left {
    width: 220px;
    flex-shrink: 0;
    border-right: 1px solid var(--admin-border);
    background: var(--admin-surface-2);
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sv-main {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #1e1e2e;
    min-width: 0;
}

.sv-right {
    width: 270px;
    flex-shrink: 0;
    border-left: 1px solid var(--admin-border);
    background: var(--admin-surface);
    overflow-y: auto;
    padding: 16px;
}

/* === Panneau gauche === */

.sv-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--admin-muted);
    padding: 4px 2px;
}

.sv-plan-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sv-plan-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid transparent;
    font-size: 0.88rem;
    transition: background 0.15s, border-color 0.15s;
}

.sv-plan-item:hover {
    background: rgba(37, 99, 235, 0.06);
    border-color: rgba(147, 180, 245, 0.4);
}

.sv-plan-item.is-active {
    background: rgba(37, 99, 235, 0.12);
    border-color: rgba(37, 99, 235, 0.35);
    font-weight: 600;
    color: #2563EB;
}

.sv-plan-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sv-plan-delete {
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    padding: 0 2px;
    font-size: 0.9rem;
    line-height: 1;
    flex-shrink: 0;
}

.sv-plan-delete:hover { color: #dc2626; }

.sv-btn-add-plan {
    background: none;
    border: 1px dashed var(--admin-border-strong);
    border-radius: 10px;
    padding: 8px;
    cursor: pointer;
    font-size: 0.84rem;
    color: var(--admin-muted);
    width: 100%;
    text-align: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.sv-btn-add-plan:hover {
    background: rgba(37, 99, 235, 0.06);
    color: var(--admin-link);
    border-color: var(--admin-link);
}

.sv-divider {
    height: 1px;
    background: var(--admin-border);
    margin: 6px 0;
}

/* === Palette === */

.sv-palette {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sv-palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--admin-border);
    background: var(--admin-surface);
    cursor: grab;
    font-size: 0.88rem;
    transition: border-color 0.15s, background 0.15s;
    user-select: none;
}

.sv-palette-item:hover {
    border-color: var(--admin-border-strong);
    background: rgba(37, 99, 235, 0.04);
}

.sv-palette-item:active { cursor: grabbing; }

.sv-palette-item img {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

/* === Canvas === */

.sv-canvas-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 20px;
    box-sizing: border-box;
}

.sv-no-plan {
    color: #6b7280;
    font-size: 1rem;
    text-align: center;
    line-height: 1.7;
}

.sv-canvas {
    position: relative;
    display: inline-block;
    cursor: crosshair;
    user-select: none;
    flex-shrink: 0;
}

.sv-canvas-img {
    display: block;
    max-width: calc(100vw - 560px);
    max-height: calc(100vh - 270px);
    pointer-events: none;
    border-radius: 4px;
}

.sv-elements {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* === Éléments posés sur le plan === */

.sv-elem {
    position: absolute;
    transform: translate(-50%, -50%);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 4px;
    border-radius: 8px;
    border: 2px solid transparent;
    transition: border-color 0.12s, background 0.12s;
    pointer-events: all;
}

.sv-elem:hover {
    border-color: rgba(77, 184, 255, 0.6);
    background: rgba(77, 184, 255, 0.1);
}

.sv-elem.is-selected {
    border-color: #4DB8FF;
    background: rgba(77, 184, 255, 0.15);
}

.sv-elem img { pointer-events: none; }

.sv-elem-label {
    font-size: 0.72rem;
    color: #fff;
    white-space: nowrap;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    font-weight: 600;
    line-height: 1.4;
}

.sv-elem-text {
    color: #fff;
    text-shadow: 0 1px 5px rgba(0,0,0,0.95);
    white-space: nowrap;
    pointer-events: none;
    font-weight: 700;
    background: rgba(0, 0, 0, 0.45);
    padding: 3px 8px;
    border-radius: 4px;
    line-height: 1.4;
}

/* === Panneau config (droite) === */

.sv-form-row {
    margin-bottom: 13px;
}

.sv-form-row label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--admin-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sv-input {
    width: 100%;
    box-sizing: border-box;
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid var(--admin-border);
    background: var(--admin-surface-2);
    font-size: 0.9rem;
    color: var(--admin-text);
    font-family: inherit;
}

.sv-input:focus {
    outline: none;
    border-color: var(--admin-border-strong);
    background: var(--admin-surface);
}

.sv-pos-row {
    display: flex;
    gap: 8px;
}

.sv-pos-row .sv-input {
    text-align: center;
}

.sv-btn-danger {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    color: #dc2626;
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 600;
    width: 100%;
    font-family: inherit;
    margin-top: 4px;
}

.sv-btn-danger:hover { background: #fecaca; }

/* Badges type */
.sv-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.sv-badge-group   { background: #dbeafe; color: #1d4ed8; }
.sv-badge-zone    { background: #fef3c7; color: #92400e; }
.sv-badge-output  { background: #d1fae5; color: #065f46; }
.sv-badge-door    { background: #ede9fe; color: #4c1d95; }
.sv-badge-contact { background: #cffafe; color: #0e7490; }
.sv-badge-camera  { background: #e0f2fe; color: #0369a1; }
.sv-badge-label   { background: #f1f5f9; color: #475569; }

/* === Statut sauvegarde === */

.sv-save-status {
    font-size: 0.85rem;
    padding: 6px 12px;
    border-radius: 8px;
    font-weight: 500;
}

.sv-save-status.is-saving { color: #92400e; background: #fef3c7; }
.sv-save-status.is-saved  { color: #065f46; background: #d1fae5; }
.sv-save-status.is-error  { color: #dc2626; background: #fee2e2; }

/* === Modal === */

.sv-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sv-modal {
    background: var(--admin-surface);
    border-radius: 16px;
    padding: 28px;
    width: min(420px, calc(100% - 40px));
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

/* === Zoom controls === */

.sv-zoom-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(15, 30, 51, 0.82);
    border: 1px solid rgba(77, 184, 255, 0.25);
    border-radius: 10px;
    padding: 4px 8px;
    backdrop-filter: blur(6px);
}

.sv-zoom-btn {
    background: none;
    border: none;
    color: #e2e8f0;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    font-family: inherit;
}

.sv-zoom-btn:hover { background: rgba(77, 184, 255, 0.2); }

.sv-zoom-reset { font-size: 0.95rem; }

#sv-zoom-level {
    font-size: 0.78rem;
    font-weight: 600;
    color: #94a3b8;
    min-width: 38px;
    text-align: center;
}

/* === Choix couleur label === */

.sv-color-choice {
    display: flex;
    gap: 16px;
}

.sv-color-opt {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}

.sv-color-opt input { cursor: pointer; }

/* === Vue exploitation — layout === */

.sv-view-layout {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
}

.sv-view-left {
    width: 190px;
    flex-shrink: 0;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
    background: #f9fafb;
    overflow: hidden;
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.sv-plan-list-wrap {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-bottom: 6px;
}

.sv-options-section {
    flex-shrink: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.10);
    padding-top: 10px;
    padding-bottom: 2px;
}

.sv-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 2px;
    cursor: pointer;
    user-select: none;
}

.sv-toggle-label {
    font-size: 0.78rem;
    color: #4b5563;
}

.sv-toggle-switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    flex-shrink: 0;
}

.sv-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.sv-toggle-knob {
    position: absolute;
    inset: 0;
    background: #d1d5db;
    border-radius: 18px;
    transition: background 0.2s;
    cursor: pointer;
}

.sv-toggle-knob::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.sv-toggle-switch input:checked + .sv-toggle-knob { background: #3b82f6; }
.sv-toggle-switch input:checked + .sv-toggle-knob::before { transform: translateX(14px); }

.sv-view-right {
    width: 210px;
    flex-shrink: 0;
    border-left: 1px solid rgba(0, 0, 0, 0.08);
    background: #f9fafb;
    display: none;
    flex-direction: column;
    padding: 14px 10px;
    gap: 6px;
    overflow: hidden;
}

.sv-view-right.is-open { display: flex; }

.sv-journal-status {
    font-size: 0.70rem;
    color: #9ca3af;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

.sv-journal {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.sv-journal-entry {
    font-size: 0.70rem;
    font-family: monospace;
    color: #4b5563;
    line-height: 1.5;
    padding: 3px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.sv-journal-entry--change { color: #1d4ed8; }
.sv-journal-entry--alarm  { color: #dc2626; font-weight: 600; }

.sv-view-main {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px;
    background: #1a1a2e;
    min-width: 0;
}

.sv-view-main.sv-can-pan  { cursor: grab; }
.sv-view-main.sv-is-panning { cursor: grabbing !important; }

.sv-opt-save-btn {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 5px 8px;
    background: rgba(77, 184, 255, 0.12);
    border: 1px solid rgba(77, 184, 255, 0.30);
    border-radius: 6px;
    color: #4b5563;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s;
}
.sv-opt-save-btn:hover { background: rgba(77, 184, 255, 0.22); }

/* === Bandeau hors ligne === */

.sv-offline-banner {
    background: #fde8e8;
    border-bottom: 1px solid #f5b5b5;
    color: #7a1f1f;
    font-weight: 600;
    text-align: center;
    padding: 10px 16px;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* === Éléments vue exploitation === */

.sv-view-elem {
    cursor: default;
    transition: border-color 0.35s ease, background 0.35s ease;
}

.sv-view-icon {
    cursor: pointer;
}

/* === Menu contextuel === */

.sv-context-menu {
    z-index: 9999;
    min-width: 150px;
    background: #1e2035;
    border: 1px solid rgba(147, 180, 245, 0.35);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
    padding: 6px 0;
    display: flex;
    flex-direction: column;
}

.sv-ctx-title {
    font-size: 0.68rem;
    font-weight: 700;
    color: rgba(180, 190, 220, 0.7);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 12px 6px;
    border-bottom: 1px solid rgba(147, 180, 245, 0.15);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.sv-ctx-btn {
    display: block;
    width: 100%;
    background: none;
    border: none;
    text-align: left;
    padding: 7px 14px;
    font-size: 0.85rem;
    color: #d1d8f0;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

.sv-ctx-btn:hover:not(:disabled) {
    background: rgba(147, 180, 245, 0.12);
    color: #fff;
}

.sv-ctx-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

/* === États des icônes === */

.sv-state--normal   { border-color: rgba(34, 197, 94, 0.45);   background: rgba(34, 197, 94, 0.08); }
.sv-state--armed    { border-color: rgba(234, 179, 8, 0.55);   background: rgba(234, 179, 8, 0.12); }
.sv-state--alarm    { border-color: rgba(239, 68, 68, 0.85);   background: rgba(239, 68, 68, 0.18); animation: sv-pulse-alarm 1.3s ease-in-out infinite; }
.sv-state--open     { border-color: rgba(249, 115, 22, 0.55);  background: rgba(249, 115, 22, 0.10); }
.sv-state--bypass   { border-color: rgba(156, 163, 175, 0.4);  background: rgba(156, 163, 175, 0.06); opacity: 0.72; }
.sv-state--active   { border-color: rgba(239, 68, 68, 0.55);   background: rgba(239, 68, 68, 0.10); }
.sv-state--inactive { border-color: rgba(107, 114, 128, 0.28); background: transparent; }
.sv-state--libre    { border-color: rgba(34, 197, 94, 0.65);   background: rgba(34, 197, 94, 0.14); }
.sv-state--unknown  { border-color: rgba(107, 114, 128, 0.18); opacity: 0.52; }
.sv-state--cam-open { border-color: rgba(77, 184, 255, 0.70);  background: rgba(77, 184, 255, 0.12); }

@keyframes sv-pulse-alarm {
    0%,  100% { border-color: rgba(239, 68, 68, 0.75); background: rgba(239, 68, 68, 0.15); }
    50%        { border-color: rgba(239, 68, 68, 1.00); background: rgba(239, 68, 68, 0.32); }
}

/* === Acquittement alarme === */

.sv-ack-section {
    flex-shrink: 0;
    border-top: 1px solid rgba(239, 68, 68, 0.28);
    padding: 10px 0 2px;
}

.sv-ack-btn {
    display: block;
    width: 100%;
    padding: 7px 10px;
    background: rgba(239, 68, 68, 0.10);
    border: 1px solid rgba(239, 68, 68, 0.45);
    border-radius: 6px;
    color: #dc2626;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
    animation: sv-ack-pulse 2s ease-in-out infinite;
}

.sv-ack-btn:hover {
    background: rgba(239, 68, 68, 0.22);
    border-color: rgba(239, 68, 68, 0.70);
}

@keyframes sv-ack-pulse {
    0%, 100% { background: rgba(239, 68, 68, 0.08); }
    50%       { background: rgba(239, 68, 68, 0.20); }
}

/* === Bouton test connexion caméra (éditeur admin) === */

.sv-btn-test-cam {
    display: block;
    width: 100%;
    padding: 7px 12px;
    background: rgba(3, 105, 161, 0.08);
    border: 1px solid rgba(3, 105, 161, 0.35);
    border-radius: 8px;
    color: #0369a1;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
}

.sv-btn-test-cam:hover {
    background: rgba(3, 105, 161, 0.16);
    border-color: rgba(3, 105, 161, 0.55);
}

/* === Popup flux caméra (vue exploitation) === */

.sv-cam-popup {
    position: fixed;
    z-index: 8000;
    background: #0f1117;
    border: 1px solid rgba(77, 184, 255, 0.45);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.65);
    overflow: hidden;
    user-select: none;
}

.sv-cam-popup-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: rgba(77, 184, 255, 0.10);
    border-bottom: 1px solid rgba(77, 184, 255, 0.20);
    cursor: grab;
}

.sv-cam-popup-bar:active { cursor: grabbing; }

.sv-cam-popup-title {
    flex: 1;
    font-size: 0.78rem;
    font-weight: 600;
    color: #94a3b8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sv-cam-popup-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 1rem;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    padding: 0;
    flex-shrink: 0;
    font-family: inherit;
}

.sv-cam-popup-btn:hover { color: #e2e8f0; background: rgba(255, 255, 255, 0.08); }

.sv-cam-popup-img {
    display: block;
    background: #000;
}
