:root {
    --bg-dark: #0f172a;
    --bg-panel: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --border-color: #334155;
    --font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-family);
    margin: 0;
    height: 100vh;
    display: flex;
    overflow: hidden;
}

h1,
h2,
h3 {
    margin: 0;
    font-weight: 600;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.brand {
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.brand h1 {
    font-size: 1.5rem;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.status-indicator {
    font-size: 0.875rem;
    color: var(--accent-green);
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-indicator.offline {
    color: var(--accent-red);
}

.status-indicator::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    background-color: currentColor;
    border-radius: 50%;
    box-shadow: 0 0 8px currentColor;
}

.panel h2 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 15px;
}

.control-group {
    margin-bottom: 15px;
}

.control-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

select,
input[type="text"],
select,
input[type="text"],
input[type="password"],
input[type="number"] {
    width: 100%;
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.2s;
    box-sizing: border-box;
    margin-bottom: 8px;
}

select:focus,
input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

button {
    width: 100%;
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 10px;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

button:hover {
    background-color: var(--accent-blue-hover);
}

.primary-btn {
    background-color: var(--accent-blue);
}

.success-btn {
    background-color: var(--accent-green);
}

.success-btn:hover {
    background-color: #059669;
}

.danger-btn {
    background-color: var(--accent-red);
}

.danger-btn:hover {
    background-color: #dc2626;
}

.secondary-btn {
    background-color: #607D8B;
}

.secondary-btn:hover {
    background-color: #546E7A;
}

.info-btn {
    background-color: #009688;
}

.info-btn:hover {
    background-color: #00796B;
}

.button-row {
    display: flex;
    gap: 10px;
}

/* Main Content - Flex Column Layout for Tabs + View */
.main-content {
    display: flex !important;
    /* Override grid */
    flex-direction: column;
    /* Remove grid properties if they were inline or specific */
    grid-template-columns: none;
    gap: 0;
    flex: 1;
    background-color: var(--border-color);
}

.terminal-wrapper {
    background-color: var(--bg-dark);
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Prevent flex item from overflowing */
}

.terminal-header {
    background-color: var(--bg-panel);
    padding: 10px 15px;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-secondary);
}

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

.chart-wrapper {
    position: relative;
    /* Removed padding to let canvas fill */
    display: flex;
    flex-direction: column;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    background-color: var(--surface-color-alt);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.chart-title {
    font-weight: 600;
    color: var(--text-primary);
}

.chart-stats {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
}

.chart-canvas-container {
    flex: 1;
    position: relative;
    width: 100%;
    min-height: 0;
    /* Important for flex child to shrink */
    overflow: hidden;
}

.terminal-container {
    flex: 1;
    position: relative;
    padding: 10px;
    overflow: hidden;
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Sidebar Tab Navigation */
.tab-nav {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.9rem;
    padding: 10px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    border-radius: 0;
}

.tab-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.05);
}

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

.tab-content {
    display: none;
    animation: fadeIn 0.2s ease-in-out;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Helper classes */
.flex-grow {
    flex-grow: 1;
}

.auto-width {
    width: auto !important;
}

.help-text {
    font-size: 0.75rem;
    color: #94a3b8;
    display: block;
    margin-top: 4px;
}

.checkbox-group {
    margin-top: 10px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.mic-input-group {
    display: flex;
    gap: 5px;
}

.radio-group {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

/* Main View Tabs (Top Bar) */
.view-tabs {
    flex: 0 0 40px;
    /* Fixed height */
    position: static;
    width: 100%;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    z-index: 10;
    /* overflow-x: auto;  REMOVED: User requested fixed width / no scroll */
    /* white-space: nowrap; REMOVED */
}

/* Hide scrollbar for view-tabs */
.view-tabs::-webkit-scrollbar {
    height: 4px;
    /* Tiny scrollbar */
}

.view-tabs::-webkit-scrollbar-thumb {
    background: var(--border-color);
}

.view-tab-btn {
    flex: 1;
    /* Make them fill the width like sidebar tabs */
    padding: 0 20px;
    height: 100%;
    /* flex-shrink: 0; REMOVED: Allow shrinking */
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    /* Match sidebar tab style */
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    border-radius: 0;
    /* Ensure square corners */
}

.view-tab-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.05);
}

.view-tab-btn.active {
    color: var(--accent-blue);
    background-color: transparent;
    /* Removed dark bg */
    border-bottom-color: var(--accent-blue);
}

/* View Containers */
.view-container {
    flex: 1;
    /* Fill remaining space */
    width: 100%;
    padding-top: 0;
    display: none;
    /* Hidden by default */
    overflow: hidden;
    overflow: hidden;
    /* Handle internal scrolling */
    flex-direction: column;
    /* Ensure default vertical stacking */
}

/* Explicit scrollable content area for admin/tables */
.scrollable-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.view-container.active {
    display: flex;
}

/* Terminal View - Specific Layout */
#terminal-view {
    display: none;
}

#terminal-view.active {
    display: grid;
    /* Restore original grid layout */
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background-color: var(--border-color);
}

/* Data View - Specific Layout */
#data-view {
    display: none;
}

