/* ==========================================================================
   NoGSM Web - Tactical Clarity Design System
   levelwaves.com
   Tokens source: /var/www/alex/nogsm/designs/app-ui/tokens/
   ========================================================================== */

/* CSS Custom Properties - Semantic Color System (matches colors.kt exactly) */
:root {
    /* Light theme (default) - matches LightColorPalette */
    --color-surface: #FAFAFA;
    --color-surface-elevated: #FFFFFF;
    --color-border: #E2E8F0;

    --color-text-primary: #0F172A;
    --color-text-secondary: #475569;
    --color-text-inverse: #FFFFFF;

    /* Threat semantics */
    --color-threat-critical: #DC2626;
    --color-threat-elevated: #F59E0B;
    --color-threat-none: #059669;

    /* Mesh semantics */
    --color-mesh-active: #2563EB;
    --color-mesh-inactive: #64748B;

    /* Proof semantics */
    --color-proof-valid: #059669;
    --color-proof-pending: #F59E0B;
    --color-proof-invalid: #DC2626;

    /* Overlays */
    --color-accuracy-ring: rgba(37, 99, 235, 0.3);

    /* Component colors (semantic aliases) */
    --color-primary: var(--color-mesh-active);
    --color-primary-container: rgba(37, 99, 235, 0.15);
    --color-on-primary: var(--color-text-inverse);
    --color-on-primary-container: var(--color-mesh-active);

    --color-secondary: var(--color-threat-none);
    --color-secondary-container: rgba(5, 150, 105, 0.15);
    --color-on-secondary: var(--color-text-inverse);

    --color-tertiary: var(--color-threat-elevated);
    --color-tertiary-container: rgba(245, 158, 11, 0.15);
    --color-on-tertiary: #000000;

    --color-error: var(--color-threat-critical);
    --color-error-container: rgba(220, 38, 38, 0.15);
    --color-on-error: var(--color-text-inverse);

    /* Focus */
    --color-focus: var(--color-mesh-active);
    --color-focus-ring: rgba(37, 99, 235, 0.4);

    /* Shadows (matches NoGSMDimensions elevation) */
    --shadow-elevation-low: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-elevation-medium: 0 4px 8px -2px rgba(15, 23, 42, 0.15), 0 2px 4px -2px rgba(15, 23, 42, 0.1);
    --shadow-elevation-high: 0 10px 20px -5px rgba(15, 23, 42, 0.2), 0 4px 8px -4px rgba(15, 23, 42, 0.1);
    --shadow-elevation-overlay: 0 20px 40px -10px rgba(15, 23, 42, 0.3), 0 8px 16px -8px rgba(15, 23, 42, 0.15);

    /* Spacing - 8dp base grid (matches NoGSMSpacing) */
    --space-none: 0;
    --space-xxxs: 4px;    /* base/2 - hairline gaps */
    --space-xxs: 8px;     /* base - tight internal padding (inline) */
    --space-xs: 16px;     /* base*2 - standard padding (compact) */
    --space-sm: 24px;     /* base*3 - comfortable padding (comfortable) */
    --space-md: 32px;     /* base*4 - section spacing (section) */
    --space-lg: 40px;     /* base*5 - large section spacing (major) */
    --space-xl: 48px;     /* base*6 - major section spacing (screen) */
    --space-xxl: 64px;    /* base*8 - screen-level spacing */
    --space-xxxl: 80px;   /* base*10 - hero spacing */

    /* Semantic spacing aliases */
    --space-inline: var(--space-xxs);      /* 8dp */
    --space-compact: var(--space-xs);      /* 16dp */
    --space-comfortable: var(--space-sm);  /* 24dp */
    --space-section: var(--space-md);      /* 32dp */
    --space-major: var(--space-lg);        /* 40dp */
    --space-screen: var(--space-xl);       /* 48dp */

    /* Border radius (matches NoGSMDimensions) */
    --radius-none: 0;
    --radius-xs: 4px;        /* chip, badges */
    --radius-sm: 8px;        /* standard: cards, sheets, buttons */
    --radius-md: 12px;       /* larger containers */
    --radius-lg: 16px;       /* sheets, modals */
    --radius-xl: 24px;       /* full-screen modals */
    --radius-full: 9999px;   /* pills, circles */

    /* Semantic radius */
    --radius-chip: var(--radius-xs);
    --radius-button: var(--radius-sm);
    --radius-card: var(--radius-sm);
    --radius-sheet: var(--radius-lg);
    --radius-modal: var(--radius-xl);
    --radius-pill: var(--radius-full);

    /* Border widths */
    --border-hairline: 0.5px;
    --border-thin: 1px;
    --border-thick: 2px;

    /* Icon sizes */
    --icon-xs: 16px;
    --icon-sm: 20px;
    --icon-md: 24px;
    --icon-lg: 32px;
    --icon-xl: 48px;

    /* Map marker sizes */
    --marker-peer: 12px;
    --marker-position: 28px;
    --marker-cluster: 36px;

    /* Sheet sizes */
    --right-sheet-width: 300px;
    --bottom-sheet-peek: 160px;   /* collapsed height */
    --bottom-sheet-half: 60%;     /* half expanded ratio */
    --bottom-sheet-full: 90%;     /* full expanded ratio */

    /* Touch targets */
    --touch-target-min: 48px;
    --touch-target-comfortable: 56px;
    --touch-target-dense: 40px;

    /* Animation durations (MAX 150ms per spec) */
    --anim-instant: 0ms;
    --anim-fast: 75ms;
    --anim-standard: 150ms;
    --anim-slow: 200ms;

    /* Z-index layers */
    --z-base: 0;
    --z-map: 1;
    --z-map-markers: 10;
    --z-top-bar: 100;
    --z-bottom-sheet: 200;
    --z-right-sheet: 200;
    --z-threat-overlay: 1000;
    --z-toast: 2000;

    /* Typography (matches NoGSMTypeScale) */
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* UI text styles */
    --text-display-large: 32px;
    --text-display-medium: 28px;
    --text-headline-large: 22px;
    --text-headline-medium: 18px;
    --text-headline-small: 16px;
    --text-title-large: 14px;
    --text-title-medium: 13px;
    --text-title-small: 12px;
    --text-body-large: 14px;
    --text-body-medium: 13px;
    --text-body-small: 12px;
    --text-label-large: 13px;
    --text-label-medium: 12px;
    --text-label-small: 11px;

    /* Data styles (monospace) */
    --text-data-display: 28px;
    --text-data-display-medium: 22px;
    --text-data-large: 14px;
    --text-data-medium: 13px;
    --text-data-small: 11px;
    --text-data-micro: 10px;
    --text-code: 12px;

    /* Line heights (dp-aligned) */
    --lh-display: 40px;
    --lh-display-medium: 36px;
    --lh-headline-large: 28px;
    --lh-headline-medium: 24px;
    --lh-headline-small: 22px;
    --lh-title-large: 20px;
    --lh-title-medium: 18px;
    --lh-title-small: 16px;
    --lh-body-large: 20px;
    --lh-body-medium: 18px;
    --lh-body-small: 16px;
    --lh-label-large: 18px;
    --lh-label-medium: 16px;
    --lh-label-small: 14px;
    --lh-data-display: 36px;
    --lh-data-display-medium: 28px;
    --lh-data-large: 20px;
    --lh-data-medium: 18px;
    --lh-data-small: 14px;
    --lh-data-micro: 12px;
    --lh-code: 16px;

    /* Letter spacing */
    --ls-tight: -0.5px;
    --ls-normal: 0;
    --ls-loose: 0.1px;
    --ls-label: 0.2px;
    --ls-label-small: 0.3px;

    /* Component dimensions */
    --topbar-height: 48px;
    --sheet-handle-height: 16px;
    --chip-height: 32px;
    --button-height: 40px;
    --list-item-min-height: 48px;
}

