/* CSS Variables */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a24;
    --bg-card: #16161f;
    --border-color: #2a2a3a;
    --border-accent: #3a3a4a;
    --text-primary: #e0e0e0;
    --text-secondary: #8a8a9a;
    --text-muted: #5a5a6a;
    --accent-red: #ff4444;
    --accent-orange: #ff8c00;
    --accent-yellow: #ffd700;
    --accent-green: #00ff88;
    --accent-blue: #00a8ff;
    --accent-cyan: #00ffff;
    --accent-purple: #a855f7;
    --alert-active: #ff4444;
    --alert-expired: #666680;
    --glow-red: rgba(255, 68, 68, 0.3);
    --glow-orange: rgba(255, 140, 0, 0.3);
    --header-height: 40px;
    --feed-height: 90px;
    --feed-height-mobile: 80px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* Header Bar */
.header-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.logo {
    display: flex;
    align-items: center; /* Keep center to align icon vertically */
    gap: 8px;
}

.powered-by {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 500;
    margin-left: 6px;
    margin-top: 4px;
}

.logo-icon {
    font-size: 18px;
    color: var(--accent-orange);
    /* Performance optimization: use transform instead of filter */
    animation: pulse-scale 2s ease-in-out infinite;
    display: inline-block; /* Required for transform */
}

@keyframes pulse-scale {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

/* @keyframes pulse-glow {
    0%, 100% { filter: drop-shadow(0 0 4px var(--accent-orange)); }
    50% { filter: drop-shadow(0 0 12px var(--accent-orange)); }
} */

.logo-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-orange);
    letter-spacing: 1px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-green);
    border-radius: 50%;
    animation: blink 1.5s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.status-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sound-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.sound-toggle:hover {
    border-color: var(--accent-cyan);
}

.sound-toggle input {
    display: none;
}

.toggle-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.checkbox-box {
    width: 14px;
    height: 14px;
    border: 1px solid var(--text-muted);
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.2s ease;
}

.sound-toggle input:checked ~ .checkbox-box {
    background: var(--accent-green);
    border-color: var(--accent-green);
}

.sound-toggle input:checked ~ .toggle-text {
    color: var(--text-primary);
}

.sound-toggle input:checked ~ .checkbox-box::after {
    content: '✓';
    font-size: 10px;
    color: #000;
    font-weight: bold;
}

.stats {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-secondary);
}

.stats span {
    color: var(--accent-cyan);
    font-weight: 600;
}

/* Alert Feed Container */
.alert-feed-container {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    height: var(--feed-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    z-index: 999;
    overflow: hidden;
}

.alert-feed {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.alert-feed::-webkit-scrollbar {
    height: 4px;
}

.alert-feed::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

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

.alert-feed::-webkit-scrollbar-thumb:hover {
    background: var(--accent-cyan);
}

/* Alert Cards */
.alert-card {
    flex-shrink: 0;
    width: 280px;
    height: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.alert-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--alert-expired);
}

.alert-card.active::before {
    background: var(--accent-red);
    box-shadow: 0 0 10px var(--glow-red);
}

.alert-card:hover {
    border-color: var(--accent-cyan);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 168, 255, 0.15);
}

.alert-card.selected {
    border-color: var(--accent-orange);
    box-shadow: 0 0 20px var(--glow-orange);
}

.alert-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

.alert-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-muted);
}

.alert-status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
}

.alert-status.active {
    color: var(--accent-green);
    border: 1px solid var(--accent-green);
}

.alert-status.expired {
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.alert-status-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
}

.alert-status.active .alert-status-dot {
    animation: blink 1s ease-in-out infinite;
}

.alert-message {
    flex: 1;
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-primary);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.alert-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--border-color);
}

.alert-id {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--text-muted);
}

.alert-view-btn {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--accent-cyan);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color 0.2s ease;
}

.alert-view-btn:hover {
    color: var(--accent-orange);
}

