/* ========================================
   SUPPLY CHAIN MAP - REDESIGNED
   Based on ECHO's liberation-ui-patterns & mobile-crisis-design
   
   Principles:
   - Dark mode default
   - Mobile-first, touch-optimized
   - Low bandwidth, efficient
   - Accessible under stress
   ======================================== */

/* ========================================
   CSS CUSTOM PROPERTIES (Design Tokens)
   ======================================== */
:root {
    /* Colors - Dark theme (default) */
    --color-bg: #0d0d0d;
    --color-bg-elevated: #1a1a1a;
    --color-bg-overlay: rgba(26, 26, 26, 0.95);
    --color-bg-hover: #2a2a2a;
    
    --color-text: #e5e5e5;
    --color-text-secondary: #a3a3a3;
    --color-text-muted: #737373;
    
    --color-border: #333333;
    --color-border-focus: #525252;
    
    --color-accent: #dc2626; /* Red for danger/alert */
    --color-accent-secondary: #ef4444;
    
    --color-danger: #dc2626;
    --color-warning: #f59e0b;
    --color-success: #22c55e;
    --color-info: #3b82f6;
    
    /* Confidence colors */
    --conf-vh: #dc2626;  /* Very High - 80%+ */
    --conf-h: #f59e0b;   /* High - 70-79% */
    --conf-m: #eab308;   /* Medium - 60-69% */
    --conf-l: #22c55e;   /* Low - <60% */
    
    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    
    /* Typography */
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    
    --text-xs: 11px;
    --text-sm: 13px;
    --text-base: 15px;
    --text-lg: 18px;
    --text-xl: 22px;
    
    /* Borders */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
    
    /* Z-index */
    --z-base: 0;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-overlay: 300;
    --z-modal: 400;
    --z-toast: 500;
    
    /* Transitions */
    --duration-fast: 150ms;
    --duration-normal: 250ms;
}

/* Light theme override */
[data-theme="light"] {
    --color-bg: #f5f5f5;
    --color-bg-elevated: #ffffff;
    --color-bg-overlay: rgba(255, 255, 255, 0.95);
    --color-bg-hover: #eeeeee;
    
    --color-text: #171717;
    --color-text-secondary: #525252;
    --color-text-muted: #737373;
    
    --color-border: #e5e5e5;
    --color-border-focus: #a3a3a3;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.15);
}

/* ========================================
   BASE RESET
   ======================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    overflow: hidden; /* App-like feel */
}

/* ========================================
   HEADER - Compact, Status-First
   ======================================== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--color-bg-elevated);
    border-bottom: 2px solid var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-4);
    z-index: var(--z-sticky);
}

.header__brand {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.header__title {
    font-size: var(--text-base);
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.header__subtitle {
    font-size: 10px;
    color: var(--color-text-secondary);
    display: block;
    line-height: 1.2;
}

.header__actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* Status indicators in header */
.header__status {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    font-size: var(--text-sm);
}

.status-item {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-success);
}

.status-dot--warning {
    background: var(--color-warning);
}

.status-dot--danger {
    background: var(--color-danger);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Theme switcher */
.theme-switcher {
    display: flex;
    gap: var(--space-1);
}

.theme-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    font-size: var(--text-sm);
    opacity: 0.6;
    transition: var(--duration-fast);
}

.theme-btn:hover {
    opacity: 1;
    background: var(--color-bg-hover);
}

.theme-btn[aria-pressed="true"] {
    opacity: 1;
    background: var(--color-accent);
}

/* ========================================
   MAIN LAYOUT - Desktop: Map center, sidebars on sides
   ======================================== */
#main {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 36px;
    display: flex;
    overflow: hidden;
}

/* Map View - Flexbox container */
#map-view {
    display: flex;
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Map container - takes remaining space */
#map-container {
    flex: 1;
    position: relative;
    min-width: 0;
    overflow: hidden;
}

