/* ============================================================================
   Kernel 3D Visualizer - CSS Styles
   ============================================================================ */

:root {
    --bg-primary: #0a0a12;
    --bg-secondary: #12121f;
    --bg-panel: rgba(15, 15, 25, 0.9);
    --text-primary: #ecf0f1;
    --text-secondary: #95a5a6;
    --accent-kernel: #ff6b6b;
    --accent-cpu: #45b7d1;
    --accent-memory: #4ecdc4;
    --accent-network: #3498db;
    --accent-ebpf: #9b59b6;
    --accent-process: #ecf0f1;
    --border-color: rgba(255, 255, 255, 0.1);
    --glow-color: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    text-align: center;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-kernel);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader h2 {
    color: var(--text-primary);
    margin-bottom: 10px;
}

.loader p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.progress-bar {
    width: 300px;
    height: 4px;
    background: var(--bg-secondary);
    border-radius: 2px;
    overflow: hidden;
}

.progress {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-kernel), var(--accent-cpu));
    width: 0%;
    transition: width 0.3s ease;
}

/* Canvas */
#kernel-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* UI Overlay */
#ui-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

/* Panels */
.panel {
    pointer-events: auto;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.panel h3 {
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.panel.collapsed {
    max-height: 50px;
    overflow: hidden;
}

/* Navigation Panel */
#nav-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 220px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-kernel) var(--bg-secondary);
}

#nav-panel::-webkit-scrollbar {
    width: 6px;
}

#nav-panel::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 3px;
}

#nav-panel::-webkit-scrollbar-thumb {
    background: var(--accent-kernel);
    border-radius: 3px;
}

.zone-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.zone-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    margin-bottom: 4px;
}

.zone-group .group-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.zone-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 12px;
}

.zone-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--zone-color);
    box-shadow: 0 0 15px rgba(var(--zone-color), 0.3);
    transform: translateX(-2px);
}

.zone-btn.active {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--zone-color);
    box-shadow: 0 0 20px var(--zone-color);
}

.zone-btn .icon {
    font-size: 14px;
}

/* Stats Panel */
#stats-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 250px;
}

.stats-grid {
    display: grid;
    gap: 12px;
}

.stat-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    width: 80px;
}

.stat-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
}

.stat-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.cpu-fill {
    background: linear-gradient(90deg, var(--accent-cpu), #2980b9);
}

.mem-fill {
    background: linear-gradient(90deg, var(--accent-memory), #16a085);
}

.stat-value {
    font-size: 14px;
    font-weight: bold;
    min-width: 50px;
    text-align: left;
}

/* Info Panel */
#info-panel {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 300px;
}

#zone-title {
    font-size: 18px;
}

#zone-description {
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 10px;
}

.details {
    font-size: 11px;
    color: var(--text-secondary);
    max-height: 150px;
    overflow-y: auto;
}

/* Registers Panel */
#registers-panel {
    position: absolute;
    top: 200px;
    left: 20px;
    width: 250px;
}

.register-grid {
    display: grid;
    gap: 8px;
}

.register {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
}

.reg-name {
    color: var(--accent-cpu);
    font-weight: bold;
    font-size: 11px;
}

.reg-value {
    color: var(--text-primary);
    font-size: 10px;
}

/* Logs Panel Enhanced */
#logs-panel {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 500px;
    max-height: 300px;
}

#logs-panel.collapsed {
    max-height: 50px;
}

.logs-scroll {
    max-height: 220px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    background: #0a0a0a;
    padding: 8px;
    border-radius: 4px;
}

