﻿/*
 * ============================================================================
 *  RtfPage.css  — Component-scoped styles  (v3 — full improvement pass)
 *
 *  Changes vs v2:
 *  ✓ Tokens merged into one .rtf-one-page declaration (no duplicate selector)
 *  ✓ Font-size token scale  (--rtf-text-2xs … --rtf-text-lg)
 *  ✓ Surface + ink token scale  (replaces ~40 raw hex values)
 *  ✓ Z-index token stack  (--rtf-z-backdrop … --rtf-z-dialog)
 *  ✓ --rtf-slots-w token for fixed slot-panel width
 *  ✓ `contain: layout style` on every pane for paint isolation
 *  ✓ `transition: all` → explicit property lists everywhere
 *  ✓ `flex: 1 1 0` removed from gallery-scroll (was a grid child — no-op)
 *  ✓ Firefox scrollbar-width / scrollbar-color on all scroll containers
 *  ✓ scroll-padding-top on slot-scroll (keyboard focus no longer clips)
 *  ✓ focus-visible rings on ALL interactive elements
 *  ✓ @supports guard for backdrop-filter  (older Safari fallback)
 *  ✓ @supports guard for color-mix        (Safari < 16.2 fallback)
 *  ✓ 900 px breakpoint: grid-column / grid-row resets added (were missing)
 *  ✓ Dark-mode token layer  (prefers-color-scheme: dark)
 * ============================================================================
 */

/* ============================================================
   § 0 + § 1  DESIGN TOKENS  +  PAGE SHELL
   ============================================================ */

