/* Estructura y Navegación de la SPA - Café Más Vida */

#app-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height para móviles */
  background-color: var(--bg-secondary);
}

/* Ocultar cabecera y barra de navegación en login y pantallas públicas */
body.login-mode #app-header,
body.login-mode #bottom-nav,
body.kiosk-mode #app-header,
body.kiosk-mode #bottom-nav {
  display: none !important;
}

/* Cabecera Superior */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(var(--spacing-lg), env(safe-area-inset-left, 0px));
  padding-right: max(var(--spacing-lg), env(safe-area-inset-right, 0px));
  padding-bottom: 0;
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
  min-height: calc(60px + env(safe-area-inset-top, 0px));
  box-sizing: border-box;
  flex-shrink: 0;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.brand-logo {
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-crop-container {
  height: 60px;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
}

.logo-img {
  height: 180px;
  width: auto;
  object-fit: contain;
  display: block;
  margin-top: 14px;
}

.brand-name {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.user-section {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  position: relative;
}

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

/* Botón de Avatar */
.btn-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background-color: var(--brand-primary);
  color: var(--text-on-dark);
  border: 2px solid var(--bg-primary);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: var(--transition-fast);
  user-select: none;
}

.btn-avatar:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
}

.btn-avatar:active {
  transform: scale(0.95);
}

.avatar-initials {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #ffffff;
  line-height: 1;
}

/* Punto indicador de estado en Avatar */
.avatar-status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 11px;
  height: 11px;
  border-radius: var(--radius-full);
  background-color: #8e8e93;
  border: 2px solid var(--bg-primary);
  transition: var(--transition-fast);
}

.avatar-status-dot.barista-theme {
  background-color: #34c759;
}

.avatar-status-dot.cajero-theme {
  background-color: #007aff;
}

.avatar-status-dot.no-rol-theme {
  background-color: #8e8e93;
}

/* Dropdown / Popover de Perfil */
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 230px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--spacing-sm);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  animation: dropdown-fade-in 0.15s ease-out forwards;
}

@keyframes dropdown-fade-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.dropdown-user-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-xs) var(--spacing-xs);
}

.dropdown-avatar-circle {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background-color: var(--brand-primary);
  color: var(--text-on-dark);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dropdown-user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dropdown-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-user-email {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-divider {
  height: 1px;
  background-color: var(--border-color);
  margin: var(--spacing-xs) 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-sm);
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition-fast);
  text-align: left;
}

.dropdown-item:hover {
  background-color: var(--bg-secondary);
}

.dropdown-item i,
.dropdown-item svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.btn-dropdown-logout {
  color: var(--highlight-red);
}

.btn-dropdown-logout:hover {
  background-color: rgba(255, 59, 48, 0.08);
}

.btn-dropdown-logout i,
.btn-dropdown-logout svg {
  color: var(--highlight-red);
}

.user-rol {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Tema Sin Rol (Gris) */
.user-rol.no-rol-theme {
  color: #8e8e93;
  background-color: rgba(142, 142, 147, 0.12);
  border: 1px solid rgba(142, 142, 147, 0.35);
}

/* Tema Barista (Verde) */
.user-rol.barista-theme {
  color: #1a7a3a;
  background-color: rgba(52, 199, 89, 0.12);
  border: 1px solid rgba(52, 199, 89, 0.35);
  animation: barista-pulse 3s ease-in-out infinite;
}

/* Tema Cajero (Azul) */
.user-rol.cajero-theme {
  color: #007aff;
  background-color: rgba(0, 122, 255, 0.12);
  border: 1px solid rgba(0, 122, 255, 0.35);
  animation: cajero-pulse 3s ease-in-out infinite;
}

@keyframes barista-pulse {
  0%   { box-shadow: 0 0 0px 0px rgba(52, 199, 89, 0); }
  40%  { box-shadow: 0 0 6px 2px rgba(52, 199, 89, 0.45); }
  60%  { box-shadow: 0 0 6px 2px rgba(52, 199, 89, 0.45); }
  100% { box-shadow: 0 0 0px 0px rgba(52, 199, 89, 0); }
}

@keyframes cajero-pulse {
  0%   { box-shadow: 0 0 0px 0px rgba(0, 122, 255, 0); }
  40%  { box-shadow: 0 0 6px 2px rgba(0, 122, 255, 0.45); }
  60%  { box-shadow: 0 0 6px 2px rgba(0, 122, 255, 0.45); }
  100% { box-shadow: 0 0 0px 0px rgba(0, 122, 255, 0); }
}

.btn-logout,
.btn-sound-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--bg-primary);
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition-fast);
}

.btn-logout:hover {
  background-color: var(--bg-tertiary);
  color: var(--highlight-red);
}