#data-view.active {
    display: flex;
    flex-direction: row;
    /* Ensure Map and Stats are side-by-side on desktop */
    background-color: var(--bg-dark);
}

/* Map & Chart Styles */
.map-container {
    flex: 1;
    /* 1:1 Split initially */
    min-width: 0;
    width: 50%;
    position: relative;
    border-right: 1px solid var(--border-color);
}

#map {
    width: 100%;
    height: 100%;
}

/* Fullscreen Map Mode */
body.map-fullscreen .map-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    border: none;
}

body.map-fullscreen .leaflet-control-container .leaflet-top {
    top: 10px;
}

.stats-container {
    flex: 1;
    /* 1:1 Split */
    min-width: 0;
    width: 50%;
    display: flex;
    flex-direction: column;
}

.chart-wrapper {
    flex: 1;
    /* Split vertical */
    padding: 10px;
    position: relative;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    /* Prevent canvas overflow */
}

.chart-wrapper:last-child {
    border-bottom: none;
}

/* --- Added Styles for Modular Frontend --- */

/* Audio Analysis Tracks */
.track-container {
    background: #000;
    margin-bottom: 15px;
    border-radius: 4px;
    padding: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
}

[id^="wf-"] {
    min-height: 60px;
    width: 100%;
}

.track-source-primary {
    border: 1px solid #2e7d32;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.2);
}

.track-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    align-items: center;
}

.track-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.track-name-source {
    font-weight: bold;
    color: #4CAF50;
}

.track-name-output {
    font-weight: bold;
}

.badge-primary {
    background: #4CAF50;
    color: #000;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 0.7em;
}

.badge-rx {
    border: 1px solid;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.7em;
}

.track-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.offset-label {
    font-size: 0.8em;
    color: #aaa;
}

.offset-input {
    width: 38px;
    background: #222;
    border: 1px solid #444;
    color: #fff;
    padding: 2px 5px;
    border-radius: 3px;
}

.track-details-group {
    margin-top: 5px;
}

.track-details-group summary {
    cursor: pointer;
    font-size: 0.8em;
    color: #888;
}

.track-details-content {
    padding: 5px;
    font-size: 0.8em;
    color: #ccc;
    background: #111;
    margin-top: 5px;
    border-radius: 3px;
}

.meta-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 10px;
}

.small {
    padding: 4px 8px;
    font-size: 0.8em;
    width: auto !important;
    display: inline-block;
    margin: 0;
}

.small-btn {
    padding: 2px 8px;
    font-size: 0.8em;
    width: auto;
}


.action-btn-group {
    display: flex;
    gap: 5px;
    width: 100%;
}

