/* =========================================================================
   ARMisure — Design System
   Palette derived from the AR brand mark: a blue → violet → magenta gradient
   with luminous white accents. Dark by default; light via media query.
   ========================================================================= */

:root {
    /* Surfaces — cosmic indigo */
    --color-bg:            #07061a;
    --color-surface:       #110d2c;
    --color-surface-2:     #1a1438;
    --color-surface-3:     #221b47;
    --color-border:        #2c2456;
    --color-border-strong: #3d3470;

    /* Text */
    --color-text:          #ece9fb;
    --color-text-muted:    #9a92c8;
    --color-text-subtle:   #6b6492;

    /* Brand spectrum (used for gradients) */
    --color-brand-blue:    #4d6eff;
    --color-brand-indigo:  #6b4ff5;
    --color-brand-violet:  #8b5cf6;
    --color-brand-magenta: #d946ef;
    --color-brand-pink:    #ec4899;
    --color-brand-cyan:    #4ecbff;

    /* Accent — primary brand violet */
    --color-accent:        #8b5cf6;
    --color-accent-hover:  #a879ff;
    --color-accent-press:  #7547e0;
    --color-accent-soft:   rgba(139, 92, 246, 0.14);
    --color-accent-ring:   rgba(139, 92, 246, 0.40);

    /* Status */
    --color-danger:        #fb7185;
    --color-danger-soft:   rgba(251, 113, 133, 0.14);
    --color-success:       #34d399;
    --color-warning:       #fbbf24;

    /* Gradients */
    --brand-gradient:      linear-gradient(135deg, #4d6eff 0%, #6b4ff5 35%, #b13ce5 70%, #d946ef 100%);
    --brand-gradient-soft: linear-gradient(135deg, rgba(77, 110, 255, 0.18), rgba(217, 70, 239, 0.18));
    --brand-gradient-line: linear-gradient(90deg, var(--color-brand-blue), var(--color-brand-violet), var(--color-brand-magenta));

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-pill: 999px;

    /* Shadow */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.45);

    /* Spacing — 4px scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;

    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

    /* Layout */
    --sidebar-width: 240px;
    --topbar-height: 64px;

    color-scheme: dark;
}

/* Light palette — applied either when the user explicitly picks light,
   or when "auto" (the default) is on and the OS prefers light. An explicit
   data-theme="dark" opts out of the OS-driven case. */
:root[data-theme="light"] {
    --color-bg:            #faf8ff;
    --color-surface:       #ffffff;
    --color-surface-2:     #f2effa;
    --color-surface-3:     #e6e1f5;
    --color-border:        #e0dcf1;
    --color-border-strong: #c8c0e4;

    --color-text:          #14102c;
    --color-text-muted:    #5a507c;
    --color-text-subtle:   #8b82b0;

    --color-accent:        #7c3aed;
    --color-accent-hover:  #8b5cf6;
    --color-accent-press:  #6929d9;
    --color-accent-soft:   rgba(124, 58, 237, 0.10);
    --color-accent-ring:   rgba(124, 58, 237, 0.35);

    --color-danger:        #db2777;
    --color-danger-soft:   rgba(219, 39, 119, 0.08);

    --shadow-sm: 0 1px 2px rgba(20, 16, 44, 0.06);
    --shadow-md: 0 6px 20px rgba(20, 16, 44, 0.10);
    --shadow-lg: 0 18px 50px rgba(20, 16, 44, 0.14);

    color-scheme: light;
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="light"]) {
        --color-bg:            #faf8ff;
        --color-surface:       #ffffff;
        --color-surface-2:     #f2effa;
        --color-surface-3:     #e6e1f5;
        --color-border:        #e0dcf1;
        --color-border-strong: #c8c0e4;

        --color-text:          #14102c;
        --color-text-muted:    #5a507c;
        --color-text-subtle:   #8b82b0;

        --color-accent:        #7c3aed;
        --color-accent-hover:  #8b5cf6;
        --color-accent-press:  #6929d9;
        --color-accent-soft:   rgba(124, 58, 237, 0.10);
        --color-accent-ring:   rgba(124, 58, 237, 0.35);

        --color-danger:        #db2777;
        --color-danger-soft:   rgba(219, 39, 119, 0.08);

        --shadow-sm: 0 1px 2px rgba(20, 16, 44, 0.06);
        --shadow-md: 0 6px 20px rgba(20, 16, 44, 0.10);
        --shadow-lg: 0 18px 50px rgba(20, 16, 44, 0.14);

        color-scheme: light;
    }
}

/* ---------- Reset / base ------------------------------------------------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0 0 var(--space-3) 0;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--color-text);
}

h1 { font-size: 1.75rem; line-height: 1.2; }
h2 { font-size: 1.375rem; line-height: 1.25; }
h3 { font-size: 1.0625rem; line-height: 1.3; }
h4 { font-size: 0.9375rem; }

p { margin: 0 0 var(--space-3) 0; }

a {
    color: var(--color-accent);
    text-decoration: none;
    transition: color 120ms ease;
}

a:hover {
    color: var(--color-accent-hover);
}

code, kbd, pre, samp {
    font-family: var(--font-mono);
    font-size: 0.875em;
}

::selection {
    background: var(--color-accent-soft);
    color: var(--color-text);
}

:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-pill);
    border: 2px solid var(--color-bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-border-strong); }

/* ---------- Blazor loading / error UI ------------------------------------ */

#blazor-error-ui {
    background: var(--color-surface);
    color: var(--color-text);
    border-top: 1px solid var(--color-danger);
    bottom: 0;
    box-shadow: var(--shadow-lg);
    display: none;
    left: 0;
    padding: var(--space-3) var(--space-5);
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: var(--space-4);
    top: var(--space-3);
}

.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--color-border);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--color-accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: relative;
    text-align: center;
    font-family: var(--font-mono);
    color: var(--color-text-muted);
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

/* =========================================================================
   App Shell
   ========================================================================= */

.dashboard-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
    background: var(--color-bg);
}

/* ---------- Sidebar ------------------------------------------------------ */

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: var(--space-5) var(--space-3);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    z-index: 30;
}

.sidebar-header {
    padding: 0 var(--space-2) var(--space-5) var(--space-2);
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-family: var(--font-sans);
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
}

.brand-link:hover { color: var(--color-text); }

.brand-link .brand-wordmark {
    display: inline-flex;
    align-items: baseline;
    gap: 1px;
}

.brand-link .brand-mark {
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.brand-link .brand-exp {
    font-size: 0.75em;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    transform: translateY(-0.35em);
    margin-left: 1px;
    font-weight: 800;
}

/* The miniature AR mark used in nav + login */
.brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--brand-gradient);
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 900;
    font-family: var(--font-sans);
    letter-spacing: -0.04em;
    box-shadow:
        0 4px 14px rgba(107, 79, 245, 0.40),
        inset 0 1px 0 rgba(255, 255, 255, 0.22);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.brand-logo::after {
    /* faint wireframe overlay echoing the iOS mark */
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(120deg, transparent 49%, rgba(255,255,255,0.20) 50%, transparent 51%),
        linear-gradient(120deg, transparent 60%, rgba(255,255,255,0.14) 61%, transparent 62%),
        linear-gradient(120deg, transparent 39%, rgba(255,255,255,0.14) 40%, transparent 41%);
    pointer-events: none;
    opacity: 0.65;
}

img.brand-logo,
img.brand-logo.brand-logo-lg,
img.brand-logo.brand-logo-xl {
    background: none;
    box-shadow: none;
    object-fit: contain;
    padding: 0;
    display: block;
}

img.brand-logo::after { content: none; }

.brand-logo .brand-logo-text {
    position: relative;
    font-size: 12px;
    line-height: 1;
    z-index: 1;
}

.brand-logo .brand-logo-exp {
    font-size: 7px;
    transform: translateY(-4px);
}

.brand-logo.brand-logo-lg {
    width: 56px;
    height: 56px;
    border-radius: 14px;
}

