/* OrthoAnalytix - (c) 2026 IdeaShelf. All rights reserved. Proprietary and confidential. */
/* ==========================================================================
   Design tokens. Every colour in the app comes from here.
   Light is the default; [data-theme="dark"] swaps the values. The 3D viewers keep a dark
   canvas in both themes (.viewer-scope re-points the tokens for anything drawn over a scan).

   Colour roles (app-wide):
     accent  = actions (buttons, links, focus)     success = complete / no action needed
     warning = needs review / borderline            danger  = missing / extraction / destructive
     violet  = scan-stage badges                    neutral greys = everything else
   ========================================================================== */
:root {
    color-scheme: light;
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eef2f6;
    --border: #e3e8ef;
    --border-strong: #cfd7e2;
    --text-strong: #0f1b2d;
    --text: #263449;
    --text-muted: #5d6b7e;
    --text-subtle: #8792a2;
    --overlay: rgba(15, 27, 45, 0.38);

    --accent: #4f7cac;
    --accent-hover: #426b96;
    --accent-text: #3d6690;
    --accent-soft: #eaf1f8;
    --accent-border: #c3d5e8;
    --accent-contrast: #ffffff;
    --focus-ring: 0 0 0 3px rgba(79, 124, 172, 0.28);

    --success: #3d8b67;
    --success-soft: #e8f4ee;
    --success-border: #bfdccd;
    --warning: #a96f17;
    --warning-soft: #fcf3e3;
    --warning-border: #ecd3a6;
    --danger: #b9504d;
    --danger-soft: #fbecec;
    --danger-border: #ecc3c1;
    --violet: #7357a8;
    --violet-soft: #f1edf8;
    --violet-border: #d6cbea;

    /* Arch line colours (on the scan and as small dots next to their names) */
    --line-mmv: #d9534f;
    --line-mpv: #c99a1b;
    --line-ppl: #a05cc8;

    --viewer-bg: #0f141c;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(15, 27, 45, 0.06), 0 1px 3px rgba(15, 27, 45, 0.05);
    --shadow-md: 0 4px 14px rgba(15, 27, 45, 0.08), 0 1px 3px rgba(15, 27, 45, 0.06);
    --shadow-lg: 0 18px 48px rgba(15, 27, 45, 0.18);

    --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-heading: var(--font-body);
    --fs-xs: 0.72rem;
    --fs-sm: 0.8rem;
    --fs-md: 0.875rem;
    --fs-lg: 1rem;
    --fs-xl: 1.2rem;
    --fs-2xl: 1.45rem;

    --transition-fast: 0.15s ease;
    --transition-smooth: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    /* Old names kept as aliases so every existing rule follows the theme */
    --bg-darkest: var(--bg);
    --bg-darker: var(--surface-2);
    --bg-dark: var(--surface-3);
    --bg-panel: var(--surface);
    --border-color: var(--border);
    --border-color-glow: var(--accent-border);
    --accent-cyan: var(--accent);
    --accent-cyan-glow: var(--accent-border);
    --accent-teal: var(--accent);
    --accent-teal-glow: var(--accent-border);
    --accent-emerald: var(--success);
    --accent-emerald-glow: var(--success-border);
    --accent-amber: var(--warning);
    --accent-rose: var(--danger);
    --text-primary: var(--text);
    --text-secondary: var(--text-muted);
}

/* Muted dark theme (no neon) */
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #12161d;
    --surface: #1a1f28;
    --surface-2: #1f2530;
    --surface-3: #262d3a;
    --border: #2c3442;
    --border-strong: #3a4455;
    --text-strong: #f1f4f8;
    --text: #d6dde7;
    --text-muted: #9ba7b8;
    --text-subtle: #6f7b8d;
    --overlay: rgba(4, 7, 12, 0.6);

    --accent: #7ea6d4;
    --accent-hover: #93b5dc;
    --accent-text: #9dbde2;
    --accent-soft: rgba(126, 166, 212, 0.14);
    --accent-border: rgba(126, 166, 212, 0.38);
    --accent-contrast: #0f1620;
    --focus-ring: 0 0 0 3px rgba(126, 166, 212, 0.35);

    --success: #74c19c;
    --success-soft: rgba(116, 193, 156, 0.13);
    --success-border: rgba(116, 193, 156, 0.36);
    --warning: #e0b468;
    --warning-soft: rgba(224, 180, 104, 0.13);
    --warning-border: rgba(224, 180, 104, 0.36);
    --danger: #e38b88;
    --danger-soft: rgba(227, 139, 136, 0.13);
    --danger-border: rgba(227, 139, 136, 0.38);
    --violet: #b3a0dc;
    --violet-soft: rgba(179, 160, 220, 0.14);
    --violet-border: rgba(179, 160, 220, 0.38);

    --line-mmv: #e8817e;
    --line-mpv: #e3c35a;
    --line-ppl: #c592e3;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.32);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.5);
}

/* Anything drawn over a 3D scan stays dark in both themes */
.viewer-scope {
    color-scheme: dark;
    --surface: rgba(20, 26, 36, 0.94);
    --surface-2: rgba(24, 31, 43, 0.92);
    --surface-3: rgba(255, 255, 255, 0.07);
    --border: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.2);
    --text-strong: #f3f6fa;
    --text: #dbe2eb;
    --text-muted: #a3aebd;
    --text-subtle: #7a8698;
    --accent: #8db1da;
    --accent-hover: #a2c0e2;
    --accent-text: #a9c6e6;
    --accent-soft: rgba(141, 177, 218, 0.16);
    --accent-border: rgba(141, 177, 218, 0.42);
    --accent-contrast: #0f1620;
    --success: #7fcaa5;
    --success-soft: rgba(127, 202, 165, 0.16);
    --success-border: rgba(127, 202, 165, 0.4);
    --warning: #e6bd73;
    --warning-soft: rgba(230, 189, 115, 0.16);
    --warning-border: rgba(230, 189, 115, 0.4);
    --danger: #ea9592;
    --danger-soft: rgba(234, 149, 146, 0.16);
    --danger-border: rgba(234, 149, 146, 0.42);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
    --line-mmv: #e8817e;
    --line-mpv: #e3c35a;
    --line-ppl: #c592e3;
    color: var(--text);
}


/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-darkest);
    color: var(--text);
    font-family: var(--font-body);
    overflow-x: hidden;
    height: 100vh;
}

/* App Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 12px;
    gap: 12px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--bg-panel);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--accent);
    box-shadow: none;
    position: relative;
}

.logo-icon::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 6px;
    right: 6px;
    bottom: 6px;
    background-color: var(--bg-darkest);
    border-radius: 3px;
}

.app-header h1 {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-strong);
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge {
    font-size: 0.7rem;
    font-weight: 500;
    background: var(--accent-soft);
    border: 1px solid var(--accent-cyan-glow);
    color: var(--accent-cyan);
    padding: 2px 8px;
    border-radius: 20px;
    text-transform: uppercase;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    position: relative;
}

.status-indicator.online {
    background-color: var(--accent-emerald);
    box-shadow: none;
}

/* Main Grid Layout */
.main-content {
    display: grid;
    grid-template-columns: 320px 1fr 340px;
    gap: 12px;
    flex: 1;
    min-height: 0;
}

/* General Panels (Glassmorphism) */
.panel {
    background: var(--bg-panel);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    min-height: 0;
    transition: border-color var(--transition-fast);
}

.panel:hover {
    border-color: var(--border);
}

.panel-title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-strong);
    margin-bottom: 16px;
}

.section-title {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 12px;
    border-left: 2px solid var(--accent-cyan);
    padding-left: 8px;
}

.panel-section {
    margin-bottom: 24px;
}

.panel-section:last-child {
    margin-bottom: 0;
    margin-top: auto;
}

/* Left Panel: Uploads */
.upload-group {
    margin-bottom: 12px;
}

.upload-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 20px 16px;
    cursor: pointer;
    background: var(--surface-2);
    transition: all var(--transition-fast);
    text-align: center;
}

.upload-box:hover {
    border-color: var(--accent-cyan);
    background: var(--accent-soft);
    box-shadow: none;
}

.upload-box.uploaded {
    border-style: solid;
    border-color: var(--accent-emerald);
    background: var(--success-soft);
}

.upload-icon {
    font-size: 1.4rem;
    color: var(--text-subtle);
    margin-bottom: 8px;
    transition: color var(--transition-fast);
}

.upload-box:hover .upload-icon {
    color: var(--accent-cyan);
}

.upload-box.uploaded .upload-icon {
    color: var(--accent-emerald);
}

.upload-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-strong);
    margin-bottom: 4px;
}

.file-name {
    font-size: 0.75rem;
    color: var(--text-subtle);
    word-break: break-all;
    max-width: 100%;
}

.upload-box.uploaded .file-name {
    color: var(--success);
    font-weight: 500;
}

.hidden-input {
    display: none;
}

/* View Control Buttons */
.view-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.view-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 12px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    text-align: left;
    transition: all var(--transition-fast);
}

.view-btn:hover {
    background: var(--surface-3);
    color: var(--text-strong);
    border-color: var(--border);
}

.view-btn.active {
    background: var(--accent-soft);
    border-color: var(--accent-cyan);
    color: var(--text-strong);
    box-shadow: none;
}

.btn-icon {
    font-size: 1rem;
    color: var(--accent-cyan);
}

/* General Buttons */
.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    gap: 8px;
}

.primary-btn {
    background: var(--accent);
    border: none;
    color: var(--bg-darkest);
    box-shadow: none;
}

.primary-btn:hover {
    box-shadow: none;
    transform: translateY(-1px);
}

.primary-btn:disabled {
    background: var(--surface-3);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    margin-top: 10px;
}

.secondary-btn:hover {
    border-color: var(--accent-rose);
    color: var(--accent-rose);
    background: var(--danger-soft);
}

.success-btn {
    background: var(--success);
    border: none;
    color: var(--bg-darkest);
    box-shadow: none;
}

.success-btn:hover {
    box-shadow: none;
    transform: translateY(-1px);
}

.success-btn:disabled {
    background: var(--surface);
    color: var(--text-subtle);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* Spinner & Loader */
.loader-ring {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 50%;
    border-top-color: var(--bg-darkest);
    animation: spin 0.8s linear infinite;
}

.hidden {
    display: none !important;
}

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

/* Center Viewport */
.viewport-panel {
    grid-column: 3;
    padding: 0;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-color);
}

.viewport-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

.view-indicator {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-strong);
}

.viewport-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.canvas-container {
    position: relative;
    flex: 1;
    width: 100%;
    height: 100%;
}

.canvas-container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    outline: none;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--surface-2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 20;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--accent-border);
    border-left-color: var(--accent-cyan);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    font-size: 0.9rem;
    color: var(--accent-cyan);
    font-weight: 500;
}

.instruction-overlay {
    position: absolute;
    bottom: 16px;
    left: 16px;
    right: 16px;
    background: var(--surface-2);
    backdrop-filter: none;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 16px;
    z-index: 10;
    pointer-events: none;
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.instruction-overlay p {
    line-height: 1.4;
}

/* Floating Diagnostic Overlay Controls Panel */
.debug-panel {
    position: absolute;
    top: 16px;
    left: 16px;
    background: var(--surface-2);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 16px;
    z-index: 100;
    width: 220px;
    box-shadow: var(--shadow-md);
    pointer-events: auto;
}

.debug-header {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-strong);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
}

.debug-row {
    margin-bottom: 8px;
}

.debug-row:last-child {
    margin-bottom: 0;
}

/* Checkbox Container styles */
.checkbox-container {
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 24px;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-muted);
    user-select: none;
    transition: color var(--transition-fast);
}

.checkbox-container:hover {
    color: var(--text-strong);
}

.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    position: absolute;
    top: 0;
    left: 0;
    height: 16px;
    width: 16px;
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: all var(--transition-fast);
}

.checkbox-container input:checked ~ .checkmark {
    background-color: var(--accent-cyan);
    border-color: var(--accent-cyan);
    box-shadow: none;
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
    display: block;
}

.checkbox-container .checkmark:after {
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid var(--bg-darkest);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* FDI labels floating on canvas in 2D */
.labels-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 15;
    overflow: hidden;
}

.tooth-label-3d {
    position: absolute;
    background: var(--surface);
    backdrop-filter: none;
    border: 1px solid var(--accent-border);
    color: var(--accent-text);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    font-family: var(--font-heading);
    letter-spacing: 0.02em;
    pointer-events: none;
    user-select: none;
    transform: translate(-50%, -100%);
    box-shadow: var(--shadow-sm);
    z-index: 20;
    transition: opacity 0.15s ease;
    white-space: nowrap;
}

.arch-confirm-banner {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    backdrop-filter: none;
    border-radius: 8px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 40;
    box-shadow: var(--shadow-md);
    font-size: 0.82rem;
    color: var(--text);
    border: 1px solid var(--border);
}

.arch-confirm-banner.hidden {
    display: none !important;
}

.red-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger) !important;
    box-shadow: none;
    animation: pulse 1.8s infinite;
}

.yellow-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--warning) !important;
    box-shadow: none;
    animation: pulse 1.8s infinite;
}

.btn-confirm-save {
    padding: 5px 14px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.76rem;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-confirm-save.red-btn {
    background: var(--danger);
    color: var(--text-strong);
}
.btn-confirm-save.red-btn:hover {
    background: var(--danger);
    box-shadow: none;
}

.btn-confirm-save.yellow-btn {
    background: var(--warning);
    color: var(--accent-contrast);
}
.btn-confirm-save.yellow-btn:hover {
    background: #ca8a04;
    box-shadow: none;
}

.btn-confirm-cancel {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
    padding: 2px 4px;
}
.btn-confirm-cancel:hover {
    color: var(--text);
}

/* Right Panel: Measurements Table */
.results-panel {
    grid-column: 5;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.results-count {
    font-size: 0.75rem;
    background: var(--surface-3);
    border: 1px solid var(--border-color);
    padding: 3px 8px;
    border-radius: 20px;
    color: var(--text-muted);
}

.table-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--surface-2);
    margin-bottom: 16px;
}

.table-container::-webkit-scrollbar,
.panel::-webkit-scrollbar {
    width: 6px;
}

.table-container::-webkit-scrollbar-track,
.panel::-webkit-scrollbar-track {
    background: transparent;
}

.table-container::-webkit-scrollbar-thumb,
.panel::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 10px;
}

.table-container::-webkit-scrollbar-thumb:hover,
.panel::-webkit-scrollbar-thumb:hover {
    background: var(--surface-3);
}

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

.measurements-table th {
    background-color: var(--surface-2);
    color: var(--text-muted);
    padding: 12px 12px;
    font-family: var(--font-heading);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 5;
    border-bottom: 1px solid var(--border-color);
}

.measurements-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text);
    vertical-align: middle;
}

.measurements-table tbody tr {
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.measurements-table tbody tr:hover {
    background-color: var(--surface-3);
}

.measurements-table tbody tr.selected-row {
    background-color: var(--accent-soft);
}

.text-right {
    text-align: right;
}

.empty-state-row:hover {
    background-color: transparent !important;
}

.empty-table-state {
    padding: 60px 24px;
    text-align: center;
    color: var(--text-subtle);
    line-height: 1.6;
    font-size: 0.8rem;
}

/* Tooth status badges */
.status-pill {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 600;
}

.status-pill.auto {
    background-color: var(--accent-soft);
    color: var(--accent-cyan);
    border: 1px solid var(--accent-border);
}

.status-pill.edited {
    background-color: var(--warning-soft);
    color: var(--accent-amber);
    border: 1px solid var(--warning-border);
}

.status-pill.verified {
    background-color: var(--success-soft);
    color: var(--accent-emerald);
    border: 1px solid var(--success-border);
}

.status-pill.fallback {
    background-color: var(--danger-soft);
    color: var(--accent-rose);
    border: 1px solid var(--danger-border);
}

.status-pill.warning {
    background-color: var(--danger-soft);
    color: var(--accent-rose);
    border: 1px solid var(--danger-border);
}

.status-pill.unresolved {
    background-color: var(--surface-3);
    color: var(--text-muted);
    border: 1px dashed var(--border-strong);
}

/* Table Verification Checkbox column */
.verify-checkbox {
    cursor: pointer;
    width: 15px;
    height: 15px;
    accent-color: var(--accent-emerald);
    vertical-align: middle;
}

/* Table Metric Summaries */
.results-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.summary-metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: 12px;
}

