/* Medical Imaging App Styles - Sotis AI Design System */
/* .page-header, .eyebrow and the .btn-* hierarchy live in the core style.css.
   This app must not redefine them: it used to override .btn-primary and
   .btn-secondary, which turned every primary action of the app violet. */

/* ============================================
   SHARED: INLINE ICONS
   ============================================ */

/* Lucide-shaped SVGs are written inline in the markup here rather than through
   <i data-lucide>, because three viewer functions (showStructureNotice,
   updateStructureInfoDisplay, the expand toggle) inject markup long after
   chrome.js has called lucide.createIcons(); a data-lucide placeholder in those
   fragments would stay empty. */
.mi-icon {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

/* Opt-in solid part of an icon (contrast half-disc, dot glyphs). Needs a class
   because the .mi-icon `fill: none` above beats a presentation attribute. */
.mi-icon .mi-fill {
    fill: currentColor;
    stroke: none;
}

/* The accented icon tile of the design system: brand wash + brand ink. */
.mi-icon-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: var(--violet-wash);
    color: var(--violet-primary);
    flex-shrink: 0;
}

/* ============================================
   UPLOAD / SESSIONS PAGES
   ============================================ */

/* `main` already caps the width at 1200px and supplies the horizontal padding,
   so this wrapper only owns the vertical rhythm. */
.medicalimg-page {
    padding-bottom: var(--space-lg);
}

.medicalimg-page > section {
    padding: var(--space-lg) 0;
}

/* Neighbouring sections are separated by a hairline, never by a background
   change and never by a centred word. */
.medicalimg-page > section + section {
    border-top: 1px solid var(--border-color);
}

@media (max-width: 768px) {
    .medicalimg-page > section {
        padding: var(--space-md) 0;
    }
}

/* Section head. Same grammar as home.css, restated because home.css is only
   loaded on the landing page. */
.medicalimg-page .section-head {
    margin-bottom: var(--space-md);
}

.medicalimg-page .section-head h2 {
    font-size: var(--text-2xl);
    color: var(--text-primary);
    margin-top: 0.5rem;
}

.medicalimg-page .section-lead {
    color: var(--text-secondary);
    max-width: 62ch;
}

/* Page header with a trailing action (sessions page). The hairline moves to
   the wrapper so it spans the action too. */
.mi-page-actions {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-color);
}

