:root{
  --bg:#061018;
  --panel:#0b1b24;
  --panel2:#071622;
  --text:#e8eef6;
  --muted:#a7b3c3;

  --primary:#1ea7ff;
  --accent:#12b886;
  --accent2:#2dd4bf;
  --shadow: rgba(0,0,0,0.35);
  /* Altura real del header; app.js actualiza con medición del DOM */
  --topbar-h: 72px;
  /* Altura útil de la ventana (px); JS la fija en resize/orientación — evita fallos de 100vh al rotar el celular */
  --app-height: 100dvh;
}

*{box-sizing:border-box}
html,body{
  margin:0;
  height:var(--app-height);
  min-height:var(--app-height);
  max-height:var(--app-height);
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,"Noto Sans",sans-serif;
  background:var(--bg); color:var(--text);
  overflow:hidden;
}

.topbar{
  min-height:72px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  flex-wrap:wrap;
  gap:10px;
  padding:10px 16px;
  background:linear-gradient(90deg, rgba(30,167,255,0.18), rgba(18,184,134,0.18));
  border-bottom:1px solid rgba(255,255,255,0.10);
}

.brand{display:flex; gap:12px; align-items:center}
.brand-logos{display:flex; gap:8px; align-items:center; flex-shrink:0}
.brand-logo{
  width:44px; height:44px;
  object-fit:contain;
  border-radius:12px;
  background: rgba(255,255,255,0.08);
  padding:6px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.25);
}
.brand-logo-xochi{
  width:auto;
  max-width:min(120px, 28vw);
  height:44px;
  padding:4px 8px;
}
.brand-text .brand-title{font-weight:900; font-size:18px; line-height:1.05}
.brand-text .brand-subtitle{font-size:12px; opacity:0.8; margin-top:2px}

.top-actions{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:center;
  flex:1;
  min-width:0;
  justify-content:flex-end;
  max-width:min(920px, 100%);
}
.search-wrap{
  flex:1 1 200px;
  position:relative;
  min-width:0;
}
.search{
  width:100%;
  box-sizing:border-box;
  background:rgba(255,255,255,0.06);
  color:var(--text);
  border:1px solid rgba(255,255,255,0.10);
  border-radius:14px;
  padding:10px 12px;
  outline:none;
}
.search-suggestions{
  position:absolute;
  left:0;
  right:0;
  top:calc(100% + 4px);
  z-index:2000;
  max-height:min(40vh, 280px);
  overflow-y:auto;
  border-radius:14px;
  border:1px solid rgba(255,255,255,0.14);
  background:rgba(11,27,36,0.98);
  box-shadow:0 16px 40px rgba(0,0,0,0.45);
}
.search-suggestions .sug-item{
  -webkit-appearance:none;
  appearance:none;
  display:block;
  width:100%;
  margin:0;
  box-sizing:border-box;
  padding:10px 12px;
  border:none;
  border-bottom:1px solid rgba(255,255,255,0.06);
  border-radius:0;
  background:transparent;
  color:var(--text);
  font:inherit;
  font-size:13px;
  font-weight:700;
  line-height:1.35;
  text-align:left;
  cursor:pointer;
}
.search-suggestions .sug-item:first-child{border-top-left-radius:13px;border-top-right-radius:13px}
.search-suggestions .sug-item:last-child{
  border-bottom:none;
  border-bottom-left-radius:13px;border-bottom-right-radius:13px;
}
.search-suggestions .sug-item:hover,
.search-suggestions .sug-item:focus{
  background:rgba(30,167,255,0.22);
  color:var(--text);
  outline:none;
}
.search-suggestions .sug-item:focus-visible{
  box-shadow:inset 0 0 0 2px rgba(30,167,255,0.55);
}

.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  text-decoration:none;
  background:rgba(255,255,255,0.10);
  color:white;
  border:1px solid rgba(255,255,255,0.14);
  border-radius:14px;
  padding:10px 14px;
  font-weight:800;
  cursor:pointer;
  box-shadow:none;
  white-space:nowrap;
}
.topbar-reporte{flex-shrink:0}
.btn.primary{
  border:none;
  background:linear-gradient(180deg, rgba(30,167,255,0.95), rgba(30,167,255,0.75));
  box-shadow:0 12px 30px var(--shadow);
}