.metric-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.metric-value {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-cyan);
}

canvas {
    cursor: grab;
}

canvas:active {
    cursor: grabbing;
}

/* PLY Diagnostics */
.ply-diagnostics {
    margin-top: 8px;
    padding: 8px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.72rem;
    line-height: 1.5;
}

.ply-diag-header {
    font-weight: 600;
    margin-bottom: 4px;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
    font-size: 0.7rem;
}

.ply-diag-header.ply-diag-good {
    background: var(--success-soft);
    color: var(--accent-emerald);
    border: 1px solid var(--success-border);
}

.ply-diag-header.ply-diag-warn {
    background: var(--warning-soft);
    color: var(--accent-amber);
    border: 1px solid var(--warning-border);
}

.ply-diag-header.ply-diag-neutral {
    background: var(--surface-3);
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
}

.ply-diag-error {
    color: var(--accent-rose);
    font-size: 0.7rem;
}

.ply-diag-details {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 0.68rem;
}

.ply-diag-details b {
    color: var(--text);
}

/* Calibration & Multi-slot Upload Styles */
.upload-subheading {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-cyan);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

.upload-dual-row {
    display: flex;
    gap: 6px;
    width: 100%;
}

.compact-upload {
    flex: 1;
    padding: 8px 10px !important;
    min-height: 54px !important;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 1px dashed var(--border);
    background: var(--surface-2);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.compact-upload:hover {
    border-color: var(--accent-cyan);
    background: var(--surface-2);
}

.compact-upload .upload-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
}

.compact-upload .file-name {
    font-size: 0.65rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 110px;
}

.custom-select {
    width: 100%;
    padding: 9px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    transition: var(--transition-fast);
}

.custom-select:focus {
    border-color: var(--accent-cyan);
    box-shadow: none;
}

.custom-select-small {
    padding: 4px 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.75rem;
    outline: none;
    cursor: pointer;
}

.calib-card {
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.calib-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
}

.calib-label {
    color: var(--text-muted);
    font-weight: 500;
}

.calib-val {
    color: var(--text);
    font-weight: 600;
    font-family: var(--font-body); font-variant-numeric: tabular-nums;
}

.calib-tab-btn {
    flex: 1;
    padding: 5px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
}

.calib-tab-btn.active {
    background: var(--accent-soft);
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.calib-btn {
    padding: 6px 10px;
    border-radius: 6px;
    border: none;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
}

.calib-btn.primary {
    background: var(--accent-soft);
    color: var(--accent-cyan);
    border: 1px solid var(--accent-border);
}

.calib-btn.primary:hover {
    background: var(--accent-soft);
}

.calib-btn.secondary {
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border-strong);
}

.calib-btn.secondary:hover {
    background: var(--surface-3);
}

.calib-btn.success {
    background: var(--success-soft);
    color: var(--accent-emerald);
    border: 1px solid var(--success-border);
}

.calib-btn.success:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.calib-btn.cancel {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.ref-calib-container {
    background: var(--surface);
    border: 1px solid var(--accent-cyan);
    box-shadow: none;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ref-calib-header {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent-cyan);
}

.ref-calib-instructions {
    font-size: 0.7rem;
    color: var(--text);
    background: var(--surface-2);
    padding: 6px 8px;
    border-radius: 4px;
    border-left: 2px solid var(--accent-cyan);
}

.calib-input {
    width: 80px;
    padding: 3px 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.75rem;
    text-align: right;
}

.calib-warning-banner {
    background: var(--warning-soft);
    border: 1px solid var(--warning-border);
    color: var(--warning);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.72rem;
    line-height: 1.4;
    margin-bottom: 8px;
}

/* ==========================================================================
   Phase 2 Styles: Hamburger, Drawer, Modals, Orthodontics, Editable Widths
   ========================================================================== */

/* Header Navigation Pills */
.nav-view-pills {
    display: flex;
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 3px;
    gap: 4px;
}

.nav-pill {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-fast);
}

.nav-pill:hover {
    color: var(--text);
}

.nav-pill.active {
    background: var(--accent-soft);
    color: var(--accent-cyan);
    box-shadow: none;
}

/* Hamburger Menu Button */
.hamburger-btn {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 32px;
    height: 32px;
    background: var(--surface-3);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.hamburger-btn:hover {
    background: var(--accent-soft);
    border-color: var(--accent-cyan);
}

.hamburger-btn .bar {
    width: 100%;
    height: 2px;
    background-color: var(--surface);
    border-radius: 2px;
    transition: var(--transition-fast);
}

/* Side Navigation Drawer */
.drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--overlay);
    backdrop-filter: none;
    z-index: 9990;
    transition: opacity 0.25s ease;
}

.side-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    height: 100vh;
    background: #0d1527;
    border-right: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.side-drawer.closed {
    transform: translateX(-100%);
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-color);
}

.drawer-title {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-strong);
}

.drawer-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

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

.drawer-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--surface-3);
    border-bottom: 1px solid var(--border-color);
}

.user-avatar {
    font-size: 1.5rem;
    background: var(--accent-soft);
    padding: 8px;
    border-radius: 50%;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    color: var(--text);
    font-size: 0.9rem;
}

.user-role {
    font-size: 0.72rem;
    color: var(--text-subtle);
}

.drawer-nav {
    display: flex;
    flex-direction: column;
    padding: 14px 12px;
    gap: 6px;
    flex: 1;
}

.drawer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 8px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: var(--transition-fast);
}

.drawer-item:hover {
    background: var(--surface-3);
    color: var(--text);
}

.drawer-item.active {
    background: var(--accent-soft);
    border-color: var(--accent-border);
    color: var(--accent-cyan);
    font-weight: 600;
}

.drawer-item.danger {
    color: #fb7185;
}

.drawer-item.danger:hover {
    background: var(--danger-soft);
    border-color: var(--danger-border);
}

.drawer-icon {
    font-size: 1.1rem;
}

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

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--overlay);
    backdrop-filter: none;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    color: var(--text-strong);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    background: var(--overlay);
    border-top: 1px solid var(--border-color);
}

.danger-modal {
    border-color: var(--danger-border);
    box-shadow: none;
}

.danger-input {
    width: 100%;
    padding: 8px 12px;
    margin-top: 10px;
    background: var(--surface-2);
    border: 1px solid var(--danger-border);
    border-radius: 6px;
    color: var(--text-strong);
    font-family: var(--font-body); font-variant-numeric: tabular-nums;
    font-size: 0.95rem;
    box-sizing: border-box;
}

.danger-input:focus {
    outline: none;
    border-color: var(--danger);
    box-shadow: none;
}

.calib-btn.danger {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

.calib-btn.danger:hover:not(:disabled) {
    background: var(--danger-soft);
}

.calib-btn.danger:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Dedicated Full-Screen Login Page */
.login-page-view {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    background: var(--viewer-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
    box-sizing: border-box;
}

.login-page-view.hidden {
    display: none !important;
}

.login-container {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* Logout Notification Toast */
.logout-toast {
    width: 100%;
    box-sizing: border-box;
    background: var(--success-soft);
    border: 1px solid var(--success-border);
    color: var(--success);
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 0.92rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: none;
    animation: toastFadeIn 250ms ease-out forwards;
    transition: opacity 300ms ease, transform 300ms ease;
}

.logout-toast-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: var(--success);
    color: var(--text-strong);
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
}

.logout-toast.fade-out {
    opacity: 0;
    transform: translateY(-8px);
}

.logout-toast.hidden {
    display: none !important;
}

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

/* Login Card inside Login Page */
.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 32px 28px;
    box-shadow: var(--shadow-md);
    box-sizing: border-box;
}

.login-brand {
    text-align: center;
    margin-bottom: 20px;
}

.login-brand .logo-icon.large {
    width: 44px;
    height: 44px;
    margin: 0 auto 12px auto;
}

.login-brand h2 {
    font-family: var(--font-heading);
    color: var(--text-strong);
    font-size: 1.35rem;
}

.login-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-error {
    background: var(--danger-soft);
    border: 1px solid var(--danger-border);
    color: var(--danger);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.78rem;
    text-align: center;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
}

.login-input {
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-strong);
    font-family: inherit;
    font-size: 0.85rem;
}

.login-input:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: none;
}

.login-btn {
    margin-top: 6px;
    padding: 10px;
    font-weight: 600;
}

/* Editable Tooth Width Input & Overrides */
.tooth-width-cell {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.tooth-width-input {
    width: 58px;
    padding: 3px 5px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--font-body); font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
    font-weight: 600;
    text-align: right;
    transition: var(--transition-fast);
}

.tooth-width-input:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: none;
    background: var(--surface);
}

.tooth-width-input.has-override {
    border-color: var(--accent-amber);
    color: var(--warning);
}

.override-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    font-size: 0.62rem;
    font-weight: 700;
    border-radius: 3px;
    background: var(--warning-soft);
    color: var(--warning);
    border: 1px solid var(--warning-border);
    cursor: help;
}

.btn-clear-override {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}

.btn-clear-override:hover {
    color: var(--danger);
}

/* FDI 3D Floating Labels & Leader Lines */
.labels-svg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 8;
}

.tooth-label-3d.has-conflict {
    border-color: var(--danger) !important;
    background: var(--danger-soft) !important;
    color: var(--danger) !important;
}

.tooth-label-3d.has-conflict::after {
    content: " ⚠️";
    font-size: 0.6rem;
}

/* Place Line Button and Placement Workflow */
.btn-place-line {
    background: var(--accent-soft);
    border: 1px solid var(--accent-cyan);
    color: var(--accent-cyan);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-place-line:hover {
    background: var(--accent-soft);
    box-shadow: none;
}

.unmeasured-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-style: italic;
    margin-right: 4px;
}

.status-pill.unplaced {
    background-color: var(--surface-3);
    color: var(--text-muted);
    border: 1px dashed var(--border-strong);
}

.status-pill.provisional {
    background-color: var(--warning-soft);
    color: var(--accent-amber);
    border: 1px solid var(--warning-border);
}

.placement-banner {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--accent-cyan);
    border-radius: 8px;
    padding: 8px 16px;
    z-index: 100;
    box-shadow: var(--shadow-md);
    backdrop-filter: none;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 500;
    pointer-events: auto;
}

.placement-banner.hidden {
    display: none !important;
}

.placement-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--accent-cyan);
    box-shadow: none;
    animation: pulse 1.2s infinite;
}

.btn-cancel-placement {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.btn-cancel-placement:hover {
    color: var(--danger);
}

/* Orthodontic Analysis View */
.orthodontic-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 4px;
    gap: 14px;
}

.ortho-header-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    backdrop-filter: none;
}

.back-btn {
    padding: 6px 14px;
    font-size: 0.78rem;
}

.case-summary-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.summary-badge {
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--text);
}

/* ==========================================================================
   Orthodontic View: View Mode Toggle (legacy styles)
   ========================================================================== */
.ortho-view-mode-toggle {
    display: inline-flex;
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
}

.view-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: 1;
}

.view-toggle-btn:hover:not(.active) {
    color: var(--text);
    background: var(--surface-3);
}

.view-toggle-btn.active {
    background: var(--accent-soft);
    border-color: var(--accent-border);
    color: var(--accent-cyan);
    box-shadow: none;
}

.view-toggle-btn:focus-visible {
    outline: 2px solid var(--accent-cyan);
    outline-offset: 2px;
}

/* Screen Reader Only Utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ==========================================================================
   Orthodontic Main Display Area (Grid)
   ========================================================================== */
.ortho-display-container {
    width: 100%;
    position: relative;
    padding-bottom: 24px;
}

/* Legacy fallback class */
.ortho-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 14px;
    padding-bottom: 24px;
}

/* Base Card Styling */
.ortho-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    backdrop-filter: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    transition: border-color var(--transition-fast);
}

.ortho-card:hover {
    border-color: var(--accent-border);
}

/* Focus button inside card header (Grid mode only) */
.btn-card-focus {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    border-radius: 6px;
    color: var(--accent-cyan);
    font-size: 0.70rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: 1;
    margin-left: auto;
}

/* Prevent SVG children from capturing the click event */
.btn-card-focus *,
.btn-card-focus svg,
.btn-card-focus polyline,
.btn-card-focus line,
.btn-card-focus span {
    pointer-events: none;
}

.btn-card-focus:hover {
    background: var(--accent-soft);
    border-color: var(--accent-cyan);
    box-shadow: none;
    transform: translateY(-1px);
}

.btn-card-focus:focus-visible {
    outline: 2px solid var(--accent-cyan);
    outline-offset: 2px;
}

.btn-card-focus + .card-status-pill {
    margin-left: 8px;
}

.ortho-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-3);
}

.card-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent-cyan);
    border: 1px solid var(--accent-cyan-glow);
    font-weight: 700;
    font-size: 0.85rem;
}

.card-title {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-strong);
}

.card-subtitle {
    font-size: 0.7rem;
    color: var(--text-subtle);
    margin-top: 2px;
}

.ortho-card-body {
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 0.82rem;
    color: var(--text);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
}

.metric-box {
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.metric-title {
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

.metric-val {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: var(--font-body); font-variant-numeric: tabular-nums;
    color: var(--text);
}

.metric-val.highlight {
    color: var(--accent-cyan);
}

.metric-val.warning {
    color: var(--accent-amber);
}

.metric-val.danger {
    color: var(--accent-rose);
}

.metric-val.success {
    color: var(--accent-emerald);
}

.ortho-input-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}

.ortho-input {
    width: 90px;
    padding: 4px 8px;
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-strong);
    font-family: var(--font-body); font-variant-numeric: tabular-nums;
    font-size: 0.8rem;
    text-align: right;
}

.ortho-input:focus {
    outline: none;
    border-color: var(--accent-cyan);
}

.interpretation-box {
    background: var(--surface-2);
    border-left: 3px solid var(--accent-cyan);
    padding: 10px 12px;
    border-radius: 4px;
    font-size: 0.78rem;
    line-height: 1.4;
}

.interpretation-box.extraction {
    border-left-color: var(--accent-rose);
    background: var(--danger-soft);
}

.interpretation-box.borderline {
    border-left-color: var(--accent-amber);
    background: var(--warning-soft);
}

.interpretation-box.non-extraction {
    border-left-color: var(--accent-emerald);
    background: var(--success-soft);
}

/* Card Status Pills & Diagnostics */
.card-status-pill {
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 0.70rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    margin-left: auto;
}

.card-status-pill.status-complete {
    background: var(--success-soft);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.card-status-pill.status-needs_dentist_verification {
    background: var(--warning-soft);
    color: var(--warning);
    border: 1px solid var(--warning-border);
}

.card-status-pill.status-missing_measurements {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

.card-status-pill.status-additional_measurements_required {
    background: var(--accent-soft);
    color: var(--accent-text);
    border: 1px solid var(--accent-border);
}

.card-status-pill.status-reference_data_unavailable {
    background: var(--violet-soft);
    color: var(--violet);
    border: 1px solid var(--violet-border);
}

.card-status-pill.status-not_applicable {
    background: var(--surface-3);
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
}

.diag-banner {
    font-size: 0.74rem;
    padding: 6px 10px;
    border-radius: 6px;
    line-height: 1.4;
}

.diag-banner.warning {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

.diag-banner.info {
    background: var(--warning-soft);
    color: var(--warning);
    border: 1px solid var(--warning-border);
}

.diag-banner.notice {
    background: var(--accent-soft);
    color: var(--accent-text);
    border: 1px solid var(--accent-border);
}

.hidden {
    display: none !important;
}

/* ==========================================================================
   Analytics grid (grid only) + focus popup
   ========================================================================== */
.ortho-cards-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    align-items: stretch;
}

@media (min-width: 640px) and (max-width: 1099.98px) {
    .ortho-cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
}

@media (max-width: 639.98px) {
    .ortho-cards-grid { grid-template-columns: 1fr; gap: 14px; }
}

.ortho-card-placeholder {
    border: 1px dashed var(--accent-border);
    border-radius: 14px;
    background: var(--accent-soft);
}

.focus-overlay {
    background: var(--overlay) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    padding: 32px;
}

.focus-modal-shell {
    position: relative;
    width: min(1100px, 100%);
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    border-radius: 16px;
}

.focus-modal-content .ortho-card {
    background: var(--surface);
    border-color: var(--accent-border);
    box-shadow: var(--shadow-md);
}

.focus-modal-content .ortho-card-header { padding: 18px 64px 18px 24px; }
.focus-modal-content .card-title { font-size: 1.2rem; }
.focus-modal-content .card-subtitle { font-size: 0.8rem; }
.focus-modal-content .ortho-card-body { padding: 22px 24px; font-size: 0.95rem; gap: 16px; }
.focus-modal-content .metric-title { font-size: 0.8rem; }
.focus-modal-content .metric-val { font-size: 1.25rem; }
.focus-modal-content .interpretation-box { font-size: 0.92rem; }
.focus-modal-content .btn-card-focus { display: none; }

.focus-close-btn {
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 2;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.focus-close-btn:hover { border-color: var(--accent-cyan); color: var(--accent-cyan); }

@media (max-width: 640px) {
    .focus-overlay { padding: 12px; }
    .focus-modal-shell { max-height: calc(100vh - 24px); }
}

.arch-cols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.arch-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--surface-2);
}

.arch-col-title {
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text);
    font-size: 0.85rem;
}

