/**
 * Tên file: style.css
 * Phiên bản: v4.0.0 (Enhanced Dashboard UI/UX)
 * Ngày sửa đổi: 25/12/2024
 * Nội dung sửa lần gần nhất:
 * - Cải tiến toàn bộ giao diện dashboard với modern design
 * - Tối ưu hóa responsive design và mobile experience
 * - Enhanced visual hierarchy và accessibility
 * - Improved performance với GPU acceleration
 */

/* Root Variables for Consistent Design System */
:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --success-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --warning-gradient: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --error-gradient: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    --surface-elevation-1: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    --surface-elevation-2: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
    --surface-elevation-3: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
    --border-radius-sm: 6px;
    --border-radius-md: 8px;
    --border-radius-lg: 12px;
    --border-radius-xl: 16px;
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base Styles with Performance Optimization */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    overflow: hidden;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
    font-variant-numeric: oldstyle-nums;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Enhanced Scrollbar Styling */
.scrollbar-hide {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

/* Custom Scrollbar for containers */
.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: rgba(156, 163, 175, 0.5) transparent;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.5);
    border-radius: 3px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 0.8);
}

/* Enhanced Animation System */
.log-entry {
    animation: slideInUp 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Enhanced Theme Toggle */
#theme-toggle svg {
    transition: transform var(--transition-normal), opacity var(--transition-normal);
    will-change: transform, opacity;
}

#moon-icon {
    transform: scale(1) rotate(0deg);
    opacity: 1;
    position: absolute;
}

#sun-icon {
    transform: scale(0) rotate(-90deg);
    opacity: 0;
    position: absolute;
}

.dark #moon-icon {
    transform: scale(0) rotate(90deg);
    opacity: 0;
}

.dark #sun-icon {
    transform: scale(1) rotate(0deg);
    opacity: 1;
}

/* Enhanced Data Flow Animations */
.path-line.connected {
    animation: dataFlow 2s linear infinite;
    background-image: linear-gradient(90deg, transparent 40%, rgba(59, 130, 246, 0.6) 50%, transparent 60%);
    background-size: 40px 100%;
    will-change: background-position;
}

@keyframes dataFlow {
    from { background-position: 40px 0; }
    to { background-position: 0 0; }
}

.packet {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    opacity: 0.9;
    will-change: left, opacity, transform, box-shadow;
    z-index: 10;
}

.packet-out {
    background: radial-gradient(circle, #3b82f6 0%, #1d4ed8 100%);
    box-shadow: 
        0 0 12px rgba(59, 130, 246, 0.8), 
        0 0 6px rgba(59, 130, 246, 0.6),
        inset 0 0 4px rgba(255, 255, 255, 0.3);
    animation: flowToServer 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.packet-in {
    background: radial-gradient(circle, #ef4444 0%, #dc2626 100%);
    box-shadow: 
        0 0 12px rgba(239, 68, 68, 0.8), 
        0 0 6px rgba(239, 68, 68, 0.6),
        inset 0 0 4px rgba(255, 255, 255, 0.3);
    animation: flowToClient 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes flowToServer {
    0% { 
        left: 5%; 
        opacity: 1; 
        transform: translateY(-50%) scale(0.8);
        box-shadow: 
            0 0 8px rgba(59, 130, 246, 0.6), 
            0 0 4px rgba(59, 130, 246, 0.4),
            inset 0 0 4px rgba(255, 255, 255, 0.3);
    }
    25% { 
        transform: translateY(-50%) scale(1.2);
        box-shadow: 
            0 0 16px rgba(59, 130, 246, 1), 
            0 0 8px rgba(59, 130, 246, 0.8),
            inset 0 0 4px rgba(255, 255, 255, 0.5);
    }
    50% { 
        transform: translateY(-50%) scale(1);
    }
    75% { 
        opacity: 0.8;
        transform: translateY(-50%) scale(0.9);
    }
    100% { 
        left: 95%; 
        opacity: 0; 
        transform: translateY(-50%) scale(0.6);
        box-shadow: 
            0 0 4px rgba(59, 130, 246, 0.3), 
            0 0 2px rgba(59, 130, 246, 0.2);
    }
}

@keyframes flowToClient {
    0% { 
        left: 95%; 
        opacity: 1; 
        transform: translateY(-50%) scale(0.8);
        box-shadow: 
            0 0 8px rgba(239, 68, 68, 0.6), 
            0 0 4px rgba(239, 68, 68, 0.4),
            inset 0 0 4px rgba(255, 255, 255, 0.3);
    }
    25% { 
        transform: translateY(-50%) scale(1.2);
        box-shadow: 
            0 0 16px rgba(239, 68, 68, 1), 
            0 0 8px rgba(239, 68, 68, 0.8),
            inset 0 0 4px rgba(255, 255, 255, 0.5);
    }
    50% { 
        transform: translateY(-50%) scale(1);
    }
    75% { 
        opacity: 0.8;
        transform: translateY(-50%) scale(0.9);
    }
    100% { 
        left: 5%; 
        opacity: 0; 
        transform: translateY(-50%) scale(0.6);
        box-shadow: 
            0 0 4px rgba(239, 68, 68, 0.3), 
            0 0 2px rgba(239, 68, 68, 0.2);
    }
}

/* Enhanced Packet Types */
.packet-command {
    background: radial-gradient(circle, #8b5cf6 0%, #7c3aed 100%) !important;
    box-shadow: 
        0 0 12px rgba(139, 92, 246, 0.8), 
        0 0 6px rgba(139, 92, 246, 0.6),
        inset 0 0 4px rgba(255, 255, 255, 0.3) !important;
}

.packet-heartbeat {
    background: radial-gradient(circle, #10b981 0%, #059669 100%) !important;
    box-shadow: 
        0 0 10px rgba(16, 185, 129, 0.7), 
        0 0 5px rgba(16, 185, 129, 0.5),
        inset 0 0 3px rgba(255, 255, 255, 0.2) !important;
    width: 6px !important;
    height: 6px !important;
}

.packet-error {
    background: radial-gradient(circle, #f59e0b 0%, #d97706 100%) !important;
    box-shadow: 
        0 0 14px rgba(245, 158, 11, 0.9), 
        0 0 7px rgba(245, 158, 11, 0.7),
        inset 0 0 4px rgba(255, 255, 255, 0.4) !important;
    animation-duration: 0.8s !important;
}

.packet-chart {
    background: radial-gradient(circle, #06b6d4 0%, #0891b2 100%) !important;
    box-shadow: 
        0 0 12px rgba(6, 182, 212, 0.8), 
        0 0 6px rgba(6, 182, 212, 0.6),
        inset 0 0 4px rgba(255, 255, 255, 0.3) !important;
    width: 10px !important;
    height: 10px !important;
}

.packet-data {
    /* Default data packet styling - inherits from .packet-in/.packet-out */
    position: relative;
}

/* Enhanced connection path with animated gradient */
.path-line {
    background: linear-gradient(90deg, 
        rgba(59, 130, 246, 0.3) 0%, 
        rgba(59, 130, 246, 0.6) 50%, 
        rgba(59, 130, 246, 0.3) 100%);
    background-size: 200% 100%;
    animation: pathPulse 2s ease-in-out infinite;
}

@keyframes pathPulse {
    0%, 100% { 
        background-position: 0% 0%;
        opacity: 0.3;
    }
    50% { 
        background-position: 100% 0%;
        opacity: 0.7;
    }
}

/* Enhanced Status LED Activity Effects */
.activity-flash {
    transform: scale(1.3);
    filter: brightness(1.5);
}

.activity-data {
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.activity-command {
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.6);
}

.activity-error {
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.8);
}

.activity-heartbeat {
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

/* Enhanced Panel Controls */
#pin-toggle-icon {
    transition: transform var(--transition-normal);
    will-change: transform;
}

.pinned #pin-toggle-icon {
    transform: rotate(45deg);
}

#connection-content {
    transition: max-height var(--transition-slow), opacity var(--transition-normal), padding var(--transition-slow);
    max-height: 500px;
    opacity: 1;
    overflow: hidden;
    will-change: max-height, opacity;
}

.pinned #connection-content {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0 !important;
}

/* Enhanced Signal Indicators */
.signal-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
}

.signal-bar {
    width: 4px;
    background: #6b7280;
    transition: all var(--transition-normal);
    will-change: background-color, transform;
}

.signal-bar.active {
    background: linear-gradient(to top, #10b981, #34d399);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

/* Enhanced Floating Panel System */
#left-panel-container {
    position: absolute;
    left: 1.5rem;
    top: 0;
    bottom: 0;
    width: 20rem;
    z-index: 20;
    transition: transform var(--transition-normal);
    transform: translateX(0);
    will-change: transform;
}

#left-panel-container.collapsed {
    transform: translateX(calc(-100% - 3rem));
}

#left-panel-toggle svg {
    transition: transform var(--transition-normal);
    will-change: transform;
}

#left-panel-container.collapsed #left-panel-toggle svg {
    transform: rotate(180deg);
}

/* Enhanced Mobile Layout */
@media (max-width: 1023px) {
    #left-panel-container {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        margin-right: 0;
        padding: 1.5rem;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(20px) saturate(180%);
        transform: translateX(-100%);
        z-index: 40;
        box-shadow: var(--surface-elevation-3);
    }
    
    .dark #left-panel-container {
        background: rgba(31, 41, 55, 0.95);
    }
    
    #left-panel-container.open {
        transform: translateX(0);
    }
    
    #left-panel-toggle {
        display: none;
    }
}

