/* ════════════════════════════════════════════════════════════
   CENTRAL DE ÁNGELES — APP SHELL / LAYOUT
   Sidebar, topbar, contenedores. Para app autenticada.
   Excepción: .page-loader (al final del archivo) es de página
   completa — lo carga también la landing (ver patrón 14 de app.js).
   ════════════════════════════════════════════════════════════ */

/* ── App shell ─────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* Safari iOS: 100vh incluye la barra de dirección */
  overflow: hidden;
}

body.app-body {
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  order: 2; /* a la derecha del área principal (plataforma orientada al mapa) */
  background: var(--surface-2);
  border-left: 1px solid var(--border-1);
  display: flex;
  flex-direction: column;
  /* El scroll vive en .sidebar-nav (abajo), no acá: así el colapso/logo/
     usuario (arriba) y el footer (abajo) quedan siempre visibles aunque
     la lista de items sea larga y haga scroll. */
  overflow-y: hidden;
  overflow-x: hidden;
  z-index: var(--z-sidebar);
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s ease, margin-right 0.25s ease, background 0.3s ease, border-color 0.3s ease;
}

/* Cabecera del sidebar con flecha para ocultarlo (inyectada por app.js).
   Markup: <div class="sidebar-collapse"><button class="sidebar-collapse-btn"
   data-sidebar-toggle>›</button><span class="sidebar-collapse-lbl">Ocultar</span></div> */
.sidebar-collapse {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--border-2);
  flex-shrink: 0;
}
.sidebar-collapse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--surface-3);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  color: var(--text-2);
  font-size: var(--text-xl);
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-collapse-btn:hover { background: var(--surface-2); color: var(--text-1); }
.sidebar-collapse-lbl { font-size: var(--text-xs); font-weight: 600; color: var(--text-4); }

.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--border-2);
  flex-shrink: 0;
}
.sidebar-logo img {
  height: 40px;
  width: auto;
  max-width: 100%;
  filter: var(--logo-filter);
  transition: filter 0.3s ease;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-2);
  flex-shrink: 0;
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--electric-light);
  border: 1.5px solid var(--electric);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--electric-text);
  flex-shrink: 0;
}
.user-name { font-size: var(--text-base); font-weight: 600; color: var(--text-1); }
.user-role { font-size: var(--text-xs); color: var(--text-4); }
.client-badge {
  margin-left: auto;
  font-size: var(--text-2xs);
  font-weight: 700;
  background: var(--gps-light);
  color: var(--success-text);
  border: 1px solid var(--success-border);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  /* min-height: 0 es necesario para que un hijo flex se achique por
     debajo de su contenido y scrollee internamente, en vez de estirar
     el padre (.sidebar) y arrastrar consigo el colapso/logo/usuario. */
  min-height: 0;
  padding: 8px 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section {
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-4);
  padding: 14px 16px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
  position: relative;
  text-decoration: none;
}
.nav-item:hover {
  color: var(--text-1);
  background: var(--surface-3);
}
.nav-item.active {
  color: var(--electric-text);
  background: var(--electric-light);
  border-left-color: var(--electric);
  font-weight: 600;
}
.nav-item.active .nav-icon { opacity: 1; }
.nav-icon {
  font-size: var(--text-lg);
  width: 18px;
  text-align: center;
  opacity: 0.7;
}
.nav-badge {
  margin-left: auto;
  font-size: var(--text-2xs);
  font-weight: 700;
  background: var(--danger-light);
  color: var(--danger-text);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
}
.nav-badge.warn { background: var(--warning-light); color: var(--warning-text); }
.nav-badge.info { background: var(--info-light);    color: var(--info-text); }

.sidebar-footer {
  padding: 12px 0;
  border-top: 1px solid var(--border-2);
  flex-shrink: 0;
}

