/* Core Design System & Variables */
:root {
    --bg-gradient: linear-gradient(135deg, #090d16 0%, #111827 100%);
    --card-bg: rgba(30, 41, 59, 0.45);
    --card-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-red: #ef4444;
    --accent-amber: #f59e0b;
    --accent-green: #10b981;
    --accent-blue: #3b82f6;
    
    /* LED panel specific colors */
    --led-amber: #ff9800;
    --led-amber-glow: rgba(255, 152, 0, 0.75);
    
    /* Font stacks */
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --font-led: 'Share Tech Mono', monospace;
}

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

body {
    background: var(--bg-gradient);
    color: var(--text-primary);
    font-family: var(--font-main);
    min-height: 100vh;
    padding: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1.5;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Glassmorphism Cards */
.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

/* Layout Container */
.app-container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Header Styles */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding-bottom: 0.5rem;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-area h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.logo-area h1 .highlight {
    color: var(--accent-red);
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    transition: background-color 0.3s, box-shadow 0.3s;
}

.status-indicator.connected {
    background-color: var(--accent-green);
    box-shadow: 0 0 10px var(--accent-green);
}

.status-indicator.connecting {
    background-color: var(--accent-amber);
    box-shadow: 0 0 10px var(--accent-amber);
    animation: pulse 1s infinite alternate;
}

.status-indicator.disconnected {
    background-color: var(--accent-red);
    box-shadow: 0 0 10px var(--accent-red);
}

.api-settings {
    display: flex;
    gap: 1.5rem;
    padding: 0.75rem 1.25rem;
    align-items: center;
}

/* Form inputs & inputs */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.input-group label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    font-weight: 600;
}

.input-group input, .input-group select {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    outline: none;
    font-family: var(--font-main);
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus, .input-group select:focus {
    border-color: var(--accent-red);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.25);
}

/* Dashboard Grid Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* Grid Sections */
.grid-section {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.grid-section h2 {
    font-size: 1.2rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.75rem;
}

/* LED Matrix Section */
.led-display-container {
    background: #000;
    border: 3px solid #222;
    border-radius: 10px;
    padding: 0.75rem 1rem;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.8);
}

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

.led-display {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 50px;
    font-family: var(--font-led);
    color: var(--led-amber);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.led-line-number {
    font-size: 2.2rem;
    font-weight: 700;
    text-shadow: 0 0 8px var(--led-amber-glow);
    border-right: 2px dashed rgba(255, 152, 0, 0.3);
    padding-right: 0.75rem;
    line-height: 1;
}

.led-destination-scroll {
    overflow: hidden;
    white-space: nowrap;
    width: 100%;
    display: flex;
    align-items: center;
}

.led-text {
    font-size: 1.8rem;
    display: inline-block;
    text-shadow: 0 0 8px var(--led-amber-glow);
    animation: led-glow 2s infinite alternate;
}

/* Helper flex utilities */
.input-row {
    display: flex;
    gap: 1rem;
}
.flex-1 { flex: 1; }
.flex-3 { flex: 3; }

.control-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Presets styles */
.presets-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.presets-container label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.preset-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.preset-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.primary-btn {
    background: var(--accent-red);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    transition: filter 0.2s, transform 0.1s;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.primary-btn:hover {
    filter: brightness(1.1);
}

.primary-btn:active {
    transform: scale(0.98);
}

/* Bus Visualizer Styles (Image overlay mode) */
.visualizer-tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.25rem;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.2s, border-bottom 0.2s;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--accent-red);
    border-bottom-color: var(--accent-red);
}

.bus-render-area {
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 12px;
    padding: 1.5rem;
    min-height: 250px;
}

/* Image overlay core styling */
.bus-image-container {
    position: relative;
    width: 100%;
    max-width: 700px;
    display: none;
}

.bus-image-container.active {
    display: block;
}

.bus-bg-image {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

/* Fallback message if files are missing */
.image-fallback {
    width: 100%;
    min-height: 200px;
    background: rgba(0, 0, 0, 0.4);
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Overlay Lights Spots */
.overlay-light {
    position: absolute;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: background-color 0.2s, box-shadow 0.2s;
    pointer-events: auto; /* Clickable */
    cursor: pointer;
}

/* 1. Front Light overlays */
.overlay-light.front-low {
    background-color: rgba(254, 240, 138, 0.7);
    box-shadow: 0 0 15px 6px rgba(254, 240, 138, 0.85);
}

.overlay-light.front-high {
    background-color: rgba(255, 255, 255, 0.95);
    box-shadow: 0 0 25px 12px rgba(255, 255, 255, 0.95), 0 0 40px 20px rgba(255, 255, 255, 0.5);
}

/* 2. Rear Light overlays */
.rear-light-spot-rect {
    border-radius: 4px !important;
}

.overlay-light.rear-active {
    background-color: rgba(239, 68, 68, 0.85);
    box-shadow: 0 0 16px 8px rgba(239, 68, 68, 0.9);
}

/* 3. Blinker overlays (Amber blinking) */
.overlay-light.blink-active {
    animation: blink-overlay 0.8s infinite steps(2, start);
}

@keyframes blink-overlay {
    to {
        background-color: rgba(245, 158, 11, 0.95);
        box-shadow: 0 0 16px 8px rgba(245, 158, 11, 0.9);
    }
}

/* Passenger Windows Glow Mask */
.interior-glow-mask {
    position: absolute;
    border-radius: 4px;
    pointer-events: none;
    mix-blend-mode: screen;
    transition: background-color 0.3s, box-shadow 0.3s;
}

.interior-glow-mask.active {
    background-color: rgba(74, 222, 128, 0.15); /* warm light green glow typical for modern salon */
    box-shadow: inset 0 0 30px rgba(74, 222, 128, 0.4);
}

/* LED Matrix Screen Overlay over the image display boards */
.image-led-overlay {
    position: absolute;
    background: #000;
    border-radius: 2px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 0 4px;
    box-shadow: inset 0 0 4px rgba(0,0,0,0.9);
    container-type: size;
}

.img-led-text {
    font-family: var(--font-led);
    color: var(--led-amber);
    text-transform: uppercase;
    font-size: 60cqh; /* Scales perfectly with the height of the container! */
    letter-spacing: 0.5px;
    text-shadow: 0 0 3px var(--led-amber-glow);
    white-space: nowrap;
    display: inline-block;
    flex-shrink: 0;
}
}

/* Controls tab panels */
.control-groups {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.control-card {
    background: rgba(0,0,0,0.15);
    border: 1px solid rgba(255,255,255,0.03);
    border-radius: 12px;
    padding: 1rem;
}

.control-card h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Mode selectors (Front lights) */
.mode-selector {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    padding: 3px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.05);
}

.mode-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 6px;
    font-weight: 500;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--accent-red);
    color: white;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.2);
}

