/* --- CORE VARIABLES --- */
:root {
    --bg-color: #030303;
    --panel-bg: #0a0a0a;
    --surface: #111111;
    
    --border-dim: #333333;
    --border-bright: #555555;
    
    --primary: #ff5e00; 
    --primary-dim: rgba(255, 94, 0, 0.15);
    --primary-glow: rgba(255, 94, 0, 0.4);
    
    --secondary: #00ccff;
    --text-main: #e0e0e0;
    --text-muted: #666666;
    
    --success: #00ff41;
    --danger: #ff003c;
    
    --cut-size: 15px; 
}

/* --- THEMES --- */
body.theme-rust {
    --bg-color: #050404;
    --primary: #ce422b; 
    --primary-dim: rgba(206, 66, 43, 0.15);
    --secondary: #dcb15d; 
}

body.theme-terminal {
    --bg-color: #000900;
    --primary: #33ff00; 
    --primary-dim: rgba(51, 255, 0, 0.1);
    --secondary: #33ff00;
    --text-muted: #1a5c00;
}

body.theme-ninja {
    --bg-color: #050208;
    --primary: #d946ef; 
    --primary-dim: rgba(217, 70, 239, 0.15);
    --secondary: #8b5cf6; 
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: 'Chakra Petch', sans-serif;
    overflow-x: hidden;
    background-image: 
        radial-gradient(circle at 50% 50%, rgba(20, 20, 20, 0.5) 0%, transparent 100%),
        linear-gradient(0deg, rgba(0,0,0,0.2) 50%, transparent 50%);
    background-size: 100% 100%, 100% 4px; 
}

/* --- INDUSTRIAL LIGHTS --- */
.industrial-light {
    width: 14px; height: 14px; border-radius: 50%;
    background: #2a0a0a; border: 1px solid #111;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.8), 0 1px 0 rgba(255,255,255,0.1);
    position: relative; transition: background 0.3s ease;
}
.industrial-light::after {
    content: ''; position: absolute; top: 2px; left: 3px; width: 4px; height: 4px;
    border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0) 70%);
    opacity: 0.6;
}

/* Stan włączony z animacją */
.industrial-light.on {
    background: var(--success);
    border-color: #fff;
    /* Industrial Flicker: Nieregularne mruganie */
    animation: industrialFlicker 4s infinite cubic-bezier(0.1, 0.7, 1.0, 0.1);
}

/* Stan błędu */
.industrial-light.error {
    background: var(--danger);
    box-shadow: 0 0 10px var(--danger), 0 0 20px var(--danger);
    animation: blinkSlow 0.5s infinite;
}

/* Opóźnienie dla drugiej diody, żeby nie mrugały równo (realizm) */
#status-uplink.on {
    animation-delay: 1.3s;
}

/* --- UI COMPONENTS --- */
.tech-panel {
    background: var(--panel-bg); border: 1px solid var(--border-dim);
    position: relative;
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--cut-size)), calc(100% - var(--cut-size)) 100%, 0 100%);
    transition: all 0.3s ease;
}
.tech-panel:hover { border-color: var(--primary-dim); box-shadow: 0 0 20px rgba(0,0,0,0.3); }

.header-glow {
    border-bottom: 1px solid var(--border-dim);
    background: linear-gradient(90deg, rgba(0,0,0,0.9) 0%, rgba(10,10,10,0.95) 50%, rgba(0,0,0,0.9) 100%);
    backdrop-filter: blur(10px);
}

.btn-cyber {
    background: transparent; border: 1px solid var(--primary);
    color: var(--primary); text-transform: uppercase;
    font-family: 'Share Tech Mono', monospace; font-weight: bold; letter-spacing: 2px;
    position: relative; overflow: hidden; transition: all 0.3s;
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}
.btn-cyber::before {
    content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, var(--primary-glow), transparent);
    transition: left 0.5s;
}
.btn-cyber:hover::before { left: 100%; }
.btn-cyber:hover {
    background: var(--primary-dim); box-shadow: 0 0 20px var(--primary-dim);
    text-shadow: 0 0 8px var(--primary); transform: translateY(-2px);
}
.btn-cyber:active { transform: translateY(0); }
.btn-cyber:disabled {
    border-color: var(--border-dim); color: var(--text-muted); cursor: not-allowed;
    background: rgba(0,0,0,0.5); box-shadow: none;
}