.action-btn-group .small {
    flex: 1;
    text-align: center;
    width: 100% !important;
    /* Force full width within flex item */
}

/* Admin View specific override */
#admin-view {
    display: none;
    flex-direction: column;
    overflow: hidden;
    /* Container itself shouldn't scroll, let content scroll */
}

#admin-view.active {
    display: flex;
}

#admin-view>.admin-section-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.btn-active-red {
    background-color: #f44336 !important;
    color: white !important;
}

.btn-active-orange {
    background-color: #ff9800 !important;
    color: black !important;
}

.btn-active-green {
    background-color: #4CAF50 !important;
    color: black !important;
}

/* Log Coloring */
.log-entry {
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    margin-bottom: 2px;
}

.log-ts {
    color: #888;
    margin-right: 5px;
}

.log-error {
    color: #ff5252;
}

.log-success {
    color: #69f0ae;
}

.log-warn {
    color: #ffd740;
}

.log-info {
    color: #40c4ff;
}

/* --- Rich Dropdown --- */
.rich-dropdown {
    position: relative;
    width: 100%;
    /* min-width: 250px; Remove fixed min-width to allow flex */
    min-width: 120px;
    /* Sensible minimum, but allow shrinking via flex if needed */
    flex-shrink: 0;
    font-family: 'Inter', sans-serif;
    user-select: none;
}

.rich-dropdown-trigger {
    background-color: var(--bg-dark);
    /* Match input background */
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 12px;
    /* Match standard inputs padding */
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
    min-height: 38px;
    /* Approximate height of standard inputs */
    box-sizing: border-box;
    color: var(--text-primary);
}

.rich-dropdown-trigger:hover {
    border-color: var(--accent-blue);
    background-color: #2a2a2a;
}

.rich-dropdown.open .rich-dropdown-trigger {
    border-color: var(--accent-blue);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.rich-dropdown-label {
    color: var(--text-primary);
    font-size: 0.875rem;
    /* Match standard font size */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    /* Allow label to grow to fill space */
    margin-right: 10px;
    /* Space before arrow */
}

.rich-dropdown-arrow {
    color: var(--text-secondary);
    font-size: 0.8em;
    margin-left: 10px;
}

.rich-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-top: none;
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
    z-index: 1000;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.rich-dropdown-list {
    display: flex;
    flex-direction: column;
}

.rich-dropdown-item {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.1s;
    position: relative;
    /* Changed from flex row to relative for overlay */
}

.rich-dropdown-item:last-child {
    border-bottom: none;
}

.rich-dropdown-item:hover {
    background-color: #2a2a2a;
}

/* Ensure actions show on hover */
.rich-dropdown-item:hover .rich-dropdown-item-actions {
    display: flex;
}

.rich-dropdown-item.selected {
    background-color: rgba(59, 130, 246, 0.2) !important;
    /* slightly stronger highlight */
    border-left: 3px solid var(--accent-blue) !important;
    color: white !important;
}

.rich-dropdown-item-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
    /* padding-right removed for overlay */
}