#map {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
}

/* Sidebars - fixed 300px, hidden when closed */
.sidebar,
.filter-panel {
    width: 300px;
    flex-shrink: 0;
    position: relative;
    height: 100%;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: var(--z-sidebar);
    box-sizing: border-box;
}

.sidebar {
    border-right: 1px solid var(--color-border);
}

.filter-panel {
    border-left: 1px solid var(--color-border);
}

/* Hide sidebars when closed */
.sidebar.closed,
.filter-panel.closed {
    display: none;
}

/* Panel header */
.panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
    flex-shrink: 0;
}

.panel__title {
    font-size: var(--text-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text);
}

.panel__close {
    display: none;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: var(--text-base);
}

.panel__close:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}

/* Panel body - scrollable */
.panel__body {
    min-width: 0;
    width: 100%;
    flex: 1;
    transition: margin 0.3s ease;
    overflow-y: auto;
    padding: var(--space-3) var(--space-3);
    scrollbar-width: thin;
    scrollbar-color: var(--color-accent) transparent;
    box-sizing: border-box;
}

.panel__body::-webkit-scrollbar {
    width: 4px;
}

.panel__body::-webkit-scrollbar-thumb {
    background: var(--color-accent);
    border-radius: 2px;
}

/* ========================================
   FILTER SECTIONS - Compact Cards
   ======================================== */
.filter-section {
    margin-bottom: var(--space-3);
    padding: 0 var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
}

/* Ensure inputs don't overflow in sidebar */
.sidebar .form-input,
.sidebar .form-select,
.sidebar input[type="text"],
.sidebar input[type="search"],
.sidebar select,
.sidebar input[type="range"] {
    max-width: 100%;
    box-sizing: border-box;
}

/* Fix sidebar-select specifically */
.sidebar-select {
    width: 100% !important;
}

.filter-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.filter-section__title {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
}

/* Toggle items - touch friendly */
.toggle-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.toggle-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    min-height: 36px; /* Touch-friendly */
    transition: var(--duration-fast);
}

.toggle-item:hover {
    background: var(--color-bg-hover);
}

.toggle-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-accent);
}

.toggle-item__label {
    font-size: var(--text-sm);
    color: var(--color-text);
}

/* ========================================
   FORM ELEMENTS - Crisis-Optimized
   ======================================== */
.form-input, .form-select {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-size: var(--text-sm);
    min-height: 40px; /* Touch-friendly */
    transition: var(--duration-fast);
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(220, 38, 26, 0.2);
}

.form-input::placeholder {
    color: var(--color-text-muted);
}

/* Range slider */
input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--color-bg);
    border-radius: var(--radius-full);
    appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--color-accent);
    border-radius: 50%;
    cursor: pointer;
}

/* ========================================
   BUTTONS - High Contrast, Touch-Friendly
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--color-accent);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
    min-height: 44px; /* WCAG minimum + crisis context */
    transition: var(--duration-fast);
}

.btn:hover {
    background: var(--color-accent-secondary);
}

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

.btn--secondary {
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn--secondary:hover {
    background: var(--color-bg-hover);
}

.btn--small {
    min-height: 36px;
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
}

/* ========================================
   STATS - Quick Scan
   ======================================== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.stat-card {
    background: var(--color-bg);
    border-radius: var(--radius-md);
    padding: var(--space-2);
    text-align: center;
    border: 1px solid var(--color-border);
}

.stat-card__value {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--color-text);
}

.stat-card__label {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    text-transform: uppercase;
}

.stat-card--danger {
    border-color: var(--color-danger);
    background: rgba(220, 38, 26, 0.1);
}

.stat-card--danger .stat-card__value {
    color: var(--color-danger);
}

.stat-card--warning {
    border-color: var(--color-warning);
    background: rgba(245, 158, 11, 0.1);
}

.stat-card--warning .stat-card__value {
    color: var(--color-warning);
}

.stat-card--accent {
    border-color: var(--color-accent);
    background: rgba(220, 38, 26, 0.1);
}

.stat-card--accent .stat-card__value {
    color: var(--color-accent);
}

/* ========================================
   CONFIDENCE BARS - Visual Scanner
   ======================================== */
.confidence-chart {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.confidence-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) 0;
    cursor: pointer;
}