.brand-logo.brand-logo-lg .brand-logo-text { font-size: 22px; }
.brand-logo.brand-logo-lg .brand-logo-exp { font-size: 13px; transform: translateY(-7px); }

.brand-logo.brand-logo-xl {
    width: 76px;
    height: 76px;
    border-radius: 18px;
    box-shadow:
        0 12px 30px rgba(107, 79, 245, 0.50),
        0 4px 16px rgba(217, 70, 239, 0.30),
        inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.brand-logo.brand-logo-xl .brand-logo-text { font-size: 30px; }
.brand-logo.brand-logo-xl .brand-logo-exp { font-size: 18px; transform: translateY(-10px); }

.nav-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav-section-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-subtle);
    padding: var(--space-3) var(--space-3) var(--space-2);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-weight: 500;
    font-size: 0.875rem;
    transition: background-color 120ms ease, color 120ms ease;
}

.nav-link .nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke: currentColor;
}

.nav-link:hover {
    color: var(--color-text);
    background: var(--color-surface-2);
}

.nav-link.active {
    color: var(--color-text);
    background: var(--color-accent-soft);
    box-shadow: inset 2px 0 0 var(--color-accent);
}

.nav-link.active .nav-icon {
    color: var(--color-accent);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-pill);
    background: var(--brand-gradient);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.8125rem;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(107, 79, 245, 0.40);
}

.user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.user-name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-chip-hint {
    font-size: 0.6875rem;
    color: var(--color-text-subtle);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.user-chip-link {
    width: 100%;
    border-radius: var(--radius-md);
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: background var(--transition-fast, 0.15s) ease;
}

.user-chip-link:hover,
.user-chip-link:focus-visible {
    background: var(--color-surface-2);
}

.user-chip-link.active {
    background: var(--color-accent-soft);
}

.user-chip-chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--color-text-subtle);
}

.sidebar-footer .btn {
    width: 100%;
    margin-top: var(--space-2);
}

/* ---------- Main content area ------------------------------------------- */

.main-content {
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
}

.page {
    padding: var(--space-6);
    flex: 1;
    min-width: 0;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

/* =========================================================================
   Primitives
   ========================================================================= */

/* ---------- Buttons ----------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: 36px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: transparent;
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease,
                color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
    white-space: nowrap;
    user-select: none;
}

.btn:disabled,
.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-accent-ring);
}

.btn-primary {
    background: var(--brand-gradient);
    color: #fff;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow:
        0 6px 18px rgba(107, 79, 245, 0.35),
        0 2px 6px rgba(217, 70, 239, 0.20);
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 50%);
    pointer-events: none;
}

.btn-primary:hover:not(:disabled) {
    filter: brightness(1.08);
    color: #fff;
    transform: translateY(-1px);
    box-shadow:
        0 10px 24px rgba(107, 79, 245, 0.45),
        0 4px 10px rgba(217, 70, 239, 0.30);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
    filter: brightness(0.98);
}

.btn-secondary {
    background: transparent;
    color: var(--color-text);
    border-color: var(--color-border-strong);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-surface-2);
    border-color: var(--color-text-subtle);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    filter: brightness(1.05);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}

.btn-ghost:hover:not(:disabled) {
    color: var(--color-text);
    background: var(--color-surface-2);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    color: var(--color-text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
}

.btn-icon:hover:not(:disabled) {
    color: var(--color-text);
    background: var(--color-surface-2);
}

.btn-icon.active {
    color: var(--color-accent);
    background: var(--color-accent-soft);
    border-color: var(--color-accent-ring);
}

.btn-sm { height: 30px; padding: 0 var(--space-3); font-size: 0.8125rem; }
.btn-lg { height: 44px; padding: 0 var(--space-5); font-size: 0.9375rem; }

/* ---------- Inputs ------------------------------------------------------ */

.input,
.form-control {
    display: block;
    width: 100%;
    height: 38px;
    padding: 0 var(--space-3);
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.4;
    transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.input::placeholder,
.form-control::placeholder {
    color: var(--color-text-subtle);
}

.input:hover,
.form-control:hover {
    border-color: var(--color-text-subtle);
}

.input:focus,
.form-control:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-ring);
}

.input.invalid,
.form-control.invalid,
.input.modified.invalid,
.form-control.modified.invalid {
    border-color: var(--color-danger);
}

.input.valid.modified,
.form-control.valid.modified {
    border-color: var(--color-success);
}

.form-group,
.form-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.form-group label,
.form-row label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.input-with-icon {
    position: relative;
}

.input-with-icon .input-icon {
    position: absolute;
    left: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--color-text-subtle);
    pointer-events: none;
}

.input-with-icon .input,
.input-with-icon .form-control {
    padding-left: calc(var(--space-3) + 16px + var(--space-2));
}

/* ---------- Validation message ------------------------------------------ */

.validation-message {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-2) 0;
    padding: var(--space-3);
    background: var(--color-danger-soft);
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
}

.validation-message::before {
    content: "⚠";
    font-size: 1em;
}

/* ---------- Cards ------------------------------------------------------- */

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}

/* ---------- Badge ------------------------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px var(--space-2);
    background: var(--color-surface-3);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.4;
}

.badge-accent {
    color: var(--color-accent);
    border-color: var(--color-accent-ring);
    background: var(--color-accent-soft);
}

/* ---------- Toolbar ----------------------------------------------------- */

.toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    background: rgba(7, 6, 26, 0.72);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

:root[data-theme="light"] .toolbar {
    background: rgba(255, 255, 255, 0.78);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="light"]) .toolbar {
        background: rgba(255, 255, 255, 0.78);
    }
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--color-border);
    margin: 0 var(--space-1);
}

/* =========================================================================
   Page: Login — cosmic wow-factor with animated LiDAR scan stage
   ========================================================================= */

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--space-5);
    background:
        radial-gradient(900px 600px at 12% 8%, rgba(77, 110, 255, 0.32), transparent 55%),
        radial-gradient(900px 600px at 88% 92%, rgba(217, 70, 239, 0.30), transparent 55%),
        radial-gradient(700px 500px at 50% 100%, rgba(107, 79, 245, 0.22), transparent 60%),
        var(--color-bg);
    position: relative;
    overflow: hidden;
    isolation: isolate;
}