/* Action Buttons Container (Overlay) */
.rich-dropdown-item-actions {
    display: none;
    /* Hidden by default */
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    background: linear-gradient(to right, transparent, #2a2a2a 20%);
    /* Blend with bg */
    padding-left: 20px;
    padding-right: 10px;
    align-items: center;
    gap: 5px;
    z-index: 10;
}

.rich-dropdown-item-main {
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.9em;
}

.rich-dropdown-item-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

.badge-wireless {
    background-color: #00897b;
    color: white;
}

.badge {
    font-size: 0.7em;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-codec {
    background-color: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-info {
    background-color: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* --- Modals --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.2s ease-in-out;
}

.modal {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1em;
    color: var(--text-primary);
}

.close-modal {
    background: transparent !important;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5em;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: auto !important;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-modal:hover {
    color: var(--text-primary);
    background: transparent !important;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.rich-dropdown-item-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 80px;
    /* Adjusted for 2 buttons */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    /* Spacing between icons */
    opacity: 0;
    transition: opacity 0.2s;
    background: linear-gradient(to left, var(--bg-panel) 80%, transparent);
    /* Fade effect */
    border-top-right-radius: 6px;
    /* Match container if needed */
    border-bottom-right-radius: 6px;
}

.rich-dropdown-item:hover .rich-dropdown-item-actions {
    opacity: 1;
}

.rich-dropdown-rename-btn,
.rich-dropdown-delete-btn {
    cursor: pointer;
    font-size: 1.0em;
    padding: 6px;
    border-radius: 4px;
    opacity: 0.7;
    transition: opacity 0.2s, transform 0.2s;
}

.rich-dropdown-rename-btn {
    color: var(--accent-blue);
}

.rich-dropdown-delete-btn {
    color: var(--accent-red);
}

.rich-dropdown-rename-btn:hover,
.rich-dropdown-delete-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.rich-dropdown-rename-btn:hover {
    background: rgba(59, 130, 246, 0.1);
}

.rich-dropdown-delete-btn:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Base Bottom Nav Hidden on Desktop */
.bottom-nav {
    display: none;
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {

    /* Layout */
    .app-container {
        /* Sidebar will be absolute, so main can take full width */
    }

    .main-content {
        /* Add padding for bottom nav */
        padding-bottom: 60px;
        width: 100vw;
        box-sizing: border-box;
        /* Ensure padding is inside height */
    }

    /* Sidebar - Hidden by default, overlay when active */
    .sidebar {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: calc(100% - 60px);
        /* Leave space for bottom nav */
        z-index: 2000;
        border-right: none;
        box-sizing: border-box;
        /* Includes padding in width */
        overflow-y: auto;
    }

    .sidebar.mobile-active {
        display: flex;
    }

    /* Bottom Navigation Bar */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 60px;
        background-color: var(--bg-panel);
        border-top: 1px solid var(--border-color);
        z-index: 3000;
        padding: 0;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    }

    .nav-item {
        flex: 1;
        height: 100%;
        background: transparent;
        border: none;
        color: var(--text-secondary);
        font-size: 0.8rem;
        cursor: pointer;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 5px;
        border-radius: 0;
    }

    .nav-item.active {
        color: var(--text-primary);
        background-color: rgba(255, 255, 255, 0.1);
        border-top: 2px solid var(--accent-blue);
    }

    .nav-group {
        display: flex;
        flex: 3;
        /* Take remaining space */
        height: 100%;
    }

    /* View Specific Mobile Layouts */

    /* Terminal View */
    #terminal-view.active {
        display: block !important;
        /* Override grid */
        height: 100%;
    }

    .terminal-wrapper {
        height: 100%;
        display: none;
        /* Hide all wrappers initially */
    }

    .terminal-wrapper.mobile-active {
        display: flex;
        /* Flex column as defined in standard css */
    }

    /* Data View */
    #data-view.active {
        display: block !important;
        /* Override flex row/column logic if needed, but standard is flex row */
        /* Actually standard was display:flex (row). Flex-direction logic for mobile: */
        flex-direction: column;
        padding-bottom: 100px !important;
    }

    .map-container,
    .stats-container {
        display: none;
        width: 100%;
        min-height: 100%;
        height: auto;
    }

    .map-container.mobile-active,
    .stats-container.mobile-active {
        display: flex;
        /* Restore flex display */
        height: 100%;
    }

    /* Ensure ChartJS canvases fit */
    .chart-wrapper {
        flex: none;
        height: auto;
        min-height: 300px;
        /* Allow scrolling */
    }

    .stats-container.mobile-active {
        flex-direction: column;
        /* Charts stacked vertically */
        padding-bottom: 80px !important;
    }

    /* Audio Analysis View */
    #audio-analysis-view {
        /* Standard was flex row. Force block or column? */
        flex-direction: column;
    }

    #audio-analysis-view>div {
        /* Direct children (Left controls, Right FFT) */
        display: none !important;
        width: 100%;
        height: 100%;
        border-right: none;
    }

    #audio-analysis-view>div.mobile-active {
        display: flex !important;
    }

    /* Benchmark View */
    #benchmark-view {
        /* Usually just one panel, so no sub-tabs needed explicitly, but consistency is good */
        /* It is display:flex column already. */
    }

    /* Hide scrollbars on main to prevent double scrolling with panels */
    .main-content {
        overflow: hidden;
    }

    /* Ensure Panels trigger internal scrolling */
    .view-container {
        overflow-y: auto;
    }

    #audio-tracks-scroll-wrapper {
        padding-bottom: 80px !important;
        /* Force space for bottom nav */
    }



    /* Mobile Benchmark Layout */
    .benchmark-controls-wrapper {
        flex-direction: column !important;
        /* Force column stack */
        align-items: stretch !important;
        gap: 15px !important;
        height: auto !important;
        /* Allow growing */
        padding: 15px !important;
    }

    .benchmark-inputs-group {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .benchmark-input-item {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        /* Prevent wrapping */
        align-items: center !important;
        width: 100% !important;
    }

    .benchmark-input-item label {
        min-width: 60px;
        flex-shrink: 0;
        /* Keep label size */
    }

    .benchmark-input-item input,
    .benchmark-input-item select {
        flex: 1;
        min-width: 0;
        /* Allow shrinking if needed */
    }

    .benchmark-input-item span {
        flex-shrink: 0;
        /* Keep unit size */
        margin-left: 8px;
    }

    .benchmark-divider {
        display: none !important;
        /* Hide vertical separator on mobile */
    }

    .benchmark-run-btn {
        width: 100% !important;
        /* Full width button */
        margin-top: 10px;
        padding: 10px !important;
    }

    /* Mobile Data View Layout */
    .data-view-controls {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        height: auto !important;
    }

    .data-layer-select {
        width: 100% !important;
        margin-bottom: 5px !important;
    }

    .data-view-buttons {
        display: flex;
        gap: 10px;
        width: 100%;
        margin-left: 0 !important;
        /* Reset any margin */
    }

    .data-view-buttons button {
        flex: 1;
        /* Distribute space */
        white-space: normal !important;
        /* Allow text wrap if needed */
        font-size: 0.8em;
        padding: 8px 4px;
        /* Tighter padding */
    }

    /* Mobile Top Bar Optimization */
    .view-tab-btn {
        padding: 0 5px;
        /* Reduce padding significantly */
        font-size: 0.75rem;
        /* Reduce font size */
        white-space: normal;
        /* Allow wrapping of text e.g. "Terminal Console" -> "Terminal\nConsole" if really needed, or just shrink */
        line-height: 1.1;
        /* Tighter lines if wrap */
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .rich-dropdown {
        /* Ensure dropdown doesn't take too much space but stays usable */
        min-width: 0 !important;
        /* Allow shrinking */
        width: auto;
    }

    .rich-dropdown-trigger {
        padding: 4px 8px;
        /* Reduce trigger padding */
    }

    .rich-dropdown-label {
        font-size: 0.75rem;
    }
}

/* Benchmark Desktop Styles (outside media query) */
.benchmark-controls-wrapper {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    width: 100%;
    box-sizing: border-box;
}

.benchmark-inputs-group {
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 1;
}

.benchmark-input-item {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.benchmark-input-item label {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin: 0;
    white-space: nowrap;
}

.benchmark-input-item input,
.benchmark-input-item select {
    flex: 1;
    min-width: 60px;
    margin: 0;
    height: 40px;
    box-sizing: border-box;
    /* Reset generic input margins if any */
    margin-bottom: 0 !important;
}

.benchmark-input-item span {
    color: var(--text-secondary);
    font-size: 0.9em;
}

.benchmark-divider {
    width: 1px;
    height: 40px;
    background-color: var(--border-color);
    flex-shrink: 0;
}

.benchmark-run-btn {
    margin: 0;
    width: auto;
    height: 40px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 30px;
    white-space: nowrap;
}

/* Data View Desktop Styles */
.data-view-controls {
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--surface-color, #1e293b);
    display: flex;
    gap: 10px;
    align-items: center;
}

.data-layer-select {
    flex: 1;
    margin-bottom: 0;
}

.data-view-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
    flex: 2;
    /* Take substantial space */
}

.data-view-buttons button {
    white-space: nowrap;
    width: auto;
}

/* Generic Upward Opening Class (Global) */
.rich-dropdown.open-up .rich-dropdown-menu {
    top: auto !important;
    bottom: 100% !important;
    border-top: 1px solid var(--border-color) !important;
    border-bottom: none !important;
    border-radius: 6px 6px 0 0 !important;
    box-shadow: 0 -4px 6px rgba(0, 0, 0, 0.3) !important;
}

/* --- Video Mode Styles --- */
body.video-mode .sidebar,
body.video-mode .view-tabs,
body.video-mode .brand,
body.video-mode #user-dropdown {
    display: none !important;
}