/* Dark theme - matches DarkColorPalette exactly */
[data-theme="dark"] {
    --color-surface: #030712;
    --color-surface-elevated: #0F172A;
    --color-border: #1E293B;

    --color-text-primary: #F8FAFC;
    --color-text-secondary: #94A3B8;
    --color-text-inverse: #030712;

    --color-threat-critical: #EF4444;
    --color-threat-elevated: #FBBF24;
    --color-threat-none: #34D399;

    --color-mesh-active: #60A5FA;
    --color-mesh-inactive: #64748B;

    --color-proof-valid: #34D399;
    --color-proof-pending: #FBBF24;
    --color-proof-invalid: #EF4444;

    --color-accuracy-ring: rgba(96, 165, 250, 0.3);

    --color-primary: var(--color-mesh-active);
    --color-primary-container: rgba(96, 165, 250, 0.2);
    --color-on-primary: var(--color-text-inverse);
    --color-on-primary-container: var(--color-mesh-active);

    --color-secondary: var(--color-threat-none);
    --color-secondary-container: rgba(52, 211, 153, 0.2);
    --color-on-secondary: var(--color-text-inverse);

    --color-tertiary: var(--color-threat-elevated);
    --color-tertiary-container: rgba(251, 191, 36, 0.2);
    --color-on-tertiary: #000000;

    --color-error: var(--color-threat-critical);
    --color-error-container: rgba(239, 68, 68, 0.2);
    --color-on-error: var(--color-text-inverse);

    --color-focus: var(--color-mesh-active);
    --color-focus-ring: rgba(96, 165, 250, 0.4);

    --shadow-elevation-low: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-elevation-medium: 0 4px 8px -2px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-elevation-high: 0 10px 20px -5px rgba(0, 0, 0, 0.4), 0 4px 8px -4px rgba(0, 0, 0, 0.3);
    --shadow-elevation-overlay: 0 20px 40px -10px rgba(0, 0, 0, 0.5), 0 8px 16px -8px rgba(0, 0, 0, 0.4);
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
}