/* Enhanced Animation Library */
@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

@keyframes ring {
    0%, 100% { transform: rotate(0); }
    10%, 30%, 50%, 70%, 90% { transform: rotate(-10deg); }
    20%, 40%, 60%, 80% { transform: rotate(10deg); }
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 5px currentColor; }
    50% { box-shadow: 0 0 20px currentColor, 0 0 30px currentColor; }
}

.ringing { animation: ring 1s ease-in-out; }
.pulsing { animation: pulse 2s ease-in-out infinite; }
.glowing { animation: glow 2s ease-in-out infinite; }

/* Enhanced Alarm System */
#alarm-btn.alarm-warning {
    color: #f59e0b;
    animation: glow 2s ease-in-out infinite;
}

#alarm-btn.alarm-critical {
    color: #ef4444;
    animation: ring 1s ease-in-out infinite;
}

/* Alarm popup visibility - controlled by JavaScript hidden class */
#alarm-popup:not(.hidden) {
    display: block;
}

/* Alarm Badge */
.alarm-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 9999px;
    height: 1.25rem;
    min-width: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.25rem;
    animation: badgePulse 2s ease-in-out infinite;
}

@keyframes badgePulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 4px rgba(239, 68, 68, 0);
    }
}

/* Alarm Modal */
#alarm-modal .custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: rgba(156, 163, 175, 0.5) transparent;
}

#alarm-modal .custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

#alarm-modal .custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

#alarm-modal .custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.5);
    border-radius: 3px;
}

#alarm-modal .custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 0.8);
}

.alarm-item {
    transition: all 0.2s ease;
}

.alarm-item:hover {
    transform: translateY(-1px);
}

/* Enhanced Device Cards */
.device-card {
    transition: all var(--transition-normal);
    will-change: transform, box-shadow;
}

.device-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--surface-elevation-2);
}

.device-card .device-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Enhanced Toast System */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1055;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--surface-elevation-2);
    opacity: 0;
    transform: translateX(100%) scale(0.95);
    transition: all var(--transition-normal);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    pointer-events: auto;
    will-change: transform, opacity;
}

.toast.show {
    opacity: 1;
    transform: translateX(0) scale(1);
}

.toast.success { 
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.95), rgba(5, 150, 105, 0.95));
    color: white; 
}

.toast.error { 
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.95), rgba(220, 38, 38, 0.95));
    color: white; 
}

.toast.info { 
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.95), rgba(37, 99, 235, 0.95));
    color: white; 
}

.toast.warning { 
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.95), rgba(217, 119, 6, 0.95));
    color: white; 
}