.metric-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.metric-sub {
    font-size: 0.68rem;
    color: var(--text-subtle);
    margin-top: 2px;
}

.src-tag {
    display: inline-block;
    font-size: 0.62rem;
    padding: 1px 6px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-weight: 600;
}
.src-tag.drawn { color: var(--success); border-color: var(--success-border); }
.src-tag.auto { color: var(--warning); border-color: var(--warning-border); }
.src-tag.missing { color: var(--danger); border-color: var(--danger-border); }

.inference-line { padding: 4px 0; }
.inference-line + .inference-line { border-top: 1px solid var(--border-color); }

.formula-note {
    font-size: 0.7rem;
    color: var(--text-subtle);
    line-height: 1.45;
}

.card-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.draw-arch-btn {
    background: var(--warning-soft) !important;
    border: 1px solid var(--warning-border) !important;
    color: var(--warning) !important;
    font-weight: 600;
}
.draw-arch-btn:hover { background: var(--warning-soft) !important; color: var(--text-strong) !important; }

.mini-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.mini-table th, .mini-table td { padding: 5px 6px; border-bottom: 1px solid var(--border-color); text-align: left; vertical-align: top; }
.mini-table th { color: var(--text-muted); font-weight: 600; }
.text-right { text-align: right; }
/* Visit analysis summary: every cell centred vertically so status pills line up */
.summary-table { table-layout: fixed; }
.summary-table td { vertical-align: middle; }
.summary-table col.col-name { width: 130px; }
.summary-table col.col-status { width: 190px; }
.summary-table .card-status-pill { display: inline-block; white-space: nowrap; line-height: 1.4; margin-left: 0; }
.summary-table .cell-message { max-width: none; }

/* ==========================================================================
   Arch measurement line tools (MMV / MPV / PPL)
   ========================================================================== */

.arch-tool-btn {
    background: var(--tool-bg) !important;
    border: 1px solid var(--tool-color) !important;
    color: var(--tool-text) !important;
    font-weight: 600 !important;
    cursor: pointer;
    transition: all 0.2s ease;
}
.arch-tool-btn:hover, .arch-tool-btn.active {
    background: var(--tool-bg-strong) !important;
    box-shadow: none !important;
    color: var(--text-strong) !important;
}