.cyber-tab {
    border: 1px solid transparent; color: var(--text-muted);
    clip-path: polygon(10px 0, 100% 0, 100% 100%, 0 100%, 0 10px); transition: all 0.3s;
    position: relative;
}
.cyber-tab::after {
    content: ''; position: absolute; bottom: 0; left: 0; width: 0; height: 2px;
    background: var(--primary); transition: width 0.3s;
}
.cyber-tab:hover { color: var(--text-main); background: rgba(255,255,255,0.05); }
.cyber-tab:hover::after { width: 100%; }
.cyber-tab.active {
    background: var(--panel-bg); border-color: var(--primary); color: var(--primary);
    text-shadow: 0 0 8px var(--primary-dim);
}
.cyber-tab.active::after { width: 100%; }

/* --- CONSOLE --- */
.crt-monitor {
    background: #000; border: 2px solid var(--border-dim);
    font-family: 'Share Tech Mono', monospace; position: relative; overflow: hidden;
}
.crt-line { 
    padding: 2px 8px; 
    border-left: 2px solid transparent; 
    animation: fadeIn 0.3s ease-out;
}
.crt-line.log-system { 
    color: #888; 
    border-left-color: #444;
}
.crt-line.log-uplink { 
    color: #4a9eff; 
    border-left-color: #2d7acc;
    background: rgba(74, 158, 255, 0.05);
}
.crt-line.log-success { 
    color: #00ff88; 
    border-left-color: #00cc6a;
    background: rgba(0, 255, 136, 0.05);
    text-shadow: 0 0 5px rgba(0, 255, 136, 0.3);
}
.crt-line.log-error { 
    color: #ff4466; 
    border-left-color: #cc1133;
    background: rgba(255, 68, 102, 0.05);
}
.crt-line.log-warn { 
    color: #ffaa00; 
    border-left-color: #cc8800;
    background: rgba(255, 170, 0, 0.05);
}
.crt-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 2px, 3px 100%; pointer-events: none; z-index: 10;
}

/* --- SWITCHES --- */
.toggle-rect {
    width: 70px; height: 32px; background: linear-gradient(135deg, #0a0a0a 0%, #000 100%);
    border: 2px solid var(--border-dim); position: relative; cursor: pointer;
    clip-path: polygon(5px 0, 100% 0, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0 100%, 0 5px);
    transition: all 0.3s;
}
.toggle-rect:hover { border-color: var(--border-bright); }
.toggle-rect-indicator {
    width: 28px; height: 24px; background: #222; border: 2px solid #444;
    position: absolute; top: 2px; left: 2px; transition: all 0.3s;
}
.toggle-active { border-color: var(--primary); background: linear-gradient(135deg, var(--primary-dim) 0%, #000 100%); }
.toggle-active .toggle-rect-indicator {
    left: 36px; background: var(--primary); border-color: var(--primary); box-shadow: 0 0 15px var(--primary);
}

/* --- CARDS & CAMERAS --- */
.device-card {
    background: linear-gradient(135deg, var(--surface) 0%, var(--panel-bg) 100%);
    border: 1px solid var(--border-dim); 
    transition: all 0.3s;
    position: relative; 
    overflow: hidden;
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%);
}
.device-card::before {
    content: ''; 
    position: absolute; 
    top: -2px; 
    left: -2px; 
    right: -2px; 
    bottom: -2px;
    background: linear-gradient(135deg, var(--primary-dim), transparent);
    opacity: 0; 
    transition: opacity 0.3s;
    z-index: -1;
}
.device-card:hover::before { 
    opacity: 1; 
}
.device-card:hover { 
    border-color: var(--primary); 
    box-shadow: 0 8px 30px rgba(0,0,0,0.6), 0 0 20px var(--primary-dim); 
    transform: translateY(-5px); 
}
.cam-card.active-ptz { 
    border-color: var(--primary); 
    box-shadow: 0 0 20px var(--primary-dim), inset 0 0 30px var(--primary-dim); 
}

/* --- CRT VIEWPORT STYLE --- */
.cam-viewport {
    background: #000;
    border: 1px solid var(--border-dim);
    transition: all 0.3s;
    position: relative;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.9);
}

.cam-viewport::before {
    content: " ";
    display: block;
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), 
                linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 2px, 3px 100%;
    z-index: 15;
    pointer-events: none;
}

.cam-viewport::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    box-shadow: 0 0 10px var(--primary);
    animation: scan 8s linear infinite;
    z-index: 16;
    pointer-events: none;
    opacity: 0.3;
}

