/* ============================================================
   Dashboard sísmico — tema oscuro
   ============================================================ */
:root {
  --bg: #0b0f1a;
  --bg-panel: #121829;
  --bg-card: #171f33;
  --line: #26304d;
  --text: #e8ecf6;
  --muted: #93a0bd;
  --accent: #ffb020;
  --danger: #ff4d4f;
  --ok: #38d996;
  --info: #4da3ff;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
}

/* ---------------- header ---------------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 26px;
  background: linear-gradient(135deg, #10162a 0%, #1a1030 60%, #2a1020 100%);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; gap: 14px; align-items: center; min-width: 300px; }

.brand-icon {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  font-size: 26px;
  color: #1a0d00;
  background: radial-gradient(circle at 30% 30%, #ffd262, #ff7a1a 70%);
  border-radius: 50%;
  box-shadow: 0 0 24px rgba(255, 140, 30, .45);
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 18px rgba(255,140,30,.35); }
  50%      { box-shadow: 0 0 34px rgba(255,140,30,.65); }
}

.brand h1 { margin: 0; font-size: 21px; letter-spacing: .2px; }
.subtitle { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }

.kpis { display: flex; gap: 10px; flex-wrap: wrap; }

.kpi {
  min-width: 128px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.kpi-value { font-size: 21px; font-weight: 700; color: var(--accent); }
.kpi-label { font-size: 10.5px; color: var(--muted); line-height: 1.3; }

/* ---------------- disclaimer ---------------- */
.disclaimer {
  margin: 12px 26px 0;
  padding: 12px 16px;
  background: rgba(255, 77, 79, .08);
  border: 1px solid rgba(255, 77, 79, .4);
  border-left: 4px solid var(--danger);
  border-radius: 10px;
  color: #ffd9d9;
  font-size: 13px;
  line-height: 1.55;
}

/* ---------------- tabs ---------------- */
.tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 14px 26px 0;
}

.tab {
  background: var(--bg-panel);
  color: var(--muted);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  padding: 10px 18px;
  font-size: 13.5px;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: inset 0 2px 0 var(--accent);
  font-weight: 600;
}

/* ---------------- panels ---------------- */
main { padding: 0 26px 30px; }

.panel { display: none; padding-top: 18px; animation: fadein .25s ease; }
.panel.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

h2 { margin: 6px 0 6px; font-size: 19px; }
h3.sub { margin: 26px 0 6px; font-size: 16px; color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 14px; max-width: 1000px; line-height: 1.5; }

/* ---------------- mapa ---------------- */
.map-layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 14px;
  min-height: 640px;
}
@media (max-width: 980px) { .map-layout { grid-template-columns: 1fr; } }

.map-side {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
  overflow: hidden;
}
.map-side h2 { font-size: 15px; margin: 0; }