/* Enhanced DataTables */
.dataTables_wrapper {
    font-size: 0.875rem;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.dataTables_scroll {
    flex-grow: 1;
}

.dataTables_filter { display: none; }
.dataTables_length, .dataTables_info, .dataTables_paginate { display: none; }

table.dataTable {
    width: 100% !important;
    border-collapse: separate;
    border-spacing: 0;
}

table.dataTable thead th {
    background: linear-gradient(135deg, #f8fafc, #f1f5f9);
    border-bottom: 2px solid #e2e8f0;
    font-weight: 600;
    color: #475569;
    padding: 12px 16px;
    text-align: left;
}

.dark table.dataTable thead th {
    background: linear-gradient(135deg, #1e293b, #334155);
    border-bottom-color: #475569;
    color: #e2e8f0;
}

table.dataTable tbody tr {
    transition: all var(--transition-fast);
    will-change: background-color;
}

table.dataTable tbody tr:hover {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.05), rgba(99, 102, 241, 0.05));
    transform: scale(1.001);
}

.dark table.dataTable tbody tr:hover {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(99, 102, 241, 0.1));
}

table.dataTable tbody tr.selected {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe) !important;
}

.dark table.dataTable tbody tr.selected {
    background: linear-gradient(135deg, #1e3a8a, #1e40af) !important;
}

/* Enhanced Grid System for 16 Columns */
.grid-stack {
    background-image:
        linear-gradient(rgba(59, 130, 246, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(59, 130, 246, 0.1) 1px, transparent 1px);
    background-size: calc(100% / 16) calc(100% / 16);
    transition: background-image var(--transition-normal);
    position: relative;
}

.dark .grid-stack {
    background-image:
        linear-gradient(rgba(99, 102, 241, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(99, 102, 241, 0.1) 1px, transparent 1px);
}

.grid-stack.grid-hidden {
    background-image: none !important;
}

/* Enhanced Grid Items */
.grid-stack-item-content {
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px) saturate(180%);
    border: 1px solid rgba(229, 231, 235, 0.3);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    box-shadow: var(--surface-elevation-1);
    transition: all var(--transition-normal);
    will-change: transform, box-shadow, border-color;
}

.dark .grid-stack-item-content {
    background: rgba(31, 41, 55, 0.8);
    border-color: rgba(75, 85, 99, 0.3);
}

.grid-stack-item-content:hover {
    transform: translateY(-1px);
    box-shadow: var(--surface-elevation-2);
    border-color: rgba(59, 130, 246, 0.3);
}

.dark .grid-stack-item-content:hover {
    border-color: rgba(99, 102, 241, 0.3);
}

/* Enhanced Alert States */
.grid-stack-item-content.alerting-warning {
    border-color: #f59e0b;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.3);
    animation: pulseWarning 2s ease-in-out infinite;
}

.grid-stack-item-content.alerting-critical {
    border-color: #ef4444;
    animation: pulseCritical 1.5s ease-in-out infinite;
}

@keyframes pulseWarning {
    0%, 100% { box-shadow: 0 0 20px rgba(245, 158, 11, 0.3); }
    50% { box-shadow: 0 0 30px rgba(245, 158, 11, 0.6), 0 0 40px rgba(245, 158, 11, 0.3); }
}

@keyframes pulseCritical {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
    }
    50% { 
        transform: scale(1.02); 
        box-shadow: 0 0 30px rgba(239, 68, 68, 0.8), 0 0 40px rgba(239, 68, 68, 0.4);
    }
}

/* Enhanced Resize Handles */
.ui-resizable-handle {
    filter: none;
    opacity: 0;
    transition: opacity var(--transition-normal);
    background: linear-gradient(45deg, #3b82f6, #6366f1);
    border-radius: 2px;
}

.grid-stack-item:hover .ui-resizable-handle {
    opacity: 0.7;
}

.ui-resizable-handle:hover {
    opacity: 1 !important;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.5);
}

/* Enhanced Placeholder */
.grid-stack .grid-stack-placeholder {
    opacity: 1 !important;
}

.grid-stack .grid-stack-placeholder > .placeholder-content {
    border: 2px dashed #3b82f6 !important;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(99, 102, 241, 0.1)) !important;
    border-radius: var(--border-radius-lg) !important;
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    box-sizing: border-box !important;
}

.grid-stack .grid-stack-placeholder > .placeholder-content::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(45deg, transparent 40%, rgba(59, 130, 246, 0.1) 50%, transparent 60%);
    background-size: 20px 20px;
    animation: placeholderShimmer 1s linear infinite;
}

@keyframes placeholderShimmer {
    0% { background-position: -20px -20px; }
    100% { background-position: 20px 20px; }
}

/* Enhanced Chart Card Headers */
.chart-card-header {
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(229, 231, 235, 0.3);
    cursor: move;
    flex-shrink: 0;
    position: relative;
    background: linear-gradient(135deg, rgba(248, 250, 252, 0.8), rgba(241, 245, 249, 0.8));
    backdrop-filter: blur(8px);
}

.dark .chart-card-header {
    border-color: rgba(75, 85, 99, 0.3);
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.8), rgba(51, 65, 85, 0.8));
}

.chart-card-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
    padding-left: 14px;
    color: #374151;
}

.dark .chart-card-header h3 {
    color: #f3f4f6;
}

.chart-card-header .header-buttons {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Enhanced Chart Card Body */
.chart-card-body {
    padding: 12px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    position: relative;
    min-height: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(249, 250, 251, 0.9));
}

.dark .chart-card-body {
    background: linear-gradient(135deg, rgba(17, 24, 39, 0.9), rgba(31, 41, 55, 0.9));
}

.chart-card-body > .chart-container {
    position: relative;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius-md);
    overflow: hidden;
}

.chart-card-body canvas, 
.chart-card-body .table-container, 
.chart-card-body .seven-segment-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Enhanced Widget Timestamp */
.widget-last-updated {
    position: absolute;
    bottom: 6px;
    right: 10px;
    font-size: 0.6rem;
    color: rgba(156, 163, 175, 0.8);
    z-index: 5;
    pointer-events: none;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 4px;
    backdrop-filter: blur(4px);
}

