:root {
    --bg-dark: #0f1419;
    --bg-card: #1a1f26;
    --text-primary: #e7e9ea;
    --text-muted: #8b98a5;
    --accent: #c9a227;
    --accent-dim: rgba(201, 162, 39, 0.3);
    --border: rgba(139, 152, 165, 0.2);
}

* {
    box-sizing: border-box;
}

html {
    overflow-y: auto;
    overflow-x: hidden;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.header {
    padding: 2rem 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
}

.header-text {
    flex: 1 1 auto;
}

.site-title {
    margin: 0;
    font-family: 'DM Sans', sans-serif;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
}

.site-subtitle {
    margin: 0.5rem 0 0;
    color: var(--text-muted);
    font-size: 1rem;
}

.lang-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.lang-btn {
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 0.85rem;
}

.lang-btn.lang-active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}

.lang-separator {
    opacity: 0.6;
}

/* Sticky section navigation */
.section-nav {
    position: sticky;
    top: 0;
    z-index: 500;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.section-nav::-webkit-scrollbar { display: none; }
.section-nav-link {
    padding: 0.7rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}
.section-nav-link:hover { color: var(--text-primary); }
.section-nav-link.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.main {
    padding: 2rem 0 4rem;
}

.map-section {
    margin-bottom: 3rem;
}

.section-header h2 {
    margin: 0 0 0.5rem;
    font-size: 1.5rem;
}

.section-desc {
    margin: 0 0 1.5rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.section-header-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}
.section-header-row h2 {
    margin: 0;
}
.incident-count-badge {
    font-size: 0.9rem;
    color: var(--accent);
    font-weight: 600;
    background: var(--accent-dim);
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--accent);
    white-space: nowrap;
}

.loading-msg, .error-msg {
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}
.loading-msg {
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.loading-msg::before {
    content: '';
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--accent-dim);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: loading-spin 0.7s linear infinite;
}
@keyframes loading-spin {
    to { transform: rotate(360deg); }
}
.error-msg { color: #e74c3c; }

.map-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.filter-group > label {
    font-weight: 500;
    font-size: 0.9rem;
}

.filter-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.filter-checkboxes label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 400;
    cursor: pointer;
    font-size: 0.9rem;
}

.time-slider-group {
    min-width: 200px;
}

.time-slider-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.time-slider {
    flex: 1;
    min-width: 100px;
}

.time-slider-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 5ch;
}

.time-play-btn {
    padding: 0.25rem 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
}

.time-play-btn:hover {
    border-color: var(--accent);
}

.reset-btn {
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    align-self: flex-end;
}

.reset-btn:hover {
    border-color: var(--accent);
}

.show-history-btn {
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.9rem;
}

.show-history-btn:hover:not(:disabled) {
    border-color: var(--accent);
}

.show-history-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.incident-count {
    align-self: flex-end;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.year-select {
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
}

.year-select:focus {
    outline: none;
    border-color: var(--accent);
}

.map-container {
    width: 100%;
    height: 500px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.map-container .leaflet-container {
    background: #1a2a2a;
    height: 100%;
}

.map-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--bg-card);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.legend-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #fff;
}