.mi-page-actions > .page-header {
    flex: 1 1 320px;
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

/* Admin Panel */
.admin-panel {
    margin-bottom: var(--space-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.admin-panel-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-secondary);
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: var(--text-base);
    color: var(--text-primary);
    transition: background-color var(--transition-fast);
}

.admin-panel-toggle:hover {
    background: var(--surface-raised);
}

.toggle-icon {
    display: inline-flex;
    color: var(--text-secondary);
}

.toggle-icon .mi-icon {
    width: 16px;
    height: 16px;
}

.toggle-text {
    flex: 1;
    text-align: left;
    font-weight: var(--font-weight-medium);
}

.toggle-arrow {
    display: inline-flex;
    color: var(--text-secondary);
    transition: transform var(--transition-fast);
}

.toggle-arrow .mi-icon {
    width: 16px;
    height: 16px;
}

.toggle-arrow.open {
    transform: rotate(180deg);
}

.admin-panel-content {
    display: none;
    padding: var(--space-sm);
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
}

.admin-panel-content.open {
    display: block;
}

.admin-panel-content h3 {
    margin-bottom: var(--space-sm);
}

.admin-stats {
    margin-bottom: var(--space-md);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
}

.stat-item {
    padding: 0 var(--space-sm);
    border-left: 1px solid var(--border-color);
}

.stat-item:first-child {
    padding-left: 0;
    border-left: none;
}

.stat-value {
    display: block;
    font-family: var(--font-mono);
    font-size: var(--text-2xl);
    font-weight: var(--font-weight-medium);
    letter-spacing: var(--tracking-tighter);
    line-height: 1;
    color: var(--text-primary);
}

.stat-label {
    display: block;
    margin-top: 0.35rem;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.admin-actions {
    margin-bottom: var(--space-md);
}

.action-buttons {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

.admin-users {
    border-top: 1px solid var(--border-color);
    padding-top: var(--space-sm);
}

.users-list {
    display: flex;
    flex-direction: column;
}

/* Rows are separated by a hairline: a --bg-secondary fill would be invisible
   here, since the panel body already sits on the identical --card-bg. */
.user-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-sm);
    padding: var(--space-xs) 0;
    border-top: 1px solid var(--border-color);
}

.user-row:first-child {
    border-top: none;
}

.user-name {
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    min-width: 100px;
}

.user-stats {
    flex: 1;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

/* Compact variant. Raised in specificity rather than forced with !important,
   which means every container carrying a .btn-small has to be listed here: the
   local .btn-danger rule is declared later in this file, so a bare .btn-small
   would lose its padding to it. .session-actions is the one on the session
   cards (upload page and sessions page). */
.action-buttons .btn-small,
.session-actions .btn-small,
.user-row .btn-small {
    padding: 4px 8px;
    font-size: var(--text-xs);
}

/* Hero: the landing page header, copy on the left and the viewer itself on the
   right. It replaced a plain title and two small "quick start" cards that read
   as information rather than as a way in: nothing on the page showed the tool.
   It stays a .page-header (mandatory for every app title) and only adds the
   two-column grid on top of it. */
.mi-hero {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    align-items: center;
    gap: var(--space-md);
    padding-bottom: var(--space-md);
}

.mi-hero-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1.25rem;
    margin-top: var(--space-sm);
}

.mi-hero-actions .mi-icon {
    width: 16px;
    height: 16px;
    transition: transform var(--transition-fast);
}

.mi-hero-actions a:hover .mi-icon {
    transform: translateX(3px);
}

/* Secondary destination as a bare link: a second button of equal size would
   split the click between two volumes when one of them is the obvious start. */
.mi-hero-alt {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: var(--text-base);
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.mi-hero-alt:hover {
    color: var(--text-primary);
}

/* `.page-header p` sets every paragraph of the header to the subtitle size. */
.page-header .mi-hero-note {
    margin-top: 0.75rem;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.mi-hero-media {
    display: block;
    overflow: hidden;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    box-shadow: var(--shadow-lg);
    transition: border-color var(--transition-fast);
}

.mi-hero-media:hover {
    border-color: var(--violet-dark);
}

.mi-hero-media img {
    display: block;
    width: 100%;
    height: auto;
}

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

/* Capabilities: metric line + short notes */
.mi-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
}

.mi-metric {
    padding: 0 var(--space-sm);
    border-left: 1px solid var(--border-color);
}

.mi-metric:first-child {
    padding-left: 0;
    border-left: none;
}

.mi-metric-value {
    display: block;
    font-family: var(--font-mono);
    font-size: var(--text-4xl);
    font-weight: var(--font-weight-medium);
    letter-spacing: var(--tracking-tighter);
    line-height: 1;
    color: var(--text-primary);
}

.mi-metric-unit {
    margin-left: 0.2rem;
    font-size: var(--text-xl);
    letter-spacing: var(--tracking-normal);
}

.mi-metric-label {
    display: block;
    margin-top: 0.6rem;
    font-size: var(--text-base);
    color: var(--text-primary);
}

.mi-metric-detail {
    display: block;
    margin-top: 0.25rem;
    font-size: var(--text-sm);
    line-height: var(--leading-snug);
    color: var(--text-tertiary);
}

.mi-notes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-md);
    margin-top: var(--space-md);
}

.mi-note h3 {
    margin-bottom: 0.4rem;
    font-size: var(--text-base);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
}

.mi-note p {
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    color: var(--text-secondary);
    max-width: 36ch;
}

/* Login Prompt */
.login-prompt {
    color: var(--text-secondary);
    max-width: 62ch;
}

.login-prompt a {
    color: var(--violet-primary);
    text-decoration: none;
}

.login-prompt a:hover {
    text-decoration: underline;
}

/* Upload cards */
.upload-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--space-sm);
}

.upload-card {
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}

.upload-card-title {
    font-size: var(--text-lg);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
}

.upload-info {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    margin-bottom: var(--space-sm);
}