.login-page::before {
    /* faint diamond grid */
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(45deg, var(--color-border-strong) 1px, transparent 1px),
        linear-gradient(-45deg, var(--color-border-strong) 1px, transparent 1px);
    background-size: 56px 56px;
    opacity: 0.12;
    mask-image: radial-gradient(1100px 800px at 50% 50%, #000 30%, transparent 80%);
    -webkit-mask-image: radial-gradient(1100px 800px at 50% 50%, #000 30%, transparent 80%);
    pointer-events: none;
    z-index: 0;
}

.login-page::after {
    /* slow aurora orbs */
    content: "";
    position: absolute;
    inset: -10%;
    background:
        radial-gradient(circle at 20% 30%, rgba(77, 110, 255, 0.35) 0%, transparent 28%),
        radial-gradient(circle at 80% 70%, rgba(217, 70, 239, 0.30) 0%, transparent 32%),
        radial-gradient(circle at 50% 90%, rgba(78, 203, 255, 0.20) 0%, transparent 30%);
    filter: blur(40px);
    animation: aurora 24s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes aurora {
    0%, 100% { transform: translate3d(0, 0, 0) rotate(0deg); }
    50%      { transform: translate3d(-3%, 2%, 0) rotate(8deg); }
}

/* ---------- Two-pane shell --------------------------------------------- */

.login-shell {
    position: relative;
    z-index: 1;
    width: min(1080px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
    gap: var(--space-6);
    align-items: stretch;
    animation: shellRise 900ms cubic-bezier(.16,.84,.32,1) both;
}

@keyframes shellRise {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Login stage (animated LiDAR scene) ------------------------- */

.login-stage {
    position: relative;
    overflow: hidden;
    min-height: 540px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--color-border-strong);
    background:
        radial-gradient(80% 60% at 50% 50%, rgba(107, 79, 245, 0.22), transparent 70%),
        linear-gradient(160deg, #0d0a26 0%, #150f33 55%, #07061a 100%);
    box-shadow:
        0 30px 80px rgba(7, 6, 26, 0.55),
        0 12px 30px rgba(107, 79, 245, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    isolation: isolate;
    perspective: 1000px;
    animation: stageFade 1100ms ease-out 200ms both;
}

@keyframes stageFade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Gradient border outline */
.login-stage::before {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: var(--radius-xl);
    padding: 1px;
    background: var(--brand-gradient);
    -webkit-mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    opacity: 0.55;
    pointer-events: none;
    z-index: 4;
}

/* The grid floor + lines */
.stage-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(to right, rgba(139, 92, 246, 0.10) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(139, 92, 246, 0.10) 1px, transparent 1px);
    background-size: 40px 40px;
    mask-image:
        radial-gradient(70% 70% at 50% 55%, #000 0%, transparent 80%);
    -webkit-mask-image:
        radial-gradient(70% 70% at 50% 55%, #000 0%, transparent 80%);
    animation: gridDrift 30s linear infinite;
}

@keyframes gridDrift {
    from { background-position: 0 0, 0 0; }
    to   { background-position: 40px 40px, 40px 40px; }
}

/* Aurora glow that drifts behind the scene */
.stage-aurora {
    position: absolute;
    inset: -20%;
    background:
        radial-gradient(circle at 30% 40%, rgba(77, 110, 255, 0.55) 0%, transparent 30%),
        radial-gradient(circle at 75% 65%, rgba(217, 70, 239, 0.45) 0%, transparent 32%),
        radial-gradient(circle at 50% 90%, rgba(78, 203, 255, 0.30) 0%, transparent 30%);
    filter: blur(60px);
    opacity: 0.85;
    animation: stageAurora 18s ease-in-out infinite;
    pointer-events: none;
}

@keyframes stageAurora {
    0%, 100% { transform: translate3d(0, 0, 0); }
    50%      { transform: translate3d(4%, -3%, 0) rotate(6deg); }
}

/* Viewfinder corner brackets */
.vf-corner {
    position: absolute;
    width: 26px;
    height: 26px;
    border: 1.5px solid var(--color-brand-cyan);
    opacity: 0.7;
    box-shadow: 0 0 12px rgba(78, 203, 255, 0.4);
    z-index: 3;
    animation: vfPulse 3.2s ease-in-out infinite;
}

.vf-tl { top: 16px; left: 16px; border-right: 0; border-bottom: 0; border-top-left-radius: 6px; }
.vf-tr { top: 16px; right: 16px; border-left: 0; border-bottom: 0; border-top-right-radius: 6px; animation-delay: 0.4s; }
.vf-bl { bottom: 16px; left: 16px; border-right: 0; border-top: 0; border-bottom-left-radius: 6px; animation-delay: 0.8s; }
.vf-br { bottom: 16px; right: 16px; border-left: 0; border-top: 0; border-bottom-right-radius: 6px; animation-delay: 1.2s; }

@keyframes vfPulse {
    0%, 100% { opacity: 0.55; }
    50%      { opacity: 1; }
}

/* ---------- The 3D scan scene ------------------------------------------ */

.scan-scene {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    transform-style: preserve-3d;
    perspective: 900px;
}

/* Orbiting rings */
.scan-orbit {
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(139, 92, 246, 0.35);
    transform-style: preserve-3d;
    pointer-events: none;
}

.orbit-1 {
    width: 280px; height: 280px;
    border-color: rgba(77, 110, 255, 0.40);
    box-shadow: 0 0 26px rgba(77, 110, 255, 0.18) inset;
    animation: orbitTilt1 14s linear infinite;
}
.orbit-2 {
    width: 360px; height: 360px;
    border-color: rgba(139, 92, 246, 0.30);
    border-style: dashed;
    animation: orbitTilt2 22s linear infinite;
}
.orbit-3 {
    width: 460px; height: 460px;
    border-color: rgba(217, 70, 239, 0.22);
    animation: orbitTilt3 36s linear infinite reverse;
}

@keyframes orbitTilt1 {
    from { transform: rotateX(70deg) rotateZ(0deg); }
    to   { transform: rotateX(70deg) rotateZ(360deg); }
}
@keyframes orbitTilt2 {
    from { transform: rotateX(74deg) rotateY(-12deg) rotateZ(0deg); }
    to   { transform: rotateX(74deg) rotateY(-12deg) rotateZ(360deg); }
}
@keyframes orbitTilt3 {
    from { transform: rotateX(68deg) rotateY(8deg) rotateZ(0deg); }
    to   { transform: rotateX(68deg) rotateY(8deg) rotateZ(360deg); }
}

/* Rotating wireframe cube — the scan target */
.scan-cube {
    --size: 140px;
    width: var(--size);
    height: var(--size);
    position: relative;
    transform-style: preserve-3d;
    animation: cubeSpin 16s linear infinite;
    filter: drop-shadow(0 0 24px rgba(139, 92, 246, 0.45));
}

@keyframes cubeSpin {
    from { transform: rotateX(-22deg) rotateY(0deg); }
    to   { transform: rotateX(-22deg) rotateY(360deg); }
}

.cf {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(135deg, rgba(77, 110, 255, 0.10), rgba(217, 70, 239, 0.10));
    border: 1.5px solid rgba(167, 139, 250, 0.85);
    box-shadow:
        0 0 16px rgba(139, 92, 246, 0.30) inset,
        0 0 14px rgba(139, 92, 246, 0.25);
}

/* Inner wireframe pattern on each face */
.cf::before,
.cf::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(to right, rgba(167, 139, 250, 0.30) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(167, 139, 250, 0.30) 1px, transparent 1px);
    background-size: 28px 28px;
    pointer-events: none;
}

.cf::after {
    background-image:
        radial-gradient(circle at 50% 50%, rgba(78, 203, 255, 0.55) 0, rgba(78, 203, 255, 0) 8px);
    background-size: auto;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.9;
}

.cf-front  { transform: translateZ(70px); }
.cf-back   { transform: translateZ(-70px) rotateY(180deg); }
.cf-right  { transform: rotateY(90deg) translateZ(70px); }
.cf-left   { transform: rotateY(-90deg) translateZ(70px); }
.cf-top    { transform: rotateX(90deg) translateZ(70px); }
.cf-bottom { transform: rotateX(-90deg) translateZ(70px); }

/* Glow base under the cube */
.scan-base {
    position: absolute;
    bottom: 18%;
    width: 260px;
    height: 30px;
    background: radial-gradient(ellipse at center, rgba(139, 92, 246, 0.55), transparent 65%);
    filter: blur(8px);
    pointer-events: none;
    animation: basePulse 4s ease-in-out infinite;
}

@keyframes basePulse {
    0%, 100% { opacity: 0.55; transform: scale(1); }
    50%      { opacity: 0.95; transform: scale(1.08); }
}

/* Scanning beam — horizontal line sweeping vertically */
.scan-beam {
    position: absolute;
    left: 12%;
    right: 12%;
    height: 2px;
    background: linear-gradient(90deg,
        transparent,
        rgba(78, 203, 255, 0.85) 20%,
        #4ecbff 50%,
        rgba(78, 203, 255, 0.85) 80%,
        transparent);
    box-shadow:
        0 0 24px rgba(78, 203, 255, 0.85),
        0 0 60px rgba(78, 203, 255, 0.45);
    border-radius: 2px;
    animation: beamSweep 5s cubic-bezier(.45,.05,.55,.95) infinite;
    pointer-events: none;
    z-index: 2;
}

.scan-beam::before {
    /* trailing wash */
    content: "";
    position: absolute;
    inset: -36px -2px 2px;
    background: linear-gradient(to bottom, rgba(78, 203, 255, 0.18), transparent);
    pointer-events: none;
}

@keyframes beamSweep {
    0%   { top: 18%; opacity: 0; }
    8%   { opacity: 1; }
    50%  { top: 82%; opacity: 1; }
    52%  { opacity: 0; }
    52.01% { top: 18%; opacity: 0; }
    60%, 100% { top: 18%; opacity: 0; }
}

/* ---------- Point cloud sparks ----------------------------------------- */

.point-cloud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
}

.pc-dot {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--color-brand-cyan);
    box-shadow: 0 0 8px var(--color-brand-cyan);
    opacity: 0;
    animation: pcDot 5s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.18s);
    /* deterministic-but-varied positions using nth-child positioning below */
}

@keyframes pcDot {
    0%, 100% { opacity: 0; transform: scale(0.6); }
    20%      { opacity: 1; transform: scale(1); }
    70%      { opacity: 0.5; transform: scale(0.9); }
}

/* Sprinkle point-cloud dots around the cube area */
.pc-dot:nth-child(1)  { left: 28%; top: 32%; }
.pc-dot:nth-child(2)  { left: 62%; top: 28%; background: var(--color-brand-pink); box-shadow: 0 0 8px var(--color-brand-pink); }
.pc-dot:nth-child(3)  { left: 44%; top: 24%; }
.pc-dot:nth-child(4)  { left: 38%; top: 64%; background: var(--color-accent); box-shadow: 0 0 8px var(--color-accent); }
.pc-dot:nth-child(5)  { left: 70%; top: 56%; }
.pc-dot:nth-child(6)  { left: 26%; top: 58%; background: var(--color-brand-violet); box-shadow: 0 0 8px var(--color-brand-violet); }
.pc-dot:nth-child(7)  { left: 56%; top: 70%; }
.pc-dot:nth-child(8)  { left: 50%; top: 42%; background: var(--color-brand-pink); box-shadow: 0 0 8px var(--color-brand-pink); width: 3px; height: 3px; }
.pc-dot:nth-child(9)  { left: 34%; top: 46%; }
.pc-dot:nth-child(10) { left: 66%; top: 44%; background: var(--color-accent); box-shadow: 0 0 8px var(--color-accent); }
.pc-dot:nth-child(11) { left: 48%; top: 68%; }
.pc-dot:nth-child(12) { left: 30%; top: 50%; width: 3px; height: 3px; }
.pc-dot:nth-child(13) { left: 72%; top: 38%; background: var(--color-brand-pink); box-shadow: 0 0 8px var(--color-brand-pink); }
.pc-dot:nth-child(14) { left: 42%; top: 76%; background: var(--color-brand-cyan); box-shadow: 0 0 8px var(--color-brand-cyan); }
.pc-dot:nth-child(15) { left: 58%; top: 36%; width: 3px; height: 3px; }
.pc-dot:nth-child(16) { left: 22%; top: 42%; background: var(--color-accent); box-shadow: 0 0 8px var(--color-accent); }
.pc-dot:nth-child(17) { left: 76%; top: 50%; }
.pc-dot:nth-child(18) { left: 46%; top: 30%; background: var(--color-brand-violet); box-shadow: 0 0 8px var(--color-brand-violet); }
.pc-dot:nth-child(19) { left: 52%; top: 60%; }
.pc-dot:nth-child(20) { left: 40%; top: 38%; background: var(--color-brand-pink); box-shadow: 0 0 8px var(--color-brand-pink); width: 3px; height: 3px; }
.pc-dot:nth-child(21) { left: 64%; top: 64%; }
.pc-dot:nth-child(22) { left: 36%; top: 56%; background: var(--color-brand-cyan); box-shadow: 0 0 8px var(--color-brand-cyan); }
.pc-dot:nth-child(23) { left: 60%; top: 48%; }
.pc-dot:nth-child(24) { left: 32%; top: 38%; background: var(--color-accent); box-shadow: 0 0 8px var(--color-accent); width: 3px; height: 3px; }
.pc-dot:nth-child(25) { left: 68%; top: 32%; }
.pc-dot:nth-child(26) { left: 44%; top: 52%; background: var(--color-brand-violet); box-shadow: 0 0 8px var(--color-brand-violet); }
.pc-dot:nth-child(27) { left: 54%; top: 22%; }
.pc-dot:nth-child(28) { left: 38%; top: 70%; background: var(--color-brand-pink); box-shadow: 0 0 8px var(--color-brand-pink); }

/* ---------- HUD overlays ----------------------------------------------- */

.stage-hud {
    position: absolute;
    z-index: 3;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-2) var(--space-3);
    background: rgba(7, 6, 26, 0.55);
    border: 1px solid rgba(167, 139, 250, 0.30);
    border-radius: var(--radius-md);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    font-family: var(--font-mono);
    box-shadow: 0 8px 24px rgba(7, 6, 26, 0.45);
    animation: hudIn 800ms cubic-bezier(.16,.84,.32,1) both;
}

.stage-hud .hud-label {
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #9a92c8;
}

.stage-hud .hud-value {
    font-size: 1.0625rem;
    font-weight: 700;
    color: #ece9fb;
    line-height: 1.1;
    text-shadow: 0 0 14px rgba(139, 92, 246, 0.45);
}

.stage-hud .hud-unit {
    font-size: 0.75rem;
    color: #c5bfe6;
    margin-left: 3px;
    font-weight: 500;
    text-shadow: none;
}

.hud-tl { top: 52px; left: 52px; flex-direction: row; align-items: center; gap: var(--space-2); animation-delay: 600ms; }
.hud-tr { top: 52px; right: 52px; align-items: flex-end; text-align: right; animation-delay: 750ms; }
.hud-bl { bottom: 78px; left: 52px; animation-delay: 900ms; }
.hud-br { bottom: 78px; right: 52px; align-items: flex-end; text-align: right; animation-delay: 1050ms; }

@keyframes hudIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.hud-tl .hud-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.hud-tl .hud-status {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-brand-cyan);
    letter-spacing: 0.04em;
}

.hud-pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-brand-cyan);
    box-shadow: 0 0 10px var(--color-brand-cyan);
    animation: hudPulse 1.3s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes hudPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.4; transform: scale(0.7); }
}

