/* --- APPLE HIG DESIGN SYSTEM & DESIGN TOKENS --- */
:root {
    --bg-base: #000000;
    --panel-surface: rgba(28, 28, 30, 0.88);
    --panel-border: rgba(255, 255, 255, 0.12);
    --card-surface: rgba(44, 44, 46, 0.65);
    --card-surface-hover: rgba(58, 58, 60, 0.85);
    --card-border: rgba(255, 255, 255, 0.08);

    --text-primary: #F5F5F7;
    --text-secondary: rgba(235, 235, 245, 0.65);
    --text-tertiary: rgba(235, 235, 245, 0.4);

    --accent-blue: #0A84FF;
    --accent-blue-active: #0066CC;
    --accent-cyan: #64D2FF;
    --system-green: #30D158;
    --system-amber: #FF9F0A;
    --system-red: #FF453A;
    --system-star: #FFD60A;

    --spring-easing: cubic-bezier(0.19, 1, 0.22, 1);
    --radius-large: 20px;
    --radius-medium: 12px;
    --radius-small: 8px;

    --font-stack: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", sans-serif;
}

/* UNIVERSAL UTILITIES */
.is-hidden {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    width: 100vw;
    height: 100dvh;
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-stack);
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-font-smoothing: antialiased;
}

.app-shell {
    display: flex;
    width: 100vw;
    height: 100dvh;
    position: relative;
    background: radial-gradient(circle at 50% 20%, #15181e 0%, #000000 85%);
}

/* =======================================================
   DESKTOP (70% Viewer / 30% Sidebar)
   ======================================================= */
@media (min-width: 901px) {
    .viewport-stage {
        flex: 7;
        height: 100dvh;
    }
    .clinical-panel {
        flex: 3;
        max-width: 440px;
        min-width: 330px;
        height: 100dvh;
        border-left: 1px solid var(--panel-border);
    }
    .sheet-handle { display: none; }
}

/* =======================================================
   MOBILE STRICT LOCK: GUARANTEED 70dvh / 30dvh SPLIT
   ======================================================= */
@media (max-width: 900px) {
    .app-shell {
        flex-direction: column;
        height: 100dvh;
        width: 100vw;
    }

    .viewport-stage {
        flex: 0 0 44dvh !important;
        height: 44dvh !important;
        min-height: 44dvh !important;
        max-height: 44dvh !important;
        width: 100vw !important;
    }

    .clinical-panel {
        flex: 1 1 56dvh !important;
        height: 56dvh !important;
        min-height: 56dvh !important;
        max-height: 56dvh !important;
        width: 100vw !important;
        border-left: none !important;
        border-top: 1px solid var(--panel-border) !important;
        border-radius: 18px 18px 0 0 !important;
        box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.8) !important;
    }

    .sheet-handle {
        width: 38px;
        height: 4px;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.28);
        margin: 6px auto 4px auto;
        flex-shrink: 0;
    }

    .dynamic-island {
        top: 8px !important;
        padding: 4px 8px !important;
        transform: scale(0.9);
        transform-origin: top center;
    }

    .hud-dock {
        bottom: 8px !important;
        padding: 4px 8px !important;
        gap: 6px !important;
        max-width: 96% !important;
        transform: scale(0.9);
        transform-origin: bottom center;
    }

    .panel-content {
        padding: 6px 14px 12px 14px !important;
        gap: 8px !important;
    }

    .panel-header { display: none !important; }

    .ai-box {
        padding: 6px 10px !important;
    }
    .metric-item small { font-size: 0.62rem !important; }
    .metric-item b { font-size: 0.95rem !important; }

    .segmented-control { padding: 2px !important; gap: 2px !important; }
    .segment-btn { padding: 6px 0 !important; }
    .segment-btn span { display: none !important; }
    .segment-btn b { font-size: 0.95rem !important; }

    .action-row {
        display: grid !important;
        grid-template-columns: auto 1fr !important;
        gap: 8px !important;
    }
    .toggle-card { padding: 6px 8px !important; }
    .toggle-sub { display: none !important; }
    .toggle-main { font-size: 0.78rem !important; }

    .cta-submit-btn { padding: 9px 12px !important; font-size: 0.86rem !important; }
    .ios-textarea { font-size: 0.8rem !important; min-height: 40px !important; padding: 6px 8px !important; }
    .search-wrap { display: none !important; }
}