.dark .widget-last-updated {
    color: rgba(107, 114, 128, 0.8);
    background: rgba(31, 41, 55, 0.8);
}

/* Enhanced Modal System */
#data-selection-modal, 
#chart-config-modal, 
#field-manager-modal, 
#connection-modal {
    z-index: 1050;
    backdrop-filter: blur(8px);
}

#data-selection-list {
    max-height: 40vh;
    overflow-y: auto;
}

/* Enhanced Widget Toolbox */
.widget-tool-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 12px 8px;
    width: 100%;
    background: linear-gradient(135deg, #f8fafc, #f1f5f9);
    border-radius: var(--border-radius-md);
    border: 1px solid rgba(229, 231, 235, 0.5);
    cursor: grab;
    transition: all var(--transition-normal);
    user-select: none;
    text-align: center;
    position: relative;
    overflow: hidden;
    will-change: transform, box-shadow;
}

.widget-tool-item::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(99, 102, 241, 0.1));
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.widget-tool-item:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: var(--surface-elevation-2);
}

.widget-tool-item:hover::before {
    opacity: 1;
}

.dark .widget-tool-item {
    background: linear-gradient(135deg, #374151, #4b5563);
    border-color: rgba(75, 85, 99, 0.5);
}

.widget-tool-item:active {
    cursor: grabbing;
    transform: translateY(-1px) scale(0.98);
}

/* Enhanced Widget Toolbox Container */
#widget-toolbox {
    position: absolute;
    right: 1.5rem;
    top: 1.5rem;
    width: 280px;
    max-height: calc(100% - 3rem);
    z-index: 200; /* Must be above enhanced-header (100) and dropdowns (1000) */
    transition: all var(--transition-normal);
    transform: translateX(0);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--surface-elevation-3);
    border: 1px solid rgba(229, 231, 235, 0.3);
    will-change: transform;
}

.dark #widget-toolbox {
    background: rgba(31, 41, 55, 0.95);
    border-color: rgba(75, 85, 99, 0.3);
}

#widget-toolbox.collapsed {
    transform: translateX(calc(100% + 1.5rem));
}

/* Expanded toolbox size - 800x70vh */
#widget-toolbox.toolbox-expanded {
    width: 800px !important;
    height: 70vh !important;
    max-height: 70vh !important;
    max-width: calc(100vw - 4rem);
    top: 50% !important;
    right: 2rem !important;
    transform: translateY(-50%) !important;
}

/* Ensure content scrolls properly in expanded mode */
#widget-toolbox.toolbox-expanded .toolbox-content {
    flex: 1 1 auto !important;
    overflow: hidden !important;
    min-height: 0 !important;
}

#widget-toolbox.toolbox-expanded #widget-toolbox-items {
    height: 100% !important;
    overflow-y: auto !important;
}

/* Default toolbox content structure */
.toolbox-content {
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#widget-toolbox-items {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* Optimize spacing for widget categories */
.widget-category {
    margin-bottom: 0.75rem;
}

.widget-category:last-child {
    margin-bottom: 0;
}

/* Filter toggle states */
#widget-search-container,
#widget-category-container {
    transition: all 0.2s ease;
}

#widget-search-container.hidden-filter,
#widget-category-container.hidden-filter {
    max-height: 0 !important;
    opacity: 0 !important;
    overflow: hidden !important;
    margin-bottom: 0 !important;
}

#widget-toolbox-toggle {
    position: absolute;
    top: 50%;
    left: -1.25rem;
    transform: translateY(-50%);
    z-index: 21;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 50%;
    box-shadow: var(--surface-elevation-2);
    border: 1px solid rgba(229, 231, 235, 0.3);
    padding: 8px;
    transition: all var(--transition-normal);
}

.dark #widget-toolbox-toggle {
    background: rgba(31, 41, 55, 0.95);
    border-color: rgba(75, 85, 99, 0.3);
}

/* Hide widget toolbox in live mode */
#widget-toolbox.hidden,
#modern-widget-toolbox.hidden {
    display: none !important;
}

/* Dashboard Lock States */
.grid-stack.dashboard-locked .grid-stack-item {
    cursor: default !important;
}

.widget-lock-btn.locked, 
#dashboard-lock-btn.locked {
    color: #3b82f6;
}

/* Enhanced On/Off Widget System */
.on-off-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    padding: 1rem;
}

.on-off-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform var(--transition-normal);
}

.on-off-container:hover {
    transform: scale(1.05);
}

.on-off-widget {
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all var(--transition-fast);
    color: #374151;
    background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
    position: relative;
    overflow: hidden;
    will-change: transform, box-shadow;
}

.dark .on-off-widget {
    background: linear-gradient(135deg, #4b5563, #374151);
    color: #e5e7eb;
}

.on-off-widget::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(99, 102, 241, 0.1));
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.on-off-widget:hover::before {
    opacity: 1;
}

.on-off-widget:active {
    transform: translateY(2px) scale(0.98);
}

.on-off-widget .on-off-label {
    font-size: 0.75rem;
    margin-top: 0.5rem;
    color: #6b7280;
    transition: color var(--transition-fast);
}

.dark .on-off-widget .on-off-label {
    color: #e5e7eb;
}

/* On/Off Widget Styles */
.on-off-grid.style-round .on-off-widget {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    box-shadow: var(--surface-elevation-1);
}

.on-off-grid.style-square .on-off-widget {
    width: 80px;
    height: 80px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--surface-elevation-1);
}

.on-off-grid.style-group {
    flex-direction: column;
    gap: 0.5rem;
}

.on-off-grid.style-group .on-off-container {
    width: 100%;
}

.on-off-grid.style-group .on-off-widget {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: var(--surface-elevation-1);
}

.on-off-grid.style-group .on-off-widget .on-off-label {
    margin: 0;
    font-size: 0.875rem;
}

/* Enhanced On/Off States */
.on-off-widget.on {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
    animation: onPulse 0.3s ease-out;
}

@keyframes onPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.on-off-widget.on:active {
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
}

