/* CSS Variables for design tokens */
:root {
    --bg-primary: #0b0f19;
    --bg-secondary: #131a26;
    --bg-card: rgba(22, 30, 46, 0.85);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(249, 115, 22, 0.4);
    
    --accent-orange: #f97316;
    --accent-orange-glow: rgba(249, 115, 22, 0.25);
    --accent-cyan: #06b6d4;
    --accent-cyan-glow: rgba(6, 182, 212, 0.25);
    --accent-red: #ef4444;
    --accent-green: #10b981;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-orange);
}

/* Typography */
h1, h2, h3, h4 {
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

/* Header */
.app-header {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 2rem;
    height: 2rem;
    color: var(--accent-orange);
    animation: pulse 2s infinite;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--text-primary) 30%, var(--accent-orange));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    display: flex;
    gap: 1rem;
}

.btn-nav {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.btn-nav:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-orange);
    color: var(--accent-orange);
}

/* Main Container (Mobile-first grid) */
.dashboard-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 1600px;
    margin: 0 auto;
}

/* Controls / Filters Panel */
.panel-filters {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.25rem;
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow-premium);
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-top: 1rem;
}

@media (min-width: 640px) {
    .filter-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.form-control {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.625rem 0.875rem;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    outline: none;
    transition: var(--transition-smooth);
    width: 100%;
}

.form-control:focus {
    border-color: var(--accent-orange);
    box-shadow: 0 0 0 3px var(--accent-orange-glow);
}

/* Statistics cards */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

@media (min-width: 768px) {
    .stats-summary {
        grid-template-columns: repeat(4, 1fr);
    }
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow-premium);
    transition: var(--transition-smooth);
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-hover);
}

.stat-card .value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--accent-orange);
    margin-top: 0.25rem;
}

.stat-card .label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
}

/* Map and List Section */
.map-list-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 1024px) {
    .map-list-section {
        grid-template-columns: 2fr 1fr;
        height: 600px;
    }
}

/* Map Styling */
.map-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-premium);
    min-height: 400px;
    height: 100%;
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Leaflet Customizations for Dark Mode */
.leaflet-container {
    background: var(--bg-primary) !important;
}

.leaflet-popup-content-wrapper {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem !important;
    box-shadow: var(--shadow-premium) !important;
}

.leaflet-popup-tip {
    background: var(--bg-secondary) !important;
}

.popup-content {
    font-family: var(--font-sans);
    padding: 0.25rem;
}

.popup-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--accent-orange);
    margin-bottom: 0.5rem;
}

.popup-details {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
}

.popup-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.375rem 0.75rem;
    background: var(--accent-orange);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0.375rem;
    width: 100%;
    text-align: center;
    transition: var(--transition-smooth);
}

.popup-link:hover {
    background: #ea580c;
}

/* Sismo List Container */
.list-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.25rem;
    box-shadow: var(--shadow-premium);
    display: flex;
    flex-direction: column;
    height: 450px; /* Fixed height on mobile so it scrolls properly and doesn't spill */
    overflow: hidden; /* Prevent child list items from spilling over */
}

@media (min-width: 1024px) {
    .list-container {
        height: 100%; /* Take full height of parent grid on desktop */
        max-height: none;
    }
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.list-title {
    font-size: 1rem;
    font-weight: 700;
}

.list-count {
    background: rgba(249, 115, 22, 0.15);
    color: var(--accent-orange);
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 700;
}

.list-items {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-right: 0.25rem;
}

.sismo-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.875rem;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    gap: 0.875rem;
    position: relative;
    overflow: hidden;
    flex-shrink: 0; /* Prevent items from shrinking when list content overflows */
}

.sismo-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-orange);
    opacity: 0;
    transition: var(--transition-smooth);
}

.sismo-item:hover, .sismo-item.selected {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border-hover);
    transform: translateX(2px);
}

.sismo-item:hover::before, .sismo-item.selected::before {
    opacity: 1;
}

.sismo-item.selected {
    border-color: var(--accent-cyan);
}
.sismo-item.selected::before {
    background: var(--accent-cyan);
}

.sismo-badge {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.sismo-badge.level-minor {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green);
}
.sismo-badge.level-moderate {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}
.sismo-badge.level-strong {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
}

.sismo-info {
    flex: 1;
    min-width: 0;
}

.sismo-place {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.sismo-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

/* Charts Section */
.charts-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 768px) {
    .charts-section {
        grid-template-columns: 1fr 1fr;
    }
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.25rem;
    box-shadow: var(--shadow-premium);
    display: flex;
    flex-direction: column;
    min-height: 320px;
}

.chart-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 240px; /* Fixed height to prevent collapse and overflow */
}

/* Info and Prevention Page specific styles */
.info-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.info-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-premium);
}

.info-card h2 {
    font-size: 1.5rem;
    color: var(--accent-orange);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.info-card p {
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
    font-size: 0.95rem;
}

.info-card ul {
    margin-left: 1.5rem;
    margin-bottom: 1.25rem;
    color: var(--text-secondary);
}

.info-card li {
    margin-bottom: 0.5rem;
}

/* Detail page specific styling */
.detail-container {
    max-width: 700px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.detail-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    overflow: hidden;
    box-shadow: var(--shadow-premium);
}

.detail-header {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-primary));
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
    position: relative;
}

.detail-mag-badge {
    width: 5rem;
    height: 5rem;
    border-radius: 1.25rem;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.25rem;
    font-weight: 900;
}

.detail-map {
    height: 250px;
    border-bottom: 1px solid var(--border-color);
}

.detail-body {
    padding: 2rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.detail-field {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem;
}

.detail-field .label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.detail-field .value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.detail-footer {
    display: flex;
    gap: 1rem;
    padding: 1rem 2rem 2rem;
}

.btn-primary {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    background: var(--accent-orange);
    color: white;
    text-decoration: none;
    font-weight: 700;
    border-radius: 0.75rem;
    transition: var(--transition-smooth);
    border: none;
    cursor: pointer;
}

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

.btn-secondary {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    border-radius: 0.75rem;
    transition: var(--transition-smooth);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-orange);
}

/* Animations */
@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

.pulse-anim {
    animation: pulse 2s infinite;
}

/* Loading overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(11, 15, 25, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 100;
    transition: opacity 0.3s ease;
    border-radius: 1rem;
}

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

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error banner */
.error-banner {
    background: rgba(239, 68, 68, 0.15);
    border-left: 4px solid var(--accent-red);
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    display: none;
}
