:root {
  --navy: #0b1f33;
  --navy-2: #123049;
  --agua: #0284c7;
  --agua-soft: #e0f2fe;
  --agua-deep: #0369a1;
  --esgoto: #059669;
  --esgoto-soft: #d1fae5;
  --esgoto-deep: #047857;
  --alert: #dc2626;
  --alert-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --radius: 16px;
}

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

html, body {
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
}

body { padding-bottom: 48px; }

.topbar {
  background: linear-gradient(135deg, #071525 0%, #123049 55%, #0b3a5c 100%);
  color: #fff;
  padding: 22px 28px 20px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 8px 24px rgba(7, 21, 37, 0.28);
}

.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
}

.brand-kicker {
  font-size: 11px;
  letter-spacing: 2.2px;
  text-transform: uppercase;
  color: #7dd3fc;
  font-weight: 700;
  margin-bottom: 4px;
}

.brand h1 {
  font-family: Outfit, DM Sans, sans-serif;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.4px;
}

.brand p { color: #cbd5e1; font-size: 13px; margin-top: 4px; }

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

.pill {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  color: #e2e8f0;
}

.pill strong { color: #fff; }

.wrap {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 20px 0;
}

.filters {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1.3fr repeat(7, minmax(110px, 1fr));
  gap: 10px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.filters label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.filters input, .filters select {
  width: 100%;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 10px;
  padding: 9px 10px;
  font: inherit;
  color: var(--ink);
  outline: none;
}

.filters input:focus, .filters select:focus {
  border-color: #7dd3fc;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(14,165,233,0.15);
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
}

.kpi-panel {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.kpi-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  color: #fff;
}

.kpi-head.agua { background: linear-gradient(90deg, #0369a1, #0ea5e9); }
.kpi-head.esgoto { background: linear-gradient(90deg, #047857, #10b981); }

.kpi-head h2 { font-size: 15px; font-weight: 700; letter-spacing: 0.6px; }
.kpi-head span { font-size: 12px; opacity: 0.9; }

.kpi-body {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
}

.kpi-item {
  padding: 16px 14px 18px;
  border-right: 1px solid var(--line);
}

.kpi-item:last-child { border-right: none; }

.kpi-item .lbl {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.kpi-item .val {
  font-family: Outfit, DM Sans, sans-serif;
  font-size: 22px;
  font-weight: 700;
  margin: 6px 0 4px;
  letter-spacing: -0.5px;
}

.kpi-item .sub { font-size: 12px; color: var(--muted); }

.neg { color: var(--alert); }
.pos { color: var(--ok); }

.progress {
  height: 7px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
  margin-top: 10px;
}

.progress > i {
  display: block;
  height: 100%;
  border-radius: 99px;
}

.charts {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.charts-3 {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 12px;
  min-height: 360px;
}

.card h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}

.card .hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; }

.chart-box { position: relative; height: 250px; }
.chart-box.tall { height: 340px; }
.chart-box.extra { height: 380px; }
.chart-box.lib { height: 430px; }

.native-chart {
  height: 100%;
  overflow: auto;
  font-size: 12px;
  display: flex;
  flex-direction: column;
}

.chart-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.ckpi {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  min-width: 0;
}

.ckpi span {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.ckpi b {
  display: block;
  font-family: Outfit, DM Sans, sans-serif;
  font-size: 13px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ckpi.ok b { color: var(--ok); }
.ckpi.warn b { color: var(--warn); }
.ckpi.bad b { color: var(--alert); }

.chart-legend-inline {
  display: flex;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 8px;
}

.hbar {
  display: grid;
  grid-template-columns: 118px 1fr 86px;
  gap: 8px;
  align-items: center;
  margin-bottom: 7px;
}

.hbar.rank { grid-template-columns: 118px 1fr 118px; }

.swatch {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 99px;
  margin-right: 6px;
  vertical-align: middle;
}

.hbar b { font-weight: 600; color: #334155; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar em { font-style: normal; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

.hbar-track, .hbar-duo {
  height: 8px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}

.hbar-duo { height: 16px; background: #f1f5f9; }

.hbar-track i, .hbar-duo i {
  display: block;
  height: 100%;
  border-radius: 99px;
}

.hbar-duo i.prev { position: absolute; inset: 2px auto 2px 0; height: auto; background: #cbd5e1; }
.hbar-duo i.real { position: absolute; inset: 5px auto 5px 0; height: auto; }

.vbars {
  display: flex;
  align-items: stretch;
  gap: 8px;
  height: 100%;
  padding-top: 4px;
}

.vbar {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.vbar-track {
  flex: 1;
  background: #eef2f7;
  border-radius: 8px 8px 4px 4px;
  position: relative;
  overflow: hidden;
}

.vbar-track i {
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 0;
  border-radius: 6px 6px 0 0;
}

.vbar span {
  display: block;
  text-align: center;
  margin-top: 6px;
  color: #64748b;
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.donut-row {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 14px;
  align-items: center;
  height: 100%;
}

.donut {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  margin: 0 auto;
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 28px;
  background: #fff;
  border-radius: 50%;
}

.donut-legend { display: flex; flex-direction: column; gap: 6px; }
.donut-legend div { display: flex; align-items: center; gap: 8px; }
.donut-legend i { width: 8px; height: 8px; border-radius: 99px; flex-shrink: 0; }
.donut-legend b { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend em { font-style: normal; color: var(--muted); }

.city-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  height: 100%;
}

.city-col h4 { font-size: 12px; margin-bottom: 6px; color: #334155; }
.city-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  font-size: 13px;
}
.city-head b { font-family: Outfit, DM Sans, sans-serif; font-size: 18px; }
.city-meter { margin-bottom: 12px; }
.city-meter span { display: flex; justify-content: space-between; margin-bottom: 4px; color: #64748b; }
.city-meter .hbar-track, .city-meter .hbar-duo { height: 12px; }

.native-chart svg {
  width: 100%;
  flex: 1;
  min-height: 170px;
  display: block;
}

.lib-layout {
  display: grid;
  grid-template-columns: 168px 1fr;
  gap: 14px;
  align-items: center;
  flex: 1;
  min-height: 0;
}

.lib-donut {
  position: relative;
  width: 168px;
  height: 168px;
  margin: 0 auto;
}

.lib-donut svg {
  width: 168px;
  height: 168px;
  min-height: 0;
  flex: none;
}

.lib-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.lib-center b {
  font-family: Outfit, DM Sans, sans-serif;
  font-size: 22px;
  letter-spacing: -0.4px;
  color: var(--ink);
}

.lib-center span {
  font-size: 10px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.lib-rank { min-width: 0; }

.hbar.lib {
  grid-template-columns: 148px 1fr 92px;
  margin-bottom: 8px;
}

.hbar.lib b small {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hbar.lib .hbar-track { height: 10px; }

.bottom-grid {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.insights {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}

.insights h3 { font-size: 14px; margin-bottom: 12px; }

.insight {
  border-left: 4px solid #94a3b8;
  background: #f8fafc;
  border-radius: 0 12px 12px 0;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.insight.bad { border-color: var(--alert); background: var(--alert-soft); }
.insight.warn { border-color: var(--warn); background: var(--warn-soft); }
.insight.good { border-color: var(--ok); background: var(--ok-soft); }
.insight.info { border-color: var(--agua); background: var(--agua-soft); }

.insight b { display: block; font-size: 13px; margin-bottom: 2px; }
.insight p { font-size: 12.5px; color: #334155; line-height: 1.45; }

.table-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.tabs { display: flex; gap: 6px; }

.tab, .btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  color: #334155;
}

.tab.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.search {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  min-width: 240px;
  font: inherit;
  background: #f8fafc;
}

.table-wrap { overflow: auto; max-height: 520px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}

th:hover { color: var(--ink); }

td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}

tr:hover td { background: #f8fafc; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
}

.badge.agua { background: var(--agua-soft); color: var(--agua-deep); }
.badge.esgoto { background: var(--esgoto-soft); color: var(--esgoto-deep); }
.badge.ok { background: var(--ok-soft); color: #166534; }
.badge.run { background: #dbeafe; color: #1d4ed8; }
.badge.off { background: #f1f5f9; color: #64748b; }

.bar-mini {
  width: 92px;
  height: 6px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
}

.bar-mini i { display: block; height: 100%; background: var(--agua); }

.legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.dot { width: 8px; height: 8px; border-radius: 99px; display: inline-block; margin-right: 5px; }

.empty {
  text-align: center;
  padding: 28px;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .kpi-grid, .charts, .charts-3, .bottom-grid { grid-template-columns: 1fr; }
  .kpi-body { grid-template-columns: 1fr 1fr; }
  .kpi-item { border-bottom: 1px solid var(--line); }
  .chart-box.tall, .chart-box.extra { height: 320px; }
  .lib-layout { grid-template-columns: 1fr; }
}