.rtf-one-page {
    /* ── Brand / accent — inherit from app-common.css tokens ── */
    --rtf-accent: var(--app-accent, #2a6b82);
    --rtf-accent-dark: var(--app-accent-dark, #1d4f60);
    --rtf-accent-soft: var(--app-accent-soft, #e6f3f7);
    --rtf-accent-glow: var(--app-accent-glow, rgba(42,107,130,.18));
    /* ── Surface scale — light mode defaults ── */
    --rtf-bg: var(--app-bg, #f0f4f7);
    --rtf-panel: var(--app-surface-solid, #ffffff);
    --rtf-surface-1: var(--app-surface-muted, #f4f7f8);
    --rtf-surface-2: var(--app-surface-strong, #e9f1f4);
    --rtf-surface-3: var(--app-border-strong, rgba(15,30,45,.18));
    --rtf-surface-4: #cbd5e1; /* scrollbar thumbs — fixed neutral */
    --rtf-surface-5: var(--app-text-muted, #8496a3);
    /* ── Ink (text) scale ── */
    --rtf-text: var(--app-text, #111d26);
    --rtf-ink-1: var(--app-text-darkest, #212529);
    --rtf-ink-2: var(--app-text-secondary, #4a5a68);
    --rtf-ink-3: var(--app-text-muted, #8496a3);
    --rtf-muted: var(--app-text-muted, #8496a3);
    /* ── Borders & shadows ── */
    --rtf-border: var(--app-border, rgba(15,30,45,.09));
    --rtf-border-soft: var(--app-border, rgba(15,30,45,.07));
    --rtf-shadow: var(--app-shadow-sm, 0 2px 8px rgba(15,30,45,.06));
    /* ── Radius scale ── */
    --rtf-radius: var(--app-radius-md, 12px);
    --rtf-radius-md: var(--app-radius-sm, 8px);
    --rtf-radius-sm: 6px;
    /* ── Font-size scale ── */
    --rtf-text-2xs: 0.64rem;  /* 10.2 px — overline labels    */
    --rtf-text-xs:  0.68rem;  /* 10.9 px — chips, badges      */
    --rtf-text-sm:  0.72rem;  /* 11.5 px — captions, hints    */
    --rtf-text-rg:  0.78rem;  /* 12.5 px — secondary body     */
    --rtf-text-md:  0.88rem;  /* 14.1 px — pane titles        */
    --rtf-text-lg:  0.95rem;  /* 15.2 px — dialog / h5 titles */
    /* ── Spacing (4-px / 0.25-rem grid) ── */
    --sp-1: 0.25rem; /*  4 px */
    --sp-2: 0.5rem;  /*  8 px */
    --sp-3: 0.75rem; /* 12 px */
    --sp-4: 1rem;    /* 16 px */
    /* ── Layout constants ── */
    --rtf-header-h: 56px;
    --rtf-slots-w: 300px;
    /* ── Z-index stack ── */
    --rtf-z-backdrop: 1200;
    --rtf-z-header:   1400;
    --rtf-z-anchor:   1501;
    --rtf-z-picker:   1502;
    --rtf-z-dialog:   9999;
    /* ── Image workbench ── */
    --img-selected-bg: var(--rtf-accent-soft);
    --img-selected-border: var(--rtf-accent);
    --img-hover-shadow: 0 4px 14px rgba(42,107,130,.18);
    --img-active-shadow: 0 0 0 3px var(--rtf-accent-glow);
    /* ── Medical image viewer bg (true black for clinical images) ── */
    --rtf-viewer-bg: #0d1117;
    /* ── Page shell ── */
    display: grid;
    grid-template-rows: var(--rtf-header-h) minmax(0, 1fr);
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    background: var(--rtf-bg);
    color: var(--rtf-text);
    font-family: var(--app-font-body, "Segoe UI", system-ui, sans-serif);
}

/* ── Dark-mode token overrides ──
   Responds to both Tabler's data-bs-theme="dark" and OS prefers-color-scheme.
   Per blazor-development skill: prefer --tblr-* vars for surface/text,
   use rgba() overlays so the accent still reads clearly on dark backgrounds.
── */
[data-bs-theme="dark"] .rtf-one-page {
    --rtf-bg: #0f172a;
    --rtf-panel: #1e293b;
    --rtf-surface-1: #1e293b;
    --rtf-surface-2: #263245;
    --rtf-surface-3: #334155;
    --rtf-surface-4: #475569;
    --rtf-surface-5: #64748b;
    --rtf-text: #f1f5f9;
    --rtf-ink-1: #f1f5f9;
    --rtf-ink-2: #cbd5e1;
    --rtf-ink-3: #94a3b8;
    --rtf-muted: #64748b;
    --rtf-border: rgba(255,255,255,.10);
    --rtf-border-soft: rgba(255,255,255,.06);
    --rtf-shadow: 0 1px 4px rgba(0,0,0,.35);
    --rtf-accent-soft: rgba(42,107,130,.18);
    --img-selected-bg: rgba(42,107,130,.15);
}

@media (prefers-color-scheme: dark) {
    .rtf-one-page {
        --rtf-bg: #0f172a;
        --rtf-panel: #1e293b;
        --rtf-surface-1: #1e293b;
        --rtf-surface-2: #263245;
        --rtf-surface-3: #334155;
        --rtf-surface-4: #475569;
        --rtf-surface-5: #64748b;
        --rtf-text: #f1f5f9;
        --rtf-ink-1: #f1f5f9;
        --rtf-ink-2: #cbd5e1;
        --rtf-ink-3: #94a3b8;
        --rtf-muted: #64748b;
        --rtf-border: rgba(255,255,255,.10);
        --rtf-border-soft: rgba(255,255,255,.06);
        --rtf-shadow: 0 1px 4px rgba(0,0,0,.35);
        --rtf-accent-soft: rgba(42,107,130,.18);
        --img-selected-bg: rgba(42,107,130,.15);
    }
}

/* ============================================================
   § 2  PATIENT CONTEXT HEADER
   ============================================================ */

.rtf-one-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    min-width: 0;
    overflow: visible;
    padding: 0.5rem var(--sp-4);
    background: linear-gradient(135deg, var(--rtf-accent-dark) 0%, var(--rtf-accent) 100%);
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.18);
    box-shadow: 0 2px 6px rgba(15,23,42,.12);
    z-index: var(--rtf-z-header);
}

.rtf-one-context {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    min-width: 0;
    flex: 1;
}

.rtf-one-context-item {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 80px;
    max-width: 230px;
    padding: 0.125rem var(--sp-2);
    border-left: 1px solid rgba(255,255,255,.22);
}

.rtf-one-context-item--strong {
    border-left: 0;
}

.rtf-one-context-item--wide {
    flex: 1;
    min-width: 180px;
    max-width: 460px;
}

.rtf-one-context-item--layout {
    flex: 0 0 clamp(240px, 20vw, 320px);
    min-width: 240px;
    max-width: 320px;
    padding: 0;
    border-left: 0;
}

.rtf-one-label {
    color: rgba(255,255,255,.72);
    font-size: var(--rtf-text-2xs);
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    line-height: 1;
}

.rtf-one-value {
    min-width: 0;
    overflow: hidden;
    color: #fff;
    font-size: 0.84rem;
    font-weight: 700;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rtf-one-header-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-shrink: 0;
}

/* Status badge */
.rtf-one-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
    font-size: var(--rtf-text-sm);
    font-weight: 800;
    border: 1px solid rgba(255,255,255,.28);
}

.rtf-one-status--approved {
    background: var(--app-success-bg, rgba(16,185,129,.22));
    color: var(--app-success-text, #166534);
    border-color: var(--app-success-border, rgba(255,255,255,.28));
}

.rtf-one-status--draft {
    background: rgba(255,255,255,.14);
}

.rtf-one-primary-action {
    min-width: 88px;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(0,0,0,.2);
}

/* ── Layout selector widget ── */
.rtf-one-layout-anchor {
    position: relative;
    width: 100%;
}

    .rtf-one-layout-anchor.is-open {
        z-index: var(--rtf-z-anchor);
    }

.rtf-one-layout-selector {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    height: 56px;
    min-height: 52px;
    padding: 0.375rem var(--sp-2);
    overflow: hidden;
    color: #fff;
    font: inherit;
    text-align: left;
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.38);
    border-radius: var(--rtf-radius-md);
    cursor: pointer;
    transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

    .rtf-one-layout-selector:hover,
    .rtf-one-layout-anchor.is-open .rtf-one-layout-selector {
        background: rgba(255,255,255,.2);
        border-color: rgba(255,255,255,.62);
        box-shadow: 0 0 0 2px rgba(255,255,255,.1);
    }

    .rtf-one-layout-selector:focus-visible {
        outline: none;
        box-shadow: 0 0 0 3px rgba(255,255,255,.5);
    }

.rtf-one-layout-preview-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 68px;
    height: 58px;
    overflow: hidden;
    /*background: rgba(255,255,255,.12);
    border: 1.5px solid rgba(255,255,255,.5);
    border-radius: var(--rtf-radius-sm);*/
    line-height: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,.25);
}

    .rtf-one-layout-preview-small img {
        width: 100%;
        height: 100%;
        display: block;
        object-fit: contain;
        object-position: center;
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }

.rtf-one-layout-placeholder {
    display: inline-flex;
    color: rgba(255,255,255,.86);
    font-size: var(--rtf-text-lg);
}

.rtf-one-layout-info-small {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
}

.rtf-one-layout-select-label {
    color: rgba(255,255,255,.76);
    font-size: var(--rtf-text-xs);
    font-weight: 800;
    letter-spacing: .06em;
    line-height: 1;
    text-transform: uppercase;
}

.rtf-one-layout-label-small {
    min-width: 0;
    overflow: hidden;
    color: #fff;
    font-size: var(--rtf-text-md);
    font-weight: 800;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rtf-one-layout-chevron {
    flex: 0 0 auto;
    color: rgba(255,255,255,.86);
    font-size: 0.82rem;
}

/* ── Layout picker dropdown ── */
.layout-picker-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--rtf-z-backdrop);
    padding: 0;
    background: transparent;
    border: 0;
    cursor: default;
}

/* Legacy / narrow variant */
.layout-picker-dropdown {
    position: absolute;
    top: calc(100% + var(--sp-2));
    left: 0;
    z-index: var(--rtf-z-picker);
    width: min(360px, calc(100vw - var(--sp-4)));
}

/* Full-width variant — stretches across entire header */
.layout-picker-dropdown--fullwidth {
    position: fixed;
    top: var(--rtf-header-h);
    left: 0;
    right: 0;
    z-index: var(--rtf-z-picker);
    width: 100%;
    padding: 0 var(--sp-4);
}

    .layout-picker-dropdown--fullwidth .layout-picker-dropdown-content {
        max-height: min(60vh, 400px);
        border-radius: 0 0 12px 12px;
    }

    .layout-picker-dropdown--fullwidth .layout-picker-list-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

.layout-picker-dropdown-content {
    max-height: min(64vh, 440px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--rtf-surface-4) var(--rtf-surface-1);
    padding: var(--sp-2);
    background: var(--rtf-panel);
    border: 1px solid rgba(15,23,42,.12);
    border-radius: var(--rtf-radius);
    box-shadow: 0 16px 40px rgba(15,23,42,.28);
}

.layout-picker-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
    gap: var(--sp-2);
}

.layout-picker-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
    padding: 0.25rem;
    text-align: left;
    background: var(--rtf-panel);
    border: 1px solid var(--rtf-border);
    border-radius: 7px;
    cursor: pointer;
    transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

    .layout-picker-item:hover {
        border-color: var(--rtf-accent);
        box-shadow: 0 6px 16px rgba(42,107,130,.18);
    }

    .layout-picker-item:focus-visible {
        outline: none;
        box-shadow: 0 0 0 3px var(--rtf-accent-glow);
    }

/* color-mix with @supports fallback */
.layout-picker-item--selected {
    border-color: var(--rtf-accent);
    background: var(--rtf-accent-soft); /* fallback */
}

@supports (background: color-mix(in srgb, white 95%, red)) {
    .layout-picker-item--selected {
        background: color-mix(in srgb, white 95%, var(--rtf-accent-soft));
    }
}

.layout-picker-item .rtf-one-layout-preview {
    width: 100%;
    height: 76px;
    object-fit: contain;
    background: var(--rtf-surface-1);
    border: 1px solid rgba(148,163,184,.28);
    border-radius: 7px;
}

.layout-picker-item .rtf-one-layout-preview--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    background-color: var(--rtf-surface-2);
}

    .layout-picker-item .rtf-one-layout-preview--empty span {
        width: 8px;
        height: 8px;
        border-radius: 999px;
        opacity: .5;
    }

.layout-picker-item .rtf-one-layout-name {
    display: block;
    color: var(--rtf-ink-3);
    font-size: var(--rtf-text-xs);
    font-weight: 700;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

/* ============================================================
   § 3  THREE-COLUMN COCKPIT GRID
   ============================================================ */

.rtf-one-grid {
    display: grid;
    grid-template-columns: minmax(160px, 15%) /* layout rail     */
    minmax(480px, 49%) /* RTE editor pane */
    minmax(420px, 36%); /* image workbench */
    gap: var(--sp-2);
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    padding: var(--sp-2);
}

.rtf-one-grid--no-layout {
    grid-template-columns: minmax(0, 57%) minmax(0, 43%);
    gap: var(--sp-2);
    padding: var(--sp-2);
}

/* Shared pane shell */
.rtf-one-pane {
    min-width: 0;
    min-height: 0;
    width: 100%;
    overflow: hidden;
    background: var(--rtf-panel);
    border: 1px solid var(--rtf-border);
    border-radius: var(--rtf-radius);
    box-shadow: var(--rtf-shadow);
    contain: layout style; /* paint-isolation: prevents sibling repaints */
}

/* Pane header — 38px */
.rtf-one-pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    min-height: 38px;
    padding: 0.25rem var(--sp-2);
    background: var(--rtf-panel);
    border-bottom: 1px solid var(--rtf-border-soft);
    flex-shrink: 0;
}

.rtf-one-pane-title {
    color: var(--rtf-ink-1);
    font-size: var(--rtf-text-md);
    font-weight: 800;
    line-height: 1.15;
}

.rtf-one-pane-subtitle {
    color: var(--rtf-muted);
    font-size: 0.69rem;
    font-weight: 600;
}

/* Count pill */
.rtf-one-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 var(--sp-1);
    border-radius: 999px;
    background: var(--rtf-accent-soft);
    color: var(--rtf-accent-dark);
    font-size: var(--rtf-text-sm);
    font-weight: 900;
}

/* ============================================================
   § 4  LEFT PANE — LAYOUT / TEMPLATE RAIL
   ============================================================ */

.rtf-one-layout-pane {
    display: grid;
    grid-template-rows: auto minmax(0,1fr) auto;
    background: var(--rtf-panel);
}

.rtf-one-template-list {
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--rtf-surface-4) var(--rtf-surface-1);
    padding: var(--sp-2);
}

/* Template card */
.rtf-one-layout-card {
    display: grid;
    grid-template-columns: 52px minmax(0,1fr);
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    min-height: 72px;
    margin: 0 0 var(--sp-2);
    padding: 0.375rem;
    color: inherit;
    text-align: left;
    background: var(--rtf-panel);
    border: 1.5px solid var(--rtf-surface-3);
    border-radius: var(--rtf-radius-md);
    cursor: pointer;
    transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease, transform 150ms ease;
}

    .rtf-one-layout-card:hover {
        border-color: var(--rtf-accent);
        background: var(--rtf-accent-soft);
        box-shadow: 0 0 0 2px var(--rtf-accent-glow), 0 4px 12px rgba(15,95,118,.1);
        transform: translateY(-1px);
    }

@supports (background: color-mix(in srgb, white 96%, red)) {
    .rtf-one-layout-card:hover {
        background: color-mix(in srgb, var(--rtf-panel) 96%, var(--rtf-accent));
    }
}

.rtf-one-layout-card--selected {
    border-color: var(--rtf-accent);
    background: var(--rtf-accent-soft);
    box-shadow: 0 0 0 2px var(--rtf-accent-glow);
}

@supports (background: color-mix(in srgb, white 93%, red)) {
    .rtf-one-layout-card--selected {
        background: color-mix(in srgb, var(--rtf-panel) 93%, var(--rtf-accent));
    }
}

/* Focus rings — all interactive elements */
.rtf-one-layout-card:focus-visible,
.rtf-one-layout-selector:focus-visible,
.rtf-one-action:focus-visible,
.rtf-one-slot-card:focus-visible,
.rtf-one-gallery-card:focus-visible,
.layout-picker-item:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--rtf-accent-glow);
}

/* Thumbnail */
.rtf-one-layout-preview {
    width: 52px;
    height: 66px;
    object-fit: contain;
    border: 1px solid var(--rtf-surface-3);
    border-radius: 5px;
    background: var(--rtf-surface-1);
}

.rtf-one-layout-preview--empty {
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
    align-items: stretch;
    justify-content: center;
    padding: var(--sp-2);
}

    .rtf-one-layout-preview--empty span {
        height: 3px;
        background: var(--rtf-surface-4);
        border-radius: 2px;
    }

.rtf-one-layout-name {
    font-size: var(--rtf-text-sm);
    font-weight: 700;
    line-height: 1.3;
    color: var(--rtf-ink-2);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ============================================================
   § 5  CENTER PANE — RTE EDITOR
   ============================================================ */

.rtf-one-editor-pane {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.rtf-one-editor-header {
    padding-bottom: 0;
}

.rtf-one-clinical-state {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
}

.rtf-one-status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    height: 24px;
    padding: 0 var(--sp-2);
    border-radius: 999px;
    font-size: var(--rtf-text-xs);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.rtf-one-status-chip--editable {
    background: var(--app-success-bg, rgba(16,185,129,.15));
    color: var(--app-success-text, #166534);
}

.rtf-one-status-chip--readonly {
    background: var(--app-surface-strong, rgba(148,163,184,.15));
    color: var(--rtf-muted);
}

/* Clinical inputs — 2-row grid, template dominates row 2 */
/*.rtf-one-clinical-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.4fr);
    grid-template-rows: 1fr 1fr;*/ /* equal-height rows */
    /*align-items: end;*/ /* anchor inputs to bottom so float labels rise uniformly */
    /*gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3) var(--sp-3);
    background: var(--rtf-panel);
    border-bottom: 1px solid var(--rtf-border-soft);
    flex-shrink: 0;
}*/
.rtf-one-clinical-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-end; /* float labels sit above, inputs align at bottom */
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3) var(--sp-3);
    background: var(--rtf-panel);
    border-bottom: 1px solid var(--rtf-border-soft);
    flex-shrink: 0;
}

.rtf-one-clinical-field--procedure {
    flex: 1 1 120px;
    min-width: 0;
}

.rtf-one-clinical-field--impression {
    flex: 2 1 180px;
    min-width: 0;
}

.rtf-one-clinical-field--instrument {
    flex: 1 1 120px;
    min-width: 0;
}

.rtf-one-clinical-field--template {
    flex: 2 1 180px;
    min-width: 0;
}

.rtf-one-clinical-field--upload {
    flex: 0 0 auto;
    align-self: flex-end;
}

.rtf-one-clinical-field {
    min-width: 0;
}

/* Row 1 */
/*.rtf-one-clinical-field--procedure {
    grid-column: 1;
    grid-row: 1;
}

.rtf-one-clinical-field--impression {
    grid-column: 2 / 4;
    grid-row: 1;
}

.rtf-one-clinical-field--instrument {
    grid-column: 4;
    grid-row: 1;
}*/
/* Row 2 — template nearly full-width */
/*.rtf-one-clinical-field--template {
    grid-column: 1 / 4;
    grid-row: 2;
}

.rtf-one-clinical-field--upload {
    grid-column: 4;
    grid-row: 2;
}*/

/* RTE frame */
.rtf-one-editor-frame {
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin: var(--sp-2);
    overflow: hidden;
    background: var(--rtf-panel);
    border: 1px solid var(--rtf-border-soft);
    border-radius: var(--rtf-radius-md);
}

    .rtf-one-editor-frame .e-richtexteditor,
    .rtf-one-editor-frame .rtf-one-rte {
        flex: 1 1 auto;
        min-height: 0 !important;
        height: 100% !important;
    }

    .rtf-one-editor-frame .e-rte-toolbar,
    .rtf-one-editor-frame .e-toolbar-wrapper {
        flex: 0 0 auto;
    }

    .rtf-one-editor-frame .e-rte-content {
        flex: 1 1 auto;
        min-height: 0 !important;
    }

        .rtf-one-editor-frame .e-rte-content iframe,
        .rtf-one-editor-frame .e-rte-content .e-content {
            min-height: 0 !important;
            height: 100% !important;
        }

.e-float-text.e-label-top {
    color: var(--rtf-text) !important;
}
/* ============================================================
   § 5B  PROCEDURE BAR  (image pane)
   ============================================================ */
.rtf-one-procedure-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
    min-height: 28px;
    padding: 0.15rem var(--sp-2);
    background: linear-gradient(to bottom, var(--rtf-surface-1) 0%, var(--rtf-surface-2) 100%);
    border-bottom: 1px solid var(--rtf-border-soft);
    flex-shrink: 0;
}

.rtf-one-procedure-readonly {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    min-width: 0;
    max-width: 55%;
    overflow: hidden;
    font-size: var(--rtf-text-sm);
    color: var(--rtf-ink-3);
    font-weight: 600;
}

    .rtf-one-procedure-readonly strong {
        color: var(--rtf-ink-1);
        font-weight: 800;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

.rtf-one-badges {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-shrink: 0;
}

.rtf-one-badge {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 var(--sp-2);
    border-radius: 999px;
    font-size: var(--rtf-text-xs);
    font-weight: 800;
    white-space: nowrap;
}

.rtf-one-badge--captured {
    background: var(--app-info-bg, rgba(99,102,241,.12));
    color: var(--app-info-text, #0f5fa8);
}

.rtf-one-badge--available {
    background: var(--app-warn-bg, rgba(245,158,11,.12));
    color: var(--app-warn-text, #a15c07);
}

.rtf-one-badge--selected {
    background: var(--app-success-bg, rgba(16,185,129,.15));
    color: var(--app-success-text, #166534);
}

/* ============================================================
   § 6  RIGHT PANE — IMAGE WORKBENCH
   ============================================================ */

.rtf-one-image-pane {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--rtf-panel);
}

.rtf-one-image-header {
    padding-bottom: 0;
}

.rtf-one-image-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.rtf-one-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid var(--rtf-surface-3);
    border-radius: var(--rtf-radius-sm);
    background: var(--rtf-panel);
    color: var(--rtf-ink-2);
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

    .rtf-one-action:hover:not(:disabled) {
        border-color: var(--rtf-accent);
        background: var(--rtf-accent-soft);
        color: var(--rtf-accent-dark);
    }

    .rtf-one-action:disabled {
        opacity: .4;
        cursor: not-allowed;
    }

    .rtf-one-action i {
        font-size: 1rem;
    }

/* Workbench body */
.rtf-one-image-workbench {
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
    min-height: 0;
    overflow: hidden;
}

.rtf-one-image-workbench--with-bbps {
    grid-template-rows: minmax(0, 1fr) auto;
}

.rtf-one-image-workbench > .image-selection-panel.rtf-one-images-grid {
    width: 100% !important;
    max-width: none !important;
    min-width: 0;
    min-height: 0;
    height: 100%;
}

/* BBPS collapsible panel */
.rtf-one-bbps-panel {
    background: var(--rtf-panel);
    border-top: 1px solid var(--rtf-border-soft);
}

    .rtf-one-bbps-panel summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: var(--sp-2) var(--sp-3);
        font-size: var(--rtf-text-rg);
        font-weight: 800;
        color: var(--rtf-ink-1);
        cursor: pointer;
        list-style: none;
        transition: background 120ms ease;
    }

        .rtf-one-bbps-panel summary:hover {
            background: var(--rtf-surface-1);
        }

        .rtf-one-bbps-panel summary span {
            display: flex;
            align-items: center;
        }

        .rtf-one-bbps-panel summary small {
            color: var(--rtf-muted);
            font-weight: 600;
            font-size: var(--rtf-text-sm);
        }

.rtf-one-bbps-body {
    padding: 0 var(--sp-3) var(--sp-3);
    border-top: 1px solid var(--rtf-border-soft);
}

/* ============================================================
   § 7  IMAGE SELECTION PANEL  (v4 — image-first, clean, on-brand)
   ============================================================ */

/* ── Layout: gallery left | slots right ── */
.rtf-one-images-grid {
    display: grid;
    grid-template-columns: 1fr var(--rtf-slots-w);
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    background: var(--rtf-surface-1);
}

.rtf-one-image-section {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

/* Gallery column — neutral light bg */
.rtf-one-gallery-section {
    background: var(--rtf-surface-1);
    border-right: 1px solid var(--rtf-border);
}

/* Slots column — very subtle accent tint to signal "destination" */
.rtf-one-selected-section {
    background: var(--rtf-panel);
    border-left: 1px solid var(--rtf-border);
}

/* ── All-assigned state (gallery collapses) ── */
.rtf-one-image-workbench--all-assigned .rtf-one-images-grid {
    grid-template-columns: minmax(180px, 22%) minmax(0, 1fr);
}

.rtf-one-image-workbench--all-assigned .rtf-one-gallery-section {
    background: var(--rtf-surface-1);
}

.rtf-one-image-workbench--all-assigned .rtf-one-gallery-scroll {
    grid-template-columns: 1fr;
    align-content: center;
    justify-items: center;
}

    .rtf-one-image-workbench--all-assigned .rtf-one-gallery-scroll::before {
        content: "All images assigned";
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 80px;
        width: min(100%, 220px);
        padding: var(--sp-3);
        color: var(--rtf-muted);
        font-size: var(--rtf-text-sm);
        font-weight: 700;
        text-align: center;
        background: var(--rtf-panel);
        border: 1px dashed var(--rtf-border);
        border-radius: var(--rtf-radius-md);
    }

.rtf-one-image-workbench--all-assigned .rtf-one-slot-scroll {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    align-content: start;
}

/* ── Section headers ── */
.rtf-one-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
    padding: 0.375rem var(--sp-3);
    background: var(--rtf-panel);
    border-bottom: 1px solid var(--rtf-border);
    flex-shrink: 0;
}

    .rtf-one-section-header span {
        font-size: var(--rtf-text-sm);
        font-weight: 700;
        color: var(--rtf-ink-2);
        text-transform: uppercase;
        letter-spacing: .05em;
    }

    .rtf-one-section-header strong {
        font-size: var(--rtf-text-rg);
        font-weight: 800;
        color: var(--rtf-text);
    }

.rtf-one-section-sep {
    margin: 0 0.2rem;
    color: var(--rtf-surface-5);
    font-weight: 500;
}

/* ── Available images grid ── */
.rtf-one-gallery-scroll {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    align-content: start;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--rtf-surface-4) transparent;
    gap: var(--sp-1);
    padding: var(--sp-1) var(--sp-2) var(--sp-2);
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

    .rtf-one-gallery-scroll::-webkit-scrollbar {
        width: 6px;
    }

    .rtf-one-gallery-scroll::-webkit-scrollbar-track {
        background: transparent;
    }

    .rtf-one-gallery-scroll::-webkit-scrollbar-thumb {
        background: var(--rtf-surface-4);
        border-radius: 3px;
    }

        .rtf-one-gallery-scroll::-webkit-scrollbar-thumb:hover {
            background: var(--rtf-surface-5);
        }

/* Drop hint — full-width banner at top of gallery */
.rtf-one-gallery-drop-hint {
    grid-column: 1 / -1;
    padding: var(--sp-1) var(--sp-2);
    text-align: center;
    font-size: var(--rtf-text-sm);
    font-weight: 600;
    color: var(--rtf-muted);
    background: rgba(42,107,130,.04);
    border: 1px dashed var(--rtf-border);
    border-radius: var(--rtf-radius-sm);
    margin-bottom: var(--sp-1);
}

/* ── Available image card ──
   2px pad, 4:3 ratio cuts the black space CT images leave in 1:1 squares.
   Label is a tight strip below.
── */
.rtf-one-gallery-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 2px;
    background: var(--rtf-viewer-bg, #0d1117);
    border: 1.5px solid var(--rtf-surface-3);
    border-radius: var(--rtf-radius-sm);
    cursor: pointer;
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

    .rtf-one-gallery-card:hover {
        border-color: var(--rtf-accent);
        box-shadow: 0 0 0 2px var(--rtf-accent-glow), var(--img-hover-shadow);
        transform: translateY(-1px);
        z-index: 1;
    }

.rtf-one-gallery-card--previewing {
    border-color: var(--img-selected-border);
    box-shadow: 0 0 0 3px var(--rtf-accent-glow);
}

/* Drag handle — fades in on hover */
.rtf-one-gallery-drag-handle {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: rgba(0,0,0,.6);
    border-radius: 3px;
    color: rgba(255,255,255,.85);
    font-size: .75rem;
    opacity: 0;
    transition: opacity 120ms ease;
    z-index: 2;
    cursor: grab;
}

.rtf-one-gallery-card:hover .rtf-one-gallery-drag-handle,
.rtf-one-gallery-card:active .rtf-one-gallery-drag-handle {
    opacity: 1;
}

/* Thumbnail — cover fills the frame cleanly, no letterbox bars */
.rtf-one-gallery-img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    object-position: center;
    display: block;
    background: var(--rtf-viewer-bg, #0d1117);
    border-radius: 1px;
}

/* Label — tight single-line strip */
.rtf-one-gallery-label {
    padding: 0.15rem var(--sp-1);
    font-size: var(--rtf-text-2xs);
    font-weight: 600;
    color: var(--rtf-ink-3);
    text-align: center;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: var(--rtf-surface-2);
    border-top: 1px solid var(--rtf-border);
}

/* ── Fixed slots column ── */
.rtf-one-slot-scroll {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--rtf-surface-4) transparent;
    padding: var(--sp-2);
    scroll-behavior: smooth;
    scroll-padding-top: var(--sp-2);
}

    .rtf-one-slot-scroll::-webkit-scrollbar {
        width: 6px;
    }

    .rtf-one-slot-scroll::-webkit-scrollbar-track {
        background: transparent;
    }

    .rtf-one-slot-scroll::-webkit-scrollbar-thumb {
        background: var(--rtf-surface-4);
        border-radius: 3px;
    }

        .rtf-one-slot-scroll::-webkit-scrollbar-thumb:hover {
            background: var(--rtf-surface-5);
        }

/* ── Slot card ──
   flex column: thumb-wrap → meta row → comment combobox, all visible.
   Single outer border, no inner borders.
   NOTE: overflow must NOT be hidden here — comment div sits outside thumb-wrap.
── */
.rtf-one-slot-card {
    position: relative;
    display: flex;
    flex-direction: column;
    border: 1.5px solid var(--rtf-border);
    border-radius: var(--rtf-radius-sm);
    cursor: pointer;
    background: var(--rtf-panel);
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

    .rtf-one-slot-card:hover {
        border-color: var(--rtf-accent);
        box-shadow: 0 0 0 2px var(--rtf-accent-glow);
    }

.rtf-one-slot-card--active {
    border-color: var(--rtf-accent);
    box-shadow: 0 0 0 3px var(--rtf-accent-glow);
}

/* Thumb wrap — 3:2 ratio, more compact than 4:3, image still fully visible */
.rtf-one-slot-thumb-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 2;
    overflow: hidden;
    background: var(--rtf-viewer-bg, #0d1117);
    flex-shrink: 0;
}

.rtf-one-slot-thumb {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    background: var(--rtf-viewer-bg, #0d1117);
    display: block;
}

/* Drag handle — slot */
.rtf-one-slot-drag-handle {
    position: absolute;
    top: var(--sp-1);
    left: var(--sp-1);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: rgba(0,0,0,.55);
    border-radius: 4px;
    color: rgba(255,255,255,.85);
    font-size: .9rem;
    opacity: 0;
    transition: opacity 120ms ease;
    z-index: 3;
    cursor: grab;
}

.rtf-one-slot-card:hover .rtf-one-slot-drag-handle {
    opacity: 1;
}

/* Remove button */
.rtf-one-slot-remove {
    position: absolute;
    top: var(--sp-1);
    right: var(--sp-1);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: rgba(220,38,38,.88);
    border: none;
    border-radius: 4px;
    color: #fff;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 120ms ease, transform 120ms ease, background 120ms ease;
    z-index: 3;
}

.rtf-one-slot-card:hover .rtf-one-slot-remove {
    opacity: 1;
}

.rtf-one-slot-remove:hover {
    background: #dc2626;
    transform: scale(1.08);
}

/* Slot footer bar — compact: label left, reorder hint right */
.rtf-one-slot-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-1);
    padding: 0.2rem var(--sp-2) 0.15rem;
    background: var(--rtf-panel);
    border-top: 1px solid var(--rtf-border);
}

.rtf-one-slot-label {
    font-size: var(--rtf-text-2xs);
    font-weight: 700;
    color: var(--rtf-accent-dark);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rtf-one-drag-hint {
    font-size: var(--rtf-text-2xs);
    color: var(--rtf-muted);
    font-weight: 600;
    flex-shrink: 0;
}

/* Comment combobox — compact padding */
.rtf-one-slot-comment {
    padding: 0.2rem var(--sp-2) var(--sp-1);
    background: var(--rtf-panel);
    border-top: 1px solid var(--rtf-border);
}

/* ── Empty slot ── */
.rtf-one-slot-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    aspect-ratio: 3 / 2;
    padding: var(--sp-2);
    color: var(--rtf-surface-5);
    text-align: center;
    border: 1.5px dashed var(--rtf-surface-4);
    border-radius: var(--rtf-radius-sm);
    background: var(--rtf-surface-1);
    transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
}

.rtf-one-slot-card:hover .rtf-one-slot-empty {
    border-color: var(--rtf-accent);
    color: var(--rtf-accent);
    background: var(--rtf-accent-soft);
}

.rtf-one-slot-empty i {
    font-size: 1.5rem;
}

.rtf-one-slot-empty .slot-label {
    font-size: var(--rtf-text-sm);
    font-weight: 700;
    display: block;
}

/* ============================================================
   § 8  IMAGE EDITOR DIALOG
   ============================================================ */

.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.85); /* fallback — no backdrop-filter */
    z-index: var(--rtf-z-dialog);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
    animation: fadeIn 200ms ease;
}

@supports (backdrop-filter: blur(4px)) {
    .dialog-overlay {
        background: rgba(15,23,42,.75);
        backdrop-filter: blur(4px);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.dialog-box {
    position: relative;
    width: 100%;
    max-width: 92vw;
    max-height: 92vh;
    overflow: hidden;
    background: var(--rtf-panel);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(15,23,42,.4);
    display: flex;
    flex-direction: column;
    animation: slideUp 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.rtf-one-dialog-box {
    max-width: 1400px;
}

.dialog-header {
    padding: var(--sp-3) var(--sp-4);
    background: linear-gradient(135deg, var(--rtf-accent-dark) 0%, var(--rtf-accent) 100%);
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.15);
    flex-shrink: 0;
}

    .dialog-header h5 {
        font-size: var(--rtf-text-lg);
        font-weight: 800;
        margin: 0;
    }

.rtf-one-image-editor-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 260px);
    min-height: 0;
    height: min(720px, calc(92vh - 60px));
    overflow: hidden;
    background: var(--rtf-panel);
}

.rtf-one-image-editor-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: var(--sp-3);
    border-right: 1px solid var(--rtf-border-soft);
}

    .rtf-one-image-editor-main .image-editor-shell {
        flex: 1 1 auto;
        min-height: 0;
        width: 100% !important;
        max-width: none !important;
        height: auto;
        overflow: hidden;
        padding: 0;
    }

.rtf-one-image-editor-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex: 0 0 auto;
    padding-top: var(--sp-3);
}