/* Sidebar card listing the three lines: one row each, colour swatch + name + value */
.arch-line-hint { font-size: 11px; color: var(--text-subtle); margin: 0 0 8px; line-height: 1.45; }
.arch-line-card {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--surface-2);
    overflow: hidden;
}
.arch-line-row { display: flex; align-items: center; min-width: 0; }
.arch-line-row + .arch-line-row { border-top: 1px solid var(--border-color); }
.arch-line-item {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 4px 9px 12px;
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition-fast), box-shadow var(--transition-fast);
}
.arch-line-row:hover { background: var(--surface-3); }
.arch-line-item:focus-visible { outline: 2px solid var(--tool-color); outline-offset: -2px; }
.arch-line-item.active { background: var(--tool-bg); box-shadow: inset 3px 0 0 var(--tool-color); }
.arch-line-item:disabled, .arch-tool-btn:disabled { cursor: not-allowed; opacity: 0.45; }
.arch-line-item:disabled .arch-swatch { box-shadow: none; }
.arch-tool-btn:disabled { box-shadow: none !important; }
.arch-swatch {
    flex: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--tool-color);
    box-shadow: 0 0 0 3px var(--tool-bg);
}
.arch-line-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.arch-line-name { font-size: 0.82rem; font-weight: 700; letter-spacing: 0.04em; color: var(--text); }
.arch-line-desc { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arch-tool-val { flex: none; font-size: 0.82rem; font-weight: 600; color: var(--tool-text, var(--text)); font-variant-numeric: tabular-nums; white-space: nowrap; }
.arch-tool-val.empty { color: var(--text-subtle); font-weight: 500; }
.arch-remove-btn {
    flex: none;
    width: 28px;
    height: 28px;
    margin: 0 8px 0 4px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-subtle);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.arch-remove-btn:hover:not(:disabled) { color: var(--accent-rose); background: var(--danger-soft); border-color: var(--danger-border); }
.arch-remove-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.arch-line-footer { display: flex; justify-content: flex-end; margin-top: 6px; }
.arch-remove-all {
    background: none;
    border: none;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.75rem;
    padding: 4px 2px;
    cursor: pointer;
}
.arch-remove-all:hover:not(:disabled) { color: var(--accent-rose); text-decoration: underline; }
.arch-remove-all:disabled { opacity: 0.4; cursor: not-allowed; }

.floating-arch-badge {
    position: absolute;
    background: var(--surface);
    border: 1.5px solid var(--badge-color, var(--danger));
    color: var(--badge-text, var(--danger));
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    font-family: var(--font-heading);
    pointer-events: none;
    user-select: none;
    transform: translate(-50%, -100%);
    box-shadow: var(--shadow-sm);
    z-index: 25;
    white-space: nowrap;
}

.arch-confirm-banner[data-tool="mmv"] { border-color: var(--danger-border); }
.arch-confirm-banner[data-tool="mpv"] { border-color: var(--warning-border); }
.arch-confirm-banner[data-tool="ppl"] { border-color: var(--violet-border); }
.arch-source { color: var(--text-muted); font-size: 0.72rem; }

.verify-all-row { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.verify-all-row .calib-btn { flex: 1; }

/* ==========================================================================
   Resizable workspace panels
   ========================================================================== */
.main-content {
    grid-template-columns: 320px 8px minmax(320px, 1fr) 8px 340px;
    gap: 4px;
}

.panel-resizer {
    cursor: col-resize;
    border-radius: 4px;
    position: relative;
    touch-action: none;
    outline: none;
}
.panel-resizer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 48px;
    transform: translate(-50%, -50%);
    border-radius: 2px;
    background: var(--surface-3);
    transition: background var(--transition-fast), height var(--transition-fast);
}
.panel-resizer:hover::after,
.panel-resizer:focus-visible::after,
.panel-resizer.dragging::after {
    background: var(--accent-cyan);
    height: 96px;
}
body.resizing-panels, body.resizing-panels * { cursor: col-resize !important; user-select: none !important; }

/* ==========================================================================
   Read-only (referred) workspace
   ========================================================================== */
body.read-only .owner-only { display: none !important; }
body.read-only .owner-only-block { display: none !important; }
body.read-only .upload-box { cursor: not-allowed; opacity: 0.75; }

.readonly-badge {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 999px;
    color: var(--warning);
    border: 1px solid var(--warning-border);
    background: var(--warning-soft);
    white-space: nowrap;
}

.case-context {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 14px;
    border-left: 1px solid var(--border-color);
    min-width: 0;
}
.case-context-name { font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.case-context-meta { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.nav-pill:disabled { opacity: 0.4; cursor: not-allowed; }
.drawer-item:disabled { opacity: 0.45; cursor: not-allowed; }

/* ==========================================================================
   Dashboard, patient history, doctors
   ========================================================================== */
.page-view {
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 4px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.page-title { font-family: var(--font-heading); font-size: 1.35rem; color: var(--text-strong); }
.page-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.page-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.action-btn.compact { width: auto; margin: 0; padding: 8px 16px; }

.search-input {
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text);
    padding: 8px 12px;
    font-family: inherit;
    min-width: 220px;
}
.search-input:focus { outline: none; border-color: var(--accent-cyan); }

.tab-bar { display: flex; gap: 6px; }
.tab-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 7px 14px;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
}
.tab-btn.active { color: var(--accent-cyan); border-color: var(--accent-border); background: var(--accent-soft); }
.tab-count { font-size: 0.7rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-3); margin-left: 4px; }

.data-panel { padding: 0; overflow: hidden; }
.data-panel .table-container { overflow: auto; max-height: none; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.data-table th {
    position: sticky;
    top: 0;
    background: #111a2c;
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    z-index: 1;
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border-color); vertical-align: top; }
.data-table tr:hover td { background: var(--surface-3); }
.data-table .patient-cont-row td { border-top: none; padding-top: 4px; }
.data-table .patient-first-row td { border-top: 1px solid var(--border); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
/* In tables the actions cell must stay a real table cell (flex on a <td> breaks row and border alignment) */
td.row-actions { display: table-cell; text-align: right; vertical-align: middle; white-space: normal; }
td.row-actions > * { display: inline-flex; vertical-align: middle; margin: 2px 0 2px 6px; }
.cell-sub { font-size: 0.72rem; color: var(--text-subtle); margin-top: 2px; }
.cell-message { max-width: 280px; color: var(--text); white-space: pre-wrap; }
.link-btn { color: var(--accent-cyan); text-decoration: none; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.muted-text { color: var(--text-subtle); font-size: 0.78rem; }

.mini-badge {
    display: inline-block;
    font-size: 0.66rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    color: var(--text);
    margin: 1px 3px 1px 0;
    white-space: nowrap;
}
.mini-badge.open { color: var(--accent-text); border-color: var(--accent-border); }
.mini-badge.returned { color: var(--warning); border-color: var(--warning-border); }

.patient-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 14px;
    align-items: start;
}
@media (max-width: 1000px) { .patient-layout { grid-template-columns: 1fr; } }
.patient-side { display: flex; flex-direction: column; gap: 14px; }

.visit-list { display: flex; flex-direction: column; gap: 10px; }
.visit-card {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 14px;
    background: var(--surface-2);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.visit-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.visit-date { font-weight: 700; color: var(--text); }
.visit-summary { border-top: 1px solid var(--border-color); padding-top: 8px; }

.detail-list { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 0.8rem; }
.detail-list dt { color: var(--text-subtle); }
.detail-list dd { color: var(--text); word-break: break-word; }

.referral-list, .note-list { display: flex; flex-direction: column; gap: 8px; font-size: 0.8rem; }
.referral-item, .note-item { border: 1px solid var(--border-color); border-radius: 8px; padding: 8px 10px; }
.referral-msg { margin-top: 4px; color: var(--text); white-space: pre-wrap; }
.referral-msg.returned { color: #fde68a; }
.note-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.note-body { margin-top: 4px; white-space: pre-wrap; color: var(--text); }
.note-form { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.note-form textarea, .form-field input, .form-field select, .form-field textarea {
    background: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text);
    padding: 7px 10px;
    font-family: inherit;
    font-size: 0.82rem;
    width: 100%;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus, .note-form textarea:focus {
    outline: none;
    border-color: var(--accent-cyan);
}

/* Forms in modals */
.wide-modal { max-width: 720px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid.single { grid-template-columns: 1fr; }
.form-field { display: flex; flex-direction: column; gap: 5px; font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }
.form-field.span-2 { grid-column: 1 / -1; }
.form-error {
    grid-column: 1 / -1;
    color: var(--danger);
    background: var(--danger-soft);
    border: 1px solid var(--danger-border);
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 0.8rem;
}
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.modal-card { max-height: calc(100vh - 40px); }
.modal-card > .modal-body { overflow-y: auto; }

.stepper { display: flex; gap: 8px; padding: 10px 20px 0; }
.step {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    color: var(--text-subtle);
}
.step.active { color: var(--accent-cyan); border-color: var(--accent-border); }

/* ==========================================================================
   Carey's arch length drawing popup
   ========================================================================== */
.arch-draw-shell {
    width: min(1200px, 100%);
    height: min(820px, calc(100vh - 40px));
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}
.arch-draw-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-color);
}
.arch-draw-header h3 { font-family: var(--font-heading); color: var(--text-strong); font-size: 1.05rem; }
.arch-draw-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}
.arch-draw-hint { font-size: 0.75rem; color: var(--text-muted); flex: 1; min-width: 200px; }
.seg-toggle { display: inline-flex; border: 1px solid var(--border-color); border-radius: 8px; padding: 3px; gap: 3px; }
.seg-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 5px 12px;
    border-radius: 6px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.78rem;
    cursor: pointer;
}
.seg-btn.active { color: var(--warning); border-color: var(--warning-border); background: var(--warning-soft); }
.arch-draw-canvas { flex: 1; min-height: 0; position: relative; }
.arch-draw-canvas canvas { display: block; }
.arch-draw-footer {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 18px;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}
.arch-length-readout { display: flex; flex-direction: column; }
.arch-length-edit { display: flex; flex-direction: column; gap: 4px; font-size: 0.72rem; color: var(--text-muted); font-weight: 600; }
.arch-length-edit input { width: 160px; }

/* Arch line save bar: compact, in the top-right corner of the 3D view (opposite the overlays panel),
   so it never sits over the arch where the line points are dragged */
.arch-confirm-banner {
    top: 12px;
    right: 12px;
    bottom: auto;
    left: auto;
    transform: none;
    max-width: min(280px, calc(100% - 24px));
    flex-wrap: wrap;
    padding: 6px 10px;
    gap: 6px 8px;
    font-size: 0.76rem;
}
.arch-confirm-banner #arch-confirm-text { flex: 1 1 100%; line-height: 1.35; }

/* Card headers: title takes the free space; Focus and status wrap under it on narrow cards */
.ortho-card-header { flex-wrap: wrap; row-gap: 8px; }
.ortho-card-header > div { flex: 1 1 160px; min-width: 0; }
.ortho-card-header .btn-card-focus { margin-left: 0; }

.page-header .back-btn,
.ortho-header-banner .back-btn { width: auto; margin: 0; white-space: nowrap; flex: 0 0 auto; }

/* Make room for the open case in the header */
.app-header:has(.case-context:not(.hidden)) .logo-container .badge { display: none; }

/* Refresh Analyses feedback */
.refresh-note { font-size: 0.72rem; color: var(--success); min-width: 110px; }
.refresh-skeleton {
    height: 44px;
    border-radius: 8px;
    background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
    background-size: 200% 100%;
    animation: refresh-shimmer 1s linear infinite;
}
.refresh-skeleton.short { width: 60%; height: 28px; }
@keyframes refresh-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .refresh-skeleton { animation: none; } }

/* Carey wire controls */
.wire-points { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }
.wire-points b { min-width: 18px; text-align: center; color: var(--warning); }
.wire-step { padding: 2px 9px; }

/* ==========================================================================
   Role-specific navigation (drawer items, bell) — hidden until the role is known
   ========================================================================== */
.app-container:not([data-role="doctor"]):not([data-role="visitor"]) .role-doctor,
.app-container:not([data-role="admin"]) .role-admin { display: none !important; }

.drawer-badge, .bell-badge {
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9999px;
    background: var(--accent-rose); color: var(--text-strong); font-size: 0.68rem; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
.drawer-badge { margin-left: auto; }
.drawer-badge.hidden, .bell-badge.hidden { display: none; }

.bell-btn {
    position: relative; width: 36px; height: 36px; border-radius: 10px;
    background: var(--surface-3); border: 1px solid var(--border-color);
    color: var(--text); font-size: 1rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.bell-btn:hover { border-color: var(--accent-cyan); }
.bell-btn .bell-badge { position: absolute; top: -6px; right: -6px; }

.next-visit-chip {
    background: var(--accent-soft); border: 1px solid var(--border-color-glow); color: var(--accent-cyan);
    border-radius: 9999px; padding: 3px 10px; font-size: 0.72rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.next-visit-chip:hover { background: var(--accent-soft); }

.calib-btn.icon-danger {
    background: transparent; border: 1px solid var(--danger-border); color: var(--accent-rose); padding-inline: 8px;
}
.calib-btn.icon-danger:hover { background: var(--danger-soft); }

.next-visit-hint { color: var(--text-muted); }
.next-visit-hint.overdue { color: var(--accent-rose); font-weight: 600; }
.next-visit-hint.today { color: var(--accent-amber); font-weight: 600; }
.next-visit-hint.soon { color: var(--accent-cyan); }
.small-link { background: none; border: none; cursor: pointer; font-size: 0.74rem; padding: 0 4px; }

/* Verify contact points (LII) popup */
.contact-verify-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 260px; }
.contact-verify-side {
    border-left: 1px solid var(--border-color); padding: 14px; overflow-y: auto;
    display: flex; flex-direction: column; gap: 10px; background: var(--surface-2);
}
.contact-verify-side .section-title { margin: 0; }
.cv-table td, .cv-table th { vertical-align: middle; }
.cv-table tfoot th { color: var(--text); font-size: 0.82rem; border-top: 1px solid var(--border-color); }
.cv-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; vertical-align: middle; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--border); }
.cv-row td:first-child { border-left: 3px solid var(--cv-color); padding-left: 8px; }
.cv-severity { font-weight: 700; color: var(--accent-cyan); font-size: 0.9rem; }
.cv-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.cv-label {
    position: absolute; transform: translate(-50%, -150%); white-space: nowrap;
    background: var(--surface); color: var(--text); border: 1px solid var(--cv-color, var(--accent));
    border-radius: 6px; padding: 2px 7px; font-size: 0.7rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.cv-label.below { transform: translate(-50%, 60%); }
.lii-col .arch-col-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.lii-col .mini-table { margin: 8px 0; }
.lii-col-status {
    font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
    padding: 2px 8px; border-radius: 9999px; border: 1px solid var(--border-strong); color: var(--text-muted);
}
.lii-col-status.status-complete { color: var(--success); border-color: var(--success-border); }
.lii-col-status.status-needs_dentist_verification { color: var(--warning); border-color: var(--warning-border); }
.lii-col-status.status-missing_measurements { color: var(--danger); border-color: var(--danger-border); }
.cv-card-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 4px; }
@media (max-width: 900px) {
    .contact-verify-body { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
    .contact-verify-side { border-left: none; border-top: 1px solid var(--border-color); max-height: 38vh; }
}

/* Scan stage badge */
.scan-stage-badge {
    display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 9999px;
    font-size: 0.68rem; font-weight: 700; letter-spacing: 0.03em; white-space: nowrap; vertical-align: middle;
    color: var(--violet); background: var(--violet-soft); border: 1px solid var(--violet-border);
}
.scan-stage-badge.is-baseline { color: var(--success); background: var(--success-soft); border-color: var(--success-border); }
.scan-stage-badge.is-pre { color: var(--text-muted); background: var(--surface-3); border-color: var(--border-strong); }
.scan-stage-badge.hidden { display: none; }

/* Admin clinic overview */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat-tile { background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 12px; padding: 12px 16px; }
.stat-value { font-family: var(--font-heading); font-size: 1.6rem; font-weight: 700; color: var(--text-strong); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.admin-doctor-list { display: flex; flex-direction: column; gap: 10px; }
.admin-doctor { padding: 0; overflow: hidden; }
.admin-doctor-head {
    width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 16px;
    background: none; border: none; color: inherit; cursor: pointer; text-align: left; font: inherit;
}
.admin-doctor-head:hover { background: var(--surface-3); }
.admin-caret { color: var(--accent-cyan); width: 12px; }
.admin-doctor-name { font-weight: 700; color: var(--text-strong); }
.admin-count { margin-left: auto; color: var(--text-muted); font-size: 0.8rem; }
.admin-doctor .table-container { border-top: 1px solid var(--border-color); }
.admin-empty { padding: 0 16px 14px 38px; }

/* Actions Due: every group's table uses the same fixed column widths, so columns line up */
.actions-table { table-layout: fixed; width: 100%; }
.actions-table col.c-date { width: 13%; }
.actions-table col.c-uhid { width: 11%; }
.actions-table col.c-patient { width: 18%; }
.actions-table col.c-contact { width: 15%; }
.actions-table col.c-purpose { width: 15%; }
.actions-table col.c-status { width: 11%; }
.actions-table col.c-actions { width: 17%; }
.actions-table td, .actions-table th { overflow: hidden; text-overflow: ellipsis; }
.actions-table .cell-message { max-width: none; }

.admin-doctor-bar { display: flex; align-items: center; gap: 8px; padding-right: 12px; }
.admin-doctor-bar .admin-doctor-head { flex: 1; min-width: 0; }
.admin-edit-btn { flex: none; }

/* Actions Due */
.actions-list { display: flex; flex-direction: column; gap: 12px; }
.action-group.overdue .section-title { color: var(--accent-rose); }
.action-group.today .section-title { color: var(--accent-amber); }
.data-table td { vertical-align: middle; }

/* ==========================================================================
   Workspace left panel: scroll inside the card (content used to spill past its bottom edge)
   ========================================================================== */
.control-panel {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.3) transparent;
}
.control-panel > .panel-section { flex-shrink: 0; }
/* Sections flow one after another; the last one is not pushed to the bottom of the card */
.control-panel > .panel-section:last-child { margin-top: 0; }

/* 3D viewport header: title stays on one line, tool groups wrap as whole units */
.viewport-header { flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; }
.view-indicator { white-space: nowrap; }
.viewport-actions { flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; }
.viewport-actions .icon-btn { white-space: nowrap; }
.viewport-actions .arch-buttons-group { flex-wrap: nowrap; align-items: center; }
.viewport-actions .arch-buttons-group > button {
    white-space: nowrap;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    line-height: 1.2;
}

/* Header: the left side (logo + case context) shrinks and truncates; the nav on the right never gets overlapped */
.app-header { gap: 12px; }
.app-header .header-left { flex: 1 1 auto; min-width: 0; overflow: hidden; }
.app-header .header-right { flex: none; }
.app-header .logo-container { flex: none; }
.case-context { flex: 1 1 auto; overflow: hidden; }
.case-context-meta { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.next-visit-chip { flex: none; }
@media (max-width: 1180px) {
    .app-header .logo-container h1 { font-size: 1.05rem; }
    .case-context-meta { display: none; }
}
.case-context-name { flex: 0 1 auto; min-width: 70px; }
@media (max-width: 1180px) {
    .next-visit-chip .nv-word { display: none; }
}
@media (max-width: 1180px) {
    .app-header:has(.case-context:not(.hidden)) .logo-container h1 { display: none; }
}
.data-table th.text-right, .data-table td.text-right { text-align: right; }
.data-table td:first-child { white-space: nowrap; }
/* Accounts page: the wide accounts table needs the full width before the side form */
@media (max-width: 1280px) {
    #doctors-view .patient-layout { grid-template-columns: 1fr; }
    #doctors-view .patient-side .form-grid.single { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #doctors-view .patient-side .form-grid.single > .form-error,
    #doctors-view .patient-side .form-grid.single > button { grid-column: 1 / -1; }
}

/* ==========================================================================
   DESIGN SYSTEM: shared components (applies to every screen, both themes).
   Kept last in the file so it is the single source of truth for look and feel.
   ========================================================================== */

/* ── Base & typography ── */
html { font-size: 15px; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--fs-md);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "cv11", "ss01";
}
h1, h2, h3, h4, .page-title, .card-title, .modal-header h3 { font-family: var(--font-body); color: var(--text-strong); letter-spacing: -0.01em; }
.page-title { font-size: var(--fs-2xl); font-weight: 650; }
.page-subtitle, .card-subtitle { color: var(--text-muted); font-size: var(--fs-sm); }
.muted-text, .cell-sub { color: var(--text-muted); }
a, .link-btn { color: var(--accent-text); }
.link-btn:hover { color: var(--accent-hover); }
::selection { background: var(--accent-soft); color: var(--text-strong); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* Section headings: sentence case, no neon bar */
.section-title {
    font-family: var(--font-body);
    font-size: var(--fs-sm);
    font-weight: 650;
    color: var(--text-strong);
    text-transform: none;
    letter-spacing: 0;
    border-left: none;
    padding-left: 0;
    margin-bottom: 10px;
}
.section-title::before, .section-title::after { display: none; }

/* ── Surfaces ── */
.panel, .ortho-card, .modal-card, .login-card, .stat-tile, .arch-draw-shell, .admin-doctor {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.panel:hover, .ortho-card:hover { border-color: var(--border); box-shadow: var(--shadow-sm); transform: none; }
.app-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.app-header h1 { color: var(--text-strong); font-weight: 700; font-size: 1.05rem; letter-spacing: 0.02em; }
.logo-icon { background: var(--accent); box-shadow: none; }
.logo-container .badge {
    background: var(--accent-soft); color: var(--accent-text); border: 1px solid var(--accent-border);
    font-weight: 600; text-transform: none; letter-spacing: 0;
}
.header-status .status-text { color: var(--text-muted); }
.status-indicator.online { background: var(--success); box-shadow: none; }

/* Top navigation: a calm segmented control */
.nav-view-pills { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 3px; }
.nav-pill {
    color: var(--text-muted); border-radius: 7px; font-weight: 550; font-size: var(--fs-sm);
    background: transparent; box-shadow: none;
}
.nav-pill:hover:not(:disabled) { color: var(--text-strong); background: var(--surface-3); }
.nav-pill.active { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm); border: 1px solid var(--border); }

/* ── Buttons: three kinds only (primary, secondary, tool) + danger ── */
.action-btn, .calib-btn, .icon-btn, .login-btn, .action-btn-sm, .seg-btn, .btn-confirm-save, .btn-confirm-cancel,
.btn-cancel-placement, .drawer-close-btn, .modal-close, .hamburger-btn, .bell-btn {
    font-family: var(--font-body);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring) !important;
}
button:disabled, .action-btn:disabled, .calib-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Primary: filled accent */
.action-btn.primary-btn, .action-btn.success-btn, .calib-btn.primary, .calib-btn.success, .login-btn, .btn-confirm-save {
    background: var(--accent) !important;
    color: var(--accent-contrast) !important;
    border: 1px solid var(--accent) !important;
    border-radius: 8px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}
.action-btn.primary-btn:hover:not(:disabled), .action-btn.success-btn:hover:not(:disabled), .calib-btn.primary:hover:not(:disabled),
.calib-btn.success:hover:not(:disabled), .login-btn:hover:not(:disabled), .btn-confirm-save:hover:not(:disabled) {
    background: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
    transform: none;
    box-shadow: var(--shadow-md);
}

/* Secondary: outlined neutral */
.action-btn.secondary-btn, .calib-btn.secondary, .calib-btn.cancel, .icon-btn, .btn-confirm-cancel, .btn-cancel-placement {
    background: var(--surface) !important;
    color: var(--text) !important;
    border: 1px solid var(--border-strong) !important;
    border-radius: 8px;
    font-weight: 550;
    box-shadow: none;
}
.action-btn.secondary-btn:hover:not(:disabled), .calib-btn.secondary:hover:not(:disabled), .calib-btn.cancel:hover:not(:disabled),
.icon-btn:hover:not(:disabled), .btn-confirm-cancel:hover:not(:disabled), .btn-cancel-placement:hover:not(:disabled) {
    background: var(--surface-3) !important;
    color: var(--text-strong) !important;
    border-color: var(--border-strong) !important;
}
.calib-btn { padding: 6px 12px; font-size: var(--fs-sm); }
.icon-btn { padding: 6px 12px; font-size: var(--fs-sm); }
.action-btn { border-radius: 8px; font-size: var(--fs-md); }

/* Danger */
.calib-btn.danger, .calib-btn.icon-danger, .drawer-item.danger {
    background: var(--surface) !important;
    color: var(--danger) !important;
    border: 1px solid var(--danger-border) !important;
}
.calib-btn.danger:hover:not(:disabled), .calib-btn.icon-danger:hover:not(:disabled) { background: var(--danger-soft) !important; }
.calib-btn.danger:not(:disabled):last-child { font-weight: 600; }

/* Tool: "opens the scan to adjust" - icon + label, accent outline, clearly clickable */
.tool-btn, .action-btn-sm, .draw-arch-btn, .card-actions .arch-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px !important;
    border-radius: 8px !important;
    background: var(--accent-soft) !important;
    color: var(--accent-text) !important;
    border: 1px solid var(--accent-border) !important;
    font-size: var(--fs-sm) !important;
    font-weight: 600 !important;
    box-shadow: none !important;
    width: auto;
    text-decoration: none;
}
.tool-btn:hover:not(:disabled), .action-btn-sm:hover:not(:disabled), .draw-arch-btn:hover:not(:disabled), .card-actions .arch-tool-btn:hover:not(:disabled) {
    background: var(--accent) !important;
    color: var(--accent-contrast) !important;
    border-color: var(--accent) !important;
}
.tool-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--tool-color, var(--accent)); flex: none; box-shadow: 0 0 0 2px var(--surface); }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tool-btn-sample {
    display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 6px; font-weight: 600;
    background: var(--accent-soft); color: var(--accent-text); border: 1px solid var(--accent-border); font-size: var(--fs-xs);
}

/* Arch line tools: line colour shown as a dot, never as a full neon fill */
.tool-mmv { --tool-color: var(--line-mmv); --tool-text: var(--text); --tool-bg: color-mix(in srgb, var(--line-mmv) 14%, transparent); --tool-bg-strong: color-mix(in srgb, var(--line-mmv) 24%, transparent); }
.tool-mpv { --tool-color: var(--line-mpv); --tool-text: var(--text); --tool-bg: color-mix(in srgb, var(--line-mpv) 16%, transparent); --tool-bg-strong: color-mix(in srgb, var(--line-mpv) 26%, transparent); }
.tool-ppl { --tool-color: var(--line-ppl); --tool-text: var(--text); --tool-bg: color-mix(in srgb, var(--line-ppl) 14%, transparent); --tool-bg-strong: color-mix(in srgb, var(--line-ppl) 24%, transparent); }
.viewport-actions .arch-tool-btn {
    background: var(--surface) !important;
    color: var(--text) !important;
    border: 1px solid var(--border-strong) !important;
    box-shadow: none !important;
    font-weight: 600 !important;
    display: inline-flex; align-items: center; gap: 6px;
}
.viewport-actions .arch-tool-btn::before {
    content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--tool-color); flex: none;
}
.viewport-actions .arch-tool-btn:hover:not(:disabled), .viewport-actions .arch-tool-btn.active {
    background: var(--tool-bg) !important;
    border-color: var(--tool-color) !important;
    color: var(--text-strong) !important;
}
.floating-arch-badge.badge-mmv { --badge-color: var(--line-mmv); --badge-text: var(--line-mmv); }
.floating-arch-badge.badge-mpv { --badge-color: var(--line-mpv); --badge-text: var(--line-mpv); }
.floating-arch-badge.badge-ppl { --badge-color: var(--line-ppl); --badge-text: var(--line-ppl); }
.arch-line-item.active { background: var(--tool-bg); }

/* ── Chips: one shape for status pills, badges and tags ── */
.card-status-pill, .status-chip, .mini-badge, .src-tag, .readonly-badge, .scan-stage-badge, .status-pill, .lii-col-status,
.summary-badge, .results-count, .next-visit-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 9999px;
    font-size: var(--fs-xs);
    font-weight: 600;
    line-height: 1.5;
    text-transform: none;
    letter-spacing: 0;
    white-space: nowrap;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
    box-shadow: none;
}
.card-status-pill::before, .status-chip::before, .lii-col-status::before {
    content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none;
}
.status-complete { background: var(--success-soft) !important; color: var(--success) !important; border-color: var(--success-border) !important; }
.status-needs_dentist_verification { background: var(--warning-soft) !important; color: var(--warning) !important; border-color: var(--warning-border) !important; }
.status-additional_measurements_required { background: var(--accent-soft) !important; color: var(--accent-text) !important; border-color: var(--accent-border) !important; }
.status-missing_measurements { background: var(--danger-soft) !important; color: var(--danger) !important; border-color: var(--danger-border) !important; }
.status-reference_data_unavailable, .status-not_applicable { background: var(--surface-3) !important; color: var(--text-muted) !important; border-color: var(--border) !important; }

