/* ===== Global ===== */
*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
img { max-width: 100%; height: auto; display: block; }

/* Estructura principal — flex column ocupa toda la pantalla */
body {
  display: flex;
  flex-direction: column;
  height: 100dvh; /* dynamic viewport height: clave en móvil */
}

/* ===== Header ===== */
header {
  background-color: #33c7ff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  min-height: 0;
}

#logos-izquierda,
#logo-derecha {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

#logo  { max-height: clamp(32px, 5.5vw, 66px); height: auto; }
#logo3 { max-height: clamp(36px, 6vw,   74px); height: auto; }

header h1 {
  color: #fff;
  margin: 0;
  line-height: 1.15;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.titulo-principal {
  font-weight: 800;
  letter-spacing: .5px;
  font-size: clamp(13px, 2.2vw + 0.4rem, 28px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.subtitulo {
  font-weight: 600;
  font-size: clamp(10px, 1.1vw + 0.3rem, 18px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ===== Barra estadísticas globales ===== */
#stats-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  background: #0f172a;
  padding: 0 8px;
  flex: 0 0 auto;
  min-height: 40px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#stats-bar::-webkit-scrollbar { display: none; }

.stat-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  flex-shrink: 0;
}

.stat-item i  { font-size: 13px; }
.stat-label   { font-size: 9px; font-weight: 700; letter-spacing: 0.8px; color: #94a3b8; text-transform: uppercase; white-space: nowrap; }
.stat-value   { font-size: 16px; font-weight: 800; color: #f8fafc; font-family: Arial, sans-serif; min-width: 24px; white-space: nowrap; }
.stat-pct     { font-size: 10px; font-weight: 500; color: #64748b; min-width: 32px; white-space: nowrap; }
.stat-divider { width: 1px; height: 24px; background: #1e293b; flex-shrink: 0; }

/* Colores por estado */
#stat-total   .stat-value { color: #38bdf8; }
.stat-buena   i           { color: #22c55e; }
.stat-buena   .stat-value { color: #22c55e; }
.stat-regular i           { color: #f59e0b; }
.stat-regular .stat-value { color: #f59e0b; }
.stat-mala    i           { color: #ef4444; }
.stat-mala    .stat-value { color: #ef4444; }
.stat-sindato i           { color: #94a3b8; }
.stat-sindato .stat-value { color: #94a3b8; }

/* Pantallas pequeñas: ocultar % */
@media (max-width: 480px) {
  .stat-pct     { display: none; }
  .stat-item    { padding: 5px 8px; }
  .stat-value   { font-size: 14px; }
  .stat-label   { font-size: 8px; }
  .stat-divider { height: 20px; }
}

/* ===== Mapa ===== */
#map {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;          /* permite que flex shrink funcione */
  border-top: 1px solid rgba(0,0,0,.15);
  background: #f0f0f0;
}

/* ===== Dashboard ===== */
#dashboard {
  display: none;
  position: absolute;
  bottom: calc(var(--macro-h, 68px) + 10px);
  right: 10px;
  width: min(290px, calc(100vw - 20px));
  max-height: calc(100dvh - 160px);
  overflow-y: auto;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  border: 1px solid #e2e8f0;
  z-index: 1001;
  padding: 14px 16px 16px;
  pointer-events: all;
}

#dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f1f5f9;
}

#dash-nombre {
  font-weight: 700;
  font-size: 14px;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 32px);
}

#dash-cerrar {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: #94a3b8;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
#dash-cerrar:hover { color: #b91c1c; }

#total {
  font-size: 13px;
  color: #475569;
  margin-bottom: 14px;
  line-height: 1.5;
}
#total strong {
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
  display: block;
  margin-top: 2px;
}

#graficoEstado {
  width: 100% !important;
  max-height: 200px;
}

/* ===== Barra inferior Macrosectores ===== */
#barra-macro {
  position: relative;       /* parte del flujo flex — no fixed */
  flex: 0 0 auto;
  background: #0f172a;
  z-index: 1000;
  padding: 6px 10px;
  overflow-x: auto;
  white-space: nowrap;
  border-top: 2px solid #1e293b;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #334155 #0f172a;
}
#barra-macro::-webkit-scrollbar        { height: 4px; }
#barra-macro::-webkit-scrollbar-track  { background: #0f172a; }
#barra-macro::-webkit-scrollbar-thumb  { background: #334155; border-radius: 2px; }

#barra-macro-inner {
  display: inline-flex;
  gap: 8px;
  align-items: stretch;
}

.macro-card {
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  background: #1e293b;
  border-radius: 8px;
  padding: 6px 12px;
  min-width: 100px;
  cursor: pointer;
  border: 1px solid #334155;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.macro-card:hover,
.macro-card:active { background: #334155; }

.macro-card-nombre {
  font-size: 9px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 96px;
}
.macro-card-total {
  font-size: 16px;
  font-weight: 700;
  color: #f1f5f9;
  line-height: 1.1;
}
.macro-card-pct {
  font-size: 9px;
  color: #64748b;
  margin-bottom: 3px;
}
.macro-card-barra {
  height: 3px;
  border-radius: 2px;
  display: flex;
  overflow: hidden;
  background: #0f172a;
  margin-top: 4px;
}

/* ===== Popup señalética ===== */
.pp-popup {
  font-family: Arial, sans-serif;
  min-width: 200px;
  max-width: min(260px, calc(100vw - 60px));
}
.pp-header {
  background: #0f172a;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  padding: 6px 10px;
  border-radius: 6px 6px 0 0;
  text-transform: uppercase;
}
.pp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.pp-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
.pp-table .pp-label {
  color: #64748b;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 600;
  padding-right: 10px;
}
.pp-table .pp-val {
  font-weight: 500;
  color: #0f172a;
  word-break: break-word;
}
.pp-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
}

/* ===== Leaflet — ajustes móvil ===== */
.leaflet-control-zoom   { touch-action: manipulation; }
.leaflet-control-layers { max-width: calc(100vw - 30px); }
.leaflet-popup-content  {
  max-width: min(280px, calc(100vw - 60px));
  overflow-x: auto;
  margin: 0 !important;
  padding: 0 !important;
}
.leaflet-popup-content-wrapper { padding: 0 !important; border-radius: 8px !important; overflow: hidden; }
.leaflet-popup-tip-container    { margin-top: -1px; }

/* ===== Controles Leaflet (der. sup.) ===== */
.leaflet-top.leaflet-right .controls-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: flex-start;
  margin: 8px 8px 0 0;
}
.leaflet-top.leaflet-right .controls-row .leaflet-control { margin: 0; }

/* ===== Geocoder ===== */
.geocoder-shell.leaflet-control {
  background: #e9f6ff; border: 1px solid #cfeafa; border-radius: 8px; padding: 6px;
}
.geo-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid #dbeafe; border-radius: 8px;
  padding: 6px 10px; font-size: 13px; font-weight: 700; color: #0f172a; cursor: pointer;
}
.geo-panel { margin-top: 6px; display: none; }
.geo-panel.open { display: block; }
.geo-panel .leaflet-control-geocoder { background: transparent; border: 0; padding: 0; border-radius: 0; }
.geo-panel .leaflet-control-geocoder-form input {
  width: clamp(120px, 28vw, 220px);
  font-size: 13px; padding: 6px 8px; border-radius: 6px; border: 1px solid #dbeafe; outline: none;
}

/* ===== Barra de dibujo ===== */
.leaflet-control.drawing-bar.leaflet-bar {
  display: flex; flex-direction: column; gap: 6px; padding: 6px;
  background: #e9f6ff; border: 1px solid #cfeafa; border-radius: 6px;
}
.drawing-bar .draw-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; background: #fff; border-radius: 8px;
  text-decoration: none; box-shadow: 0 0 0 1px #e5e7eb inset; font-size: 16px; color: #111;
  transition: background .15s ease;
}
.drawing-bar .draw-btn:hover  { background: #f3f4f6; }
.drawing-bar .draw-btn.active { outline: 2px solid #60a5fa; }
.drawing-bar .draw-btn.danger { color: #b91c1c; }

/* ===== Botón Home ===== */
.leaflet-control.home-control.leaflet-bar {
  display: flex; padding: 6px; background: #e9f6ff; border: 1px solid #cfeafa; border-radius: 6px;
}
.home-control .home-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; background: #fff; border-radius: 8px;
  text-decoration: none; box-shadow: 0 0 0 1px #e5e7eb inset; font-size: 16px; color: #111;
}
.home-control .home-btn:hover { background: #f3f4f6; }

/* ===== Zoom mini ===== */
.leaflet-control.zoom-mini-control {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: #e9f6ff; border: 1px solid #cfeafa; border-radius: 6px; padding: 6px;
}
.zoom-mini .mini-arrow {
  width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid #e5e7eb; border-radius: 6px; background: #fff; font-size: 12px;
}
.zoom-mini .mini-range-wrap { height: 100px; display: flex; align-items: center; }
.zoom-mini input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100px; height: 4px; border-radius: 999px;
  background: linear-gradient(90deg, #c7d2fe, #93c5fd);
  outline: none; transform: rotate(-90deg);
}
.zoom-mini input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; border: 2px solid #60a5fa;
}
.zoom-mini input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid #60a5fa;
}

/* ===== Clusters ===== */
.custom-cluster div {
  border-radius: 50%; text-align: center; font-weight: bold;
  color: white; line-height: 40px; font-size: 14px;
}
.cluster-small  { background: rgba(0,150,255,0.7); }
.cluster-medium { background: rgba(255,165,0,0.8); }
.cluster-large  { background: rgba(255,0,0,0.8); }

/* ===== Popup con foto ===== */
.vehab-popup .popup-photo-wrap { margin-bottom: 8px; }
.vehab-popup .popup-photo {
  display: block; width: 100%; max-height: 220px; object-fit: contain;
  border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.vehab-dot {
  width: 12px; height: 12px; background: #ff2d55; border: 2px solid #fff; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,.15);
}

/* ===== Pantallas muy pequeñas (≤ 360px) ===== */
@media (max-width: 360px) {
  #logo  { max-height: 28px; }
  #logo3 { max-height: 30px; }
  .titulo-principal { font-size: 12px; }
  .subtitulo        { display: none; }
  .macro-card       { min-width: 88px; padding: 5px 8px; }
  .macro-card-total { font-size: 14px; }
}

/* ===== Tablets y PC (≥ 768px): estilos más amplios ===== */
@media (min-width: 768px) {
  header          { padding: 8px 16px; gap: 12px; }
  .stat-item      { padding: 8px 20px; }
  .stat-value     { font-size: 18px; }
  .stat-label     { font-size: 10px; }
  .stat-pct       { display: inline; }
  .stat-divider   { height: 28px; }
  .macro-card     { min-width: 120px; padding: 7px 14px; }
  .macro-card-total  { font-size: 18px; }
  .macro-card-nombre { font-size: 10px; max-width: 110px; }
  .macro-card-pct    { font-size: 10px; }
  #barra-macro       { padding: 8px 14px; }
}