.rtf-one-editor-readonly-note {
    color: var(--rtf-muted);
    font-size: var(--rtf-text-rg);
    font-weight: 700;
}

/* ============================================================
   § 9  GRAPHICAL ANNOTATION POPUP
   ============================================================ */

.rtf-graphical-dialog {
    max-width: 1200px;
}

.ar-graphical-dialog-body {
    min-height: 0;
    overflow: auto;
    padding: var(--sp-4);
}

/* ============================================================
   § 10  FORM VALIDATION
   ============================================================ */

.invalid-tooltips {
    color: var(--app-danger-text, #b42318);
    font-size: var(--rtf-text-rg);
    font-weight: 600;
    margin-top: var(--sp-1);
    display: block;
}

/* ============================================================
   § 11  FINDINGS & ANNOTATIONS
   ============================================================ */

.rtf-one-findings-panel {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    min-width: 0;
    min-height: 0;
    padding: var(--sp-3);
    background: var(--rtf-surface-1);
}

.rtf-one-findings-title {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--rtf-ink-2);
}

.rtf-one-findings-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--rtf-surface-4) var(--rtf-surface-1);
}

.rtf-one-empty-state {
    display: grid;
    place-items: center;
    gap: 0.375rem;
    min-height: 140px;
    color: var(--rtf-surface-5);
    font-size: var(--rtf-text-rg);
    font-weight: 700;
    text-align: center;
}

    .rtf-one-empty-state i {
        font-size: 1.375rem;
    }