.src-tag { padding: 1px 7px; background: var(--surface); }
.src-tag.drawn { color: var(--success); border-color: var(--success-border); background: var(--success-soft); }
.src-tag.auto { color: var(--warning); border-color: var(--warning-border); background: var(--warning-soft); }
.src-tag.missing { color: var(--danger); border-color: var(--danger-border); background: var(--danger-soft); }
.mini-badge.open { color: var(--success); border-color: var(--success-border); background: var(--success-soft); }
.mini-badge.returned { color: var(--text-muted); }
.readonly-badge { color: var(--warning); border-color: var(--warning-border); background: var(--warning-soft); }
.scan-stage-badge { color: var(--violet); border-color: var(--violet-border); background: var(--violet-soft); }
.scan-stage-badge.is-baseline { color: var(--success); border-color: var(--success-border); background: var(--success-soft); }
.next-visit-chip { color: var(--accent-text); border-color: var(--accent-border); background: var(--accent-soft); cursor: pointer; }
.status-pill.verified { color: var(--success); border-color: var(--success-border); background: var(--success-soft); }
.status-pill.edited, .status-pill.warning, .status-pill.provisional { color: var(--warning); border-color: var(--warning-border); background: var(--warning-soft); }
.status-pill.unresolved, .status-pill.unplaced, .status-pill.fallback { color: var(--danger); border-color: var(--danger-border); background: var(--danger-soft); }
.status-pill.auto { color: var(--accent-text); border-color: var(--accent-border); background: var(--accent-soft); }

/* ── Analysis cards: answer first, details folded ── */
.ortho-card { padding: 0; overflow: hidden; }
.ortho-card-header { background: transparent; border-bottom: 1px solid var(--border); padding: 14px 16px; }
.ortho-card-body { padding: 14px 16px 16px; gap: 10px; font-size: var(--fs-md); }
.card-answer { margin: 0; }
.ortho-card-header > div { flex: 1 1 200px; }
.ortho-card-header .card-status-pill { margin-left: auto; }

/* Analyses page header: title on one line, controls wrap below on narrow screens */
.ortho-header-banner { flex-wrap: wrap; gap: 10px 16px; padding: 12px 16px; }
.ortho-header-banner > div:first-child { flex: 1 1 auto; min-width: 0; }
.ortho-header-banner h2 { white-space: nowrap; font-size: var(--fs-xl) !important; overflow: hidden; text-overflow: ellipsis; }
.ortho-header-banner .back-btn { flex: none; white-space: nowrap; width: auto; }
.case-summary-info { flex-wrap: wrap; justify-content: flex-end; }
#btn-refresh-ortho { white-space: nowrap; }
.ortho-card-header { gap: 10px; align-items: flex-start; }
.card-num {
    background: var(--surface-3); color: var(--text-muted); border: 1px solid var(--border);
    border-radius: 8px; font-weight: 600; box-shadow: none;
}
.card-title { font-size: var(--fs-lg); font-weight: 650; }
.btn-card-focus {
    background: transparent !important; color: var(--text-muted) !important; border: 1px solid transparent !important;
    border-radius: 7px; font-size: var(--fs-xs); font-weight: 600;
}
.btn-card-focus:hover { background: var(--surface-3) !important; color: var(--text-strong) !important; }

.card-answer { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; }
.answer-row {
    display: grid;
    grid-template-columns: minmax(90px, auto) 1fr;
    gap: 4px 12px;
    align-items: baseline;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong);
}
.answer-row.tone-good { border-left-color: var(--success); }
.answer-row.tone-warn { border-left-color: var(--warning); }
.answer-row.tone-bad { border-left-color: var(--danger); }
.answer-row.tone-input { border-left-color: var(--accent); }
.answer-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); }
.answer-text { font-size: var(--fs-md); font-weight: 600; color: var(--text-strong); }
.answer-text .answer-sub { display: block; font-weight: 400; color: var(--text-muted); font-size: var(--fs-sm); margin-top: 2px; }
.tone-good .answer-text .tone-word { color: var(--success); }
.tone-warn .answer-text .tone-word { color: var(--warning); }
.tone-bad .answer-text .tone-word { color: var(--danger); }
.tone-input .answer-text .tone-word { color: var(--accent-text); }

.kv-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.kv { padding: 8px 10px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.kv-label { display: block; font-size: var(--fs-xs); color: var(--text-muted); font-weight: 500; }
.kv-value { display: block; font-size: var(--fs-lg); font-weight: 650; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.kv-meta { display: block; margin-top: 3px; }

details.card-details { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }
details.card-details > summary {
    cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px;
    font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); padding: 4px 6px; border-radius: 6px;
}
details.card-details > summary::-webkit-details-marker { display: none; }
details.card-details > summary::before { content: "▸"; font-size: 0.8em; transition: transform var(--transition-fast); }
details.card-details[open] > summary::before { transform: rotate(90deg); }
details.card-details > summary:hover { color: var(--text-strong); background: var(--surface-3); }
details.card-details > .details-body { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }

/* Metric boxes (inside details and elsewhere) */
.metric-grid { gap: 8px; }
.metric-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; }
.metric-title { text-transform: none; letter-spacing: 0; font-size: var(--fs-xs); color: var(--text-muted); font-weight: 500; }
.metric-val { font-family: var(--font-body); font-size: var(--fs-md); font-weight: 650; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.metric-val.highlight { color: var(--text-strong); }
.metric-val.success, .metric-val.non-extraction { color: var(--success); }
.metric-val.warning, .metric-val.borderline { color: var(--warning); }
.metric-val.danger, .metric-val.extraction { color: var(--danger); }
.metric-sub { color: var(--text-subtle); font-size: var(--fs-xs); }
.arch-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.arch-col-title { font-family: var(--font-body); color: var(--text-strong); font-weight: 650; font-size: var(--fs-sm); }

.interpretation-box {
    background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong); border-radius: var(--radius); font-size: var(--fs-sm); line-height: 1.55;
}
.interpretation-box.non-extraction { border-left-color: var(--success); background: var(--surface-2); }
.interpretation-box.borderline { border-left-color: var(--warning); background: var(--surface-2); }
.interpretation-box.extraction { border-left-color: var(--danger); background: var(--surface-2); }
.inference-line { color: var(--text); }
.formula-note { color: var(--text-subtle); font-size: var(--fs-xs); line-height: 1.5; }
.diag-banner {
    background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
    font-size: var(--fs-sm); padding: 7px 10px; margin-top: 8px;
}
.diag-banner.warning { border-color: var(--danger-border); background: var(--danger-soft); color: var(--text); }
.diag-banner.notice { border-color: var(--warning-border); background: var(--warning-soft); color: var(--text); }
.diag-banner.info { border-color: var(--accent-border); background: var(--accent-soft); color: var(--text); }

/* Legend on the analyses page */
.analysis-legend {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
    padding: 9px 14px; margin: 0 0 12px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-muted);
}
.legend-title { font-weight: 650; color: var(--text-strong); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-sep { width: 1px; height: 16px; background: var(--border); }

.ortho-header-banner {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.ortho-header-banner h2 { color: var(--text-strong) !important; font-weight: 650; }
.calib-warning-banner { background: var(--warning-soft); color: var(--text); border: 1px solid var(--warning-border); border-radius: var(--radius); }

/* ── Tables ── */
.data-table, .mini-table { border-collapse: collapse; }
.data-table th, .mini-table th {
    background: var(--surface-2); color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600;
    text-transform: none; letter-spacing: 0; border-bottom: 1px solid var(--border);
}
.data-table td, .mini-table td { color: var(--text); border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table tr.patient-cont-row td { border-top: none; }
.table-container { border-radius: var(--radius); }
.empty-table-state { color: var(--text-muted); }

/* ── Forms ── */
input[type="text"], input[type="search"], input[type="email"], input[type="tel"], input[type="password"], input[type="number"],
input[type="date"], select, textarea, .custom-select, .custom-select-small, .search-input, .login-input, .ortho-input, .danger-input, .width-input {
    background: var(--surface) !important;
    color: var(--text-strong) !important;
    border: 1px solid var(--border-strong) !important;
    border-radius: 8px !important;
    font-family: var(--font-body);
    box-shadow: none;
}
input::placeholder, textarea::placeholder { color: var(--text-subtle); }
input:focus, select:focus, textarea:focus, .custom-select:focus, .search-input:focus, .login-input:focus {
    border-color: var(--accent) !important;
    box-shadow: var(--focus-ring) !important;
    outline: none;
}
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2) !important; color: var(--text-muted) !important; }
.form-field { color: var(--text-muted); font-weight: 550; }
.form-error, .login-error { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger-border); border-radius: 8px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* ── Popups ── */
.modal-overlay { background: var(--overlay); backdrop-filter: none; }
.modal-card { box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid var(--border); }
.modal-actions { border-top: 1px solid var(--border); }
.modal-close, .drawer-close-btn { background: transparent; color: var(--text-muted); border: none; border-radius: 6px; }
.modal-close:hover, .drawer-close-btn:hover { background: var(--surface-3); color: var(--text-strong); }
.danger-modal { border-top: 3px solid var(--danger); }
.warning-text { color: var(--text); }
.arch-draw-shell { box-shadow: var(--shadow-lg); }
.arch-draw-header, .arch-draw-toolbar, .arch-draw-footer { border-color: var(--border); background: var(--surface); }
.arch-draw-hint { color: var(--text-muted); }
.seg-toggle { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.seg-btn { color: var(--text-muted); background: transparent; border: none; border-radius: 6px; font-weight: 550; }
.seg-btn.active { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm); }
.contact-verify-side { background: var(--surface-2); border-color: var(--border); }
.cv-severity { color: var(--text-strong); }
.stepper .step { color: var(--text-muted); }
.stepper .step.active { color: var(--accent-text); border-color: var(--accent); }

/* ── Drawer ── */
.drawer-backdrop { background: var(--overlay); backdrop-filter: none; }
.side-drawer { background: var(--surface); border-right: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.drawer-header { border-bottom: 1px solid var(--border); }
.drawer-title { font-family: var(--font-body); color: var(--text-strong); font-weight: 700; }
.drawer-user-info { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.drawer-user-info .user-name { color: var(--text-strong); }
.drawer-user-info .user-role { color: var(--text-muted); }
.drawer-item { color: var(--text); border-radius: 8px; font-weight: 550; background: transparent; border: none; }
.drawer-item:hover:not(:disabled) { background: var(--surface-3); color: var(--text-strong); }
.drawer-item.active { background: var(--accent-soft); color: var(--accent-text); box-shadow: none; border: none; }
.drawer-divider { border-color: var(--border); }
.hamburger-btn { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.hamburger-btn .bar { background: var(--text-muted); }
.bell-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); }

/* ── Settings ── */
.settings-group { border: none; padding: 0; margin: 0; }
.settings-group legend { font-weight: 650; color: var(--text-strong); margin-bottom: 4px; }
.theme-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.theme-option {
    display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 8px; cursor: pointer;
    border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); font-weight: 550;
}
.theme-option:has(input:checked) { border-color: var(--accent); box-shadow: var(--focus-ring); color: var(--accent-text); }
.theme-option input { position: absolute; opacity: 0; pointer-events: none; }
.theme-option:has(input:focus-visible) { box-shadow: var(--focus-ring); }
.theme-swatch { width: 100%; height: 44px; border-radius: 8px; border: 1px solid var(--border); }
.theme-swatch.light { background: linear-gradient(135deg, #ffffff 50%, #eaf1f8 50%); }
.theme-swatch.dark { background: linear-gradient(135deg, #1a1f28 50%, #262d3a 50%); }
.theme-swatch.system { background: linear-gradient(135deg, #ffffff 50%, #1a1f28 50%); }

/* ── Login ── */
.login-page-view { background: var(--bg); }
.login-container::before, .login-container::after, .login-page-view::before, .login-page-view::after { display: none !important; }
.login-card { box-shadow: var(--shadow-md); }
.login-brand h2 { color: var(--text-strong); font-family: var(--font-body); }
.login-subtitle { color: var(--text-muted); }
.login-brand .logo-icon.large { background: var(--accent); box-shadow: none; }

/* ── Workspace (scan view) ── */
.upload-box { background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.upload-box:hover { border-color: var(--accent); background: var(--accent-soft); }
.upload-box.uploaded { border-style: solid; border-color: var(--success-border); background: var(--success-soft); }
.upload-title { color: var(--text-strong); }
.file-name { color: var(--text-muted); }
.upload-subheading { color: var(--text-muted); font-weight: 600; }
.viewport-panel { background: var(--surface); }
.viewport-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.view-indicator { color: var(--text-strong); font-family: var(--font-body); font-weight: 650; }
.canvas-container { background: var(--viewer-bg) !important; }
.results-panel .results-header h2, .control-panel h2 { color: var(--text-strong); }
.calib-card, .calib-panel, .calibration-box { background: var(--surface-2); border-color: var(--border); }
.arch-line-card { background: var(--surface); }
.arch-tool-val { color: var(--text-strong); }

/* ── Dashboard / pages ── */
.tab-bar { border-bottom: 1px solid var(--border); }
.tab-btn { color: var(--text-muted); background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0; font-weight: 600; }
.tab-btn:hover { color: var(--text-strong); }
.tab-btn.active { color: var(--accent-text); border-bottom-color: var(--accent); background: transparent; }
.tab-count { background: var(--surface-3); color: var(--text-muted); border-radius: 9999px; }
.tab-btn.active .tab-count { background: var(--accent-soft); color: var(--accent-text); }
.visit-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.visit-date { color: var(--text-strong); font-weight: 650; }
.referral-item, .note-item { border-color: var(--border); }
.referral-msg { background: var(--surface-2); color: var(--text); border-radius: 8px; }
.stat-value { color: var(--text-strong); font-family: var(--font-body); }
.stat-label { color: var(--text-muted); text-transform: none; letter-spacing: 0; font-size: var(--fs-sm); }
.admin-doctor-name { color: var(--text-strong); }
.admin-caret { color: var(--text-muted); }
.toast, .logout-toast { background: var(--text-strong); color: var(--surface); border-radius: 8px; box-shadow: var(--shadow-md); }

/* Refresh skeleton */
.refresh-skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; }
.refresh-note { color: var(--text-muted); }

/* Patient-category / teeth counters in the analyses header */
.summary-badge { background: var(--surface-2); color: var(--text); }

/* Viewport toolbar: groups wrap instead of overflowing the panel */
.viewport-actions .arch-buttons-group { flex-wrap: wrap; row-gap: 6px; }
.viewport-actions { max-width: 100%; }
.modal-actions { background: var(--surface-2); }


/* ==========================================================================
   Admin: Usage analytics
   ========================================================================== */
/* The page scrolls as a whole: its sections keep their natural height instead of being squeezed */
.usage-filters {
    display: grid; grid-template-columns: repeat(3, minmax(130px, 1fr)) minmax(220px, 1.6fr) minmax(130px, 1fr) minmax(180px, 1.6fr) auto;
    align-items: end; gap: 12px; padding: 14px 16px; margin-bottom: 0;
}
.usage-filters .form-field { min-width: 0; }
.usage-filters .form-field input, .usage-filters .form-field select { width: 100%; box-sizing: border-box; }
.usage-filter-actions { display: flex; gap: 8px; }
.usage-drill { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 1 / -1; }
.usage-drill:empty { display: none; }
.usage-chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; cursor: pointer;
    font: inherit; font-size: var(--fs-sm); color: var(--accent-text); background: var(--accent-soft); border: 1px solid var(--accent-border);
}
.usage-chip:hover { background: var(--accent-border); }
.stat-tile.tone-bad .stat-value { color: var(--danger); }
.stat-tile.tone-warn .stat-value { color: var(--warning); }
.usage-panels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.usage-panel.wide { grid-column: span 2; }
.usage-panel.usage-daily, .usage-panel.usage-full { grid-column: 1 / -1; }
.usage-tabs { display: inline-flex; gap: 2px; margin-left: auto; padding: 2px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.usage-tab { border: 0; background: transparent; color: var(--text-muted); font: inherit; font-size: var(--fs-sm); font-weight: 600; padding: 4px 12px; border-radius: 6px; cursor: pointer; }
.usage-tab:hover { color: var(--text); }
.usage-tab.active { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm); }
.usage-foot { padding: 8px 16px; margin: 0; font-size: var(--fs-xs); border-top: 1px solid var(--border); }
.usage-type.type-modal { background: var(--warning-soft, var(--surface-3)); color: var(--warning, var(--text-muted)); border-color: var(--warning-border, var(--border)); }
.usage-click-row.is-selected td { background: var(--accent-soft); font-weight: 600; }
.mono-cell { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: var(--fs-xs); color: var(--text-muted); }
.usage-ended { font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); }
.usage-ended.ended-active { color: var(--success); }
.usage-ended.ended-logged_out { color: var(--text); }
.usage-panel { padding: 0; overflow: hidden; min-width: 0; }
.usage-panel-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.usage-panel-head .section-title { margin: 0; }
.usage-panel-head .muted-text { font-size: var(--fs-sm); }
.usage-panel .table-container { max-height: 340px; overflow: auto; }
.usage-log .table-container { max-height: 70vh; }
.usage-panel thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-2, var(--bg-panel)); }
.usage-table th.num, .usage-table td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.usage-table td { font-size: var(--fs-sm); }
.usage-table td.nowrap, .usage-table .nowrap { white-space: nowrap; }
.usage-msg { max-width: 360px; color: var(--text-muted); word-break: break-word; }
.usage-empty { padding: 14px 16px; margin: 0; }
.usage-click-row { cursor: pointer; }
.usage-click-row:hover td { background: var(--accent-soft); }
.usage-bad { color: var(--danger); font-weight: 600; }
.usage-drop { color: var(--warning); font-weight: 600; }
.usage-type {
    display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
    background: var(--surface-3); color: var(--text-muted); border: 1px solid var(--border);
}
.usage-type.type-auth { background: var(--violet-soft); color: var(--violet); border-color: var(--violet-border); }
.usage-type.type-api, .usage-type.type-workflow { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent-border); }
.usage-type.type-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.usage-type.type-view { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.usage-pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); }
.usage-pager .muted-text { margin-right: auto; font-size: var(--fs-sm); }
.link-btn.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: var(--fs-xs); }
@media (max-width: 1400px) {
    .usage-panels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .usage-panel.usage-daily, .usage-panel.usage-blocked { grid-column: span 2; }
    .usage-filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .usage-filters .usage-q { grid-column: span 2; }
}
@media (max-width: 900px) {
    .usage-panels { grid-template-columns: 1fr; }
    .usage-panel.wide, .usage-panel.usage-daily, .usage-panel.usage-blocked { grid-column: auto; }
    .usage-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .usage-filters .usage-q, .usage-filter-actions { grid-column: 1 / -1; }
}

