/* ─── ZonaSeguraMX — Estilos del Portal ─────────────────────────────────── */

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

:root {
    --alto:      #E24B4A;
    --alto-bg:   #FCEBEB;
    --alto-text: #A32D2D;
    --medio:     #EF9F27;
    --medio-bg:  #FAEEDA;
    --medio-text:#854F0B;
    --bajo:      #639922;
    --bajo-bg:   #EAF3DE;
    --bajo-text: #3B6D11;
    --blue:      #185FA5;
    --blue-dark: #0C447C;
    --border:    rgba(0,0,0,0.1);
    --bg:        #f4f5f7;
    --surface:   #ffffff;
    --text:      #1a1a1a;
    --muted:     #6b7280;
    --radius:    8px;
    --radius-lg: 12px;
    --shadow:    0 1px 4px rgba(0,0,0,0.08);
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* ─── Layout principal ──────────────────────────────────────────────────── */
.portal-layout { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ─── Header ────────────────────────────────────────────────────────────── */
.portal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 20px; background: var(--surface);
    border-bottom: 0.5px solid var(--border); flex-shrink: 0;
    height: 52px;
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.brand-text { font-size: 16px; font-weight: 400; color: var(--text); }
.brand-text strong { color: var(--blue); font-weight: 600; }
.badge-ai {
    font-size: 11px; background: #EBF4FF; color: var(--blue);
    padding: 3px 8px; border-radius: 20px; border: 0.5px solid #B5D4F4;
}
.header-status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* ─── Toolbar ───────────────────────────────────────────────────────────── */
.portal-toolbar {
    display: flex; gap: 10px; align-items: center;
    padding: 10px 20px; background: #f9fafb;
    border-bottom: 0.5px solid var(--border);
    flex-shrink: 0; flex-wrap: wrap;
}
.ctrl-select, .ctrl-input {
    height: 36px; padding: 0 12px;
    border: 0.5px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text);
    font-size: 13px; min-width: 160px; outline: none;
    transition: border-color 0.15s;
}
.ctrl-select:focus, .ctrl-input:focus { border-color: var(--blue); }
.ctrl-input { min-width: 180px; }

.btn-primary {
    height: 36px; padding: 0 18px;
    background: var(--blue); color: #fff;
    border: none; border-radius: var(--radius);
    font-size: 13px; font-weight: 500;
    cursor: pointer; display: flex; align-items: center; gap: 6px;
    transition: background 0.15s;
    white-space: nowrap;
}
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

/* ─── Content grid ──────────────────────────────────────────────────────── */
.content-grid {
    display: grid;
    grid-template-columns: 1fr 360px;
    flex: 1; overflow: hidden;
}

/* ─── Mapa ──────────────────────────────────────────────────────────────── */
.map-container {
    position: relative;
    border-right: 0.5px solid var(--border);
    background: #d4e9f7;
}
.map-warning {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    background: rgba(255,255,255,0.96);
    border: 1px solid rgba(229, 115, 115, 0.45);
    border-left: 4px solid var(--alto);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    font-size: 12px;
}
.map-warning strong { color: var(--alto-text); }
.map-warning span { color: var(--muted); }
.map-legend {
    position: absolute; bottom: 20px; left: 16px;
    background: rgba(255,255,255,0.95);
    border: 0.5px solid var(--border);
    border-radius: var(--radius); padding: 10px 14px;
    z-index: 1000; backdrop-filter: blur(4px);
}
.legend-title { font-size: 11px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 5px; }
.legend-row:last-child { margin-bottom: 0; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.dot.alto  { background: var(--alto); }
.dot.medio { background: var(--medio); }
.dot.bajo  { background: var(--bajo); }

/* Estilos heredados del mapa */
.zona-marker {
    background: rgba(255,255,255,0.92);
    border: 1.5px solid currentColor;
    border-radius: 6px; padding: 3px 7px;
    text-align: center; white-space: nowrap;
    backdrop-filter: blur(2px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    min-width: 70px;
}
.zona-marker.nivel-alto  { color: var(--alto);  border-color: var(--alto); }
.zona-marker.nivel-medio { color: var(--medio); border-color: var(--medio); }
.zona-marker.nivel-bajo  { color: var(--bajo);  border-color: var(--bajo); }
.zm-pct   { font-size: 13px; font-weight: 700; }
.zm-nombre { font-size: 10px; font-weight: 400; color: #444; margin-top: 1px; }

.popup-content { padding: 14px; min-width: 220px; }
.popup-google { min-width: 240px; }

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
    display: flex; flex-direction: column;
    background: var(--surface); overflow: hidden;
}

.tab-bar {
    display: flex; border-bottom: 0.5px solid var(--border);
    flex-shrink: 0;
}
.tab {
    flex: 1; padding: 10px 6px; font-size: 12px; text-align: center;
    cursor: pointer; color: var(--muted);
    border: none; background: none;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 500; }

.panel {
    flex: 1; overflow-y: auto; padding: 12px;
    display: flex; flex-direction: column; gap: 8px;
}

/* ─── Zona card ─────────────────────────────────────────────────────────── */
.zona-card {
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg); padding: 10px 12px;
    cursor: pointer; transition: background 0.12s, border-color 0.12s;
    background: var(--surface);
}
.zona-card:hover { background: #f9fafb; border-color: rgba(0,0,0,0.18); }
.zona-card.selected { border-color: var(--blue); background: #EBF4FF; }

.zona-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.zona-nombre { font-size: 13px; font-weight: 500; color: var(--text); }

.badge { font-size: 11px; padding: 2px 9px; border-radius: 20px; font-weight: 500; }
.badge-alto  { background: var(--alto-bg);  color: var(--alto-text); }
.badge-medio { background: var(--medio-bg); color: var(--medio-text); }
.badge-bajo  { background: var(--bajo-bg);  color: var(--bajo-text); }

.progress-bar { height: 5px; background: #eee; border-radius: 3px; margin: 6px 0; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; transition: width 0.6s ease; }

.zona-meta { font-size: 11px; color: var(--muted); line-height: 1.5; }
.zona-resumen {
    margin-top: 8px; padding: 8px; background: #f8f9fa;
    border-radius: var(--radius); font-size: 12px; color: #444;
    line-height: 1.6; border-left: 3px solid var(--blue);
}

/* ─── Noticia card ──────────────────────────────────────────────────────── */
.noticia-card {
    border-left: 3px solid var(--border);
    padding: 8px 10px; border-radius: 0 var(--radius) var(--radius) 0;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-left-width: 3px;
}
.noticia-card.nivel-alto  { border-left-color: var(--alto); }
.noticia-card.nivel-medio { border-left-color: var(--medio); }
.noticia-card.nivel-bajo  { border-left-color: var(--bajo); }

.noticia-fuente {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 11px; color: var(--muted); margin-bottom: 4px;
}
.tag-fuente {
    font-size: 10px; padding: 1px 6px;
    background: #f1f3f5; border-radius: 4px; color: var(--muted);
}
.noticia-titulo { font-size: 12px; font-weight: 500; color: var(--text); line-height: 1.4; margin-bottom: 3px; }
.noticia-desc   { font-size: 11px; color: var(--muted); line-height: 1.5; margin-bottom: 3px; }
.noticia-tiempo { font-size: 10px; color: #9ca3af; }

/* ─── Estadísticas ──────────────────────────────────────────────────────── */
.stats-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px;
}
.stat-card {
    background: #f8f9fa; border-radius: var(--radius);
    padding: 12px; text-align: center;
    border: 0.5px solid var(--border);
}
.stat-num       { font-size: 26px; font-weight: 600; color: var(--text); line-height: 1; }
.stat-num.alto  { color: var(--alto); }
.stat-num.medio { color: var(--medio); }
.stat-num.bajo  { color: var(--bajo); }
.stat-lbl       { font-size: 11px; color: var(--muted); margin-top: 4px; }

.analisis-box {
    background: #f0f6ff; border: 0.5px solid #B5D4F4;
    border-radius: var(--radius); padding: 12px; margin-bottom: 12px;
}
.analisis-label { font-size: 11px; font-weight: 500; color: var(--blue); margin-bottom: 6px; }
.analisis-texto { font-size: 12px; color: #374151; line-height: 1.6; }

.fuentes-label  { font-size: 11px; font-weight: 500; color: var(--muted); margin-bottom: 8px; }
.fuente-chip {
    display: inline-block; font-size: 11px;
    background: #f1f3f5; color: var(--blue);
    padding: 3px 10px; border-radius: 20px;
    margin: 3px 3px 0 0; border: 0.5px solid #B5D4F4;
}

/* ─── AI status bar ─────────────────────────────────────────────────────── */
.ai-status-bar {
    display: flex; align-items: center; gap: 7px;
    padding: 8px 14px; font-size: 11px; color: var(--muted);
    border-top: 0.5px solid var(--border);
    background: #fafafa; flex-shrink: 0;
}
.status-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--bajo); flex-shrink: 0;
}
.status-dot.pulsing {
    background: var(--medio);
    animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.4; transform: scale(0.85); }
}

/* ─── Estados vacío / carga ─────────────────────────────────────────────── */
.empty-state, .loading-state {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 40px; text-align: center; color: var(--muted);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h2 { font-size: 18px; font-weight: 500; color: var(--text); margin-bottom: 8px; }
.empty-state p  { font-size: 13px; max-width: 400px; line-height: 1.6; }

.loading-ring {
    width: 44px; height: 44px;
    border: 3px solid #e5e7eb;
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state p { font-size: 13px; }

/* ─── Spinner en botón ──────────────────────────────────────────────────── */
.spinner {
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

/* ─── Leaflet overrides ─────────────────────────────────────────────────── */
.leaflet-container { font-family: inherit; }
.leaflet-popup-content-wrapper {
    border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}
.leaflet-popup-tip { background: #fff; }

/* ─── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .content-grid { grid-template-columns: 1fr; grid-template-rows: 50vh 1fr; }
    .portal-toolbar { gap: 6px; }
    .ctrl-select, .ctrl-input { min-width: 120px; }
}
