*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #0f1117;
    color: #e0e0e0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---- Browser view ---- */
#browser-view {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#browser-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #1a1d27;
    border-bottom: 1px solid #2a2d3a;
    flex-shrink: 0;
}

.browser-title {
    font-size: 14px;
    font-weight: 600;
    color: #e0e0e0;
    margin-right: 12px;
    white-space: nowrap;
}

#browser-topbar label {
    font-size: 13px;
    color: #9aa;
    white-space: nowrap;
}

#data-root-input {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #3a3d4a;
    background: #0f1117;
    color: #e0e0e0;
    border-radius: 4px;
    font-size: 13px;
    font-family: monospace;
}

#set-root-btn {
    padding: 5px 14px;
    background: #3a7bd5;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}
#set-root-btn:hover { background: #4a8be5; }

#browser-columns {
    display: flex;
    flex: 1;
    overflow-x: auto;
    min-height: 0;
}

.browser-column {
    min-width: 200px;
    flex: 1;
    border-right: 1px solid #2a2d3a;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.col-header {
    padding: 8px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9aa;
    background: #13151f;
    border-bottom: 1px solid #2a2d3a;
    flex-shrink: 0;
}

.col-body {
    flex: 1;
    overflow-y: auto;
}

.browser-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    border-left: 3px solid transparent;
}
.browser-item:hover { background: #1e2133; }
.browser-item.selected {
    border-left-color: #3a7bd5;
    background: #1a1d27;
}

.browser-item-name {
    font-size: 13px;
    color: #e0e0e0;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.browser-item-sub {
    font-size: 11px;
    color: #777;
    flex-shrink: 0;
}

.browser-empty {
    padding: 16px 12px;
    color: #555;
    font-size: 12px;
}

/* ---- Metadata table in detail column ---- */
.metadata-table {
    width: 100%;
    border-collapse: collapse;
}

.metadata-table td {
    padding: 6px 12px;
    font-size: 12px;
    border-bottom: 1px solid #1e2133;
    vertical-align: top;
}

.meta-key {
    color: #9aa;
    width: 40%;
    white-space: nowrap;
}

.meta-value {
    color: #e0e0e0;
}

/* ---- Recording badges ---- */
.recording-badges {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.recording-badge {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-events {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.badge-channels {
    background: rgba(74, 222, 128, 0.2);
    color: #4ade80;
}

/* ---- Breadcrumb in analysis topbar ---- */
#recording-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0;
    font-size: 13px;
    min-width: 0;
    overflow: hidden;
}

.breadcrumb-sep {
    color: #555;
    flex-shrink: 0;
}

.breadcrumb-segment {
    color: #e0e0e0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.breadcrumb-clickable {
    color: #4e9af1;
    cursor: pointer;
}
.breadcrumb-clickable:hover {
    text-decoration: underline;
}

#browse-btn {
    padding: 5px 14px;
    background: transparent;
    color: #9aa;
    border: 1px solid #3a3d4a;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
}
#browse-btn:hover { background: #252840; color: #e0e0e0; }

/* ---- Analysis view ---- */
#analysis-view {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ---- Top bar ---- */
#topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #1a1d27;
    border-bottom: 1px solid #2a2d3a;
    flex-shrink: 0;
}

#topbar label { font-size: 13px; color: #9aa; white-space: nowrap; }

#path-input {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #3a3d4a;
    background: #0f1117;
    color: #e0e0e0;
    border-radius: 4px;
    font-size: 13px;
    font-family: monospace;
}

#load-btn {
    padding: 5px 14px;
    background: #3a7bd5;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}
#load-btn:hover { background: #4a8be5; }
#load-btn:disabled { background: #555; cursor: not-allowed; }

#shutdown-btn {
    padding: 5px 10px;
    background: transparent;
    color: #c55;
    border: 1px solid #c55;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}
#shutdown-btn:hover { background: #c55; color: #fff; }

#status-msg {
    font-size: 12px;
    color: #e88;
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

#notch-select {
    padding: 5px 6px;
    background: #0f1117;
    border: 1px solid #3a3d4a;
    color: #e0e0e0;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}
#notch-select:disabled { color: #555; cursor: not-allowed; }
#notch-select:not(:disabled):hover { border-color: #5a5d6a; }

#layout-btn {
    padding: 5px 10px;
    background: transparent;
    border: 1px solid #3a3d4a;
    color: #9aa;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}
#layout-btn:hover { background: #252840; color: #e0e0e0; }

/* ---- Workspace ---- */
#workspace {
    flex: 1;
    display: flex;
    flex-direction: row;
    min-height: 0;
    overflow: hidden;
}

/* ---- Sidebar ---- */
#sidebar {
    width: 220px;
    flex-shrink: 0;
    background: #13151f;
    border-right: 1px solid #2a2d3a;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.2s ease;
}

#sidebar.collapsed {
    width: 0;
    border-right: none;
}

#sidebar-header {
    flex-shrink: 0;
    padding: 8px;
    border-bottom: 1px solid #2a2d3a;
}