.confidence-bar__label {
    width: 24px;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--color-text-muted);
}

.confidence-bar__track {
    flex: 1;
    transition: margin 0.3s ease;
    height: 8px;
    background: var(--color-bg);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.confidence-bar__fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width var(--duration-normal);
}

.confidence-bar--vh .confidence-bar__fill { background: var(--conf-vh); }
.confidence-bar--h .confidence-bar__fill { background: var(--conf-h); }
.confidence-bar--m .confidence-bar__fill { background: var(--conf-m); }
.confidence-bar--l .confidence-bar__fill { background: var(--conf-l); }

.confidence-bar__count {
    width: 28px;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--color-text);
    text-align: right;
}

/* ========================================
   DETAIL CARD - Entity Info
   ======================================== */
.detail-card {
    background: var(--color-bg);
    border: 1px solid var(--color-accent);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-top: var(--space-3);
}

.detail-card__header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    background: rgba(220, 38, 26, 0.15);
    border-bottom: 1px solid var(--color-border);
}

.detail-card__icon {
    font-size: 24px;
}

.detail-card__title {
    font-size: var(--text-base);
    font-weight: 700;
    color: var(--color-text);
    flex: 1;
    transition: margin 0.3s ease;
}

.detail-card__subtitle {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.detail-card__row {
    display: flex;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--text-sm);
}

.detail-card__row:last-child {
    border-bottom: none;
}

.detail-card__key {
    color: var(--color-text-muted);
}

.detail-card__value {
    color: var(--color-text);
    font-weight: 600;
    text-align: right;
    max-width: 60%;
    word-break: break-word;
}

.detail-card__value--danger {
    color: var(--color-danger);
}

.detail-card__value--warning {
    color: var(--color-warning);
}

.detail-card__tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
}

.detail-card__tag {
    padding: var(--space-1) var(--space-2);
    background: var(--color-bg-elevated);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.detail-card__tag--danger {
    background: rgba(220, 38, 26, 0.15);
    color: var(--color-danger);
    border-color: var(--color-danger);
}

.detail-card__tag--success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--color-success);
    border-color: var(--color-success);
}

.detail-card__tag--info {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    border-color: #3b82f6;
}

.detail-card__tag--warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--color-warning);
    border-color: var(--color-warning);
}

.detail-card__flag-reason {
    margin: var(--space-2) var(--space-3) var(--space-3);
    padding: var(--space-2);
    background: rgba(220, 38, 26, 0.1);
    border-left: 3px solid var(--color-danger);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    color: var(--color-danger);
}

.detail-card__actions {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3);
    border-top: 1px solid var(--color-border);
}

.detail-card__btn {
    flex: 1;
    transition: margin 0.3s ease;
    padding: var(--space-2);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    min-height: 40px;
    transition: var(--duration-fast);
}

.detail-card__btn:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-accent);
}

.detail-empty {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    text-align: center;
    padding: var(--space-4);
}

/* ========================================
   FOOTER - Status Bar
   ======================================== */
.status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: var(--color-bg-elevated);
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-4);
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    z-index: var(--z-sticky);
}