.btn-sound-toggle:hover {
  background-color: var(--bg-tertiary);
  color: var(--brand-primary);
}

/* Contenedor Principal de Vistas */
.app-main {
  flex-grow: 1;
  width: 100%;
  overflow-y: auto;
  position: relative;
  padding-bottom: 72px; /* Margen para no tapar el navbar inferior */
}

/* Barra de Navegación Inferior (Móvil y Escritorio) */
.bottom-nav {
  position: fixed;
  bottom: calc(14px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: fit-content;
  max-width: 95%;
  height: 60px;
  background-color: rgba(255, 255, 255, 0.52); /* Opacidad traslúcida óptima para traslucir texto */
  backdrop-filter: blur(12px) saturate(180%) contrast(105%); /* Blur refinado de 12px para no desaparecer el texto */
  -webkit-backdrop-filter: blur(12px) saturate(180%) contrast(105%);
  border: 1px solid rgba(255, 255, 255, 0.75); /* Resplandor biselado de cristal */
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  z-index: 100;
  flex-shrink: 0;
  border-radius: 9999px; /* Extremos en semicírculo completo */
  box-shadow: 0 12px 32px -4px rgba(0, 0, 0, 0.12), 0 4px 12px -2px rgba(0, 0, 0, 0.06), inset 0 1px 1px rgba(255, 255, 255, 0.9);
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Indicador Circular Desplazable Animado */
.nav-active-pill {
  position: absolute;
  top: 50%;
  left: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  transform: translateY(-50%) translate3d(0, 0, 0);
  transition: transform 0.35s cubic-bezier(0.34, 1.25, 0.64, 1), background-color 0.3s ease, opacity 0.2s ease;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
}

.nav-active-pill.visible {
  opacity: 1;
}

.nav-item {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  text-decoration: none;
  width: 46px;
  height: 46px;
  transition: color 0.2s ease;
  cursor: pointer;
}

.nav-item > span:not(.nav-item-icon-wrapper) {
  display: none;
}

.nav-item-icon-wrapper {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: var(--text-secondary);
  background-color: transparent !important; /* Desactivar fondo estático para usar la píldora animada */
  transition: color 0.2s ease;
}

.nav-item-icon-wrapper i,
.nav-item-icon-wrapper svg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  transform: none !important; /* Sin escalado de tamaño al activar o hover */
}

/* Hover sin alteración de tamaño */
@media (hover: hover) {
  .nav-item:hover .nav-item-icon-wrapper {
    color: var(--text-primary);
  }
}

/* Colores Temáticos para el Icono de cada Pestaña Activa */
.nav-item[href="#/ventas"].active .nav-item-icon-wrapper { color: #b25e1a; }
.nav-item[href="#/suscripciones"].active .nav-item-icon-wrapper { color: #0b7a6f; }
.nav-item[href="#/pendientes"].active .nav-item-icon-wrapper { color: #c2410c; }
.nav-item[href="#/roles"].active .nav-item-icon-wrapper { color: #1d4ed8; }
.nav-item[href="#/finanzas"].active .nav-item-icon-wrapper { color: #15803d; }

/* Badge Circular de Pendientes en Barra de Navegación */
.nav-badge-pendientes {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background-color: #000000;
  color: #ffffff;
  font-size: 10px;
  font-family: var(--font-sans);
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-sizing: border-box;
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
  user-select: none;
  white-space: nowrap;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
  transform: scale(1);
}

.nav-badge-pendientes.hidden {
  display: none !important;
}

/* Responsividad para pantallas medianas/grandes (Layout Escritorio Horizontal) */
@media (min-width: 768px) {
  .app-main {
    max-width: 1400px;
    margin: 0 auto;
    padding-left: 24px;
    padding-right: 24px;
    padding-bottom: 84px;
    border-left: none;
    border-right: none;
    background-color: transparent;
    box-shadow: none;
    box-sizing: border-box;
  }
  
  .bottom-nav {
    bottom: 20px;
    height: 54px;
    padding: 0 16px;
    gap: 10px;
    background-color: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.85);
    box-shadow: 0 16px 36px -6px rgba(0, 0, 0, 0.15), 0 4px 12px -2px rgba(0, 0, 0, 0.08);
  }

  .nav-item {
    width: auto;
    padding: 0 14px;
    gap: 6px;
    border-radius: var(--radius-full);
  }

  .nav-item > span:not(.nav-item-icon-wrapper) {
    display: inline-block;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: -0.2px;
  }

  .app-header {
    max-width: 1400px;
    margin: 0 auto;
    padding-left: 24px;
    padding-right: 24px;
    width: 100%;
    border-left: none;
    border-right: none;
  }
}