/* =======================================================
   VIEWPORT CANVAS & VECTOR LAYER
   ======================================================= */
.viewport-stage {
    position: relative;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
    background: #000;
}
.viewport-stage:active { cursor: grabbing; }

.canvas-wrap {
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
    width: 2048px;
    height: 998px;
    transform-origin: 0 0;
    will-change: transform;
}

.photo-raw, .photo-over, .vector-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 2048px;
    height: 998px;
    max-width: none !important;
    max-height: none !important;
    display: block;
    margin: 0;
    padding: 0;
    border: none;
    pointer-events: none;
}
.photo-raw { z-index: 1; opacity: 1; }
.photo-over { z-index: 2; opacity: 0; transition: opacity 0.15s ease-out; }
.vector-overlay { z-index: 10; pointer-events: none; }
.vector-overlay .tooth-bbox { pointer-events: auto; cursor: pointer; }

.probe-line {
    stroke-width: 2.2;
    stroke-linecap: round;
    transition: stroke 0.2s, stroke-width 0.2s;
}
.probe-line.normal   { stroke: var(--system-green); stroke-dasharray: 2 2; opacity: 0.8; }
.probe-line.stage-1  { stroke: var(--system-star); stroke-width: 3.2; }
.probe-line.stage-2  { stroke: var(--system-amber); stroke-width: 4; }
.probe-line.stage-3  { stroke: var(--system-red); stroke-width: 5; }

.probe-line.is-peak {
    stroke: #FF3B30 !important;
    stroke-width: 5.5 !important;
    filter: drop-shadow(0 0 6px rgba(255, 59, 48, 0.9));
}
.probe-line.is-confirming {
    stroke: var(--system-amber) !important;
    stroke-width: 4.5 !important;
    filter: drop-shadow(0 0 5px rgba(255, 159, 10, 0.8));
}

.tooth-bbox {
    fill: none;
    stroke: rgba(255, 255, 255, 0.14);
    stroke-width: 1.5;
    rx: 6;
    transition: all 0.2s;
}
.tooth-bbox.is-peak-tooth {
    stroke: #FF3B30;
    stroke-width: 2.5;
    fill: rgba(255, 59, 48, 0.12);
}
.tooth-bbox.is-confirming-tooth {
    stroke: var(--system-amber);
    stroke-width: 2;
    fill: rgba(255, 159, 10, 0.08);
}

.vector-badge {
    font-family: var(--font-stack);
    font-weight: 700;
    font-size: 11px;
    fill: #ffffff;
    paint-order: stroke;
    stroke: #000000;
    stroke-width: 3px;
    stroke-linejoin: round;
}
.vector-badge.badge-peak {
    font-size: 12.5px;
    fill: #FF453A;
}

/* Dynamic Island Navigation */
.dynamic-island {
    position: absolute;
    top: env(safe-area-inset-top, 14px);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(28, 28, 30, 0.82);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border: 1px solid var(--panel-border);
    border-radius: 999px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.6);
}

.island-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}
.island-btn:hover { background: rgba(255, 255, 255, 0.12); }
.island-btn:active { transform: scale(0.9); }

.island-meta {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 130px;
}
.island-counter { font-size: 0.68rem; font-weight: 600; color: var(--text-tertiary); }
.island-title { font-size: 0.88rem; font-weight: 600; color: var(--text-primary); }
.island-badge {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}
.island-badge.is-reviewed {
    color: var(--system-green);
    background: rgba(48, 209, 88, 0.16);
}

/* Floating Bottom HUD Dock */
.hud-dock {
    position: absolute;
    bottom: env(safe-area-inset-bottom, 16px);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(28, 28, 30, 0.85);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border: 1px solid var(--panel-border);
    border-radius: 18px;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.65);
}

.hud-divider {
    width: 1px;
    height: 18px;
    background: rgba(255, 255, 255, 0.12);
}

.hud-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    padding: 7px 11px;
    border-radius: 10px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s var(--spring-easing);
}
.hud-pill:hover { background: rgba(255, 255, 255, 0.14); }
.hud-pill:active, .hud-pill.is-active {
    background: rgba(10, 132, 255, 0.28);
    border-color: var(--accent-blue);
    color: var(--accent-cyan);
}
.hud-pill.highlight {
    background: rgba(255, 59, 48, 0.18);
    border-color: rgba(255, 59, 48, 0.4);
    color: #FF6961;
}