.rtf-one-finding-chip {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    border: 1px solid var(--rtf-border);
    border-radius: var(--rtf-radius-md);
    background: var(--rtf-panel);
    color: var(--rtf-ink-2);
    font-size: var(--rtf-text-sm);
    font-weight: 700;
    text-align: left;
    padding: 0.375rem var(--sp-2);
    cursor: grab;
    transition: border-color 120ms ease, color 120ms ease;
}

    .rtf-one-finding-chip:active {
        cursor: grabbing;
    }

    .rtf-one-finding-chip:hover {
        border-color: var(--rtf-accent);
        color: var(--rtf-accent-dark);
    }

/* Annotation panel */
.rtf-annotation-panel {
    width: 100%;
    padding: var(--sp-3);
    background: var(--rtf-panel);
}

.rtf-annotation-toolbar {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-bottom: var(--sp-3);
}

.rtf-annotation-title {
    font-size: .9rem;
    font-weight: 800;
    color: var(--rtf-ink-1);
    line-height: 1.1;
}

.rtf-annotation-subtitle {
    font-size: var(--rtf-text-sm);
    color: var(--rtf-muted);
}

.rtf-annotation-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    height: 1.75rem;
    border-radius: 999px;
    background: var(--rtf-accent-soft);
    color: var(--rtf-accent-dark);
    font-weight: 900;
    font-size: var(--rtf-text-rg);
}

