:root {
    --bg-dark: #0a0e14;
    --bg-card: #141a24;
    --bg-input: #1a222e;
    --bg-hover: #1e2836;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --danger: #ef4444;
    --warn: #f59e0b;
    --text-main: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #2a3444;
    --border-light: #3a4454;
    --ch0: #ef4444;
    --ch1: #3b82f6;
    --ch2: #10b981;
    --ch3: #f59e0b;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.navbar {
    height: 52px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
}

.navbar-brand svg {
    color: var(--primary);
}

.navbar-info {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.layout {
    display: flex;
    height: calc(100vh - 52px);
}

.sidebar {
    width: 280px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

.drop-zone svg {
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.drop-zone p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.drop-zone p.small {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.file-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    max-height: 200px;
}

.file-list .empty {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
    padding: 1rem;
    font-style: italic;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.15s;
}

.file-item:hover {
    background: var(--bg-hover);
}

.file-item.selected {
    background: rgba(59, 130, 246, 0.15);
    border-left: 2px solid var(--primary);
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.file-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    border-radius: 0.25rem;
    transition: all 0.15s;
}

.file-remove:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.info-panel {
    font-size: 0.8rem;
}

.info-panel .placeholder {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 1rem 0;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
}

.info-row:last-child {
    border-bottom: none;
}

.info-row span:first-child {
    color: var(--text-muted);
}

.info-row span:last-child {
    color: var(--text-main);
    font-weight: 500;
}

.info-row .mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
}

.info-row.merged {
    background: rgba(59, 130, 246, 0.1);
    margin: 0.5rem -1rem -1rem;
    padding: 0.5rem 1rem;
    border-radius: 0 0 0.5rem 0.5rem;
}

.gps-valid {
    color: var(--success);
}

.gps-invalid {
    color: var(--text-muted);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar-group label {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.toolbar-group input[type="checkbox"] {
    accent-color: var(--primary);
}

.toolbar-actions {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
}

.channel-toggles {
    display: flex;
    gap: 0.25rem;
}

.channel-btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-muted);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.15s;
}

.channel-btn:hover {
    border-color: var(--ch-color);
}

.channel-btn.active {
    background: var(--ch-color);
    border-color: var(--ch-color);
    color: #0a0e14;
    text-shadow: none;
}

.channel-btn[data-channel="0"].active,
.channel-btn[data-channel="3"].active {
    color: white;
}

select {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    color: var(--text-main);
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.15s;
    color: white;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.btn-small {
    background: #10b981;
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
}

.delta-config {
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.delta-config.hidden {
    display: none;
}

.delta-selectors {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.delta-selectors > div {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.delta-selectors label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.delta-operator {
    font-size: 1.5rem;
    font-weight: 300;
    color: var(--text-muted);
}

.charts-container {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chart-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.chart-placeholder svg {
    margin-bottom: 1rem;
    opacity: 0.5;
}

.chart-placeholder p {
    font-size: 0.9rem;
}

.chart-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem;
    min-height: 180px;
}

.chart-wrapper.overlay,
.chart-wrapper.delta {
    flex: 1;
    min-height: 400px;
}

.chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

.stats-bar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.stat-label {
    color: var(--text-muted);
}

.stat-value {
    color: var(--text-main);
    font-family: 'JetBrains Mono', monospace;
}

.cursor-info {
    margin-left: auto;
}

.analysis-panel {
    width: 320px;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.2s;
}

.analysis-panel.collapsed {
    width: 40px;
}

.analysis-panel.collapsed .panel-content {
    display: none;
}

.analysis-panel.collapsed .panel-header h3 {
    display: none;
}

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

.panel-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
}

.panel-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.analysis-panel.collapsed .panel-toggle {
    transform: rotate(180deg);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.analysis-section {
    margin-bottom: 1.25rem;
}

.analysis-section h4 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
}

.time-range {
    display: grid;
    gap: 0.5rem;
}

.time-input {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.time-input label {
    font-size: 0.75rem;
    color: var(--text-muted);
    width: 60px;
}

.time-input input {
    flex: 1;
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    color: var(--text-main);
}

.time-input input:focus {
    outline: none;
    border-color: var(--primary);
}

.time-range .btn {
    margin-top: 0.25rem;
}

.stats-grid {
    font-size: 0.75rem;
}

.stat-row {
    display: grid;
    grid-template-columns: 40px repeat(4, 1fr);
    gap: 0.25rem;
    padding: 0.35rem 0.5rem;
    border-radius: 0.25rem;
}

.stat-row.header {
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.25rem;
}

.stat-row:not(.header) {
    background: var(--bg-input);
    margin-bottom: 0.2rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
}

.cursor-measurements {
    font-size: 0.8rem;
}

.cursor-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
}

.cursor-row label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.cursor-row.delta {
    color: var(--text-muted);
}

.cursor-row.delta span:last-child {
    font-family: 'JetBrains Mono', monospace;
    color: var(--primary);
}

.fft-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.fft-freq-range {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.freq-input {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex: 1;
}

.freq-input label {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.freq-input input {
    flex: 1;
    padding: 0.25rem 0.4rem;
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    color: var(--text-main);
    width: 60px;
}

.freq-input input:focus {
    outline: none;
    border-color: var(--primary);
}

.fft-chart-container {
    height: 150px;
    background: var(--bg-input);
    border-radius: 0.375rem;
    padding: 0.5rem;
}

.export-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.export-options label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.export-channels {
    display: flex;
    gap: 0.75rem;
    padding: 0.5rem;
    background: var(--bg-input);
    border-radius: 0.25rem;
    flex-wrap: wrap;
}

.export-channels label {
    font-size: 0.75rem;
}

.export-channels.hidden {
    display: none;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    max-width: 400px;
    text-align: center;
}

.modal-content h3 {
    margin-bottom: 0.75rem;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

@media (max-width: 1200px) {
    .analysis-panel {
        position: fixed;
        right: 0;
        top: 52px;
        height: calc(100vh - 52px);
        z-index: 100;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .analysis-panel.collapsed {
        width: 40px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 52px;
        height: calc(100vh - 52px);
        z-index: 100;
        transition: left 0.3s;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .sidebar.open {
        left: 0;
    }

    .toolbar {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .toolbar-group label {
        display: none;
    }

    .toolbar-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .charts-container {
        padding: 0.5rem;
    }

    .chart-wrapper {
        min-height: 150px;
    }

    .stats-bar {
        flex-wrap: wrap;
        gap: 0.5rem 1rem;
    }

    .analysis-panel {
        width: 100%;
        max-width: 320px;
    }
}