/* ── Main area ─────────────────────────────────────────── */
.main {
  flex: 1;
  order: 1; /* área principal a la izquierda; el sidebar va a la derecha */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Colapso del sidebar (desktop) ─────────────────────────
   El ☰ (topbar) y la flecha › (sidebar) alternan .sidebar-collapsed
   en .app. Colapsado: el sidebar se desliza fuera por la derecha y
   libera su espacio → el mapa ocupa toda la pantalla. */
@media (min-width: 901px) {
  .app.sidebar-collapsed .sidebar {
    transform: translateX(100%);
    margin-right: calc(-1 * var(--sidebar-w));
    box-shadow: none;
  }
}
/* No animar el colapso en la carga inicial de cada página */
.app.no-anim .sidebar { transition: none; }

/* ── Top bar ───────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-1);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: var(--sp-3);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: var(--z-sticky);
  transition: background 0.3s ease;
}
.topbar-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.01em;
}
.topbar-sub {
  font-size: var(--text-sm);
  color: var(--text-4);
  margin-left: 4px;
}
.topbar-spacer { flex: 1; }

/* Live indicator (.live-chip / .live-dot) → movido a components.css
   porque es un COMPONENTE reusable (lo consume el design-system doc,
   que solo carga tokens + components). Aquí queda solo su comportamiento
   responsivo de topbar (ocultarse en móvil, más abajo en este archivo). */

/* Theme toggle (top-bar variant, small).
   Markup: <button type="button" data-theme-toggle aria-pressed="…"> */
.toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-3);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-full);
  padding: 5px 12px 5px 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  user-select: none;
  font-family: var(--font-body);
}
.toggle-btn:hover { box-shadow: var(--shadow-md); }
.toggle-track {
  display: inline-block;
  width: 34px;
  height: 18px;
  background: var(--toggle-track);
  border-radius: var(--radius-full);
  position: relative;
  transition: background 0.25s ease;
  flex-shrink: 0;
}
[data-theme="dark"] .toggle-track { background: var(--gps); }
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface-2);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.25s ease;
}
[data-theme="dark"] .toggle-thumb { transform: translateX(16px); }
.toggle-lbl { font-size: var(--text-sm); font-weight: 600; color: var(--text-3); }
.toggle-icon { font-size: var(--text-md); }

/* Date picker / select rápido en topbar */
.date-select {
  background: var(--surface-3);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--text-2);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

/* ── Content scroll area ───────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
/* Sin esto, el flex column con scroll comprime a los hijos
   (flex-shrink default) y las cards se encimarían entre sí. */
.content > * { flex-shrink: 0; }

/* Page header (dentro de .content) — usado en pantallas de form/tabla */
.page-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: 4px;
}
.page-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-1);
}
.page-sub {
  font-size: var(--text-sm);
  color: var(--text-3);
}

/* ── Two-column generic split (form + tabla, mapa + panel) */
.split-2 {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--sp-3);
  min-height: 340px;
}
.split-2.wider-side { grid-template-columns: 1fr 380px; }

@media (max-width: 1100px) {
  .split-2,
  .split-2.wider-side { grid-template-columns: 1fr; }
}

/* ── Auth shell (login etc.) ───────────────────────────── */
.auth-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  /* Sin esto, la única columna implícita de un grid sin
     grid-template-columns se dimensiona a su contenido (comportamiento
     tipo max-content) y puede terminar más ancha que el viewport en
     pantallas chicas — empujando toda la página a scrollear
     horizontalmente en vez de que la card se achique. minmax(0, 1fr)
     fuerza un mínimo de 0 para que sí se achique. */
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, var(--electric-dim), transparent 40%),
    radial-gradient(circle at 80% 80%, var(--gps-light), transparent 40%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  /* Refuerzo: los grid items también heredan min-width:auto por
     defecto (= su propio max-content), lo que puede impedir que ESTA
     card se achique aunque la columna de arriba ya se pueda achicar. */
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  box-sizing: border-box;
}

@media (max-width: 420px) {
  .auth-shell { padding: 16px; }
  .auth-card { padding: 28px 20px; }
}
.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.auth-logo img {
  height: 36px;
  filter: var(--logo-filter);
  transition: filter 0.3s ease;
}

/* ── Responsive shell ──────────────────────────────────── */

/* Botón hamburguesa (solo visible en móvil).
   Markup: <button type="button" class="menu-btn" data-sidebar-toggle aria-label="Abrir menú">☰</button> */
.menu-btn {
  display: inline-flex; /* visible en todos los tamaños: abre/cierra el menú */
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  background: var(--surface-3);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  color: var(--text-2);
  font-size: var(--text-xl);
  cursor: pointer;
  padding: 0;
}

/* Overlay que cierra el sidebar en móvil.
   Markup: <div class="sidebar-overlay" data-sidebar-close></div> */
.sidebar-overlay { display: none; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    left: auto;
    height: 100dvh;
    transform: translateX(100%);
    transition: transform 0.25s ease, background 0.3s ease;
    z-index: var(--z-drawer);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 32, 68, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: var(--z-overlay);
  }
  .sidebar-overlay.show {
    opacity: 1;
    pointer-events: auto;
  }

  /* Touch targets más generosos en el nav */
  .nav-item { padding: 12px 16px; }
}

