:root {
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --blue: #2563eb;
  --blue-dark: #1e40af;
  --blue-soft: #eff6ff;
  --green: #16a34a;
  --amber: #d97706;
  --yellow: #facc15;
  --attr-missing: #94a3b8;
}

* { box-sizing: border-box; }
html, body, #map { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; color: var(--ink); font-family: Inter, Arial, sans-serif; background: #edf1f5; }

#map { position: fixed; inset: 0; }
.panel {
  position: fixed; z-index: 1000; top: 14px; bottom: 14px; left: 14px; width: 470px;
  display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid #cbd5e1; border-radius: 20px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.17);
}

.header { display: flex; gap: 13px; padding: 15px 18px 12px; border-bottom: 1px solid var(--line); }
.logo {
  width: 40px; height: 40px; display: grid; place-items: center; flex: 0 0 auto;
  border-radius: 11px; color: #fff; background: linear-gradient(145deg, #2563eb, #1d4ed8);
  font-weight: 800; font-size: 18px;
}
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1 { margin: 0; font-size: 20px; letter-spacing: -.025em; }
.subtitle { margin: 3px 0 0; color: var(--muted); font-size: 11px; }

.filters { padding: 10px 18px 9px; border-bottom: 1px solid var(--line); }
label { display: block; margin-bottom: 7px; }
label span { display: block; margin-bottom: 4px; color: #475569; font-size: 8px; font-weight: 800; letter-spacing: .075em; text-transform: uppercase; }
select {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid #cbd5e1;
  border-radius: 9px; color: #1e293b; background: #fff; font-size: 11px; outline: none;
}
select:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px #dbeafe; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row label { margin-bottom: 7px; }
.filter-note { margin: 0; color: #64748b; font-size: 8px; line-height: 1.4; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 9px 18px; border-bottom: 1px solid var(--line); }
.kpi { padding: 7px 5px 6px; border: 1px solid var(--line); border-radius: 9px; background: #f8fafc; text-align: center; }
.kpi.primary { border-color: #bfdbfe; background: var(--blue-soft); }
.kpi span { display: block; color: var(--muted); font-size: 7px; font-weight: 800; text-transform: uppercase; }
.kpi strong { display: block; margin-top: 2px; font-size: 13px; }
.kpi.primary strong { color: #1d4ed8; }
.kpi em { display: block; min-height: 9px; margin-top: 1px; color: #94a3b8; font-size: 7px; font-style: normal; }

.status {
  display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 6px;
  min-height: 34px; padding: 7px 18px; border-bottom: 1px solid var(--line);
  color: var(--muted); background: #f8fafc; font-size: 9px;
}
.status b { color: var(--green); }
.status .warning { color: var(--amber); }

.rank-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 18px 6px; }
.rank-head h2 { margin: 0; font-size: 13px; }
.rank-chip {
  max-width: 58%; overflow: hidden; padding: 4px 7px; border-radius: 99px;
  color: #1d4ed8; background: #dbeafe; font-size: 8px; font-weight: 800;
  text-overflow: ellipsis; white-space: nowrap;
}

.ranking { min-height: 0; flex: 1; margin: 0; padding: 0 10px 7px; overflow: auto; list-style: none; }
.ranking li { margin-bottom: 3px; }
.ranking button {
  width: 100%; min-height: 67px; display: grid; grid-template-columns: 31px minmax(0, 1fr) 16px;
  align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid transparent;
  border-radius: 10px; background: transparent; text-align: left; cursor: pointer;
}
.ranking button:hover, .ranking button:focus { border-color: #bfdbfe; background: #eff6ff; outline: none; }
.ranking button.selected { border-color: #fde047; background: #fefce8; }
.badge {
  width: 28px; height: 28px; display: grid; place-items: center; border: 2px solid #fff;
  border-radius: 50%; color: #fff; background: var(--blue); box-shadow: 0 2px 7px #94a3b8;
  font-size: 9px; font-weight: 800;
}
.copy { min-width: 0; }
.copy strong, .copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy strong { font-size: 10px; }
.copy small { margin-top: 2px; color: #334155; font-size: 8px; }
.copy .mix { color: #475569; }
.polygon-symbol { width: 12px; height: 12px; border: 2px solid #1e40af; border-radius: 3px; background: #60a5fa; }
.empty { margin: 18px 10px; padding: 16px; border: 1px dashed #cbd5e1; border-radius: 10px; color: var(--muted); font-size: 11px; text-align: center; }

.foot { padding: 7px 12px; border-top: 1px solid var(--line); color: #64748b; background: #f8fafc; font-size: 7px; line-height: 1.35; text-align: center; }

/* Popups y leyendas */
.leaflet-popup-content-wrapper { border-radius: 16px; }
.leaflet-popup-content { width: 430px !important; margin: 17px !important; }
.popup .eyebrow { margin-bottom: 5px; font-size: 10px; }
.popup h3 { margin: 5px 0 4px; font-size: 18px; }
.popup p { margin: 0 0 10px; color: #475569; font-size: 10px; line-height: 1.4; }
.pgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pgrid span { padding: 8px 5px; border-radius: 8px; color: #64748b; background: #f8fafc; font-size: 8px; text-align: center; }
.pgrid strong { display: block; margin-bottom: 2px; color: #1e293b; font-size: 12px; }
.detail { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); color: #475569; font-size: 9px; line-height: 1.55; }
.detail strong { color: #334155; }
.detail .blue { color: #1d4ed8; }
.street-list, .network-list { max-height: 165px; margin: 6px 0 0; padding: 0; overflow: auto; list-style: none; }
.street-list li, .network-list li { padding: 5px 6px; border-bottom: 1px solid #f1f5f9; }
.street-list li:last-child, .network-list li:last-child { border-bottom: 0; }
.street-list strong, .street-list span, .network-list strong, .network-list span { display: block; }
.street-list strong, .network-list strong { color: #334155; font-size: 9px; }
.street-list span, .network-list span { margin-top: 1px; color: #64748b; font-size: 8px; }
.no-streets { margin: 5px 0 0 !important; color: #94a3b8 !important; font-style: italic; }

.attractiveness-legend {
  width: 318px; padding: 10px; border: 1px solid #cbd5e1; border-radius: 12px;
  color: #334155; background: rgba(255, 255, 255, 0.96); box-shadow: 0 4px 18px rgba(15, 23, 42, 0.14);
  font: 10px/1.35 Inter, Arial, sans-serif;
}
.attractiveness-legend > strong { display: block; margin-bottom: 6px; color: #59657a; font-size: 11px; letter-spacing: .04em; text-align: center; }
.attractiveness-scale { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.attractiveness-scale span { height: 25px; display: grid; place-items: center; border-radius: 4px; font-size: 11px; font-weight: 900; }
.attractiveness-legend .legend-note { margin: 6px 0 2px; color: #64748b; font-size: 8px; text-align: center; }
.attractiveness-legend .legend-row { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.attractiveness-legend .legend-row i { width: 13px; height: 13px; display: inline-block; flex: 0 0 auto; border: 1px solid #64748b; border-radius: 3px; }
.attractiveness-legend .top-border { background: #fff; border: 3px solid var(--blue-dark); }

.manzana-number-icon { border: 0 !important; background: transparent !important; pointer-events: none !important; }
.manzana-number-icon span {
  display: block; color: #111827; font-size: 10px; font-weight: 900; line-height: 18px;
  text-align: center; white-space: nowrap;
  text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff, 0 0 3px #fff;
}

/* Modal y configuración CARTO */
.carto-settings {
  max-width: min(280px, calc(100vw - 24px)); padding: 8px 10px;
  border: 1px solid #cbd5e1 !important; border-radius: 9px !important;
  background: rgba(255, 255, 255, 0.97); color: #334155; font: 12px/1.35 Arial, sans-serif;
}
.carto-settings button { padding: 0; border: 0; background: none; color: #1d4ed8; font: 700 12px Arial, sans-serif; cursor: pointer; }
.carto-status { display: block; margin-top: 4px; font-size: 11px; color: #475569; }

.carto-dialog {
  width: min(470px, calc(100vw - 28px)); max-height: 85vh; padding: 22px;
  border: 1px solid #cbd5e1; border-radius: 14px; color: #1e293b; background: #fff;
  box-shadow: 0 24px 70px #0f172a40; font: 14px/1.45 Arial, sans-serif;
}
.carto-dialog::backdrop { background: #0f172a66; }
.carto-dialog h2 { margin: 0 0 12px; font-size: 20px; }
.carto-dialog p { margin: 10px 0; }
.carto-dialog a { color: #1d4ed8; }
.carto-dialog label { margin: 12px 0 5px; font-size: 13px; font-weight: 600; display: block; }
.carto-dialog input[type=password] { width: 100%; padding: 10px; border: 1px solid #94a3b8; border-radius: 7px; font: 14px Arial, sans-serif; }
.carto-dialog .carto-remember { display: flex; align-items: center; gap: 7px; font-weight: 400; }
.carto-dialog .carto-help { font-size: 12px; color: #64748b; }
.carto-dialog .carto-feedback { font-size: 13px; color: #334155; }
.carto-dialog .carto-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.carto-dialog button { padding: 8px 12px; border: 1px solid #cbd5e1; border-radius: 7px; background: #f8fafc; color: #334155; font-size: 13px; cursor: pointer; }
.carto-dialog .carto-apply { border-color: #1d4ed8; background: #1d4ed8; color: white; }

/* Barra de sesión del usuario en panel lateral */
.user-session-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 18px;
  background: #fef2f2;
  border-bottom: 1px solid #fee2e2;
  font-size: 11px;
}
.user-session-bar span {
  font-weight: 700;
  color: #991b1b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logout-btn {
  background: #fff;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.logout-btn:hover {
  background: #ef4444;
  color: #fff;
  border-color: #dc2626;
}

/* Pantalla de Login en Rojo Corporativo Claro */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at 50% 30%, #ef4444 0%, #dc2626 40%, #991b1b 100%);
  padding: 20px;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.login-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 410px;
  background: rgba(255, 255, 255, 0.98);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
  padding: 36px 32px 28px;
  text-align: center;
  animation: loginAppear 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes loginAppear {
  from { opacity: 0; transform: scale(0.94) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.login-badge {
  display: inline-block;
  padding: 4px 12px;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  border-radius: 20px;
  margin-bottom: 12px;
}

.login-card h2 {
  margin: 0 0 6px;
  color: #0f172a;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.login-sub {
  margin: 0 0 24px;
  color: #64748b;
  font-size: 12px;
}

.login-form {
  text-align: left;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper input {
  width: 100%;
  height: 44px;
  padding: 0 44px 0 14px;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  font-size: 14px;
  color: #0f172a;
  outline: none;
  transition: all 0.2s;
  background: #f8fafc;
}

.input-wrapper input:focus {
  border-color: #dc2626;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.toggle-password {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: #64748b;
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
}

.toggle-password:hover {
  color: #0f172a;
}

.login-error {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 16px;
  text-align: center;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.login-btn {
  width: 100%;
  height: 46px;
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(185, 28, 28, 0.35);
  transition: all 0.2s;
}

.login-btn:hover {
  background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%);
  box-shadow: 0 10px 24px rgba(185, 28, 28, 0.45);
  transform: translateY(-1px);
}

.login-btn:active {
  transform: translateY(0);
}

.login-footer {
  margin-top: 20px;
  font-size: 11px;
  color: #94a3b8;
}

