/* ═══════════════════════════════════════════════════════════════════
   Gotham SDP — style.css
   Painel de Segurança Pública · Santana de Parnaíba
   ═══════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ─────────────────────────────────────────────── */
:root {
    --bg: #0a0c10;
    --bg2: #111318;
    --bg3: #1a1d25;
    --border: rgba(255, 255, 255, 0.07);
    --border2: rgba(255, 255, 255, 0.12);
    --accent: #e8ff47;
    --accent2: #ff6b35;
    --accent3: #47c9ff;
    --text: #e8eaf0;
    --muted: #6b7280;
    --danger: #ff4444;
    --warn: #ffaa00;
    --safe: #22c55e;
    --font-display: 'Syne', sans-serif;
    --font-body: 'DM Sans', sans-serif;
    --font-mono: 'DM Mono', monospace;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    height: 100vh;
    overflow: hidden;
    display: grid;
    grid-template-rows: 52px 1fr;
    grid-template-columns: 280px 1fr;
}

/* ── HEADER ────────────────────────────────────────────────────── */
header {
    grid-column: 1 / -1;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
}

.logo {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 15px;
    letter-spacing: -0.02em;
    color: var(--accent);
    white-space: nowrap;
}
.logo span { color: var(--text); font-weight: 400; }

.header-sep {
    width: 1px; height: 24px;
    background: var(--border2);
    margin: 0 4px;
}

.header-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
    font-family: var(--font-mono);
}
.header-stat strong { color: var(--text); }

.header-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--safe);
    animation: pulse 2s infinite;
}

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


.year-badge {
    font-family: var(--font-mono);
    font-size: 11px;
    background: rgba(232, 255, 71, 0.1);
    color: var(--accent);
    border: 1px solid rgba(232, 255, 71, 0.2);
    border-radius: 4px;
    padding: 3px 8px;
}

/* ── SIDEBAR ───────────────────────────────────────────────────── */
aside {
    background: var(--bg2);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
aside::-webkit-scrollbar { width: 4px; }
aside::-webkit-scrollbar-track { background: transparent; }
aside::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.section-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.1em;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 8px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

select, input[type=text], input[type=password] {
    background: var(--bg3);
    border: 1px solid var(--border2);
    color: var(--text);
    border-radius: 6px;
    padding: 7px 10px;
    font-family: var(--font-body);
    font-size: 13px;
    width: 100%;
    outline: none;
    transition: border-color 0.2s;
}
select:focus, input:focus { border-color: rgba(232, 255, 71, 0.4); }
option { background: var(--bg3); }

/* Search bar with icon */
.search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.search-wrap input {
    padding-left: 32px;
}
.search-icon {
    position: absolute;
    left: 10px;
    width: 14px;
    height: 14px;
    color: var(--muted);
    pointer-events: none;
}

.btn {
    background: var(--accent);
    color: #0a0c10;
    border: none;
    border-radius: 6px;
    padding: 9px 14px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    width: 100%;
    transition: opacity 0.2s, transform 0.1s;
    letter-spacing: 0.01em;
}
.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.98); }

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border2);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border2); opacity: 1; }

.btn-export {
    width: auto;
    padding: 6px 12px;
    font-size: 12px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.btn-export svg {
    vertical-align: middle;
}

/* ── Ranking bairros ───────────────────────────────────────────── */
.bairro-rank {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bairro-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid transparent;
}
.bairro-item:hover { background: var(--bg3); border-color: var(--border); }
.bairro-item.active { background: rgba(232, 255, 71, 0.07); border-color: rgba(232, 255, 71, 0.2); }
.bairro-item.hidden { display: none; }

.bairro-rank-num {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted);
    min-width: 18px;
}

.bairro-name { flex: 1; font-size: 13px; }

.bairro-count {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
}

.bairro-bar-wrap {
    width: 100%;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 3px;
}
.bairro-bar {
    height: 3px;
    border-radius: 2px;
    background: var(--accent2);
    transition: width 0.5s;
}

/* ── MAIN / MAP ────────────────────────────────────────────────── */
main {
    display: grid;
    grid-template-rows: 1fr;
    position: relative;
    overflow: hidden;
}

