/**
 * ============================================================================
 * STROKE 2D BRAIN ATLAS VIEWER - Complete UI Stylesheet
 * ============================================================================
 *
 * Professional Medical Dashboard Design
 * 6-Column Grid Layout:
 * [MRI Nav] [In vivo MRI] [MRI Registered] [Histology] [Icon Bar] [Histology Nav]
 *
 * ============================================================================
 */

/* ============================================================================
   CSS RESET & BASE
   ============================================================================ */

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

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
    font-size: 13px;
    line-height: 1.4;
    background-color: #f5f5f5;
    color: #333;
}

/* ============================================================================
   FULL PAGE LOADER
   ============================================================================ */

.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 99999;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.page-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 40px 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    min-width: 280px;
}

.loader-spinner {
    width: 56px;
    height: 56px;
    border: 4px solid rgba(33, 150, 243, 0.2);
    border-top-color: #2196F3;
    border-radius: 50%;
    animation: loader-spin 1s linear infinite;
}

@keyframes loader-spin {
    to {
        transform: rotate(360deg);
    }
}

.loader-title {
    font-size: 20px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 8px 0 0 0;
}

.loader-subtitle {
    font-size: 14px;
    font-weight: 400;
    color: #666666;
    margin: 0;
}

/* Dark mode support for loader */
body.dark-mode .page-loader {
    background: rgba(0, 0, 0, 0.7);
}

body.dark-mode .loader-card {
    background: #1e293b;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

body.dark-mode .loader-spinner {
    border-color: rgba(33, 150, 243, 0.3);
    border-top-color: #2196F3;
}

body.dark-mode .loader-title {
    color: #f1f5f9;
}

body.dark-mode .loader-subtitle {
    color: #94a3b8;
}

/* ============================================================================
   CSS VARIABLES
   ============================================================================ */

:root {
    /* Layout Dimensions */
    --header-height: 60px;
    --footer-height: 32px;
    /* Sidebar dimensions - increased for better readability */
    --sidebar-width: 200px;
    --tools-width: 155px;
    --mri-column-width: 240px;
    --icon-bar-width: 70px;

    /* Colors - Light Theme */
    --bg-color: #f5f5f5;
    --surface-color: #ffffff;
    --border-color: #ddd;
    --text-color: #333;
    --text-muted: #666;

    /* Additional variables for thumbnail popup (from old UI) */
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-dark: rgba(0, 0, 0, 0.15);
    --light-surface: #f0f0f0;

    /* Header Colors */
    --mri-nav-header: #fce4d6;      /* Peach/salmon */
    --mri-blue-header: #d6eaf8;     /* Light blue */
    --histology-nav-header: #fce4d6; /* Peach/salmon */

    /* Accent Colors */
    --primary-color: #2196F3;
    --crosshair-yellow: #f5c400;
    --crosshair-black: #000000;
    --crosshair-blue-dashed: rgba(100, 149, 237, 0.6);

    /* MRI Panel */
    --mri-bg: #1a1a2e;
    --mri-text: #ffffff;

    /* Slider */
    --slider-track: #ccc;
    --slider-thumb: #888;
    --slider-bar-bg: #e9ecef;
}

/* ============================================================================
   DARK MODE
   ============================================================================ */

body.dark-mode {
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --border-color: #334155;
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;

    /* Shadow variables - Dark Mode */
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-dark: rgba(0, 0, 0, 0.4);
    --light-surface: #334155;

    /* Header Colors - Dark Mode */
    --mri-nav-header: #4a3728;
    --mri-blue-header: #1e3a5f;
    --histology-nav-header: #4a3728;

    /* MRI Panel - Dark Mode */
    --mri-bg: #000000;

    /* Slider - Dark Mode */
    --slider-track: #475569;
    --slider-thumb: #64748b;
    --slider-bar-bg: #334155;

    background-color: var(--bg-color);
    color: var(--text-color);
}

body.dark-mode .header {
    background: linear-gradient(135deg, var(--surface-color) 0%, #1a2744 100%);
    border-color: var(--border-color);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.2);
}

body.dark-mode .sidebar {
    background: linear-gradient(180deg, var(--surface-color) 0%, #151d2e 100%);
    border-color: var(--border-color);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.2);
}

body.dark-mode .sidebar-header.mri-header,
body.dark-mode .sidebar-header.histology-header {
    background: var(--mri-nav-header);
    color: var(--text-color);
}

body.dark-mode .column-header.mri-blue-header {
    background: var(--mri-blue-header);
    color: var(--text-color);
}

body.dark-mode .mri-column {
    background: linear-gradient(180deg, #1a2744 0%, var(--surface-color) 100%);
    border-color: var(--border-color);
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.2);
}

body.dark-mode .histology-column {
    background: linear-gradient(180deg, #151d2e 0%, var(--surface-color) 100%);
    border-color: var(--border-color);
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.2);
}

body.dark-mode .histology-panel {
    background: var(--surface-color);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.2);
}

body.dark-mode .mri-view-card {
    background: #0f1420;
    border-color: rgba(255, 255, 255, 0.06);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3), 0 2px 6px rgba(0, 0, 0, 0.2);
}

body.dark-mode .mri-view-card:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), 0 4px 10px rgba(0, 0, 0, 0.25);
}

body.dark-mode .mri-view-image {
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(60, 60, 80, 0.3);
}

body.dark-mode .mri-slider {
    background: #555;
}

