:root {
  --bg: #edf1f4;
  --bg-soft: #f6f8fa;
  --card: #ffffff;
  --card-soft: #f8fafb;
  --line: #d7dde3;
  --line-soft: #e7edf2;

  --text: #1f2a33;
  --text-soft: #586673;
  --muted: #7f8b96;

  --primary: #0b7c70;
  --primary-2: #09695f;
  --accent: #18a38d;

  --danger: #d65c5c;
  --warning: #f2a33a;
  --ok: #43a047;

  --shadow-sm: 0 4px 10px rgba(31, 42, 51, 0.05);
  --shadow-md: 0 10px 24px rgba(31, 42, 51, 0.08);

  --radius-xl: 20px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;

  --topbar-h: 82px;
  --bottom-h: 230px;

  --font: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(11, 124, 112, 0.06), transparent 28%),
    linear-gradient(180deg, #f7f9fb 0%, #eceff2 100%);
}

body {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

/* =========================
   APP PRINCIPAL
   ========================= */

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: var(--topbar-h) auto minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
}

/* =========================
   TOPBAR
   ========================= */

.topbar,
header.topbar {
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-radius: var(--radius-xl);
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  color: #fff;
  box-shadow: var(--shadow-md);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo,
.brand-mini {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 12px;
  font-weight: 800;
  font-size: 17px;
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.brand h1,
.topbar-left h1 {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin-bottom: 2px;
}

.brand p,
.topbar-left p {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.9);
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.pill,
.user-badge {
  min-height: 34px;
  padding: 7px 14px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 0.86rem;
  font-weight: 700;
  color: #fff;
  background: rgba(255, 255, 255, 0.13);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.topbar-action,
.btn-secondary,
#changePasswordBtn,
#logoutBtn {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 700;
  transition: 0.2s ease;
}

.topbar-action:hover,
.btn-secondary:hover,
#changePasswordBtn:hover,
#logoutBtn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.22);
}

/* =========================
   FILTROS
   ========================= */

.filters,
section.filters {
  display: grid;
  grid-template-columns: 1.3fr repeat(5, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 12px 14px;
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow-sm);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.field input,
.field select,
.filters input,
.filters select,
.sidebar-block select,
.estado-select {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  outline: none;
  transition: 0.18s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.field input::placeholder {
  color: #98a3ad;
}

.field input:focus,
.field select:focus,
.filters input:focus,
.filters select:focus,
.sidebar-block select:focus,
.estado-select:focus {
  border-color: rgba(11, 124, 112, 0.48);
  box-shadow: 0 0 0 4px rgba(11, 124, 112, 0.10);
}

/* =========================
   BOTONES
   ========================= */

.btn,
.btn-primary,
#btnAplicarFiltros,
#btnExportarCSV,
#btnVistaMapa,
#btnVistaListado,
#btnLimpiarFiltros,
#btnMapaBase,
#btnMapaSatelital,
.btn-ver-mapa {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 800;
  transition: 0.2s ease;
}

.btn,
.btn-primary,
#btnAplicarFiltros,
#btnExportarCSV,
#btnVistaMapa,
.btn-ver-mapa {
  background: linear-gradient(180deg, var(--accent), var(--primary));
  color: #fff;
  box-shadow: 0 8px 16px rgba(11, 124, 112, 0.16);
}

.btn-secondary,
#btnLimpiarFiltros,
#btnVistaListado,
#btnMapaBase,
#btnMapaSatelital {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
  box-shadow: none;
}

.btn:hover,
.btn-primary:hover,
#btnAplicarFiltros:hover,
#btnExportarCSV:hover,
#btnVistaMapa:hover,
#btnVistaListado:hover,
#btnLimpiarFiltros:hover,
#btnMapaBase:hover,
#btnMapaSatelital:hover,
.btn-ver-mapa:hover {
  transform: translateY(-1px);
}

.layer-btn.active,
.active-view-btn,
#btnVistaMapa.active-view-btn,
#btnVistaListado.active-view-btn {
  background: linear-gradient(180deg, var(--accent), var(--primary)) !important;
  color: #fff !important;
  border-color: transparent !important;
  box-shadow: 0 8px 16px rgba(11, 124, 112, 0.16) !important;
}

/* =========================
   MAIN NUEVO
   ========================= */

.main {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 250px;
  gap: 10px;
  align-items: stretch;
}

.panel,
.map-card,
.bottom-card {
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.90);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: var(--shadow-sm);
}

.panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.panel-header,
.map-header,
.bottom-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(255,255,255,0.88), rgba(246,248,250,0.78));
}

.panel-header h3,
.map-header h3,
.bottom-header h3,
.titulo-seccion {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
}

.panel-body,
.detail-body {
  padding: 12px;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(127,139,150,0.45) transparent;
}

.panel-body::-webkit-scrollbar,
.detail-body::-webkit-scrollbar,
.table-wrapper::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.panel-body::-webkit-scrollbar-thumb,
.detail-body::-webkit-scrollbar-thumb,
.table-wrapper::-webkit-scrollbar-thumb {
  background: rgba(127,139,150,0.42);
  border-radius: 999px;
}

.kpis,
.sidebar-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.kpi,
.sidebar-stat,
.ranking-item,
.activity-item,
.detail-card {
  padding: 12px;
  border-radius: 16px;
  background: linear-gradient(180deg, #ffffff 0%, #f7f9fb 100%);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.85);
}

.kpi .value,
.sidebar-stat strong {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  margin-bottom: 6px;
}

.kpi .label,
.sidebar-stat span,
.meta {
  font-size: 0.78rem;
  color: var(--text-soft);
}

.section-title {
  margin: 14px 0 8px;
  font-size: 0.77rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* =========================
   BADGES / ESTADOS
   ========================= */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

.critical {
  background: #fde9e9;
  color: #b94d4d;
  border-color: #f2c4c4;
}

.high {
  background: #fff1dd;
  color: #b97717;
  border-color: #f1d39d;
}

.medium {
  background: #fff7d9;
  color: #9f7c00;
  border-color: #eee0a5;
}

.low {
  background: #e7f6ea;
  color: #2f8534;
  border-color: #c4e5c7;
}

/* =========================
   MAPA
   ========================= */

.map-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

.layer-btns,
.map-base-switch,
.view-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.layer-btn {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text-soft);
  font-size: 0.82rem;
  font-weight: 700;
}

.map-area {
  position: relative;
  min-height: 0;
  height: 100%;
  display: flex;
}

#map,
#mapAdmin {
  width: 100%;
  height: 100%;
  min-height: 100%;
  flex: 1;
}

#mapAdmin {
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.map-overlay-label,
.map-legend {
  position: absolute;
  z-index: 600;
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
}

.map-overlay-label {
  top: 12px;
  left: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
}

.map-legend {
  left: 12px;
  bottom: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 0.8rem;
  color: var(--text);
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-row + .legend-row {
  margin-top: 6px;
}

.legend-color {
  width: 13px;
  height: 13px;
  border-radius: 4px;
}

/* =========================
   TABLA INFERIOR
   ========================= */

.bottom-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.table-wrapper {
  min-height: 0;
  overflow: auto;
  background: #fff;
}

table,
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td,
.data-table th,
.data-table td {
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid #edf1f4;
}

th,
.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f9fb;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td,
.data-table td {
  background: rgba(255,255,255,0.9);
  color: var(--text);
}

/* =========================
   SELECT ESTADO
   ========================= */

.estado-select {
  min-width: 140px;
  height: 38px;
  font-weight: 700;
}

.estado-pendiente {
  background: #fdeaea !important;
  color: #b94d4d !important;
  border-color: #efc0c0 !important;
}

.estado-en-proceso {
  background: #fff4e1 !important;
  color: #b97717 !important;
  border-color: #efd09a !important;
}

.estado-resuelto {
  background: #e7f6ea !important;
  color: #2f8534 !important;
  border-color: #c1e0c4 !important;
}

.sin-punto {
  color: var(--muted);
}

/* =========================
   DETALLE DERECHO
   ========================= */

.detail-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-list {
  display: grid;
  gap: 8px;
  font-size: 0.88rem;
}

.detail-list > div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed #e1e8ee;
}

.detail-list > div:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.detail-list span {
  color: var(--text-soft);
}

.detail-list strong {
  color: var(--text);
  text-align: right;
}

/* =========================
   ADMIN ANTIGUO
   ========================= */

.admin-shell {
  min-height: calc(100vh - 106px);
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.admin-sidebar,
.admin-main {
  background: rgba(255,255,255,0.9);
  border: 1px solid rgba(255,255,255,0.75);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-xl);
}