body {
    font-family: var(--font-ui);
    font-size: var(--text-body-large);
    line-height: var(--lh-body-large);
    color: var(--color-text-primary);
    background: var(--color-surface);
    min-height: 100vh;
    overflow: hidden;
}

#app {
    display: grid;
    grid-template-rows: var(--topbar-height) 1fr;
    grid-template-columns: 1fr;
    grid-template-areas:
        "topbar"
        "main";
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: relative;
}

/* ==========================================================================
   Top Bar (48dp, semi-transparent surface-elevated)
   ========================================================================== */

.top-bar {
    grid-area: topbar;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-compact);
    height: var(--topbar-height);
    background: var(--color-surface-elevated);
    border-bottom: var(--border-thin) solid var(--color-border);
    z-index: var(--z-top-bar);
    position: relative;
}

/* Left: Threat Status Pill (32dp height, pill radius) */
.threat-pill {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 var(--space-compact);
    min-width: 80px;
    background: var(--color-threat-none);
    color: var(--color-text-inverse);
    border: none;
    border-radius: var(--radius-pill);
    font-family: var(--font-ui);
    font-size: var(--text-label-medium);
    font-weight: 600;
    line-height: var(--lh-label-medium);
    letter-spacing: var(--ls-label);
    text-transform: uppercase;
    cursor: pointer;
    transition: background var(--anim-fast), box-shadow var(--anim-fast), transform var(--anim-fast);
    touch-action: manipulation;
    min-height: var(--touch-target-min);
}

.threat-pill:hover {
    box-shadow: var(--shadow-elevation-medium);
    transform: scale(1.02);
}

.threat-pill:active {
    transform: scale(0.98);
}

.threat-pill:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

/* Threat pill states */
.threat-pill[data-level="normal"] { background: var(--color-threat-none); }
.threat-pill[data-level="hold"] { background: var(--color-threat-elevated); }
.threat-pill[data-level="reject"],
.threat-pill[data-level="spoofed"] { background: var(--color-threat-critical); }

/* SPOOFED pulse animation */
.threat-pill[data-level="spoofed"] {
    animation: threat-pulse 1.5s ease-in-out infinite;
}

@keyframes threat-pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--color-threat-critical); }
    50% { box-shadow: 0 0 0 6px transparent; }
}

/* Center: H3 Cell Index (monospace, copyable, resolution badge) */
.h3-cell {
    display: flex;
    align-items: center;
    gap: var(--space-xxs);
    padding: var(--space-xxxs) var(--space-xxs);
    background: transparent;
    border: none;
    border-radius: var(--radius-button);
    cursor: pointer;
    transition: background var(--anim-fast);
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
}

.h3-cell:hover {
    background: var(--color-border);
}

.h3-cell:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.h3-cell-index {
    font-family: var(--font-mono);
    font-size: var(--text-data-medium);
    font-weight: 400;
    line-height: var(--lh-data-medium);
    letter-spacing: var(--ls-normal);
    color: var(--color-text-primary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    user-select: all;
    -webkit-user-select: all;
}

.h3-resolution-badge {
    font-family: var(--font-mono);
    font-size: var(--text-data-micro);
    font-weight: 500;
    line-height: var(--lh-data-micro);
    color: var(--color-text-secondary);
    white-space: nowrap;
    padding: var(--space-xxxs) var(--space-xxxs);
    background: var(--color-border);
    border-radius: var(--radius-chip);
}

/* Right: Proof Status Icon (24dp) */
.proof-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    color: var(--color-proof-valid);
    transition: background var(--anim-fast), color var(--anim-fast);
    touch-action: manipulation;
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
}

.proof-icon-btn:hover {
    background: var(--color-border);
}

.proof-icon-btn:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.proof-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

/* Proof icon states */
.proof-icon-btn[data-status="valid"],
.proof-icon-btn[data-status="valid"] .proof-icon { color: var(--color-proof-valid); }
.proof-icon-btn[data-status="pending"],
.proof-icon-btn[data-status="pending"] .proof-icon { color: var(--color-proof-pending); }
.proof-icon-btn[data-status="invalid"],
.proof-icon-btn[data-status="invalid"] .proof-icon { color: var(--color-proof-invalid); }
.proof-icon-btn[data-status="none"],
.proof-icon-btn[data-status="none"] .proof-icon { color: var(--color-mesh-inactive); }