body.video-mode .main-content {
    height: 100vh;
    width: 100vw;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 9999;
}

body.video-mode #data-view {
    display: grid !important;
    grid-template-columns: 1fr 56.25vh;
    /* 9/16 aspect ratio relative to height */
    grid-template-rows: 61.8% 38.2%;
    grid-template-areas:
        'map video'
        'rx video';
    height: 100%;
    width: 100%;
}

body.video-mode .map-container {
    grid-area: map;
    width: 100% !important;
    height: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border-color);
}

body.video-mode .stats-container {
    display: contents !important;
}

body.video-mode .stats-container .view-controls {
    display: none !important;
}

/* Hide TX Chart in Video Mode */
body.video-mode .stats-container .chart-wrapper:nth-of-type(2) {
    display: none !important;
}

/* Style RX Chart in Video Mode */
body.video-mode .stats-container .chart-wrapper:last-child {
    grid-area: rx;
    width: 100% !important;
    height: 100% !important;
    border-bottom: none !important;
}

/* Video Placeholder */
#video-placeholder {
    display: none;
    background: #000;
    padding: 0;
    margin: 0;
}

body.video-mode #video-placeholder {
    display: block;
    grid-area: video;
    position: relative;
    border-left: 1px solid var(--border-color);
}

/* Close Button in Video Mode */
#video-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    z-index: 100;
}