.status-bar__section {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.status-bar__item {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.status-bar__value {
    color: var(--color-text);
    font-weight: 500;
}

.status-bar__value--success {
    color: var(--color-success);
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */
.toast-container {
    position: fixed;
    top: 60px;
    right: var(--space-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-width: 320px;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-3);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: slideIn var(--duration-normal) ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast--success { border-left: 3px solid var(--color-success); }
.toast--warning { border-left: 3px solid var(--color-warning); }
.toast--danger { border-left: 3px solid var(--color-danger); }
.toast--info { border-left: 3px solid var(--color-info); }

.toast__icon {
    font-size: var(--text-base);
}

.toast__content {
    flex: 1;
    transition: margin 0.3s ease;
}

.toast__title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-text);
}

.toast__message {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.toast__close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: var(--space-1);
    font-size: var(--text-base);
}

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

/* ========================================
   MOBILE RESPONSIVE - Crisis-Optimized
   ======================================== */
@media (max-width: 900px) {
    /* Mobile/Tablet: sidebars become bottom sheets */
    #main {
        flex-direction: column;
    }
    
    #map-container {
        flex: 1;
        width: 100%;
    }
    
    /* Sidebars as overlay bottom sheets - ABOVE everything */
    .sidebar,
    .filter-panel {
        position: fixed;
        left: 0;
        right: 0;
        width: 100%;
        height: 60vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        transform: translateY(100%);
        transition: transform var(--duration-normal);
        z-index: 1000; /* Above header */
        border: 1px solid var(--color-border);
    }
    
    .sidebar.is-open,
    .filter-panel.is-open {
        transform: translateY(0);
    }
    
    .panel__close {
        display: block;
    }
    
    /* Mobile header */
    .header {
        height: 48px;
    }
    
    .header__title {
        font-size: var(--text-sm);
    }
    
    .header__status {
        display: none;
    }
    
    /* Hide desktop toggles on mobile */
    .sidebar-toggle {
        display: none;
    }
    
    /* Mobile toggle buttons */
    .mobile-toggles {
        display: flex;
        gap: var(--space-2);
    }
}

@media (max-width: 600px) {
    .header {
        padding: 0 var(--space-3);
    }
    
    .header__brand {
        gap: var(--space-2);
    }
    
    .theme-switcher {
        display: none;
    }
    
    .stat-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .detail-card__actions {
        flex-direction: column;
    }
}

/* ========================================
   ACCESSIBILITY - Crisis Context
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
[data-contrast="high"] {
    --color-text: #ffffff;
    --color-text-secondary: #ffffff;
    --color-border: #ffffff;
    --color-bg-elevated: #000000;
}

/* Large touch targets for stressed hands */
[data-touch="large"] .toggle-item,
[data-touch="large"] .btn,
[data-touch="large"] .form-input {
    min-height: 56px;
}

/* ========================================
   CLUSTER MARKERS
   ======================================== */
.cluster-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    font-size: 12px;
    color: white;
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.cluster-icon--small { width: 32px; height: 32px; font-size: 11px; }
.cluster-icon--medium { width: 40px; height: 40px; font-size: 13px; }
.cluster-icon--large { width: 48px; height: 48px; font-size: 15px; }