.log-entry {
    padding: 2px 6px;
    margin: 1px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.log-info {
    color: #27ae60;
}

.log-warn {
    color: #f39c12;
}

.log-error {
    color: #e74c3c;
}

.logs-scroll::-webkit-scrollbar {
    width: 6px;
}

.logs-scroll::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* Process List */
.process-list {
    font-family: 'Courier New', monospace;
    font-size: 10px;
}

.process-header {
    display: grid;
    grid-template-columns: 50px 80px 40px 50px 60px;
    gap: 5px;
    padding: 4px;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-bottom: 4px;
    color: var(--accent-cpu);
    font-weight: bold;
}

.process-row {
    display: grid;
    grid-template-columns: 50px 80px 40px 50px 60px;
    gap: 5px;
    padding: 3px 4px;
    border-bottom: 1px solid var(--border-color);
}

.process-row:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Controls Help */
#controls-help {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
}

#controls-help.small {
    padding: 8px 15px;
}

.control {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-secondary);
}

kbd {
    padding: 2px 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 10px;
}

/* FPS Counter */
#fps-counter {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-panel);
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 12px;
    border: 1px solid var(--border-color);
}

#fps-value {
    color: var(--accent-memory);
    font-weight: bold;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

/* Animations */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 10px var(--zone-color); }
    50% { box-shadow: 0 0 25px var(--zone-color); }
}

/* ============================================================================
   Responsive Design & Accessibility
   ============================================================================ */

/* الشاشات الصغيرة (الهواتف) */
@media (max-width: 768px) {
    /* لوحة التنقل - قابلة للطي */
    #nav-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 50vh;
        padding: 10px;
        border-radius: 20px 20px 0 0;
        z-index: 1000;
        transform: translateY(calc(100% - 50px));
        transition: transform 0.3s ease;
    }
    
    #nav-panel:hover,
    #nav-panel:focus-within,
    #nav-panel.expanded {
        transform: translateY(0);
    }
    
    #nav-panel::before {
        content: '☰ التنقل';
        display: block;
        text-align: center;
        padding: 8px;
        margin: -10px -10px 10px -10px;
        background: linear-gradient(90deg, rgba(255,107,107,0.3), rgba(69,183,209,0.3));
        border-radius: 20px 20px 0 0;
        font-size: 14px;
        cursor: pointer;
    }
    
    #nav-panel h3 {
        display: none;
    }
    
    .zone-buttons {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 8px;
        max-height: 35vh;
        overflow-y: auto;
    }
    
    .zone-group {
        display: contents;
    }
    
    .zone-group .group-label {
        display: none;
    }
    
    .zone-btn {
        padding: 10px 8px;
        font-size: 11px;
        flex-direction: column;
        gap: 4px;
    }
    
    .zone-btn span:not(.icon) {
        display: block;
        font-size: 9px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .zone-btn .icon {
        font-size: 18px;
    }
    
    /* اللوحات الأخرى */
    #stats-panel {
        top: 10px;
        left: 10px;
        width: calc(50% - 15px);
        font-size: 11px;
        padding: 8px;
    }
    
    #info-panel {
        top: 10px;
        right: 10px;
        width: calc(50% - 15px);
        font-size: 11px;
        padding: 8px;
    }
    
    #photon-stats-panel {
        top: auto;
        bottom: 60px;
        left: 10px;
        width: calc(50% - 15px);
        font-size: 10px;
    }
    
    #logs-panel {
        width: 95%;
        left: 2.5%;
        bottom: 60px;
        max-height: 30vh;
    }
    
    #controls-help {
        display: none;
    }
    
    #view-switcher {
        top: auto;
        bottom: 55px;
        right: 10px;
        padding: 8px;
    }
    
    #view-switcher h4 {
        font-size: 11px;
    }
    
    .view-btn {
        padding: 8px 12px;
        font-size: 11px;
    }
    
    /* إخفاء العناوين في الوضع المضغوط */
    .panel h3, .panel h4 {
        font-size: 12px;
        margin-bottom: 8px;
    }
    
    /* تحسين التمرير */
    .panel {
        -webkit-overflow-scrolling: touch;
    }
}