.example-form,
.upload-form {
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* Example Select */
.example-select-wrapper {
    margin-bottom: var(--space-xs);
}

.example-select {
    width: 100%;
    padding: 0.55rem 0.6rem;
    font-family: inherit;
    font-size: var(--text-base);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.example-select:hover {
    border-color: var(--violet-primary);
}

.example-select:focus {
    outline: none;
    border-color: var(--violet-primary);
    box-shadow: 0 0 0 3px rgba(var(--violet-primary-rgb), 0.18);
}

.example-select optgroup {
    font-weight: var(--font-weight-medium);
    color: var(--violet-primary);
    background: var(--input-bg);
}

/* Reserved height, so picking an example does not shift the button. */
.example-description {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: var(--leading-snug);
    min-height: 2.6em;
    margin-bottom: var(--space-xs);
}

.example-btn,
.upload-btn {
    align-self: flex-start;
    margin-top: auto;
}

/* File Input. The dashed border lives HERE, on the actual drop target, and
   nowhere else. */
.file-input-wrapper {
    margin-bottom: var(--space-sm);
}

.file-input-wrapper input[type="file"] {
    display: none;
}

.file-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: center;
    transition: background-color var(--transition-fast),
                border-color var(--transition-fast),
                box-shadow var(--transition-fast);
}

.file-label:hover {
    background: var(--violet-wash);
    border-color: var(--violet-primary);
}

.file-input-wrapper.drag-over .file-label {
    background: var(--violet-wash-strong);
    border-color: var(--violet-primary);
    box-shadow: 0 0 0 3px rgba(var(--violet-primary-rgb), 0.18);
}

.file-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: var(--violet-wash);
    color: var(--violet-primary);
}

/* Two sibling glyphs, swapped by a class instead of by rewriting textContent
   (which would have destroyed the inline SVG). */
.file-icon .icon-ready {
    display: none;
}

.file-label.has-file .icon-idle {
    display: none;
}

.file-label.has-file .icon-ready {
    display: block;
}

.file-text {
    color: var(--text-primary);
    font-weight: var(--font-weight-medium);
}

.file-name {
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.file-name.has-file {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-primary);
    word-break: break-all;
}

/* Buttons. Only the two states the core system does not provide.
   .example-btn ships disabled until an example is picked, and it is a
   .btn-secondary: without this the outline button looked identical enabled and
   disabled, while the primary next to it dimmed correctly. */
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-danger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.6rem 1.1rem;
    background: transparent;
    border: 1px solid rgba(var(--danger-rgb), 0.35);
    border-radius: var(--radius-sm);
    color: var(--danger-text);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: var(--font-weight-medium);
    letter-spacing: var(--tracking-tight);
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

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

.btn-danger:focus-visible {
    outline: 2px solid var(--violet-primary);
    outline-offset: 2px;
}

/* Form Errors */
.form-errors,
.field-errors {
    margin-bottom: var(--space-sm);
    padding-left: var(--space-xs);
    border-left: 3px solid var(--danger);
    background: var(--danger-bg);
}

.error-message {
    color: var(--danger-text);
    font-size: var(--text-sm);
    margin: var(--space-xs) 0;
}

/* Sessions */
.sessions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-md);
}

.session-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    transition: var(--transition-base);
}

/* The hover changes the hairline, not the fill. */
.session-card:hover {
    border-color: var(--violet-primary);
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

.session-info h3 {
    color: var(--text-primary);
    font-size: var(--text-base);
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--space-xs);
    word-break: break-all;
}

.session-rows {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.session-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-xs);
}

.session-row .label {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.session-row .value {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-primary);
    text-align: right;
}

.session-actions {
    display: flex;
    gap: var(--space-xs);
    margin-top: auto;
    flex-wrap: wrap;
}

/* Empty State */
.empty-state {
    text-align: left;
    padding: var(--space-lg) 0;
}

.empty-state .mi-icon-tile {
    margin-bottom: var(--space-sm);
}

.empty-state h2 {
    color: var(--text-primary);
    font-size: var(--text-xl);
    margin-bottom: var(--space-xs);
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
    max-width: 62ch;
}

/* ============================================
   VIEWER STYLES
   ============================================ */