/* ---------- Floating dust particles ------------------------------------ */

.stage-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
}

.dust {
    position: absolute;
    width: 2px;
    height: 2px;
    border-radius: 50%;
    background: rgba(236, 233, 251, 0.7);
    box-shadow: 0 0 4px rgba(236, 233, 251, 0.5);
    animation: dustFloat 12s ease-in-out infinite;
    animation-delay: calc(var(--i) * -0.8s);
    opacity: 0;
}

@keyframes dustFloat {
    0%   { opacity: 0; transform: translate3d(0, 0, 0); }
    15%  { opacity: 0.8; }
    50%  { opacity: 0.6; }
    85%  { opacity: 0.3; }
    100% { opacity: 0; transform: translate3d(0, -120px, 0); }
}

.dust:nth-child(1)  { left: 8%;  top: 80%; }
.dust:nth-child(2)  { left: 18%; top: 90%; width: 3px; height: 3px; }
.dust:nth-child(3)  { left: 28%; top: 70%; }
.dust:nth-child(4)  { left: 38%; top: 88%; background: rgba(167, 139, 250, 0.7); box-shadow: 0 0 4px rgba(167, 139, 250, 0.6); }
.dust:nth-child(5)  { left: 48%; top: 92%; }
.dust:nth-child(6)  { left: 58%; top: 78%; width: 3px; height: 3px; }
.dust:nth-child(7)  { left: 68%; top: 85%; background: rgba(78, 203, 255, 0.7); box-shadow: 0 0 4px rgba(78, 203, 255, 0.6); }
.dust:nth-child(8)  { left: 78%; top: 90%; }
.dust:nth-child(9)  { left: 88%; top: 75%; }
.dust:nth-child(10) { left: 14%; top: 85%; background: rgba(236, 72, 153, 0.7); box-shadow: 0 0 4px rgba(236, 72, 153, 0.6); }
.dust:nth-child(11) { left: 32%; top: 95%; }
.dust:nth-child(12) { left: 56%; top: 88%; width: 3px; height: 3px; background: rgba(167, 139, 250, 0.7); box-shadow: 0 0 4px rgba(167, 139, 250, 0.6); }
.dust:nth-child(13) { left: 72%; top: 92%; }
.dust:nth-child(14) { left: 84%; top: 86%; background: rgba(78, 203, 255, 0.7); box-shadow: 0 0 4px rgba(78, 203, 255, 0.6); }