/* Enhanced 7-Segment Display - REMOVED DUPLICATES */
/* All seven-segment styles moved to widgets.css to avoid conflicts */
/* .seven-segment-container, .seven-segment-display, .digit, .segment classes are in widgets.css */

.segment.on.critical {
    background-color: #ef4444;
    box-shadow: 
        0 0 10px #ef4444,
        0 0 20px rgba(239, 68, 68, 0.5),
        inset 0 0 5px rgba(255, 255, 255, 0.2);
    animation: criticalBlink 1s ease-in-out infinite;
}

@keyframes criticalBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Segment positioning */
.a { width: 40px; height: 10px; top: 0; left: 10px; }
.b { width: 10px; height: 40px; top: 10px; right: 0; }
.c { width: 10px; height: 40px; top: 70px; right: 0; }
.d { width: 40px; height: 10px; bottom: 0; left: 10px; }
.e { width: 10px; height: 40px; top: 70px; left: 0; }
.f { width: 10px; height: 40px; top: 10px; left: 0; }
.g { width: 40px; height: 10px; top: 55px; left: 10px; }

/* Enhanced Dropdown System - Already in the HTML styles */

/* Enhanced Chart Expand Modal */
#chart-expand-modal {
    z-index: 1040;
    backdrop-filter: blur(12px);
}

/* Enhanced Config Editor */
.config-tab-btn {
    padding: 10px 20px;
    border-radius: var(--border-radius-md);
    font-weight: 500;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.config-tab-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.config-tab-btn.active::before {
    opacity: 1;
}

.config-tab-btn.active {
    color: white;
    box-shadow: var(--surface-elevation-1);
}

.config-tab-btn:not(.active) {
    color: #6b7280;
}

.dark .config-tab-btn:not(.active) {
    color: #9ca3af;
}

.config-tab-btn:not(.active):hover {
    background: rgba(229, 231, 235, 0.5);
    transform: translateY(-1px);
}

.dark .config-tab-btn:not(.active):hover {
    background: rgba(55, 65, 81, 0.5);
}

/* Enhanced Config Groups */
.config-group {
    border: 1px solid rgba(229, 231, 235, 0.3);
    border-radius: var(--border-radius-lg);
    margin-bottom: 1.5rem;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    overflow: hidden;
}

.dark .config-group {
    border-color: rgba(75, 85, 99, 0.3);
    background: rgba(31, 41, 55, 0.5);
}

.config-group-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(249, 250, 251, 0.8), rgba(243, 244, 246, 0.8));
    border-bottom: 1px solid rgba(229, 231, 235, 0.3);
    font-weight: 600;
}

.dark .config-group-header {
    background: linear-gradient(135deg, rgba(55, 65, 81, 0.8), rgba(75, 85, 99, 0.8));
    border-color: rgba(75, 85, 99, 0.3);
}

.config-group-body {
    padding: 20px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

.config-property {
    display: grid;
    grid-template-columns: 1fr 2fr;
    align-items: center;
    gap: 1.5rem;
}

.config-property-label {
    font-weight: 500;
    color: #374151;
}

.dark .config-property-label {
    color: #f3f4f6;
}

.config-property-desc {
    font-size: 0.8rem;
    color: #6b7280;
    margin-top: 4px;
}

.dark .config-property-desc {
    color: #9ca3af;
}

/* Enhanced Form Controls */
.config-property-input input[type="text"],
.config-property-input input[type="number"],
.config-property-input select {
    width: 100%;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(209, 213, 219, 0.5);
    border-radius: var(--border-radius-md);
    transition: all var(--transition-fast);
    backdrop-filter: blur(5px);
}

.config-property-input input:focus,
.config-property-input select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: rgba(255, 255, 255, 0.95);
}

.dark .config-property-input input[type="text"],
.dark .config-property-input input[type="number"],
.dark .config-property-input select {
    background: rgba(75, 85, 99, 0.8);
    border-color: rgba(107, 114, 128, 0.5);
    color: #e5e7eb;
}

.dark .config-property-input input:focus,
.dark .config-property-input select:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
    background: rgba(75, 85, 99, 0.95);
}

/* Enhanced Color Picker */
.config-property-input input[type="color"] {
    width: 48px;
    height: 48px;
    padding: 4px;
    background: transparent;
    border: 2px solid rgba(209, 213, 219, 0.5);
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.config-property-input input[type="color"]:hover {
    border-color: #3b82f6;
    transform: scale(1.05);
}

.dark .config-property-input input[type="color"] {
    border-color: rgba(107, 114, 128, 0.5);
}

/* Enhanced Checkbox */
.config-property-input input[type="checkbox"] {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: var(--border-radius-sm);
    border: 2px solid rgba(209, 213, 219, 0.5);
    color: #3b82f6;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.config-property-input input[type="checkbox"]:checked {
    transform: scale(1.1);
}

/* Enhanced Slider */
.config-property-input .config-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: linear-gradient(to right, #e5e7eb, #d1d5db);
    outline: none;
    border-radius: 4px;
    transition: all var(--transition-fast);
}

.dark .config-property-input .config-slider {
    background: linear-gradient(to right, #4b5563, #374151);
}

.config-property-input .config-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    cursor: pointer;
    border-radius: 50%;
    box-shadow: var(--surface-elevation-1);
    transition: all var(--transition-fast);
}

.config-property-input .config-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: var(--surface-elevation-2);
}

.config-property-input .config-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    cursor: pointer;
    border-radius: 50%;
    border: none;
    box-shadow: var(--surface-elevation-1);
    transition: all var(--transition-fast);
}

.config-property-input input.config-slider-value {
    width: 6rem;
}

/* Enhanced System Device Selector Styling */
#global-system-device-selector {
    min-width: 220px;
    padding: 8px 32px 8px 12px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(209, 213, 219, 0.6);
    border-radius: var(--border-radius-md);
    color: #374151;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    backdrop-filter: blur(10px);
    box-shadow: var(--surface-elevation-1);
    appearance: none;
    cursor: pointer;
}

#global-system-device-selector:hover {
    border-color: #3b82f6;
    background: rgba(255, 255, 255, 1);
    box-shadow: var(--surface-elevation-2);
    transform: translateY(-1px);
}