.layout{
  display:grid;
  grid-template-columns: minmax(280px, 36vw) minmax(0, 1fr);
  height:calc(var(--app-height) - var(--topbar-h));
  min-height:0;
  max-height:calc(var(--app-height) - var(--topbar-h));
}
.sidebar{
  border-right:1px solid rgba(255,255,255,0.08);
  background:var(--panel2);
  overflow-x:hidden;
  overflow-y:auto;
  min-height:0;
  -webkit-overflow-scrolling:touch;
}

.panel{
  margin:14px; padding:14px;
  border-radius:18px;
  background:var(--panel);
  border:1px solid rgba(255,255,255,0.08);
  box-shadow:0 10px 30px rgba(0,0,0,0.25);
}
.panel-title{font-weight:950; margin-bottom:10px; letter-spacing:0.2px;}
.hint{font-size:12px; color:var(--muted); margin-top:10px; line-height:1.4}

.banner{
  padding:10px 12px;
  border-radius:14px;
  background:rgba(255, 193, 7, 0.10);
  border:1px solid rgba(255, 193, 7, 0.25);
  color:#ffd27d;
  font-size:12px;
  margin:10px 0;
}
.hidden{display:none}

.panel-locate .locate-btn{width:100%; justify-content:center}
.panel-locate #locateStatus{margin-top:10px}

.panel-reporte{
  border:1px solid rgba(18,184,134,0.28);
  background:linear-gradient(145deg, rgba(18,184,134,0.10), rgba(30,167,255,0.06));
}
.panel-reporte .locate-btn{width:100%; justify-content:center; text-align:center; text-decoration:none; display:inline-flex; box-sizing:border-box}
.panel-reporte .hint-server{font-size:11px; opacity:0.9; margin-top:0.5rem}
.panel-reporte code{font-size:0.85em; background:rgba(0,0,0,0.2); padding:0.1em 0.35em; border-radius:6px}

.panel-assistant .assistant-question{
  font-size:13px; font-weight:700; margin:0 0 10px;
  color:var(--text);
}
.assistant-actions{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
}
.assistant-chip{
  font-size:12px;
  font-weight:800;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid rgba(30,167,255,0.35);
  background:rgba(30,167,255,0.12);
  color:var(--text);
  cursor:pointer;
  text-align:left;
  line-height:1.25;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.assistant-chip:hover{
  background:rgba(30,167,255,0.22);
  border-color:rgba(30,167,255,0.55);
}
.assistant-chip:focus-visible{
  outline:2px solid var(--primary);
  outline-offset:2px;
}
.assistant-detail{
  margin-top:12px;
  padding:12px;
  border-radius:14px;
  background:rgba(0,0,0,0.22);
  border:1px solid rgba(255,255,255,0.08);
  font-size:12px;
  line-height:1.5;
  color:var(--muted);
}
.assistant-detail strong{color:var(--text)}
.assistant-detail ul{margin:8px 0 0 1.1rem; padding:0}
.assistant-detail li{margin:4px 0}

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

.group{
  border:1px solid rgba(255,255,255,0.08);
  background:rgba(255,255,255,0.03);
  border-radius:16px;
  overflow:hidden;
}
.group-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 12px;
  cursor:pointer;
  user-select:none;
}
.group-title{font-weight:950; font-size:13px}
.group-toggle{color:var(--muted); font-size:12px}
.group-body{padding:10px 10px 12px; display:flex; flex-direction:column; gap:10px}

