/* ===== EXACT IDS DESIGN SYSTEM REPLICATION ===== */
/* Based on tmlsmasterclass.vercel.app */

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

:root {
    /* Core Colors - EXACT from IDS */
    --paper: #0a0a0a;
    --ink: #fafafa;
    --ink-2: rgba(250, 250, 250, 0.72);
    --ink-3: rgba(250, 250, 250, 0.54);
    --ink-4: rgba(250, 250, 250, 0.36);
    --ink-5: rgba(250, 250, 250, 0.18);
    
    /* UI Borders - EXACT opacity values */
    --ui-border: rgba(255, 255, 255, 0.07);
    --ui-border-mid: rgba(255, 255, 255, 0.13);
    --ui-border-strong: rgba(255, 255, 255, 0.26);
    --ui-border-focus: rgba(255, 255, 255, 0.54);
    
    /* Semantic Colors - Signal only */
    --signal-red: #ef4444;
    --signal-orange: #f97316;
    --signal-purple: #a855f7;
    --signal-blue: #3b82f6;
    --signal-green: #10b981;
    
    /* Typography - EXACT from IDS */
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'JetBrains Mono', 'Courier New', monospace;
    
    /* Layout */
    --nav-h: 56px;
    --sidebar-w: 280px;
}

body {
    font-family: var(--sans);
    background: var(--paper);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    height: 100vh;
}

/* ===== LOADING SCREEN ===== */
#loading-screen {
    position: fixed;
    inset: 0;
    background: var(--paper);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeOut 0.3s ease 2.2s forwards;
}

@keyframes fadeOut {
    to {
        opacity: 0;
        visibility: hidden;
    }
}

.loading-content {
    text-align: center;
}

.loading-icon {
    margin-bottom: 16px;
    animation: pulse 1.5s ease-in-out infinite;
}

.loading-icon svg {
    width: 32px;
    height: 32px;
    color: var(--ink-3);
}

.loading-text {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    color: var(--ink-4);
    margin-bottom: 24px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.loading-pulse {
    width: 32px;
    height: 32px;
    margin: 0 auto;
    border: 1.5px solid var(--signal-red);
    border-radius: 50%;
    animation: pulseRing 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.7; }
    50% { transform: scale(1.02); opacity: 1; }
}

@keyframes pulseRing {
    0% { transform: scale(0.9); opacity: 1; }
    100% { transform: scale(1.3); opacity: 0; }
}

/* ===== HEADER (NAV) ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-h);
    background: rgba(10, 10, 10, 0.94);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--ui-border);
    display: flex;
    align-items: center;
    padding: 0 28px;
    z-index: 200;
    justify-content: space-between;
    gap: 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 280px;
    flex-shrink: 0;
}

.logo svg {
    width: 20px;
    height: 20px;
    color: var(--ink);
    flex-shrink: 0;
}

.title-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.title {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.subtitle {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: var(--ink-4);
    white-space: nowrap;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.stats-bar {
    display: flex;
    gap: 32px;
}

.stat-item {
    text-align: center;
}

.stat-label {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-4);
    margin-bottom: 5px;
    font-weight: 500;
}

.stat-value {
    font-family: var(--mono);
    font-size: 30px;
    font-weight: 500;
    color: var(--ink);
    line-height: 1;
}

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

.live-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 4px;
}

.live-dot {
    width: 5px;
    height: 5px;
    background: var(--signal-red);
    border-radius: 50%;
    animation: livePulse 2s ease-in-out infinite;
}

@keyframes livePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.live-text {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--signal-red);
    letter-spacing: 0.10em;
    text-transform: uppercase;
}

.settings-btn {
    background: transparent;
    border: 1px solid var(--ui-border);
    color: var(--ink-3);
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-btn:hover {
    color: var(--ink);
}

.settings-btn svg {
    width: 16px;
    height: 16px;
}

/* ===== MAIN CONTAINER ===== */
.main-container {
    display: flex;
    height: calc(100vh - var(--nav-h));
    margin-top: var(--nav-h);
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-w);
    position: relative;
    height: calc(100vh - var(--nav-h));
    overflow-y: auto;
    padding: 24px 0 24px 20px;
    flex-shrink: 0;
    border-right: 1px solid var(--ui-border);
    transition: transform 0.3s ease;
    background: var(--bg-secondary);
    z-index: 500;
}

.sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-w)));
}

.sidebar-toggle {
    position: absolute;
    top: 16px;
    right: -36px;
    width: 36px;
    height: 36px;
    background: var(--bg-secondary);
    border: 1px solid var(--ui-border);
    border-left: none;
    border-radius: 0 6px 6px 0;
    color: var(--ink-3);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar.collapsed .sidebar-toggle {
    transform: rotate(180deg);
}

.sidebar-toggle:hover {
    background: var(--bg-elevated);
    color: var(--ink);
}

.sidebar-toggle svg {
    width: 14px;
    height: 14px;
}

.sidebar-content {
    padding-right: 16px;
}

.sidebar-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--ui-border);
}

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

.section-title {
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-4);
    margin-bottom: 5px;
}

/* Data Source */
.data-source-badge {
    display: inline-block;
    padding: 4px 10px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 600;
    color: var(--signal-red);
    letter-spacing: 0.10em;
    text-transform: uppercase;
    margin-bottom: 12px;
}

.data-source-badge.live {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.2);
    color: var(--signal-green);
}

.api-connection {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.api-info {
    font-size: 12px;
    color: var(--ink-3);
    line-height: 1.35;
}

.api-link {
    font-family: var(--sans);
    font-size: 12px;
    color: var(--signal-blue);
    text-decoration: none;
    transition: color 0.10s;
    font-weight: 400;
}

.api-link:hover {
    color: var(--ink);
}

/* Filters */
.filter-group {
    margin-bottom: 16px;
}

.filter-label {
    display: block;
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 400;
    color: var(--ink-3);
    margin-bottom: 6px;
}

.input-field {
    width: 100%;
    padding: 8px 10px;
    background: transparent;
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    color: var(--ink);
    font-size: 13px;
    font-family: var(--sans);
    transition: border-color 0.12s;
}

.input-field:focus {
    outline: none;
    border-color: var(--ui-border-focus);
}

.input-field + .input-field {
    margin-top: 6px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    font-size: 12px;
    color: var(--ink-3);
    cursor: pointer;
    transition: color 0.10s;
    line-height: 1.35;
}

.checkbox-label:hover {
    color: var(--ink);
}

.checkbox {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: var(--signal-red);
}

/* Buttons */
.btn {
    padding: 8px 14px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.12s;
    font-family: var(--sans);
}

.btn-primary {
    background: var(--signal-red);
    color: white;
}

.btn-primary:hover {
    background: #dc2626;
}

.btn-secondary {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--ui-border);
}

.btn-secondary:hover {
    border-color: var(--ui-border-mid);
}

.btn-block {
    width: 100%;
}

/* Recent Events */
.recent-events {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.recent-events::-webkit-scrollbar {
    width: 4px;
}

.recent-events::-webkit-scrollbar-thumb {
    background: var(--ink-5);
    border-radius: 2px;
}

.event-item {
    padding: 9px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    cursor: pointer;
    transition: all 0.10s;
}

.event-item:hover {
    padding-left: 4px;
}

.event-type-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 2px;
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 600;
    margin-bottom: 6px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.event-type-badge.explosion {
    background: rgba(239, 68, 68, 0.12);
    color: var(--signal-red);
}

.event-type-badge.battle {
    background: rgba(249, 115, 22, 0.12);
    color: var(--signal-orange);
}

.event-type-badge.violence {
    background: rgba(168, 85, 247, 0.12);
    color: var(--signal-purple);
}

.event-type-badge.strategic {
    background: rgba(59, 130, 246, 0.12);
    color: var(--signal-blue);
}

.event-location {
    font-size: 13px;
    font-weight: 400;
    color: var(--ink-3);
    margin-bottom: 4px;
    line-height: 1.35;
}

.event-date {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--ink-4);
}

/* ===== MAP ===== */
.map-wrapper {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
    background: var(--paper);
}

/* Map Controls */
.map-controls {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
}

