:root {
  --color-primary: #387398;
  --color-secondary: #4C92BE;
  --color-accent: #61CE70;

  --color-bg: #020617;
  --color-panel: #0b1220;
  --color-card: #111827;
  --color-card-soft: #162033;
  --color-border: rgba(148, 163, 184, 0.22);

  --color-text: #e5e7eb;
  --color-muted: #94a3b8;

  --risk-high: #991b1b;
  --risk-medium: #b45309;
  --risk-low: #047857;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: 72px 1fr 58px;
  background:
    radial-gradient(circle at top left, rgba(76, 146, 190, 0.16), transparent 32%),
    var(--color-bg);
}

/* ===============================
   BARRA SUPERIOR
   =============================== */

.topbar {
  background: linear-gradient(90deg, #1f5f82, #4C92BE);
  border-bottom: 1px solid var(--color-border);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar h1 {
  margin: 0;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: #ffffff;
}

.topbar p {
  margin: 4px 0 0;
  font-size: 13px;
  color: #e8f6ff;
}

.status-pill {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.26);
  padding: 8px 13px;
  border-radius: 999px;
  font-size: 12px;
  color: #ffffff;
  backdrop-filter: blur(10px);
}

/* ===============================
   LAYOUT PRINCIPAL
   =============================== */

.main-layout {
  display: grid;
  grid-template-columns: 28% 72%;
  min-height: 0;
}

.sidebar {
  background: linear-gradient(180deg, #0b1220, #070d19);
  border-right: 1px solid var(--color-border);
  padding: 16px;
  overflow-y: auto;
}

.map-panel {
  padding: 12px;
  background: #050a13;
}

#map {
  width: 100%;
  height: 100%;
  border-radius: 22px;
  border: 1px solid var(--color-border);
  overflow: hidden;
  box-shadow: 0 22px 55px rgba(0, 0, 0, 0.42);
}

/* ===============================
   TARJETAS
   =============================== */

.card {
  background: rgba(17, 24, 39, 0.94);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.24);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 15px;
  color: #b9ecff;
  letter-spacing: 0.2px;
}

.result-card {
  min-height: 180px;
}

#resultado {
  font-size: 13px;
  line-height: 1.55;
  color: var(--color-text);
}

/* ===============================
   FORMULARIOS Y BOTONES
   =============================== */

label {
  display: block;
  margin-top: 10px;
  margin-bottom: 5px;
  font-size: 12px;
  color: #cbd5e1;
}

button,
select,
input {
  width: 100%;
  padding: 11px;
  border-radius: 12px;
  border: 1px solid #334155;
  margin-top: 8px;
  background: #020617;
  color: var(--color-text);
  font-size: 14px;
  outline: none;
}

select:focus,
input:focus {
  border-color: var(--color-secondary);
  box-shadow: 0 0 0 3px rgba(76, 146, 190, 0.18);
}

button {
  background: linear-gradient(135deg, var(--color-secondary), var(--color-primary));
  color: white;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: transform 0.15s ease, filter 0.15s ease, background 0.15s ease;
}

button:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button.secondary {
  background: rgba(76, 146, 190, 0.10);
  border: 1px solid rgba(76, 146, 190, 0.55);
  color: #dff4ff;
}

button.secondary:hover {
  background: rgba(76, 146, 190, 0.20);
}

button.danger {
  background: #334155;
  border: 1px solid rgba(148, 163, 184, 0.28);
}

button.danger:hover {
  background: #475569;
}

/* Botones dentro de popups */
.popup-btn {
  width: auto;
  padding: 8px 10px;
  margin-top: 8px;
  border-radius: 10px;
  background: var(--color-secondary);
  color: #ffffff;
  font-size: 12px;
}

/* ===============================
   ALERTAS
   =============================== */

.alerta {
  margin-top: 12px;
  padding: 11px;
  border-radius: 12px;
  font-weight: 800;
  text-align: center;
  font-size: 15px;
  letter-spacing: 0.5px;
}

.rojo {
  background: rgba(153, 27, 27, 0.92);
  color: #fee2e2;
}

.amarillo {
  background: rgba(180, 83, 9, 0.92);
  color: #ffedd5;
}

.verde {
  background: rgba(4, 120, 87, 0.92);
  color: #d1fae5;
}

/* ===============================
   CAPAS PERSONALIZADAS
   =============================== */

.layer-option {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #020617;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 11px;
  margin-top: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.layer-option:hover {
  border-color: var(--color-secondary);
  background: rgba(76, 146, 190, 0.08);
}

.layer-option.active {
  border-color: var(--color-secondary);
  background: rgba(76, 146, 190, 0.13);
}

.layer-option input {
  width: auto;
  margin: 0;
  accent-color: var(--color-secondary);
}

.layer-option input:checked + span {
  color: #b9ecff;
  font-weight: 700;
}

.layer-option span {
  font-size: 13px;
  color: var(--color-text);
}

/* ===============================
   BARRA INFERIOR
   =============================== */

.bottom-panel {
  background: rgba(15, 23, 42, 0.96);
  border-top: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  padding: 8px 18px;
  gap: 12px;
}

.bottom-panel div {
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 12px;
  padding: 8px 12px;
}

.bottom-panel strong {
  display: block;
  font-size: 15px;
  color: #b9ecff;
}

.bottom-panel span {
  font-size: 12px;
  color: var(--color-muted);
}

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

.leaflet-control-zoom a {
  border-radius: 8px !important;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: #0f172a;
  color: #e5e7eb;
}

.leaflet-popup-content {
  font-size: 13px;
}

/* ===============================
   SCROLLBAR
   =============================== */

.sidebar::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-track {
  background: #020617;
}

.sidebar::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 999px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--color-secondary);
}

/* ===============================
   TABLET
   =============================== */

@media (max-width: 900px) {
  .app {
    grid-template-rows: 70px 1fr;
  }

  .main-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 45% 55%;
  }

  .sidebar {
    order: 2;
    border-right: none;
    border-top: 1px solid var(--color-border);
  }

  .map-panel {
    order: 1;
  }

  .bottom-panel {
    display: none;
  }
}

/* ===============================
   MODO TELÉFONO / RESPONSIVE PRO
   =============================== */

@media (max-width: 768px) {
  body {
    overflow: hidden;
  }

  .app {
    height: 100vh;
    grid-template-rows: 64px 1fr;
  }

  .topbar {
    height: 64px;
    padding: 10px 14px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .topbar p {
    font-size: 11px;
  }

  .status-pill {
    display: none;
  }

  .main-layout {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 56% 44%;
    height: calc(100vh - 64px);
  }

  .map-panel {
    order: 1;
    padding: 8px;
    min-height: 0;
  }

  #map {
    height: 100%;
    border-radius: 16px;
  }

  .sidebar {
    order: 2;
    padding: 10px;
    border-right: none;
    border-top: 1px solid var(--color-border);
    overflow-y: auto;
  }

  .card {
    border-radius: 15px;
    padding: 12px;
    margin-bottom: 10px;
  }

  .card h2 {
    font-size: 14px;
    margin-bottom: 8px;
  }

  button,
  select,
  input {
    padding: 12px;
    font-size: 14px;
    border-radius: 12px;
  }

  #resultado {
    font-size: 13px;
  }

  .bottom-panel {
    display: none;
  }

  .layer-option {
    padding: 12px;
  }
}

body.medicion-activa {
  cursor: crosshair;
}