#video-close-btn:hover {
    background: rgba(255, 50, 50, 0.8);
    border-color: red;
}


/* --- Video Controls Overlay --- */
#video-controls-overlay {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 10px;
    align-items: center;
    z-index: 100;
}

#video-controls-overlay select {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    min-width: 100px;
    font-size: 0.9em;
    margin-bottom: 0px !important;
}

#video-controls-overlay select:focus {
    border-color: var(--accent-blue);
    outline: none;
}

#video-controls-overlay button {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 5px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    height: auto;
    width: auto;
}

#video-controls-overlay button:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Specific style for Play Button in video overlay */
#video-play-btn {
    min-width: 80px;
    font-size: 1.2em;
    /* Matched to icons (1.2em) */
}

/* Adjust Close Button to fit in overlay flow */
#video-close-btn {
    position: static !important;
    /* Override absolute positioning */
    width: 32px !important;
    height: 32px !important;
    font-size: 1.2rem !important;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 0, 0, 0.3) !important;
    border-color: rgba(255, 0, 0, 0.5) !important;
}

#video-close-btn:hover {
    background: rgba(255, 0, 0, 0.6) !important;
}

/* --- Video Mode Overrides --- */
body.video-mode {
    background-color: #000000;
    color: #ffffff;
}

body.video-mode .app-container,
body.video-mode .sidebar,
body.video-mode .main-content,
body.video-mode .view-container,
body.video-mode .terminal-wrapper,
body.video-mode .terminal-header,
body.video-mode .chart-wrapper,
body.video-mode .chart-header,
body.video-mode .stats-container,
body.video-mode select {
    background-color: #000000;
    border-color: #333;
    color: #ffffff;
}