/* الشاشات الصغيرة جداً (الهواتف الصغيرة) */
@media (max-width: 480px) {
    #nav-panel {
        max-height: 60vh;
    }
    
    .zone-buttons {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .zone-btn span:not(.icon) {
        display: none;
    }
    
    #stats-panel,
    #info-panel {
        width: 100%;
        position: relative;
        top: 0;
        left: 0;
        right: 0;
        margin: 5px;
    }
    
    #ui-overlay {
        display: flex;
        flex-direction: column;
        padding: 5px;
    }
    
    #photon-stats-panel {
        display: none;
    }
}

/* تحسينات إمكانية الوصول */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* وضع التباين العالي */
@media (prefers-contrast: high) {
    .panel {
        border-width: 2px;
        border-color: #fff;
    }
    
    .zone-btn {
        border-width: 2px;
    }
    
    .zone-btn:focus {
        outline: 3px solid #fff;
        outline-offset: 2px;
    }
}

/* دعم لوحة المفاتيح */
.zone-btn:focus,
.view-btn:focus,
button:focus {
    outline: 2px solid #00c8ff;
    outline-offset: 2px;
}

/* تحسين القراءة */
.panel {
    line-height: 1.4;
}

/* زر طي/فتح للوحات */
.panel-toggle {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.panel-toggle:hover {
    background: rgba(255,255,255,0.2);
}

.panel.minimized {
    height: 40px;
    overflow: hidden;
}

.panel.minimized > *:not(h3):not(h4):not(.panel-toggle) {
    display: none;
}

/* ============================================================================
   Photon Stats Panel Styles
   ============================================================================ */

#photon-stats-panel {
    position: absolute;
    top: 400px;
    left: 20px;
    width: 250px;
}

.photon-stats-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.photon-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: 6px;
}

.photon-stat .stat-icon {
    font-size: 16px;
}

.photon-stat .stat-label {
    flex: 1;
    font-size: 11px;
    color: var(--text-secondary);
}

.photon-stat .stat-value {
    font-size: 14px;
    font-weight: bold;
    color: var(--accent-cpu);
    font-family: 'Courier New', monospace;
}

.photon-legend {
    display: flex;
    justify-content: space-between;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 9px;
    color: var(--text-secondary);
}

.legend-item .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.dot.fast {
    background: #00ffff;
    box-shadow: 0 0 5px #00ffff;
}

.dot.normal {
    background: #44ff44;
    box-shadow: 0 0 5px #44ff44;
}

.dot.slow {
    background: #ff4444;
    box-shadow: 0 0 5px #ff4444;
}

/* View Switcher */
#view-switcher {
    position: fixed;
    bottom: 80px;
    left: 10px;
    z-index: 100;
}

#view-switcher h3 {
    margin-bottom: 10px;
    font-size: 12px;
}

.view-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 15px;
    background: linear-gradient(135deg, rgba(69, 183, 209, 0.2), rgba(52, 152, 219, 0.2));
    border: 1px solid var(--accent-cpu);
    border-radius: 8px;
    color: var(--accent-cpu);
    text-decoration: none;
    margin-bottom: 8px;
    transition: all 0.3s ease;
    font-size: 12px;
}

.view-btn:hover {
    background: linear-gradient(135deg, rgba(69, 183, 209, 0.4), rgba(52, 152, 219, 0.4));
    transform: translateX(5px);
    box-shadow: 0 0 15px rgba(69, 183, 209, 0.3);
}

.view-btn .icon {
    font-size: 16px;
}

.current-view {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 15px;
    background: rgba(78, 205, 196, 0.15);
    border: 1px solid var(--accent-memory);
    border-radius: 8px;
    color: var(--accent-memory);
    font-size: 12px;
    opacity: 0.7;
}

.current-view .icon {
    font-size: 16px;
}

/* ============================================================================
   Simulation Controls Panel
   ============================================================================ */

#sim-controls {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 150;
    min-width: 350px;
}

#sim-controls h3 {
    text-align: center;
    margin-bottom: 15px;
}

.control-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 15px;
}

.ctrl-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 12px;
}

.ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--accent-cpu);
}