.montage-bar, .filter-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 6px;
}
.filter-bar { margin-bottom: 0; }

.montage-btn, .filter-btn {
    flex: 1;
    padding: 3px 0;
    background: transparent;
    border: 1px solid #3a3d4a;
    color: #9aa;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
}
.montage-btn.active, .filter-btn.active {
    background: #3a7bd5;
    border-color: #3a7bd5;
    color: #fff;
}
.montage-btn:hover:not(.active), .filter-btn:hover:not(.active) {
    background: #252840;
}

#channel-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.ch-placeholder {
    padding: 16px 12px;
    color: #555;
    font-size: 12px;
}

/* ---- Channel groups ---- */
.ch-group { border-bottom: 1px solid #1e2133; }

.ch-group-header {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 8px;
    cursor: pointer;
    user-select: none;
}
.ch-group-header:hover { background: #1e2133; }

.ch-group-toggle {
    font-size: 10px;
    color: #9aa;
    width: 12px;
    flex-shrink: 0;
}

.ch-group-label {
    flex: 1;
    font-size: 12px;
    color: #ccc;
    font-weight: 500;
}

.ch-group-dots {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    max-width: 70px;
    justify-content: flex-end;
}

/* ---- Contact rows ---- */
.ch-contact {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px 3px 24px;
    cursor: pointer;
    font-size: 11px;
    color: #888;
}
.ch-contact:hover { background: #1e2133; }
.ch-contact.selected { color: #e0e0e0; background: #1c2035; }

.ch-status-desc {
    font-size: 9px;
    color: #777;
    margin-left: auto;
    flex-shrink: 0;
}

/* ---- Status dots ---- */
.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}

.status-good  { background: #4caf7a; }
.status-bad   { background: #e05555; }
.status-soz   { background: #f59e0b; }
.status-resect { background: #a855f7; }
.status-unknown { background: #555; }

/* ---- Spectrogram channel row ---- */
#spect-ch-row {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-top: 1px solid #2a2d3a;
}

#spect-ch-row label {
    font-size: 11px;
    color: #9aa;
    white-space: nowrap;
    flex-shrink: 0;
}

#spect-channel-select {
    flex: 1;
    padding: 3px 4px;
    background: #0f1117;
    border: 1px solid #3a3d4a;
    color: #e0e0e0;
    border-radius: 3px;
    font-size: 11px;
    min-width: 0;
}

/* ---- Sidebar toggle ---- */
#sidebar-toggle {
    width: 16px;
    flex-shrink: 0;
    background: #13151f;
    border: none;
    border-right: 1px solid #2a2d3a;
    color: #555;
    cursor: pointer;
    font-size: 10px;
    padding: 0;
    align-self: stretch;
}
#sidebar-toggle:hover { background: #1e2133; color: #9aa; }

/* ---- Main panel grid ---- */
#main {
    flex: 1;
    display: grid;
    grid-template-rows: 1fr;
    grid-template-columns: 1fr;
    min-height: 0;
    gap: 4px;
    padding: 4px;
    overflow: hidden;
}

.panel {
    background: #1a1d27;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-bottom: 1px solid #2a2d3a;
    font-size: 12px;
    color: #9aa;
    flex-shrink: 0;
}

.panel-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ---- Placeholder text ---- */
.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #555;
    font-size: 13px;
}

/* ---- File browser modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: #1a1d27;
    border: 1px solid #3a3d4a;
    border-radius: 8px;
    width: 560px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid #2a2d3a;
    flex-shrink: 0;
    font-size: 13px;
    color: #ccc;
}

.fb-path-label {
    font-family: monospace;
    font-size: 12px;
    color: #9aa;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fb-close-btn {
    background: transparent;
    border: none;
    color: #9aa;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    flex-shrink: 0;
}
.fb-close-btn:hover { color: #fff; }

.fb-list {
    overflow-y: auto;
    flex: 1;
    padding: 4px 0;
}

.fb-entry {
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fb-entry:hover { background: #252840; }
.fb-dir  { color: #4e9af1; }
.fb-file { color: #e0e0e0; }

/* ---- Layout modal ---- */
.layout-modal-inner {
    width: 640px;
    max-height: 80vh;
}

.layout-modal-body {
    display: flex;
    gap: 0;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.layout-presets {
    width: 140px;
    flex-shrink: 0;
    padding: 12px;
    border-right: 1px solid #2a2d3a;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.layout-custom {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
}

.layout-section-title {
    font-size: 11px;
    color: #9aa;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.preset-btn {
    padding: 7px 10px;
    background: transparent;
    border: 1px solid #3a3d4a;
    color: #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    text-align: left;
}
.preset-btn:hover { background: #252840; border-color: #3a7bd5; color: #fff; }

.grid-size-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.grid-size-row label {
    font-size: 12px;
    color: #9aa;
    display: flex;
    align-items: center;
    gap: 4px;
}

.grid-size-row select {
    padding: 3px 6px;
    background: #0f1117;
    border: 1px solid #3a3d4a;
    color: #e0e0e0;
    border-radius: 3px;
    font-size: 12px;
}

#grid-size-apply {
    padding: 4px 10px;
    background: transparent;
    border: 1px solid #3a3d4a;
    color: #9aa;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
}
#grid-size-apply:hover { background: #252840; }

#grid-editor {
    display: grid;
    gap: 6px;
    min-height: 60px;
}

.grid-cell-select {
    padding: 5px 6px;
    background: #0f1117;
    border: 1px solid #3a3d4a;
    color: #e0e0e0;
    border-radius: 4px;
    font-size: 12px;
    width: 100%;
}

#layout-apply-btn {
    padding: 8px 16px;
    background: #3a7bd5;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    align-self: flex-start;
}
#layout-apply-btn:hover { background: #4a8be5; }

/* ---- 3D Brain panel ---- */
.brain-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-bottom: 1px solid #2a2d3a;
    flex-shrink: 0;
}