.rtf-annotation-chip-row {
    display: flex;
    gap: 0.375rem;
    flex-wrap: wrap;
    margin-bottom: var(--sp-3);
    max-height: 72px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--rtf-surface-4) transparent;
}

.rtf-annotation-chip {
    border: 1px solid var(--rtf-border);
    border-radius: 999px;
    background: var(--rtf-surface-1);
    color: var(--rtf-ink-3);
    padding: 0.25rem var(--sp-2);
    font-size: var(--rtf-text-sm);
    font-weight: 700;
    line-height: 1.2;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

    .rtf-annotation-chip:not(:disabled):hover {
        background: var(--rtf-accent);
        border-color: var(--rtf-accent);
        color: #fff;
    }

.rtf-annotation-stage {
    min-height: 330px;
    border-radius: var(--rtf-radius);
    border: 1px solid var(--rtf-border-soft);
    background: radial-gradient(circle at top, var(--rtf-surface-1) 0%, var(--rtf-panel) 100%);
}

.rtf-annotation-image {
    width: min(100%, 360px);
    height: 330px;
    object-fit: contain;
}

.rtf-annotation-empty {
    display: grid;
    place-items: center;
    gap: 0.375rem;
    min-height: 280px;
    color: var(--rtf-surface-5);
    font-weight: 700;
}

.rtf-annotation-tag {
    border-width: 1px;
    padding: 0.25rem var(--sp-2);
    font-size: var(--rtf-text-sm);
}

.rtf-annotation-selector {
    margin-top: var(--sp-3);
}

/* BBPS child component */
.rtf-bbps-panel {
    padding: var(--sp-3);
}

.rtf-bbps-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-2);
    margin-bottom: var(--sp-2);
}