.layer-item{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px;
  border-radius:14px;
  background:rgba(255,255,255,0.04);
  border:1px solid rgba(255,255,255,0.07);
}
.layer-left{display:flex; gap:10px; align-items:center; min-width:0}
.layer-icon{
  width:22px; height:22px;
  border-radius:8px;
  background:rgba(255,255,255,0.08);
  display:flex; align-items:center; justify-content:center;
  flex:0 0 auto;
  overflow:hidden;
  border:1px solid rgba(255,255,255,0.10);
}
.layer-icon img{width:18px; height:18px; object-fit:contain}
.badge{width:10px; height:10px; border-radius:999px; background:var(--accent2);}
.layer-text{min-width:0}
.layer-name{font-weight:900; font-size:13px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.layer-meta{font-size:11px; color:var(--muted); margin-top:3px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis}

.layer-actions{display:flex; gap:8px; align-items:center}
.chk{transform:scale(1.1); cursor:pointer}

.layer-item-row{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.layer-dash-slot{
  margin:0 2px 2px;
  padding:10px 12px 12px;
  border-radius:14px;
  background:rgba(0,0,0,0.22);
  border:1px dashed rgba(255,255,255,0.14);
}
.layer-dash-slot-head{
  font-weight:950;
  font-size:12px;
  margin-bottom:6px;
  color:var(--text);
  letter-spacing:0.02em;
}
.layer-dash-slot .layer-dash-empty{
  margin:0;
  padding:4px 0 2px;
}
.rutas-kpi{
  font-size:11px;
  color:var(--muted);
  margin:0 0 8px 2px;
  font-weight:600;
}

.legendbox{
  margin-top:12px;
  padding:10px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,0.08);
  background:rgba(255,255,255,0.03);
}
.legend-title{font-weight:900; font-size:12px; margin-bottom:8px; color:var(--text)}
.legend{display:flex; flex-direction:column; gap:6px}
/* Filas de leyenda (coropléticos, transporte, equipamiento): muestra de color + texto */
.legend .swatch{
  display:flex;
  align-items:center;
  gap:8px;
  font-size:12px;
  line-height:1.4;
  color:var(--text);
}
.legend .swatch i{
  display:inline-block;
  flex-shrink:0;
  width:16px;
  height:16px;
  border-radius:4px;
  border:1px solid rgba(255,255,255,0.3);
  box-sizing:border-box;
  font-style:normal;
  vertical-align:middle;
}
.legend .uso-val{
  display:inline-block; min-width:1rem; font-weight:800; font-size:11px;
  color:var(--muted);
}
.legend-row{display:flex; align-items:center; gap:8px; font-size:12px; color:var(--muted)}
.legend-swatch{width:14px; height:14px; border-radius:4px; border:1px solid rgba(255,255,255,0.22)}

.identify{font-size:12px; color:var(--muted); line-height:1.45}

.dashboard-content .kpis{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
  margin-bottom:12px;
}
.kpi{
  padding:10px;
  border-radius:14px;
  background:rgba(255,255,255,0.04);
  border:1px solid rgba(255,255,255,0.07);
}
.kpi .k{font-size:11px; color:var(--muted)}
.kpi .v{font-size:18px; font-weight:900; margin-top:4px}

.chartbox, .listbox{
  margin-top:12px;
  padding:10px;
  border-radius:14px;
  background:rgba(255,255,255,0.04);
  border:1px solid rgba(255,255,255,0.07);
}
.chart-title{font-weight:800; font-size:12px; color:var(--text); margin-bottom:8px}
.routes{font-size:12px; color:var(--muted); line-height:1.35}
.routes .tag{
  display:inline-block;
  padding:4px 8px;
  margin:4px 6px 0 0;
  border-radius:999px;
  border:1px solid rgba(255,255,255,0.12);
  background:rgba(0,0,0,0.18);
}

.mapwrap{position:relative; min-height:0; min-width:0;}
#map{height:100%; width:100%}
.attribution{
  position:absolute; right:12px; bottom:10px;
  max-width:calc(100% - 100px);
  padding:8px 10px; border-radius:12px;
  background:rgba(11,27,36,0.88);
  border:1px solid rgba(255,255,255,0.10);
  font-size:11px; color:var(--muted);
  line-height:1.35;
}
.leaflet-control-attribution{display:none}

/* Botones flotantes del mapa (móvil): encima de tiles y controles Leaflet */
.map-mobile-stack{
  display:none;
  position:absolute;
  left:max(12px, env(safe-area-inset-left));
  bottom:calc(52px + env(safe-area-inset-bottom, 0px));
  z-index:1100;
  flex-direction:column;
  gap:12px;
  align-items:stretch;
  max-width:calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  pointer-events:none;
  opacity:1;
  visibility:visible;
  transition:opacity 0.22s ease, visibility 0.22s ease;
}
.map-mobile-stack .map-fab{
  pointer-events:auto;
}
.map-fab{
  min-height:48px;
  min-width:48px;
  padding:12px 20px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,0.22);
  color:#fff;
  font-weight:900;
  font-size:14px;
  line-height:1.2;
  cursor:pointer;
  box-shadow:0 8px 24px rgba(0,0,0,0.45);
  -webkit-tap-highlight-color:transparent;
}
.map-fab--layers{
  background:linear-gradient(180deg, rgba(30,167,255,0.98), rgba(18,184,134,0.92));
}
.map-fab--home{
  background:linear-gradient(180deg, rgba(18,184,134,0.95), rgba(11,90,72,0.92));
  border-color:rgba(18,184,134,0.45);
}
.map-fab:hover{
  filter:brightness(1.08);
}
.map-fab:focus-visible{
  outline:3px solid rgba(255,255,255,0.85);
  outline-offset:3px;
}
.map-fab:active{
  transform:scale(0.98);
}