/* ---------- Marquee tagline along the bottom --------------------------- */

.stage-marquee {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 22px;
    display: flex;
    gap: var(--space-4);
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--color-text-subtle);
    white-space: nowrap;
    overflow: hidden;
    z-index: 3;
    mask-image: linear-gradient(to right, transparent, #000 15%, #000 85%, transparent);
    -webkit-mask-image: linear-gradient(to right, transparent, #000 15%, #000 85%, transparent);
}

.stage-marquee > * {
    display: inline-block;
    animation: marqueeSlide 18s linear infinite;
}

.stage-marquee .dot {
    color: var(--color-accent);
}

@keyframes marqueeSlide {
    from { transform: translateX(0); }
    to   { transform: translateX(-50%); }
}

/* ---------- Login card (right pane) ------------------------------------ */

.login-card {
    position: relative;
    width: 100%;
    padding: var(--space-7) var(--space-6);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02)),
                var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-xl);
    box-shadow:
        0 30px 80px rgba(7, 6, 26, 0.55),
        0 12px 30px rgba(107, 79, 245, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(20px) saturate(140%);
    -webkit-backdrop-filter: blur(20px) saturate(140%);
    align-self: center;
    animation: cardRise 900ms cubic-bezier(.16,.84,.32,1) 100ms both;
}

@keyframes cardRise {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}

.login-card::before {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: var(--radius-xl);
    padding: 1px;
    background: var(--brand-gradient);
    -webkit-mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    opacity: 0.55;
    pointer-events: none;
}

/* Animated traveling shimmer on the gradient border */
.login-card::after {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: var(--radius-xl);
    padding: 1px;
    background:
        conic-gradient(from var(--shimmer-from, 0deg),
            transparent 0deg,
            rgba(255, 255, 255, 0.65) 12deg,
            transparent 36deg,
            transparent 360deg);
    -webkit-mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    pointer-events: none;
    opacity: 0.7;
    animation: cardShimmer 6s linear infinite;
}

@property --shimmer-from {
    syntax: '<angle>';
    inherits: false;
    initial-value: 0deg;
}

@keyframes cardShimmer {
    to { --shimmer-from: 360deg; }
}

:root[data-theme="light"] .login-card {
    background: rgba(255, 255, 255, 0.86);
    box-shadow:
        0 30px 80px rgba(20, 16, 44, 0.18),
        0 12px 30px rgba(107, 79, 245, 0.10),
        inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="light"]) .login-card {
        background: rgba(255, 255, 255, 0.86);
        box-shadow:
            0 30px 80px rgba(20, 16, 44, 0.18),
            0 12px 30px rgba(107, 79, 245, 0.10),
            inset 0 1px 0 rgba(255, 255, 255, 0.7);
    }
}

.login-card > * {
    position: relative;
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
    text-align: center;
}

.login-brand .brand-link {
    font-size: 1.75rem;
    flex-direction: column;
    gap: var(--space-3);
}

.login-brand .brand-logo-xl {
    animation: logoFloat 4.5s ease-in-out infinite;
}

@keyframes logoFloat {
    0%, 100% { transform: translateY(0); filter: drop-shadow(0 12px 24px rgba(107, 79, 245, 0.45)); }
    50%      { transform: translateY(-4px); filter: drop-shadow(0 18px 32px rgba(217, 70, 239, 0.55)); }
}

.login-brand .brand-wordmark {
    background-size: 200% 100%;
    animation: wordmarkShine 6s ease-in-out infinite;
}

@keyframes wordmarkShine {
    0%, 100% { filter: brightness(1); }
    50%      { filter: brightness(1.15); }
}

.login-card h2 {
    margin-bottom: var(--space-1);
    text-align: center;
    font-size: 1.5rem;
}

.login-card .login-subtitle {
    color: var(--color-text-muted);
    margin-bottom: var(--space-5);
    font-size: 0.875rem;
    text-align: center;
}

/* Stagger reveal each form group */
.login-card .form-group {
    animation: fieldIn 600ms cubic-bezier(.16,.84,.32,1) both;
}
.login-card .form-group:nth-of-type(1) { animation-delay: 350ms; }
.login-card .form-group:nth-of-type(2) { animation-delay: 450ms; }

@keyframes fieldIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.login-card .input {
    height: 44px;
    background: rgba(7, 6, 26, 0.45);
    transition: border-color 160ms ease, box-shadow 200ms ease, background-color 160ms ease, transform 160ms ease;
}

.login-card .input:hover {
    background: rgba(7, 6, 26, 0.6);
}

.login-card .input:focus {
    background: rgba(7, 6, 26, 0.7);
    box-shadow: 0 0 0 3px var(--color-accent-ring), 0 8px 24px rgba(139, 92, 246, 0.25);
}

:root[data-theme="light"] .login-card .input {
    background: rgba(255, 255, 255, 0.6);
}
:root[data-theme="light"] .login-card .input:hover { background: rgba(255, 255, 255, 0.85); }
:root[data-theme="light"] .login-card .input:focus { background: #fff; }

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="light"]) .login-card .input {
        background: rgba(255, 255, 255, 0.6);
    }
    :root:not([data-theme="dark"]):not([data-theme="light"]) .login-card .input:hover { background: rgba(255, 255, 255, 0.85); }
    :root:not([data-theme="dark"]):not([data-theme="light"]) .login-card .input:focus { background: #fff; }
}

.login-card .login-tagline {
    margin-top: var(--space-4);
    text-align: center;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--color-text-subtle);
}