.cam-viewport.active {
    border-color: var(--primary);
    box-shadow: inset 0 0 50px rgba(0,0,0,0.9), 0 0 20px var(--primary-dim);
}

.cam-viewport.active canvas.noise-canvas {
    display: none;
}

.cam-viewport.active .fa-video-slash {
    display: none;
}

/* Glitch effect for switching cameras */
@keyframes glitch {
    0% { clip-path: inset(40% 0 61% 0); transform: translate(-2px, 2px); }
    20% { clip-path: inset(92% 0 1% 0); transform: translate(2px, -2px); }
    40% { clip-path: inset(43% 0 1% 0); transform: translate(-2px, 2px); }
    60% { clip-path: inset(25% 0 58% 0); transform: translate(2px, -2px); }
    80% { clip-path: inset(54% 0 7% 0); transform: translate(-2px, 2px); }
    100% { clip-path: inset(58% 0 43% 0); transform: translate(2px, -2px); }
}

.glitch-anim {
    animation: glitch 0.2s cubic-bezier(.25, .46, .45, .94) both infinite;
    filter: hue-rotate(90deg) saturate(200%);
}

/* --- CANVAS NOISE --- */
canvas.noise-canvas {
    width: 100%; 
    height: 100%; 
    display: block; 
    opacity: 0.15;
    position: absolute; 
    inset: 0; 
    pointer-events: none; 
    z-index: 5;
    mix-blend-mode: hard-light; 
    filter: blur(0.5px) contrast(150%);
}

/* --- MODALS (FIXED) --- */
.modal-panel {
    background: var(--panel-bg); border: 1px solid var(--primary-dim);
    box-shadow: 0 0 60px rgba(0,0,0,0.95), 0 0 30px var(--primary-dim);
    position: relative;
    background-image: 
        linear-gradient(var(--primary), var(--primary)), linear-gradient(var(--primary), var(--primary)),
        linear-gradient(var(--primary), var(--primary)), linear-gradient(var(--primary), var(--primary));
    background-repeat: no-repeat;
    background-size: 2px 20px, 20px 2px;
    background-position: top left, top left, bottom right, bottom right;
}
.modal-header {
    display: flex; align-items: center; gap: 15px; padding-bottom: 20px;
    border-bottom: 1px solid var(--border-dim); margin-bottom: 25px;
}

.modal-icon-box {
    width: 50px; height: 50px; border: 2px solid var(--primary);
    background: var(--primary-dim); display: flex; align-items: center; justify-content: center;
    font-size: 24px; color: var(--primary);
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

.cyber-input {
    width: 100%; background: #050505; border: 1px solid var(--border-dim); color: var(--text-main);
    padding: 14px 16px; font-family: 'Share Tech Mono', monospace; font-size: 13px; outline: none;
    transition: all 0.3s;
}
.cyber-input:focus { 
    border-color: var(--primary); 
    background-color: #000; 
    box-shadow: 0 0 10px var(--primary-dim);
}

.input-label {
    display: flex; justify-content: space-between; font-size: 10px; font-weight: bold;
    color: var(--secondary); margin-bottom: 6px; letter-spacing: 1px; text-transform: uppercase;
}

.config-section {
    background: rgba(0,0,0,0.3); border: 1px solid var(--border-dim);
    padding: 20px; position: relative; margin-bottom: 20px;
}

.config-legend {
    position: absolute; top: -10px; left: 15px;
    background: var(--panel-bg); padding: 0 10px;
    font-size: 9px; font-weight: bold; color: var(--secondary);
    letter-spacing: 2px; font-family: 'Share Tech Mono', monospace;
}

.radio-card {
    border: 1px solid var(--border-dim); background: rgba(255,255,255,0.02);
    padding: 15px; cursor: pointer; transition: all 0.2s; position: relative;
}
.radio-card:hover { border-color: var(--border-bright); background: rgba(255,255,255,0.05); }
.radio-card-input:checked + .radio-card { 
    border-color: var(--primary); 
    background: var(--primary-dim);
    box-shadow: 0 0 15px var(--primary-dim);
}

.wasd-indicator {
    position: fixed; bottom: 20px; right: 20px;
    background: rgba(0,0,0,0.95); border: 2px solid var(--primary);
    padding: 15px; z-index: 50; animation: slideIn 0.3s ease-out;
    box-shadow: 0 0 30px var(--primary-dim);
    backdrop-filter: blur(10px);
}
.wasd-key {
    width: 40px; height: 40px; border: 2px solid var(--border-dim);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Share Tech Mono', monospace; font-weight: bold;
    color: var(--text-muted); background: #000;
    transition: all 0.2s;
}
.wasd-key.active {
    border-color: var(--primary); color: var(--primary); background: var(--primary-dim);
    box-shadow: 0 0 15px var(--primary-dim);
    transform: scale(0.95);
}

.loader-ring {
    width: 120px; height: 120px; border: 2px solid transparent;
    border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite;
}
.loader-ring::before {
    content: ''; position: absolute; top: 5px; left: 5px; right: 5px; bottom: 5px;
    border: 2px solid transparent; border-top-color: var(--secondary); border-radius: 50%;
    animation: spin 3s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.status-badge {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 3px;
    font-size: 9px; font-weight: bold; font-family: 'Share Tech Mono', monospace;
    text-transform: uppercase;
}
.status-badge.online {
    background: rgba(0, 255, 65, 0.1); border: 1px solid var(--success);
    color: var(--success);
}
.status-badge-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: currentColor; animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

#modal-overlay {
    pointer-events: none;
}
#modal-overlay.active {
    pointer-events: auto;
}