/* ==========================================================================
   Buttons (40dp height min, 8dp radius)
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xxs);
    height: var(--button-height);
    min-height: var(--button-height);
    padding: 0 var(--space-compact);
    font-family: var(--font-ui);
    font-size: var(--text-label-large);
    font-weight: 500;
    line-height: var(--lh-label-large);
    letter-spacing: var(--ls-label);
    border: none;
    border-radius: var(--radius-button);
    cursor: pointer;
    transition: background var(--anim-fast), color var(--anim-fast), box-shadow var(--anim-fast), transform var(--anim-fast);
    text-decoration: none;
    white-space: nowrap;
    touch-action: manipulation;
}

.btn:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--color-primary);
    color: var(--color-on-primary);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: var(--shadow-elevation-medium);
}

.btn-secondary {
    background: var(--color-surface-elevated);
    color: var(--color-text-primary);
    border: var(--border-thin) solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-border);
}

.btn-outline {
    background: transparent;
    color: var(--color-text-primary);
    border: var(--border-thin) solid var(--color-border);
}

.btn-outline:hover:not(:disabled) {
    background: var(--color-surface-variant);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    color: var(--color-text-primary);
    background: var(--color-surface-variant);
}

.btn-danger {
    background: var(--color-error);
    color: var(--color-on-error);
}

.btn-danger:hover:not(:disabled) {
    box-shadow: var(--shadow-elevation-medium);
}

.btn-large {
    height: 48px;
    min-height: 48px;
    padding: 0 var(--space-comfortable);
    font-size: var(--text-body-large);
}

.btn-block {
    width: 100%;
}

.btn-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ==========================================================================
   Main Content - MapLibre GL Map (full bleed)
   ========================================================================== */

.main-content {
    grid-area: main;
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.map-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--color-surface);
}

.map {
    width: 100%;
    height: 100%;
}

/* Map Controls (top-right) */
.map-controls {
    position: absolute;
    top: var(--space-compact);
    right: var(--space-compact);
    display: flex;
    flex-direction: column;
    gap: var(--space-xxs);
    z-index: var(--z-map-markers);
}

.map-control-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-elevated);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-full);
    cursor: pointer;
    color: var(--color-text-primary);
    box-shadow: var(--shadow-elevation-medium);
    transition: background var(--anim-fast), border-color var(--anim-fast), transform var(--anim-fast);
    touch-action: manipulation;
}

.map-control-btn:hover {
    background: var(--color-surface-variant);
    border-color: var(--color-border);
    transform: scale(1.05);
}

.map-control-btn:active {
    transform: scale(0.95);
}

.map-control-btn:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.map-control-btn svg {
    width: 20px;
    height: 20px;
}

/* Position Marker (overlay) */
.position-marker {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: var(--z-map-markers);
    transition: transform var(--anim-standard);
}

.marker-chevron {
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 20px solid var(--color-primary);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.accuracy-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100px;
    height: 100px;
    border: var(--border-hairline) dashed var(--color-accuracy-ring);
    border-radius: 50%;
    animation: pulse-ring 2s infinite;
    pointer-events: none;
}

@keyframes pulse-ring {
    0% { width: 100px; height: 100px; opacity: 0.6; }
    100% { width: 200px; height: 200px; opacity: 0; }
}

/* ==========================================================================
   Threat Overlay (full-screen modal, only on SPOOFED/JAMMED)
   ========================================================================== */

.threat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-compact);
    z-index: var(--z-threat-overlay);
    animation: fade-in var(--anim-standard);
}

.threat-overlay.hidden {
    display: none;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.threat-overlay-content {
    background: var(--color-surface-elevated);
    border-radius: var(--radius-modal);
    padding: var(--space-xl);
    max-width: 480px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-elevation-overlay);
    border: var(--border-thick) solid var(--color-threat-critical);
    animation: slide-up var(--anim-standard);
}

@keyframes slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.threat-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--space-comfortable);
    color: var(--color-threat-critical);
    animation: threat-icon-pulse 1.5s ease-in-out infinite;
}

@keyframes threat-icon-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.threat-title {
    font-family: var(--font-mono);
    font-size: var(--text-data-display);
    font-weight: 700;
    line-height: var(--lh-data-display);
    letter-spacing: 1px;
    color: var(--color-threat-critical);
    margin-bottom: var(--space-comfortable);
}

.threat-description {
    font-family: var(--font-ui);
    font-size: var(--text-body-medium);
    line-height: var(--lh-body-medium);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-major);
    opacity: 0.8;
}

.threat-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-compact);
    margin-bottom: var(--space-comfortable);
}

.threat-hint {
    font-family: var(--font-ui);
    font-size: var(--text-label-small);
    line-height: var(--lh-label-small);
    color: var(--color-text-secondary);
    opacity: 0.6;
}

/* ==========================================================================
   Right Edge Sheet (swipe from right, 300dp, full height)
   ========================================================================== */

.right-edge-sheet {
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    bottom: 0;
    width: var(--right-sheet-width);
    z-index: var(--z-right-sheet);
    display: flex;
    transform: translateX(100%);
    transition: transform var(--anim-standard);
}