/* Full-bleed viewer. Written on <main> itself, never on an inner wrapper, on
   the exact model of `main:has(.immo-explorer)`. Only max-width is touched:
   padding, overflow-x and stacking stay as the chrome defines them. */
main:has(.viewer-container) {
    max-width: none;
}

.viewer-container {
    height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-sm) 0;
}

/* Viewer Header: two stacked rows, left aligned at every width. */
.viewer-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-xs);
}

.viewer-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-sm);
}

.viewer-title h1 {
    font-size: var(--text-lg);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    margin: 0;
}

/* Dimensions and file size are technical signage: monospace, recessed. */
.viewer-meta {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

/* Toolbar */
.viewer-toolbar {
    display: flex;
    align-self: flex-start;
    flex-wrap: wrap;
    gap: var(--space-xs);
    background: var(--card-bg);
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.tool-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    transition: background-color var(--transition-fast),
                border-color var(--transition-fast),
                color var(--transition-fast);
}

.tool-btn:hover {
    background: var(--surface-raised);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

/* One active state for every kind of toolbar button: a tinted outline, not a
   filled slab. There used to be four dispersed rules producing three different
   looks for the same meaning. */
.tool-btn.active,
.tool-btn.transform-btn.active,
#toolbar-more-btn.active,
#tool-fullscreen.active {
    background: var(--violet-wash-strong);
    border-color: var(--violet-primary);
    color: var(--violet-primary);
}

.tool-btn-small {
    width: 28px;
    height: 28px;
    font-weight: var(--font-weight-medium);
}

.tool-btn-small .mi-icon {
    width: 15px;
    height: 15px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: var(--violet-primary);
}

.checkbox-label:hover {
    color: var(--text-primary);
}

.checkbox-label input[type="checkbox"]:checked + span {
    color: var(--violet-primary);
}

/* Works now that .tool-btn is position: relative. */
.tool-btn[title]:hover::after {
    content: attr(title);
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-raised);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    z-index: 20;
}

.toolbar-divider {
    width: 1px;
    background: var(--border-color);
    margin: 0 var(--space-xs);
}

/* Toolbar Colormap */
.toolbar-colormap {
    display: flex;
    align-items: center;
    gap: 6px;
}

.toolbar-colormap label {
    display: inline-flex;
    color: var(--text-secondary);
    cursor: pointer;
}

.toolbar-select {
    padding: 6px 8px;
    font-family: inherit;
    font-size: var(--text-sm);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.toolbar-select:hover,
.toolbar-select:focus {
    border-color: var(--violet-primary);
    outline: none;
}

/* Toolbar Dropdown */
.toolbar-dropdown {
    position: relative;
}

.toolbar-dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--surface-raised);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg), var(--ring-inset);
    padding: var(--space-xs);
    min-width: 170px;
    z-index: 100;
}

.toolbar-dropdown-content.open {
    display: block;
    animation: dropdownFadeIn 0.15s ease-out;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: 4px 0;
}

.dropdown-label {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-medium);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--text-tertiary);
    min-width: 40px;
}

.dropdown-buttons {
    display: flex;
    gap: 4px;
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 6px 0;
}

.toolbar-dropdown-content .checkbox-label {
    font-size: var(--text-sm);
}

/* Viewer Main Area: three planes in a row plus an information rail.
   A 2x2 grid gave 1.64-ratio cells to square images, which wasted more than
   half of every panel. */
.viewer-main {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(220px, 280px);
    grid-template-rows: minmax(0, 1fr);
    gap: var(--space-sm);
    min-height: 0;
}

/* View Panel */
.view-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* View Header */
.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.view-label {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    min-width: 0;
}

.view-label-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Plane identity colours (Material green/blue/orange). Not status tokens:
   #4CAF50 is close to --success (#28A745) but deliberately not the same. */