#global-system-device-selector:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1), var(--surface-elevation-2);
    background: rgba(255, 255, 255, 1);
    transform: translateY(-1px);
}

/* Dark theme for system device selector */
.dark #global-system-device-selector {
    background: rgba(75, 85, 99, 0.95);
    border-color: rgba(107, 114, 128, 0.6);
    color: #e5e7eb;
}

.dark #global-system-device-selector:hover {
    border-color: #60a5fa;
    background: rgba(75, 85, 99, 1);
}

.dark #global-system-device-selector:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1), var(--surface-elevation-2);
    background: rgba(75, 85, 99, 1);
}

/* System device selector options styling */
#global-system-device-selector option {
    padding: 8px 12px;
    background: #ffffff;
    color: #374151;
}

.dark #global-system-device-selector option {
    background: #4b5563;
    color: #e5e7eb;
}

/* System device selector label styling */
label[for="global-system-device-selector"] {
    color: #6b7280;
    font-weight: 500;
    font-size: 0.875rem;
    letter-spacing: 0.025em;
}

.dark label[for="global-system-device-selector"] {
    color: #9ca3af;
}

/* Dropdown arrow styling */
div:has(#global-system-device-selector) .pointer-events-none svg {
    transition: transform var(--transition-fast);
    color: #6b7280;
}

.dark div:has(#global-system-device-selector) .pointer-events-none svg {
    color: #9ca3af;
}

#global-system-device-selector:focus ~ div svg,
#global-system-device-selector:hover ~ div svg {
    transform: rotate(180deg);
    color: #3b82f6;
}

.dark #global-system-device-selector:focus ~ div svg,
.dark #global-system-device-selector:hover ~ div svg {
    color: #60a5fa;
}

/* Animation for selected device indicator */
#global-system-device-selector.has-selection {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(37, 99, 235, 0.05));
    border-color: #3b82f6;
    position: relative;
}

#global-system-device-selector.has-selection::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border-radius: var(--border-radius-md);
    z-index: -1;
    opacity: 0.2;
    animation: pulse 2s infinite;
}

.dark #global-system-device-selector.has-selection {
    background: linear-gradient(135deg, rgba(96, 165, 250, 0.1), rgba(59, 130, 246, 0.05));
    border-color: #60a5fa;
}

.dark #global-system-device-selector.has-selection::before {
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.2;
        transform: scale(1);
    }
    50% {
        opacity: 0.3;
        transform: scale(1.02);
    }
}

/* User Menu Dropdown - Higher z-index to appear above layout */
#user-menu-dropdown {
    z-index: 9999 !important;
}

/* Network Traffic Popup Styles */
#network-traffic-popup {
    backdrop-filter: blur(8px);
    box-shadow: var(--surface-elevation-3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: opacity var(--transition-normal), transform var(--transition-normal);
    transform: translateX(-50%) translateY(-4px);
    z-index: 1000;
}

#network-traffic-popup:hover {
    backdrop-filter: blur(12px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2), 0 8px 8px rgba(0, 0, 0, 0.25);
}

.dark #network-traffic-popup {
    background: rgba(31, 41, 55, 0.95);
    border-color: rgba(75, 85, 99, 0.5);
}

#network-traffic-popup .text-green-600 {
    font-weight: 600;
}

#network-traffic-popup .text-blue-600 {
    font-weight: 600;
}

/* Server node hover effects */
#server-node:hover {
    transform: scale(1.05);
    box-shadow: var(--surface-elevation-2);
    transition: all var(--transition-fast);
}

#server-node:hover svg {
    color: #3b82f6 !important;
    transition: color var(--transition-fast);
}

/* Animate numbers in popup */
#bytes-sent, #bytes-received, #transfer-rate {
    transition: color var(--transition-fast);
}

#bytes-sent:not(:empty), #bytes-received:not(:empty), #transfer-rate:not(:empty) {
    animation: numberUpdate 0.3s ease-in-out;
}

@keyframes numberUpdate {
    0% { opacity: 0.7; transform: scale(0.95); }
    50% { opacity: 1; transform: scale(1.02); }
    100% { opacity: 1; transform: scale(1); }
}

/* Continue with remaining styles... */

/* Selectbox and Option Hover State Fixes */
select {
    color: #374151;
}

.dark select {
    color: #f9fafb;
}

select option {
    color: #374151;
    background-color: white;
    padding: 8px 12px;
}

.dark select option {
    color: #f9fafb;
    background-color: #374151;
}

select option:hover {
    background-color: #f3f4f6 !important;
    color: #111827 !important;
}

.dark select option:hover {
    background-color: #4b5563 !important;
    color: #f9fafb !important;
}

select option:checked {
    background-color: #3b82f6;
    color: white;
}

.dark select option:checked {
    background-color: #3b82f6;
    color: white;
}

/* Modal Select Specific Fixes */
#modal-field-typeview option {
    color: #374151;
    background-color: white;
}

.dark #modal-field-typeview option {
    color: #f9fafb;
    background-color: #374151;
}

#modal-field-typeview option:hover {
    background-color: #f3f4f6 !important;
    color: #111827 !important;
}

.dark #modal-field-typeview option:hover {
    background-color: #4b5563 !important;
    color: #f9fafb !important;
}

/* Modal Field Editor Input Styles - Proper Text Colors */
#obj-field-editor-modal input[type="text"],
#obj-field-editor-modal input[type="number"],
#obj-field-editor-modal input[type="email"],
#obj-field-editor-modal input[type="password"],
#obj-field-editor-modal select,
#obj-field-editor-modal textarea {
    color: #374151 !important;
    background-color: white !important;
}

.dark #obj-field-editor-modal input[type="text"],
.dark #obj-field-editor-modal input[type="number"],
.dark #obj-field-editor-modal input[type="email"],
.dark #obj-field-editor-modal input[type="password"],
.dark #obj-field-editor-modal select,
.dark #obj-field-editor-modal textarea {
    color: #f9fafb !important;
    background-color: #374151 !important;
}

