/* POWERNET Theme System v15 */
/* Public: Light/Dark toggle (mid-right) */
/* Admin: Full theme selector with hamburger menu */
/* v15: Added CSS compatibility layer for legacy --color-* variables */

/* ============================================
   BASE THEME VARIABLES
   ============================================ */

:root {
    --theme-bg: #050508;
    --theme-bg-secondary: #0a0a0f;
    --theme-text: #c8c8c8;
    --theme-text-dim: #4a4a4a;
    --theme-accent-primary: #cc0000;
    --theme-accent-primary-glow: rgba(204, 0, 0, 0.5);
    --theme-accent-secondary: #00d4ff;
    --theme-accent-secondary-glow: rgba(0, 212, 255, 0.3);
    --theme-accent-warning: #ff8800;
    --theme-accent-warning-glow: rgba(255, 136, 0, 0.4);
    --theme-grid: rgba(0, 212, 255, 0.08);
    --theme-panel: rgba(0, 20, 30, 0.9);
    --theme-border: rgba(0, 212, 255, 0.3);
    
    --eye-gradient-start: #ff2200;
    --eye-gradient-mid: #cc0000;
    --eye-gradient-end: #400000;
    --eye-core-start: #ffffff;
    --eye-core-mid: #ffcccc;
    --eye-core-end: #ff8888;
    
    --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* ============================================
   HAL/SKYNET THEME (Default)
   ============================================ */

[data-theme="hal"] {
    --theme-bg: #050508;
    --theme-bg-secondary: #0a0a0f;
    --theme-text: #c8c8c8;
    --theme-text-dim: #4a4a4a;
    --theme-accent-primary: #cc0000;
    --theme-accent-primary-glow: rgba(204, 0, 0, 0.5);
    --theme-accent-secondary: #00d4ff;
    --theme-accent-secondary-glow: rgba(0, 212, 255, 0.3);
    --theme-accent-warning: #ff8800;
    --theme-accent-warning-glow: rgba(255, 136, 0, 0.4);
    --theme-grid: rgba(0, 212, 255, 0.08);
    --theme-panel: rgba(0, 20, 30, 0.9);
    --theme-border: rgba(0, 212, 255, 0.3);
    
    --eye-gradient-start: #ff2200;
    --eye-gradient-mid: #cc0000;
    --eye-gradient-end: #400000;
    --eye-core-start: #ffffff;
    --eye-core-mid: #ffcccc;
    --eye-core-end: #ff8888;
}

/* ============================================
   MR ROBOT THEME
   ============================================ */

[data-theme="mrrobot"] {
    --theme-bg: #0a0a0a;
    --theme-bg-secondary: #0d0d0d;
    --theme-text: #00ff41;
    --theme-text-dim: #006618;
    --theme-accent-primary: #00ff41;
    --theme-accent-primary-glow: rgba(0, 255, 65, 0.4);
    --theme-accent-secondary: #00ff41;
    --theme-accent-secondary-glow: rgba(0, 255, 65, 0.2);
    --theme-accent-warning: #ff3333;
    --theme-accent-warning-glow: rgba(255, 51, 51, 0.4);
    --theme-grid: rgba(0, 255, 65, 0.05);
    --theme-panel: rgba(0, 20, 0, 0.9);
    --theme-border: rgba(0, 255, 65, 0.3);
    
    --eye-gradient-start: #ffffff;
    --eye-gradient-mid: #cccccc;
    --eye-gradient-end: #333333;
    --eye-core-start: #00ff41;
    --eye-core-mid: #00cc33;
    --eye-core-end: #009922;
}

[data-theme="mrrobot"] .primary-text {
    text-shadow: 
        0 0 10px rgba(0, 255, 65, 0.8),
        0 0 20px rgba(0, 255, 65, 0.4);
}

[data-theme="mrrobot"] .hud-corner .label {
    color: var(--theme-accent-primary);
}

/* ============================================
   BREAKING BAD THEME
   ============================================ */

[data-theme="breakingbad"] {
    --theme-bg: #1a1408;
    --theme-bg-secondary: #0f0c05;
    --theme-text: #f5deb3;
    --theme-text-dim: #8b7355;
    --theme-accent-primary: #ffd700;
    --theme-accent-primary-glow: rgba(255, 215, 0, 0.5);
    --theme-accent-secondary: #00ff00;
    --theme-accent-secondary-glow: rgba(0, 255, 0, 0.3);
    --theme-accent-warning: #ff4500;
    --theme-accent-warning-glow: rgba(255, 69, 0, 0.4);
    --theme-grid: rgba(255, 215, 0, 0.06);
    --theme-panel: rgba(30, 20, 10, 0.9);
    --theme-border: rgba(255, 215, 0, 0.3);
    
    --eye-gradient-start: #ffff00;
    --eye-gradient-mid: #ffd700;
    --eye-gradient-end: #8b6914;
    --eye-core-start: #ffffff;
    --eye-core-mid: #ffffcc;
    --eye-core-end: #ffff88;
}

[data-theme="breakingbad"] .primary-text {
    color: var(--theme-text);
    text-shadow: 2px 2px 0 #000, 0 0 20px var(--theme-accent-primary-glow);
}

[data-theme="breakingbad"] .hud-corner .label {
    color: var(--theme-accent-primary);
}

/* ============================================
   LIGHT MODE VARIANTS
   ============================================ */

[data-mode="light"] {
    --theme-bg: #f0f0f0;
    --theme-bg-secondary: #e0e0e0;
    --theme-text: #1a1a1a;
    --theme-text-dim: #666666;
}

[data-theme="hal"][data-mode="light"] {
    --theme-bg: #f5f5f8;
    --theme-bg-secondary: #e8e8ec;
    --theme-text: #1a1a1e;
    --theme-text-dim: #555560;
    --theme-grid: rgba(0, 100, 150, 0.1);
    --theme-panel: rgba(255, 255, 255, 0.95);
    --theme-border: rgba(0, 150, 200, 0.4);
}

[data-theme="mrrobot"][data-mode="light"] {
    --theme-bg: #f0fff0;
    --theme-bg-secondary: #e0ffe0;
    --theme-text: #004400;
    --theme-text-dim: #228822;
    --theme-accent-primary: #008800;
    --theme-accent-primary-glow: rgba(0, 136, 0, 0.3);
    --theme-grid: rgba(0, 100, 0, 0.08);
    --theme-panel: rgba(240, 255, 240, 0.95);
    --theme-border: rgba(0, 136, 0, 0.4);
}

[data-theme="breakingbad"][data-mode="light"] {
    --theme-bg: #fffef0;
    --theme-bg-secondary: #fff8dc;
    --theme-text: #4a3c00;
    --theme-text-dim: #8b7355;
    --theme-accent-primary: #cc9900;
    --theme-accent-primary-glow: rgba(204, 153, 0, 0.4);
    --theme-grid: rgba(200, 150, 0, 0.1);
    --theme-panel: rgba(255, 254, 240, 0.95);
    --theme-border: rgba(204, 153, 0, 0.4);
}

/* ============================================
   CSS COMPATIBILITY LAYER
   Maps legacy --color-* variables to --theme-* variables
   This allows existing pages (yeahnah.html, etc.) to respond to theme changes
   without requiring inline style rewrites
   ============================================ */

/* HAL/SKYNET Theme - Legacy Variable Mapping */
html[data-theme="hal"] {
    --color-bg: var(--theme-bg);
    --color-text: var(--theme-text);
    --color-text-dim: var(--theme-text-dim);
    --color-accent-red: var(--theme-accent-primary);
    --color-accent-red-glow: var(--theme-accent-primary-glow);
    --color-accent-cyan: var(--theme-accent-secondary);
    --color-accent-cyan-glow: var(--theme-accent-secondary-glow);
    --color-accent-amber: var(--theme-accent-warning);
    --color-accent-amber-glow: var(--theme-accent-warning-glow);
    --color-grid: var(--theme-grid);
    --color-terminal: var(--theme-accent-secondary);
    --color-terminal-dim: rgba(0, 212, 255, 0.5);
    --color-warning: var(--theme-accent-primary);
    --color-amber: var(--theme-accent-warning);
    --color-cyan: var(--theme-accent-secondary);
}

/* MR ROBOT Theme - Legacy Variable Mapping */
html[data-theme="mrrobot"] {
    --color-bg: var(--theme-bg);
    --color-text: var(--theme-text);
    --color-text-dim: var(--theme-text-dim);
    --color-accent-red: var(--theme-accent-warning);
    --color-accent-red-glow: var(--theme-accent-warning-glow);
    --color-accent-cyan: var(--theme-accent-primary);
    --color-accent-cyan-glow: var(--theme-accent-primary-glow);
    --color-accent-amber: var(--theme-accent-warning);
    --color-accent-amber-glow: var(--theme-accent-warning-glow);
    --color-grid: var(--theme-grid);
    --color-terminal: var(--theme-accent-primary);
    --color-terminal-dim: rgba(0, 255, 65, 0.5);
    --color-warning: var(--theme-accent-warning);
    --color-amber: var(--theme-accent-warning);
    --color-cyan: var(--theme-accent-primary);
}

/* BREAKING BAD Theme - Legacy Variable Mapping */
html[data-theme="breakingbad"] {
    --color-bg: var(--theme-bg);
    --color-text: var(--theme-text);
    --color-text-dim: var(--theme-text-dim);
    --color-accent-red: var(--theme-accent-warning);
    --color-accent-red-glow: var(--theme-accent-warning-glow);
    --color-accent-cyan: var(--theme-accent-secondary);
    --color-accent-cyan-glow: var(--theme-accent-secondary-glow);
    --color-accent-amber: var(--theme-accent-primary);
    --color-accent-amber-glow: var(--theme-accent-primary-glow);
    --color-grid: var(--theme-grid);
    --color-terminal: var(--theme-accent-primary);
    --color-terminal-dim: rgba(255, 215, 0, 0.5);
    --color-warning: var(--theme-accent-warning);
    --color-amber: var(--theme-accent-primary);
    --color-cyan: var(--theme-accent-secondary);
}

/* Light mode overrides for legacy variables */
html[data-mode="light"] {
    --color-bg: var(--theme-bg);
    --color-text: var(--theme-text);
    --color-text-dim: var(--theme-text-dim);
}

/* ============================================
   SIMPLE MODE TOGGLE (Public Pages - Mid-Right)
   ============================================ */

.mode-toggle-simple {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: var(--theme-panel);
    border: 1px solid var(--theme-border);
    padding: 12px 8px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.6rem;
    opacity: 0.6;
    transition: opacity 0.3s;
}

.mode-toggle-simple:hover {
    opacity: 1;
}

.mode-toggle-simple .mode-toggle-switch {
    position: relative;
    width: 24px;
    height: 44px;
    background: var(--theme-bg-secondary);
    border: 1px solid var(--theme-border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
}

.mode-toggle-simple .mode-toggle-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: var(--theme-accent-secondary);
    border-radius: 50%;
    transition: all 0.3s;
}

.mode-toggle-simple .mode-toggle-switch.light::after {
    top: 23px;
    background: var(--theme-accent-primary);
}

.mode-toggle-simple .mode-label {
    color: var(--theme-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 0.55rem;
}

.mode-toggle-simple .dark-label {
    order: -1;
}

/* ============================================
   SETTINGS TOGGLE BUTTON (Gear Icon)
   ============================================ */

.settings-toggle-btn {
    position: fixed;
    top: 15px;
    right: 15px;
    z-index: 1001;
    width: 44px;
    height: 44px;
    background: var(--theme-panel);
    border: 1px solid var(--theme-border);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    transition: all 0.3s;
    color: var(--theme-accent-secondary);
}

.settings-toggle-btn:hover {
    border-color: var(--theme-accent-secondary);
    box-shadow: 0 0 15px var(--theme-accent-secondary-glow);
    transform: rotate(30deg);
}

.settings-toggle-btn.active {
    background: var(--theme-accent-secondary);
    color: var(--theme-bg);
    transform: rotate(90deg);
}

.settings-toggle-btn svg {
    transition: transform 0.3s;
}

/* ============================================
   SETTINGS RAIL (Collapsible - Hidden by Default)
   ============================================ */

.settings-rail {
    position: fixed;
    top: 0;
    right: 0;
    width: 220px;
    height: 100vh;
    background: var(--theme-bg-secondary);
    border-left: 1px solid var(--theme-border);
    z-index: 1000;
    overflow-y: auto;
    font-family: var(--font-mono);
    transition: transform 0.3s ease;
    transform: translateX(100%);
}

/* Open state - slides in from right */
.settings-rail.open {
    transform: translateX(0);
}

/* Mobile adjustments */
@media (max-width: 767px) {
    .settings-rail {
        width: 280px;
    }
    
    .settings-toggle-btn {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
    }
}

/* Show close button always since panel is collapsible */
.settings-rail.desktop-open .settings-close {
    display: none;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid var(--theme-border);
    background: var(--theme-panel);
}

.settings-title {
    color: var(--theme-accent-secondary);
    font-size: 0.8rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.settings-close {
    background: none;
    border: none;
    color: var(--theme-text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.3s;
}

.settings-close:hover {
    color: var(--theme-accent-warning);
}

.settings-section {
    padding: 15px;
    border-bottom: 1px solid var(--theme-border);
}

.settings-section-title {
    color: var(--theme-text-dim);
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 12px;
}

.theme-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.theme-btn {
    background: transparent;
    border: 1px solid var(--theme-border);
    color: var(--theme-text-dim);
    padding: 10px 12px;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    transition: all 0.3s;
    text-align: left;
}

.theme-btn:hover {
    border-color: var(--theme-accent-secondary);
    color: var(--theme-accent-secondary);
}

.theme-btn.active {
    background: var(--theme-accent-secondary);
    color: var(--theme-bg);
    border-color: var(--theme-accent-secondary);
}

.mode-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mode-toggle-label {
    color: var(--theme-text-dim);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.mode-toggle-switch {
    --toggle-track-w: 44px;
    --toggle-track-h: 22px;
    --toggle-knob: 16px;
    --toggle-pad: 2px;
    position: relative;
    width: var(--toggle-track-w);
    height: var(--toggle-track-h);
    background: var(--theme-bg);
    border: 1px solid var(--theme-border);
    border-radius: calc(var(--toggle-track-h) / 2);
    cursor: pointer;
    transition: all 0.3s;
    overflow: hidden; /* Prevent knob from escaping */
}

.mode-toggle-switch::after {
    content: '';
    position: absolute;
    top: var(--toggle-pad);
    left: var(--toggle-pad);
    width: var(--toggle-knob);
    height: var(--toggle-knob);
    background: var(--theme-accent-secondary);
    border-radius: 50%;
    transition: transform 0.3s, background 0.3s;
    transform: translateX(0);
}

.mode-toggle-switch.light::after {
    /* Move knob to right: track width - knob - padding on both sides - border */
    transform: translateX(calc(var(--toggle-track-w) - var(--toggle-knob) - var(--toggle-pad) * 2 - 2px));
    background: var(--theme-accent-primary);
}

.nav-link {
    display: block;
    color: var(--theme-text-dim);
    text-decoration: none;
    padding: 10px 0;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--theme-border);
    transition: all 0.3s;
}

.nav-link:last-child {
    border-bottom: none;
}

.nav-link:hover {
    color: var(--theme-accent-secondary);
    padding-left: 10px;
}

/* ============================================
   APPLY THEME VARIABLES TO EXISTING STYLES
   ============================================ */

body {
    background-color: var(--theme-bg);
    color: var(--theme-text);
}

.hud-grid {
    background: 
        linear-gradient(90deg, var(--theme-grid) 1px, transparent 1px),
        linear-gradient(0deg, var(--theme-grid) 1px, transparent 1px);
}

.hud-corner {
    color: var(--theme-text-dim);
}

.hud-corner .label {
    color: var(--theme-accent-secondary);
}

.hud-corner .value {
    color: var(--theme-text);
}

.hud-corner .warning {
    color: var(--theme-accent-primary);
}

.hud-corner .caution {
    color: var(--theme-accent-warning);
}

.reticle {
    border-color: var(--theme-accent-secondary);
}

.reticle::before,
.reticle::after {
    background: var(--theme-accent-secondary);
}

.reticle-inner {
    border-color: var(--theme-accent-secondary);
}

.aperture-ring {
    background: conic-gradient(
        from 0deg,
        transparent 0deg,
        var(--theme-accent-secondary-glow) 30deg,
        transparent 60deg,
        transparent 120deg,
        var(--theme-accent-secondary-glow) 150deg,
        transparent 180deg,
        transparent 240deg,
        var(--theme-accent-secondary-glow) 270deg,
        transparent 300deg
    );
}

.eye-housing {
    box-shadow: 
        0 0 80px var(--theme-accent-primary-glow),
        inset 0 0 40px rgba(0, 0, 0, 0.9);
}

.eye-lens {
    background: radial-gradient(circle at 30% 30%, 
        var(--eye-gradient-start) 0%, 
        var(--eye-gradient-mid) 30%, 
        var(--eye-gradient-end) 100%
    );
    box-shadow: 
        0 0 60px var(--theme-accent-primary-glow),
        inset 0 0 30px rgba(0, 0, 0, 0.6);
}

.eye-core {
    background: radial-gradient(circle, 
        var(--eye-core-start) 0%, 
        var(--eye-core-mid) 50%, 
        var(--eye-core-end) 100%
    );
    box-shadow: 
        0 0 30px rgba(255, 255, 255, 0.8),
        0 0 60px var(--theme-accent-primary-glow);
}

.primary-text {
    color: var(--theme-text);
}

.secondary-text {
    color: var(--theme-text-dim);
}

.status-bar {
    background: var(--theme-accent-primary-glow);
    border: 1px solid var(--theme-accent-primary);
}

.status-text {
    color: var(--theme-accent-primary);
}

.action-btn {
    color: var(--theme-text-dim);
    border-color: var(--theme-text-dim);
}

.action-btn:hover {
    color: var(--theme-accent-secondary);
    border-color: var(--theme-accent-secondary);
    box-shadow: 0 0 20px var(--theme-accent-secondary-glow);
}

.sensor-sweep {
    background: linear-gradient(
        to right,
        transparent 0%,
        var(--theme-accent-secondary) 50%,
        transparent 100%
    );
}

/* ============================================
   SETTINGS NOTICE (Admin Panel)
   ============================================ */

.settings-notice {
    background: rgba(255, 136, 0, 0.15);
    border: 1px solid var(--theme-accent-warning);
    color: var(--theme-accent-warning);
    padding: 8px 12px;
    font-size: 0.6rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-align: center;
    margin: 0;
}

/* ============================================
   NOTIFICATION TOAST
   ============================================ */

.settings-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--theme-panel);
    border: 1px solid var(--theme-accent-secondary);
    color: var(--theme-accent-secondary);
    padding: 12px 24px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: 0 0 20px var(--theme-accent-secondary-glow);
}

.settings-notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.settings-notification.error {
    border-color: var(--theme-accent-warning);
    color: var(--theme-accent-warning);
    box-shadow: 0 0 20px var(--theme-accent-warning-glow);
}

/* ============================================
   PER-PAGE SETTINGS (Admin Panel)
   ============================================ */

.page-settings-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.page-settings-item {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--theme-border);
    border-radius: 4px;
    padding: 10px;
}

.page-settings-label {
    color: var(--theme-accent-secondary);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--theme-border);
}