.brain-metric-select {
    padding: 3px 6px;
    background: #0f1117;
    border: 1px solid #3a3d4a;
    color: #e0e0e0;
    border-radius: 3px;
    font-size: 12px;
}

.brain-scrub-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-top: 1px solid #2a2d3a;
    flex-shrink: 0;
}

.brain-scrubber {
    flex: 1;
    accent-color: #3a7bd5;
}

.brain-time-label {
    font-size: 11px;
    color: #9aa;
    white-space: nowrap;
    min-width: 60px;
}

.brain-play-btn {
    padding: 2px 8px;
    background: transparent;
    border: 1px solid #3a3d4a;
    color: #ccc;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    flex-shrink: 0;
}
.brain-play-btn:hover { background: #252840; }

.brain-speed-select {
    padding: 2px 4px;
    background: #0f1117;
    border: 1px solid #3a3d4a;
    color: #9aa;
    border-radius: 3px;
    font-size: 11px;
    flex-shrink: 0;
}

/* ---- Folder picker modal ---- */
.folder-picker-inner {
    width: 520px;
    max-height: 70vh;
}

.folder-picker-pathbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-bottom: 1px solid #2a2d3a;
}

#fp-path-input {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #3a3d4a;
    background: #0f1117;
    color: #e0e0e0;
    border-radius: 4px;
    font-size: 13px;
    font-family: monospace;
}

#fp-up-btn, #fp-go-btn {
    padding: 5px 10px;
    background: transparent;
    border: 1px solid #3a3d4a;
    color: #9aa;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    flex-shrink: 0;
}
#fp-up-btn:hover, #fp-go-btn:hover { background: #252840; color: #e0e0e0; }

.folder-picker-footer {
    padding: 8px 12px;
    border-top: 1px solid #2a2d3a;
    display: flex;
    justify-content: flex-end;
}

#fp-select-btn {
    padding: 7px 18px;
    background: #3a7bd5;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
#fp-select-btn:hover { background: #4a8be5; }

/* ---- Download status badges ---- */
.badge-downloaded {
    background: rgba(74, 222, 128, 0.2);
    color: #4ade80;
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.badge-cloud {
    background: rgba(147, 155, 255, 0.15);
    color: #939bff;
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

/* ---- Download modal ---- */
.download-modal-inner {
    width: 520px;
    max-height: 70vh;
}

.download-modal-body {
    padding: 16px;
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.download-modal-body p {
    font-size: 13px;
    color: #ccc;
    line-height: 1.5;
}

.download-progress-bar {
    height: 4px;
    background: #2a2d3a;
    border-radius: 2px;
    overflow: hidden;
    flex-shrink: 0;
}

.download-progress-fill {
    height: 100%;
    background: #3a7bd5;
    width: 0%;
    transition: width 0.3s;
}

.download-progress-fill.indeterminate {
    width: 30%;
    animation: indeterminate 1.5s ease-in-out infinite;
}

@keyframes indeterminate {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

#download-log {
    max-height: 200px;
    overflow-y: auto;
    font-size: 11px;
    color: #9aa;
    background: #0f1117;
    padding: 8px;
    border-radius: 4px;
    white-space: pre-wrap;
    word-break: break-all;
    flex: 1;
    min-height: 60px;
}

.download-modal-footer {
    padding: 10px 16px;
    border-top: 1px solid #2a2d3a;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

#download-cancel-btn {
    padding: 7px 16px;
    background: transparent;
    border: 1px solid #3a3d4a;
    color: #9aa;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
#download-cancel-btn:hover { background: #252840; color: #e0e0e0; }

#download-start-btn {
    padding: 7px 18px;
    background: #3a7bd5;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
#download-start-btn:hover { background: #4a8be5; }
#download-start-btn:disabled { background: #555; cursor: not-allowed; }

/* Plotly modebar dark tweak */
.modebar { background: transparent !important; }
.modebar-btn path { fill: #9aa !important; }