.view-label-dot.axial { background: #4CAF50; }
.view-label-dot.sagittal { background: #2196F3; }
.view-label-dot.coronal { background: #FF9800; }

.view-label-text {
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
}

.slice-info {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    margin-left: auto;
    white-space: nowrap;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    position: relative;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.canvas-container canvas {
    max-width: 100%;
    max-height: 100%;
    image-rendering: pixelated;
}

/* Slice Slider */
.slice-slider-container {
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.slice-slider {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-strong);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.slice-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--violet-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.slice-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.slice-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--violet-primary);
    border-radius: 50%;
    border: none;
    cursor: pointer;
}

/* Info Panel. The five groups used to sit on --bg-secondary, which is the
   exact value of --card-bg: five invisible boxes. A hairline separates them. */
.info-panel {
    padding: var(--space-sm);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* This panel holds more than it shows at most window heights (at 900px of
   viewport it hides the whole help block). `scrollbar-width: thin` is not
   enough on its own: macOS Chrome keeps overlay scrollbars, which are invisible
   at rest, so the hidden content had no affordance whatsoever. Styling the
   pseudo-elements forces a classic, always-visible bar. */
.info-panel::-webkit-scrollbar {
    width: 8px;
}

.info-panel::-webkit-scrollbar-track {
    background: transparent;
}

.info-panel::-webkit-scrollbar-thumb {
    /* --border-strong is a hairline alpha: at 8px wide on this canvas it is
       invisible, which defeats the point. --text-tertiary is the faintest
       token that still reads as an object. */
    background: var(--text-tertiary);
    border-radius: var(--radius-full);
}

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

.info-panel h3 {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: var(--space-xs);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-medium);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.info-panel h3 .mi-icon {
    width: 14px;
    height: 14px;
    color: var(--violet-primary);
}

.info-group {
    background: none;
    padding: 0;
}

.info-group + .info-group {
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border-color);
}

.info-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-xs);
    padding: 0.25rem 0;
}

.info-row .label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.info-row .value {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--text-primary);
    text-align: right;
}

/* Window Level Controls */
.window-level-controls {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.wl-row {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.wl-row label {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    min-width: 50px;
}

.wl-row input[type="range"] {
    flex: 1;
    min-width: 0;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-strong);
    border-radius: 2px;
}

.wl-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--violet-primary);
    border-radius: 50%;
    cursor: pointer;
}

.wl-row .value {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--text-primary);
    min-width: 48px;
    text-align: right;
}

/* Help Section */
.help-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.help-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--text-sm);
    line-height: var(--leading-snug);
}

.help-icon {
    display: inline-flex;
    color: var(--text-tertiary);
}

.help-icon .mi-icon {
    width: 14px;
    height: 14px;
}

.help-text {
    color: var(--text-secondary);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--border-strong);
    border-top-color: var(--violet-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    color: var(--text-primary);
    margin-top: var(--space-sm);
    font-size: var(--text-base);
}

/* Error Message */
.viewer-error {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    height: 100%;
    padding: var(--space-lg) 0;
    gap: var(--space-sm);
}

.error-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: var(--warning-bg);
    color: var(--warning);
}

.viewer-error h2 {
    color: var(--text-primary);
    font-size: var(--text-xl);
}

.viewer-error p {
    color: var(--text-secondary);
    max-width: 62ch;
}

/* Responsive */

/* Below 1200px the rail cannot hold its width, so the previous 2x2 grid comes
   back with the information panel in its historical slot. */
@media (max-width: 1200px) {
    .viewer-main {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
    }

    .view-panel.panel-info {
        grid-row: 2;
        grid-column: 2;
    }
}

/* This threshold must stay in sync with resizeCanvas() in viewer.js
   (`isMobile = window.innerWidth <= 1024`). */
@media (max-width: 1024px) {
    .viewer-container {
        height: auto;
        min-height: calc(100vh - 120px);
    }

    .viewer-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
        gap: var(--space-sm);
    }

    .view-panel {
        min-height: 300px;
    }

    .view-panel.panel-info {
        grid-row: 4;
        grid-column: 1;
        min-height: auto;
    }

    .canvas-container {
        min-height: 250px;
    }

    .viewer-title h1 {
        word-break: break-all;
    }
}

@media (max-width: 900px) {
    .mi-metrics {
        grid-template-columns: 1fr 1fr;
        row-gap: var(--space-sm);
    }

    .mi-metric:nth-child(3) {
        padding-left: 0;
        border-left: none;
    }
}