#map { width: 100%; height: 100%; background: #0d1117; }
.leaflet-container { background: #0d1117; }

/* Loading overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 12, 16, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    transition: opacity 0.4s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }

.loading-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 13px;
}

.spinner-lg {
    width: 32px; height: 32px;
    border: 3px solid var(--border2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* Legend overlay */
.map-overlay {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: 10px;
    padding: 14px 16px;
    min-width: 220px;
    pointer-events: none;
    font-size: 12px;
    z-index: 800;
}
.map-overlay h4 {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 10px;
    color: var(--accent);
}

.legend-item { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.legend-hint { margin-top: 10px; font-size: 11px; color: var(--muted); }

/* ── MODAL ─────────────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-backdrop.open { display: flex; }

.modal {
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: 16px;
    width: 100%;
    max-width: 860px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease;
}
.modal::-webkit-scrollbar { width: 4px; }
.modal::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

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

.modal-title {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 20px;
    letter-spacing: -0.02em;
}

.modal-sub {
    font-size: 12px;
    color: var(--muted);
    margin-top: 3px;
    font-family: var(--font-mono);
}

.modal-actions { display: flex; align-items: center; gap: 8px; }

.close-btn {
    background: var(--bg3);
    border: 1px solid var(--border2);
    color: var(--muted);
    border-radius: 6px;
    width: 32px; height: 32px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}
.close-btn:hover { color: var(--text); border-color: var(--border2); }

.modal-body {
    padding: 20px 24px;
    display: grid;
    gap: 20px;
}

/* ── Stat Cards ────────────────────────────────────────────────── */
.cards-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

.stat-card {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
}
.stat-card .label {
    font-size: 11px;
    color: var(--muted);
    font-family: var(--font-mono);
    margin-bottom: 4px;
}
.stat-card .value {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 22px;
}
.stat-card .value.danger { color: var(--danger); }
.stat-card .value.warn { color: var(--warn); }
.stat-card .value.safe { color: var(--safe); }
.stat-card .value.accent { color: var(--accent); }

/* ── Charts ────────────────────────────────────────────────────── */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.chart-card {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
}
.chart-card h3 {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Top Crimes list ───────────────────────────────────────────── */
.crimes-list { display: flex; flex-direction: column; gap: 5px; }

.crime-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 5px;
    font-size: 12px;
}
.crime-row .crime-name { color: var(--text); flex: 1; }
.crime-row .crime-n {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent2);
    background: rgba(255, 107, 53, 0.1);
    border-radius: 3px;
    padding: 1px 6px;
}

/* ── IA Analysis Box ───────────────────────────────────────────── */
.ai-box {
    background: var(--bg3);
    border: 1px solid rgba(71, 201, 255, 0.2);
    border-radius: 10px;
    padding: 16px;
}
.ai-header { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }

.ai-tag {
    font-family: var(--font-mono);
    font-size: 10px;
    background: rgba(71, 201, 255, 0.1);
    color: var(--accent3);
    border: 1px solid rgba(71, 201, 255, 0.2);
    border-radius: 4px;
    padding: 2px 7px;
}
.ai-header h3 { font-family: var(--font-display); font-weight: 700; font-size: 15px; }

.ai-text { font-size: 13px; line-height: 1.7; color: #cdd2dc; }

.ai-recs { margin-top: 12px; display: flex; flex-direction: column; gap: 7px; }

.ai-rec {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 9px 12px;
    background: rgba(71, 201, 255, 0.04);
    border-radius: 7px;
    border-left: 2px solid var(--accent3);
    font-size: 12px;
    line-height: 1.6;
}
.ai-rec-icon {
    flex-shrink: 0;
    margin-top: 2px;
    width: 16px;
    height: 16px;
    color: var(--accent3);
    display: flex;
    align-items: center;
    justify-content: center;
}
.ai-rec-icon svg {
    width: 16px;
    height: 16px;
}

.ai-fallback-notice {
    margin-top: 12px;
    font-size: 11px;
    color: #4b5563;
    font-family: var(--font-mono);
}

.ai-error {
    padding: 10px 14px;
    background: rgba(255, 68, 68, 0.08);
    border: 1px solid rgba(255, 68, 68, 0.2);
    border-radius: 7px;
    color: #ff8888;
    font-size: 12px;
    line-height: 1.6;
}

/* ── Loading / Spinner ─────────────────────────────────────────── */
.loading-ai {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-family: var(--font-mono);
}

.spinner {
    width: 14px; height: 14px;
    border: 2px solid var(--border2);
    border-top-color: var(--accent3);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ── Marker tooltip ────────────────────────────────────────────── */
.marker-tooltip {
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: 8px;
    padding: 8px 12px;
    font-family: var(--font-body);
    font-size: 12px;
    color: var(--text);
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.marker-tooltip .tooltip-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 2px;
}
.marker-tooltip .tooltip-count {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent);
}

/* ── Animations ────────────────────────────────────────────────── */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

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