body.video-mode .chart-title,
body.video-mode .chart-stats,
body.video-mode label {
    color: #ffffff;
}

/* Hide Standard Charts */
body.video-mode #tx-chart-wrapper,
body.video-mode #rx-chart-wrapper {
    display: none !important;
}

/* Show Video Charts Row */
body.video-mode #video-charts-row {
    display: flex !important;
    flex-direction: row;
    flex: 1;
    width: 100%;
    min-height: 0;
    border-top: 1px solid #111 !important;
    /* Separator between Map and Charts */
}

body.video-mode #video-charts-row .chart-wrapper {
    display: flex !important;
    flex-direction: column;
    flex: 1;
    width: 50% !important;
    height: 100% !important;
    grid-area: auto !important;
    /* Override generic rx grid placement */
    border-bottom: none;
    border-right: 1px solid #111 !important;
    border-left: none !important;
    min-height: 0;
}

body.video-mode #video-charts-row .chart-wrapper:last-child {
    border-right: none !important;
    width: 50% !important;
    /* Ensure last child isn't forced to 100% by generic rule */
}

/* Fix Canvas Sizing */
body.video-mode .chart-canvas-container {
    flex: 1;
    height: 100% !important;
    min-height: 200px !important;
    /* Force minimum height */
    width: 100% !important;
    position: relative;
}

body.video-mode canvas {
    max-width: 100%;
}

/* Fix for Leaflet Layer Canvases being constrained */
body.video-mode .leaflet-pane canvas {
    max-width: none !important;
}

/* Increase Header Font Size for Video Mode */
body.video-mode .chart-header {
    font-size: 1.3em !important;
    /* Scales title and stats */
}

body.video-mode .chart-stats {
    font-size: 1em !important;
    /* Inherits increase from header or ensures consistency */
}

/* Remove all generic blue borders in video mode */
body.video-mode .stats-container,
body.video-mode .view-container,
body.video-mode .map-container {
    border: none !important;
}

/* Separator between Charts and Video Placeholder */
body.video-mode #video-placeholder {
    border-left: 1px solid #111 !important;
    border-top: none !important;
    border-right: none !important;
    border-bottom: none !important;
}

/* Legend Indicators for Video Mode Headers */
.legend-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* Fix for Chart Bottom Cutoff */
body.video-mode .chart-canvas-container {
    padding-bottom: 20px !important;
    /* Ensure space for X-axis labels */
}

/* Dark Mode Map Tiles */
body.video-mode .leaflet-tile-pane {
    filter: invert(100%) hue-rotate(180deg);
}

/* Dark Mode Leaflet Attribution */
body.video-mode .leaflet-control-attribution {
    background: #000000 !important;
    color: #cccccc !important;
}

body.video-mode .leaflet-control-attribution a {
    color: #4CAF50 !important;
    /* Green like other links or just white */
}

/* Video Mode: Light Map Theme Overrides */
body.video-mode.video-map-light .leaflet-tile-pane {
    filter: none !important;
}

body.video-mode.video-map-light .leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.8) !important;
    color: #333 !important;
}

body.video-mode.video-map-light .leaflet-control-attribution a {
    color: #0078A8 !important;
    /* Standard Leaflet Blue */
}

/* Light Theme Overrides (Full UI) */
body.video-mode.video-map-light {
    background-color: #ffffff !important;
    color: #000000 !important;
}

