/* ============================================================================
   Layout Mobile-First (360px -> 768px -> 1024px -> 1440px -> 1920px+)
   ============================================================================ */

app-shell {
  display: block;
  min-height: 100dvh;
}

app-shell[hidden],
.auth-screen[hidden],
.nav-item[hidden] {
  display: none;
}

/* Pantalla dedicada de Login (antes de iniciar sesión, cero menú operativo) */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: var(--space-6) var(--space-4);
  gap: var(--space-5);
}

.auth-box {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.auth-brand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.auth-brand-mark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
}

.auth-logo-square {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--accent-primary);
  color: var(--ink-on-accent);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
}

.shell-grid {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100dvh;
  padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
}

/* Barra lateral (oculta como rail en móvil, visible como bottom-bar fija deslizable) */
.shell-nav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow-x: auto;
  gap: var(--space-1);
  height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  padding: var(--space-1) var(--space-2) env(safe-area-inset-bottom, 0px);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-hairline);
}

.shell-brand {
  display: none;
}

.nav-item {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  gap: 2px;
  min-width: 60px;
  min-height: var(--touch-min);
  padding: var(--space-1) var(--space-2);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease-out-expo),
              color var(--dur-fast) var(--ease-out-expo),
              transform var(--dur-fast) var(--ease-out-expo);
}

.nav-item:hover {
  background: var(--bg-subtle);
  color: var(--ink-primary);
}

.nav-item[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-primary);
}

.nav-item svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Columna principal fluida */
.shell-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-hairline);
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.topbar-title {
  font-size: var(--text-lg);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.workspace-content {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  container-type: inline-size;
  container-name: workspace;
}

/* Panel lateral "Ticket Vivo" */
.shell-ticket {
  display: none;
}

.shell-ticket.is-open-mobile {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg-canvas);
  padding: var(--space-4);
  overflow-y: auto;
}

/* Grids adaptativos mediante Container Queries */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

.two-col-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

@container workspace (min-width: 520px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@container workspace (min-width: 820px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .two-col-grid {
    grid-template-columns: 1.15fr 0.85fr;
    align-items: start;
  }
}

/* Tablet (>= 768px): Rail lateral de 72px */
@media (min-width: 768px) {
  .shell-grid {
    grid-template-columns: var(--rail-width) minmax(0, 1fr);
    padding-bottom: 0;
  }

  .shell-nav {
    position: sticky;
    top: 0;
    inset-inline: auto;
    bottom: auto;
    height: 100dvh;
    width: var(--rail-width);
    overflow-y: auto;
    overflow-x: hidden;
    flex-direction: column;
    justify-content: flex-start;
    padding: var(--space-4) var(--space-2);
    gap: var(--space-2);
    border-top: 0;
    border-right: 1px solid var(--border-hairline);
  }

  .shell-brand {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-bottom: var(--space-2);
    border-radius: var(--radius-md);
    background: var(--accent-primary);
    color: var(--ink-on-accent);
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.25rem;
  }

  .nav-item {
    width: 56px;
    height: 54px;
  }

  .nav-label {
    font-size: 0.68rem;
  }

  .topbar {
    padding: var(--space-4) var(--space-6);
  }

  .workspace-content {
    padding: var(--space-6);
  }
}

/* Escritorio (>= 1024px): Sidebar completo con etiquetas claras + workspace + Ticket Vivo */
@media (min-width: 1024px) {
  .shell-grid {
    grid-template-columns: 224px minmax(0, 1fr);
  }

  .shell-nav {
    width: 224px;
    align-items: stretch;
    padding: var(--space-4) var(--space-3);
    gap: 4px;
  }

  .shell-brand {
    width: 100%;
    height: 44px;
    justify-content: flex-start;
    padding: 0 var(--space-3);
    margin-bottom: var(--space-3);
  }

  .nav-item {
    width: 100%;
    height: 44px;
    min-height: 44px;
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-3);
    padding: 0 var(--space-3);
  }

  .nav-label {
    font-size: var(--text-sm);
  }
}

/* Escritorio amplio (>= 1240px): Cuadrícula de 3 zonas (Sidebar 224px + 1fr + Ticket Vivo 380px) */
@media (min-width: 1240px) {
  .shell-grid {
    grid-template-columns: 224px minmax(0, 1fr) var(--ticket-width);
  }

  .shell-grid.ticket-collapsed {
    grid-template-columns: 224px minmax(0, 1fr) 0px;
  }

  .shell-ticket {
    display: block;
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
    padding: var(--space-5);
    background: var(--bg-subtle);
    border-left: 1px solid var(--border-hairline);
  }

  .shell-grid.ticket-collapsed .shell-ticket {
    display: none;
  }
}

.site-footer {
  margin-top: auto;
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-hairline);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