.layer-controls { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.layer-controls label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.layer-controls input { accent-color: var(--accent); }

.time-filter { border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; }
.time-filter label { display: block; margin-bottom: 6px; color: var(--muted); }
.time-filter output { color: var(--accent); font-weight: 600; }
#time-range { width: 100%; accent-color: var(--accent); }
.time-hint { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.4; }

.event-feed {
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  max-height: 380px;
}
.feed-item {
  display: flex; gap: 10px; align-items: center;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s;
}
.feed-item:hover { background: rgba(255,255,255,.05); }
.feed-mag {
  min-width: 46px; text-align: center;
  font-weight: 700; font-size: 13px;
  padding: 3px 4px; border-radius: 6px;
  background: rgba(255,255,255,.08);
}
.feed-mag.big { color: #fff; }
.feed-body { font-size: 11.5px; line-height: 1.35; color: var(--muted); }
.feed-body strong { color: var(--text); display: block; font-size: 12px; }

.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
#map { height: 640px; width: 100%; background: #0a0e18; }
@media (max-width: 980px) { #map { height: 480px; } }

.map-legend {
  position: absolute;
  right: 12px; top: 12px;
  z-index: 500;
  background: rgba(11, 15, 26, .88);
  backdrop-filter: blur(4px);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 11px;
  color: var(--muted);
  max-width: 230px;
}
.map-legend h4 { margin: 0 0 6px; font-size: 11.5px; color: var(--text); }
.map-legend .lg-row { display: flex; align-items: center; gap: 7px; margin: 3px 0; }
.lg-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------------- etiquetas de probabilidad sobre el mapa ---------------- */
.leaflet-marker-icon.prob-wrap { background: none; border: none; }

.prob-badge {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transform: translate(-50%, -50%);
  background: rgba(11, 15, 26, .88);
  backdrop-filter: blur(4px);
  border: 1.5px solid;
  border-radius: 10px;
  padding: 5px 9px;
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
  font-family: "Segoe UI", system-ui, sans-serif;
  box-shadow: 0 3px 14px rgba(0,0,0,.55);
  transition: transform .12s ease, box-shadow .12s ease;
}
.prob-badge:hover {
  transform: translate(-50%, -50%) scale(1.08);
  box-shadow: 0 5px 22px rgba(0,0,0,.75);
  z-index: 9999;
}
.prob-badge .pb-name {
  font-size: 10.5px; font-weight: 700; color: var(--text);
  letter-spacing: .3px; text-transform: uppercase;
}
.prob-badge .pb-main {
  font-size: 17px; font-weight: 800; line-height: 1.05;
}
.prob-badge .pb-sub {
  font-size: 9.5px; color: var(--muted); line-height: 1.25;
}
.prob-badge.hot  { border-color: var(--danger); }
.prob-badge.hot  .pb-main { color: #ff8f90; }
.prob-badge.mid  { border-color: var(--accent); }
.prob-badge.mid  .pb-main { color: var(--accent); }
.prob-badge.low  { border-color: #4da3ff; }
.prob-badge.low  .pb-main { color: #7db8ff; }
.prob-badge .pb-pin {
  width: 7px; height: 7px; border-radius: 50%;
  border: 1.5px solid rgba(11,15,26,.9);
  transform: translateY(4px);
}
.prob-badge.hot .pb-pin { background: var(--danger); }
.prob-badge.mid .pb-pin { background: var(--accent); }
.prob-badge.low .pb-pin { background: #4da3ff; }

/* tabla de probabilidad dentro de popups */
.prob-table { width: 100%; border-collapse: collapse; margin: 6px 0 2px; }
.prob-table th, .prob-table td {
  font-size: 11px; padding: 3px 6px; text-align: center;
  border: 1px solid var(--line);
}
.prob-table th { color: var(--muted); font-weight: 600; background: rgba(255,255,255,.04); }
.prob-table td { color: var(--text); font-weight: 700; }
.prob-table td.hot  { color: #ff8f90; }
.prob-table td.mid  { color: var(--accent); }
.prob-table td.low  { color: #7db8ff; }

/* etiqueta de probabilidad en el feed */
.feed-prob {
  display: inline-block; margin-left: 5px; padding: 1px 6px;
  border-radius: 8px; font-size: 9.5px; font-weight: 700;
  background: rgba(255,176,32,.14); color: var(--accent);
}
.feed-prob.hot { background: rgba(255,77,79,.16); color: #ff9a9b; }

/* leaflet dark popups */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.leaflet-popup-content { margin: 12px 14px; font-size: 12.5px; line-height: 1.45; }
.leaflet-popup-content b { color: var(--accent); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-control-attribution { background: rgba(11,15,26,.75) !important; color: var(--muted) !important; font-size: 9.5px !important; }
.leaflet-control-attribution a { color: var(--info) !important; }

/* ---------------- chips segmentos ---------------- */
.seg-chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 10px 0 16px; }
.seg-chip {
  border: 1px solid var(--line);
  background: var(--bg-panel);
  color: var(--muted);
  border-radius: 20px;
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all .15s;
}
.seg-chip .swatch { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.seg-chip.active { color: var(--text); border-color: var(--accent); background: rgba(255,176,32,.12); font-weight: 600; }
.seg-chip:hover { color: var(--text); }

/* ---------------- cards / charts ---------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(430px, 1fr));
  gap: 14px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card h3 { margin: 0 0 10px; font-size: 14.5px; color: var(--text); }
.card.wide { grid-column: 1 / -1; }
.card canvas { max-height: 320px; }
.card-foot { color: var(--muted); font-size: 11.5px; line-height: 1.5; margin: 10px 0 0; }

.method-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 14px; }
ul.method { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.6; }
ul.method strong { color: var(--text); }
ul.method code { background: rgba(255,255,255,.07); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---------------- watchlist ---------------- */
.watchlist { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-bottom: 20px; }
.watch-card {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  background: linear-gradient(135deg, var(--bg-card), rgba(255,176,32,.05));
  padding: 14px 16px;
}
.watch-card.heat { border-left-color: var(--danger); }
.watch-card h4 { margin: 0 0 4px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.watch-card .swatch { width: 10px; height: 10px; border-radius: 50%; }
.watch-card p { margin: 4px 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.watch-why { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .3px; padding: 2px 8px; border-radius: 10px; margin-right: 5px; }
.watch-why.hot { background: rgba(255,77,79,.15); color: #ff9a9b; }
.watch-why.warn { background: rgba(255,176,32,.15); color: var(--accent); }

/* ---------------- table ---------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-card); }
table.risk { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 960px; }
table.risk th, table.risk td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.risk th { background: var(--bg-panel); color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; position: sticky; top: 0; }
table.risk th.sortable { cursor: pointer; user-select: none; }
table.risk th.sortable:hover { color: var(--text); }
table.risk th.sorted-asc::after { content: " ▲"; color: var(--accent); }
table.risk th.sorted-desc::after { content: " ▼"; color: var(--accent); }
table.risk td.num, table.risk th.num { text-align: right; }
table.risk tbody tr { cursor: pointer; transition: background .12s; }
table.risk tbody tr:hover { background: rgba(255,255,255,.045); }
tbody tr.ring-row td:first-child { border-left: 3px solid var(--accent); }

.seg-name { display: flex; align-items: center; gap: 8px; }
.seg-name .swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.pill { padding: 2px 8px; border-radius: 10px; font-weight: 700; font-size: 11px; }
.pill.hot  { background: rgba(255,77,79,.16); color: #ff8f90; }
.pill.mid  { background: rgba(255,176,32,.16); color: var(--accent); }
.pill.low  { background: rgba(77,163,255,.14); color: #7db8ff; }
.pill.calm { background: rgba(56,217,150,.13); color: #6fe3b2; }

/* ---------------- ventanas historicas ---------------- */
.windows { display: flex; flex-direction: column; gap: 10px; }
.win-card { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.win-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer; user-select: none;
}
.win-head:hover { background: rgba(255,255,255,.03); }
.win-head .date { font-weight: 700; font-size: 14px; }
.win-head .count { color: var(--accent); font-weight: 700; }
.win-body { display: none; border-top: 1px dashed var(--line); padding: 10px 16px 14px; }
.win-card.open .win-body { display: block; }
.win-ev { display: flex; gap: 10px; font-size: 12.5px; padding: 4px 0; color: var(--muted); }
.win-ev .m { min-width: 44px; font-weight: 700; color: var(--text); }
.win-card.current { border-color: var(--danger); }
.win-card.current .win-head { background: rgba(255,77,79,.07); }

/* ---------------- footer ---------------- */
footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  padding: 14px 26px;
  line-height: 1.6;
}
.foot-gen { color: var(--muted); font-size: 11.5px; margin-top: 14px; }

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }
