:root {
  --bg: #0e1117;
  --panel: #161b22;
  --panel2: #1c2330;
  --border: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #e6007e;
  --green: #2ea043;
  --lime: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --gray: #6e7681;
}

html[data-theme="light"] {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel2: #eef1f6;
  --border: #d7dde6;
  --text: #1b2330;
  --muted: #5b6573;
  --green: #1a7f37;
  --lime: #1f9d57;
  --amber: #9a6700;
  --gray: #8b95a1;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand-logo { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; }
.brand h1 { margin: 0; font-size: 18px; }
.brand .sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.theme-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font-size: 18px; cursor: pointer; line-height: 1; }
.theme-btn:hover { background: var(--border); }
.updated { text-align: right; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.badge { background: var(--panel2); border: 1px solid var(--border); border-radius: 12px; padding: 2px 10px; color: var(--lime); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; padding: 16px 22px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 700; }
.kpi .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent .v { color: var(--accent); }

.globalbar { display: flex; align-items: center; gap: 14px; padding: 0 22px 14px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); font-size: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 8px 14px; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.globalbar .hint { color: var(--muted); font-size: 13px; }
.estado-sel { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 6px 12px; }
.estado-sel select { background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 8px; font-size: 14px; }
.panel-note { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.tabs { display: flex; gap: 6px; padding: 0 22px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab { background: none; border: none; color: var(--muted); padding: 12px 16px; cursor: pointer; font-size: 14px; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 16px 22px 40px; }
.panel { display: none; }
.panel.active { display: block; }

#map { height: 72vh; border-radius: 12px; border: 1px solid var(--border); }
.leaflet-popup-content { font-size: 13px; line-height: 1.5; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.legend .it { display: flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; min-width: 220px;
}
.toolbar .count { color: var(--muted); font-size: 13px; }

#grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 3px; max-height: 64vh; overflow: auto; padding: 4px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.cell { aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; font-size: 9px; color: #06080c; border-radius: 3px; cursor: pointer; user-select: none; overflow: hidden; }
.cell:hover { outline: 2px solid var(--text); }
.cell.s-reportando { background: var(--green); }
.cell.s-reciente { background: var(--lime); }
.cell.s-sinreporte { background: var(--amber); }
.cell.s-inactivo { background: var(--gray); color: #c9d1d9; }
.cell.s-tigo { background: #2f81f7; color: #fff; }
.kpi.tigo .v { color: #2f81f7; }

.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 1190; }
.detail {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1200;
  width: 100%; max-width: 560px; margin: 0 auto;
  background: var(--panel2); border-top: 2px solid var(--accent);
  border-radius: 16px 16px 0 0; padding: 18px 18px 26px; font-size: 14px;
  box-shadow: 0 -10px 34px rgba(0,0,0,.55);
  max-height: 75vh; overflow: auto;
}
.detail-close {
  position: absolute; top: 10px; right: 12px; width: 34px; height: 34px;
  border: none; border-radius: 50%; background: var(--panel); color: var(--text);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.detail-close:hover { background: var(--border); }
.detail h3 { margin: 0 40px 12px 0; font-size: 16px; }
.detail .row { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.detail .row:last-child { border-bottom: none; }
.detail .row b { min-width: 120px; color: var(--muted); font-weight: 500; }
@media (min-width: 760px) {
  .detail { bottom: 18px; right: 18px; left: auto; margin: 0; max-width: 420px; border-radius: 14px; border: 1px solid var(--border); border-top: 2px solid var(--accent); }
}
.hidden { display: none; }

.tablewrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--panel); position: sticky; top: 0; cursor: pointer; }
tr:hover td { background: var(--panel2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