@media (max-width: 600px) {
  .topbar { padding: 0 12px; gap: var(--sp-2); }
  .topbar-title {
    font-size: var(--text-md);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Elementos secundarios que no caben en 375px */
  .topbar-sub,
  .toggle-lbl,
  .live-chip,
  .refresh-live { display: none; }
  .date-select { max-width: 130px; }
  .content { padding: var(--sp-3); }
}

/* ── Barra de carga simulada (patrón 14 de app.js) ────────
   Una por página, justo después de <body>. Fija arriba de todo
   (por encima incluso de modales/popups). Puramente cosmético. */
.page-loader {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  z-index: var(--z-modal);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease 0.1s;
}
.page-loader.is-active { opacity: 1; transition: opacity 0.1s ease; }
.page-loader-bar {
  height: 100%;
  width: 0%;
  background: var(--electric);
  box-shadow: 0 0 8px var(--electric);
  transition: width 0.4s ease;
}

/* ☰ al extremo derecho del topbar (congruente con el login y el sidebar derecho) */
.menu-btn { order: 10; }

/* ── Paneles colapsables (flecha "ocultar", estilo "Ocultar menú") ── */
.panel-collapse {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  color: var(--text-3);
  font-size: var(--text-md);
  line-height: 1;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.15s ease, color 0.15s ease;
}
.panel-collapse:hover { background: var(--surface-3); color: var(--text-1); }
/* flecha apunta hacia abierto (abajo) y rota a cerrado */
[data-collapsible].is-collapsed .panel-collapse { transform: rotate(-90deg); }
[data-collapsible].is-collapsed > .collapsible-body { display: none; }
[data-collapsible].no-anim, [data-collapsible].no-anim * { transition: none !important; }

/* Cabecera slim para paneles sin header propio (Cards) */
.panel-caption {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 6px;
}
.panel-caption-lbl {
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-4);
}
.panel-caption .panel-collapse { margin-left: auto; }

/* Panel lateral (Resumen+Alertas) colapsado → el mapa ocupa todo el ancho */
.split-2.is-collapsed { grid-template-columns: 1fr; }
.split-2.is-collapsed > .side-panel { display: none; }

/* Flecha "ocultar panel" alineada a la derecha en las pestañas de Resumen */
.resumen-tabs .panel-collapse { margin-left: auto; }

/* Botón para reabrir el panel lateral: solo cuando .split-2 está colapsado */
.side-reopen { display: none; }
.split-2.is-collapsed .side-reopen {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 20;
  width: 30px;
  height: 30px;
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  color: var(--text-2);
  font-size: var(--text-lg);
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}
.split-2.is-collapsed .side-reopen:hover { background: var(--surface-3); color: var(--text-1); }

/* Botón "Mapa completo" en el header del mapa (a la derecha) */
.map-full-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-full);
  color: var(--text-2);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.map-full-btn:hover { background: var(--surface-3); color: var(--text-1); }

/* El botón de mapa completo alterna su etiqueta según el estado */
.map-full-btn .mf-label-exit { display: none; }
.content.map-focus .map-full-btn .mf-label-enter { display: none; }
.content.map-focus .map-full-btn .mf-label-exit { display: inline; }

/* ── MODO MAPA: solo el mapa, a pantalla completa ─────────── */
.content.map-focus { padding: 0; gap: 0; }
.content.map-focus > *:not(.split-2) { display: none; }      /* oculta cards y tabla */
.content.map-focus .split-2 {
  grid-template-columns: 1fr;
  flex: 1;
  min-height: 0;
  margin: 0;
}
.content.map-focus .side-panel { display: none; }
.content.map-focus .map-card { height: 100%; border-radius: 0; position: relative; }
.content.map-focus .map-body { min-height: 0; }

/* ── Logo en el topbar (arriba-izquierda, siempre visible) ── */
.topbar-logo {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  margin-right: 6px;
}
.topbar-logo img {
  height: 26px;
  width: auto;
  filter: var(--logo-filter);
  transition: filter 0.3s ease;
}
@media (max-width: 900px) {
  .topbar-logo img { height: 22px; }
}

/* ── Barra flotante de "modo mapa" (traer de vuelta menús/paneles) ──
   Solo visible cuando el mapa está a pantalla completa. */
.map-focus-bar { display: none; }
.content.map-focus .map-focus-bar {
  display: inline-flex;
  gap: 8px;
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 30;
}
.map-focus-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-full);
  color: var(--text-1);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: background 0.15s ease, color 0.15s ease;
}
.map-focus-btn:hover { background: var(--surface-3); }
.map-focus-btn.is-icon {
  padding: 0;
  width: 34px;
  justify-content: center;
  font-size: var(--text-lg);
}

/* ── Modo embebido (dentro del shell de pestañas App.aspx) ──
   La página se carga en un iframe con ?embed=1: se ocultan su
   propio sidebar y topbar (el shell ya da la navegación) y el
   .content ocupa todo el alto/ancho disponible. */
html.is-embedded .sidebar,
html.is-embedded .sidebar-overlay,
html.is-embedded .topbar { display: none !important; }
html.is-embedded .app { height: 100vh; height: 100dvh; }
</content>