.legend-icon.no-location { background: #888888; }
.legend-icon.armed-clash { background: #dc143c; }
.legend-icon.kidnapping { background: #ff4500; }
.legend-icon.assassination { background: #8b0000; }
.legend-icon.mass-shooting { background: #ffa500; }
.legend-icon.cartel-violence { background: #b22222; }
.legend-icon.other { background: #666; }

.stats-section h2 {
    margin: 0 0 1.5rem;
    font-size: 1.5rem;
}

.year-quick-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.year-quick-btn {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.year-quick-btn:hover {
    border-color: var(--accent);
    background: var(--accent-dim);
}

.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.charts-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    overflow: hidden;
    min-height: 0; /* allow flex/grid shrinking where needed */
}

.chart-container > div {
    min-height: 320px;
    width: 100%;
}

.chart-container h3 {
    margin: 0 0 1rem;
    font-size: 1rem;
    flex-shrink: 0;
}

.last-updated {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.footer {
    padding: 1.5rem 0;
    border-top: 1px solid var(--border);
    text-align: center;
}

.footer p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.leaflet-popup-content-wrapper {
    background: #fff;
    color: #1a1a2e;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.leaflet-popup-content {
    margin: 0.75rem;
    min-width: min(240px, calc(100vw - 80px));
    max-width: min(360px, calc(100vw - 60px));
}

.popup-content h3 {
    margin: 0 0 0.4rem;
    font-size: 1rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.4rem;
    color: #555;
}
.popup-title {
    margin: 0 0 0.6rem;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.4;
    color: #1a1a2e;
}
.popup-title a { color: #1a6ab1; text-decoration: none; }
.popup-title a:hover { text-decoration: underline; }

.popup-content p {
    margin: 0.5rem 0;
    font-size: 0.9rem;
}

.popup-content a {
    color: #c9a227;
}

.location-approx {
    font-size: 0.85em;
    color: #888;
    font-weight: 400;
}

.popup-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
    font-size: 0.8rem;
    color: #666;
}

.lang-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    border: 1px solid #ccc;
    font-size: 0.7rem;
    text-transform: uppercase;
}

.translation-toggle {
    margin-top: 0.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.translation-toggle button {
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    border: 1px solid #ddd;
    background: #f5f5f5;
    color: #444;
    font-size: 0.75rem;
    cursor: pointer;
}

.translation-toggle button.is-active {
    background: #c9a227;
    color: #fff;
    border-color: #c9a227;
}

.summary-text {
    margin-top: 0.25rem;
}

.footer-note {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.system-status {
    align-self: flex-end;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    background: var(--bg-card);
    cursor: default;
    white-space: nowrap;
}
.system-status.status-ok { border-color: #22c55e; color: #22c55e; }
.system-status.status-degraded { border-color: #ef4444; color: #ef4444; }

.time-last30-btn {
    padding: 0.25rem 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
}
.time-last30-btn:hover { border-color: var(--accent); }

.filter-type-actions {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.25rem;
}
.filter-action-btn {
    padding: 0.15rem 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.78rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.filter-action-btn:hover { border-color: var(--accent); color: var(--accent); }

.incidents-section {
    padding: 2rem 0 3rem;
    border-top: 1px solid var(--border);
}
.incidents-section h2 {
    margin: 0 0 1rem;
    font-size: 1.5rem;
}
.incidents-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.incident-search {
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    width: 280px;
    max-width: 100%;
}
.incident-search:focus { outline: none; border-color: var(--accent); }
.incident-search::placeholder { color: var(--text-muted); }
.incident-table-wrap { overflow-x: auto; }
.incident-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.incident-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
.incident-table th:hover { color: var(--accent); }
.incident-table th.sort-asc::after { content: ' ↑'; color: var(--accent); }
.incident-table th.sort-desc::after { content: ' ↓'; color: var(--accent); }
.incident-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.incident-table tr:hover td { background: rgba(201,162,39,0.05); }
.incident-table a { color: var(--accent); text-decoration: none; }
.incident-table a:hover { text-decoration: underline; }
.incident-title-cell { max-width: 260px; }
.incident-title-link { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.35; }
.type-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
}
.pagination-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.4rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}
.page-btn {
    padding: 0.3rem 0.65rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.15s;
}
.page-btn:hover:not(:disabled) { border-color: var(--accent); }
.page-btn.page-active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.incidents-count-info { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.5rem; }

/* Filter toggle button — visible on mobile, hidden on desktop */
.filter-toggle-btn {
    display: none;
    width: 100%;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 0.5rem;
    text-align: left;
    transition: border-color 0.15s;
}
.filter-toggle-btn:hover { border-color: var(--accent); }

.map-controls.filters-collapsed {
    display: none;
}

/* Footer credit */
.footer-credit {
    margin-top: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.footer-credit a {
    color: var(--accent);
    text-decoration: none;
}
.footer-credit a:hover { text-decoration: underline; }

/* Scroll-to-top button */
.scroll-top-btn {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 44px;
    height: 44px;
    background: var(--accent);
    color: var(--bg-dark);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    z-index: 999;
    box-shadow: 0 4px 14px rgba(0,0,0,0.4);
    transition: transform 0.15s;
}
.scroll-top-btn.visible { display: flex; }
.scroll-top-btn:hover { transform: translateY(-2px); }

/* Primary chart row — 2 col, larger */
.charts-row-primary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}
.charts-row-primary .chart-container > div {
    min-height: 300px;
}

@media (max-width: 768px) {
    .main { padding: 1rem 0 3rem; }
    .map-container { height: 55vh; min-height: 280px; }
    .filter-toggle-btn { display: block; }
    .incident-table-wrap { overflow-x: auto; }
    .incident-search { width: 100%; }
    .incidents-header { flex-direction: column; align-items: flex-start; }
    .chart-container > div { min-height: 240px; }
    .charts-row-primary .chart-container > div { min-height: 260px; }
    .section-nav-link { padding: 0.6rem 1rem; font-size: 0.85rem; }
    .site-title { font-size: 1.35rem; }
    .site-subtitle { font-size: 0.88rem; }
    .header { padding: 1.25rem 0; }
    .stats-cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .stat-value { font-size: 1.5rem; }
    .time-slider-row { flex-wrap: wrap; row-gap: 0.4rem; }
    .time-slider { order: 1; min-width: 100%; }
    .time-slider-label { order: 2; }
    .time-play-btn { order: 3; }
    .time-last30-btn { order: 4; }
}

@media (max-width: 480px) {
    .container { padding: 0 0.75rem; }
    .map-container { height: 50vh; min-height: 260px; border-radius: 8px; }
    .map-legend { gap: 0.75rem; font-size: 0.8rem; padding: 0.75rem; }
    .header-row { gap: 0.75rem; }
}