body.dark-mode .mri-slider::-webkit-slider-thumb {
    background: #ccc;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

body.dark-mode .mri-slider::-moz-range-thumb {
    background: #ccc;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

body.dark-mode .histology-panel-header,
body.dark-mode .histology-panel-footer {
    background: var(--surface-color);
    border-color: var(--border-color);
}

body.dark-mode .control-select {
    background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
    border-color: var(--border-color);
    color: var(--text-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

body.dark-mode .control-select:hover {
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

body.dark-mode .control-select:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

body.dark-mode .action-btn {
    background: var(--bg-color);
    border-color: var(--border-color);
    color: var(--text-color);
}

body.dark-mode .action-btn:hover {
    background: var(--surface-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Dark mode - Annotations */
body.dark-mode .action-btn-annotations.active {
    background: rgba(236, 72, 153, 0.2);
    border-color: #ec4899;
    color: #f9a8d4;
}

/* Dark mode - Heatmap */
body.dark-mode .action-btn-heatmap.active {
    background: rgba(245, 158, 11, 0.2);
    border-color: #f59e0b;
    color: #fcd34d;
}

/* Dark mode - Measure */
body.dark-mode .action-btn-measure.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: #3b82f6;
    color: #93c5fd;
}

/* Dark mode - 3D */
body.dark-mode .action-btn-3d {
    background: linear-gradient(135deg, #1e293b 0%, #2e1065 100%);
}

body.dark-mode .action-btn-3d:hover {
    background: linear-gradient(135deg, #2e1065 0%, #4c1d95 100%);
}

body.dark-mode .nav-btn {
    background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
    border-color: var(--border-color);
    color: var(--text-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

body.dark-mode .nav-btn:hover {
    background: linear-gradient(145deg, #2d3a4f 0%, #1e293b 100%);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

body.dark-mode .footer-nav-controls .nav-separator {
    color: var(--text-muted);
}

body.dark-mode .footer-bar {
    background: linear-gradient(180deg, #1a2744 0%, var(--surface-color) 100%);
    border-color: var(--border-color);
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.2);
}

body.dark-mode .coord-value {
    background: rgba(255, 255, 255, 0.08);
}

body.dark-mode .coordinates-box {
    background: linear-gradient(145deg, #0f172a 0%, #1e293b 100%);
    border-color: var(--border-color);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Dark mode thumbnail styles are defined in the THUMBNAIL POPUP section below */

body.dark-mode .histology-ref-panel .ref-panel-expanded {
    background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
    border-color: var(--border-color);
}

body.dark-mode .ref-panel-header {
    border-color: var(--border-color);
    background: linear-gradient(135deg, #1e293b 0%, #1a1f2e 100%);
}

body.dark-mode .ref-panel-title::before {
    color: #475569;
}

body.dark-mode .mri-placeholder-message {
    color: var(--text-secondary);
}

body.dark-mode .loading-overlay {
    background: rgba(15, 23, 42, 0.9);
}

body.dark-mode .theme-toggle {
    background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
    border-color: var(--border-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

body.dark-mode .theme-toggle:hover {
    background: linear-gradient(145deg, #2d3a4f 0%, #1e293b 100%);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Dark mode - Map elements */
body.dark-mode .histology-map-wrapper {
    background: #0f172a;
}

body.dark-mode .histology-map-container {
    background: #1e293b;
}

/* Dark mode - Error overlay */
body.dark-mode .loading-overlay.image-error {
    background: rgba(30, 30, 30, 0.88);
    color: #ff6b6b;
}

body.dark-mode .loading-overlay.image-error .error-message {
    color: #ff6b6b;
}

body.dark-mode .loading-overlay.image-error .error-detail {
    color: rgba(255, 255, 255, 0.6);
}

body.dark-mode .loading-overlay.image-error .error-recovery-label {
    color: rgba(255, 255, 255, 0.5);
}

body.dark-mode .loading-overlay.image-error .error-stain-btn {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.25);
}

body.dark-mode .loading-overlay.image-error .error-stain-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

body.dark-mode .loading-overlay.image-error .error-nav-btn {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.4);
    color: #60a5fa;
}

body.dark-mode .loading-overlay.image-error .error-nav-btn:hover {
    background: rgba(59, 130, 246, 0.35);
    border-color: rgba(59, 130, 246, 0.6);
}

/* Dark mode - Axis Legend */
body.dark-mode .axis-legend-box {
    background: linear-gradient(145deg, #1a1a2e 0%, #16213e 100%);
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .axis-label {
    color: #ccc;
}

body.dark-mode .axis-legend-note {
    border-top-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .stain-badge {
    background: #dc2626;
}

body.dark-mode .brain-id-badge {
    background: #2980b9;
}

body.dark-mode .section-id-badge {
    background: #1e8449;
}

body.dark-mode .cursor-coords {
    background: rgba(0, 0, 0, 0.5);
}

body.dark-mode .icon-bar-select {
    background: var(--bg-color);
    border-color: var(--border-color);
    color: var(--text-color);
}

/* ============================================================================
   SELECT/DROPDOWN OPTION STYLING - BOTH MODES
   ============================================================================ */

/* Base select styling - Light mode */
select,
.control-select,
.icon-bar-select,
.stain-select {
    background-color: var(--surface-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

/* Light mode - all select options */
select option,
.control-select option,
.icon-bar-select option,
.stain-select option {
    background: #ffffff;
    color: #333;
    padding: 8px 12px;
}

/* Dark mode - all select elements */
body.dark-mode select,
body.dark-mode .control-select,
body.dark-mode .icon-bar-select,
body.dark-mode .stain-select {
    background-color: #1e293b;
    color: #f1f5f9;
    border-color: #475569;
}

/* Dark mode - all select options */
body.dark-mode select option,
body.dark-mode .control-select option,
body.dark-mode .icon-bar-select option,
body.dark-mode .stain-select option {
    background: #1e293b;
    color: #f1f5f9;
}

/* Dark mode - select on focus */
body.dark-mode select:focus,
body.dark-mode .control-select:focus,
body.dark-mode .icon-bar-select:focus,
body.dark-mode .stain-select:focus {
    border-color: #3b82f6;
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

/* Dark mode - select hover */
body.dark-mode select:hover,
body.dark-mode .control-select:hover,
body.dark-mode .icon-bar-select:hover {
    border-color: #64748b;
}

/* ============================================================================
   HEADER
   ============================================================================ */

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: linear-gradient(135deg, var(--surface-color) 0%, #f8fafc 100%);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
    filter: invert(1); /* Invert white logo to black for light mode */
    transition: filter 0.3s ease;
}

/* In dark mode, keep original white logo */
body.dark-mode .header-logo {
    filter: none;
}

.header-titles {
    display: flex;
    flex-direction: column;
}

.header-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
}

.header-subtitle {
    font-size: 12px;
    color: #28a745;
    margin: 0;
}

.header-right {
    display: flex;
    align-items: center;
}

.theme-toggle {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: linear-gradient(145deg, #ffffff 0%, #f0f0f0 100%);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.25s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.theme-toggle:hover {
    background: linear-gradient(145deg, #f0f0f0 0%, #e5e5e5 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* ============================================================================
   MAIN LAYOUT - 5 COLUMN GRID
   ============================================================================ */

.main-layout {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: var(--footer-height);
    display: grid;
    /* 6 columns: MRI Nav | In vivo MRI | MRI Registered | Histology | Histology Nav | Tools */
    /* Tools panel at extreme right (narrower), giving more space to histology area */
    grid-template-columns: var(--sidebar-width) var(--mri-column-width) var(--mri-column-width) 1fr var(--sidebar-width) var(--tools-width);
    background: var(--bg-color);
    overflow: hidden;
}

/* ============================================================================
   SIDEBARS (MRI Nav & Histology Nav Panes)
   ============================================================================ */

.sidebar {
    background: linear-gradient(180deg, var(--surface-color) 0%, #f8f9fa 100%);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.04);
}

.sidebar.histology-nav-pane {
    border-right: none;
    border-left: 1px solid var(--border-color);
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.04);
    background: linear-gradient(180deg, var(--surface-color) 0%, #f8f9fa 100%);
}

.sidebar.tools-pane {
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.04), 2px 0 12px rgba(0, 0, 0, 0.04);
}

/* ============================================================================
   TOOLS PANE - Slightly scaled styling for narrower width (155px vs 170px)
   ============================================================================ */

.sidebar.tools-pane .sidebar-content {
    padding: 10px 10px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Tools pane - Section labels */
.sidebar.tools-pane .nav-section-label {
    font-size: 10px;
    padding: 6px 8px;
    margin-bottom: 8px;
}

/* Tools pane - Control groups */
.sidebar.tools-pane .control-group {
    margin-bottom: 10px;
}

/* Tools pane - Control labels */
.sidebar.tools-pane .control-label {
    font-size: 10px;
    margin-bottom: 4px;
}

/* Tools pane - Dropdowns/Selects */
.sidebar.tools-pane .control-select {
    padding: 6px 8px;
    font-size: 10px;
}

/* Tools pane - Slider container */
.sidebar.tools-pane .slider-container {
    gap: 5px;
}

.sidebar.tools-pane .slider {
    height: 4px;
}

.sidebar.tools-pane .slider::-webkit-slider-thumb {
    width: 11px;
    height: 11px;
}

.sidebar.tools-pane .slider::-moz-range-thumb {
    width: 11px;
    height: 11px;
}

.sidebar.tools-pane .slider-value {
    font-size: 10px;
    min-width: 28px;
}

/* Tools pane - Dividers */
.sidebar.tools-pane .sidebar-divider {
    margin: 10px 0;
}

/* Tools pane - Toggle buttons group */
.sidebar.tools-pane .toggle-buttons-group {
    gap: 5px;
}

/* Tools pane - Toggle buttons */
.sidebar.tools-pane .toggle-btn {
    padding: 7px 10px;
    font-size: 10px;
    gap: 7px;
    border-radius: 5px;
}

.sidebar.tools-pane .toggle-btn svg {
    width: 15px;
    height: 15px;
}

.sidebar-header.tools-header {
    background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
    color: #0369a1;
}

.sidebar-header {
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.sidebar-header.mri-header,
.sidebar-header.histology-header {
    background: linear-gradient(135deg, var(--mri-nav-header) 0%, #f9d5c5 100%);
    color: #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    font-size: 10px;
    letter-spacing: 0.8px;
}

.sidebar-content {
    flex: 1;
    padding: 10px 12px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Both sidebars - ensure no scrollbar with proper sizing */
.mri-nav-pane .sidebar-content,
.histology-nav-pane .sidebar-content {
    overflow-y: auto;
    scrollbar-width: thin;
    padding: 6px 8px;
}

/* Hide scrollbar but keep functionality */
.sidebar-content::-webkit-scrollbar {
    width: 4px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 2px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

.sidebar-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--border-color) 20%, var(--border-color) 80%, transparent 100%);
    margin: 8px 0;
}

/* Main center divider between top and bottom image controls */
.sidebar-divider.center-divider {
    height: 2px;
    margin: 8px 0;
    background: linear-gradient(90deg, #3b82f6 0%, #a855f7 100%);
    border-radius: 1px;
}

.nav-section-label {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    padding: 5px 8px;
    background: linear-gradient(135deg, rgba(33, 150, 243, 0.08) 0%, rgba(33, 150, 243, 0.02) 100%);
    border-left: 3px solid var(--primary-color);
    border-radius: 0 4px 4px 0;
}

/* Top image section label - blue accent */
.nav-section-label.top-panel {
    margin-top: 8px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.12) 0%, rgba(59, 130, 246, 0.03) 100%);
    border-left-color: #3b82f6;
    color: #1e40af;
}

/* Bottom image section label - purple accent */
.nav-section-label.bottom-panel {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.12) 0%, rgba(168, 85, 247, 0.03) 100%);
    border-left-color: #a855f7;
    color: #6b21a8;
}

/* ============================================================================
   FORM CONTROLS
   ============================================================================ */

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

.control-label {
    display: block;
    font-size: 10px;
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 5px;
}

.control-label-inline {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-color);
    margin-right: 8px;
}

.control-select {
    width: 100%;
    padding: 5px 8px;
    font-size: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background: linear-gradient(145deg, #ffffff 0%, #f8f9fa 100%);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.control-select:hover {
    border-color: rgba(0, 0, 0, 0.2);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.control-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.15);
}

.control-select-inline,
.control-select-small {
    padding: 4px 8px;
    font-size: 11px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    background: var(--surface-color);
}

/* Slider Styles */
.slider-container {
    display: flex;
    align-items: center;
    gap: 6px;
}

.slider {
    flex: 1;
    min-width: 0; /* Allow slider to shrink */
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--slider-track);
    border-radius: 2px;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 11px;
    height: 11px;
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.slider::-moz-range-thumb {
    width: 11px;
    height: 11px;
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.slider::-webkit-slider-thumb:hover,
.slider::-webkit-slider-thumb:active {
    transform: scale(1.15);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.slider::-moz-range-thumb:hover,
.slider::-moz-range-thumb:active {
    transform: scale(1.15);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.slider-value {
    font-size: 10px;
    color: var(--text-muted);
    min-width: 28px;
    flex-shrink: 0;
    text-align: right;
}

/* Toggle Buttons Group */
.toggle-buttons-group {
    display: flex;
    flex-direction: row;
    gap: 6px;
}

.toggle-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    width: 100%;
    padding: 5px 8px;
    font-size: 10px;
    font-weight: 500;
    color: var(--text-color);
    background: linear-gradient(145deg, #ffffff 0%, #f5f5f5 100%);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.toggle-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.toggle-btn svg {
    flex-shrink: 0;
}

.toggle-btn span {
    flex: 1;
    text-align: left;
}

/* Annotations button - Pink */
.toggle-btn.annotations {
    border-color: rgba(236, 72, 153, 0.3);
}
.toggle-btn.annotations:hover {
    background: #fdf2f8;
    border-color: #ec4899;
}
.toggle-btn.annotations.active {
    background: linear-gradient(145deg, #fce7f3 0%, #fbcfe8 100%);
    border-color: #ec4899;
    color: #be185d;
}

/* Heatmap button - Orange */
.toggle-btn.heatmap {
    border-color: rgba(245, 158, 11, 0.3);
}
.toggle-btn.heatmap:hover {
    background: #fffbeb;
    border-color: #f59e0b;
}
.toggle-btn.heatmap.active {
    background: linear-gradient(145deg, #fef3c7 0%, #fde68a 100%);
    border-color: #f59e0b;
    color: #b45309;
}

/* Mask button - Red */
.toggle-btn.mask {
    border-color: rgba(239, 68, 68, 0.3);
}
.toggle-btn.mask:hover {
    background: #fef2f2;
    border-color: #ef4444;
}
.toggle-btn.mask.active {
    background: linear-gradient(145deg, #fee2e2 0%, #fecaca 100%);
    border-color: #ef4444;
    color: #b91c1c;
}

/* Map View button - Blue (matches Measure button) */
.toggle-btn.map-view {
    border-color: rgba(59, 130, 246, 0.3);
}
.toggle-btn.map-view:hover {
    background: #eff6ff;
    border-color: #3b82f6;
}
.toggle-btn.map-view.active {
    background: linear-gradient(145deg, #dbeafe 0%, #bfdbfe 100%);
    border-color: #3b82f6;
    color: #1d4ed8;
}

/* Measure button - Blue */
.toggle-btn.measure {
    border-color: rgba(59, 130, 246, 0.3);
}
.toggle-btn.measure:hover {
    background: #eff6ff;
    border-color: #3b82f6;
}
.toggle-btn.measure.active {
    background: linear-gradient(145deg, #dbeafe 0%, #bfdbfe 100%);
    border-color: #3b82f6;
    color: #1d4ed8;
}

/* Clear button - Red */
.toggle-btn.clear {
    border-color: rgba(239, 68, 68, 0.3);
}
.toggle-btn.clear:hover {
    background: #fef2f2;
    border-color: #ef4444;
}

/* Thumbnails button - Gray */
.toggle-btn.thumbnails {
    border-color: rgba(107, 114, 128, 0.3);
}
.toggle-btn.thumbnails:hover {
    background: #f9fafb;
    border-color: #6b7280;
}

/* 3D Viewer button - Purple */
.toggle-btn.viewer3d {
    border-color: rgba(139, 92, 246, 0.3);
}
.toggle-btn.viewer3d:hover {
    background: #f5f3ff;
    border-color: #8b5cf6;
}

.slider-small {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--slider-track);
    border-radius: 2px;
}

.slider-small::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border-radius: 50%;
}

/* Coordinates Box */
.coordinates-box {
    background: linear-gradient(145deg, #f8f9fa 0%, #eef1f5 100%);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* Coordinate subsections with dividers */
.coord-subsection {
    padding: 4px 0;
}

.coord-subsection-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    margin-bottom: 4px;
}

.coord-divider {
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(0,0,0,0.1), transparent);
    margin: 8px 0;
}

.coord-subsection-highlight {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.08) 0%, rgba(239, 68, 68, 0.03) 100%);
    border-radius: 6px;
    padding: 8px 12px;
    border-left: 3px solid #EF4444;
}

.coord-row-highlight {
    font-size: 14px !important;
    padding: 4px 0 !important;
}

.coord-row-highlight span {
    color: #EF4444 !important;
    font-weight: 700 !important;
}

.coord-row-secondary {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    padding: 2px 0;
}

.coord-row-secondary span:first-child {
    color: #aaa;
}

/* Mapping Mode Selector Styles */
.mapping-mode-controls {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 4px;
}

.mapping-mode-controls select {
    flex: 1;
    font-size: 0.85em;
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.2);
    color: inherit;
    cursor: pointer;
}

.mapping-mode-controls select:hover {
    border-color: rgba(255,255,255,0.2);
}

.mapping-mode-controls select:focus {
    outline: none;
    border-color: #3B82F6;
}

#mappingModeIndicator {
    font-size: 0.75em;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
    white-space: nowrap;
}

.mapping-mode-stats {
    font-size: 0.7em;
    color: #666;
    margin-top: 4px;
}

.coord-row {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    padding: 2px 0;
}

.coord-row span:first-child {
    font-weight: 600;
}



/* Axis Legend Box */
.axis-legend-box {
    background: linear-gradient(145deg, #f8f9fa 0%, #e9ecef 100%);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 8px;
}

.axis-legend-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
}

.axis-color-box {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

.axis-label {
    font-size: 9px;
    color: #555;
}

.axis-label.axis-slice {
    color: #EF4444;
    font-weight: 600;
}

.axis-legend-note {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 10px;
    color: #888;
}

/* Checkbox Group */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

.checkbox-label input[type="checkbox"] {
    width: 12px;
    height: 12px;
}

.checkbox-label.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.checkbox-label.disabled input[type="checkbox"] {
    cursor: not-allowed;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-color);
    background: var(--surface-color);
    border: 1.5px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn svg {
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.action-btn span {
    flex: 1;
}

.action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Annotations Button - Pink (#ec4899) */
.action-btn-annotations {
    border-left: 3px solid #ec4899;
}

.action-btn-annotations svg {
    stroke: #ec4899;
}

.action-btn-annotations:hover {
    background: #fdf2f8;
    border-color: #ec4899;
}

.action-btn-annotations.active {
    background: #fce7f3;
    border-color: #ec4899;
    color: #be185d;
}

.action-btn-annotations.active svg {
    stroke: #be185d;
}

/* Heatmap Button - Amber (#f59e0b) */
.action-btn-heatmap {
    border-left: 3px solid #f59e0b;
}

.action-btn-heatmap svg {
    stroke: #f59e0b;
}

.action-btn-heatmap:hover {
    background: #fffbeb;
    border-color: #f59e0b;
}

.action-btn-heatmap.active {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #b45309;
}

.action-btn-heatmap.active svg {
    stroke: #b45309;
}

/* Measure Button - Blue (#3b82f6) */
.action-btn-measure {
    border-left: 3px solid #3b82f6;
}

.action-btn-measure svg {
    stroke: #3b82f6;
}

.action-btn-measure:hover {
    background: #eff6ff;
    border-color: #3b82f6;
}

.action-btn-measure.active {
    background: #dbeafe;
    border-color: #3b82f6;
    color: #1d4ed8;
}

.action-btn-measure.active svg {
    stroke: #1d4ed8;
}

/* Clear Button - Red (#ef4444) */
.action-btn-clear {
    border-left: 3px solid #ef4444;
}

.action-btn-clear svg {
    stroke: #ef4444;
}

.action-btn-clear:hover {
    background: #fef2f2;
    border-color: #ef4444;
}

.action-btn-clear:active {
    background: #fee2e2;
    transform: scale(0.98);
}

/* Thumbnails Button - Gray (#6b7280) */
.action-btn-thumbnails {
    border-left: 3px solid #6b7280;
}

.action-btn-thumbnails svg {
    stroke: #6b7280;
}

.action-btn-thumbnails:hover {
    background: #f9fafb;
    border-color: #6b7280;
}

/* 3D Viewer Button - Special gradient styling */
.action-btn-3d {
    border-left: 3px solid #8b5cf6;
    background: linear-gradient(135deg, #fafafa 0%, #f5f3ff 100%);
}

.action-btn-3d svg {
    stroke: #8b5cf6;
}

.action-btn-3d:hover {
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
    border-color: #8b5cf6;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
}

.action-btn-3d:active {
    transform: scale(0.98);
}

.btn-icon {
    font-size: 16px;
}

/* ============================================================================
   MRI COLUMNS (In vivo MRI & MRI Registered to Histology)
   ============================================================================ */

.mri-column {
    background: linear-gradient(180deg, #f0f7ff 0%, var(--surface-color) 100%);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.05);
}

.column-header {
    padding: 10px 15px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    letter-spacing: 0.3px;
}

.column-header.mri-blue-header {
    background: linear-gradient(135deg, var(--mri-blue-header) 0%, #c5ddf5 100%);
    color: #1e3a5f;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.8px;
}

.header-italic {
    font-style: italic;
}

.mri-views-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
    overflow-y: auto;
}

/* MRI View Card */
.mri-view-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06), 0 2px 6px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.mri-view-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.06);
}

.mri-view-image {
    flex: 1;
    position: relative;
    background: var(--mri-bg);
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 8px 8px 0 0;
    overflow: hidden;
    /* Make MRI images approximately square */
    aspect-ratio: 1 / 1;
    max-width: 100%;
    /* Ensure minimum dimensions for VTK.js WebGL context initialization */
    min-height: 50px;
    min-width: 50px;
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.15);
}

.mri-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--mri-bg);
}

.mri-error-text {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    padding: 10px;
}

/* MRI Loading Spinner */
.mri-loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: mri-spin 0.8s linear infinite;
    margin-bottom: 8px;
}

@keyframes mri-spin {
    to { transform: rotate(360deg); }
}

.mri-loading-text {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.7);
    text-align: center;
}

/* VTK.js Canvas Styling */
.mri-view-image canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

/* VTK.js Render Window Container */
.mri-view-image .vtk-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* MRI Slider Bar */
.mri-slider-bar {
    position: relative;
    background: var(--slider-bar-bg);
    padding: 5px 12px;
    border-radius: 0 0 4px 4px;
    display: flex;
    align-items: center;
}

/* Floating value badge - hidden until hover/drag, follows the thumb
   (JS in BrainStateIntegration.js sets tooltip.style.left to track the thumb) */
.mri-slider-tooltip {
    position: absolute;
    bottom: 100%;
    margin-bottom: 4px;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    padding: 3px 6px;
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    white-space: nowrap;
    z-index: 20;
}

.mri-slider-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: #1e293b;
}

.mri-slider-tooltip.visible {
    opacity: 1;
}

body.dark-mode .mri-slider-tooltip {
    background: #f1f5f9;
    color: #0f172a;
}

body.dark-mode .mri-slider-tooltip::after {
    border-top-color: #f1f5f9;
}

.mri-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: #cbd5e1;
    border-radius: 2px;
    cursor: pointer;
}

.mri-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    background: #64748b;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.mri-slider::-moz-range-thumb {
    width: 13px;
    height: 13px;
    background: #64748b;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.mri-slider::-webkit-slider-thumb:hover,
.mri-slider::-webkit-slider-thumb:active {
    transform: scale(1.15);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.mri-slider::-moz-range-thumb:hover,
.mri-slider::-moz-range-thumb:active {
    transform: scale(1.15);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* ================================================================
   Histology Crosshair (OpenLayers overlay, positioned at map coordinate)
   Uses ::before/::after pseudo-elements for full-spanning crossing lines.
   Plane-based colors: horizontal=BLUE (Axial/Y), vertical=GREEN (Coronal/X)
   ================================================================ */
.crosshair {
    position: relative;
    width: 0;
    height: 0;
    pointer-events: none;
    z-index: 10;
}

.crosshair::before {
    /* Horizontal line - BLUE (Axial plane intersection, Y position) */
    content: '';
    position: absolute;
    top: 0;
    left: -5000px;
    width: 10000px;
    height: 2px;
    background-color: #3B82F6;
    opacity: 0.85;
    transform: translateY(-1px);
}

.crosshair::after {
    /* Vertical line - GREEN (Coronal plane intersection, X position) */
    content: '';
    position: absolute;
    left: 0;
    top: -5000px;
    width: 2px;
    height: 10000px;
    background-color: #22C55E;
    opacity: 0.85;
    transform: translateX(-1px);
}

/* Image boundary indicator - shows actual MRI image area vs black padding */
.image-boundary {
    position: absolute;
    border: 1px solid rgba(255, 255, 255, 0.35);
    pointer-events: none;
    z-index: 5;
    box-sizing: border-box;
    border-radius: 1px;
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.1);
}

/* MRI Crosshair Overlay - Synchronized across views like QuadView */
.crosshair-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 10;
}

/*
 * PLANE-BASED CROSSHAIR COLORS (PERMANENT DOMAIN-VALIDATED CONVENTION)
 * ============================================================================
 * Colors represent SLICING PLANES, not just axes:
 *   RED   = Sagittal Plane (XY plane, normal along Z) - CONTROLS SECTIONS
 *   GREEN = Coronal Plane  (YZ plane, normal along X)
 *   BLUE  = Axial Plane    (XZ plane, normal along Y)
 *
 * Summary Mapping:
 *   - X axis (GREEN) → Coronal (A-P)
 *   - Y axis (BLUE)  → Axial (S-I)
 *   - Z axis (RED)   → Sagittal (L-R) — CONTROLS SECTIONS
 *
 * Crosshair lines show INTERSECTIONS of planes with the current view:
 * The horizontal line = plane that intersects horizontally
 * The vertical line = plane that intersects vertically
 */

/* AXIAL view (XZ plane, normal Y, BLUE plane produces this)
   - Horizontal crosshair = Coronal plane intersection (X position) = GREEN
   - Vertical crosshair = Sagittal plane intersection (Z position) = RED */
.crosshair-h {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1px;
    background-color: #22C55E; /* GREEN - Coronal plane intersection */
    transform: translateY(-50%);
    transition: top 0.03s linear;
    opacity: 0.9;
    pointer-events: auto;
    cursor: ns-resize;
}

/* Invisible hit area for horizontal line - makes it easier to grab */
.crosshair-h::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 16px;
    transform: translateY(-50%);
    background: transparent;
    cursor: ns-resize;
}

.crosshair-v {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    background-color: #EF4444;; /* RED - Sagittal plane intersection (CONTROLS SECTIONS) */
    transform: translateX(-50%);
    transition: left 0.03s linear;
    opacity: 0.9;
    pointer-events: auto;
    cursor: ew-resize;
}

/* Invisible hit area for vertical line - makes it easier to grab */
.crosshair-v::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 16px;
    transform: translateX(-50%);
    background: transparent;
    cursor: ew-resize;
}

/* CORONAL view (YZ plane, normal X, GREEN plane produces this)
   - Horizontal crosshair = Axial plane intersection (Y position) = BLUE
   - Vertical crosshair = Sagittal plane intersection (Z position) = RED */
#mriInVivoCoronal .crosshair-h,
#mriRegCoronal .crosshair-h,
#mriRawCoronal .crosshair-h {
    background-color: #3B82F6; /* BLUE - Axial plane intersection */
}
/* Vertical stays RED (sagittal) - default is already correct */

/* SAGITTAL view (XY plane, normal Z, RED plane produces this)
   - Horizontal crosshair = Axial plane intersection (Y position) = BLUE
   - Vertical crosshair = Coronal plane intersection (X position) = GREEN */
#mriInVivoSagittal .crosshair-h,
#mriRegSagittal .crosshair-h,
#mriRawSagittal .crosshair-h {
    background-color: #3B82F6; /* BLUE - Axial plane intersection */
}

#mriInVivoSagittal .crosshair-v,
#mriRegSagittal .crosshair-v,
#mriRawSagittal .crosshair-v {
    background-color: #22C55E; /* GREEN - Coronal plane intersection */
}

/* Crosshair Center - The draggable intersection point
   =====================================================
   This is the point where the two crosshair lines intersect.
   It can be clicked and dragged to reposition the cursor in real-time.
   Minimalist design: small circle that expands on hover.
*/
.crosshair-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 11px;
    height: 11px;
    transition: top 0.03s linear, left 0.03s linear, transform 0.1s ease, background 0.1s ease;
    border-radius: 50%;
    /* Semi-transparent with subtle border */
    background: rgba(255, 255, 255, 0.55);
    border: 1.5px solid rgba(255, 215, 0, 0.85);
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
    /* Enable pointer events on center for drag detection */
    pointer-events: auto;
    /* Use 'move' cursor (four-way arrow) like QuadView */
    cursor: move;
    z-index: 10;
}

/* Inner dot - smaller and subtler */
.crosshair-center::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 3px;
    height: 3px;
    background: rgba(255, 215, 0, 0.8);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.15s ease, height 0.15s ease;
}

/* Remove the after pseudo-element */
.crosshair-center::after {
    display: none;
}

/* Direct hover on crosshair center - expand and highlight */
.crosshair-center:hover {
    transform: translate(-50%, -50%) scale(1.25);
    background: rgba(255, 215, 0, 0.85);
    border-color: rgba(255, 215, 0, 1);
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.6), 0 0 3px rgba(0, 0, 0, 0.4);
    cursor: move;
}

.crosshair-center:hover::before {
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.9);
}

/* Enhanced visual feedback when hovering near crosshair center
   This state is set by JavaScript when cursor is within grab distance */
.mri-view-image.crosshair-hover .crosshair-center {
    transform: translate(-50%, -50%) scale(1.25);
    background: rgba(255, 215, 0, 0.85);
    border-color: rgba(255, 215, 0, 1);
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.6), 0 0 3px rgba(0, 0, 0, 0.4);
}

/* Cursor style for hovering near crosshair - use 'move' cursor */
.mri-view-image.crosshair-hover {
    cursor: move !important;
}

/* When actively dragging - use 'move' cursor (four-way arrow) */
.mri-view-image.dragging .crosshair-center {
    background: rgba(255, 215, 0, 0.95);
    transform: translate(-50%, -50%) scale(1.3);
    border-color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.8), 0 0 4px rgba(0, 0, 0, 0.5);
    cursor: move;
}

/* CRITICAL: Disable transitions during dragging for instant response
   ===================================================================
   Transitions create visual lag between mouse movement and crosshair update.
   During active dragging, we need immediate/synchronous position updates. */
.mri-view-image.dragging .crosshair-h,
.mri-view-image.dragging .crosshair-v,
.mri-view-image.dragging .crosshair-center {
    transition: none !important;
}

/* GPU acceleration for crosshair elements to prevent visual artifacts
   ====================================================================
   Using will-change and transform3d triggers GPU compositing layer,
   which prevents white/black flashing during rapid updates. */
.crosshair-overlay {
    will-change: contents;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.crosshair-h,
.crosshair-v,
.crosshair-center {
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform-style: preserve-3d;
}

/* Ensure VTK canvas doesn't cause z-index conflicts during drag */
.mri-view-image.dragging canvas {
    pointer-events: none;
}

/* Prevent any selection or highlighting during drag which can cause visual glitches */
.mri-view-image.dragging {
    user-select: none;
    -webkit-user-select: none;
    cursor: move !important;
}

/* ============================================================================
   CONTRAST (WINDOW/LEVEL) DRAGGING
   ============================================================================
   Visual feedback when adjusting contrast via Shift+Drag or Right-Click+Drag.
   Shows crosshair cursor and subtle border highlight.
   ============================================================================ */

.mri-view-image.contrast-dragging {
    cursor: crosshair !important;
    user-select: none;
    -webkit-user-select: none;
}

.mri-view-image.contrast-dragging::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px solid rgba(255, 193, 7, 0.6);
    border-radius: 4px;
    pointer-events: none;
    z-index: 100;
    animation: contrast-pulse 1s ease-in-out infinite;
}

@keyframes contrast-pulse {
    0%, 100% { border-color: rgba(255, 193, 7, 0.4); }
    50% { border-color: rgba(255, 193, 7, 0.8); }
}

/* Ensure canvas doesn't interfere during contrast drag */
.mri-view-image.contrast-dragging canvas {
    pointer-events: none;
}

/* Hide crosshair lines during contrast adjustment for cleaner UI */
.mri-view-image.contrast-dragging .crosshair-h,
.mri-view-image.contrast-dragging .crosshair-v,
.mri-view-image.contrast-dragging .crosshair-center {
    opacity: 0.3;
}

/* Default cursor for MRI views - default cursor, grab only on crosshair center */
.mri-view-image {
    cursor: default;
}

/* MRI View Label - Shows view type (Axial, Coronal, Sagittal) */
.mri-view-label {
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    padding: 2px 6px;
    font-size: 9px;
    font-weight: 500;
    border-radius: 3px;
    z-index: 15;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Coordinate display in MRI views */
.mri-coord-display {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: #aaa;
    padding: 2px 6px;
    font-size: 8px;
    font-family: monospace;
    border-radius: 3px;
    z-index: 15;
}

/* ============================================================================
   HISTOLOGY COLUMN
   ============================================================================ */

.histology-column {
    /* NOTE: display: grid is set in the Adaptive Layout section (line ~3473) */
    /* Do NOT set display: flex here - it conflicts with the grid layout system */
    background: linear-gradient(180deg, #f5f5f8 0%, var(--surface-color) 100%);
    border-right: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.05);
}

/* Histology Panel */
.histology-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
    margin: 4px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.05);
    background: #1a1a2e;
    overflow: hidden;
}

/* Swap Stains Button — absolutely positioned at gap between panels */
.stain-swap-btn {
    position: absolute;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    background: rgba(20, 20, 40, 0.75);
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    /* Default: vertical layout — centered horizontally, at the gap between top and bottom */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.stain-swap-btn:hover {
    background: rgba(50, 50, 80, 0.95);
    color: rgba(255, 255, 255, 0.95);
    border-color: rgba(255, 255, 255, 0.35);
}

.stain-swap-btn:active {
    transform: translate(-50%, -50%) scale(0.88);
}

/* Show vertical arrows by default, hide horizontal */
.stain-swap-btn .swap-icon-vertical { display: block; }
.stain-swap-btn .swap-icon-horizontal { display: none; }

/* Horizontal layout: show horizontal arrows, position at vertical center gap */
.histology-column.layout-horizontal .stain-swap-btn {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.histology-column.layout-horizontal .stain-swap-btn:active {
    transform: translate(-50%, -50%) scale(0.88);
}
.histology-column.layout-horizontal .stain-swap-btn .swap-icon-vertical { display: none; }
.histology-column.layout-horizontal .stain-swap-btn .swap-icon-horizontal { display: block; }

/* Histology Panel Header - Transparent overlay on top of image */
.histology-panel-header {
    position: absolute;
    top: 6px;
    left: 6px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.5);
    gap: 4px;
    min-height: 24px;
    z-index: 70;
    pointer-events: none;
    border-radius: 4px;
}

.histology-panel-header > * {
    pointer-events: auto;
}

/* Header left group - stain badge and selector - smaller and subtle */
.header-left-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Info badges - Small, subtle badges */
.info-badge {
    padding: 2px 6px;
    font-size: 9px;
    font-weight: 600;
    color: #fff;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    cursor: pointer;
    opacity: 0.85;
    transition: opacity 0.2s ease;
}

.info-badge:hover {
    opacity: 1;
}

/* Brain ID badge - Blue */
.brain-id-badge {
    background: rgba(52, 152, 219, 0.8);
}

/* Section ID badge - Green */
.section-id-badge {
    background: rgba(39, 174, 96, 0.8);
}

/* Stain badge - shows current stain (Red) */
.stain-badge {
    padding: 2px 6px;
    font-size: 9px;
    font-weight: 600;
    color: #fff;
    background: rgba(231, 76, 60, 0.8);
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    cursor: help;
    opacity: 0.85;
    transition: opacity 0.2s ease;
}

.stain-badge:hover {
    opacity: 1;
}

/* Stain selector dropdown - small and subtle */
.stain-select {
    padding: 2px 4px;
    font-size: 9px;
    font-weight: 500;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    cursor: pointer;
    min-width: 50px;
    opacity: 0.85;
}

.stain-select:hover {
    opacity: 1;
}

.stain-select:focus {
    outline: none;
    border-color: var(--primary-color);
    opacity: 1;
}

/* Dark mode stain select - override for panel headers */
body.dark-mode .stain-select {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
}

body.dark-mode .stain-select:focus {
    border-color: rgba(52, 152, 219, 0.5);
}

/* Header right group - hidden, cursor coords moved to map-info-overlay */
.header-right-group {
    display: none;
}

/* Feature-overlay dropdown - button + popover, lives in the panel header */
.header-overlay-group {
    position: relative;
}

.overlay-dropdown-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 7px;
    font-size: 9px;
    font-weight: 600;
    color: #fff;
    background: rgba(99, 102, 241, 0.75);
    border: none;
    border-radius: 5px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    cursor: pointer;
    opacity: 0.85;
    transition: opacity 0.2s ease, background 0.2s ease, transform 0.12s ease;
}

.overlay-dropdown-btn:hover {
    opacity: 1;
}

.overlay-dropdown-btn:active {
    transform: scale(0.96);
}

.overlay-dropdown-btn.active {
    opacity: 1;
    background: rgba(99, 102, 241, 0.95);
}

.overlay-dropdown-count {
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 12px;
    height: 12px;
    padding: 0 3px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.9);
    color: #4338ca;
    font-size: 8px;
    font-weight: 700;
}

.overlay-dropdown-count.visible {
    display: inline-flex;
}

.overlay-dropdown-panel {
    display: none;
    /* position: fixed (not absolute) + JS-computed top/left in setupOverlayDropdown()
       so this escapes .histology-panel's overflow:hidden instead of being clipped. */
    position: fixed;
    width: 200px;
    max-height: 70vh;
    overflow-y: auto;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    padding: 8px;
    z-index: 10050;
    text-transform: none;
    cursor: default;
}

.overlay-dropdown-panel.open {
    display: block;
}

.overlay-dropdown-panel .control-label {
    display: block;
    margin-bottom: 4px;
    font-size: 9.5px;
    font-weight: 600;
    letter-spacing: 0.2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.overlay-dropdown-panel .control-group + .control-group {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-color);
}

body.dark-mode .overlay-dropdown-panel {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* Cursor coordinates display in header (hidden) */
.cursor-coords {
    display: none;
}

/* Dark mode panel header */
body.dark-mode .histology-panel-header {
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.6) 0%, transparent 100%);
}

/* Histology Map Wrapper - Takes full available space */
.histology-map-wrapper {
    flex: 1;
    position: relative;
    min-height: 0;
    background: #ffffff;
}

/* Histology Map Container - Full wrapper space */
.histology-map-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f8f9fa;
}

.histology-map {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    overflow: visible !important;
}

/* Ensure OpenLayers canvas layers are properly visible */
.histology-map canvas {
    z-index: 5;
}

/* OpenLayers overlay for measurements should be on top */
.histology-map .ol-overlay-container {
    z-index: 20;
}

/* Histology Crosshair - lower z-index to not cover measure lines */
/* Histology Crosshair - Hidden (not needed) */
.histology-crosshair {
    display: none;
}

/* Loading Overlay */
/* z-index: 50 ensures it's BELOW header controls (z-index: 70) */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    z-index: 50;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e0e0e0;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 10px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Image Not Available Overlay */
/* pointer-events: none allows clicks to pass through to header controls (stain dropdown, badges) */
.loading-overlay.image-error {
    background: rgba(245, 245, 245, 0.92);
    color: #dc2626;
    pointer-events: none;
}

.loading-overlay.image-error .loading-spinner {
    display: none;
}

.loading-overlay.image-error .error-icon {
    font-size: 36px;
    margin-bottom: 8px;
    opacity: 0.8;
}

.loading-overlay.image-error .error-message {
    font-size: 13px;
    font-weight: 600;
    color: #dc2626;
}

.loading-overlay.image-error .error-detail {
    font-size: 11px;
    color: rgba(0, 0, 0, 0.5);
    margin-top: 6px;
    max-width: 320px;
    text-align: center;
    line-height: 1.4;
}

/* Error Recovery Buttons (stain switch / section nav) */
.loading-overlay.image-error .error-recovery {
    margin-top: 12px;
    text-align: center;
}

.loading-overlay.image-error .error-recovery-label {
    font-size: 11px;
    color: rgba(0, 0, 0, 0.45);
    margin-bottom: 8px;
}

.loading-overlay.image-error .error-stain-buttons {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
}

.loading-overlay.image-error .error-stain-btn {
    background: rgba(0, 0, 0, 0.06);
    color: #333;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    padding: 5px 12px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.loading-overlay.image-error .error-stain-btn:hover {
    background: rgba(0, 0, 0, 0.12);
    border-color: rgba(0, 0, 0, 0.3);
}

.loading-overlay.image-error .error-nav-btn {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.3);
    color: #2563eb;
}

.loading-overlay.image-error .error-nav-btn:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.5);
}

/* Map Label - Positioned at top-center to avoid zoom controls on left */
.map-label {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 5px 14px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    z-index: 50;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Sidebar Overlay Legend - color dot + name per active overlay,
   shown in the Histology Navigation pane below the opacity sliders */
.overlay-legend-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 4px 2px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75em;
    color: var(--text-secondary, #666);
}

.legend-dot {
    flex: 0 0 auto;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.legend-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Thumbnail Preview (bottom-right of histology panel) */
.thumbnail-preview {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 80px;
    height: 60px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    z-index: 50;
}

.thumbnail-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Map Info Overlay - Top-right with cursor coords + zoom preview */
.map-info-overlay {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 140px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 60;
    pointer-events: none;
}

.map-info-overlay > * {
    pointer-events: auto;
}

/* Cursor Coordinates Display - Inside overlay */
.overlay-cursor-coords {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: auto;
    min-width: 100%;
    padding: 5px 10px;
    background: var(--surface-color);
    color: var(--text-color);
    font-size: 10px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    border-radius: 4px;
    text-align: center;
    border: 1px solid var(--border-color);
    white-space: nowrap;
    box-shadow: 0 2px 8px var(--shadow);
}

/* Dark mode overlay coords */
body.dark-mode .overlay-cursor-coords {
    background: rgba(30, 41, 59, 0.95);
    color: #f1f5f9;
    border-color: rgba(52, 152, 219, 0.4);
}

/* Cursor Preview / Zoom Preview - Inside overlay */
.cursor-preview {
    position: relative;
    width: 140px;
    height: 140px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    background: var(--surface-color);
    box-shadow: 0 4px 15px var(--shadow-dark);
    display: none;
}

/* Light mode cursor preview */
body:not(.dark-mode) .cursor-preview {
    background: #f8f9fa;
    border-color: #ccc;
}

/* Dark mode cursor preview */
body.dark-mode .cursor-preview {
    background: #1e293b;
    border-color: rgba(52, 152, 219, 0.5);
}

/* Let OpenLayers handle canvas sizing via updateSize() */
/* Don't override - the lazy init ensures proper dimensions */

/* Label for cursor preview */
.cursor-preview-label {
    font-size: 8px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    text-align: center;
}

/* Footer navigation controls - removed histology panel footer, nav is now in main footer */

.annotation-layer-control {
    display: flex;
    align-items: center;
    gap: 6px;
}

.mini-slider {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    color: var(--text-muted);
}

.scale-text {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-color);
}

.scale-indicator {
    font-size: 11px;
    color: var(--text-muted);
}

/* Navigation Buttons */
.nav-btn {
    padding: 8px 18px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-color);
    background: linear-gradient(145deg, #ffffff 0%, #f0f0f0 100%);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.nav-btn:hover {
    background: linear-gradient(145deg, #f0f0f0 0%, #e0e0e0 100%);
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.15);
    transform: translateY(-1px);
}

.nav-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.nav-separator {
    color: var(--text-muted);
    font-weight: 300;
}

.section-info {
    font-size: 11px;
    color: var(--text-muted);
}

/* ============================================================================
   ICON BAR (Quick Actions - Right of Histology)
   ============================================================================ */

.icon-bar {
    background: linear-gradient(180deg, var(--surface-color) 0%, #f8f9fa 100%);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.04), 2px 0 12px rgba(0, 0, 0, 0.04);
}

.icon-bar-item {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Comparison dropdown in icon bar */
.icon-bar-item.comparison-item {
    padding: 4px;
    gap: 4px;
}

.icon-bar-label {
    font-size: 8px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    text-align: center;
    margin-bottom: 2px;
}

.icon-bar-select {
    width: 100%;
    padding: 4px 4px;
    font-size: 9px;
    font-weight: 500;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--surface-color);
    color: var(--text-color);
    cursor: pointer;
}

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

/* Icon bar section label */
.icon-bar-section-label {
    font-size: 8px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    padding: 2px 0;
}

/* Icon bar slider */
.icon-bar-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--slider-track);
    border-radius: 2px;
    cursor: pointer;
}

.icon-bar-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

.icon-bar-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Icon bar divider */
.icon-bar-divider {
    width: 80%;
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

.icon-bar-btn {
    width: 44px;
    height: 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: linear-gradient(145deg, #ffffff 0%, #f5f5f5 100%);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.icon-bar-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    border-color: rgba(0, 0, 0, 0.15);
}

.icon-bar-btn svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.icon-bar-text {
    font-size: 7px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
    line-height: 1;
}

/* Icon bar button states */
.icon-bar-btn.active {
    background: #fce7f3;
    border-color: #ec4899;
}

.icon-bar-btn.active .icon-bar-text {
    color: #be185d;
}

/* Annotations button */
.icon-bar-btn[data-action="annotations"] svg {
    stroke: #ec4899;
}

.icon-bar-btn[data-action="annotations"].active {
    background: #fce7f3;
    border-color: #ec4899;
}

/* Heatmap button */
.icon-bar-btn[data-action="heatmap"] svg {
    stroke: #f59e0b;
}

.icon-bar-btn[data-action="heatmap"].active {
    background: #fef3c7;
    border-color: #f59e0b;
}

.icon-bar-btn[data-action="heatmap"].active .icon-bar-text {
    color: #b45309;
}

/* Measure button */
.icon-bar-btn[data-action="measure"] svg {
    stroke: #3b82f6;
}

.icon-bar-btn[data-action="measure"].active {
    background: #dbeafe;
    border-color: #3b82f6;
}

.icon-bar-btn[data-action="measure"].active .icon-bar-text {
    color: #1d4ed8;
}

/* Clear button */
.icon-bar-btn[data-action="clear"] svg {
    stroke: #ef4444;
}

.icon-bar-btn[data-action="clear"]:hover {
    background: #fef2f2;
    border-color: #ef4444;
}

/* Thumbnails button */
.icon-bar-btn[data-action="thumbnails"] svg {
    stroke: #6b7280;
}

/* 3D button */
.icon-bar-btn[data-action="3d"] {
    background: linear-gradient(135deg, #fafafa 0%, #f5f3ff 100%);
}

.icon-bar-btn[data-action="3d"] svg {
    stroke: #8b5cf6;
}

.icon-bar-btn[data-action="3d"]:hover {
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
    border-color: #8b5cf6;
}

/* Icon bar divider */
.icon-bar-divider {
    width: 70%;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, var(--border-color) 30%, var(--border-color) 70%, transparent 100%);
    margin: 6px 0;
    border-radius: 1px;
}

/* Dark mode icon bar */
body.dark-mode .icon-bar {
    background: linear-gradient(180deg, #1a2744 0%, var(--surface-color) 50%, #151d2e 100%);
    border-color: var(--border-color);
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.2), 2px 0 12px rgba(0, 0, 0, 0.2);
}

body.dark-mode .icon-bar-btn {
    background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
    border-color: var(--border-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

body.dark-mode .icon-bar-btn:hover {
    background: linear-gradient(145deg, #2d3a4f 0%, #1e293b 100%);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

body.dark-mode .icon-bar-btn[data-action="annotations"].active {
    background: rgba(236, 72, 153, 0.2);
}

body.dark-mode .icon-bar-btn[data-action="heatmap"].active {
    background: rgba(245, 158, 11, 0.2);
}

body.dark-mode .icon-bar-btn[data-action="measure"].active {
    background: rgba(59, 130, 246, 0.2);
}

body.dark-mode .icon-bar-btn[data-action="3d"] {
    background: linear-gradient(135deg, #1e293b 0%, #2e1065 100%);
}

/* ============================================================================
   FOOTER COORDINATE BAR
   ============================================================================ */

.footer-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--footer-height);
    background: linear-gradient(180deg, #f8fafc 0%, var(--surface-color) 100%);
    border-top: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: 1fr auto auto auto auto 1fr;
    align-items: center;
    gap: 20px;
    padding: 0 15px;
    z-index: 1000;
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.05);
}

.footer-nav-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-self: end;
}

.footer-nav-controls .nav-btn {
    padding: 4px 10px;
    font-size: 10px;
    font-weight: 500;
    border-radius: 4px;
    min-width: auto;
}

.footer-nav-controls .nav-separator {
    color: var(--text-muted);
    font-size: 10px;
    opacity: 0.5;
    margin: 0 2px;
}


.footer-search-group {
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
}

.footer-search-input {
    width: 90px;
    padding: 3px 8px;
    font-size: 10px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--surface-color);
    color: var(--text-color);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.footer-search-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.footer-search-input.not-found {
    border-color: #ef4444;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.footer-search-btn {
    padding: 4px 10px;
    font-size: 10px;
    font-weight: 500;
    border-radius: 4px;
    min-width: auto;
}

.footer-search-status {
    position: absolute;
    top: -18px;
    left: 0;
    font-size: 9px;
    font-weight: 600;
    white-space: nowrap;
    color: #ef4444;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.footer-search-status.visible {
    opacity: 1;
}

.coord-display {
    display: flex;
    align-items: center;
    gap: 5px;
}

.coord-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
}

.coord-value {
    font-size: 10px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    color: var(--text-color);
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 3px;
}

/* ============================================================================
   THUMBNAIL POPUP - Exact copy from old UI
   ============================================================================ */

.thumbnail-popup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    overflow: auto;
}

.thumbnail-popup-content {
    background-color: var(--surface-color);
    margin: auto;
    padding: 1.2rem 1.5rem;
    width: 70vw;
    max-width: 1000px;
    height: auto;
    max-height: 92vh;
    border-radius: 0.5rem;
    position: relative;
    overflow: hidden;
    transition: background-color 0.3s ease;
    box-shadow: 0 4px 20px var(--shadow-dark);
    display: flex;
    flex-direction: column;
}

.thumbnail-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.75rem;
    transition: border-color 0.3s ease;
}

.thumbnail-popup-header h2 {
    margin: 0;
    color: var(--text-color);
    font-size: 1.4rem;
    font-weight: 500;
    transition: color 0.3s ease;
}

.thumbnail-close-btn {
    background: none;
    border: none;
    font-size: 2.25rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 1.875rem;
    height: 1.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease;
}

.thumbnail-close-btn:hover {
    color: var(--text-color);
}

.thumbnail-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2rem 1rem;
    padding: 5rem 1rem 0.5rem 1rem;
    justify-items: center;
    align-items: center;
    flex: 1;
    overflow: auto;
    margin-top: 0;
}

.section-thumbnail-group {
    position: relative;
    display: inline-block;
    cursor: pointer;
    transition: transform 0.3s ease;
    margin: min(0.5rem, 1vw);
    perspective: 1000px;
    overflow: visible;
}

.section-thumbnail-group:hover {
    transform: scale(1.05);
    z-index: 100;
}

.thumbnail-images-container {
    position: relative;
    width: min(10rem, 14vh); 
    min-height: min(8rem, 12vh);
    transform-style: preserve-3d;
    perspective: 1000px;
    transition: transform 0.4s ease;
    overflow: visible;
}

.thumbnail-img {
    position: absolute;
    width: min(5rem, 7vh);
    height: min(5rem, 7vh);
    object-fit: cover;
    border-radius: 0.375rem;
    background-color: #fff;
    transition: transform 0.4s ease-out, box-shadow 0.4s ease-out, filter 0.4s ease, opacity 0.4s ease;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

body.dark-mode .thumbnail-img {
    background-color: #fff;
    filter: brightness(0.9);
}

.thumbnail-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 3rem;
    height: 3rem;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 100;
    transition: background-color 0.3s ease;
}

.thumbnail-nav-btn:hover {
    background-color: rgba(0, 0, 0, 0.9);
}

body.dark-mode .thumbnail-nav-btn {
    background-color: rgba(255, 255, 255, 0.2);
    color: var(--text-color);
}

body.dark-mode .thumbnail-nav-btn:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.thumbnail-nav-left {
    left: 0.625rem;
}

.thumbnail-nav-right {
    right: 0.625rem;
}

.thumbnail-page-indicator {
    text-align: center;
    margin-top: 0.5rem;
    padding-bottom: 0.5rem;  
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: color 0.3s ease;
    flex-shrink: 0; 
}

.section-thumbnail-label {
    position: absolute;
    bottom: min(3rem, 4vh);
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    font-size: 0.9rem;
    color: white;
    font-weight: 700;
    background-color: rgba(0, 0, 0, 0.8);
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    z-index: 50;
    white-space: nowrap;
    transition: background-color 0.3s ease;
}

body.dark-mode .section-thumbnail-label {
    background-color: rgba(255, 255, 255, 0.9);
    color: #1a202c;
}

/* Hide stain label on individual thumbnails */
.thumbnail-stain-label {
    display: none;
}

.thumbnail-error {
    position: absolute;
    width: min(5rem, 7vh);
    height: min(5rem, 7vh);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f7fafc;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 0.375rem;
    box-shadow: 0 2px 8px var(--shadow);
    transition: transform 0.4s ease-out, box-shadow 0.4s ease-out, filter 0.4s ease, opacity 0.4s ease, background-color 0.3s ease, color 0.3s ease;
}

.thumbnail-skeleton {
    position: absolute;
    width: min(5rem, 7vh);
    height: min(5rem, 7vh);
    background: linear-gradient(90deg, var(--light-surface) 25%, var(--border-color) 50%, var(--light-surface) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 0.375rem;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* 3D Thumbnail Effects and Layout */
.thumbnail-img.ihc, .thumbnail-skeleton.ihc, .thumbnail-error.ihc {
    z-index: 30;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.1),
        0 8px 24px rgba(0, 0, 0, 0.25),
        0 2px 8px rgba(0, 0, 0, 0.15);
}

.thumbnail-img.left-1, .thumbnail-skeleton.left-1, .thumbnail-error.left-1 {
    z-index: 20;
    width: min(6rem, 10vh);
    height: min(6rem, 10vh);
    transform: translate(-50%, -50%) translateZ(20px) rotateY(20deg) translateX(min(-42px, -4.2vh));
    transform-origin: center;
    box-shadow:
        -4px 4px 16px rgba(0, 0, 0, 0.2),
        -2px 2px 8px rgba(0, 0, 0, 0.15);
    opacity: 0.8;
}

.thumbnail-img.right-1, .thumbnail-skeleton.right-1, .thumbnail-error.right-1 {
    z-index: 20;
    width: min(6rem, 10vh);
    height: min(6rem, 10vh);
    transform: translate(-50%, -50%) translateZ(20px) rotateY(-20deg) translateX(min(42px, 4.2vh));
    transform-origin: center;
    box-shadow:
        4px 4px 16px rgba(0, 0, 0, 0.2),
        2px 2px 8px rgba(0, 0, 0, 0.15);
    opacity: 0.8;
}

.thumbnail-img.back, .thumbnail-skeleton.back, .thumbnail-error.back {
    z-index: 10;
    width: min(5.3rem, 9vh);
    height: min(5.3rem, 9vh);
    transform: translate(-50%, -50%) translateZ(0px) translateY(min(-36px, -3.6vh)) scale(0.92);
    opacity: 0.8;
    box-shadow:
        0 2px 12px rgba(0, 0, 0, 0.15),
        0 1px 4px rgba(0, 0, 0, 0.1);
}

/* Hover Effects for 3D Thumbnails */
.section-thumbnail-group:hover .thumbnail-img.left-1,
.section-thumbnail-group:hover .thumbnail-skeleton.left-1,
.section-thumbnail-group:hover .thumbnail-error.left-1 {
    transform: translate(-50%, -50%) translateZ(20px) rotateY(25deg) translateX(min(-60px, -6vh));
    opacity: 1;
}

.section-thumbnail-group:hover .thumbnail-img.right-1,
.section-thumbnail-group:hover .thumbnail-skeleton.right-1,
.section-thumbnail-group:hover .thumbnail-error.right-1 {
    transform: translate(-50%, -50%) translateZ(20px) rotateY(-25deg) translateX(min(60px, 6vh));
    opacity: 1;
}

.section-thumbnail-group:hover .thumbnail-img.back,
.section-thumbnail-group:hover .thumbnail-skeleton.back,
.section-thumbnail-group:hover .thumbnail-error.back {
    transform: translate(-50%, -50%) translateZ(5px) translateY(min(-48px, -4.8vh)) scale(0.95);
    opacity: 1;
}

.section-thumbnail-group:hover .thumbnail-img.ihc,
.section-thumbnail-group:hover .thumbnail-skeleton.ihc,
.section-thumbnail-group:hover .thumbnail-error.ihc {
    transform: translate(-50%, -50%) translateZ(45px) scale(1.03);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.1),
        0 12px 32px rgba(0, 0, 0, 0.3),
        0 4px 12px rgba(0, 0, 0, 0.2);
}

/* ============================================================================
   OPENLAYERS OVERRIDES
   ============================================================================ */

.ol-viewport {
    border-radius: 0;
    overflow: visible !important;
}

/* OpenLayers Zoom Controls - Compact size to match UI */
.ol-zoom {
    position: absolute !important;
    top: 38px !important;
    left: 10px !important;
    background: transparent !important;
}

.ol-zoom button {
    background: rgba(0, 0, 0, 0.6) !important;
    color: rgba(255, 255, 255, 0.85) !important;
    border: none !important;
    width: 22px !important;
    height: 22px !important;
    font-size: 12px !important;
    line-height: 20px !important;
    border-radius: 3px !important;
    margin: 1px !important;
    cursor: pointer !important;
    padding: 0 !important;
}

.ol-zoom button:hover {
    background: rgba(0, 0, 0, 0.8) !important;
    color: #fff !important;
}

/* OpenLayers ScaleLine - Bottom-left, compact size */
.ol-scale-line {
    position: absolute !important;
    bottom: 10px !important;
    left: 10px !important;
    width: 100px !important;
    background: rgba(0, 0, 0, 0.7) !important;
    border-radius: 4px !important;
    padding: 4px 8px !important;
    text-align: center !important;
    border: 1px solid rgba(52, 152, 219, 0.4) !important;
    z-index: 55 !important;
}

.ol-scale-line-inner {
    color: #fff !important;
    font-size: 9px !important;
    border-color: rgba(255, 255, 255, 0.4) !important;
    display: block !important;
    text-align: center !important;
}

/* OpenLayers ScaleBar - Stepped scale with measurement labels */
.ol-scale-bar {
    position: absolute !important;
    bottom: 10px !important;
    left: 10px !important;
    background: transparent !important;
    z-index: 55 !important;
    /* Crisp text rendering */
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
    text-rendering: geometricPrecision !important;
}

.ol-scale-bar-inner {
    display: flex !important;
    align-items: flex-end !important;
}

/* Individual scale bar segments */
.ol-scale-singlebar {
    height: 8px !important;
    border: 1px solid rgba(0, 0, 0, 0.8) !important;
    box-sizing: border-box !important;
}

/* Step markers (vertical lines between segments) */
.ol-scale-step-marker {
    width: 1px !important;
    height: 12px !important;
    background-color: rgba(0, 0, 0, 0.8) !important;
}

/* Step text labels (0, 25mm, 50mm, 100mm) */
.ol-scale-step-text {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
    font-size: 10px !important;
    font-weight: 600 !important;
    color: rgba(0, 0, 0, 0.9) !important;
    white-space: nowrap !important;
    /* Crisp text rendering - prevents blur */
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
    text-rendering: geometricPrecision !important;
    /* Prevent subpixel positioning blur */
    transform: translateZ(0) !important;
    backface-visibility: hidden !important;
    /* Text shadow for better readability */
    text-shadow:
        0 0 3px rgba(255, 255, 255, 0.95),
        0 0 6px rgba(255, 255, 255, 0.9),
        0 1px 2px rgba(255, 255, 255, 0.8) !important;
}

/* Scale ratio text (1 : 1000) */
.ol-scale-text {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
    font-size: 10px !important;
    font-weight: 600 !important;
    color: rgba(0, 0, 0, 0.9) !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
    text-rendering: geometricPrecision !important;
    transform: translateZ(0) !important;
    text-shadow:
        0 0 3px rgba(255, 255, 255, 0.95),
        0 0 6px rgba(255, 255, 255, 0.9) !important;
}

/* Dark mode scale bar text */
body.dark-mode .ol-scale-step-text,
body.dark-mode .ol-scale-text {
    color: rgba(255, 255, 255, 0.95) !important;
    text-shadow:
        0 0 3px rgba(0, 0, 0, 0.8),
        0 0 6px rgba(0, 0, 0, 0.6),
        0 1px 2px rgba(0, 0, 0, 0.5) !important;
}

body.dark-mode .ol-scale-singlebar {
    border-color: rgba(255, 255, 255, 0.8) !important;
}

body.dark-mode .ol-scale-step-marker {
    background-color: rgba(255, 255, 255, 0.8) !important;
}

/* Overview Map - Left side, above scale bar */
.ol-overviewmap,
.ol-overviewmap.overviewmap-custom {
    position: absolute !important;
    left: 10px !important;
    right: auto !important;
    bottom: 45px !important;
    top: auto !important;
    background: transparent !important;
    border: none !important;
    z-index: 50 !important;
}

/* Overview map inner map container */
.ol-overviewmap-map {
    width: 120px !important;
    height: 120px !important;
    border: 1px solid rgba(52, 152, 219, 0.5) !important;
    border-radius: 4px !important;
    background: #000 !important;
    overflow: hidden !important;
}

/* Let OpenLayers handle canvas sizing */

/* Overview map box indicator (the red dotted box showing current view) */
.ol-overviewmap-box {
    border: 2px dotted red !important;
    background: rgba(255, 0, 0, 0.1) !important;
}

/* Overview map collapse/expand button - positioned at bottom-left of the overview map */
.ol-overviewmap button {
    position: absolute !important;
    bottom: 2px !important;
    left: 2px !important;
    top: auto !important;
    right: auto !important;
    transform: none !important;
    width: 18px !important;
    height: 18px !important;
    background: rgba(0, 0, 0, 0.6) !important;
    color: #fff !important;
    border: none !important;
    border-radius: 3px !important;
    font-size: 10px !important;
    line-height: 18px !important;
    cursor: pointer !important;
    z-index: 60 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
}

.ol-overviewmap button:hover {
    background: rgba(0, 0, 0, 0.85) !important;
}

/* When overview is collapsed - show only the button with same size */
.ol-overviewmap.ol-collapsed {
    width: auto !important;
    height: auto !important;
}

.ol-overviewmap.ol-collapsed .ol-overviewmap-map {
    display: none !important;
}

.ol-overviewmap.ol-collapsed button {
    position: relative !important;
    bottom: auto !important;
    left: auto !important;
    top: auto !important;
    right: auto !important;
    width: 18px !important;
    height: 18px !important;
    font-size: 10px !important;
    line-height: 18px !important;
}

/* ============================================================================
   TOOLTIPS & OVERLAYS
   ============================================================================ */

.measure-tooltip,
.heatmap-tooltip {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 100;
}

.measure-tip {
    background: rgba(0, 0, 0, 0.6);
    color: rgba(255, 255, 255, 0.9);
    padding: 2px 4px;
    border-radius: 2px;
    font-size: 10px;
    pointer-events: none;
    z-index: 100;
}

/* Crosshair for OpenLayers */
.crosshair {
    position: relative;
    width: 20px;
    height: 20px;
}

.crosshair::before,
.crosshair::after {
    content: '';
    position: absolute;
    background: #ef4444;
}

.crosshair::before {
    left: 50%;
    top: 0;
    width: 2px;
    height: 100%;
    transform: translateX(-50%);
}

.crosshair::after {
    top: 50%;
    left: 0;
    width: 100%;
    height: 2px;
    transform: translateY(-50%);
}

/* ============================================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================================ */

@media (max-width: 1600px) {
    :root {
        --sidebar-width: 190px;
        --tools-width: 145px;
        --mri-column-width: 200px;
        --icon-bar-width: 65px;
    }

    /* Tools pane scaling for 1600px */
    .sidebar.tools-pane .sidebar-content {
        padding: 8px 8px;
    }
    .sidebar.tools-pane .nav-section-label {
        font-size: 9px;
        padding: 5px 6px;
        margin-bottom: 6px;
    }
    .sidebar.tools-pane .control-label {
        font-size: 9px;
    }
    .sidebar.tools-pane .control-select {
        padding: 5px 6px;
        font-size: 9px;
    }
    .sidebar.tools-pane .toggle-btn {
        padding: 6px 8px;
        font-size: 9px;
        gap: 6px;
    }
    .sidebar.tools-pane .toggle-btn svg {
        width: 14px;
        height: 14px;
    }
}

@media (max-width: 1400px) {
    :root {
        --sidebar-width: 180px;
        --tools-width: 140px;
        --mri-column-width: 180px;
        --icon-bar-width: 60px;
    }

    .map-info-overlay {
        width: 120px;
    }

    .ol-scale-line {
        width: 90px !important;
    }

    .ol-overviewmap-map {
        width: 100px !important;
        height: 100px !important;
    }

    .cursor-preview {
        width: 120px;
        height: 120px;
    }

    .icon-bar-btn {
        width: 45px;
        height: 45px;
    }

    .icon-bar-text {
        font-size: 7px;
    }

    /* Tools pane scaling for 1400px */
    .sidebar.tools-pane .sidebar-content {
        padding: 7px 7px;
    }
    .sidebar.tools-pane .nav-section-label {
        font-size: 9px;
        padding: 5px 5px;
        margin-bottom: 5px;
    }
    .sidebar.tools-pane .control-group {
        margin-bottom: 8px;
    }
    .sidebar.tools-pane .control-label {
        font-size: 9px;
        margin-bottom: 3px;
    }
    .sidebar.tools-pane .control-select {
        padding: 5px 5px;
        font-size: 9px;
    }
    .sidebar.tools-pane .sidebar-divider {
        margin: 8px 0;
    }
    .sidebar.tools-pane .toggle-buttons-group {
        gap: 4px;
    }
    .sidebar.tools-pane .toggle-btn {
        padding: 5px 7px;
        font-size: 9px;
        gap: 5px;
        border-radius: 4px;
    }
    .sidebar.tools-pane .toggle-btn svg {
        width: 13px;
        height: 13px;
    }
    .sidebar.tools-pane .slider-value {
        font-size: 9px;
        min-width: 24px;
    }
}

@media (max-width: 1200px) {
    :root {
        --sidebar-width: 145px;
        --tools-width: 130px;
        --mri-column-width: 160px;
        --icon-bar-width: 55px;
    }

    .control-label {
        font-size: 11px;
    }

    .map-info-overlay {
        width: 100px;
    }

    .overlay-cursor-coords {
        font-size: 9px;
        padding: 3px 6px;
    }

    .ol-scale-line {
        width: 80px !important;
    }

    .ol-overviewmap-map {
        width: 90px !important;
        height: 90px !important;
    }

    .cursor-preview {
        width: 100px;
        height: 100px;
    }

    .control-select {
        padding: 6px 8px;
        font-size: 11px;
    }

    .icon-bar-btn {
        width: 40px;
        height: 40px;
    }

    .icon-bar-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Tools pane scaling for 1200px */
    .sidebar.tools-pane .sidebar-content {
        padding: 6px 6px;
    }
    .sidebar.tools-pane .nav-section-label {
        font-size: 8px;
        padding: 4px 5px;
        margin-bottom: 4px;
    }
    .sidebar.tools-pane .control-group {
        margin-bottom: 6px;
    }
    .sidebar.tools-pane .control-label {
        font-size: 8px;
        margin-bottom: 2px;
    }
    .sidebar.tools-pane .control-select {
        padding: 4px 4px;
        font-size: 8px;
    }
    .sidebar.tools-pane .sidebar-divider {
        margin: 6px 0;
    }
    .sidebar.tools-pane .toggle-buttons-group {
        gap: 3px;
    }
    .sidebar.tools-pane .toggle-btn {
        padding: 4px 6px;
        font-size: 8px;
        gap: 4px;
        border-radius: 4px;
    }
    .sidebar.tools-pane .toggle-btn svg {
        width: 12px;
        height: 12px;
    }
    .sidebar.tools-pane .slider-value {
        font-size: 8px;
        min-width: 22px;
    }
    .sidebar.tools-pane .slider {
        height: 4px;
    }
    .sidebar.tools-pane .slider::-webkit-slider-thumb {
        width: 10px;
        height: 10px;
    }
    .sidebar.tools-pane .slider::-moz-range-thumb {
        width: 10px;
        height: 10px;
    }
}

/* ============================================================================
   MOBILE HAMBURGER MENU BUTTON (Hidden on desktop)
   ============================================================================ */
.mobile-menu-btn {
    display: none; /* Hidden on desktop */
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-color, #fff);
    cursor: pointer;
    color: var(--text-color);
    transition: all 0.2s ease;
    margin-left: 8px;
    flex-shrink: 0;
}

.mobile-menu-btn:hover {
    background: #f0f0f0;
    border-color: var(--primary-color, #2196F3);
}

.mobile-menu-btn.active {
    background: linear-gradient(145deg, #e3f2fd 0%, #bbdefb 100%);
    border-color: var(--primary-color, #2196F3);
    color: var(--primary-color, #2196F3);
}

body.dark-mode .mobile-menu-btn {
    background: var(--surface-color, #1e293b);
    border-color: var(--border-color);
    color: var(--text-color);
}

body.dark-mode .mobile-menu-btn:hover {
    background: #2d3a4f;
    border-color: #3b82f6;
}

/* ============================================================================
   MOBILE NAVIGATION DRAWER
   ============================================================================ */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-nav-overlay.open {
    display: block;
    opacity: 1;
}

.mobile-nav-drawer {
    position: fixed;
    top: 0;
    right: -100%;
    width: min(44vw, 240px);
    height: 100vh;
    background: var(--surface-color, #fff);
    z-index: 2001;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.mobile-nav-drawer.open {
    right: 0;
}

.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 10px;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-color);
    flex-shrink: 0;
}

.mobile-nav-header h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
}

.mobile-nav-close {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-color);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.mobile-nav-close:hover {
    background: rgba(0, 0, 0, 0.08);
}

/* Tab bar for switching between MRI Nav / Histology Nav / Tools */
.mobile-nav-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    flex-shrink: 0;
    background: var(--surface-color);
}

.mobile-nav-tab {
    flex: 1;
    padding: 7px 4px;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
}

.mobile-nav-tab.active {
    color: var(--primary-color, #2196F3);
    border-bottom-color: var(--primary-color, #2196F3);
}

.mobile-nav-tab:hover {
    color: var(--text-color);
    background: rgba(0, 0, 0, 0.03);
}

/* Content area - scrollable, compact for narrow drawer */
.mobile-nav-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
}

/* Make sidebar content compact when inside mobile drawer */
.mobile-nav-content .sidebar-content {
    font-size: 11px;
}

.mobile-nav-content .sidebar-content .section-title,
.mobile-nav-content .sidebar-content h4 {
    font-size: 11px;
}

.mobile-nav-content .sidebar-content .slider-container,
.mobile-nav-content .sidebar-content .checkbox-group {
    gap: 4px;
}

.mobile-nav-content .sidebar-content label {
    font-size: 10px;
}

.mobile-nav-content .sidebar-content button,
.mobile-nav-content .sidebar-content .btn {
    font-size: 10px;
    padding: 4px 8px;
}

/* Dark mode for mobile drawer */
body.dark-mode .mobile-nav-drawer {
    background: var(--surface-color);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.4);
}

body.dark-mode .mobile-nav-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

body.dark-mode .mobile-nav-tab:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* ============================================================================
   MOBILE SCROLL INDICATOR
   A sleek semi-circular pill handle on the right edge (mobile only).
   Drag it vertically to scroll the page without conflicting with map touches.
   ============================================================================ */
.mobile-scroll-indicator {
    display: none; /* Hidden on desktop, shown via media query */
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1500; /* Below drawer (2001) but above content */
    user-select: none;
    -webkit-user-select: none;
    transition: opacity 0.3s ease, top 0.1s linear;
}

.mobile-scroll-indicator .scroll-pill {
    width: 18px;
    height: 48px;
    background: rgba(120, 120, 120, 0.35);
    border-radius: 10px 0 0 10px; /* Semi-circular on left, flat on right (edge) */
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: all 0.2s ease;
    box-shadow: -1px 0 4px rgba(0, 0, 0, 0.1);
    cursor: grab;
}

.mobile-scroll-indicator .scroll-pill:active,
.mobile-scroll-indicator .scroll-pill.dragging {
    width: 24px;
    height: 56px;
    background: rgba(100, 100, 100, 0.55);
    cursor: grabbing;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.2);
}

/* Dark mode */
body.dark-mode .mobile-scroll-indicator .scroll-pill {
    background: rgba(180, 180, 180, 0.25);
    color: rgba(255, 255, 255, 0.6);
}

body.dark-mode .mobile-scroll-indicator .scroll-pill:active,
body.dark-mode .mobile-scroll-indicator .scroll-pill.dragging {
    background: rgba(180, 180, 180, 0.45);
}

/* ============================================================================
   RESPONSIVE: TABLET & MOBILE (max-width: 992px)
   Stack everything vertically, all sections visible via scrolling.
   Sidebars go into hamburger menu drawer.
   ============================================================================ */
@media (max-width: 992px) {
    /* --- BODY: enable scrolling (but allow drawer to lock scroll via class) --- */
    html, body {
        overflow: auto;
        overflow-x: hidden;
        height: auto !important;
        min-height: 100vh;
    }

    /* When mobile drawer is open, prevent background scroll */
    body.mobile-drawer-open {
        overflow: hidden !important;
    }

    /* --- HAMBURGER MENU: show on mobile --- */
    .mobile-menu-btn {
        display: flex !important;
    }

    /* --- MAIN LAYOUT: vertical flow, scrollable --- */
    .main-layout {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        min-height: calc(100vh - var(--header-height));
        margin-top: var(--header-height);
        margin-bottom: 0 !important;
        padding-bottom: 36px; /* Space for fixed footer */
        overflow: visible !important;
        grid-template-columns: none !important;
    }

    /* --- SIDEBARS: hide from flow, available via hamburger drawer --- */
    .sidebar {
        display: none !important;
    }

    /* --- SIDEBAR TOGGLE BUTTONS: hide --- */
    .sidebar-toggle-btn {
        display: none !important;
    }

    /* --- MRI COLUMNS: full width, stacked --- */
    .mri-column {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-color);
        overflow: visible !important;
    }

    .mri-views-container {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px;
        padding: 8px;
        overflow: visible !important;
        flex: none !important;
    }

    .mri-view-image {
        aspect-ratio: 1 / 1;
        min-height: 100px;
    }

    /* --- HISTOLOGY: KEEP GRID but force vertical with EXPLICIT row heights --- */
    /* This is critical: 1fr rows collapse to 0 without a definite container height.
       Using explicit heights (45vh) ensures panels always have size. */
    .histology-column,
    .histology-column.layout-vertical,
    .histology-column.layout-horizontal {
        display: grid !important;
        grid-template-columns: 1fr !important;
        grid-template-rows: 45vh 45vh !important;
        gap: 4px !important;
        overflow: visible !important;
        height: auto !important;
        min-height: auto !important;
    }

    /* Panels fill their grid cells */
    .histology-panel {
        min-height: 0 !important;
        overflow: hidden !important;
    }

    /* Map wrapper fills panel */
    .histology-column .histology-map-wrapper {
        flex: 1;
        min-height: 0;
        position: relative;
    }

    /* Map container fills wrapper - use absolute so it takes full space */
    .histology-column .histology-map-container {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        min-height: 0 !important;
    }

    .histology-column .histology-map {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: auto !important;
        height: auto !important;
    }

    /* --- HEADER: compact --- */
    .header {
        padding: 0 12px;
    }

    .header-title {
        font-size: 14px;
    }

    .header-subtitle {
        font-size: 10px;
    }

    .header-logo {
        width: 32px;
        height: 32px;
    }

    /* Hide tools and tour buttons on mobile - accessible from hamburger menu */
    .header-btn.tools-btn,
    .header-btn.tour-btn {
        display: none !important;
    }

    /* --- FOOTER: fixed at bottom on mobile, no dead space --- */
    .footer-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        display: flex !important;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        padding: 4px 8px;
        height: auto;
        min-height: 28px;
        z-index: 1000;
    }

    .footer-bar .coord-display:first-child {
        display: none;
    }

    /* --- TOUCH HANDLING: allow page scroll over maps --- */
    /* Single finger scrolls the page. Two-finger pinch/pan works for map interaction. */
    .histology-map,
    .histology-map-container,
    .mri-view-image {
        touch-action: pan-y !important;
    }

    /* --- HISTOLOGY REF PANEL: smaller on tablet --- */
    .histology-ref-panel {
        bottom: 45px;
        right: 10px;
    }
    .ref-expand-icon-btn {
        width: 46px;
        height: 46px;
    }
    .ref-panel-expanded {
        width: 170px;
    }
    .ref-mri-view {
        height: 120px;
    }

    /* --- THUMBNAIL DOCK --- */
    .thumbnail-dock {
        max-width: calc(100% - 16px);
    }

    .dock-nav-btn.dock-nav-left {
        margin-right: 8px;
    }

    .dock-nav-btn.dock-nav-right {
        margin-left: 8px;
    }

    .dock-thumbnails {
        overflow: hidden;
        min-width: 0;
    }

    /* --- TOOLS DRAWER: responsive --- */
    .tools-drawer {
        max-width: min(280px, 80vw) !important;
        min-width: 0 !important;
    }

    /* --- MOBILE SCROLL INDICATOR --- */
    .mobile-scroll-indicator {
        display: flex !important;
    }
}

/* ============================================================================
   RESPONSIVE: SMALL TABLET / LARGE PHONE (max-width: 768px)
   ============================================================================ */
@media (max-width: 768px) {
    :root {
        --header-height: 50px;
        --footer-height: auto;
    }

    .header {
        height: 50px;
        padding: 0 10px;
    }

    .header-title {
        font-size: 12px;
    }

    .header-subtitle {
        font-size: 9px;
    }

    .header-logo {
        width: 28px;
        height: 28px;
    }

    .header-left {
        gap: 8px;
    }

    .main-layout {
        margin-top: 50px !important;
    }

    /* MRI views */
    .mri-views-container {
        grid-template-columns: 1fr 1fr 1fr !important;
        gap: 4px;
        padding: 4px;
    }

    .mri-view-image {
        min-height: 80px;
    }

    /* Histology panels: smaller on smaller screens */
    .histology-column,
    .histology-column.layout-vertical,
    .histology-column.layout-horizontal {
        grid-template-rows: 40vh 40vh !important;
    }

    /* MRI column header */
    .column-header {
        padding: 6px 8px;
        font-size: 11px;
    }

    /* Footer */
    .footer-bar {
        gap: 6px;
        padding: 4px 8px;
    }

    .coord-display {
        font-size: 9px;
    }

    .footer-nav-controls .nav-btn {
        padding: 3px 6px;
        font-size: 9px;
    }

    /* Histology panel header compact */
    .histology-panel-header {
        padding: 3px 6px;
        gap: 2px;
    }

    .info-badge {
        font-size: 8px;
        padding: 1px 4px;
    }

    .stain-select {
        font-size: 9px;
        min-width: 40px;
    }

    /* Tools drawer full width */
    .tools-drawer {
        max-width: 100% !important;
        min-width: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 50px !important;
        border-radius: 0 !important;
    }

    /* Map info overlay smaller */
    .map-info-overlay {
        width: 80px;
    }

    .cursor-preview {
        width: 80px;
        height: 80px;
    }

    /* Histology ref panel - smaller on small tablet */
    .histology-ref-panel {
        bottom: 40px;
        right: 8px;
    }
    .ref-expand-icon-btn {
        width: 42px;
        height: 42px;
    }
    .ref-expand-icon-btn svg {
        width: 18px;
        height: 18px;
    }
    .ref-panel-expanded {
        width: 150px;
    }
    .ref-mri-view {
        height: 100px;
    }

    /* Thumbnail popup responsive */
    .thumbnail-popup-content {
        width: 90vw;
        max-height: 85vh;
    }

    .thumbnail-container {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .thumbnail-nav-btn {
        width: 2rem;
        height: 2rem;
        font-size: 1rem;
    }

    /* Mobile drawer - less than half screen */
    .mobile-nav-drawer {
        width: min(44vw, 220px);
    }

    .mobile-menu-btn {
        width: 36px;
        height: 36px;
        margin-left: 6px;
    }

    .mobile-menu-btn svg {
        width: 20px;
        height: 20px;
    }
}

/* ============================================================================
   RESPONSIVE: PHONE (max-width: 480px)
   ============================================================================ */
@media (max-width: 480px) {
    :root {
        --header-height: 44px;
    }

    .header {
        height: 44px;
        padding: 0 8px;
    }

    .header-title {
        font-size: 11px;
    }

    .header-subtitle {
        display: none;
    }

    .header-logo {
        width: 24px;
        height: 24px;
    }

    .header-left {
        gap: 6px;
    }

    /* Tools button already hidden at 992px */

    .theme-toggle {
        width: 30px;
        height: 30px;
        font-size: 13px;
    }

    .mobile-menu-btn {
        width: 34px;
        height: 34px;
        margin-left: 6px;
    }

    .main-layout {
        margin-top: 44px !important;
    }

    /* MRI views: 1 column on phones */
    .mri-views-container {
        grid-template-columns: 1fr !important;
        gap: 4px;
        padding: 4px;
    }

    .mri-view-image {
        min-height: 200px;
        aspect-ratio: 1 / 1;
    }

    /* Histology: shorter panels for phone */
    .histology-column,
    .histology-column.layout-vertical,
    .histology-column.layout-horizontal {
        grid-template-rows: 35vh 35vh !important;
    }

    /* Footer minimal */
    .footer-bar {
        gap: 4px;
        padding: 3px 6px;
    }

    .coord-label {
        font-size: 8px;
    }

    .coord-value {
        font-size: 8px;
        padding: 1px 4px;
    }

    /* Direction indicators */
    .direction-indicator {
        font-size: 9px;
        width: 16px;
        height: 16px;
    }

    /* Thumbnail popup */
    .thumbnail-container {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.5rem;
        padding: 2vh 2vw 2vh;
    }

    .thumbnail-images-container {
        width: min(10rem, 40vw);
        min-height: min(8rem, 35vw);
    }

    /* Histology ref panel - smallest on phone */
    .ref-expand-icon-btn {
        width: 40px;
        height: 40px;
    }
    .ref-expand-icon-btn svg {
        width: 16px;
        height: 16px;
    }
    .ref-expand-icon-label {
        font-size: 8px;
    }
    .ref-panel-expanded {
        width: 130px;
    }
    .ref-mri-view {
        height: 80px;
    }
    .ref-view-btn {
        width: 26px;
        height: 20px;
        font-size: 10px;
        line-height: 20px;
    }

    /* Tools drawer */
    .tools-drawer {
        top: 44px !important;
    }

    /* Mobile drawer - compact on phone */
    .mobile-nav-drawer {
        width: min(48vw, 200px);
    }

    .mobile-nav-tab {
        font-size: 10px;
        padding: 8px 4px;
    }
}

/* ============================================================================
   HISTOLOGY 3D REFERENCE PANEL (replaces old coronal indicator)
   ============================================================================ */

/* Reference panel - Fixed position overlay, draggable like tools box */
.histology-ref-panel {
    position: fixed;
    bottom: calc(var(--footer-height, 32px) + 10px);
    right: 15px;
    z-index: 1200; /* Above sidebars and navigation panels */
    /* Only transition visual properties, NOT position (left/top/right/bottom) */
    transition: opacity 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}

/* Draggable state - optimized for smooth drag */
.histology-ref-panel.dragging {
    cursor: grabbing;
    user-select: none;
    transition: none !important;
    will-change: left, top;
    z-index: 9999 !important; /* Always on top when dragging */
}

/* --- COLLAPSED STATE: Big icon button to expand --- */
.ref-panel-collapsed {
    position: relative;
}

.ref-expand-icon-btn {
    width: 52px;
    height: 52px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 12px;
    background: linear-gradient(145deg, #ffffff 0%, #f1f5f9 100%);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0;
    color: #475569;
    transition: all 0.2s ease;
}

.ref-expand-icon-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 4px 10px rgba(0, 0, 0, 0.1);
    color: #1e293b;
    border-color: rgba(0, 0, 0, 0.2);
}

.ref-expand-icon-btn:active {
    transform: scale(1.02);
}

.ref-expand-icon-btn svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.ref-expand-icon-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.5px;
    line-height: 1;
    user-select: none;
}

body.dark-mode .ref-expand-icon-btn {
    background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
    border-color: rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.3);
}

body.dark-mode .ref-expand-icon-btn:hover {
    color: #e2e8f0;
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 4px 10px rgba(0, 0, 0, 0.4);
}

/* --- EXPANDED STATE: Header + single MRI view + A/C/S toggle --- */
.ref-panel-expanded {
    width: 190px;
    background: linear-gradient(145deg, #ffffff 0%, #f5f5f5 100%);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.ref-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    cursor: grab;
    user-select: none;
}

.ref-panel-header:active {
    cursor: grabbing;
}

.ref-panel-title {
    font-size: 9px;
    font-weight: 600;
    color: #334155;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ref-panel-title::before {
    content: '\22EE\22EE';
    font-size: 8px;
    color: #94a3b8;
    letter-spacing: 1px;
}

body.dark-mode .ref-panel-title {
    color: #cbd5e1;
}

/* Collapse button (shown in expanded state) */
.ref-collapse-btn {
    width: 22px;
    height: 22px;
    background: rgba(0, 0, 0, 0.08);
    border: none;
    border-radius: 4px;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s ease;
}

.ref-collapse-btn:hover {
    background: rgba(0, 0, 0, 0.15);
}

/* Single MRI view container (one visible at a time) */
.ref-panel-views {
    padding: 2px;
}

.ref-mri-view {
    width: 100%;
    height: 140px;
}

.ref-mri-view:not(.active) {
    display: none;
}

.ref-view-image {
    width: 100%;
    height: 100%;
    position: relative;
    background: var(--mri-bg);
    border-radius: 4px;
    overflow: hidden;
}

/* A/C view toggle buttons */
.ref-panel-view-toggle {
    display: flex;
    justify-content: center;
    gap: 3px;
    padding: 2px 3px 4px;
}

.ref-view-btn {
    width: 26px;
    height: 20px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.05);
    color: #64748b;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    line-height: 20px;
}

.ref-view-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #334155;
}