.right-edge-sheet:not(.hidden) {
    transform: translateX(0);
}

.right-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--anim-standard), visibility var(--anim-standard);
    z-index: -1;
}

.right-edge-sheet:not(.hidden) .right-sheet-backdrop {
    opacity: 1;
    visibility: visible;
}

.right-sheet-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--color-surface-elevated);
    border-left: var(--border-thin) solid var(--color-border);
    box-shadow: var(--shadow-elevation-high);
    overflow-y: auto;
    max-height: 100%;
}

.right-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-compact);
    border-bottom: var(--border-thin) solid var(--color-border);
    flex-shrink: 0;
}

.right-sheet-title {
    font-family: var(--font-mono);
    font-size: var(--text-title-small);
    font-weight: 700;
    line-height: var(--lh-title-small);
    letter-spacing: var(--ls-loose);
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

.right-sheet-close {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background var(--anim-fast), color var(--anim-fast);
    touch-action: manipulation;
}

.right-sheet-close:hover {
    background: var(--color-border);
    color: var(--color-text-primary);
}

.right-sheet-close:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.right-sheet-close svg {
    width: 20px;
    height: 20px;
}

.right-sheet-section {
    padding: var(--space-compact);
    border-bottom: var(--border-thin) solid var(--color-border);
}

.right-sheet-section:last-child {
    border-bottom: none;
}

.right-sheet-subtitle {
    font-family: var(--font-ui);
    font-size: var(--text-label-small);
    font-weight: 600;
    line-height: var(--lh-label-small);
    letter-spacing: var(--ls-label-small);
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin-bottom: var(--space-compact);
}

/* Toggle Chips (full width, chip height, chip radius) */
.toggle-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: var(--chip-height);
    min-height: var(--chip-height);
    padding: 0 var(--space-compact);
    background: var(--color-surface);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-chip);
    cursor: pointer;
    transition: background var(--anim-fast), border-color var(--anim-fast);
    touch-action: manipulation;
    gap: var(--space-compact);
}

.toggle-chip:hover {
    background: var(--color-surface-variant);
}

.toggle-chip:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.toggle-chip[aria-checked="true"] {
    background: var(--color-primary-container);
    border-color: var(--color-primary);
}

.toggle-chip-label {
    font-family: var(--font-ui);
    font-size: var(--text-body-medium);
    font-weight: 400;
    line-height: var(--lh-body-medium);
    color: var(--color-text-primary);
    flex: 1;
    text-align: left;
}

.toggle-chip-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-chip-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: var(--color-text-inverse);
    border-radius: 50%;
    box-shadow: var(--shadow-elevation-low);
    transition: transform var(--anim-fast), background var(--anim-fast);
}

.toggle-chip[aria-checked="true"] .toggle-chip-thumb {
    transform: translateX(20px);
    background: var(--color-primary);
}

/* Right Sheet Trigger Zone */
.right-sheet-trigger {
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    bottom: 0;
    width: 30px;
    background: transparent;
    cursor: ew-resize;
    z-index: var(--z-map-markers);
}

/* ==========================================================================
   Bottom Sheet (drag handle, 40% → 60% → 90%)
   ========================================================================== */

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-surface-elevated);
    border-top-left-radius: var(--radius-sheet);
    border-top-right-radius: var(--radius-sheet);
    border-top: var(--border-thin) solid var(--color-border);
    box-shadow: var(--shadow-elevation-high);
    z-index: var(--z-bottom-sheet);
    transform: translateY(calc(100% - var(--bottom-sheet-peek)));
    transition: transform var(--anim-standard);
    max-height: calc(var(--bottom-sheet-full) + var(--space-xl));
    overflow: hidden;
}

/* Sheet states */
.bottom-sheet[data-state="collapsed"] {
    transform: translateY(calc(100% - var(--bottom-sheet-peek)));
}

.bottom-sheet[data-state="half"] {
    transform: translateY(calc(100% - var(--bottom-sheet-half)));
}

.bottom-sheet[data-state="full"] {
    transform: translateY(calc(100% - var(--bottom-sheet-full)));
}

/* Drag Handle: 16dp tall, centered 32dp wide pill, border color, radiusFull */
.sheet-handle {
    width: 100%;
    height: var(--sheet-handle-height);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    touch-action: none;
    min-height: var(--touch-target-min);
}

.sheet-handle:active {
    cursor: grabbing;
}

.sheet-handle-bar {
    width: 32px;
    height: 4px;
    background: var(--color-border);
    border-radius: var(--radius-full);
}

.sheet-content {
    overflow-y: auto;
    max-height: calc(100% - var(--sheet-handle-height));
}

/* Collapsed view (40% / 160dp) — Key Metrics Row */
.sheet-collapsed {
    padding: var(--space-compact) var(--space-compact) var(--space-xxs);
}