/* Type-specific cluster colors */
.custom-cluster--port .cluster-icon { background: #3b82f6; }
.custom-cluster--factory .cluster-icon { background: #ef4444; }

/* Cluster icon color override using CSS variable */
.cluster-icon { background: #22c55e; }
.cluster-icon[style*="--cluster-color"] { background: var(--cluster-color, #22c55e); }

/* ========================================
   MAP POPUPS
   ======================================== */
.leaflet-popup-content-wrapper {
    background: var(--color-bg-elevated);
    color: var(--color-text);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.leaflet-popup-tip {
    background: var(--color-bg-elevated);
}

.ship-popup, .port-popup, .factory-popup {
    min-width: 180px;
}

.ship-popup__title {
    font-size: var(--text-base);
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: var(--space-2);
}

.ship-popup__row {
    display: flex;
    justify-content: space-between;
    font-size: var(--text-xs);
    padding: var(--space-1) 0;
}

.ship-popup__label {
    color: var(--color-text-muted);
}

.ship-popup__value {
    color: var(--color-text);
    font-weight: 500;
}

.ship-popup__value--danger {
    color: var(--color-danger);
}

.ship-popup__alert {
    margin-top: var(--space-2);
    padding: var(--space-2);
    background: rgba(220, 38, 38, 0.15);
    border-left: 3px solid var(--color-danger);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    color: var(--color-danger);
}

.ship-popup__badge {
    display: inline-block;
    margin-top: var(--space-1);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: 600;
}

.ship-popup__badge--success {
    background: rgba(34, 197, 94, 0.2);
    color: var(--color-success);
    border: 1px solid var(--color-success);
}

.ship-popup__badge--info {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
    border: 1px solid #3b82f6;
}

.ship-popup__btn {
    width: 100%;
    margin-top: var(--space-2);
    padding: var(--space-2);
    background: var(--color-accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 600;
    cursor: pointer;
}

.ship-popup__btn:hover {
    background: var(--color-accent-secondary);
}

/* ========================================
   GEEK THEME - Terminal/Hacker Aesthetic
   ======================================== */
[data-theme="geek"] {
    --color-bg: #000000;
    --color-bg-elevated: #0a0a0a;
    --color-bg-overlay: rgba(0, 0, 0, 0.95);
    --color-bg-hover: rgba(0, 255, 0, 0.08);
    
    --color-text: #00ff00;
    --color-text-secondary: #00cc00;
    --color-text-muted: #006600;
    
    --color-border: #003300;
    --color-border-focus: #00ff00;
    
    --color-accent: #00ffff;
    --color-accent-secondary: #00cccc;
    --color-danger: #ff0000;
    --color-warning: #ffff00;
    --color-success: #00ff00;
    --color-info: #00ffff;
    
    --conf-vh: #ff0000;
    --conf-h: #ff6600;
    --conf-m: #ffff00;
    --conf-l: #00ff00;
    
    --shadow-sm: 0 0 5px rgba(0, 255, 0, 0.3);
    --shadow-md: 0 0 10px rgba(0, 255, 0, 0.4);
    --shadow-lg: 0 0 20px rgba(0, 255, 0, 0.5);
    
    font-family: 'Courier New', Courier, monospace;
}

[data-theme="geek"] body {
    min-width: 100vw;
    max-width: none;
    text-shadow: 0 0 2px rgba(0, 255, 0, 0.3);
}

[data-theme="geek"] .header {
    border-bottom-color: #00ff00;
    box-shadow: 0 2px 10px rgba(0, 255, 0, 0.3);
}

[data-theme="geek"] .btn {
    background: #003300;
    border: 1px solid #00ff00;
    color: #00ff00;
    text-shadow: none;
}

[data-theme="geek"] .btn:hover {
    background: #00ff00;
    color: #000000;
}

[data-theme="geek"] .sidebar,
[data-theme="geek"] .filter-panel {
    border-color: #003300;
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.2);
}

[data-theme="geek"] .stat-card--danger {
    border-color: #ff0000;
    box-shadow: 0 0 10px rgba(255, 0, 0, 0.3);
}

[data-theme="geek"] .detail-card {
    border-color: #00ffff;
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.3);
}

[data-theme="geek"] .cluster-icon {
    background: #00ff00;
    color: #000000;
    box-shadow: 0 0 10px #00ff00;
}

[data-theme="geek"] input[type="range"]::-webkit-slider-thumb {
    background: #00ff00;
    box-shadow: 0 0 10px #00ff00;
}

[data-theme="geek"] .toggle-item input[type="checkbox"] {
    accent-color: #00ff00;
}

/* Cluster Legend */
.cluster-legend {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    box-shadow: var(--shadow-md);
}

/* Collapsible legend */
.cluster-legend__toggle {
    cursor: pointer;
    font-weight: 600;
    margin-bottom: var(--space-2);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.cluster-legend__toggle-icon {
    font-size: 10px;
    transition: transform 0.2s;
}

.cluster-legend--collapsed .cluster-legend__toggle-icon {
    transform: rotate(-90deg);
}

.cluster-legend--collapsed .cluster-legend__content {
    display: none;
}

.cluster-legend__title {
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-1);
    color: var(--color-text-primary);
}

.cluster-legend__item {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-top: 4px;
    color: var(--color-text-secondary);
}

.cluster-legend__dot {
    border-radius: 50%;
    background: var(--color-primary);
}

.cluster-legend__dot--1 { width: 12px; height: 12px; }
.cluster-legend__dot--10 { width: 20px; height: 20px; }
.cluster-legend__dot--50 { width: 28px; height: 28px; }

/* Keyboard Shortcuts Modal */
.shortcuts-modal h3 {
    margin-bottom: var(--space-3);
    color: var(--color-text-primary);
}

.shortcut-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.shortcut {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
}

.shortcut kbd {
    display: inline-block;
    padding: 2px 8px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: monospace;
    font-size: var(--text-xs);
    color: var(--color-text-primary);
    min-width: 30px;
    text-align: center;
}

/* Confidence Breakdown Bar */
.detail-card__confidence-bar {
    margin: var(--space-2) var(--space-3);
}

.detail-card__confidence-track {
    display: flex;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--color-bg-elevated);
}

.detail-card__confidence-segment {
    height: 100%;
}

.detail-card__confidence-segment--algo {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.detail-card__confidence-segment--intel {
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

.detail-card__confidence-labels {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* ========================================
   LOADING SKELETON & ERROR BANNER
   Added by PIXEL - 2026-03-03
   ======================================== */

/* Loading Skeleton */
.loading-skeleton {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 36px;
    background: var(--color-bg);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-4);
}

.skeleton-map {
    flex: 1;
    transition: margin 0.3s ease;
    background: var(--color-bg-elevated);
    border-radius: var(--radius-lg);
    position: relative;
    overflow: hidden;
}

.skeleton-pulse {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

.skeleton-sidebar {
    background: var(--color-bg-elevated);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.skeleton-line {
    height: 16px;
    background: linear-gradient(90deg, var(--color-bg) 25%, var(--color-border) 50%, var(--color-bg) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

.skeleton-line.skeleton-title {
    height: 24px;
    width: 60%;
}

.skeleton-line.skeleton-short {
    width: 40%;
}

.skeleton-stats {
    display: flex;
    gap: var(--space-3);
}

.skeleton-stat {
    flex: 1;
    transition: margin 0.3s ease;
    height: 60px;
    background: var(--color-bg-elevated);
    border-radius: var(--radius-lg);
    animation: pulse 2s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Hide skeleton when loaded */
.loading-skeleton.hidden {
    display: none;
}

/* Error Banner */
.error-banner {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--color-danger);
    color: white;
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    z-index: 10000;
    font-size: var(--text-sm);
}

.error-banner__icon {
    font-size: var(--text-lg);
}

.error-banner__message {
    flex: 1;
    transition: margin 0.3s ease;
}

.error-banner__retry {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: var(--text-sm);
    transition: background var(--duration-fast);
}

.error-banner__retry:hover {
    background: rgba(255,255,255,0.3);
}

.error-banner__close {
    position: relative;
    z-index: 10001;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: var(--text-lg);
    padding: var(--space-1);
    opacity: 0.8;
}

.error-banner__close:hover {
    opacity: 1;
}

/* Mobile panel polish */
@media (max-width: 900px) {
    .loading-skeleton {
    left: 0;
    right: 0;
        top: 48px;
        bottom: 36px;
    }
    
    .sidebar, .filter-panel {
        /* Enhance mobile transitions */
        transition: transform var(--duration-smooth) cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    /* Better touch targets */
    .panel__close {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Smooth panel slide */
    .sidebar.is-open, .filter-panel.is-open {
        animation: slideUp var(--duration-smooth) cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
}

:root {
    --duration-smooth: 350ms;
}

/* ========================================
   CHARTS SECTION (PIXEL - 2026-03-03)
   ======================================== */

.charts-section {
    border-top: 1px solid var(--color-border);
    padding-top: var(--space-3);
}

.chart-card {
    background: var(--color-bg);
    border-radius: var(--radius-md);
    padding: var(--space-2);
}

.chart-card__title {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    margin-bottom: var(--space-1);
    font-weight: 500;
}

/* Make charts responsive */
#chart-ships-by-flag,
#chart-confidence,
#chart-ports-country {
    width: 100%;
}

/* View Tabs */
.view-tabs {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    display: flex;
    gap: var(--space-1);
    background: var(--color-bg);
    padding: var(--space-1);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--color-border);
}

.view-tab {
    padding: var(--space-2) var(--space-4);
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.view-tab:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}

.view-tab--active {
    background: var(--color-primary);
    color: white;
    box-shadow: var(--shadow-md);
}

/* Map View - use flexbox layout defined above */

/* Analytics View */
#analytics-view {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    background: var(--color-bg);
}

.analytics-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-6);
}

.analytics-header {
    text-align: center;
    margin-bottom: var(--space-6);
}

.analytics-header h2 {
    font-size: var(--text-2xl);
    margin-bottom: var(--space-2);
}

.analytics-header p {
    color: var(--color-text-muted);
}

.analytics-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.analytics-stat {
    background: var(--color-bg-secondary);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    text-align: center;
}

.analytics-stat__value {
    font-size: var(--text-3xl);
    font-weight: 700;
    color: var(--color-primary);
}

.analytics-stat__label {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

.analytics-charts {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}

.analytics-chart {
    background: var(--color-bg-secondary);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
}

.analytics-chart h3 {
    font-size: var(--text-base);
    margin-bottom: var(--space-3);
}

@media (max-width: 1024px) {
    .analytics-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    .analytics-charts {
        grid-template-columns: 1fr;
    }
}

/* Legend divider */
.cluster-legend__divider {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-2) 0;
}

/* Desktop sidebar toggles - visible on desktop */
.sidebar-toggle {
    display: inline-flex;
}

/* Mobile toggle buttons - hidden on desktop */
.mobile-toggles {
    display: none;
}

/* Hidden state for sidebars */
.sidebar--hidden,
.filter-panel--hidden {
    display: none !important;
}

/* Sidebar closed state on desktop */
@media (min-width: 901px) {
    .sidebar.closed,
    .filter-panel.closed {
        display: none;
    }
}


/* ========================================
   WATCHLIST ITEMS
   ======================================== */
.watchlist-items {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.watchlist-item {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: var(--space-2);
    border-left: 3px solid var(--color-accent);
}

.watchlist-item__name {
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--color-text);
}

.watchlist-item__meta {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    margin-top: 2px;
}

.watchlist-item__reason {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
    font-style: italic;
}

/* ========================================
   FILTER CHIPS - Modern pill-style filters
   ======================================== */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--duration-fast) ease;
    user-select: none;
}

.filter-chip:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-accent);
    color: var(--color-text);
}

.filter-chip:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.filter-chip--active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--color-bg);
}

.filter-chip--active:hover {
    background: var(--color-accent-hover, var(--color-accent));
    border-color: var(--color-accent-hover, var(--color-accent));
}

.filter-chip__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 var(--space-1);
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 600;
}

/* Touch-friendly sizing for crisis context */
@media (pointer: coarse) {
    .filter-chip {
        min-height: 44px;
        padding: var(--space-2) var(--space-4);
        font-size: var(--text-sm);
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .filter-chip {
        border-width: 2px;
        font-weight: 600;
    }
    
    .filter-chip--active {
        border-color: var(--color-text);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .filter-chip {
        transition: none;
    }
}