.login-card .login-switch {
    margin-top: var(--space-4);
    text-align: center;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.login-card .login-switch a {
    color: var(--color-accent);
    font-weight: 600;
    text-decoration: none;
}

.login-card .login-switch a:hover {
    color: var(--color-accent-hover);
    text-decoration: underline;
}

.login-card .login-demo-btn {
    width: 100%;
    margin-top: var(--space-3);
    font-size: 0.875rem;
}

.login-card .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

.login-card .form-row .form-group {
    margin-bottom: 0;
}

.input-with-toggle {
    position: relative;
}

.input-with-toggle > .input {
    padding-right: 42px;
}

.input-toggle-btn {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: color 160ms ease, background-color 160ms ease;
}

.input-toggle-btn:hover {
    color: var(--color-text);
    background: var(--color-surface-2);
}

.input-toggle-btn:focus-visible {
    outline: none;
    color: var(--color-text);
    box-shadow: 0 0 0 2px var(--color-accent-ring);
}

.input-toggle-btn[aria-pressed="true"] {
    color: var(--color-accent);
}

.login-card .btn-primary {
    width: 100%;
    height: 46px;
    margin-top: var(--space-3);
    font-size: 0.9375rem;
    animation: fieldIn 600ms cubic-bezier(.16,.84,.32,1) 550ms both;
}

.login-card .btn-primary .btn-arrow {
    width: 16px;
    height: 16px;
    transition: transform 220ms cubic-bezier(.4,.0,.2,1);
}

.login-card .btn-primary:hover:not(:disabled) .btn-arrow {
    transform: translateX(4px);
}

/* ---------- Responsive: collapse to single column ---------------------- */

@media (max-width: 920px) {
    .login-shell {
        grid-template-columns: 1fr;
        max-width: 480px;
        gap: var(--space-5);
    }
    .login-stage {
        min-height: 320px;
        order: 2;
    }
    .login-card {
        order: 1;
        padding: var(--space-6);
    }
    .hud-tl, .hud-tr { top: 24px; }
    .hud-tl { left: 24px; }
    .hud-tr { right: 24px; }
    .hud-bl, .hud-br { bottom: 56px; }
    .hud-bl { left: 24px; }
    .hud-br { right: 24px; }
    .vf-tl, .vf-tr { top: 12px; }
    .vf-bl, .vf-br { bottom: 12px; }
    .vf-tl, .vf-bl { left: 12px; }
    .vf-tr, .vf-br { right: 12px; }
}

@media (max-width: 520px) {
    .login-stage { min-height: 260px; }
    .stage-hud .hud-value { font-size: 0.875rem; }
    .scan-cube { --size: 100px; }
    .cf-front  { transform: translateZ(50px); }
    .cf-back   { transform: translateZ(-50px) rotateY(180deg); }
    .cf-right  { transform: rotateY(90deg) translateZ(50px); }
    .cf-left   { transform: rotateY(-90deg) translateZ(50px); }
    .cf-top    { transform: rotateX(90deg) translateZ(50px); }
    .cf-bottom { transform: rotateX(-90deg) translateZ(50px); }
    .orbit-1 { width: 200px; height: 200px; }
    .orbit-2 { width: 260px; height: 260px; }
    .orbit-3 { width: 320px; height: 320px; }
}

/* ---------- Honor reduced motion --------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .login-shell,
    .login-card,
    .login-stage,
    .stage-grid,
    .stage-aurora,
    .scan-cube,
    .scan-orbit,
    .scan-beam,
    .scan-base,
    .pc-dot,
    .dust,
    .stage-marquee > *,
    .login-card::after,
    .login-brand .brand-logo-xl,
    .vf-corner,
    .hud-pulse,
    .login-card .form-group,
    .login-card .btn-primary {
        animation: none !important;
    }
    .scan-beam { opacity: 0.6; top: 50%; }
}

/* Backwards-compat for old class names */
.auth-page { /* alias */ }
.auth-card { /* alias */ }

/* =========================================================================
   Page: Home
   ========================================================================= */

.home-hero {
    position: relative;
    padding: var(--space-8) var(--space-5);
    text-align: center;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    background:
        radial-gradient(600px 300px at 50% 0%, var(--color-accent-soft), transparent 65%),
        linear-gradient(180deg, var(--color-surface), var(--color-bg));
    overflow: hidden;
    margin-bottom: var(--space-6);
}

.home-hero::before {
    /* starfield / grid texture */
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(1px 1px at 20% 30%, var(--color-text-muted) 50%, transparent 51%),
        radial-gradient(1px 1px at 70% 20%, var(--color-accent) 50%, transparent 51%),
        radial-gradient(1px 1px at 40% 70%, var(--color-text-subtle) 50%, transparent 51%),
        radial-gradient(1px 1px at 85% 60%, var(--color-text-muted) 50%, transparent 51%),
        radial-gradient(1px 1px at 15% 80%, var(--color-accent) 50%, transparent 51%),
        linear-gradient(to right, var(--color-border) 1px, transparent 1px),
        linear-gradient(to bottom, var(--color-border) 1px, transparent 1px);
    background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 56px 56px, 56px 56px;
    opacity: 0.35;
    mask-image: radial-gradient(900px 500px at 50% 30%, #000 0%, transparent 80%);
    -webkit-mask-image: radial-gradient(900px 500px at 50% 30%, #000 0%, transparent 80%);
    pointer-events: none;
}

.home-hero > * { position: relative; }

.hero-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 4px var(--space-3);
    margin-bottom: var(--space-4);
    background: var(--color-accent-soft);
    border: 1px solid var(--color-accent-ring);
    border-radius: var(--radius-pill);
    color: var(--color-accent);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.hero-eyebrow::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-accent);
    box-shadow: 0 0 8px var(--color-accent);
}

.home-hero h1 {
    font-size: clamp(1.875rem, 4vw, 2.75rem);
    line-height: 1.1;
    letter-spacing: -0.02em;
    margin-bottom: var(--space-3);
}

.home-hero h1 .accent {
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.home-hero .hero-subtitle {
    max-width: 640px;
    margin: 0 auto var(--space-5);
    color: var(--color-text-muted);
    font-size: 1.0625rem;
}

.hero-cta {
    display: inline-flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    justify-content: center;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--space-4);
}

.feature-card {
    padding: var(--space-5);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.feature-card:hover {
    transform: translateY(-2px);
    border-color: var(--color-accent-ring);
    box-shadow: var(--shadow-md);
}

.feature-icon {
    width: 40px;
    height: 40px;
    margin-bottom: var(--space-3);
    display: grid;
    place-items: center;
    border-radius: var(--radius-md);
    background: var(--color-accent-soft);
    color: var(--color-accent);
}

.feature-icon svg { width: 22px; height: 22px; }

.feature-card h3 {
    margin-bottom: var(--space-2);
}

.feature-card p {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin: 0;
}

/* =========================================================================
   Page: Scans
   ========================================================================= */

.scans-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
}

.scans-header h2 { margin: 0; }

.scans-header .scans-title-group {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
}

.scans-header .scans-count {
    color: var(--color-text-subtle);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
}

.scans-controls {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.scans-search {
    width: clamp(220px, 32vw, 360px);
}

.scan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--space-4);
}

.pager-row {
    margin-top: var(--space-6);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    color: var(--color-text-muted);
}

.pager-row .pager-label {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-8) var(--space-5);
    background: var(--color-surface);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-lg);
}

.empty-state .empty-icon {
    width: 56px;
    height: 56px;
    margin-bottom: var(--space-4);
    color: var(--color-text-subtle);
}

.empty-state h3 {
    margin-bottom: var(--space-2);
}

.empty-state p {
    color: var(--color-text-muted);
    max-width: 420px;
    margin: 0;
}

/* Secondary note under an empty state: which API/account the (empty) list came from. */
.empty-state .empty-note {
    margin-top: var(--space-3);
    max-width: 520px;
    color: var(--color-text-subtle);
    font-size: 0.8125rem;
    line-height: 1.5;
}

.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    padding: var(--space-7);
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--color-border-strong);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- Scan card --------------------------------------------------- */

.scan-card {
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
    text-align: left;
    position: relative;
}

.scan-card:hover {
    transform: translateY(-2px);
    border-color: var(--color-accent-ring);
    box-shadow: var(--shadow-md);
}

.scan-card:focus-visible {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-ring);
}

.scan-thumb-wrap {
    position: relative;
    aspect-ratio: 16 / 10;
    background:
        linear-gradient(135deg, #1a1438 0%, #221b47 50%, #110d2c 100%);
    overflow: hidden;
}

.scan-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Client-rendered preview, layered over the placeholder cube. thumbnailer.js sets
   the src and fades opacity to 1 once the mesh has been rendered to a PNG; until
   then the placeholder shows through underneath. */
.scan-thumb.generated {
    position: absolute;
    inset: 0;
    z-index: 1;
    opacity: 0;
    transition: opacity 220ms ease;
}

.scan-thumb.placeholder {
    display: grid;
    place-items: center;
    color: var(--color-text-subtle);
}

.scan-thumb-wrap.placeholder {
    background:
        radial-gradient(circle at 30% 30%, rgba(77, 110, 255, 0.30), transparent 55%),
        radial-gradient(circle at 70% 70%, rgba(217, 70, 239, 0.18), transparent 55%),
        linear-gradient(135deg, #110d2c, #221b47);
}

.scan-thumb-wrap.placeholder::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(to right, rgba(255,255,255,0.04) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.04) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
}

.scan-thumb-wrap.placeholder .placeholder-icon {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--color-text-subtle);
}

.scan-thumb-wrap.placeholder .placeholder-icon svg {
    width: 40px;
    height: 40px;
    opacity: 0.6;
}

.scan-card-body {
    padding: var(--space-3) var(--space-4) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.scan-card-body .scan-name {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text);
}

.scan-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2);
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.scan-meta .scan-size,
.scan-meta .scan-time {
    font-family: var(--font-mono);
}

.scan-meta .meta-dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--color-text-subtle);
    flex-shrink: 0;
}

/* =========================================================================
   Page: Scan Detail
   ========================================================================= */