.rtf-bbps-summary-item {
    border: 1px solid var(--rtf-border);
    border-radius: var(--rtf-radius-md);
    padding: 0.375rem var(--sp-2);
    background: var(--rtf-panel);
}

.rtf-bbps-summary-label {
    display: block;
    font-size: var(--rtf-text-xs);
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--rtf-muted);
    font-weight: 700;
}

.rtf-bbps-summary-value {
    font-size: var(--rtf-text-md);
    color: var(--rtf-ink-1);
}

.rtf-bbps-reference {
    height: 28vh;
    margin-bottom: var(--sp-2);
}

.rtf-bbps-score-table th,
.rtf-bbps-score-table td {
    font-size: var(--rtf-text-sm);
    padding: 6px;
}

.rtf-bbps-description p {
    margin-bottom: 0.25rem;
    font-size: var(--rtf-text-sm) !important;
}

.rtf-bbps-result {
    margin-top: 0.5rem;
    font-size: .9rem;
}

/* Viewer header */
.rtf-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    width: 100%;
}

.rtf-viewer-title-block {
    min-width: 0;
}

.rtf-viewer-title {
    display: block;
    font-size: var(--rtf-text-lg);
    font-weight: 800;
    color: var(--rtf-text);
    line-height: 1.1;
}

.rtf-viewer-report-name {
    display: block;
    max-width: 62vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--rtf-text-sm);
    color: var(--rtf-muted);
    font-weight: 700;
}