.sidebar-backdrop{
  display:none;
}
@media (min-width:901px){
  .sidebar-backdrop{display:none !important;}
}

/* ——— Tablet: panel un poco más estrecho ——— */
@media (max-width: 1100px){
  .layout{
    grid-template-columns: minmax(260px, 42vw) minmax(0, 1fr);
  }
  .brand-text .brand-subtitle{
    font-size:11px;
  }
}

/* ——— Móvil / panel cajón: mapa a pantalla completa ——— */
@media (max-width: 900px){
  html,body{
    overflow:hidden;
  }
  .layout{
    display:block;
    height:calc(var(--app-height) - var(--topbar-h));
    max-height:calc(var(--app-height) - var(--topbar-h));
    min-height:0;
  }
  .mapwrap{
    height:100%;
    max-height:100%;
    min-height:200px;
  }
  .map-mobile-stack{
    display:flex;
  }
  /* Cajón abierto: los FAB no deben quedar encima del panel (landscape/móvil). */
  .layout > aside.sidebar.is-open ~ main.mapwrap .map-mobile-stack{
    opacity:0;
    visibility:hidden;
    pointer-events:none;
  }
  .sidebar{
    position:fixed;
    top:var(--topbar-h);
    left:0;
    bottom:0;
    width:min(100vw - 48px, 400px);
    max-width:100%;
    z-index:1200;
    border-right:1px solid rgba(255,255,255,0.12);
    border-top:none;
    box-shadow:8px 0 32px rgba(0,0,0,0.35);
    transform:translateX(-102%);
    transition:transform 0.28s ease;
    overscroll-behavior:contain;
  }
  .sidebar.is-open{
    transform:translateX(0);
  }
  .sidebar-backdrop{
    display:block;
    position:fixed;
    inset:0;
    top:var(--topbar-h);
    z-index:1190;
    background:rgba(0,0,0,0.45);
    opacity:0;
    visibility:hidden;
    transition:opacity 0.22s ease, visibility 0.22s ease;
    pointer-events:none;
  }
  .sidebar-backdrop.is-visible{
    opacity:1;
    visibility:visible;
    pointer-events:auto;
  }
  .attribution{
    right:8px;
    bottom:calc(168px + env(safe-area-inset-bottom, 0px));
    font-size:10px;
    padding:6px 8px;
    max-width:min(200px, 50vw);
  }
}

/* ——— Pantallas muy estrechas: barra superior y acciones ——— */
@media (max-width: 640px){
  .brand{
    width:100%;
    min-width:0;
  }
  .brand-text{
    min-width:0;
  }
  .brand-text .brand-title{
    font-size:16px;
  }
  .brand-text .brand-subtitle{
    display:none;
  }
  .topbar{
    flex-direction:column;
    align-items:stretch;
  }
  .top-actions{
    max-width:none;
    width:100%;
    justify-content:stretch;
  }
  .search-wrap{
    flex:1 1 100%;
    order:-1;
  }
  .top-actions .btn,
  .top-actions .topbar-reporte{
    flex:1 1 auto;
    min-width:0;
    white-space:normal;
    text-align:center;
    padding:10px 12px;
    font-size:13px;
  }
  .assistant-actions{
    grid-template-columns:1fr;
  }
  .dashboard-content .kpis{
    grid-template-columns:1fr;
  }
}

@media (max-width: 380px){
  .brand-logo{width:40px; height:40px}
  .brand-logo-xochi{height:40px}
}