.metrics-row {
    display: flex;
    justify-content: space-around;
    gap: var(--space-xxs);
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: var(--space-xxs) 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.metrics-row::-webkit-scrollbar {
    display: none;
}

.metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-xxs) var(--space-xs);
    background: var(--color-surface-variant);
    border-radius: var(--radius-button);
    min-width: 72px;
    flex: 0 0 auto;
}

.metric-value {
    font-family: var(--font-mono);
    font-size: var(--text-data-large);
    font-weight: 500;
    line-height: var(--lh-data-large);
    letter-spacing: var(--ls-normal);
    color: var(--color-text-primary);
    white-space: nowrap;
}

.metric-label {
    font-family: var(--font-ui);
    font-size: var(--text-label-small);
    font-weight: 500;
    line-height: var(--lh-label-small);
    letter-spacing: var(--ls-label-small);
    text-transform: uppercase;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.threat-metric .metric-value {
    color: var(--color-threat-none);
}

.threat-metric[data-level="hold"] .metric-value { color: var(--color-threat-elevated); }
.threat-metric[data-level="reject"] .metric-value,
.threat-metric[data-level="spoofed"] .metric-value { color: var(--color-threat-critical); }

/* Half view (60%) — Sensor Fusion State */
.sheet-half,
.sheet-full {
    padding: var(--space-compact);
    display: flex;
    flex-direction: column;
    gap: var(--space-section);
}

.sheet-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-compact);
}

.sheet-section-title {
    font-family: var(--font-ui);
    font-size: var(--text-title-small);
    font-weight: 600;
    line-height: var(--lh-title-small);
    letter-spacing: var(--ls-loose);
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.fusion-metrics {
    display: flex;
    flex-direction: column;
    gap: var(--space-xxs);
}

.fusion-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xxs) var(--space-xs);
    background: var(--color-surface-variant);
    border-radius: var(--radius-button);
    min-height: var(--touch-target-dense);
}

.fusion-label {
    font-family: var(--font-ui);
    font-size: var(--text-body-small);
    font-weight: 400;
    line-height: var(--lh-body-small);
    color: var(--color-text-secondary);
}

.fusion-value {
    font-family: var(--font-mono);
    font-size: var(--text-data-medium);
    font-weight: 400;
    line-height: var(--lh-data-medium);
    letter-spacing: var(--ls-normal);
    color: var(--color-text-primary);
    white-space: nowrap;
}

/* Full view (90%) — Threat Timeline + Proof Log */
.timeline {
    display: flex;
    flex-direction: column;
    gap: var(--space-xxs);
}

.timeline-empty {
    text-align: center;
    padding: var(--space-major);
    color: var(--color-text-muted);
    font-size: var(--text-body-small);
}

.timeline-item {
    display: grid;
    grid-template-columns: 60px auto 1fr auto;
    gap: var(--space-compact);
    align-items: center;
    padding: var(--space-xxs) var(--space-xs);
    background: var(--color-surface-variant);
    border-radius: var(--radius-button);
    font-size: var(--text-body-small);
}

.timeline-time {
    font-family: var(--font-mono);
    font-size: var(--text-data-small);
    line-height: var(--lh-data-small);
    color: var(--color-text-muted);
    white-space: nowrap;
}

.timeline-level {
    font-family: var(--font-mono);
    font-size: var(--text-label-small);
    font-weight: 600;
    line-height: var(--lh-label-small);
    text-transform: uppercase;
    padding: var(--space-xxxs) var(--space-xxxs);
    border-radius: var(--radius-chip);
}

.timeline-level.critical { background: var(--color-threat-critical); color: var(--color-text-inverse); }
.timeline-level.elevated { background: var(--color-threat-elevated); color: var(--color-text-inverse); }
.timeline-level.none { background: var(--color-threat-none); color: var(--color-text-inverse); }

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

.timeline-duration {
    font-family: var(--font-mono);
    font-size: var(--text-data-small);
    line-height: var(--lh-data-small);
    color: var(--color-text-muted);
    white-space: nowrap;
}