.page-settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 6px;
}

.page-settings-row-label {
    color: var(--theme-text-dim);
    font-size: 0.6rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.page-settings-select {
    background: var(--theme-bg);
    border: 1px solid var(--theme-border);
    color: var(--theme-text);
    padding: 4px 8px;
    font-family: var(--font-mono);
    font-size: 0.6rem;
    cursor: pointer;
    min-width: 120px;
}

.page-settings-select:hover {
    border-color: var(--theme-accent-secondary);
}

.page-settings-select:focus {
    outline: none;
    border-color: var(--theme-accent-secondary);
    box-shadow: 0 0 5px var(--theme-accent-secondary-glow);
}

.loading-text,
.no-pages-text {
    color: var(--theme-text-dim);
    font-size: 0.65rem;
    text-align: center;
    padding: 10px;
}

/* Add margin between global theme buttons and mode toggle */
#global-theme-buttons {
    margin-bottom: 12px;
}

#global-mode-toggle {
    margin-top: 8px;
}

/* ============================================
   RESPONSIVE / MOBILE
   ============================================ */

@media (max-width: 768px) {
    .mode-toggle-simple {
        right: 10px;
        padding: 8px 6px;
    }
    
    .mode-toggle-simple .mode-toggle-switch {
        --toggle-track-w: 20px;
        --toggle-track-h: 36px;
        --toggle-knob: 12px;
        --toggle-pad: 3px;
        width: var(--toggle-track-w);
        height: var(--toggle-track-h);
    }
    
    .mode-toggle-simple .mode-toggle-switch::after {
        width: var(--toggle-knob);
        height: var(--toggle-knob);
        top: var(--toggle-pad);
        left: calc((var(--toggle-track-w) - var(--toggle-knob)) / 2);
        transform: translateY(0);
    }
    
    .mode-toggle-simple .mode-toggle-switch.light::after {
        /* Move knob down for vertical toggle */
        transform: translateY(calc(var(--toggle-track-h) - var(--toggle-knob) - var(--toggle-pad) * 2 - 2px));
    }
    
    .hamburger-menu {
        top: 10px;
        right: 10px;
        width: 36px;
        height: 36px;
    }
}