/* Carey's arch draw: first-molar FDI landmarks */
.arch-draw-fdi {
    position: absolute; left: 0; top: 0; pointer-events: none; z-index: 2;
    padding: 2px 7px; border-radius: 4px; font-size: 0.75rem; font-weight: 700;
    font-family: var(--font-heading); color: #e0f2fe; background: rgba(8, 47, 73, 0.9); border: 1px solid #38bdf8;
}
.arch-draw-fdi-note {
    position: absolute; left: 12px; top: 12px; z-index: 2; padding: 4px 10px; border-radius: 6px;
    font-size: var(--fs-sm); color: #fde68a; background: rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   Legal terms gate and ownership marks
   ========================================================================== */
.login-terms {
    display: flex; align-items: flex-start; gap: 9px; margin: 2px 0 4px; cursor: pointer;
    font-size: 0.78rem; line-height: 1.45; color: var(--text-muted); font-weight: 500;
}
.login-terms input { margin-top: 2px; width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }
.login-terms a { color: var(--accent-text); text-decoration: underline; text-underline-offset: 2px; }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.3); }
.owner-mark { font-size: 0.7rem; color: var(--text-muted); opacity: 0.75; letter-spacing: 0.01em; }
.login-owner-mark { margin-top: 18px; text-align: center; }
.drawer-owner-mark { display: flex; flex-direction: column; gap: 4px; padding: 12px 18px 16px; border-top: 1px solid var(--border); }
.drawer-owner-mark a { color: var(--text-muted); text-decoration: underline; text-underline-offset: 2px; }
@media print {
    body[data-print-mark]::after {
        content: attr(data-print-mark); position: fixed; bottom: 4mm; left: 0; right: 0;
        text-align: center; font-size: 8pt; color: #777;
    }
}

/* ==========================================================================
   Manual FDI labels: add-line dropdown and label popup
   ========================================================================== */
.fdi-tool-group { display: flex; align-items: center; margin-right: 6px; padding-right: 6px; border-right: 1px solid var(--border); }
.fdi-add-select {
    height: 30px; padding: 0 8px; border-radius: 8px; font: inherit; font-size: 0.75rem; font-weight: 600;
    color: var(--accent-text); background: var(--accent-soft); border: 1px solid var(--accent-border); cursor: pointer;
}
.fdi-add-select:disabled { color: var(--text-muted); background: var(--surface-2); border-color: var(--border); cursor: default; }
.tooth-label-3d.is-clickable { pointer-events: auto; cursor: pointer; }
.tooth-label-3d.is-clickable:hover { border-color: var(--accent); background: var(--accent-soft); }
.fdi-label-popup {
    position: absolute; z-index: 40; transform: translate(-50%, -100%);
    display: flex; align-items: center; gap: 4px; padding: 4px 4px 4px 10px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-md);
}
.fdi-label-popup.hidden { display: none; }
.fdi-popup-title { font-size: 0.75rem; font-weight: 700; color: var(--text-strong); margin-right: 4px; }
.fdi-popup-btn {
    width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 7px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 0.85rem;
}
.fdi-popup-btn:hover { background: var(--surface-3); }
.fdi-popup-btn.danger:hover { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }

/* Visit history: next-visit action as a compact button, aligned with the badges */
.visit-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.next-visit-btn { height: 26px; padding: 0 10px; font-size: 0.74rem; line-height: 1; display: inline-flex; align-items: center; gap: 4px; width: auto; margin: 0; }

/* Carey's arch popup opened by a read-only user: look only */
#arch-draw-modal.view-only #btn-arch-mode-draw,
#arch-draw-modal.view-only #btn-arch-mode-adjust,
#arch-draw-modal.view-only #btn-arch-undo,
#arch-draw-modal.view-only #btn-arch-clear,
#arch-draw-modal.view-only .wire-points,
#arch-draw-modal.view-only .arch-draw-hint,
#arch-draw-modal.view-only #btn-arch-save { display: none; }
#arch-draw-modal.view-only #arch-draw-edit-mm { pointer-events: none; opacity: 0.85; }

/* Carey's arch tool: PBDT guide line */
.seg-btn.pbdt-mode-btn.active { background: #0d9488; color: #fff; }
.pbdt-readout .pbdt-row { display: inline-flex; align-items: center; gap: 6px; }
.pbdt-val { color: #0d9488; }
.pbdt-btn { height: 26px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-size: 0.72rem; font-weight: 600; cursor: pointer; }
.pbdt-btn:disabled { opacity: 0.5; cursor: default; }
.pbdt-btn.danger:hover { color: var(--danger); border-color: var(--danger-border); }
.pbdt-btn.hidden, .pbdt-readout.hidden { display: none; }
.pbdt-state { font-size: 0.7rem; color: var(--text-muted); }
.pbdt-note { margin-top: 6px; }
#arch-draw-modal.view-only #btn-arch-mode-pbdt { display: none; }

/* ==========================================================================
   View remote: TV-remote style camera controls, top-right of every 3D viewer.
   Sized in em; the script sets font-size from the viewer size (9-13 px).
   The viewers always have a dark background, so the remote uses a dark glass style.
   ========================================================================== */
.view-remote {
    --vr-bg: rgba(15, 20, 30, 0.78);
    --vr-line: rgba(255, 255, 255, 0.12);
    --vr-btn: rgba(255, 255, 255, 0.07);
    --vr-btn-hover: rgba(255, 255, 255, 0.16);
    --vr-text: #e2e8f0;
    --vr-muted: #94a3b8;
    --vr-accent: #60a5fa;
    position: absolute; top: 1.1em; right: 1.1em; z-index: 30;
    display: flex; flex-direction: column; align-items: center; gap: 0.8em;
    width: 11.2em; padding: 0.8em 0.8em 0.9em;
    background: var(--vr-bg); border: 1px solid var(--vr-line); border-radius: 1.6em;
    box-shadow: 0 0.6em 1.8em rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    color: var(--vr-text); font-family: var(--font-body, inherit); user-select: none; touch-action: none;
}
.view-remote button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.view-remote button:focus-visible { outline: 2px solid var(--vr-accent); outline-offset: 2px; }
.view-remote svg { width: 1.25em; height: 1.25em; display: block; }

.vr-head { display: flex; align-items: center; gap: 0.4em; width: 100%; }
.vr-mode { flex: 1; display: grid; grid-template-columns: 1fr 1fr; padding: 0.2em; border-radius: 999px; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--vr-line); }
.vr-mode-btn { border: 0; background: transparent; padding: 0.3em 0; border-radius: 999px; font-size: 0.85em; font-weight: 700; letter-spacing: 0.02em; color: var(--vr-muted); transition: background 0.15s, color 0.15s; }
.vr-mode-btn.active { background: var(--vr-accent); color: #0b1220; }
.vr-collapse { width: 1.9em; height: 1.9em; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid var(--vr-line); background: var(--vr-btn); color: var(--vr-muted); }
.vr-collapse:hover { background: var(--vr-btn-hover); color: var(--vr-text); }
.vr-collapse svg { width: 1em; height: 1em; }

/* Round D-pad: four wedge buttons around a centre button */
.vr-pad {
    position: relative; width: 9.4em; height: 9.4em; border-radius: 50%;
    background: radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.03) 70%);
    border: 1px solid var(--vr-line);
    box-shadow: inset 0 0.15em 0.4em rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 255, 255, 0.05);
    display: grid; grid-template: 1fr 1.15fr 1fr / 1fr 1.15fr 1fr;
}
.vr-pad .vr-btn { border: 0; background: transparent; display: flex; align-items: center; justify-content: center; color: var(--vr-text); transition: background 0.12s, color 0.12s, transform 0.08s; }
.vr-pad .vr-up { grid-area: 1 / 2; border-radius: 0.9em 0.9em 0.3em 0.3em; }
.vr-pad .vr-down { grid-area: 3 / 2; border-radius: 0.3em 0.3em 0.9em 0.9em; }
.vr-pad .vr-left { grid-area: 2 / 1; border-radius: 0.9em 0.3em 0.3em 0.9em; }
.vr-pad .vr-right { grid-area: 2 / 3; border-radius: 0.3em 0.9em 0.9em 0.3em; }
.vr-pad .vr-up:hover, .vr-pad .vr-down:hover, .vr-pad .vr-left:hover, .vr-pad .vr-right:hover { background: var(--vr-btn-hover); color: #fff; }
.vr-pad .vr-btn svg { width: 1.6em; height: 1.6em; }
.vr-pad .vr-center {
    grid-area: 2 / 2; margin: 0.25em; border-radius: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.05));
    border: 1px solid var(--vr-line); box-shadow: 0 0.2em 0.5em rgba(0, 0, 0, 0.45);
    color: var(--vr-accent);
}
.vr-pad .vr-center:hover { background: linear-gradient(180deg, rgba(96, 165, 250, 0.35), rgba(96, 165, 250, 0.12)); color: #fff; }
.view-remote .vr-btn.pressed, .view-remote .vr-btn:active { transform: scale(0.92); color: var(--vr-accent); }
.view-remote[data-mode="pan"] .vr-pad { box-shadow: inset 0 0.15em 0.4em rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(96, 165, 250, 0.25); }

.vr-row { display: flex; gap: 0.5em; width: 100%; }
.vr-pill { flex: 1; display: grid; grid-template-columns: 1fr 1fr; border-radius: 999px; overflow: hidden; border: 1px solid var(--vr-line); background: var(--vr-btn); }
.vr-pill .vr-btn { border: 0; background: transparent; height: 2.3em; display: flex; align-items: center; justify-content: center; transition: background 0.12s; }
.vr-pill .vr-btn + .vr-btn { border-left: 1px solid var(--vr-line); }
.vr-pill .vr-btn:hover { background: var(--vr-btn-hover); }

/* Collapsed: a single round button that brings the remote back */
.vr-open { display: none; width: 2.8em; height: 2.8em; border-radius: 50%; border: 1px solid var(--vr-line); background: var(--vr-btn); align-items: center; justify-content: center; }
.vr-open:hover { background: var(--vr-btn-hover); }
.vr-open svg { width: 1.4em; height: 1.4em; }
.view-remote.collapsed { width: auto; padding: 0.35em; border-radius: 50%; }
.view-remote.collapsed > :not(.vr-open) { display: none; }
.view-remote.collapsed .vr-open { display: inline-flex; }

/* ==========================================================================
   Admin: Analytics tabs (App / Security), KPI tiles, charts, attack timeline, IP popover
   Chart series colours: a colour-blind-checked categorical palette (fixed order), stepped
   separately for dark mode. Text never takes a series colour.
   ========================================================================== */
:root {
    --series-1: #2a78d6;   /* blue   - stopped by nginx */
    --series-2: #eb6834;   /* orange - stopped by the app */
    --series-3: #1baf7a;   /* aqua   - seen, not stopped */
    --series-4: #eda100;   /* yellow - went through */
    --chart-grid: #e1e0d9;
}
:root[data-theme="dark"] {
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --chart-grid: #2c2c2a;
}
button.link-btn { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-weight: 600; }

.an-refresh { gap: 12px; }
.an-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm, 0.85rem); color: var(--text-muted); cursor: pointer; }
.an-toggle input { accent-color: var(--accent); }
.an-updated { font-variant-numeric: tabular-nums; }
.an-sub { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; }
.an-inline-btn { margin-left: auto; }