.scan-detail-layout {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.viewer-container {
    position: relative;
    min-height: 70vh;
    background: #07061a;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.mesh-viewer-container {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 70vh;
}

.mesh-viewer-canvas {
    display: block;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse at center, #110d2c 0%, #07061a 70%);
}

.mesh-viewer-toolbar {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1);
    background: rgba(7, 6, 26, 0.72);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 5;
}

.mesh-viewer-toolbar .btn-icon {
    color: var(--color-text);
}

.mesh-viewer-toolbar .btn-icon:disabled {
    opacity: 0.35;
    cursor: default;
}

.mesh-viewer-toolbar .btn-icon:disabled:hover {
    background: transparent;
    color: var(--color-text);
}

.mesh-viewer-toolbar .toolbar-divider {
    background: var(--color-border-strong);
}

.scan-info-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4);
    align-items: start;
    min-width: 0;
}

.scan-info-row > * {
    min-width: 0;
}

/* The location map is the prominent panel at the bottom of the scan page. */
.scan-location-card {
    width: 100%;
}

.scan-info-card {
    padding: var(--space-5);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

.scan-info-card h2 {
    margin: 0 0 var(--space-1);
    word-break: break-word;
}

.scan-info-card .scan-subtitle {
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    margin-bottom: var(--space-4);
}

.scan-info-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-2) var(--space-4);
    margin-bottom: var(--space-4);
    font-size: 0.8125rem;
}

.scan-info-grid dt {
    color: var(--color-text-subtle);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.6875rem;
    letter-spacing: 0.06em;
    align-self: center;
}

.scan-info-grid dd {
    margin: 0;
    color: var(--color-text);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    word-break: break-word;
}

.scan-sidebar-actions {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.scan-sidebar-actions .btn { flex: 1; }

.scan-danger-zone {
    margin-top: var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--color-border);
}

.scan-delete-trigger {
    color: var(--color-danger);
    padding-left: 0;
    padding-right: 0;
}

.scan-delete-trigger:hover:not(:disabled) {
    color: var(--color-danger);
    background: var(--color-danger-soft);
}

.scan-delete-prompt {
    margin: 0 0 var(--space-2);
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.scan-delete-confirm {
    display: flex;
    gap: var(--space-2);
}

.scan-delete-confirm .btn { flex: 1; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    margin-bottom: var(--space-4);
}

.back-link:hover {
    color: var(--color-accent);
}

.back-link svg { width: 14px; height: 14px; }

/* =========================================================================
   Measurement Panel — instrument-grade display
   ========================================================================= */

/* Floating label drawn over the 3D scene at each measurement's midpoint.
   --label-color is set per-measurement inline so it matches the panel card. */
.measurement-label {
    --label-color: var(--color-accent);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    color: #fff;
    background: rgba(7, 6, 26, 0.82);
    border: 1px solid var(--label-color);
    border-radius: 999px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45), 0 0 14px -3px var(--label-color);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    pointer-events: none;
    user-select: none;
}

.measurement-label::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--label-color);
    box-shadow: 0 0 8px var(--label-color);
}

/* The live running total shown while a broken line is still being drawn. A
   dashed outline marks it as not-yet-committed. */
.measurement-label-pending {
    border-style: dashed;
    opacity: 0.92;
}

.measurement-panel {
    padding: var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.measurement-panel h3 {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-subtle);
}

.measurement-panel h3::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-accent);
    box-shadow: 0 0 6px var(--color-accent);
}

.measurement-panel h3 .mp-count {
    margin-left: auto;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--color-accent);
    background: var(--color-accent-soft);
    border: 1px solid var(--color-accent-ring);
    border-radius: 999px;
}

.measurement-empty {
    padding: var(--space-4);
    background: var(--color-bg);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-md);
    color: var(--color-text-subtle);
    font-size: 0.8125rem;
    text-align: center;
    font-family: var(--font-mono);
}

.measurement-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-height: 440px;
    overflow-y: auto;
}

.measurement-card {
    --card-color: var(--color-accent);
    position: relative;
    padding: var(--space-3);
    padding-left: calc(var(--space-3) + 5px);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

/* Colored rail ties each card to its line/label in the 3D scene. */
.measurement-card::before {
    content: "";
    position: absolute;
    top: var(--space-2);
    bottom: var(--space-2);
    left: 0;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--card-color);
}

.measurement-card .mc-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.measurement-card .mc-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--card-color);
    box-shadow: 0 0 8px var(--card-color);
    flex-shrink: 0;
}

.measurement-card .mc-index {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--color-text-subtle);
}

.measurement-card .mc-remove {
    margin-left: auto;
    width: 26px;
    height: 26px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-subtle);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.measurement-card .mc-remove:hover {
    color: var(--color-danger);
    background: var(--color-danger-soft);
}

.measurement-card .mc-tag {
    width: 100%;
    padding: var(--space-1) var(--space-2);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.measurement-card .mc-tag::placeholder {
    color: var(--color-text-subtle);
}

.measurement-card .mc-tag:focus {
    outline: none;
    border-color: var(--card-color);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--card-color) 28%, transparent);
}

.measurement-card .mc-value {
    font-family: var(--font-mono);
    font-size: 1.375rem;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -0.01em;
    color: var(--color-text);
}

.measurement-card .mc-value .mc-unit {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    font-weight: 500;
    margin-left: 3px;
}

.measurement-card .mc-value .mc-segments {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    letter-spacing: 0;
    margin-left: 8px;
}

.measurement-card .mc-value .mc-segments::before {
    content: "· ";
}

.measurement-card .mc-points {
    display: grid;
    gap: 2px;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--color-text-muted);
}

.measurement-card .mc-point-row {
    display: grid;
    grid-template-columns: 26px 1fr;
    align-items: center;
    gap: var(--space-2);
}

.measurement-card .mc-point-row .mc-point-label {
    color: var(--card-color);
    font-weight: 700;
}

.measurement-card .mc-point-row .mc-point-coords {
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 900px) {
    .scan-info-row {
        grid-template-columns: 1fr;
    }
    .viewer-container,
    .mesh-viewer-container {
        min-height: 55vh;
    }
    .scan-map {
        height: 340px;
    }
}

@media (max-width: 760px) {
    .dashboard-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-3) var(--space-4);
        border-right: 0;
        border-bottom: 1px solid var(--color-border);
    }

    .sidebar-header {
        padding: 0;
        margin: 0;
    }

    .nav-stack {
        flex-direction: row;
        flex: 1;
        gap: var(--space-1);
        overflow-x: auto;
    }

    .nav-section-label { display: none; }

    .nav-link {
        padding: var(--space-2) var(--space-3);
        white-space: nowrap;
    }

    .sidebar-footer {
        margin-top: 0;
        padding-top: 0;
        border-top: 0;
        border-left: 1px solid var(--color-border);
        padding-left: var(--space-3);
    }

    .user-chip { padding: 0; }
    .user-info { display: none; }
    .user-chip-chevron { display: none; }
    .sidebar-footer .btn { margin-top: 0; width: auto; }

    .page { padding: var(--space-4); }

    .home-hero { padding: var(--space-6) var(--space-4); }
}

/* =========================================================================
   Page: Settings
   ========================================================================= */

.settings-container {
    max-width: 880px;
    margin: 0 auto;
}

.settings-header {
    margin-bottom: var(--space-6);
}

.settings-header h2 {
    margin-bottom: var(--space-2);
}

.settings-subtitle {
    color: var(--color-text-muted);
    font-size: 0.9375rem;
    margin: 0;
}