.map-control-btn {
    width: 36px;
    height: 36px;
    background: rgba(10, 10, 10, 0.94);
    backdrop-filter: blur(16px);
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    color: var(--ink-3);
    cursor: pointer;
    transition: color 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-control-btn:hover {
    color: var(--ink);
}

.map-control-btn.active {
    background: var(--signal-red);
    border-color: var(--signal-red);
    color: white;
}

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

/* Legend */
.legend {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: rgba(10, 10, 10, 0.94);
    backdrop-filter: blur(16px);
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    padding: 14px;
    min-width: 180px;
    z-index: 1000;
}

.legend-title {
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-4);
    margin-bottom: 10px;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--ink-3);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-dot-small {
    width: 8px;
    height: 8px;
    background: var(--ink-5);
}

.legend-dot-large {
    width: 14px;
    height: 14px;
    background: var(--ink-5);
}

.legend-divider {
    height: 1px;
    background: var(--ui-border);
    margin: 8px 0;
}

.legend-disclaimer {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--ui-border);
}

.legend-disclaimer p {
    font-size: 9px;
    line-height: 1.4;
    color: var(--ink-4);
    margin: 0;
}

/* Timeline Panel */
.timeline-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(10, 10, 10, 0.94);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--ui-border);
    padding: 16px 20px;
    display: none;
    z-index: 1000;
}

.timeline-panel.active {
    display: block;
}

.timeline-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.timeline-btn {
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    color: var(--ink-3);
    cursor: pointer;
    transition: color 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.timeline-btn:hover {
    color: var(--ink);
}

.timeline-btn svg {
    width: 14px;
    height: 14px;
}

.timeline-date {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink);
}

.timeline-slider {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--ink);
    border-radius: 50%;
    cursor: pointer;
}

.timeline-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--ink);
    border-radius: 50%;
    border: none;
    cursor: pointer;
}

/* ===== MODAL ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--paper);
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--ink-3);
    font-size: 24px;
    cursor: pointer;
    transition: color 0.12s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: var(--ink);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--ink-5);
    border-radius: 3px;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-2);
    margin-bottom: 8px;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch label {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.1);
    transition: 0.12s;
    border-radius: 24px;
}

.toggle-switch label:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    transition: 0.12s;
    border-radius: 50%;
}

.toggle-switch input:checked + label {
    background: var(--signal-red);
}

.toggle-switch input:checked + label:before {
    transform: translateX(20px);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--ui-border);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ===== LEAFLET OVERRIDES ===== */
.leaflet-container {
    background: var(--paper);
    font-family: var(--sans);
}

.leaflet-popup-content-wrapper {
    background: rgba(10, 10, 10, 0.96);
    backdrop-filter: blur(16px);
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    color: var(--ink);
}

.leaflet-popup-content {
    margin: 14px;
    font-size: 13px;
    line-height: 1.5;
}

.leaflet-popup-tip {
    background: rgba(10, 10, 10, 0.96);
    border: 1px solid var(--ui-border);
}

.leaflet-control-zoom a {
    background: rgba(10, 10, 10, 0.94);
    backdrop-filter: blur(16px);
    border: 1px solid var(--ui-border);
    color: var(--ink-3);
}

.leaflet-control-zoom a:hover {
    color: var(--ink);
}

/* Popup Content Styling */
.popup-content {
    font-family: var(--sans);
}

.popup-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 10px;
    letter-spacing: -0.01em;
}

.popup-field {
    margin-bottom: 6px;
    font-size: 12px;
    line-height: 1.5;
}

.popup-label {
    color: var(--ink-4);
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.popup-value {
    color: var(--ink-2);
    margin-left: 6px;
}

.popup-notes {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--ui-border);
    font-size: 12px;
    line-height: 1.6;
    color: var(--ink-3);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .header {
        padding: 0 16px;
    }
    
    .stats-bar {
        gap: 16px;
    }
    
    .stat-value {
        font-size: 20px;
    }
    
    .sidebar {
        width: 100%;
        max-width: 280px;
    }
    
    .map-controls {
        top: 12px;
        right: 12px;
    }
    
    .legend {
        bottom: 12px;
        right: 12px;
    }
}