/* KPI tiles: click to expand a detail panel below the row */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi {
    position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
    padding: 12px 14px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
    color: inherit; font: inherit; cursor: pointer; min-width: 0; transition: border-color 0.15s, box-shadow 0.15s;
}
.kpi:hover { border-color: var(--accent-border); box-shadow: var(--shadow-sm); }
.kpi.is-open { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.kpi-value { font-family: var(--font-heading); font-size: 1.5rem; font-weight: 700; color: var(--text-strong); font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.kpi-sub { font-size: 0.72rem; color: var(--text-subtle); }
.kpi-caret { position: absolute; top: 10px; right: 12px; color: var(--text-subtle); font-size: 0.75rem; }
.kpi.tone-bad { border-left: 3px solid var(--danger); }
.kpi.tone-bad .kpi-value { color: var(--danger); }
.kpi.tone-warn { border-left: 3px solid var(--warning); }
.kpi.tone-good { border-left: 3px solid var(--success); }
.an-kpi-detail { padding: 0; overflow: hidden; }
.an-kpi-detail .table-container { max-height: 360px; overflow: auto; }

.an-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.an-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.an-pad-grid { padding: 12px 16px; }
.an-pad { padding: 12px 16px; margin: 0; }
.an-h4 { margin: 0 0 8px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.an-note { margin: 0 0 10px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); font-size: var(--fs-sm, 0.85rem); }
.an-note.tone-warn { border-color: var(--warning-border); background: var(--warning-soft); }
.an-note.tone-bad { border-color: var(--danger-border); background: var(--danger-soft); }
.an-pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; white-space: nowrap;
    background: var(--surface-3); color: var(--text-muted); border: 1px solid var(--border); }
.an-pill.tone-good { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.an-pill.tone-warn { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.an-pill.tone-bad { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.an-row-slow td { background: var(--warning-soft); }

/* Collapsible sections */
.an-section { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; }
.an-section > summary { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 12px 16px; cursor: pointer; list-style: none; }
.an-section > summary::-webkit-details-marker { display: none; }
.an-section > summary::before { content: '▸'; color: var(--text-subtle); font-size: 0.8rem; transition: transform 0.15s; }
.an-section[open] > summary::before { transform: rotate(90deg); }
.an-section[open] > summary { border-bottom: 1px solid var(--border); }
.an-section-title { font-family: var(--font-heading); font-weight: 700; color: var(--text-strong); }
.an-section .muted-text { font-size: var(--fs-sm, 0.8rem); }
.an-count { padding: 0 7px; border-radius: 999px; background: var(--surface-3); font-size: 0.72rem; font-weight: 700; color: var(--text-muted); }
.an-focus-btn { margin-left: auto; font-size: var(--fs-sm, 0.8rem); }
.an-section.tone-bad { border-color: var(--danger-border); }
.an-section.tone-warn { border-color: var(--warning-border); }
.an-section-body > .table-container { max-height: 420px; overflow: auto; }
.an-focus-card { max-width: min(1200px, 96vw); }
.an-focus-body { overflow: auto; max-height: calc(100vh - 120px); padding: 16px; }
.an-focus-body .table-container { max-height: none; }

/* Charts */
.an-chart { padding: 10px 16px 14px; }
.an-chart-tools { display: flex; align-items: center; gap: 12px; min-height: 22px; margin-bottom: 6px; }
.an-table-toggle { margin-left: auto; font-size: var(--fs-xs, 0.75rem); }
.an-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--fs-xs, 0.75rem); color: var(--text-muted); }
.an-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.an-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.an-chart-plot { position: relative; padding-top: 14px; }
.an-axis-max { position: absolute; top: 0; left: 0; font-size: 0.68rem; color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.an-cols { display: flex; align-items: stretch; gap: 2px; height: 170px; border-top: 1px solid var(--chart-grid); border-bottom: 1px solid var(--border-strong); }
.an-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; background: none; border: 0; padding: 0; cursor: default; font: inherit; position: relative; }
.an-col.is-link { cursor: pointer; }
.an-col-bar { flex: 1; width: 100%; max-width: 24px; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; }
.an-seg { display: block; width: 100%; min-height: 2px; }
.an-col-bar .an-seg:first-child { border-radius: 4px 4px 0 0; }
.an-col:hover .an-col-bar { filter: brightness(1.08); }
.an-col:hover::before { content: ''; position: absolute; inset: 0 -1px; background: var(--accent-soft); z-index: -1; border-radius: 4px; }
.an-col-label { position: absolute; bottom: -18px; font-size: 0.66rem; color: var(--text-subtle); white-space: nowrap; }
.an-chart-plot { margin-bottom: 18px; }
.an-chart-table .table-container, .an-chart-table { max-height: 240px; overflow: auto; }
.an-chart-tip { position: absolute; z-index: 20000; pointer-events: none; max-width: 300px; padding: 8px 10px; border-radius: 8px;
    background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); box-shadow: var(--shadow-md); font-size: 0.78rem; line-height: 1.45; }
.an-chart-tip.hidden { display: none; }
.an-tip-row { display: flex; align-items: center; gap: 6px; }
.an-tip-row span:last-child { margin-left: auto; padding-left: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.an-barlist { list-style: none; margin: 0; padding: 8px 16px 12px; display: flex; flex-direction: column; gap: 6px; }
.an-barlist li { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(60px, 1fr) auto; align-items: center; gap: 10px; font-size: var(--fs-sm, 0.82rem); padding: 2px 4px; border-radius: 6px; }
.an-barlist li.is-link { cursor: pointer; }
.an-barlist li.is-link:hover, .an-barlist li.is-link:focus-visible { background: var(--accent-soft); outline: none; }
.an-bl-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-bl-track { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.an-bl-bar { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1); }
.an-bl-bar.tone-bad { background: var(--series-2); }
.an-bl-value { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-strong); text-align: right; min-width: 3ch; }
.an-grid-3 .an-barlist, .an-grid-2 .an-barlist { padding: 0; }

/* Security tab */
.sec-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); align-items: end; gap: 12px; padding: 14px 16px; margin: 0; }
.sec-filters .form-field input, .sec-filters .form-field select { width: 100%; box-sizing: border-box; }
.sec-mode { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: var(--fs-sm, 0.82rem); }
.sec-mode .muted-text { font-size: var(--fs-sm, 0.8rem); }
.sec-banner { display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--danger-border);
    background: var(--danger-soft); color: var(--text); }
.sec-banner > div { flex: 1; min-width: 0; font-size: var(--fs-sm, 0.85rem); }
.sec-banner-icon { color: var(--danger); font-size: 1.2rem; line-height: 1; }
.sec-banner-list { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; }
.sec-banner ul { margin: 6px 0 0; padding-left: 16px; }
.sec-banner li { margin: 3px 0; }
.sev { display: inline-block; padding: 0 7px; border-radius: 999px; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap;
    border: 1px solid var(--border); background: var(--surface-3); color: var(--text-muted); }