/* Config Dynamic Container Specific Styles */
#config-dynamic-container input[type="text"],
#config-dynamic-container input[type="number"],
#config-dynamic-container select,
#config-dynamic-container textarea {
    color: #374151 !important;
    background-color: white !important;
}

.dark #config-dynamic-container input[type="text"],
.dark #config-dynamic-container input[type="number"],
.dark #config-dynamic-container select,
.dark #config-dynamic-container textarea {
    color: #f9fafb !important;
    background-color: #374151 !important;
}

/* Memory Variables Table Styles - Compact and Clean */
#memory-vars-content table {
    border-collapse: collapse;
    font-size: 0.875rem;
    line-height: 1.25rem;
}

#memory-vars-content table th,
#memory-vars-content table td {
    padding: 0.5rem 0.75rem;
    vertical-align: middle;
    height: auto;
    min-height: 2.5rem;
}

#memory-vars-content table tbody tr {
    height: auto;
    min-height: 2.5rem;
}

#memory-vars-content table input[type="text"] {
    height: 1.75rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    line-height: 1.2;
    min-height: auto;
}

#memory-vars-content table button {
    height: 1.75rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    line-height: 1;
    white-space: nowrap;
}

/* Responsive adjustments for memory table */
@media (max-width: 768px) {
    #memory-vars-content table th,
    #memory-vars-content table td {
        padding: 0.375rem 0.5rem;
        font-size: 0.8rem;
    }
    
    #memory-vars-content table input[type="text"] {
        font-size: 0.75rem;
        height: 1.5rem;
    }
    
    #memory-vars-content table button {
        font-size: 0.7rem;
        height: 1.5rem;
        padding: 0.125rem 0.375rem;
    }
}

/* ===== MEMORY QUICK VIEW PANEL STYLES ===== */
/* CodeMirror container for memory quick view */
.memory-codemirror-container {
    position: relative;
    height: 100%;
    width: 100%;
}

.memory-codemirror-container .CodeMirror {
    height: 100% !important;
    width: 100% !important;
    font-family: 'JetBrains Mono', 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.4;
    border: none;
    border-radius: 0;
    background: transparent;
}

/* Custom scrollbar for memory CodeMirror */
.memory-codemirror-container .CodeMirror-scrollbar-filler,
.memory-codemirror-container .CodeMirror-gutter-filler {
    background: transparent;
}

.memory-codemirror-container .CodeMirror-scroll {
    height: 100% !important;
    overflow-y: auto !important;
    overflow-x: auto !important;
    scrollbar-width: thin;
    scrollbar-color: rgba(156, 163, 175, 0.5) transparent;
}

/* WebKit scrollbar for memory CodeMirror */
.memory-codemirror-container .CodeMirror-scroll::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.memory-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-track {
    background: rgba(243, 244, 246, 0.5);
    border-radius: 4px;
}

.dark .memory-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-track {
    background: rgba(31, 41, 55, 0.5);
}

.memory-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.6);
    border-radius: 4px;
    border: 1px solid rgba(243, 244, 246, 0.3);
}

.dark .memory-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-thumb {
    background: rgba(107, 114, 128, 0.6);
    border: 1px solid rgba(31, 41, 55, 0.3);
}

.memory-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 0.8);
}

.dark .memory-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(107, 114, 128, 0.8);
}

.memory-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-corner {
    background: transparent;
}

/* Ensure CodeMirror gutters blend with the container */
.memory-codemirror-container .CodeMirror-gutters {
    background-color: rgba(249, 250, 251, 0.8);
    border-right: 1px solid rgba(209, 213, 219, 0.5);
}

.dark .memory-codemirror-container .CodeMirror-gutters {
    background-color: rgba(17, 24, 39, 0.8);
    border-right: 1px solid rgba(75, 85, 99, 0.5);
}

/* Hide horizontal scrollbar when not needed */
.memory-codemirror-container .CodeMirror-hscrollbar {
    height: 8px !important;
}

/* Line number styling for better readability */
.memory-codemirror-container .CodeMirror-linenumber {
    color: rgba(156, 163, 175, 0.7);
    font-size: 12px;
    padding: 0 8px 0 5px;
}

.dark .memory-codemirror-container .CodeMirror-linenumber {
    color: rgba(107, 114, 128, 0.7);
}

/* Search highlight styling */
.memory-codemirror-container .CodeMirror-searching {
    background-color: rgba(251, 191, 36, 0.3) !important;
    border-radius: 2px;
}

.dark .memory-codemirror-container .CodeMirror-searching {
    background-color: rgba(217, 119, 6, 0.3) !important;
}

/* ===== SCRIPT EDITOR CODEMIRROR STYLES ===== */
/* CodeMirror container for script editor */
.script-codemirror-container {
    position: relative;
    height: 100%;
    width: 100%;
    min-height: 400px; /* Minimum height for better UX */
}

.script-codemirror-container .CodeMirror {
    height: 100% !important;
    width: 100% !important;
    font-family: 'JetBrains Mono', 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.4;
    border: 1px solid rgba(209, 213, 219, 0.5);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
}

.dark .script-codemirror-container .CodeMirror {
    border: 1px solid rgba(75, 85, 99, 0.5);
    background: rgba(17, 24, 39, 0.95);
}

/* Custom scrollbar for script CodeMirror */
.script-codemirror-container .CodeMirror-scrollbar-filler,
.script-codemirror-container .CodeMirror-gutter-filler {
    background: transparent;
}

.script-codemirror-container .CodeMirror-scroll {
    height: 100% !important;
    overflow-y: auto !important;
    overflow-x: auto !important;
    scrollbar-width: thin;
    scrollbar-color: rgba(156, 163, 175, 0.5) transparent;
}

/* WebKit scrollbar for script CodeMirror */
.script-codemirror-container .CodeMirror-scroll::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.script-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-track {
    background: rgba(243, 244, 246, 0.5);
    border-radius: 4px;
}

.dark .script-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-track {
    background: rgba(31, 41, 55, 0.5);
}

.script-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.6);
    border-radius: 4px;
    border: 1px solid rgba(243, 244, 246, 0.3);
}