@media (max-width: 768px) {
    .upload-card {
        padding: var(--space-sm);
    }

    .sessions-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        row-gap: var(--space-sm);
    }

    .stat-item {
        padding-left: 0;
        border-left: none;
    }
}

@media (max-width: 480px) {
    .mi-metrics {
        grid-template-columns: 1fr;
        row-gap: var(--space-sm);
    }

    .mi-metric {
        padding-left: 0;
        border-left: none;
    }
}

/* ============================================
   Notification
   ============================================ */

/* The toast pattern of the chrome: raised surface, hairline, and the status
   carried by a 3px left rule instead of a saturated fill. */
.viewer-notification {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    background: var(--surface-raised);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg), var(--ring-inset);
    color: var(--text-primary);
    font-size: var(--text-sm);
    z-index: 1000;
    display: none;
}

.viewer-notification.success {
    border-left: 3px solid var(--success);
}

.viewer-notification.error {
    border-left: 3px solid var(--danger);
}

.viewer-notification.info {
    border-left: 3px solid var(--violet-primary);
}

/* Harmonize Button */
.btn-harmonize {
    width: 100%;
    margin-top: var(--space-xs);
    padding: 0.5rem 0.9rem;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.btn-harmonize:hover {
    background: rgba(255, 255, 255, 0.06);
}

/* Escalates through ink, not through hue: same grammar as .btn-primary. */
.btn-harmonize.btn-recommended {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: transparent;
}

.btn-harmonize.btn-recommended:hover {
    background: var(--white);
}

/* ===================================
   Harmonization Alert
   =================================== */

/* This is a warning, not brand signage: it uses the semantic status tokens so
   the single yellow of the screen stays on the orientation markers drawn in
   the canvases. */
.harmonization-alert {
    display: none;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--warning-bg);
    border: 1px solid rgba(var(--warning-rgb), 0.28);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius-md);
    margin: 0;
}

.harmonization-alert .alert-icon {
    display: inline-flex;
    color: var(--warning);
    flex-shrink: 0;
}

.harmonization-alert .alert-content {
    flex: 1;
}

.harmonization-alert .alert-title {
    font-weight: var(--font-weight-medium);
    color: var(--warning-text);
    margin-bottom: 4px;
}

.harmonization-alert .alert-message {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.harmonization-alert .alert-issues {
    margin: 8px 0 0 0;
    padding-left: 20px;
    list-style: disc;
}

.harmonization-alert .alert-issues li {
    margin: 4px 0;
}

.harmonization-alert .alert-issues .issue-high {
    /* Not --danger (#DC3545): close but a distinct red, kept as-is. */
    color: #e74c3c;
    font-weight: 500;
}

.harmonization-alert .alert-issues .issue-medium {
    color: var(--warning-text);
}

.harmonization-alert .alert-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.harmonization-alert .btn-harmonize-alert {
    padding: 0.5rem 0.9rem;
    background: var(--text-primary);
    color: var(--bg-primary);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: background-color var(--transition-fast);
    white-space: nowrap;
}

.harmonization-alert .btn-harmonize-alert:hover {
    background: var(--white);
}

.harmonization-alert .btn-dismiss-alert {
    padding: 0.4rem 0.9rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

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

/* ===================================
   Structure Status Indicator
   =================================== */
.structure-status {
    display: inline-flex;
    align-items: center;
    width: auto;
    gap: 6px;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: var(--text-xs);
    font-weight: 500;
}

.structure-status.status-ok {
    /* Not --success (#28A745): a distinct green paired with the rgba wash. */
    background: rgba(46, 204, 113, 0.15);
    color: #27ae60;
    border: 1px solid rgba(46, 204, 113, 0.3);
}

.structure-status.status-warning {
    background: var(--warning-bg);
    color: var(--warning-text);
    border: 1px solid rgba(var(--warning-rgb), 0.28);
}

.structure-status .status-icon {
    display: inline-flex;
}

.structure-status .status-icon .mi-icon {
    width: 13px;
    height: 13px;
}

/* Value warning highlight */
.info-row .value.value-warning {
    /* Not --danger (#DC3545): close but a distinct red, kept as-is. */
    color: #e74c3c;
    font-weight: 600;
}

/* ===================================
   Expanded View Mode (Double-click)
   =================================== */

.expand-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    opacity: 0;
    transition: opacity var(--transition-fast), background-color var(--transition-fast);
    cursor: pointer;
    z-index: 10;
}

.expand-btn .mi-icon {
    width: 14px;
    height: 14px;
}

/* Two sibling glyphs swapped by a class, so the JS never rewrites the button's
   contents. */
.expand-btn .icon-collapse {
    display: none;
}

.expand-btn.is-collapse .icon-expand {
    display: none;
}

.expand-btn.is-collapse .icon-collapse {
    display: block;
}

.canvas-container:hover .expand-btn {
    opacity: 0.8;
}

.expand-btn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.8);
}