.sev-medium { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.sev-high, .sev-critical { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.sev-critical { background: var(--danger); color: #fff; border-color: var(--danger); }
.sec-row-flag td { background: var(--danger-soft); }
.sec-row-flag:hover td { background: var(--danger-soft); filter: brightness(0.98); }
.sec-layers span { display: inline-flex; align-items: center; gap: 4px; margin-right: 8px; font-variant-numeric: tabular-nums; }
.lane-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.sec-went { font-size: 0.78rem; }
.sec-went-critical, .sec-went-high { color: var(--danger); font-weight: 600; }
.sec-went-cell { min-width: 180px; max-width: 320px; }
/* What went through: one block per attack session */
.sec-went-list { display: flex; flex-direction: column; }
.sec-went-group { border-top: 1px solid var(--border); }
.sec-went-group:first-child { border-top: 0; }
.sec-went-group.is-open .sec-went-head { box-shadow: inset 3px 0 0 var(--danger); }
.sec-went-head { display: grid; gap: 6px; padding: 14px 18px 10px; }
.sec-went-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sec-went-attack { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.sec-went-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.sec-went-group .table-container { margin: 0 0 6px; }
@media (max-width: 640px) { .sec-went-head { padding: 12px 14px 8px; } }
.sec-block-form { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(110px, 0.6fr) minmax(160px, 1.4fr) auto; align-items: end; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.sec-block-form .form-field input, .sec-block-form .form-field select { width: 100%; box-sizing: border-box; }
.sec-block-form .form-error { grid-column: 1 / -1; }
.sec-block-form .form-error:empty { display: none; }
.calib-btn.sm { padding: 3px 9px; font-size: 0.74rem; }

/* Attack timeline drawer */
.sec-drawer-backdrop { position: fixed; inset: 0; background: var(--overlay); z-index: 10001; }
.sec-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); z-index: 10002; background: var(--bg); border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.sec-drawer.hidden, .sec-drawer-backdrop.hidden { display: none; }
.sec-drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface); }
.sec-drawer-head .section-title { margin: 0; }
.sec-drawer-body { overflow: auto; padding: 16px 18px 24px; display: flex; flex-direction: column; gap: 14px; }
.sec-drawer-body > * { flex-shrink: 0; }
.tl-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tl-block { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tl-phases { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.tl-phase { padding: 8px 12px; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; position: relative; }
.tl-phase:last-child { border-right: 0; }
.tl-phase-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 700; }
.tl-phase-time { font-size: 0.8rem; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.tl-phase.is-empty .tl-phase-time { color: var(--text-subtle); }
.tl-phase.tone-good:not(.is-empty) { box-shadow: inset 0 -3px 0 var(--success); }
.tl-swim { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px 6px; }
.tl-lane { display: grid; grid-template-columns: 130px minmax(0, 1fr); align-items: center; gap: 10px; height: 30px; }
.tl-lane-label { font-size: 0.74rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-lane-track { position: relative; height: 100%; border-bottom: 1px solid var(--chart-grid); margin: 0 9px; }
.tl-dot { position: absolute; top: 50%; transform: translate(-50%, -50%); border-radius: 50%; box-shadow: 0 0 0 2px var(--surface); cursor: default; }
.tl-dot.is-flag { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--danger); z-index: 1; }
.tl-axis { display: flex; justify-content: space-between; margin-left: 140px; font-size: 0.68rem; color: var(--text-subtle); padding-top: 4px; }
.tl-review { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tl-review-row { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: 10px; align-items: end; }
.tl-review-row .form-field input, .tl-review-row .form-field select { width: 100%; box-sizing: border-box; }
.tl-review .form-error:empty { display: none; }
.tl-list-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tl-list-head .an-h4 { margin: 0; }
.tl-list-head .usage-tabs { margin-left: auto; }
.tl-list { list-style: none; margin: 0; padding: 0; position: relative; display: flex; flex-direction: column; }
.tl-list::before { content: ''; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { display: flex; gap: 12px; padding: 7px 8px 7px 0; position: relative; border-radius: 8px; }
.tl-item-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; margin-top: 3px; box-shadow: 0 0 0 3px var(--bg); position: relative; z-index: 1; }
.tl-item-main { min-width: 0; flex: 1; font-size: var(--fs-sm, 0.82rem); }
.tl-item-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tl-time { font-variant-numeric: tabular-nums; color: var(--text-muted); }
.tl-lane-name { font-size: 0.68rem; color: var(--text-subtle); text-transform: uppercase; letter-spacing: 0.04em; }
.tl-what { word-break: break-all; color: var(--text-strong); }
.tl-item.is-flag { background: var(--danger-soft); padding-left: 0; }
.tl-item.is-flag.flag-low { background: transparent; }
.mono, .tl-what { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.78rem; }

/* Clickable IPs and their popover */
.ip-link { background: none; border: 0; padding: 0; font: inherit; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.78rem;
    color: var(--accent-text); cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.ip-link:hover { color: var(--accent-hover); text-decoration-style: solid; }
.ip-pop { position: absolute; z-index: 20001; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow-lg);
    font-size: var(--fs-sm, 0.82rem); max-height: 80vh; overflow: auto; }
.ip-pop.hidden { display: none; }
.ip-pop-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.ip-pop-head .modal-close { margin-left: auto; }
.ip-pop-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.ip-pop-body .an-h4 { margin: 8px 0 2px; }
.ip-row { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px; }
.ip-row > span:first-child { color: var(--text-muted); }
.ip-row > span:last-child { word-break: break-word; }
.ip-kinds { display: flex; flex-wrap: wrap; gap: 4px; }
.ip-flags { display: flex; flex-wrap: wrap; gap: 4px; }
.ip-actions { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-top: 4px; }
.ip-block-label { color: var(--text-muted); font-weight: 600; }
.ip-ext { display: flex; gap: 14px; padding-top: 8px; margin-top: 4px; border-top: 1px solid var(--border); }
.ip-pop .an-note { margin: 4px 0 0; }

@media (max-width: 1100px) {
    .an-grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .an-grid-2 { grid-template-columns: 1fr; }
    .sec-block-form { grid-template-columns: 1fr 1fr; }
    .sec-block-form .sec-block-reason { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi-value { font-size: 1.25rem; }
    .sec-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sec-filters .usage-filter-actions { grid-column: 1 / -1; }
    .tl-phases { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tl-phase:nth-child(2) { border-right: 0; }
    .tl-phase:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
    .tl-lane { grid-template-columns: 82px minmax(0, 1fr); }
    .tl-axis { margin-left: 92px; }
    .tl-review-row { grid-template-columns: 1fr; }
    .sec-drawer-body { padding: 12px; }
    .an-barlist li { grid-template-columns: minmax(0, 1fr) 60px auto; }
}
.usage-table td.mono-cell.usage-msg { min-width: 140px; max-width: 260px; word-break: break-all; }


/* ==========================================================================
   Admin: Analytics shell. Collapsible left menu, header with range and filters, and pages
   laid out as a 12-column grid of soft cards with icon stat tiles. Colours come from the
   theme tokens above, so light and dark mode follow the rest of the app.
   ========================================================================== */
#usage-view { padding: 0; overflow: hidden; gap: 0; }
.an-shell { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 252px minmax(0, 1fr); background: var(--bg);
    border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; transition: grid-template-columns var(--transition-smooth); }
.an-shell.is-collapsed { grid-template-columns: 68px minmax(0, 1fr); }
.an-ico { width: 18px; height: 18px; flex-shrink: 0; }

/* Menu */
.an-nav { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 14px 10px 18px; gap: 8px; }
.an-nav-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 8px 8px; }
.an-nav-brand { font-family: var(--font-heading); font-weight: 800; font-size: 1.02rem; color: var(--text-strong); letter-spacing: -0.01em; white-space: nowrap; }
.an-nav-collapse { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted);
    display: inline-grid; place-items: center; cursor: pointer; flex-shrink: 0; }
.an-nav-collapse:hover { color: var(--text-strong); border-color: var(--border-strong); }
.an-nav-collapse .an-ico { width: 16px; height: 16px; transition: transform var(--transition-smooth); }
.an-shell.is-collapsed .an-nav-collapse .an-ico { transform: rotate(180deg); }
.an-nav-groups { display: flex; flex-direction: column; gap: 6px; }
.an-nav-group + .an-nav-group { border-top: 1px solid var(--border); padding-top: 6px; }
.an-nav-group-btn, .an-nav-item { width: 100%; display: flex; align-items: center; gap: 10px; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer;
    border-radius: 10px; white-space: nowrap; position: relative; }
.an-nav-group-btn { padding: 9px 10px; color: var(--text-strong); font-weight: 700; font-size: 0.86rem; }
.an-nav-group-btn:hover { background: var(--surface-2); }
.an-nav-group.is-current > .an-nav-group-btn > .an-ico { color: var(--accent); }
.an-nav-caret { margin-left: auto; display: inline-flex; color: var(--text-subtle); }
.an-nav-caret .an-ico { width: 14px; height: 14px; transition: transform var(--transition-fast); }
.an-nav-group.is-open .an-nav-caret .an-ico { transform: rotate(90deg); }
.an-nav-items { display: none; flex-direction: column; gap: 2px; padding: 2px 0 4px 8px; }
.an-nav-group.is-open .an-nav-items { display: flex; }
.an-nav-item { padding: 7px 10px; color: var(--text-muted); font-size: 0.83rem; font-weight: 500; }
.an-nav-item .an-ico { width: 17px; height: 17px; }
.an-nav-item:hover { background: var(--surface-2); color: var(--text); }
.an-nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 650; }
.an-nav-item.active::before { content: ''; position: absolute; left: -8px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.an-nav-group-btn:focus-visible, .an-nav-item:focus-visible, .an-nav-collapse:focus-visible, .an-stat:focus-visible, .an-card-link:focus-visible, .an-seg-ctl button:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.an-nav-label { overflow: hidden; text-overflow: ellipsis; }
.an-nav-badge { margin-left: auto; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 0.68rem; font-weight: 700; line-height: 18px; text-align: center; }
.an-nav-group-btn .an-nav-badge + .an-nav-caret { margin-left: 4px; }
.an-shell.is-collapsed .an-nav { padding: 14px 8px; align-items: stretch; }
.an-shell.is-collapsed .an-nav-top { justify-content: center; padding: 2px 0 8px; }
.an-shell.is-collapsed .an-nav-brand, .an-shell.is-collapsed .an-nav-label, .an-shell.is-collapsed .an-nav-caret { display: none; }
.an-shell.is-collapsed .an-nav-group-btn, .an-shell.is-collapsed .an-nav-item { justify-content: center; padding: 10px 0; }
.an-shell.is-collapsed .an-nav-items { padding-left: 0; }
.an-shell.is-collapsed .an-nav-item.active::before { left: -8px; }
.an-shell.is-collapsed .an-nav-badge { position: absolute; top: 3px; right: 6px; min-width: 15px; padding: 0 3px; line-height: 15px; font-size: 0.6rem; }

/* Main column */
.an-main { min-width: 0; min-height: 0; overflow-y: auto; padding: 20px 24px 36px; display: flex; flex-direction: column; gap: 16px; }
.an-main > * { flex-shrink: 0; }
.an-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }
.an-head-title { min-width: 0; }
.an-head .page-title { margin: 2px 0 0; font-size: 1.45rem; letter-spacing: -0.01em; }
.an-crumb { display: inline-flex; align-items: center; gap: 6px; font-size: 0.74rem; font-weight: 700; color: var(--accent-text); text-transform: uppercase; letter-spacing: 0.06em; }
.an-crumb .an-ico { width: 14px; height: 14px; }
.an-head-tools { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.an-range { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.an-range select, .an-range input { height: 34px; box-sizing: border-box; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface); color: var(--text);
    font: inherit; font-size: 0.82rem; padding: 0 10px; }
.an-range select { font-weight: 600; padding-right: 28px; }
.an-range select:focus, .an-range input:focus { outline: none; box-shadow: var(--focus-ring); border-color: var(--accent); }
.an-range .hidden { display: none; }
.an-head-tools .calib-btn { height: 34px; padding: 0 12px; display: inline-flex; align-items: center; gap: 6px; }
.an-filter-btn .an-count { background: var(--accent); color: var(--accent-contrast); }
.an-filter-btn .an-count.hidden { display: none; }
.an-nav-open { display: none; }
.an-filterbar { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; gap: 12px; padding: 14px 16px; margin: 0;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.an-filterbar.hidden { display: none; }
.an-filterbar .form-field { min-width: 0; }
.an-filterbar .form-field input, .an-filterbar .form-field select { width: 100%; box-sizing: border-box; }
.an-filterbar .usage-q { grid-column: span 2; }
.an-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: var(--fs-sm); }
.an-chips.hidden { display: none; }
.an-page { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.an-page > * { flex-shrink: 0; }
.an-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 48px 16px; color: var(--text-muted); font-size: var(--fs-sm); }
.an-spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: an-spin 0.8s linear infinite; }
@keyframes an-spin { to { transform: rotate(360deg); } }
.an-foot { margin: 0; font-size: var(--fs-xs); }
.an-h4.an-pad-h { margin: 6px 16px 0; }
.an-pad-text { margin: 0; padding: 12px 16px 16px; display: flex; align-items: center; gap: 8px; }

/* Stat tiles */
.an-stats { display: grid; grid-template-columns: repeat(var(--c-lg, 4), minmax(0, 1fr)); gap: 14px; }
@media (min-width: 1600px) { .an-stats { grid-template-columns: repeat(var(--c-xl, 6), minmax(0, 1fr)); } }
@media (max-width: 1180px) { .an-stats { grid-template-columns: repeat(var(--c-md, 3), minmax(0, 1fr)); } }
.an-stat { display: flex; align-items: center; gap: 12px; width: 100%; min-width: 0; padding: 14px 14px 14px 16px; text-align: left; font: inherit; color: inherit;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); position: relative;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast); }
.an-stat.is-link { cursor: pointer; }
.an-stat.is-link:hover { border-color: var(--accent-border); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.an-stat.tone-bad { box-shadow: inset 3px 0 0 var(--danger), var(--shadow-sm); }
.an-stat.tone-warn { box-shadow: inset 3px 0 0 var(--warning), var(--shadow-sm); }
.an-stat.tone-bad.is-link:hover { box-shadow: inset 3px 0 0 var(--danger), var(--shadow-md); }
.an-stat.tone-warn.is-link:hover { box-shadow: inset 3px 0 0 var(--warning), var(--shadow-md); }
.an-stat-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; background: var(--accent-soft); color: var(--accent-text); }
.an-stat-ico .an-ico { width: 20px; height: 20px; }
.an-stat-ico.tone-good { background: var(--success-soft); color: var(--success); }
.an-stat-ico.tone-warn { background: var(--warning-soft); color: var(--warning); }
.an-stat-ico.tone-bad { background: var(--danger-soft); color: var(--danger); }
.an-stat-ico.tone-violet { background: var(--violet-soft); color: var(--violet); }
.an-stat-text { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 1px; }
.an-stat-label { font-size: 0.76rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.an-stat-value { font-family: var(--font-heading); font-size: 1.42rem; font-weight: 750; line-height: 1.2; color: var(--text-strong); font-variant-numeric: tabular-nums;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.01em; }
.an-stat-sub { font-size: 0.72rem; color: var(--text-subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.an-stat-go { color: var(--text-subtle); opacity: 0.45; display: inline-flex; transition: opacity var(--transition-fast), transform var(--transition-fast); }
.an-stat-go .an-ico { width: 16px; height: 16px; }
.an-stat.is-link:hover .an-stat-go { opacity: 1; color: var(--accent-text); transform: translateX(2px); }

/* Cards on a 12-column grid */
.an-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; align-items: stretch; }
.an-grid > .span-3 { grid-column: span 3; } .an-grid > .span-4 { grid-column: span 4; } .an-grid > .span-5 { grid-column: span 5; }
.an-grid > .span-6 { grid-column: span 6; } .an-grid > .span-7 { grid-column: span 7; } .an-grid > .span-8 { grid-column: span 8; }
.an-grid > .span-12 { grid-column: 1 / -1; }
.an-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.an-card.tone-accent { border-color: var(--accent-border); box-shadow: 0 0 0 1px var(--accent-border), var(--shadow-sm); }
.an-card.tone-bad { border-color: var(--danger-border); }
.an-card.form-error { padding: 14px 16px; }
.an-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px 12px; padding: 14px 16px 10px; flex-wrap: wrap; }
.an-card-heading { min-width: 0; flex: 1 1 220px; }
.an-card-title { margin: 0; font-family: var(--font-heading); font-size: 0.95rem; font-weight: 700; color: var(--text-strong); display: flex; align-items: center; gap: 8px; }
.an-card-sub { margin: 3px 0 0; font-size: 0.76rem; color: var(--text-muted); line-height: 1.45; }
.an-card-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.an-card-link { display: inline-flex; align-items: center; gap: 2px; border: 0; background: transparent; color: var(--accent-text); font: inherit; font-size: 0.78rem; font-weight: 650;
    padding: 4px 6px 4px 8px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.an-card-link .an-ico { width: 14px; height: 14px; }
.an-card-link:hover { background: var(--accent-soft); }
.an-card-body { flex: 1; min-width: 0; padding-bottom: 6px; }
.an-card-body.flush { padding-bottom: 0; }
.an-card-body.flush > .table-container, .an-card-body > div > .table-container { max-height: 520px; overflow: auto; border-top: 1px solid var(--border); }
.an-card-body.flush > .usage-empty { padding: 4px 16px 16px; margin: 0; }
.an-card .data-table thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); }
.an-card .usage-pager { padding: 10px 16px; border-top: 1px solid var(--border); }
.an-card .usage-foot { padding: 8px 16px 12px; margin: 0; }
.an-card .an-chart { padding-top: 0; }
.an-card-body > .usage-empty { padding: 4px 16px 14px; margin: 0; }
.an-card .sec-block-form { border-top: 1px solid var(--border); }
.an-split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 0 16px 14px; }
.an-split .an-h4 { margin-top: 4px; }
.an-split .table-container { max-height: 380px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.an-split .usage-pager { padding: 8px 0 0; border: 0; }
.an-split .usage-foot { padding: 6px 0 0; }

/* Status list ("health") and segmented control */
.an-status { list-style: none; margin: 0; padding: 0; }
.an-status li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.an-status li.is-link { cursor: pointer; }
.an-status li.is-link:hover, .an-status li.is-link:focus-visible { background: var(--surface-2); outline: none; }
.an-status-label { display: flex; flex-direction: column; min-width: 0; color: var(--text); font-weight: 600; }
.an-status-label .cell-sub { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-status-value { font-weight: 750; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.an-status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--success); }
.an-status-dot.tone-warn { background: var(--warning); }
.an-status-dot.tone-bad { background: var(--danger); }
.an-seg-ctl { display: inline-flex; padding: 2px; gap: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.an-seg-ctl button { border: 0; background: transparent; color: var(--text-muted); font: inherit; font-size: 0.76rem; font-weight: 650; padding: 4px 10px; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.an-seg-ctl button:hover { color: var(--text); }
.an-seg-ctl button.active { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm); }

/* Funnel */
.an-funnel { list-style: none; margin: 0; padding: 4px 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.an-funnel li { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(80px, 2fr) 92px 48px; align-items: center; gap: 12px; font-size: var(--fs-sm); }
.an-funnel-label { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-funnel-n { width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; flex-shrink: 0; background: var(--surface-3); color: var(--text-muted); font-size: 0.68rem; font-weight: 700; }
.an-funnel-track { height: 14px; border-radius: 7px; background: var(--surface-3); overflow: hidden; }
.an-funnel-bar { display: block; height: 100%; border-radius: 7px; background: var(--series-1); }
.an-funnel-value { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.an-funnel-drop { text-align: right; font-size: 0.74rem; font-variant-numeric: tabular-nums; }
.an-card.span-4 .an-funnel li { grid-template-columns: minmax(0, 1fr) 70px 64px; }
.an-card.span-4 .an-funnel-drop { display: none; }

/* Security bits on the new pages */
.sec-mode .an-pill .an-ico { width: 13px; height: 13px; }
button.an-pill { cursor: pointer; font: inherit; font-size: 0.72rem; font-weight: 600; }

@media (max-width: 1280px) {
    .an-grid > .span-3, .an-grid > .span-4 { grid-column: span 6; }
    .an-grid > .span-5, .an-grid > .span-7, .an-grid > .span-8 { grid-column: 1 / -1; }
    .an-card.span-4 .an-funnel li { grid-template-columns: minmax(0, 1.2fr) minmax(80px, 2fr) 92px 48px; }
    .an-card.span-4 .an-funnel-drop { display: block; }
}
@media (max-width: 1000px) {
    .an-split { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .an-shell, .an-shell.is-collapsed { grid-template-columns: minmax(0, 1fr); border-radius: var(--radius); }
    .an-nav { position: fixed; top: 0; left: 0; bottom: 0; width: min(280px, 86vw); z-index: 10000; transform: translateX(-105%); transition: transform var(--transition-smooth); box-shadow: var(--shadow-lg); }
    .an-shell.nav-open .an-nav { transform: none; }
    .an-nav-backdrop { position: fixed; inset: 0; background: var(--overlay); z-index: 9999; }
    .an-nav-backdrop.hidden { display: none; }
    .an-nav-collapse { display: none; }
    /* The phone menu always shows labels */
    .an-shell.is-collapsed .an-nav-brand, .an-shell.is-collapsed .an-nav-label, .an-shell.is-collapsed .an-nav-caret { display: initial; }
    .an-shell.is-collapsed .an-nav-group-btn, .an-shell.is-collapsed .an-nav-item { justify-content: flex-start; padding: 8px 10px; }
    .an-shell.is-collapsed .an-nav-badge { position: static; }
    .an-shell.is-collapsed .an-nav { padding: 14px 10px 18px; }
    .an-shell.is-collapsed .an-nav-top { justify-content: space-between; padding: 2px 4px 8px 8px; }
    .an-shell.is-collapsed .an-nav-items { padding-left: 8px; }
    .an-nav-open { display: inline-flex; margin-bottom: 8px; }
    .an-main { padding: 14px 16px 28px; }
    .an-grid > [class*="span-"] { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
    .an-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .an-stat { padding: 12px; gap: 10px; }
    .an-stat-ico { width: 34px; height: 34px; border-radius: 10px; }
    .an-stat-ico .an-ico { width: 17px; height: 17px; }
    .an-stat-value { font-size: 1.15rem; }
    .an-stat-go { display: none; }
    .an-head { align-items: stretch; }
    .an-head-tools { width: 100%; }
    .an-range { flex: 1 1 100%; }
    .an-range select { flex: 1; }
    .an-range input { flex: 1 1 120px; }
    .an-filterbar { grid-template-columns: 1fr 1fr; }
    .an-filterbar .usage-q, .an-filterbar .usage-filter-actions { grid-column: 1 / -1; }
    .an-funnel li { grid-template-columns: minmax(0, 1fr) 60px 70px; }
    .an-funnel-drop { display: none; }
    .an-card-head { padding: 12px 14px 8px; }
}

/* ─── Analytics: Landing Page (site_admin.js) ─── */
.usage-note { padding: 10px 16px; margin: 0; font-size: var(--fs-sm); color: var(--text-muted); border-bottom: 1px solid var(--border); }
.site-replay-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 10px; }
.site-replay-head > div { display: grid; gap: 2px; min-width: 0; }
.site-replay-head b { color: var(--text-strong); font-weight: 600; overflow-wrap: anywhere; }
.site-steps { list-style: none; margin: 12px 0; padding: 0; border-left: 2px solid var(--border); }
.site-step { display: grid; grid-template-columns: 90px minmax(0, 1fr) auto; gap: 10px; align-items: baseline; padding: 7px 10px 7px 14px; position: relative; }
.site-step::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent); }
.site-step.site-click::before { background: var(--accent); }
.site-step.site-pageview::before { background: var(--success); box-shadow: inset 0 0 0 2px var(--success); }
.site-step-t { font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: var(--fs-sm); }
.site-step-what { min-width: 0; overflow-wrap: anywhere; }
.site-replay-sub { margin: 16px 0 6px; font-size: var(--fs-md); color: var(--text-strong); }
.site-other { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.an-filterbar .form-check { display: flex; align-items: center; gap: 8px; align-self: end; padding-bottom: 8px; font-size: var(--fs-sm); }
@media (max-width: 640px) { .site-step { grid-template-columns: 70px minmax(0, 1fr); } .site-step > .mono { grid-column: 2; } }

/* ─── Admin: Enquiries (enquiries_admin.js) ─── */
.enq-layout .patient-side { position: sticky; top: 12px; align-self: start; }
#enq-tbody tr.is-selected td { background: var(--accent-soft); }
.enq-detail { display: grid; gap: 10px; }
.enq-detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.enq-kvs { display: grid; gap: 6px; }
.enq-kv { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px; font-size: var(--fs-md); }
.enq-kv > span { color: var(--text-muted); }
.enq-kv > b { font-weight: 600; color: var(--text-strong); overflow-wrap: anywhere; }
.enq-meta .enq-kv > b { font-weight: 500; }
.enq-message { white-space: pre-wrap; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-md); }
.enq-sub { margin: 8px 0 0; font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.enq-status-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.enq-account { margin: 0; font-size: var(--fs-md); }
.enq-note-form { display: grid; gap: 6px; justify-items: start; }
.enq-note-form textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; resize: vertical; }
.enq-history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.enq-history li { padding: 8px 10px; border-left: 3px solid var(--accent-border); background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: var(--fs-md); }
.enq-note-text { white-space: pre-wrap; margin-top: 2px; }
.enq-danger { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--border); }
.danger-link { color: var(--danger) !important; }
.select-all { user-select: all; }
.enq-account-note { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--accent-soft); border: 1px solid var(--accent-border); font-size: var(--fs-md); color: var(--text); }
@media (max-width: 900px) { .enq-layout .patient-side { position: static; } }
.mini-badge.enq-new { color: var(--accent-text); border-color: var(--accent-border); background: var(--accent-soft); }
.mini-badge.enq-contacted { color: var(--warning); border-color: var(--warning-border); background: var(--warning-soft); }
.mini-badge.enq-approved { color: var(--success); border-color: var(--success-border); background: var(--success-soft); }
.mini-badge.enq-closed { color: var(--text-muted); border-color: var(--border); }
.enq-layout .table-container { overflow-x: auto; }
.enq-account-note { grid-column: 1 / -1; }

/* ─── Visitor (view-only demo) logins (visitor_mode.js) ─── */
.demo-banner {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap; flex-shrink: 0;
    padding: 8px 16px; border-radius: 10px;
    background: var(--accent-soft); border: 1px solid var(--accent-border); color: var(--text-strong);
    font-size: 0.82rem; line-height: 1.4;
}
.demo-banner.hidden { display: none; }
.demo-banner-tag {
    font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
    padding: 3px 9px; border-radius: 999px; background: var(--accent); color: var(--accent-contrast); white-space: nowrap;
}
.demo-banner-text { flex: 1 1 320px; min-width: 0; }
.demo-banner-link { font-weight: 700; color: var(--accent-text); white-space: nowrap; }
.demo-toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 4000;
    display: flex; align-items: center; gap: 14px; max-width: min(560px, calc(100vw - 32px));
    padding: 12px 16px; border-radius: 10px; font-size: 0.85rem; line-height: 1.4;
    background: var(--text-strong); color: var(--surface); box-shadow: var(--shadow-md);
}
.demo-toast.hidden { display: none; }
.demo-toast a { color: inherit; font-weight: 700; text-decoration: underline; white-space: nowrap; }
.mini-badge.visitor { color: var(--accent-text); border-color: var(--accent-border); background: var(--accent-soft); }
.form-hint { margin: 0; font-size: 0.78rem; line-height: 1.45; color: var(--text-muted); }
.form-hint.hidden { display: none; }
@media (max-width: 640px) {
    .demo-banner { padding: 8px 12px; gap: 8px; font-size: 0.78rem; }
    .demo-banner-text { flex-basis: 100%; order: 3; }
}