.hud-peek-btn kbd {
    font-size: 0.65rem;
    padding: 1px 4px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.35);
    color: var(--text-secondary);
}

.stage-stepper { display: flex; align-items: center; gap: 4px; }
.mini-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 4px 6px;
    cursor: pointer;
    font-size: 0.72rem;
    border-radius: 4px;
}
.mini-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--text-primary); }

.chip-carousel {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    max-width: min(560px, calc(100vw - 340px));
    scroll-behavior: smooth;
    padding: 2px 4px;
}
.chip-carousel::-webkit-scrollbar { display: none; }

.pipeline-chip {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    padding: 6px 10px;
    border-radius: 9px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.pipeline-chip:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.14); }
.pipeline-chip.is-active {
    background: rgba(10, 132, 255, 0.25);
    border-color: var(--accent-blue);
    color: var(--accent-cyan);
    box-shadow: 0 0 10px rgba(10, 132, 255, 0.3);
}

/* Centered Glass Loader */
.glass-loader {
    position: absolute;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(20, 20, 22, 0.88);
    backdrop-filter: blur(15px);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 50;
    box-shadow: 0 4px 14px rgba(0,0,0,0.6);
}
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent-cyan);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =======================================================
   CLINICAL SIDEBAR PANEL
   ======================================================= */
.clinical-panel {
    background: var(--panel-surface);
    backdrop-filter: blur(35px) saturate(200%);
    -webkit-backdrop-filter: blur(35px) saturate(200%);
    display: flex;
    flex-direction: column;
    z-index: 30;
    overflow: hidden;
}

.panel-content {
    padding: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.panel-heading { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.2px; }
.panel-subheading { font-size: 0.72rem; color: var(--text-secondary); }

.icon-btn {
    background: var(--card-surface);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius-small);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.15s;
}
.icon-btn:hover { background: var(--card-surface-hover); }

/* Blinded AI Prediction Card */
.ai-box {
    background: var(--card-surface);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-medium);
    padding: 10px 12px;
    position: relative;
    transition: all 0.2s var(--spring-easing);
}

.ai-box-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.ai-tag {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--accent-cyan);
    background: rgba(100, 210, 255, 0.12);
    padding: 2px 6px;
    border-radius: 4px;
}
.audit-link-btn {
    background: transparent;
    border: none;
    color: var(--accent-blue);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
}
.audit-link-btn:hover { text-decoration: underline; }

.ai-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    transition: filter 0.2s ease, opacity 0.2s ease;
}
.metric-item { display: flex; flex-direction: column; }
.metric-item small { font-size: 0.65rem; color: var(--text-tertiary); font-weight: 600; }
.metric-item b { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); }
.metric-item .unit-text { font-size: 0.68rem; color: var(--text-secondary); margin-left: 2px; }
.accent-text { color: var(--accent-cyan); }

.ai-blind-prompt {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    text-align: center;
    margin-top: 6px;
    display: none;
}
.ai-blind-prompt kbd {
    background: rgba(255,255,255,0.1);
    padding: 1px 4px;
    border-radius: 3px;
    color: var(--text-secondary);
}

/* Blinded State */
.ai-box.is-blinded .ai-metrics {
    filter: blur(6px);
    opacity: 0.25;
    pointer-events: none;
}
.ai-box.is-blinded .ai-blind-prompt { display: block; }
.ai-box:not(.is-blinded) {
    border-color: rgba(10, 132, 255, 0.4);
    background: rgba(10, 132, 255, 0.08);
}

/* Clinical Triage Form */
.review-form { display: flex; flex-direction: column; gap: 10px; }
.form-label { font-size: 0.72rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; }

.segmented-control {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: rgba(0, 0, 0, 0.4);
    padding: 3px;
    border-radius: var(--radius-medium);
    border: 1px solid rgba(255, 255, 255, 0.06);
    gap: 3px;
}
.segment-btn {
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 8px 2px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: 0.15s;
}
.segment-btn b { font-size: 1.05rem; font-weight: 700; }
.segment-btn span { font-size: 0.62rem; color: var(--text-tertiary); }
.segment-btn.is-active {
    background: rgba(255, 255, 255, 0.18);
    color: var(--text-primary);
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.segment-btn.is-active span { color: var(--accent-cyan); }

.action-row { display: flex; gap: 8px; align-items: center; }

.toggle-card {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-surface);
    border: 1px solid var(--card-border);
    padding: 8px 10px;
    border-radius: var(--radius-medium);
    cursor: pointer;
}
.toggle-text-wrap { display: flex; flex-direction: column; }
.toggle-main { font-size: 0.82rem; font-weight: 600; }
.toggle-sub { font-size: 0.65rem; color: var(--text-secondary); }