body.video-mode.video-map-light .app-container,
body.video-mode.video-map-light .main-content,
body.video-mode.video-map-light .view-container,
body.video-mode.video-map-light .stats-container,
body.video-mode.video-map-light select {
    background-color: #ffffff !important;
    color: #000000 !important;
    border-color: #ddd !important;
}

body.video-mode.video-map-light .chart-stats,
body.video-mode.video-map-light .chart-title,
body.video-mode.video-map-light label {
    color: #000000 !important;
}

/* Tooltip-like styling for headers in light mode */
body.video-mode.video-map-light .chart-header {
    background-color: #fff !important;
    border: 1px solid #fff !important;
    border-radius: 3px !important;
    color: #222 !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4) !important;
    padding: 6px !important;
    font-family: "Helvetica Neue", Arial, Helvetica, sans-serif !important;
    margin: 5px !important;
    width: auto !important;
}

/* Light gray background for charts in light mode */
body.video-mode.video-map-light .chart-wrapper,
body.video-mode.video-map-light .chart-canvas-container {
    background-color: #f0f0f0 !important;
}

/* Separator override for light mode */
body.video-mode.video-map-light #video-charts-row {
    border-top-color: #000000 !important;
}

/* Fix borders for light mode */
body.video-mode.video-map-light .chart-wrapper {
    border-right-color: #ddd !important;
    border-left-color: #ddd !important;
}

body.video-mode.video-map-light #video-placeholder {
    border-left-color: #ddd !important;
}

/* Revert video controls to dark mode style */
body.video-mode.video-map-light #video-controls-overlay select {
    background-color: rgba(0, 0, 0, 0.5) !important;
    color: #ffffff !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
}

/* Distance Tooltip Styling */
.distance-popup-content {
    background: transparent;
    color: black;
    font-weight: bold;
    font-size: 12px;
    text-shadow: 1px 1px 0 #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff;
}

/* Video Mode Distance Tooltip */
body.video-mode .distance-popup-content {
    font-size: 20px !important;
    /* Match larger metric headers */
}

/* Map & GNSS Editor Styles */
.floating-panel {
    position: absolute;
    top: 60px;
    right: 60px;
    /* Offset from right controls */
    width: 320px;
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 15px;
    z-index: 2000;
    /* Above map controls */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    display: none;
    max-height: 80vh;
    overflow-y: auto;
    color: var(--text-primary);
}

.floating-panel.active {
    display: block;
}

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

.layer-item,
.gnss-point-item {
    background: var(--bg-dark);
    padding: 10px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.layer-controls {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 5px;
}

.layer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.crosshair-cursor {
    cursor: crosshair !important;
}

.editor-mode-indicator {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 5px 15px;
    border-radius: 20px;
    z-index: 2000;
    pointer-events: none;
    font-weight: bold;
    display: none;
    border: 1px solid var(--accent-green);
}

.editor-mode-indicator.active {
    display: block;
}

.timestamp-input {
    background: #111;
    border: 1px solid #444;
    color: #fff;
    width: 140px;
    font-size: 0.8em;
    padding: 2px 5px;
}

/* Ensure Custom Canvas Layers are Visible */
/* Ensure Custom Canvas Layers are Visible */
.leaflet-image-layer {
    display: block !important;
    visibility: visible !important;
    opacity: 1;
    /* Allow JS to override, but ensure base is visible */
    pointer-events: none;
    /* Ensure clicks pass through by default */
    z-index: 500 !important;
    /* Ensure it's above tiles */
    position: absolute !important;
}

/* GNSS Editor Marker Label */
.leaflet-tooltip.gnss-marker-label {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: #fff;
    text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
    font-weight: bold;
    font-size: 10px;
    padding: 0;
    line-height: normal;
}

.leaflet-tooltip.gnss-marker-label::before {
    display: none !important;
    border: none !important;
}

.active-moving {
    background-color: #333;
    /* lighter than #222 */
    border-left: 3px solid orange;
}