.settings-section {
    padding: var(--space-5);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.settings-section + .settings-section {
    margin-top: var(--space-5);
}

.settings-section-head {
    margin-bottom: var(--space-4);
}

.settings-section-head h3 {
    margin-bottom: var(--space-1);
}

.settings-section-head p {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* ---------- Account page ----------------------------------------------- */

.account-identity {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding-bottom: var(--space-4);
    margin-bottom: var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.account-avatar {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-pill);
    background: var(--brand-gradient);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 1.125rem;
    flex-shrink: 0;
    box-shadow: 0 6px 16px rgba(107, 79, 245, 0.40);
}

.account-identity-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.account-name {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--color-text);
}

.account-username {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.account-badge {
    margin-left: auto;
    align-self: flex-start;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-pill);
    background: var(--color-accent-soft);
    color: var(--color-accent);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.account-details {
    margin: 0;
    display: grid;
    gap: var(--space-3);
}

.account-detail {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
}

.account-detail dt {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin: 0;
}

.account-detail dd {
    margin: 0;
    color: var(--color-text);
    font-weight: 600;
    text-align: right;
    word-break: break-word;
}

.theme-picker {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-3);
}

.theme-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text);
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.theme-card:hover {
    border-color: var(--color-border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.theme-card:focus-visible {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-ring);
}

.theme-card.is-selected {
    border-color: var(--color-accent);
    background: var(--color-accent-soft);
    box-shadow: 0 0 0 1px var(--color-accent-ring) inset;
}

.theme-card-check {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    width: 18px;
    height: 18px;
    color: var(--color-accent);
}

.theme-card-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.theme-card-title {
    font-size: 0.9375rem;
    font-weight: 600;
}

.theme-card-desc {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    line-height: 1.4;
}

/* Preview tile inside each theme card */
.theme-preview {
    --tp-bg:      #07061a;
    --tp-surface: #110d2c;
    --tp-line:    #2c2456;
    --tp-accent:  #8b5cf6;

    position: relative;
    display: flex;
    height: 96px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
    background: var(--tp-bg);
}

.theme-preview-sidebar {
    width: 30%;
    background: var(--tp-surface);
    border-right: 1px solid var(--tp-line);
    position: relative;
}

.theme-preview-sidebar::before,
.theme-preview-sidebar::after {
    content: "";
    position: absolute;
    left: 10%;
    right: 18%;
    height: 6px;
    background: var(--tp-line);
    border-radius: 3px;
}

.theme-preview-sidebar::before { top: 16%; background: var(--tp-accent); }
.theme-preview-sidebar::after  { top: 38%; }

.theme-preview-body {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background:
        radial-gradient(120% 80% at 0% 0%, rgba(139, 92, 246, 0.15), transparent 60%),
        var(--tp-bg);
}

.theme-preview-bar {
    height: 8px;
    width: 80%;
    border-radius: 4px;
    background: var(--tp-accent);
    opacity: 0.85;
}

.theme-preview-bar.short {
    width: 50%;
    background: var(--tp-line);
    opacity: 1;
}

/* Dark preview — explicit values so the card looks the same regardless of active theme */
.theme-preview-dark {
    --tp-bg:      #07061a;
    --tp-surface: #110d2c;
    --tp-line:    #2c2456;
    --tp-accent:  #8b5cf6;
}

/* Light preview */
.theme-preview-light {
    --tp-bg:      #faf8ff;
    --tp-surface: #ffffff;
    --tp-line:    #d8d2ee;
    --tp-accent:  #7c3aed;
}

/* Auto preview — split down the middle */
.theme-preview-auto {
    background: linear-gradient(90deg, #07061a 0 50%, #faf8ff 50% 100%);
}

.theme-preview-auto .theme-preview-sidebar {
    background: #110d2c;
    border-right-color: #2c2456;
}
.theme-preview-auto .theme-preview-sidebar::before { background: #8b5cf6; }
.theme-preview-auto .theme-preview-sidebar::after  { background: #2c2456; }

.theme-preview-auto .theme-preview-body {
    background:
        linear-gradient(90deg, #07061a 0 40%, #faf8ff 60% 100%);
}

.theme-preview-auto .theme-preview-bar { background: #8b5cf6; }
.theme-preview-auto .theme-preview-bar.short { background: #c8c0e4; }

/* =========================================================================
   Scans — Filter panel + upload toast
   ========================================================================= */

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.btn-tertiary {
    background: transparent;
    color: var(--color-text-muted);
    border-color: transparent;
}

.btn-tertiary:hover:not(:disabled) {
    color: var(--color-text);
    background: var(--color-surface-2);
}

.spinner-sm {
    width: 14px;
    height: 14px;
    border-width: 2px;
}

.upload-btn {
    cursor: pointer;
    user-select: none;
}

.upload-btn.is-disabled {
    opacity: 0.65;
    pointer-events: none;
}

.upload-toast {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    font-size: 0.875rem;
}

.upload-toast.is-info {
    border-color: var(--color-accent-ring);
    background: var(--color-accent-soft);
    color: var(--color-text);
}

.upload-toast.is-success {
    border-color: rgba(52, 211, 153, 0.45);
    background: rgba(52, 211, 153, 0.12);
    color: var(--color-text);
}

.upload-toast.is-error {
    border-color: rgba(251, 113, 133, 0.45);
    background: var(--color-danger-soft);
    color: var(--color-text);
}

.upload-toast .toast-close {
    background: transparent;
    border: 0;
    color: inherit;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 var(--space-1);
    opacity: 0.7;
}

.upload-toast .toast-close:hover { opacity: 1; }

.filter-wrap {
    position: relative;
}

.filter-wrap .btn .filter-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 var(--space-1);
    margin-left: var(--space-1);
    border-radius: var(--radius-pill);
    background: var(--color-accent);
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 600;
}

.filter-wrap .btn.is-active,
.filter-wrap .btn.has-active {
    border-color: var(--color-accent-ring);
    color: var(--color-accent);
}

.filter-panel {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    z-index: 30;
    width: clamp(280px, 32vw, 360px);
    padding: var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.filter-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.filter-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

.filter-range {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: var(--space-2);
}

.filter-range-sep {
    color: var(--color-text-subtle);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
}

.filter-actions {
    display: flex;
    justify-content: space-between;
    gap: var(--space-2);
    margin-top: var(--space-1);
    padding-top: var(--space-3);
    border-top: 1px solid var(--color-border);
}

/* ---------------------------------------------------------------- Maps -- */

.leaflet-container {
    background: var(--color-surface-2);
    font-family: var(--font-sans, inherit);
}

/* Shown inside a map container when Google Maps can't load (no key / offline). */
.map-unavailable {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 120px;
    padding: var(--space-4);
    text-align: center;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--color-text-muted);
    background: var(--color-surface);
}

/* Pin popup: a compact scan card (preview, name, capture meta, open button). The
   Google InfoWindow chrome is white, so text colors here are dark on purpose. */
.armisure-map-popup {
    width: 224px;
    font-family: var(--font-sans, inherit);
}

.armisure-map-thumb {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: 16 / 10;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: linear-gradient(135deg, #2a2350, #14102c);
}

.armisure-map-thumb-icon {
    color: rgba(255, 255, 255, 0.4);
}

.armisure-map-thumb-icon svg {
    width: 38px;
    height: 38px;
}

.armisure-map-thumb-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.armisure-map-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 8px 2px 2px;
}

.armisure-map-name {
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.3;
    color: #14102c;
}

.armisure-map-meta {
    font-size: 0.75rem;
    color: #5b5570;
}

.armisure-map-coords {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.6875rem;
    color: #8a84a0;
}

.armisure-map-open {
    margin-top: 6px;
    border: none;
    background: var(--color-accent);
    color: #fff;
    border-radius: var(--radius-sm);
    padding: 7px 9px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.armisure-map-open:hover {
    background: var(--color-accent-hover);
}

/* Location map: the large panel at the bottom of the scan detail page. */
.scan-map {
    height: 460px;
    width: 100%;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.scan-location-note {
    margin: var(--space-2) 0 0;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--color-text-subtle);
}

.scan-location-coords {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-top: var(--space-2);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.scan-location-accuracy {
    color: var(--color-text-subtle);
}

.scan-location-empty {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.scan-location-link {
    margin-top: var(--space-2);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-accent);
}

/* Full overview map page. */
.map-page-header {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.map-canvas {
    height: 70vh;
    min-height: 420px;
    width: 100%;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.scan-card-title {
    margin: 0 0 var(--space-3);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-text);
}

.map-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: 60vh;
    min-height: 360px;
    text-align: center;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-lg);
}