.ios-switch { position: relative; width: 40px; height: 23px; flex-shrink: 0; }
.ios-switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
    position: absolute; inset: 0;
    background-color: rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    transition: 0.2s var(--spring-easing);
}
.switch-slider::before {
    position: absolute; content: "";
    height: 19px; width: 19px; left: 2px; bottom: 2px;
    background-color: #FFF; border-radius: 50%;
    transition: 0.2s var(--spring-easing);
}
.ios-switch input:checked + .switch-slider { background-color: var(--system-green); }
.ios-switch input:checked + .switch-slider::before { transform: translateX(17px); }

.cta-submit-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--accent-blue);
    color: #FFF;
    border: none;
    padding: 12px;
    border-radius: var(--radius-medium);
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(10, 132, 255, 0.3);
    transition: transform 0.1s;
}
.cta-submit-btn:active:not(:disabled) { transform: scale(0.98); }
.cta-submit-btn:disabled {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-tertiary);
    box-shadow: none;
    cursor: not-allowed;
}
.cta-submit-btn kbd {
    font-size: 0.72rem;
    padding: 2px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
}

.ios-textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-medium);
    padding: 8px 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.82rem;
    resize: none;
    outline: none;
    user-select: text;
    -webkit-user-select: text;
}
.ios-textarea:focus { border-color: var(--accent-blue); }

.toast-status {
    text-align: center;
    font-size: 0.76rem;
    color: var(--system-green);
    font-weight: 600;
}

.search-wrap {
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.search-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-medium);
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 0.82rem;
    outline: none;
    user-select: text;
    -webkit-user-select: text;
}
.search-input:focus { border-color: var(--accent-blue); }

/* =======================================================
   MODALS (Stages Gallery & Explainability Audit)
   ======================================================= */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}

.modal-card {
    background: rgba(30, 30, 32, 0.94);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-large);
    width: 100%; max-width: 680px; max-height: 82vh;
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8);
}

.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 18px; border-bottom: 1px solid var(--card-border);
}
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-subtitle { font-size: 0.72rem; color: var(--text-secondary); }

.pipeline-grid {
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
    overflow-y: auto;
}

.pipeline-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-surface);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-small);
    padding: 10px;
    cursor: pointer;
    transition: all 0.15s;
}
.pipeline-card:hover {
    background: var(--card-surface-hover);
    border-color: rgba(255, 255, 255, 0.2);
}
.pipeline-card.is-active-stage {
    border-color: var(--accent-blue);
    background: rgba(10, 132, 255, 0.2);
}
.card-stage-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-primary);
    pointer-events: none;
}
.star-btn {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 2px 4px;
}
.star-btn:hover { transform: scale(1.2); }
.star-btn.is-starred { color: var(--system-star); text-shadow: 0 0 8px rgba(255, 214, 10, 0.5); }

/* Audit Trace Layout */
.audit-card { max-width: 820px; max-height: 85vh; }
.audit-scroller {
    padding: 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    font-size: 0.85rem;
    line-height: 1.5;
}
.audit-section {
    background: var(--card-surface);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-medium);
    padding: 14px;
}
.audit-section h3 {
    font-size: 0.9rem;
    color: var(--accent-cyan);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.audit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
    margin-top: 8px;
}
.audit-table th, .audit-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.audit-table th { color: var(--text-secondary); font-weight: 600; }
.audit-pill {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
}
.audit-pill.valid { background: rgba(48, 209, 88, 0.18); color: var(--system-green); }
.audit-pill.warn { background: rgba(255, 159, 10, 0.18); color: var(--system-amber); }
.audit-pill.excluded { background: rgba(255, 69, 58, 0.18); color: var(--system-red); }