.ptz-btn {
    transition: all 0.15s;
}
.ptz-btn:active {
    transform: scale(0.9);
    box-shadow: inset 0 0 10px rgba(0,0,0,0.8);
}

.delete-modal {
    background: var(--panel-bg);
    border: 2px solid var(--danger);
    box-shadow: 0 0 60px rgba(0,0,0,0.95), 0 0 40px rgba(255, 0, 60, 0.3);
    max-width: 420px;
}

.delete-modal-icon {
    width: 60px;
    height: 60px;
    border: 3px solid var(--danger);
    background: rgba(255, 0, 60, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: var(--danger);
    margin: 0 auto 20px;
    animation: pulse 2s infinite;
}

.squad-chat-container {
    background: var(--surface);
    border: 1px solid var(--border-dim);
    padding: 16px;
    margin-top: 24px;
}

.squad-chat-messages {
    background: #000;
    border: 1px solid var(--border-dim);
    height: 200px;
    overflow-y: auto;
    padding: 12px;
    margin-bottom: 12px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
}

.squad-chat-input-group {
    display: flex;
    gap: 8px;
}

.squad-chat-input {
    flex: 1;
    background: #050505;
    border: 1px solid var(--border-dim);
    color: var(--text-main);
    padding: 10px 12px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 12px;
    outline: none;
    transition: all 0.3s;
}

.squad-chat-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--primary-dim);
}

.squad-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    border: 1px dashed var(--border-dim);
    background: rgba(0,0,0,0.3);
}

/* --- ANIMATIONS (KEYFRAMES) --- */
@keyframes glowPulse {
    0%, 100% { boxShadow: 0 0 5px var(--primary), 0 0 10px var(--primary); }
    50% { boxShadow: 0 0 15px var(--primary), 0 0 25px var(--primary); }
}
@keyframes slideIn {
    0% { transform: translateY(-10px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}
@keyframes fadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}
@keyframes modalPop {
    0% { opacity: 0; transform: translate(-50%, -45%) scale(0.95); }
    100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes scan {
    0% { transform: translateY(-100%); }
    100% { transform: translateY(100%); }
}
@keyframes blinkSlow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* NOWA, ULEPSZONA ANIMACJA MRUGANIA DIOD */
@keyframes industrialFlicker {
    0% { opacity: 1; box-shadow: 0 0 10px var(--success), 0 0 20px var(--success), inset 0 0 5px rgba(255,255,255,0.5); }
    3% { opacity: 0.4; box-shadow: 0 0 2px var(--success); }
    5% { opacity: 1; }
    6% { opacity: 0.1; box-shadow: none; } /* Krótki spadek napięcia */
    8% { opacity: 1; box-shadow: 0 0 10px var(--success), 0 0 20px var(--success), inset 0 0 5px rgba(255,255,255,0.5); }
    15% { opacity: 1; }
    30% { opacity: 0.9; }
    32% { opacity: 0.4; } /* Brownout */
    34% { opacity: 1; }
    60% { opacity: 1; }
    62% { opacity: 0.1; box-shadow: none; } /* Prawie zgasło */
    64% { opacity: 1; }
    100% { opacity: 1; }
}