.timeline-action {
    font-family: var(--font-mono);
    font-size: var(--text-label-small);
    font-weight: 600;
    line-height: var(--lh-label-small);
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

/* Proof Log */
.proof-log {
    display: flex;
    flex-direction: column;
    gap: var(--space-xxs);
}

.log-entry {
    display: flex;
    align-items: center;
    gap: var(--space-compact);
    padding: var(--space-xxs) var(--space-xs);
    background: var(--color-surface-variant);
    border-radius: var(--radius-button);
    font-size: var(--text-body-small);
}

.log-time {
    font-family: var(--font-mono);
    font-size: var(--text-data-micro);
    line-height: var(--lh-data-micro);
    color: var(--color-text-muted);
    white-space: nowrap;
}

.log-action {
    flex: 1;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.log-status {
    font-family: var(--font-mono);
    font-size: var(--text-label-small);
    font-weight: 600;
    line-height: var(--lh-label-small);
    padding: var(--space-xxxs) var(--space-xxs);
    border-radius: var(--radius-chip);
    text-transform: uppercase;
}

.log-status.verified { background: var(--color-proof-valid); color: var(--color-text-inverse); }
.log-status.pending { background: var(--color-proof-pending); color: var(--color-text-inverse); }
.log-status.invalid { background: var(--color-proof-invalid); color: var(--color-text-inverse); }

/* Hidden utility */
.hidden {
    display: none !important;
}

/* ==========================================================================
   Mobile Components
   ========================================================================== */

/* Hamburger Button */
.hamburger-btn {
    display: none;
    width: 44px;
    height: 44px;
    padding: var(--space-xxs);
    background: transparent;
    border: none;
    border-radius: var(--radius-button);
    cursor: pointer;
    color: var(--color-text-primary);
    transition: background var(--transition-fast);
}

.hamburger-btn:hover {
    background: var(--color-surface-variant);
}

.hamburger-btn:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.hamburger-btn svg {
    width: 24px;
    height: 24px;
}

/* Search Button (mobile) */
.search-btn {
    display: none;
    width: 44px;
    height: 44px;
    padding: var(--space-xxs);
    background: transparent;
    border: none;
    border-radius: var(--radius-button);
    cursor: pointer;
    color: var(--color-text-primary);
    transition: background var(--transition-fast);
}

.search-btn:hover {
    background: var(--color-surface-variant);
}

.search-btn:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.search-btn svg {
    width: 24px;
    height: 24px;
}

/* Search Overlay */
.search-overlay {
    position: fixed;
    inset: 0;
    background: var(--color-surface-elevated);
    z-index: var(--z-modal);
    display: flex;
    flex-direction: column;
    animation: slide-down var(--transition-normal);
}

.search-overlay.hidden {
    display: none;
}

@keyframes slide-down {
    from { opacity: 0; transform: translateY(-100%); }
    to { opacity: 1; transform: translateY(0); }
}

.search-overlay-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: var(--space-compact);
    padding-top: calc(var(--topbar-height) + var(--space-compact));
    overflow-y: auto;
}

.search-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: var(--space-compact);
}

.search-close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-variant);
    border: none;
    border-radius: var(--radius-button);
    cursor: pointer;
    color: var(--color-text-primary);
    transition: background var(--transition-fast);
}

.search-close:hover {
    background: var(--color-border);
}

.search-close:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.search-close svg {
    width: 24px;
    height: 24px;
}

.search-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-compact);
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.search-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-xxxs);
}

.search-label {
    font-family: var(--font-mono);
    font-size: var(--text-label-small);
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.search-input {
    padding: var(--space-xs) var(--space-compact);
    font-family: var(--font-ui);
    font-size: var(--text-body-large);
    color: var(--color-text-primary);
    background: var(--color-surface);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-button);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-input:focus {
    outline: none;
    border-color: var(--color-focus);
    box-shadow: 0 0 0 3px var(--color-focus-ring);
}

.search-field:has(.search-use-current) {
    position: relative;
}

.search-use-current {
    position: absolute;
    right: var(--space-xxs);
    top: calc(100% + var(--space-xxxs));
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-variant);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-button);
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
}

.search-use-current:hover {
    background: var(--color-border);
    color: var(--color-text-primary);
}

.search-use-current:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.search-use-current svg {
    width: 20px;
    height: 20px;
}

.search-submit {
    margin-top: var(--space-xs);
}

/* Mobile Drawer */
.mobile-drawer {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    animation: fade-in var(--transition-normal);
}

.mobile-drawer.hidden {
    display: none;
}

.mobile-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.mobile-drawer-content {
    position: relative;
    width: 100%;
    max-width: 320px;
    height: 100%;
    background: var(--color-surface-elevated);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-elevation-overlay);
    animation: slide-in-right var(--transition-normal);
}

@keyframes slide-in-right {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

.mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-compact);
    border-bottom: var(--border-thin) solid var(--color-border);
}

.mobile-drawer-title {
    font-family: var(--font-mono);
    font-size: var(--text-headline-small);
    font-weight: 700;
    color: var(--color-text-primary);
}

.mobile-drawer-close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-button);
    cursor: pointer;
    color: var(--color-text-primary);
    transition: background var(--transition-fast);
}

.mobile-drawer-close:hover {
    background: var(--color-surface-variant);
}

.mobile-drawer-close:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.mobile-drawer-close svg {
    width: 24px;
    height: 24px;
}

.mobile-drawer-nav {
    display: flex;
    flex-direction: column;
    padding: var(--space-xs) var(--space-compact);
    gap: var(--space-xxxs);
}

.mobile-nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-compact);
    padding: var(--space-xs) var(--space-compact);
    border-radius: var(--radius-button);
    color: var(--color-text-primary);
    text-decoration: none;
    font-size: var(--text-body-large);
    font-weight: 500;
    transition: background var(--transition-fast);
    min-height: 48px;
}