/* Hover Cursor Preview Loupe */
.cursor-preview {
    position: fixed;
    top: 0; left: 0;
    width: 220px; height: 150px;
    border-radius: 14px;
    background: rgba(24, 24, 26, 0.92);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.25);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    will-change: transform;
    transition: opacity 0.15s var(--spring-easing);
}
.preview-media-wrap {
    flex: 1;
    position: relative;
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.preview-media-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.preview-spinner {
    position: absolute;
    width: 18px; height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent-cyan);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.preview-caption {
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.6);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.68rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =======================================================
   FLOATING DUAL-LENS CULPRIT INSPECTOR (Raw + Hashored)
   ======================================================= */
.culprit-inspector {
    position: absolute;
    top: 72px;
    left: 20px;
    z-index: 100;
    width: min(540px, calc(100vw - 40px));
    background: rgba(18, 20, 26, 0.94);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 16px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.05);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: inspectorPop 0.22s cubic-bezier(0.19, 1, 0.22, 1);
    transition: all 0.2s ease;
}

@keyframes inspectorPop {
    from { opacity: 0; transform: translateY(-8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    gap: 10px;
}

.inspector-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.inspector-badge {
    background: #ff453a;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 800;
    padding: 2px 7px;
    border-radius: 6px;
    letter-spacing: 0.4px;
}
.inspector-badge.conf {
    background: #ff9f0a;
}

.inspector-title-group strong {
    font-size: 1.05rem;
    font-weight: 800;
    color: #fff;
}

.inspector-loss {
    font-size: 0.85rem;
    font-weight: 700;
    color: #ffd60a;
}

.inspector-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.4);
    padding: 2px;
    border-radius: 8px;
    gap: 2px;
}