/* Blinker buttons */
.blinker-controls {
    display: flex;
    gap: 0.5rem;
}

.toggle-btn {
    flex: 1;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    color: var(--text-primary);
    padding: 0.6rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
    transition: all 0.2s ease;
}

.toggle-btn:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.15);
}

.toggle-btn.active {
    background: var(--accent-amber);
    color: #000;
    font-weight: 600;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.4);
    border-color: var(--accent-amber);
}

.toggle-btn.warning-btn.active {
    background: var(--accent-red);
    color: #fff;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
    border-color: var(--accent-red);
}

/* Sliders / Switches */
.switch-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.switch-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255,255,255,0.1);
    transition: .3s;
    border-radius: 24px;
    border: 1px solid rgba(255,255,255,0.05);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: #f8fafc;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent-green);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Sound Board */
.soundboard {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.sound-btn {
    flex: 1;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: #93c5fd;
    padding: 0.6rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.sound-btn:hover {
    background: rgba(59, 130, 246, 0.25);
    color: white;
}

.sound-btn:active {
    transform: scale(0.97);
}

.sound-btn.active {
    background: var(--accent-red) !important;
    color: white !important;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
    border-color: var(--accent-red) !important;
}

/* Console Logger Log */
.console-container {
    background: rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    height: 120px;
}

.console-header {
    background: rgba(0, 0, 0, 0.25);
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    color: var(--text-secondary);
}

.clear-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.7rem;
}

.clear-btn:hover {
    color: var(--accent-red);
}

.console-body {
    padding: 0.5rem 0.75rem;
    font-family: var(--font-led);
    font-size: 0.8rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.console-log-entry {
    color: #4ade80; /* green log text */
    word-break: break-all;
}

.console-log-entry.error {
    color: #f87171;
}

.console-placeholder {
    color: #475569;
    font-style: italic;
}

/* Footer style */
.app-footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 1rem;
}

/* LED text pulsing effects */
@keyframes led-glow {
    from {
        text-shadow: 0 0 6px var(--led-amber-glow);
    }
    to {
        text-shadow: 0 0 12px var(--led-amber-glow), 0 0 18px rgba(255, 152, 0, 0.4);
    }
}

@keyframes pulse {
    from {
        opacity: 0.5;
    }
    to {
        opacity: 1;
    }
}

/* Calibration Mode styles */
.editor-mode-active .overlay-light {
    outline: 2px dashed var(--accent-amber) !important;
    outline-offset: 1px !important;
    cursor: move !important;
    background-color: rgba(245, 158, 11, 0.4) !important;
    opacity: 0.85 !important;
    box-shadow: 0 0 6px var(--accent-amber) !important;
}

.editor-mode-active .image-led-overlay {
    outline: 2px dashed var(--accent-amber) !important;
    cursor: move !important;
    background-color: rgba(0, 0, 0, 0.75) !important;
}

#btn-toggle-editor.active {
    background-color: var(--accent-amber) !important;
    color: #000 !important;
    font-weight: 600;
}

.display-resize-handle {
    display: none;
    position: absolute;
    right: 0;
    bottom: 0;
    width: 14px;
    height: 14px;
    background-color: var(--accent-amber);
    cursor: se-resize !important;
    z-index: 1001;
    border-top-left-radius: 4px;
}

.editor-mode-active .display-resize-handle {
    display: block;
}