.ctrl-btn.active {
    background: rgba(69, 183, 209, 0.3);
    border-color: var(--accent-cpu);
    box-shadow: 0 0 10px rgba(69, 183, 209, 0.3);
}

.ctrl-btn.paused {
    background: rgba(231, 76, 60, 0.3);
    border-color: #e74c3c;
}

.ctrl-btn .icon {
    font-size: 14px;
}

.speed-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: 6px;
}

.speed-indicator .label {
    color: var(--text-secondary);
    font-size: 11px;
}

.speed-indicator .value {
    color: var(--accent-cpu);
    font-weight: bold;
    font-size: 14px;
    min-width: 40px;
}

.speed-bar {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.speed-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-memory), var(--accent-cpu));
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* ============================================================================
   Panel Minimize/Maximize System - نظام تصغير وتكبير اللوحات
   ============================================================================ */

/* زر التصغير/التكبير للوحات */
.panel-minimize-btn {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 22px;
    height: 22px;
    background: rgba(69, 183, 209, 0.2);
    border: 1px solid var(--accent-cpu);
    border-radius: 4px;
    color: var(--accent-cpu);
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

.panel-minimize-btn:hover {
    background: rgba(69, 183, 209, 0.4);
    transform: scale(1.1);
}

/* لوحة مصغرة */
.panel.minimized {
    min-height: 35px !important;
    max-height: 35px !important;
    overflow: hidden;
}

.panel.minimized > *:not(h3):not(.panel-minimize-btn):not(.panel-header) {
    display: none !important;
}

.panel.minimized h3 {
    margin: 0;
    padding: 8px 12px 8px 35px;
}

/* ترويسة اللوحة مع زر التصغير */
.panel h3 {
    position: relative;
    padding-right: 30px;
}

/* نظام السحب والإفلات */
.panel.draggable {
    cursor: move;
}

.panel.draggable h3,
.panel.draggable .panel-header {
    cursor: move;
    user-select: none;
}

.panel.is-dragging {
    opacity: 0.9;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    transition: none;
}

/* ============================================================================
   Audio Control Panel - لوحة التحكم بالصوت المتقدم
   ============================================================================ */

#advanced-audio-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 280px;
    z-index: 1000;
}

#advanced-audio-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: linear-gradient(135deg, rgba(155, 89, 182, 0.3), rgba(142, 68, 173, 0.3));
    border-bottom: 1px solid #9b59b6;
}

#advanced-audio-panel .panel-header h4 {
    margin: 0;
    font-size: 12px;
    color: #9b59b6;
}

.audio-section {
    margin: 10px 0;
    padding: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
}

.audio-section-title {
    font-size: 11px;
    color: var(--accent-cpu);
    margin-bottom: 8px;
    display: block;
    font-weight: bold;
}

/* مستويات الصوت الثلاثة */
.volume-level {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 0;
}

.volume-level label {
    flex: 0 0 60px;
    font-size: 10px;
    color: var(--text-secondary);
}

.volume-level input[type="range"] {
    flex: 1;
    height: 4px;
    accent-color: var(--accent-cpu);
}

.volume-level .volume-value {
    flex: 0 0 35px;
    font-size: 10px;
    text-align: right;
    color: var(--text-primary);
}

/* Toggle للصوت المكاني */
.audio-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.audio-toggle label {
    font-size: 11px;
    color: var(--text-secondary);
}

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle-switch.active {
    background: var(--accent-memory);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
}

.toggle-switch.active::after {
    transform: translateX(16px);
}

/* الإعدادات المسبقة للصوت */
.audio-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.preset-btn {
    flex: 1;
    min-width: 60px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 9px;
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover {
    background: rgba(69, 183, 209, 0.2);
    border-color: var(--accent-cpu);
    color: var(--accent-cpu);
}

.preset-btn.active {
    background: var(--accent-cpu);
    color: var(--bg-panel);
    border-color: var(--accent-cpu);
}