/* Data Source Attribution */
.data-source {
    position: fixed;
    top: calc(var(--header-height) + var(--feed-height));
    right: 0;
    z-index: 10;
    padding: 4px 8px;
    background: rgba(10, 10, 15, 0.85);
    border-bottom-left-radius: 6px;
    border-left: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-muted);
    backdrop-filter: blur(4px);
}

.data-source a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

.data-source a:hover {
    color: var(--accent-cyan);
    text-decoration: underline;
}

/* Map */
#map {
    position: fixed;
    top: calc(var(--header-height) + var(--feed-height));
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
}

/* Dark Map Tiles */
.leaflet-tile-pane {
    filter: brightness(0.8) contrast(1.1) saturate(0.8);
}

.leaflet-container {
    background: var(--bg-primary);
}

/* Custom Leaflet Controls */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    width: 32px !important;
    height: 32px !important;
    line-height: 30px !important;
    font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-tertiary) !important;
    color: var(--accent-cyan) !important;
}

.leaflet-control-attribution {
    background: rgba(10, 10, 15, 0.8) !important;
    color: var(--text-muted) !important;
    font-size: 10px !important;
    padding: 2px 8px !important;
}

.leaflet-control-attribution a {
    color: var(--accent-cyan) !important;
}

/* Custom Popup */
.leaflet-popup-content-wrapper {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5) !important;
}

.leaflet-popup-content {
    margin: 12px !important;
    color: var(--text-primary) !important;
    font-family: 'Inter', sans-serif !important;
}

.leaflet-popup-tip {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
}

.leaflet-popup-close-button {
    color: var(--text-secondary) !important;
    font-size: 18px !important;
}

.leaflet-popup-close-button:hover {
    color: var(--accent-cyan) !important;
}

/* Alert Detail Panel */
.alert-detail-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 50vh;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 1001;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.alert-detail-panel.open {
    transform: translateY(0);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.panel-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-orange);
    letter-spacing: 1px;
}

.panel-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 0 8px;
    transition: color 0.2s ease;
}

.panel-close:hover {
    color: var(--accent-red);
}

.panel-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.panel-content h3 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.panel-content p {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.panel-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.panel-meta-item {
    background: var(--bg-tertiary);
    padding: 10px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.panel-meta-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.panel-meta-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--accent-cyan);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 15, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-orange);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 16px;
    letter-spacing: 2px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    :root {
        --header-height: 44px;
        --feed-height: var(--feed-height-mobile);
    }

    .header-bar {
        padding: 0 12px;
    }

    .logo-text {
        font-size: 12px;
    }

    .status-indicator {
        display: none;
    }

    .auto-scroll-btn {
        padding: 4px 8px;
        font-size: 10px;
    }

    .stats {
        font-size: 10px;
    }

    .alert-feed {
        padding: 8px 12px;
        gap: 10px;
    }

    .alert-card {
        width: 220px;
        padding: 8px 10px;
    }

    .alert-message {
        font-size: 10px;
        -webkit-line-clamp: 2;
    }

    .alert-card-footer {
        display: none;
    }

    .panel-content {
        padding: 12px;
    }

    .panel-meta {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 480px) {
    .alert-card {
        width: 180px;
    }

    .header-right {
        gap: 8px;
    }

    .auto-scroll-btn span:first-child {
        display: none;
    }
}

/* Polygon Styles */
.alert-polygon {
    transition: all 0.3s ease;
}

/* Tooltip */
.custom-tooltip {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 4px !important;
    padding: 8px 12px !important;
    font-family: 'JetBrains Mono', monospace !important;
    font-size: 11px !important;
    color: var(--text-primary) !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4) !important;
}

.custom-tooltip::before {
    border-top-color: var(--bg-secondary) !important;
}

/* Scrollbar for panel */
.panel-content::-webkit-scrollbar {
    width: 6px;
}

.panel-content::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

.panel-content::-webkit-scrollbar-thumb {
    background: var(--border-accent);
    border-radius: 3px;
}

.panel-content::-webkit-scrollbar-thumb:hover {
    background: var(--accent-cyan);
}