.rtf-viewer-user {
    font-size: var(--rtf-text-rg);
    font-weight: 700;
    color: var(--rtf-accent-dark);
    flex-shrink: 0;
}

/* ============================================================
   § 12  LOADING OVERLAY
   ============================================================ */

.ar-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--rtf-z-dialog);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15,23,42,.6);
}

/* ============================================================
   § 13  RESPONSIVE BREAKPOINTS
   ============================================================ */

@media (max-width: 1400px) {
    .rtf-one-grid--no-layout {
        grid-template-columns: minmax(0, 52%) minmax(0, 48%);
    }

    /*.rtf-one-clinical-row {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        grid-template-rows: 1fr 1fr;*/ /* ← was: auto auto */
        /*align-items: end;*/ /* ← add this */
    /*}

    .rtf-one-clinical-field--procedure {
        grid-column: 1 / 2;
        grid-row: 1;
    }

    .rtf-one-clinical-field--impression {
        grid-column: 2 / 4;
        grid-row: 1;
    }

    .rtf-one-clinical-field--instrument {
        grid-column: 4 / 5;
        grid-row: 1;
    }

    .rtf-one-clinical-field--template {
        grid-column: 1 / 4;
        grid-row: 2;
    }

    .rtf-one-clinical-field--upload {
        grid-column: 4 / 5;
        grid-row: 2;
    }*/

    .rtf-one-images-grid {
        grid-template-columns: 1fr 300px;
    }
}

@media (max-width: 1200px) {
    /* Slot panel stacks below gallery on narrower viewport */
    .rtf-one-images-grid {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(250px, 50%) minmax(250px, 50%);
    }

    .rtf-one-gallery-section {
        border-right: none;
        border-bottom: 2px solid var(--rtf-border);
    }

    .rtf-one-selected-section {
        border-left: none;
        border-top: 1px solid var(--rtf-border);
    }

    /* 2-col slot grid when stacked */
    .rtf-one-slot-scroll {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-content: start;
        gap: var(--sp-2);
    }
}