/* The cursor names the active pointer mode where the eye is, the toolbar being
   far from the slice being read. setTool() writes data-tool on .viewer-main.

   The base rule below is deliberately WEAKER than the per-mode ones. Written
   `.view-panel:not(.panel-info) .canvas-container` it scored (0,3,0), exactly
   tying the mode rules, and the tie was broken by source order alone: moving or
   factorising it would have silently killed every mode cursor, with no test to
   notice. Dropping :not(.panel-info) is inert, that panel holds no canvas. */
.view-panel .canvas-container {
    cursor: default;
}

.viewer-main[data-tool="locate"] .canvas-container {
    cursor: crosshair;
}

.viewer-main[data-tool="pan"] .canvas-container {
    cursor: grab;
}

.viewer-main[data-tool="pan"] .canvas-container:active {
    cursor: grabbing;
}

.viewer-main[data-tool="zoom"] .canvas-container {
    cursor: ns-resize;
}

/* When a panel is expanded */
.viewer-main.has-expanded {
    display: block;
    position: relative;
}

.viewer-main.has-expanded .view-panel {
    display: none;
}

.viewer-main.has-expanded .view-panel.expanded {
    display: flex;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    border-radius: var(--radius-md);
    animation: expandIn 0.2s ease-out;
}

@keyframes expandIn {
    from {
        opacity: 0.8;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Close button for expanded view */
.view-panel.expanded .view-header {
    position: relative;
}

.view-panel.expanded .expand-close-btn {
    display: flex;
}

.expand-close-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color var(--transition-fast),
                border-color var(--transition-fast),
                color var(--transition-fast);
    margin-left: var(--space-xs);
    flex-shrink: 0;
}

.expand-close-btn .mi-icon {
    width: 14px;
    height: 14px;
}

.expand-close-btn:hover {
    background: var(--surface-raised);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

/* In expanded mode, button shows collapse icon */
.view-panel.expanded .expand-btn {
    opacity: 0.5;
}

.view-panel.expanded .canvas-container:hover .expand-btn {
    opacity: 0.8;
}

.view-panel.expanded .expand-btn:hover {
    opacity: 1;
}

/* Adjust canvas in expanded view for better sizing */
.view-panel.expanded .canvas-container {
    min-height: 0;
}

.view-panel.expanded .canvas-container canvas {
    max-width: 100%;
    max-height: 100%;
}

/* ===================================
   Fullscreen Mode
   =================================== */

.viewer-container.fullscreen-mode {
    height: 100vh;
    width: 100vw;
    padding: var(--space-sm);
    background: var(--bg-primary);
}

.viewer-container.fullscreen-mode .viewer-main {
    height: calc(100vh - 100px);
}

/* Hide unnecessary elements in fullscreen */
.viewer-container.fullscreen-mode .viewer-title .btn-ghost {
    display: none;
}

/* Larger panels in fullscreen */
.viewer-container.fullscreen-mode .view-panel {
    min-height: 0;
}

.viewer-container.fullscreen-mode .canvas-container {
    flex: 1;
}

/* Escape hint in fullscreen */
.viewer-container.fullscreen-mode::after {
    content: 'Echap ou F11 pour quitter';
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: var(--white);
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    opacity: 0;
    transition: opacity var(--transition-base);
    pointer-events: none;
}

.viewer-container.fullscreen-mode:hover::after {
    opacity: 0.8;
}