.admin-sidebar {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-block {
  padding: 12px;
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #f7f9fb 100%);
  border: 1px solid var(--line);
}

.sidebar-block h3 {
  margin-bottom: 10px;
  font-size: 1rem;
  font-weight: 800;
}

.sidebar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.map-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  font-size: 0.88rem;
  color: var(--text-soft);
}

.map-toggle input {
  accent-color: var(--primary);
}

.admin-main {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.admin-view {
  display: none;
  padding: 14px;
  height: 100%;
  min-height: 0;
}

.admin-view.active {
  display: block;
}

.map-toolbar,
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.map-toolbar h2,
.list-toolbar h2 {
  font-size: 1.35rem;
  font-weight: 800;
}

/* =========================
   LEAFLET
   ========================= */

.leaflet-container {
  font: inherit;
  background: #dde4e8;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: rgba(255,255,255,0.96);
  color: var(--text);
}

.leaflet-popup-content {
  margin: 12px 14px;
  line-height: 1.45;
}

.leaflet-control-zoom a {
  background: rgba(255,255,255,0.95) !important;
  color: var(--text) !important;
  border-bottom-color: #e7edf1 !important;
}

.leaflet-bar {
  border: 1px solid #d8e0e7 !important;
  box-shadow: var(--shadow-sm) !important;
}

.leaflet-top.leaflet-left {
  top: 8px;
}

.leaflet-control-attribution {
  background: rgba(255,255,255,0.82) !important;
  color: var(--text-soft) !important;
  border-radius: 8px 0 0 0;
}

/* =========================
   UTILIDADES
   ========================= */

.zona-critica-clickable {
  cursor: pointer;
}

.zona-critica-clickable:hover,
.ranking-item:hover,
.activity-item:hover,
.detail-card:hover,
.sidebar-block:hover,
.kpi:hover,
.sidebar-stat:hover {
  transform: translateY(-1px);
  transition: 0.18s ease;
}

.hidden {
  display: none !important;
}

/* =========================
   RESPONSIVE
   ========================= */

@media (max-width: 1400px) {
  .main {
    grid-template-columns: 250px minmax(0, 1fr) 230px;
  }

  .brand h1,
  .topbar-left h1 {
    font-size: 1.65rem;
  }
}

@media (max-width: 1200px) {
  :root {
    --bottom-h: 300px;
  }

  body {
    overflow: auto;
  }

.app {
  height: auto;
  min-height: 100vh;
  grid-template-rows: auto auto 1fr;
}

  .filters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .main {
    grid-template-columns: 1fr;
  }

  .panel,
  .map-card,
  .bottom-card {
    min-height: auto;
  }

  .admin-shell {
    grid-template-columns: 1fr;
  }

  #map,
  #mapAdmin {
    min-height: 420px;
  }
}

@media (max-width: 900px) {
  .topbar,
  header.topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 14px;
  }

  .topbar-right {
    justify-content: flex-start;
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpis,
  .sidebar-stats {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  body {
    overflow: auto;
  }

  .app {
    padding: 10px;
    gap: 10px;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .topbar-left {
    align-items: flex-start;
  }

  .brand h1,
  .topbar-left h1 {
    font-size: 1.45rem;
  }

  .brand p,
  .topbar-left p {
    font-size: 0.8rem;
  }

  .topbar-right {
    gap: 8px;
  }

  .pill,
  .user-badge,
  .topbar-action,
  .btn-secondary,
  #changePasswordBtn,
  #logoutBtn {
    width: 100%;
    justify-content: center;
  }

  .kpis,
  .sidebar-stats {
    grid-template-columns: 1fr;
  }

  th,
  td,
  .data-table th,
  .data-table td {
    padding: 10px 8px;
    font-size: 0.8rem;
  }
}

.app-oculta {
  visibility: hidden;
}

.pantalla-carga {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, #12332f 0%, #061517 55%, #031012 100%);
}

.loader-card {
  width: min(360px, calc(100% - 40px));
  padding: 34px;
  border-radius: 24px;
  text-align: center;
  background: rgba(15, 35, 39, 0.92);
  border: 1px solid rgba(255,255,255,0.12);
  color: #f8fafc;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}

.loader-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: #0b7c70;
  font-weight: 900;
  font-size: 22px;
}

.loader-card strong {
  display: block;
  font-size: 26px;
  margin-bottom: 6px;
}

.loader-card span {
  color: #bdd6d1;
}