@media (max-width: 1100px) {
    .rtf-one-page {
        grid-template-rows: auto minmax(0, 1fr);
        --rtf-header-h: auto;
        overflow-y: auto; /* allow full page scroll when stacked */
    }

    .rtf-one-header {
        flex-wrap: wrap;
    }

    .rtf-one-grid--no-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto; /* let each pane size to content */
        overflow-y: auto;
        height: auto;
        min-height: 0;
    }

    /* Editor pane: give it a reasonable min-height when stacked */
    .rtf-one-editor-pane {
        min-height: 420px;
        height: 55vh;
    }

    /* Image pane: enough room to see gallery + slots */
    .rtf-one-image-pane {
        min-height: 500px;
        height: 70vh;
    }

    .rtf-one-context-item--layout {
        flex-basis: min(100%, 260px);
    }

    /*.rtf-one-clinical-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: 1fr 1fr 1fr;*/ /* ← was: auto auto auto */
        /*align-items: end;*/ /* ← add this */
    /*}

    .rtf-one-clinical-field--procedure {
        grid-column: 1;
        grid-row: 1;
    }

    .rtf-one-clinical-field--impression {
        grid-column: 2;
        grid-row: 1;
    }

    .rtf-one-clinical-field--instrument {
        grid-column: 1;
        grid-row: 2;
    }

    .rtf-one-clinical-field--upload {
        grid-column: 2;
        grid-row: 2;
    }

    .rtf-one-clinical-field--template {
        grid-column: 1 / 3;
        grid-row: 3;
    }*/
    .rtf-one-clinical-row {
        flex-wrap: wrap;
    }

    .rtf-one-clinical-field--procedure,
    .rtf-one-clinical-field--instrument {
        flex: 1 1 140px;
    }

    .rtf-one-clinical-field--impression {
        flex: 1 1 200px;
    }

    .rtf-one-clinical-field--template {
        flex: 1 1 200px;
    }
    .rtf-one-procedure-readonly {
        max-width: 100%;
    }

    .rtf-one-findings-panel {
        max-height: 220px;
        border-top: 1px solid var(--rtf-border-soft);
    }
}

@media (max-width: 900px) {
    .rtf-one-gallery-scroll {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }

    /* CRITICAL: reset ALL explicit placements from 1100px back to natural flow.
       Without these resets, fields are misplaced at 900px. */
    /*.rtf-one-clinical-row {
        grid-template-columns: 1fr;
        grid-template-rows: auto;*/ /* single column, auto is fine here */
        /*align-items: end;*/ /* ← still helps with multiline Impression field */
    /*}

    .rtf-one-clinical-field--procedure,
    .rtf-one-clinical-field--impression,
    .rtf-one-clinical-field--instrument,
    .rtf-one-clinical-field--template,
    .rtf-one-clinical-field--upload {
        grid-column: 1;
        grid-row: auto;
    }*/
    .rtf-one-clinical-field--procedure,
    .rtf-one-clinical-field--impression,
    .rtf-one-clinical-field--instrument,
    .rtf-one-clinical-field--template {
        flex: 1 1 100%;
    }
    /* Slot grid: single column at small sizes */
    .rtf-one-slot-scroll {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .rtf-one-header {
        gap: var(--sp-2);
        padding: 0.375rem var(--sp-3);
    }

    .rtf-one-context {
        flex-wrap: wrap;
        gap: var(--sp-2);
    }

    .rtf-one-context-item--layout {
        flex: 1 1 100%;
        max-width: none;
    }

    .layout-picker-dropdown {
        width: calc(100vw - var(--sp-4));
    }

    .rtf-one-grid--no-layout {
        padding: var(--sp-2);
        gap: var(--sp-2);
    }

    .rtf-one-gallery-scroll {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}

/* ============================================================
   § 14  ACCESSIBILITY & KEYBOARD NAV
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-contrast: high) {
    .rtf-one-gallery-card,
    .rtf-one-slot-card {
        border-width: 3px;
    }

    .rtf-one-action {
        border-width: 2px;
    }
}

/* ============================================================
   § 15  PRINT
   ============================================================ */

@media print {
    .rtf-one-header,
    .rtf-one-layout-pane,
    .rtf-one-image-actions,
    .rtf-one-action,
    .dialog-overlay {
        display: none !important;
    }
}

.upload-button-wrapper {
    flex: 0 0 auto;
}

.upload-btn {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    height: 2rem;
    font-weight: 500;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease-in-out;
}

    .upload-btn:hover {
        background: linear-gradient(135deg, #0062cc, #004999);
        transform: translateY(-1px);
        box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
    }
    .upload-btn.is-disabled {
        opacity: 0.45;
        pointer-events: none;
        cursor: not-allowed;
        color: var(--sf-content-color-disabled, #9e9e9e);
        border-color: var(--sf-border-color-disabled, #e0e0e0);
        background-color: var(--sf-background-disabled, #f5f5f5);
    }
.rtf-one-pipeline-toggle {
    height: 2rem;
    min-width: 4.75rem;
    border: 1px solid #c9d3df;
    border-radius: 6px;
    background: #fff;
    color: #26445d;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

    .rtf-one-pipeline-toggle:hover:not(:disabled) {
        border-color: #2b6f89;
        color: #1d5d75;
    }

    .rtf-one-pipeline-toggle.is-active {
        background: #215d73;
        border-color: #215d73;
        color: #fff;
    }

    .rtf-one-pipeline-toggle:disabled {
        opacity: 0.55;
        cursor: not-allowed;
    }

.rtf-one-docx-preview {
    width: 100%;
    height: 100%;
    min-height: 70vh;
    border: 0;
    background: #fff;
}

.rtf-one-docx-preview-tools {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #d9e1e8;
    background: #f8fafc;
}

.rtf-one-docx-preview-action {
    height: 2rem;
    border: 1px solid #c9d3df;
    border-radius: 6px;
    background: #fff;
    color: #26445d;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

    .rtf-one-docx-preview-action:hover {
        border-color: #2b6f89;
        color: #1d5d75;
        text-decoration: none;
    }

.rtf-one-docx-editor {
    height: 100%;
    min-height: 620px;
}

.rtf-one-docx-editor .e-documenteditorcontainer {
    height: 100%;
}

.rtf-one-docx-error {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e6b8b8;
    background: #fff4f4;
    color: #8a2222;
    font-size: 0.9rem;
    font-weight: 600;
}