.mobile-nav-item:hover,
.mobile-nav-item.active {
    background: var(--color-surface-variant);
}

.mobile-nav-item:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

.mobile-nav-item svg {
    width: 24px;
    height: 24px;
    color: var(--color-text-secondary);
    flex-shrink: 0;
}

.mobile-nav-item.active svg {
    color: var(--color-primary);
}

.mobile-drawer-divider {
    height: var(--border-hairline);
    background: var(--color-border);
    margin: var(--space-xs) var(--space-compact);
}

.mobile-drawer-section {
    padding: var(--space-xs) var(--space-compact);
}

.mobile-drawer-section-title {
    font-family: var(--font-mono);
    font-size: var(--text-label-small);
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

.mobile-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xxs) 0;
    min-height: 48px;
}

.mobile-drawer-status {
    display: flex;
    flex-direction: column;
    gap: var(--space-xxs);
    padding: var(--space-xs) var(--space-compact);
    margin-top: auto;
    border-top: var(--border-thin) solid var(--color-border);
}

.mobile-status-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xs) var(--space-compact);
    background: var(--color-surface-variant);
    border-radius: var(--radius-button);
    min-height: 48px;
}

.mobile-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 2s infinite;
}

.mobile-status-label {
    font-size: var(--text-body-small);
    color: var(--color-text-secondary);
}

.mobile-status-value {
    font-family: var(--font-mono);
    font-size: var(--text-data-small);
    font-weight: 600;
    color: var(--color-text-primary);
}

.mobile-status-item[data-level="normal"] .mobile-status-dot { color: var(--color-threat-none); }
.mobile-status-item[data-level="hold"] .mobile-status-dot { color: var(--color-threat-elevated); }
.mobile-status-item[data-level="reject"],
.mobile-status-item[data-level="spoofed"] .mobile-status-dot { color: var(--color-threat-critical); }

/* Desktop-only / Mobile-only utilities */
.desktop-only {
    display: inline-flex;
}

.mobile-only {
    display: none;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1024px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: inline-flex !important;
    }

    .hamburger-btn,
    .search-btn {
        display: flex;
    }

    .right-edge-sheet {
        display: none !important;
    }

    .right-sheet-trigger {
        display: none !important;
    }
}

@media (max-width: 480px) {
    :root {
        --topbar-height: 48px;
        --right-sheet-width: 100%;
        --bottom-sheet-peek: 160px;
    }

    .top-bar {
        padding: 0 var(--space-xxs);
    }

    .threat-pill {
        min-width: 72px;
        padding: 0 var(--space-xs);
        font-size: var(--text-label-small);
    }

    .h3-cell-index {
        max-width: 80px;
    }

    .proof-icon-btn {
        width: 36px;
        height: 36px;
    }

    .map-controls {
        top: var(--space-xxs);
        right: var(--space-xxs);
    }

    .map-control-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    .metrics-row {
        gap: var(--space-xxxs);
    }

    .metric {
        min-width: 64px;
        padding: var(--space-xxxs) var(--space-xxs);
    }

    .metric-value {
        font-size: var(--text-data-medium);
    }

    .metric-label {
        font-size: var(--text-label-small);
    }

    .fusion-row {
        padding: var(--space-xxxs) var(--space-xxs);
    }

    .timeline-item {
        grid-template-columns: 50px auto 1fr;
        font-size: var(--text-label-small);
    }

    .timeline-action {
        grid-column: 1 / -1;
        justify-self: start;
        padding-top: var(--space-xxxs);
        border-top: var(--border-hairline) solid var(--color-border);
        margin-top: var(--space-xxxs);
    }
}

/* ==========================================================================
   Scrollbar
   ========================================================================== */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--color-surface);
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

/* ==========================================================================
   Focus Visible Polyfill
   ========================================================================== */

:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: var(--border-thick) solid var(--color-focus);
    outline-offset: 2px;
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==========================================================================
   High Contrast Mode
   ========================================================================== */

@media (prefers-contrast: high) {
    :root {
        --color-border: var(--color-text-primary);
        --color-surface-variant: var(--color-surface);
    }

    [data-theme="dark"] {
        --color-border: var(--color-text-primary);
    }

    .threat-pill,
    .toggle-chip,
    .metric,
    .fusion-row,
    .log-entry,
    .timeline-item {
        border: var(--border-thick) solid currentColor;
    }
}

/* ==========================================================================
   Print
   ========================================================================== */

@media print {
    .top-bar,
    .bottom-sheet,
    .threat-overlay,
    .right-edge-sheet,
    .right-sheet-trigger,
    .map-controls,
    .position-marker {
        display: none !important;
    }

    #app {
        grid-template-rows: 1fr;
        grid-template-areas: "main";
    }

    .main-content {
        height: 100vh;
    }
}