.ref-view-btn.active {
    background: #EF4444;
    color: white;
    border-color: #EF4444;
    box-shadow: 0 1px 4px rgba(239, 68, 68, 0.4);
}

body.dark-mode .ref-view-btn {
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.05);
    color: #94a3b8;
}

body.dark-mode .ref-view-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
}

body.dark-mode .ref-view-btn.active {
    background: #EF4444;
    color: white;
    border-color: #EF4444;
}

/* --- MRI PLACEHOLDER COLUMN (future pure in-vivo) --- */
.mri-placeholder-column .mri-placeholder-content {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.mri-placeholder-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: #94a3b8;
    text-align: center;
    padding: 20px;
}

.mri-placeholder-message p {
    margin: 0;
    font-size: 13px;
    font-weight: 500;
}

.mri-placeholder-message .placeholder-hint {
    font-size: 11px;
    opacity: 0.7;
    font-weight: 400;
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ============================================================================
   SCROLLBAR STYLING
   ============================================================================ */

.sidebar-content::-webkit-scrollbar,
.mri-views-container::-webkit-scrollbar,
.thumbnail-container::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track,
.mri-views-container::-webkit-scrollbar-track,
.thumbnail-container::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb,
.mri-views-container::-webkit-scrollbar-thumb,
.thumbnail-container::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover,
.mri-views-container::-webkit-scrollbar-thumb:hover,
.thumbnail-container::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* ============================================================================
   SIDEBAR TOGGLE SYSTEM
   ============================================================================

   This system provides collapsible sidebars with:
   - Smooth sliding animations
   - Toggle buttons that remain visible when sidebar is hidden
   - Responsive layout that adjusts when sidebars collapse

   Left Sidebar (MRI Nav): Slides from left
   Right Sidebar (Histology Nav): Slides from right
   Tools: Opens as a drawer from the right side
   ============================================================================ */

/* ----- HEADER TOOLS BUTTON ----- */
.header-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface-color, #ffffff);
    border: 1px solid var(--border-color, #ddd);
    border-radius: 8px;
    color: var(--text-color, #333);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-right: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.header-btn:hover {
    background: linear-gradient(145deg, #f8f9fa 0%, #e9ecef 100%);
    border-color: var(--primary-color, #2196F3);
    color: var(--primary-color, #2196F3);
    box-shadow: 0 2px 6px rgba(33, 150, 243, 0.2);
    transform: translateY(-1px);
}

.header-btn.active {
    background: linear-gradient(145deg, #e3f2fd 0%, #bbdefb 100%);
    border-color: var(--primary-color, #2196F3);
    color: var(--primary-color, #2196F3);
}

.header-btn.tools-btn svg {
    stroke: var(--primary-color, #2196F3);
    width: 18px;
    height: 18px;
}

.header-btn.tools-btn:hover svg {
    stroke: var(--primary-color, #1976D2);
}

/* Dark mode header button */
body.dark-mode .header-btn {
    background: var(--surface-color, #1e293b);
    border-color: var(--border-color, #334155);
    color: var(--text-color, #f1f5f9);
}

body.dark-mode .header-btn:hover {
    background: linear-gradient(145deg, #2d3a4f 0%, #1e293b 100%);
    border-color: #3b82f6;
    color: #3b82f6;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

body.dark-mode .header-btn.active {
    background: linear-gradient(145deg, #1e3a5f 0%, #1e293b 100%);
    border-color: #3b82f6;
    color: #60a5fa;
}

body.dark-mode .header-btn.tools-btn svg {
    stroke: #60a5fa;
}

/* ----- SIDEBAR TOGGLE BUTTONS ----- */
.sidebar-toggle-btn {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 150; /* Below tools panel (z-index 1100) but above main content */
    width: 24px;
    height: 48px;
    background: var(--panel-bg, #ffffff);
    border: 1px solid var(--border-color, #e5e7eb);
    color: var(--text-secondary, #6b7280);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.sidebar-toggle-btn:hover {
    background: var(--hover-bg, #f3f4f6);
    color: var(--accent-color, #3b82f6);
    border-color: var(--accent-color, #3b82f6);
}

/* Left toggle button positioning - follows MRI nav pane */
.sidebar-toggle-btn.left-toggle {
    left: var(--sidebar-width, 200px);
    border-radius: 0 6px 6px 0;
    border-left: none;
    transition: left 0.3s ease, background 0.2s ease;
}

/* Right toggle button positioning - follows Histology nav pane */
.sidebar-toggle-btn.right-toggle {
    right: var(--sidebar-width, 200px);
    border-radius: 6px 0 0 6px;
    border-right: none;
    transition: right 0.3s ease, background 0.2s ease;
}

/* Toggle icon visibility */
.sidebar-toggle-btn .toggle-icon {
    display: none;
}

.sidebar-toggle-btn .toggle-icon.close-icon {
    display: block;
}

/* When sidebar is collapsed, show open icon */
.sidebar-toggle-btn.collapsed .toggle-icon.close-icon {
    display: none;
}

.sidebar-toggle-btn.collapsed .toggle-icon.open-icon {
    display: block;
}

/* Collapsed state positioning */
.sidebar-toggle-btn.left-toggle.collapsed {
    left: 0;
}

.sidebar-toggle-btn.right-toggle.collapsed {
    right: 0;
}

/* ----- COLLAPSIBLE SIDEBARS ----- */
/* Left sidebar (MRI Nav) collapse */
.sidebar.mri-nav-pane {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    transform: translateX(0);
    will-change: transform, opacity;
}

.sidebar.mri-nav-pane.collapsed {
    transform: translateX(-100%);
    width: 0;
    min-width: 0;
    padding: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

/* Right sidebar (Histology Nav) collapse */
.sidebar.histology-nav-pane {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    transform: translateX(0);
    will-change: transform, opacity;
}

.sidebar.histology-nav-pane.collapsed {
    transform: translateX(100%);
    width: 0;
    min-width: 0;
    padding: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

/* ----- MAIN LAYOUT ADJUSTMENTS ----- */
/* Default: 5-column layout (tools moved to drawer) - only on desktop */
@media (min-width: 993px) {
    .main-layout {
        grid-template-columns: var(--sidebar-width, 170px) 240px 240px 1fr var(--sidebar-width, 170px) !important;
        /* No transition on grid - sidebar transform handles animation */
    }

    /* When left sidebar is collapsed */
    .main-layout.left-collapsed {
        grid-template-columns: 0 240px 240px 1fr var(--sidebar-width, 170px) !important;
    }

    /* When right sidebar is collapsed */
    .main-layout.right-collapsed {
        grid-template-columns: var(--sidebar-width, 170px) 240px 240px 1fr 0 !important;
    }

    /* When both sidebars are collapsed */
    .main-layout.left-collapsed.right-collapsed {
        grid-template-columns: 0 240px 240px 1fr 0 !important;
    }
}

/* ----- TOOLS PANE HIDDEN ----- */
.sidebar.tools-pane.tools-pane-hidden {
    display: none !important;
}

/* ----- TOOLS DRAWER (Slides from Right) ----- */
/* ==========================================================
   TOOLS PANEL - Compact Floating Box Design
   No overlay fade, positioned above histology sidebar
   Draggable, non-intrusive, grid layout for tools
   ========================================================== */

/* Overlay - DISABLED to prevent blocking map interactions */
/* Tools panel floats independently, click-outside closes via document listener */
.tools-drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: -1; /* Behind everything */
    opacity: 0;
    visibility: hidden;
    pointer-events: none; /* ALWAYS disabled - never block interactions */
}

.tools-drawer-overlay.open {
    opacity: 0;
    visibility: hidden;
    pointer-events: none; /* Keep disabled even when "open" */
}

/* Tools Panel - Compact Floating Box */
.tools-drawer {
    position: fixed;
    /* Position: right side, above histology nav pane */
    top: 80px;
    right: 20px;
    width: auto;
    max-width: 280px;
    min-width: 200px;
    height: auto;
    max-height: calc(100vh - 120px);
    background: var(--surface-color, #ffffff);
    border-radius: 12px;
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.15),
        0 2px 8px rgba(0, 0, 0, 0.1),
        0 0 0 1px rgba(0, 0, 0, 0.05);
    z-index: 1100;
    /* Initially hidden */
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95) translateY(-10px);
    transform-origin: top right;
    transition:
        opacity 0.2s ease,
        visibility 0.2s ease,
        transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tools-drawer.open {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
}

/* Draggable state */
.tools-drawer.dragging {
    cursor: grabbing;
    user-select: none;
    transition: none;
}

/* Tools Panel Header - Compact, draggable handle */
.tools-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 1px solid var(--border-color);
    cursor: grab;
    user-select: none;
}

.tools-drawer-header:active {
    cursor: grabbing;
}

.tools-drawer-header h3 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Drag indicator dots */
.tools-drawer-header h3::before {
    content: '⋮⋮';
    font-size: 10px;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

.tools-drawer-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    width: 24px;
    height: 24px;
}

.tools-drawer-close:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.tools-drawer-close svg {
    width: 14px;
    height: 14px;
}

/* Tools Panel Content - Grid Layout */
.tools-drawer-content {
    padding: 12px;
    overflow-y: auto;
    max-height: 400px;
}

/* Section labels in floating panel */
.tools-drawer-content .nav-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}

.tools-drawer-content .control-group {
    margin-bottom: 12px;
}

.tools-drawer-content .sidebar-divider {
    margin: 10px 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

/* Tool Buttons Grid - 2 columns */
.tools-drawer-content .toggle-buttons-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

/* Compact tool buttons */
.tools-drawer-content .toggle-btn {
    padding: 8px 10px;
    font-size: 10px;
    gap: 6px;
    min-width: unset;
    flex: unset;
}

.tools-drawer-content .toggle-btn svg {
    width: 14px;
    height: 14px;
}

.tools-drawer-content .toggle-btn span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ----- DARK MODE ADJUSTMENTS ----- */
body.dark-mode .sidebar-toggle-btn {
    background: var(--panel-bg);
    border-color: var(--border-color);
}

body.dark-mode .tools-drawer {
    background: var(--surface-color, #1a1f2e);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.4),
        0 2px 8px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(255, 255, 255, 0.05);
}

body.dark-mode .tools-drawer-header {
    background: linear-gradient(135deg, #1e293b 0%, #1a1f2e 100%);
}

body.dark-mode .tools-drawer-overlay {
    background: transparent; /* NO FADE in dark mode either */
}

/* Dark mode - Toggle buttons in tools */
body.dark-mode .toggle-btn {
    background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
    color: #e2e8f0;
    border-color: #334155;
}

body.dark-mode .toggle-btn:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

body.dark-mode .toggle-btn.annotations {
    border-color: rgba(236, 72, 153, 0.4);
}
body.dark-mode .toggle-btn.annotations:hover {
    background: rgba(236, 72, 153, 0.15);
    border-color: #ec4899;
    color: #f9a8d4;
}
body.dark-mode .toggle-btn.annotations.active {
    background: rgba(236, 72, 153, 0.2);
    border-color: #ec4899;
    color: #f9a8d4;
}

body.dark-mode .toggle-btn.heatmap {
    border-color: rgba(245, 158, 11, 0.4);
}
body.dark-mode .toggle-btn.heatmap:hover {
    background: rgba(245, 158, 11, 0.15);
    border-color: #f59e0b;
    color: #fcd34d;
}
body.dark-mode .toggle-btn.heatmap.active {
    background: rgba(245, 158, 11, 0.2);
    border-color: #f59e0b;
    color: #fcd34d;
}

body.dark-mode .toggle-btn.mask {
    border-color: rgba(239, 68, 68, 0.4);
}
body.dark-mode .toggle-btn.mask:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
    color: #fca5a5;
}
body.dark-mode .toggle-btn.mask.active {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
    color: #fca5a5;
}

body.dark-mode .toggle-btn.measure {
    border-color: rgba(59, 130, 246, 0.4);
}
body.dark-mode .toggle-btn.measure:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: #3b82f6;
    color: #93c5fd;
}
body.dark-mode .toggle-btn.measure.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: #3b82f6;
    color: #93c5fd;
}

body.dark-mode .toggle-btn.map-view {
    border-color: rgba(59, 130, 246, 0.4);
}
body.dark-mode .toggle-btn.map-view:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: #3b82f6;
    color: #93c5fd;
}
body.dark-mode .toggle-btn.map-view.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: #3b82f6;
    color: #93c5fd;
}

body.dark-mode .toggle-btn.clear {
    border-color: rgba(239, 68, 68, 0.4);
}
body.dark-mode .toggle-btn.clear:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
    color: #fca5a5;
}

body.dark-mode .toggle-btn.thumbnails {
    border-color: rgba(148, 163, 184, 0.4);
}
body.dark-mode .toggle-btn.thumbnails:hover {
    background: rgba(148, 163, 184, 0.15);
    border-color: #94a3b8;
    color: #cbd5e1;
}

body.dark-mode .toggle-btn.viewer3d {
    border-color: rgba(139, 92, 246, 0.4);
}
body.dark-mode .toggle-btn.viewer3d:hover {
    background: rgba(139, 92, 246, 0.15);
    border-color: #8b5cf6;
    color: #c4b5fd;
}

/* ----- RESPONSIVE ADJUSTMENTS ----- */
@media (max-width: 1400px) {
    .tools-drawer {
        max-width: 260px;
        right: 15px;
    }
}

@media (max-width: 1200px) {
    /* Keep toggle buttons visible even when sidebars are hidden by media query */
    .sidebar-toggle-btn.left-toggle {
        left: 0;
    }

    .sidebar-toggle-btn.right-toggle {
        right: 0;
    }
}

/* ============================================================================
   ADAPTIVE HISTOLOGY COMPARISON LAYOUT
   ============================================================================

   This system provides automatic layout switching for histology comparison panels:
   - VERTICAL layout: Panels stacked on top of each other (default)
   - HORIZONTAL layout: Panels side by side

   The layout changes automatically based on:
   1. Available viewport width vs height ratio
   2. Whether sidebars are collapsed or expanded
   3. Which layout provides more usable viewing area

   DECISION LOGIC:
   - Calculate available space for histology column
   - If horizontal layout gives > 20% more area per panel → use horizontal
   - If vertical layout gives > 20% more area per panel → use vertical
   - If similar (within 20%), prefer vertical for consistency

   JavaScript in app.js handles the calculation and applies layout classes.
   ============================================================================ */

/* ----- BASE HISTOLOGY COLUMN ----- */
.histology-column {
    display: grid;
    gap: 4px;
    padding: 4px;
    padding-bottom: 162px; /* Space for dock with visible labels */
    position: relative;
    overflow: hidden;
    /* Default to vertical layout */
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
    /* Smooth transition for dock show/hide */
    transition: padding-bottom 0.3s ease-out;
}

/* When dock is hidden, panels expand to fill the space */
.histology-column.dock-hidden {
    padding-bottom: 8px; /* Minimal padding when dock is hidden */
}

/* ----- VERTICAL LAYOUT (Default) ----- */
/* Panels stacked on top of each other */
.histology-column.layout-vertical {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
}

/* ----- HORIZONTAL LAYOUT ----- */
/* Panels side by side */
.histology-column.layout-horizontal {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
}

/* ----- SINGLE-VIEW LAYOUT ----- */
/* Map 1 only - Map 2 hidden and Map 1 expands to fill the column,
   overriding whichever layout-vertical/layout-horizontal is active */
.histology-column.single-view {
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr !important;
}

.histology-column.single-view #histologyPanel2 {
    display: none;
}

/* Swap-stains button sits between the two panels as a sibling, not inside
   either panel, so hiding Map 2 alone doesn't hide it - hide it explicitly
   since there's nothing to swap with in single-view. */
.histology-column.single-view .stain-swap-btn {
    display: none;
}

/* ----- PANEL BASE STYLES ----- */
.histology-panel {
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ----- PANEL TRANSITION EFFECTS ----- */
.histology-column {
    transition: grid-template-columns 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                grid-template-rows 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ----- LAYOUT CHANGE INDICATOR (for debugging) ----- */
.histology-column::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    padding: 2px 6px;
    font-size: 10px;
    color: transparent;
    pointer-events: none;
    z-index: 100;
}

/* Optional: Show layout indicator in debug mode */
.histology-column.show-layout-debug::after {
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px 0 0 0;
}

.histology-column.show-layout-debug.layout-vertical::after {
    content: 'Vertical';
}

.histology-column.show-layout-debug.layout-horizontal::after {
    content: 'Horizontal';
}

/* ----- MAP CONTAINER ADJUSTMENTS ----- */
/* Ensure map fills available space in both layouts */
.histology-column .histology-map-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
}

.histology-column .histology-map-container {
    flex: 1;
    width: 100%;
    min-height: 0;
    position: relative;
}

.histology-column .histology-map {
    width: 100%;
    height: 100%;
}

/* ----- RESPONSIVE ADJUSTMENTS FOR ADAPTIVE LAYOUT ----- */
/* Force vertical on very narrow screens */
/* Force vertical on very narrow screens */
@media (max-width: 1000px) {
    .histology-column {
        grid-template-columns: 1fr !important;
        grid-template-rows: 1fr 1fr !important;
    }
}

/* Force horizontal on ultra-wide screens with limited height */
@media (min-width: 2400px) and (max-height: 900px) {
    .histology-column {
        grid-template-columns: 1fr 1fr !important;
        grid-template-rows: 1fr !important;
    }
}

/* ============================================================================
   NEW COMPONENTS (Per Mentor's Specification)
   ============================================================================ */

/* ============================================================================
   1. MRI NAVIGATION PANE - STROKE SIGNATURES PANEL
   ============================================================================ */

/* Stroke Signatures Panel Container - Clean white background */
.stroke-signatures-panel {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    margin: 4px 0;
}

/* Stroke Section Label */
.nav-section-label.stroke-section {
    color: #dc2626;
    border-left-color: #dc2626;
    font-weight: 600;
    margin-bottom: 8px;
}

/* ROI Overlay Group */
.roi-overlay-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Overlay Checkbox Styling */
.overlay-checkbox {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 5px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 5px;
    transition: background 0.2s ease;
}

.overlay-checkbox:hover {
    background: rgba(255, 255, 255, 0.8);
}

body.dark-mode .overlay-checkbox {
    background: rgba(0, 0, 0, 0.2);
}

body.dark-mode .overlay-checkbox:hover {
    background: rgba(0, 0, 0, 0.3);
}

.overlay-name {
    font-size: 9px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.overlay-name-ischemic {
    color: #ef4444;
    font-weight: 600;
}

.overlay-name-hyper {
    color: #d4a700;
    font-weight: 600;
}

/* Custom checkbox styling for stroke overlays */
.overlay-checkbox input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border: 2px solid #ccc;
    border-radius: 3px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}

/* Default Feature Overlay checkbox - TEAL when checked */
.overlay-checkbox input[type="checkbox"]:checked {
    background-color: #14b8a6;
    border-color: #14b8a6;
}

.overlay-checkbox input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 0px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Ischemic Core checkbox - RED when checked */
.overlay-checkbox input[data-overlay="ischemic-core"] {
    border-color: #ef4444;
}

.overlay-checkbox input[data-overlay="ischemic-core"]:checked {
    background-color: #ef4444;
    border-color: #ef4444;
}

.overlay-checkbox input[data-overlay="ischemic-core"]:checked::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 0px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Hyperintensity checkbox - YELLOW when checked */
.overlay-checkbox input[data-overlay="hyperintensity"] {
    border-color: #d4a700;
}

.overlay-checkbox input[data-overlay="hyperintensity"]:checked {
    background-color: #d4a700;
    border-color: #d4a700;
}

.overlay-checkbox input[data-overlay="hyperintensity"]:checked::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 0px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* ROI Opacity Controls */
.roi-opacity-controls {
    margin-top: 8px;
}

.roi-slider-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

body.dark-mode .roi-slider-row {
    background: rgba(0, 0, 0, 0.15);
}

.roi-slider-label {
    font-size: 9px;
    color: var(--text-secondary);
    font-weight: 500;
}

.roi-slider-label.overlay-name-ischemic {
    color: #ef4444;
}

.roi-slider-label.overlay-name-hyper {
    color: #facc15;
}

/* Compact Slider Container */
.slider-container.compact {
    gap: 4px;
}

.slider-container.compact .slider {
    height: 4px;
}

.slider-container.compact .slider::-webkit-slider-thumb {
    width: 9px;
    height: 9px;
    border-width: 1.5px;
}

.slider-container.compact .slider::-moz-range-thumb {
    width: 9px;
    height: 9px;
    border-width: 1.5px;
}

.slider-container.compact .slider-value {
    font-size: 9px;
    min-width: 28px;
}

/* ROI Opacity Slider */
.roi-opacity-slider {
    flex: 1;
}

/* ============================================================================
   2. MRI DIRECTION INDICATORS
   ============================================================================ */

/* Direction Indicators Container */
.mri-direction-indicators {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 15;
}

/* Individual Direction Indicator */
.direction-indicator {
    position: absolute;
    font-size: 12px;
    font-weight: 700;
    color: #ffffff;
    background: rgba(0, 0, 0, 0.6);
    padding: 2px 6px;
    border-radius: 3px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    z-index: 16;
}

/* Direction Positions */
.direction-indicator.dir-top {
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
}

.direction-indicator.dir-left {
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
}

.direction-indicator.dir-right {
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
}

.direction-indicator.dir-bottom {
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
}

/* ============================================================================
   3. HISTOLOGY PANEL - POSITION AND STAIN BADGES
   ============================================================================ */

/* Position Badge (Sagittal position in mm) */
.info-badge.position-badge {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    font-weight: 600;
}

/* Antibody Badge (for IHC stains) */
.info-badge.antibody-badge {
    background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
    color: white;
    font-weight: 600;
    font-size: 9px;
}

/* Feature Overlay Container */
.feature-overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 50;
}

/* ============================================================================
   4. BOTTOM THUMBNAIL DOCK (File-packed Layout like thumbnailPopup)
   ============================================================================ */

/*
 * DOCK DESIGN - File-packed like thumbnailPopup:
 * 1. Multiple stain images stacked per section (like card stack)
 * 2. Minimal gaps between section groups
 * 3. Overflow visible for hover zoom (not clipped)
 * 4. ~10 sections visible, compact width
 * 5. Labels showing section number
 */

/* ==========================================================
   DOCK ACTIVATION ZONE - Invisible trigger area at bottom
   This prevents accidental dock triggering when using images
   ========================================================== */
/* Activation zone no longer needed - dock is always visible */
.dock-activation-zone {
    display: none;
}

/* ==========================================================
   BFI PREVIEW PANEL - Large preview on left side of dock
   ========================================================== */
.dock-bfi-preview {
    position: relative;
    width: 115px;
    height: 115px;
    flex-shrink: 0;
    background: #000;
    border-radius: 14px;
    overflow: hidden;
    margin-right: 12px;
    margin-left: 10px;
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.15),
        inset 0 0 0 1px rgba(255, 255, 255, 0.1);
    /* Flexbox centering for consistent image positioning */
    display: flex;
    align-items: center;
    justify-content: center;
}

.dock-bfi-preview img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    margin: auto;
    transition: transform 0.3s ease;
}

.dock-bfi-preview:hover img {
    transform: scale(1.05);
}

.dock-bfi-preview .bfi-label {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 6px;
    border-radius: 4px;
}

#dockBfiImage {
    transition: opacity 0.15s ease;
}

/* ==========================================================
   THUMBNAIL DOCK CONTAINER - Wider dock with flexible thumbnails
   Stays centered, thumbnails grow/shrink to fill space
   ========================================================== */
.thumbnail-dock {
    position: absolute;
    bottom: 6px; /* 6px gap from bottom boundary */
    left: 4px; /* Align with Panel 1 left edge */
    right: 4px; /* Align with Panel 2 right edge */
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 4px 12px 6px 12px;
    box-sizing: border-box;
    background: linear-gradient(
        180deg,
        /* rgba(255, 255, 255, 0.97) 0%, */
        rgb(206 228 247) 0%,
        rgba(240, 242, 245, 0.98) 100%
    );
    backdrop-filter: blur(20px) saturate(1.2);
    -webkit-backdrop-filter: blur(20px) saturate(1.2);
    border-radius: 16px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    box-shadow:
        0 -6px 30px rgba(0, 0, 0, 0.1),
        0 -2px 10px rgba(0, 0, 0, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.8),
        inset 0 -1px 0 rgba(0, 0, 0, 0.03);
    opacity: 1; /* Always visible */
    z-index: 98;
    overflow: visible;
}

/* Dock hidden state - smooth slide down animation */
.thumbnail-dock.hidden {
    transform: translateY(calc(100% + 20px));
    opacity: 0;
    pointer-events: none;
}

/* Smooth transition for show/hide */
.thumbnail-dock {
    transition: transform 0.3s ease-out, opacity 0.25s ease-out;
}

/* Toggle Dock Button styling */
.toggle-dock-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px !important;
}

.toggle-dock-btn svg {
    flex-shrink: 0;
}

.toggle-dock-btn .dock-toggle-text {
    font-size: 11px;
}

/* Active state when dock is visible */
.toggle-dock-btn.dock-visible {
    background: rgba(59, 130, 246, 0.15);
    color: #3B82F6;
    border-color: rgba(59, 130, 246, 0.3);
}

.toggle-dock-btn.dock-visible svg {
    stroke: #3B82F6;
}

/* Subtle inner glow effect */
.thumbnail-dock::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20px;
    right: 20px;
    height: 1px;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(0, 0, 0, 0.06) 20%,
        rgba(0, 0, 0, 0.1) 50%,
        rgba(0, 0, 0, 0.06) 80%,
        transparent 100%
    );
    border-radius: 1px;
}

/* Dock Navigation Buttons - Circular design (reference style) */
.dock-nav-btn {
    position: relative;
    z-index: 60;
    width: 36px;
    height: 36px;
    min-width: 36px;
    max-width: 36px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    background: #ffffff;
    color: rgba(0, 0, 0, 0.5);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    flex-grow: 0;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow:
        0 2px 6px rgba(0, 0, 0, 0.08),
        0 1px 2px rgba(0, 0, 0, 0.04);
}

.dock-nav-btn:hover {
    background: #f8fafc;
    border-color: rgba(0, 0, 0, 0.15);
    color: rgba(0, 0, 0, 0.7);
    transform: scale(1.08);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.1),
        0 2px 4px rgba(0, 0, 0, 0.06);
}

.dock-nav-btn:active {
    transform: scale(0.95);
    background: #f1f5f9;
}

.dock-nav-btn svg {
    width: 14px;
    height: 14px;
    stroke-width: 2.5;
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

.dock-nav-btn:hover svg {
    transform: scale(1.05);
}

/* Left navigation button */
.dock-nav-btn.dock-nav-left {
    margin-left: 8px;
    margin-right: 8px;
}

/* Right navigation button */
.dock-nav-btn.dock-nav-right {
    margin-left: 8px;
    margin-right: 8px;
}

/* ==========================================================
   DOCK THUMBNAILS CONTAINER - Fills available space
   ========================================================== */
.dock-thumbnails {
    display: flex;
    flex: 1 1 auto;
    gap: 8px;
    align-items: center;
    justify-content: space-evenly;
    overflow-x: hidden;
    overflow-y: visible;
    padding: 12px 0 38px 0;
    min-height: 120px;
    min-width: 0;
    transform: translateZ(0);
    will-change: transform, opacity;
    backface-visibility: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    /* Smooth transition for layout changes */
    transition: gap 0.3s ease;
}

/* Hide scrollbar for Chrome/Safari */
.dock-thumbnails::-webkit-scrollbar {
    display: none;
}

/* Navigation slide animations - GPU accelerated */
.dock-thumbnails.navigating {
    transition: transform 0.18s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

.dock-thumbnails.slide-out-left {
    transform: translateX(-40px) translateZ(0);
    opacity: 0;
}

.dock-thumbnails.slide-out-right {
    transform: translateX(40px) translateZ(0);
    opacity: 0;
}

.dock-thumbnails.slide-in-left {
    transform: translateX(40px) translateZ(0);
    opacity: 0;
}

.dock-thumbnails.slide-in-right {
    transform: translateX(-40px) translateZ(0);
    opacity: 0;
}

/* ==========================================================
   SECTION GROUP - Clean card design (reference style)
   ========================================================== */
.dock-section-group {
    position: relative;
    flex: 0 0 auto;
    width: 78px;
    height: 88px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center bottom;
    border-radius: 12px;
    background: #ffffff;
    border: 2px solid transparent;
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.08),
        0 1px 3px rgba(0, 0, 0, 0.06);
    /* Smooth fade-in animation when added */
    animation: dockThumbnailFadeIn 0.3s ease-out;
}

@keyframes dockThumbnailFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Hover effect - subtle lift with blue highlight */
.dock-section-group:hover {
    transform: translateY(-6px);
    z-index: 50;
    border-color: #3b82f6;
    box-shadow:
        0 0 0 1px rgba(59, 130, 246, 0.2),
        0 8px 20px rgba(59, 130, 246, 0.15),
        0 4px 8px rgba(0, 0, 0, 0.08);
}

/* Active section styling - red border */
.dock-section-group.active {
    z-index: 10;
    border-color: #ef4444;
    box-shadow:
        0 0 0 1px rgba(239, 68, 68, 0.2),
        0 4px 12px rgba(239, 68, 68, 0.15),
        0 2px 6px rgba(0, 0, 0, 0.08);
}

.dock-section-group.active:hover {
    box-shadow:
        0 0 0 1px rgba(239, 68, 68, 0.3),
        0 8px 20px rgba(239, 68, 68, 0.2),
        0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Images container - full coverage */
.dock-images-stack {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-sizing: border-box;
}

/* Single thumbnail image - fills entire card */
.dock-stacked-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    border: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
}

/* Image hover - handled by parent group styles */

/* Single image - no stacking needed, all images use same style */

/* ==========================================================
   SECTION LABEL - Elegant pill-shaped labels
   ========================================================== */
.dock-section-label {
    position: absolute;
    bottom: -32px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.1px;
    color: #64748b;
    background: transparent;
    padding: 0;
    border: none;
    box-shadow: none;
    pointer-events: none;
    z-index: 10;
    white-space: nowrap;
    transition: color 0.2s ease;
    line-height: 1.2;
}

/* Label parts - secId on top, mm in middle, marker at bottom */
.dock-section-label .label-secid {
    display: block;
    font-weight: 600;
    font-size: 9px;
    color: #475569;
}

.dock-section-label .label-mm {
    display: block;
    font-weight: 500;
    color: #64748b;
}

.dock-section-label .label-marker {
    display: block;
    font-size: 8px;
    font-weight: 400;
    color: #94a3b8;
    margin-top: 1px;
}

/* Label on hover */
.dock-section-group:hover .dock-section-label {
    color: #475569;
}

.dock-section-group:hover .dock-section-label .label-secid {
    color: #334155;
}

.dock-section-group:hover .dock-section-label .label-mm {
    color: #475569;
}

.dock-section-group:hover .dock-section-label .label-marker {
    color: #64748b;
}

/* Active section label - red accent to match border */
.dock-section-group.active .dock-section-label .label-secid {
    color: #dc2626;
    font-weight: 700;
}

.dock-section-group.active .dock-section-label .label-mm {
    color: #ef4444;
    font-weight: 600;
}

.dock-section-group.active .dock-section-label .label-marker {
    color: #f87171;
}

/* ==========================================================
   TOOLTIP - Premium floating tooltip (DISABLED)
   ========================================================== */
/* .dock-section-group[data-tooltip]:hover::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 16px);
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 14px;
    background: linear-gradient(
        145deg,
        rgba(255, 255, 255, 0.98) 0%,
        rgba(245, 245, 250, 0.99) 100%
    );
    color: #333;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.2px;
    white-space: nowrap;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    z-index: 200;
    pointer-events: none;
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    animation: tooltipFadeIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
} */

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) scale(0.95) translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) scale(1) translateY(0);
    }
}

/* Dock Range Indicator - hidden by default, minimal */
.dock-range-indicator {
    display: none; /* Keep dock clean */
}

/* ============================================================================
   5. HISTOLOGY NAVIGATION PANE - FEATURE OVERLAY CONTROLS
   ============================================================================ */

/* Scrollable Feature Overlay Group */
.feature-overlay-group.scrollable {
    max-height: 180px;
    overflow-y: auto;
    padding-right: 4px;
}

/* Custom Scrollbar for Feature Overlay */
.feature-overlay-group.scrollable::-webkit-scrollbar {
    width: 4px;
}

.feature-overlay-group.scrollable::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
}

.feature-overlay-group.scrollable::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 2px;
}

.feature-overlay-group.scrollable::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.5);
}

/* Overlay Opacity Section */
.overlay-opacity-section {
    margin-top: 4px;
}

/* Overlay Opacity Sliders Container */
.overlay-opacity-sliders {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 150px;
    overflow-y: auto;
}

/* Opacity Placeholder */
.opacity-placeholder {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    padding: 8px;
    font-style: italic;
}

/* Dynamic Opacity Slider Row */
.overlay-opacity-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

body.dark-mode .overlay-opacity-row {
    background: rgba(255, 255, 255, 0.05);
}

.overlay-opacity-row .overlay-label {
    font-size: 9px;
    color: var(--text-secondary);
    min-width: 60px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.overlay-opacity-row .slider {
    flex: 1;
    height: 4px;
}

.overlay-opacity-row .opacity-value {
    font-size: 9px;
    color: var(--text-secondary);
    min-width: 28px;
    text-align: right;
}

/* ============================================================================
   6. MRI TRANSPARENCY DRAG INDICATOR
   ============================================================================ */

/* Transparency Drag Indicator */
.mri-transparency-indicator {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 4px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 20;
}

.mri-view-image:hover .mri-transparency-indicator,
.mri-view-image.dragging .mri-transparency-indicator {
    opacity: 1;
}

.mri-transparency-indicator svg {
    width: 12px;
    height: 12px;
    color: white;
}

.mri-transparency-value {
    font-size: 9px;
    color: white;
    font-weight: 600;
}

/* Dragging State */
.mri-view-image.dragging {
    cursor: ns-resize;
}

/* ============================================================================
   7. RESPONSIVE ADJUSTMENTS FOR NEW COMPONENTS
   ============================================================================ */

@media (max-width: 1400px) {
    .stroke-signatures-panel {
        padding: 6px;
    }

    .overlay-name {
        font-size: 9px;
    }

    .roi-slider-label {
        font-size: 8px;
    }

    .thumbnail-dock {
        max-width: calc(100% - 16px);
        padding: 7px 10px;
    }

    .dock-thumbnails {
        gap: 10px;
        min-height: 100px;
        padding-bottom: 26px;
    }

    .dock-section-group {
        width: 70px;
        height: 82px;
    }

    /* .dock-stacked-img uses 100% - no override needed */

    .dock-section-label {
        font-size: 9px;
    }

    .dock-section-label .label-secid {
        font-size: 8px;
    }

    .dock-section-label .label-marker {
        font-size: 7px;
    }
}

@media (max-width: 1200px) {
    .feature-overlay-group.scrollable {
        max-height: 140px;
    }

    .thumbnail-dock {
        max-width: calc(100% - 16px);
        padding: 6px 8px;
    }

    .dock-thumbnails {
        gap: 8px;
        min-height: 95px;
        padding-bottom: 24px;
    }

    .dock-section-group {
        width: 64px;
        height: 78px;
    }

    /* .dock-stacked-img uses 100% - no override needed */

    .dock-section-label {
        font-size: 9px;
    }

    .dock-section-label .label-secid {
        font-size: 8px;
    }

    .dock-section-label .label-marker {
        font-size: 7px;
    }
}

@media (max-width: 900px) {
    .thumbnail-dock {
        max-width: calc(100% - 12px);
        padding: 5px 6px;
    }

    .dock-thumbnails {
        gap: 6px;
        min-height: 85px;
        padding-bottom: 22px;
    }

    .dock-section-group {
        width: 56px;
        height: 70px;
    }

    /* .dock-stacked-img uses 100% - no override needed */

    .dock-nav-btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
        max-width: 28px;
    }

    .dock-nav-btn svg {
        width: 12px;
        height: 12px;
    }

    .dock-nav-btn.dock-nav-left {
        margin-left: 4px;
        margin-right: 6px;
    }

    .dock-nav-btn.dock-nav-right {
        margin-left: 6px;
        margin-right: 4px;
    }

    .dock-section-label {
        font-size: 8px;
    }

    .dock-section-label .label-secid {
        font-size: 7px;
    }

    .dock-section-label .label-marker {
        font-size: 6px;
    }

    .dock-section-group:hover {
        transform: translateY(-4px);
    }
}

/* ============================================================================
   8. DARK MODE ADJUSTMENTS FOR NEW COMPONENTS
   ============================================================================ */

body.dark-mode .stroke-signatures-panel {
    background: var(--surface-color);
    border-color: var(--border-color);
}

body.dark-mode .nav-section-label.stroke-section {
    color: #f87171;
}

body.dark-mode .direction-indicator {
    background: rgba(0, 0, 0, 0.8);
}

body.dark-mode .thumbnail-dock {
    background: linear-gradient(135deg, var(--surface-color) 0%, #1a2744 100%);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow:
        0 -6px 30px rgba(0, 0, 0, 0.4),
        0 -2px 10px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

body.dark-mode .thumbnail-dock::before {
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.2) 20%,
        rgba(255, 255, 255, 0.3) 50%,
        rgba(255, 255, 255, 0.2) 80%,
        transparent 100%
    );
}

body.dark-mode .dock-nav-btn {
    background: rgba(30, 30, 45, 0.9);
    color: rgba(255, 255, 255, 0.7);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

body.dark-mode .dock-nav-btn:hover {
    background: rgba(40, 40, 60, 0.95);
    color: white;
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

body.dark-mode .dock-section-group {
    background: rgba(30, 30, 45, 0.9);
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

body.dark-mode .dock-section-group:hover {
    border-color: #60a5fa;
    box-shadow:
        0 0 0 1px rgba(96, 165, 250, 0.3),
        0 8px 20px rgba(96, 165, 250, 0.2);
}

body.dark-mode .dock-section-group.active {
    border-color: #ef4444;
    box-shadow:
        0 0 0 1px rgba(239, 68, 68, 0.3),
        0 4px 12px rgba(239, 68, 68, 0.2);
}

body.dark-mode .dock-section-group .dock-stacked-img {
    background: rgba(255, 255, 255, 0.1);
}

body.dark-mode .dock-section-label .label-secid {
    color: rgba(255, 255, 255, 0.85);
}

body.dark-mode .dock-section-label .label-mm {
    color: rgba(255, 255, 255, 0.7);
}

body.dark-mode .dock-section-label .label-marker {
    color: rgba(255, 255, 255, 0.5);
}

/* Dark mode toggle dock button */
body.dark-mode .toggle-dock-btn.dock-visible {
    background: rgba(59, 130, 246, 0.25);
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.4);
}

body.dark-mode .toggle-dock-btn.dock-visible svg {
    stroke: #60a5fa;
}

body.dark-mode .dock-section-group:hover .dock-section-label .label-secid {
    color: rgba(255, 255, 255, 1);
}

body.dark-mode .dock-section-group:hover .dock-section-label .label-mm {
    color: rgba(255, 255, 255, 0.9);
}

body.dark-mode .dock-section-group.active .dock-section-label .label-secid {
    color: #ef4444;
}

body.dark-mode .dock-section-group.active .dock-section-label .label-mm {
    color: #f87171;
}

body.dark-mode .dock-section-group.active .dock-section-label .label-marker {
    color: #fca5a5;
}

body.dark-mode .overlay-name {
    color: var(--text-secondary);
}

body.dark-mode .roi-slider-label {
    color: var(--text-secondary);
}

body.dark-mode .feature-overlay-group.scrollable::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

body.dark-mode .feature-overlay-group.scrollable::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
}

body.dark-mode .feature-overlay-group.scrollable::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* ============================================================================
   HISTOLOGY NAVIGATION PANE - CLEAN UI (matching MRI Nav style)
   ============================================================================ */

/* Better sidebar content padding - matches MRI nav */
.sidebar.histology-nav-pane .sidebar-content {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Section labels - cleaner like MRI stroke section */
.sidebar.histology-nav-pane .nav-section-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    padding: 8px 10px;
    margin: 8px 0 6px 0;
    border-radius: 6px;
    border-left: 3px solid;
}

.sidebar.histology-nav-pane .nav-section-label:first-child {
    margin-top: 0;
}

/* Measurement section - blue accent */
.sidebar.histology-nav-pane .nav-section-label:not(.top-panel):not(.bottom-panel) {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(59, 130, 246, 0.03) 100%);
    border-left-color: #3b82f6;
    color: #1d4ed8;
}

/* Toggle buttons group - cleaner layout */
.sidebar.histology-nav-pane .toggle-buttons-group {
    display: flex;
    gap: 8px;
    margin-bottom: 6px;
}

.sidebar.histology-nav-pane .toggle-btn {
    flex: 1;
    padding: 9px 10px;
    font-size: 11px;
    gap: 6px;
    border-radius: 6px;
    font-weight: 500;
    justify-content: center;
}

.sidebar.histology-nav-pane .toggle-btn svg {
    width: 16px;
    height: 16px;
}

/* The base .toggle-btn span has flex:1, which fills all leftover row width
   and left-aligns its text inside itself - that cancels out the
   justify-content:center above (no free space is left to redistribute), so
   the icon+label never actually center as a group. Let the span size to its
   content instead, so centering works as intended. */
.sidebar.histology-nav-pane .toggle-btn span {
    flex: none;
    text-align: center;
}

/* Control groups - better spacing */
.sidebar.histology-nav-pane .control-group {
    margin-bottom: 12px;
}

/* Control labels - matches MRI nav style */
.sidebar.histology-nav-pane .control-label {
    font-size: 10px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-color);
    letter-spacing: 0.3px;
    display: block;
}

/* Feature overlay container - box style like coordinates-box */
.sidebar.histology-nav-pane .checkbox-group.feature-overlay-group {
    background: linear-gradient(145deg, #f8f9fa 0%, #eef1f5 100%);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    gap: 3px;
}

body.dark-mode .sidebar.histology-nav-pane .checkbox-group.feature-overlay-group {
    background: linear-gradient(145deg, #0f172a 0%, #1e293b 100%);
    border-color: var(--border-color);
}

/* Overlay checkboxes - cleaner rows */
.sidebar.histology-nav-pane .overlay-checkbox {
    padding: 6px 8px;
    gap: 8px;
    border-radius: 4px;
    margin: 0;
    background: transparent;
    transition: background 0.15s ease;
}

.sidebar.histology-nav-pane .overlay-checkbox:hover {
    background: rgba(59, 130, 246, 0.08);
}

body.dark-mode .sidebar.histology-nav-pane .overlay-checkbox:hover {
    background: rgba(59, 130, 246, 0.15);
}

/* Overlay names - cleaner typography */
.sidebar.histology-nav-pane .overlay-name {
    font-size: 10px;
    line-height: 1.4;
    color: var(--text-color);
    font-weight: 400;
}

/* Feature overlay scrollable area */
.sidebar.histology-nav-pane .feature-overlay-group.scrollable {
    max-height: 180px;
    padding-right: 4px;
}

/* Divider - cleaner */
.sidebar.histology-nav-pane .sidebar-divider {
    margin: 12px 0;
    border-color: var(--border-color);
    opacity: 0.5;
}

/* Center divider between Map1 and Map2 */
.sidebar.histology-nav-pane .sidebar-divider.center-divider {
    margin: 16px 0;
    border-top: 2px dashed var(--border-color);
    opacity: 0.4;
}

/* Opacity section styling */
.sidebar.histology-nav-pane .overlay-opacity-section {
    margin-top: 6px;
}

.sidebar.histology-nav-pane .opacity-placeholder {
    font-size: 9px;
    color: var(--text-tertiary, #999);
    font-style: italic;
    padding: 6px 8px;
    text-align: center;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 4px;
}

body.dark-mode .sidebar.histology-nav-pane .opacity-placeholder {
    background: rgba(255, 255, 255, 0.03);
    color: #666;
}

/* Checkbox input styling - cleaner checkmarks */
.sidebar.histology-nav-pane .overlay-checkbox input[type="checkbox"] {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* Dark mode text adjustments */
body.dark-mode .sidebar.histology-nav-pane .control-label {
    color: var(--text-color);
}

body.dark-mode .sidebar.histology-nav-pane .overlay-name {
    color: var(--text-color);
}

body.dark-mode .sidebar.histology-nav-pane .nav-section-label:not(.top-panel):not(.bottom-panel) {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(59, 130, 246, 0.05) 100%);
    color: #60a5fa;
}

body.dark-mode .sidebar.histology-nav-pane .nav-section-label.top-panel {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(59, 130, 246, 0.05) 100%);
    color: #60a5fa;
}

body.dark-mode .sidebar.histology-nav-pane .nav-section-label.bottom-panel {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.15) 0%, rgba(168, 85, 247, 0.05) 100%);
    color: #c4b5fd;
}

/* Responsive adjustments for histology nav pane */
@media (max-width: 1600px) {
    .sidebar.histology-nav-pane .sidebar-content {
        padding: 8px 10px;
    }

    .sidebar.histology-nav-pane .nav-section-label {
        font-size: 9px;
        padding: 6px 8px;
        margin: 6px 0 4px 0;
    }

    .sidebar.histology-nav-pane .toggle-btn {
        padding: 8px 10px;
        font-size: 10px;
    }

    .sidebar.histology-nav-pane .toggle-btn svg {
        width: 14px;
        height: 14px;
    }

    .sidebar.histology-nav-pane .overlay-name {
        font-size: 9px;
    }

    .sidebar.histology-nav-pane .control-label {
        font-size: 9px;
        margin-bottom: 6px;
    }

    .sidebar.histology-nav-pane .checkbox-group.feature-overlay-group {
        padding: 6px;
    }

    .sidebar.histology-nav-pane .overlay-checkbox {
        padding: 5px 6px;
        gap: 6px;
    }
}

@media (max-width: 1400px) {
    .sidebar.histology-nav-pane .sidebar-content {
        padding: 6px 8px;
    }

    .sidebar.histology-nav-pane .toggle-buttons-group {
        gap: 6px;
    }

    .sidebar.histology-nav-pane .toggle-btn {
        padding: 7px 8px;
        font-size: 9px;
    }

    .sidebar.histology-nav-pane .overlay-checkbox {
        padding: 4px 5px;
    }

    .sidebar.histology-nav-pane .feature-overlay-group.scrollable {
        max-height: 150px;
    }

    .sidebar.histology-nav-pane .control-group {
        margin-bottom: 8px;
    }

    .sidebar.histology-nav-pane .sidebar-divider {
        margin: 8px 0;
    }
}