.dark .script-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-thumb {
    background: rgba(107, 114, 128, 0.6);
    border: 1px solid rgba(31, 41, 55, 0.3);
}

.script-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 0.8);
}

.dark .script-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(107, 114, 128, 0.8);
}

.script-codemirror-container .CodeMirror-scroll::-webkit-scrollbar-corner {
    background: transparent;
}

/* Ensure CodeMirror gutters blend with the container */
.script-codemirror-container .CodeMirror-gutters {
    background-color: rgba(249, 250, 251, 0.9);
    border-right: 1px solid rgba(209, 213, 219, 0.5);
}

.dark .script-codemirror-container .CodeMirror-gutters {
    background-color: rgba(17, 24, 39, 0.9);
    border-right: 1px solid rgba(75, 85, 99, 0.5);
}

/* Hide horizontal scrollbar when not needed */
.script-codemirror-container .CodeMirror-hscrollbar {
    height: 8px !important;
}

/* Line number styling for better readability */
.script-codemirror-container .CodeMirror-linenumber {
    color: rgba(156, 163, 175, 0.7);
    font-size: 12px;
    padding: 0 8px 0 5px;
}

.dark .script-codemirror-container .CodeMirror-linenumber {
    color: rgba(107, 114, 128, 0.7);
}

/* Active line highlighting */
.script-codemirror-container .CodeMirror-activeline-background {
    background-color: rgba(59, 130, 246, 0.1) !important;
}

.dark .script-codemirror-container .CodeMirror-activeline-background {
    background-color: rgba(147, 197, 253, 0.1) !important;
}

/* Selection styling */
.script-codemirror-container .CodeMirror-selected {
    background-color: rgba(59, 130, 246, 0.2) !important;
}

.dark .script-codemirror-container .CodeMirror-selected {
    background-color: rgba(147, 197, 253, 0.15) !important;
}

/* Cursor styling */
.script-codemirror-container .CodeMirror-cursor {
    border-left: 2px solid rgba(59, 130, 246, 0.8);
}

.dark .script-codemirror-container .CodeMirror-cursor {
    border-left: 2px solid rgba(147, 197, 253, 0.8);
}

/* Search highlight styling */
.script-codemirror-container .CodeMirror-searching {
    background-color: rgba(251, 191, 36, 0.3) !important;
    border-radius: 2px;
}

.dark .script-codemirror-container .CodeMirror-searching {
    background-color: rgba(217, 119, 6, 0.3) !important;
}

/* Script Editor file list selected state */
#script-editor-file-list li.selected {
    background-color: rgba(59, 130, 246, 0.1) !important;
    border: 1px solid rgba(59, 130, 246, 0.3) !important;
    border-radius: 0.375rem;
}

.dark #script-editor-file-list li.selected {
    background-color: rgba(147, 197, 253, 0.1) !important;
    border-color: rgba(147, 197, 253, 0.3) !important;
}

/* Script Editor mode buttons active state */
.script-mode-btn.active {
    background-color: #2563eb !important;
    color: white !important;
}

.script-mode-btn:not(.active) {
    background-color: #f3f4f6 !important;
    color: #374151 !important;
}

.dark .script-mode-btn:not(.active) {
    background-color: #4b5563 !important;
    color: #d1d5db !important;
}

/* ===== SCRIPT EDITOR SYNTAX TOOLBOX STYLES ===== */
/* Syntax toolbox scrollbar styling */
#syntax-toolbox {
    scrollbar-width: thin;
    scrollbar-color: rgba(156, 163, 175, 0.5) transparent;
}

#syntax-toolbox::-webkit-scrollbar {
    width: 6px;
}

#syntax-toolbox::-webkit-scrollbar-track {
    background: rgba(243, 244, 246, 0.5);
    border-radius: 3px;
}

.dark #syntax-toolbox::-webkit-scrollbar-track {
    background: rgba(31, 41, 55, 0.5);
}

#syntax-toolbox::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.6);
    border-radius: 3px;
}

.dark #syntax-toolbox::-webkit-scrollbar-thumb {
    background: rgba(107, 114, 128, 0.6);
}

#syntax-toolbox::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 0.8);
}

.dark #syntax-toolbox::-webkit-scrollbar-thumb:hover {
    background: rgba(107, 114, 128, 0.8);
}

/* ===== PIVOT TABLE STYLES ===== */
/* Flash animation for updated cells (similar to IIoTLite) */
@keyframes flash-update {
    0% {
        background-color: rgba(34, 197, 94, 0.4);
        color: rgb(255, 255, 255);
    }
    100% {
        background-color: transparent;
    }
}

.cell-updated {
    animation: flash-update 0.8s ease-out;
}

/* Dark mode flash animation */
.dark .cell-updated {
    animation: flash-update-dark 0.8s ease-out;
}

@keyframes flash-update-dark {
    0% {
        background-color: rgba(34, 197, 94, 0.3);
        color: rgb(255, 255, 255);
    }
    100% {
        background-color: transparent;
    }
}

/* Slide-in animation for new rows */
@keyframes slide-in {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.row-new {
    animation: slide-in 0.3s ease-out;
}

/* Pivot table responsive styles */
#pivotTableView {
    position: relative;
    width: 100%;
    height: 100%;
}

/* ✅ FIX: Remove width: 100% to allow horizontal scroll when columns exceed viewport
   min-width: max-content ensures table expands to fit all columns */
#pivotTableView table {
    border-collapse: collapse;
    min-width: max-content;
}

#pivotTableView thead th {
    position: sticky;
    top: 0;
    background-color: inherit;
    z-index: 20;
}

#pivotTableView tbody tr:hover {
    background-color: rgba(59, 130, 246, 0.05);
}

.dark #pivotTableView tbody tr:hover {
    background-color: rgba(147, 197, 253, 0.05);
}

/* Sticky first column (device name) */
#pivotTableView thead th:first-child,
#pivotTableView tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 10;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
}

.dark #pivotTableView thead th:first-child,
.dark #pivotTableView tbody td:first-child {
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.15);
}

/* Cell transition for smooth updates */
#pivotTableView tbody td {
    transition: background-color 0.2s ease;
}