.ins-tab {
    background: transparent;
    border: none;
    color: rgba(235, 235, 245, 0.6);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.ins-tab:hover { color: #fff; }
.ins-tab.is-active {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-weight: 700;
}

.inspector-close {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: rgba(235, 235, 245, 0.6);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.inspector-close:hover { background: rgba(255, 255, 255, 0.16); color: #fff; }

.inspector-panes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px;
}
@media (max-width: 480px) {
    .inspector-panes { grid-template-columns: 1fr; }
}

.pane-box {
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.pane-label {
    padding: 6px 10px;
    font-size: 0.72rem;
    font-weight: 700;
    color: rgba(235, 235, 245, 0.7);
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    letter-spacing: 0.2px;
}

.pane-canvas-wrap {
    width: 100%;
    aspect-ratio: 1;
    position: relative;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.loupe-canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.pane-sub {
    padding: 5px 8px;
    font-size: 0.68rem;
    color: rgba(235, 235, 245, 0.45);
    background: rgba(0, 0, 0, 0.5);
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    text-align: center;
}

.inspector-footer {
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.calc-formula {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.78rem;
    color: rgba(235, 235, 245, 0.8);
    flex-wrap: wrap;
}
.calc-formula .op { color: rgba(235, 235, 245, 0.4); font-weight: 700; }
.calc-formula .bio-tag {
    background: rgba(48, 209, 88, 0.15);
    color: #30d158;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
}
.calc-formula .highlight-loss {
    color: #ffd60a;
    font-weight: 800;
}
.calc-formula .formula-verdict {
    color: #ff9f0a;
    font-weight: 700;
    margin-left: 4px;
}


/* =======================================================
   AAP/EFP 2018 STAGING SPECS QUICK BAR
   ======================================================= */
.staging-specs-bar {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.specs-bar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.specs-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(235, 235, 245, 0.6);
}
.specs-info-btn {
    background: rgba(10, 132, 255, 0.15);
    border: 1px solid rgba(10, 132, 255, 0.35);
    color: #64d2ff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}
.specs-info-btn:hover {
    background: rgba(10, 132, 255, 0.28);
}

.specs-chips {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
}
.spec-chip {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    padding: 4px 2px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
}
.spec-chip:hover {
    transform: translateY(-1px);
    border-color: rgba(255, 255, 255, 0.2);
}
.spec-chip b {
    display: block;
    font-size: 0.8rem;
    font-weight: 800;
}
.spec-chip span {
    display: block;
    font-size: 0.62rem;
    color: rgba(235, 235, 245, 0.6);
}

.spec-chip.s0 b { color: #30d158; }
.spec-chip.s1 b { color: #ffd60a; }
.spec-chip.s2 b { color: #ff9f0a; }
.spec-chip.s3 b { color: #ff453a; }
.spec-chip.s4 b { color: #bf5af2; }

.specs-rule {
    font-size: 0.68rem;
    color: rgba(235, 235, 245, 0.45);
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
    padding: 3px 6px;
    border-radius: 4px;
}


/* =======================================================
   AAP/EFP 2018 STAGING CONSENSUS MODAL
   ======================================================= */
.specs-modal-card {
    max-width: 920px !important;
    width: 90vw !important;
}

.specs-modal-body {
    padding: 16px 20px 24px;
    max-height: 75vh;
    overflow-y: auto;
}

.consensus-table-wrap {
    overflow-x: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    margin-bottom: 20px;
}

.consensus-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    text-align: left;
}

.consensus-table th, .consensus-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    vertical-align: top;
}

.consensus-table th {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(235, 235, 245, 0.7);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
}

.stage-tag {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 800;
}
.stage-tag.c0 { background: rgba(48, 209, 88, 0.18); color: #30d158; border: 1px solid rgba(48, 209, 88, 0.4); }
.stage-tag.c1 { background: rgba(255, 214, 10, 0.18); color: #ffd60a; border: 1px solid rgba(255, 214, 10, 0.4); }
.stage-tag.c2 { background: rgba(255, 159, 10, 0.18); color: #ff9f0a; border: 1px solid rgba(255, 159, 10, 0.4); }
.stage-tag.c3 { background: rgba(255, 69, 58, 0.18); color: #ff453a; border: 1px solid rgba(255, 69, 58, 0.4); }
.stage-tag.c4 { background: rgba(191, 90, 242, 0.18); color: #bf5af2; border: 1px solid rgba(191, 90, 242, 0.4); }

.consensus-notes {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 16px 20px;
}
.consensus-notes h4 {
    font-size: 0.88rem;
    color: #fff;
    margin-bottom: 8px;
    font-weight: 700;
}
.consensus-notes ul {
    list-style: disc;
    padding-left: 20px;
    color: rgba(235, 235, 245, 0.7);
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
}


/* =======================================================
   DOCK CHIPS STYLING (RAW, HORIZONS, ETC.)
   ======================================================= */
.chip-pill, .pipeline-chip {
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(235, 235, 245, 0.85);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s cubic-bezier(0.19, 1, 0.22, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.chip-pill:hover, .pipeline-chip:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}
.chip-pill.is-active, .pipeline-chip.is-active {
    background: rgba(10, 132, 255, 0.35);
    border-color: #0a84ff;
    color: #64d2ff;
    box-shadow: 0 0 12px rgba(10, 132, 255, 0.45);
    font-weight: 700;
}

/* Dynamic Island Incomplete Tag */
.island-incomplete-pill {
    background: rgba(255, 159, 10, 0.2);
    border: 1px solid rgba(255, 159, 10, 0.45);
    color: #ff9f0a;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s;
}
.island-incomplete-pill:hover {
    background: rgba(255, 159, 10, 0.35);
    color: #ffd60a;
}

/* =======================================================
   PERMANENT DUAL-LENS STAGING CULPRIT LOUPE IN PANEL
   ======================================================= */
.panel-loupe-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.loupe-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.loupe-title-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

.loupe-badge {
    background: #ff453a;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 5px;
    letter-spacing: 0.4px;
}
.loupe-badge.conf {
    background: #ff9f0a;
}

.loupe-title-wrap strong {
    font-size: 0.95rem;
    color: #fff;
    font-weight: 800;
}

.loupe-loss-tag {
    font-size: 0.78rem;
    font-weight: 700;
    color: #ffd60a;
}

.loupe-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.35);
    padding: 2px;
    border-radius: 8px;
    gap: 2px;
}

.loupe-tab {
    background: transparent;
    border: none;
    color: rgba(235, 235, 245, 0.6);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.loupe-tab:hover { color: #fff; }
.loupe-tab.is-active {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-weight: 700;
}

.loupe-panes-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.loupe-pane {
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s;
}
.loupe-pane:hover {
    border-color: rgba(10, 132, 255, 0.6);
    transform: scale(1.02);
}

.loupe-pane-label {
    padding: 4px 8px;
    font-size: 0.68rem;
    font-weight: 700;
    color: rgba(235, 235, 245, 0.7);
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.loupe-canvas-container {
    width: 100%;
    aspect-ratio: 1;
    position: relative;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pane-canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.loupe-pane-sub {
    padding: 3px 6px;
    font-size: 0.62rem;
    color: rgba(235, 235, 245, 0.45);
    text-align: center;
    background: rgba(0, 0, 0, 0.4);
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.loupe-footer {
    padding-top: 2px;
}

.loupe-formula {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.72rem;
    color: rgba(235, 235, 245, 0.8);
    flex-wrap: wrap;
    background: rgba(0, 0, 0, 0.25);
    padding: 5px 8px;
    border-radius: 6px;
}
.loupe-formula .op { color: rgba(235, 235, 245, 0.4); font-weight: 700; }
.loupe-formula .bio-pill {
    background: rgba(48, 209, 88, 0.15);
    color: #30d158;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 600;
}
.loupe-formula strong {
    color: #ffd60a;
    font-weight: 800;
}
.loupe-formula .stage-tag {
    color: #ff9f0a;
    font-weight: 700;
}


/* =======================================================
   COMPACT ONE-VIEW NO-SCROLL CLINICAL SIDEBAR
   ======================================================= */
.clinical-panel {
    background: var(--panel-surface);
    backdrop-filter: blur(35px) saturate(200%);
    -webkit-backdrop-filter: blur(35px) saturate(200%);
    display: flex;
    flex-direction: column;
    z-index: 30;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
}

.panel-content {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 100%;
    max-height: 100%;
    overflow-y: hidden; /* Guaranteed ONE VIEW without scroll */
}

/* Compact AI Card */
.ai-box {
    background: var(--card-surface);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 8px 12px;
    flex-shrink: 0;
}
.ai-box-header { margin-bottom: 4px; }
.ai-metrics { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.metric-item small { font-size: 0.65rem; }
.metric-item b { font-size: 1.05rem; }

/* Compact Dual-Lens Loupe Card */
.panel-loupe-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.loupe-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
}
.loupe-title-wrap strong { font-size: 0.9rem; }
.loupe-loss-tag { font-size: 0.75rem; }
.loupe-tab { padding: 3px 6px; font-size: 0.68rem; }

.loupe-panes-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.loupe-pane {
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
}
.loupe-pane:hover {
    border-color: #0a84ff;
    transform: scale(1.02);
}
.loupe-pane-label {
    padding: 3px 6px;
    font-size: 0.62rem;
    font-weight: 700;
    color: rgba(235, 235, 245, 0.7);
    background: rgba(255, 255, 255, 0.05);
}
.loupe-canvas-container {
    width: 100%;
    aspect-ratio: 1;
    position: relative;
    max-height: 110px;
}
.pane-canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.loupe-pane-sub { display: none; }

.loupe-formula {
    font-size: 0.68rem;
    padding: 4px 6px;
    gap: 4px;
}

/* Compact Staging Specs Bar */
.staging-specs-bar {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 6px 8px;
    gap: 4px;
    flex-shrink: 0;
}
.specs-title { font-size: 0.68rem; }
.specs-chips { gap: 3px; }
.spec-chip { padding: 3px 2px; }
.spec-chip b { font-size: 0.75rem; }
.spec-chip span { font-size: 0.58rem; }
.specs-rule { display: none; }

/* Review Form */
.review-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    justify-content: space-between;
}
.form-label { font-size: 0.72rem; margin-bottom: 2px; }
.segmented-control {
    background: rgba(0, 0, 0, 0.35);
    border-radius: 10px;
    padding: 3px;
    gap: 3px;
}
.segment-btn { padding: 8px 0; border-radius: 7px; }
.segment-btn b { font-size: 1rem; }
.segment-btn span { font-size: 0.64rem; }

.cta-submit-btn { padding: 10px 14px; font-size: 0.92rem; border-radius: 10px; }
.ios-textarea { min-height: 38px; max-height: 52px; font-size: 0.78rem; padding: 6px 8px; }
.search-wrap { display: none; }

/* Professor Presentation Defaults Modal */
.settings-body {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.settings-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.settings-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.settings-radios {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.settings-radio-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: var(--card-surface);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-medium);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.settings-radio-card:hover {
    background: var(--card-surface-hover);
    border-color: rgba(255, 255, 255, 0.22);
}
.settings-radio-card input[type="radio"] {
    accent-color: var(--accent-cyan);
    transform: scale(1.2);
}
.settings-radio-card div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.settings-radio-card strong {
    font-size: 0.9rem;
    color: var(--text-primary);
}
.settings-radio-card small {
    font-size: 0.76rem;
    color: var(--text-secondary);
}
.settings-actions {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
}

