/**
 * PWA Polish - CSS Base
 * Safe areas, overscroll, standalone mode, transiciones
 */

/* ============================
   SAFE AREAS + STATUS BAR COLOR
   ============================ */

:root {
  --pwa-theme-color: #5e72e4;
}

@media (display-mode: standalone) {

  /* Barra de estado coloreada: overlay fijo que cubre el area del notch/status bar */
  body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: env(safe-area-inset-top, 0px);
    background: var(--pwa-theme-color, #5e72e4);
    z-index: 99999;
    pointer-events: none;
  }

  /* Navbar superior - respetar notch / Dynamic Island */
  .navbar,
  .sidenav-header,
  .main-content .navbar {
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
  }

  /* Barra inferior / tab bar */
  .footer,
  .fixed-bottom,
  .pwa-bottom-bar {
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
  }

  /* Botones flotantes (FAB) */
  .btn-floating,
  .fab,
  .whatsapp-btn,
  [class*="fixed-bottom"] .btn {
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  /* Containers - paddings laterales con safe area */
  .container,
  .container-fluid {
    padding-left: calc(15px + env(safe-area-inset-left, 0px));
    padding-right: calc(15px + env(safe-area-inset-right, 0px));
  }

  /* Body padding para standalone */
  body {
    padding-top: env(safe-area-inset-top, 0px);
  }
}

/* ============================
   OVERSCROLL BEHAVIOR
   ============================ */

html, body {
  overscroll-behavior-y: contain;
}

/* ============================
   STANDALONE MODE ADJUSTMENTS
   ============================ */

@media (display-mode: standalone) {
  /* Ocultar elementos que no aplican en modo app */
  .browser-only {
    display: none !important;
  }

  /* Mejorar touch targets para movil */
  .nav-link,
  .list-group-item,
  .dropdown-item {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* ============================
   PULL-TO-REFRESH INDICATOR
   ============================ */

.ptr-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-60px);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  transition: transform 0.2s ease;
  pointer-events: none;
}

.ptr-indicator.visible {
  transform: translateX(-50%) translateY(20px);
}

@media (display-mode: standalone) {
  .ptr-indicator.visible {
    transform: translateX(-50%) translateY(calc(20px + env(safe-area-inset-top, 0px)));
  }
}

.ptr-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
}

.ptr-spinner.spinning {
  animation: ptr-spin 0.6s linear infinite;
}

@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}

/* ============================
   FADE-IN PAGE TRANSITION
   ============================ */

body {
  animation: pwa-fade-in 0.2s ease-out;
}

@keyframes pwa-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Progress bar superior (feedback de navegacion) */
.pwa-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, #5e72e4, #825ee4);
  z-index: 99999;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
  width: 100%;
  pointer-events: none;
}

.pwa-progress-bar.loading {
  transform: scaleX(0.7);
  transition: transform 8s cubic-bezier(0.1, 0.05, 0, 1);
}

.pwa-progress-bar.done {
  transform: scaleX(1);
  transition: transform 0.2s ease;
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.3s ease 0.2s;
}

/* Feedback tactil en enlaces de navegacion */
.nav-link:active,
.sidenav .nav-link:active,
.list-group-item:active {
  transform: scale(0.97);
  opacity: 0.8;
  transition: transform 0.1s ease, opacity 0.1s ease;
}

/* ============================
   PWA INSTALL BANNER
   ============================ */

.pwa-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  color: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-left: 40px;
  z-index: 99998;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.12);
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

.pwa-banner--visible {
  transform: translateY(0);
}

.pwa-banner__close {
  position: absolute;
  top: 50%;
  left: 10px;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: #999;
  cursor: pointer;
  padding: 4px;
}

.pwa-banner__close:hover {
  color: #333;
}

.pwa-banner__content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.pwa-banner__icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  object-fit: cover;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.pwa-banner__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.pwa-banner__text strong {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a2e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pwa-banner__text span {
  font-size: 12px;
  color: #777;
  white-space: normal;
  line-height: 1.4;
}

.pwa-banner__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: 12px;
}

.pwa-banner__btn {
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.2s;
}

.pwa-banner__btn:active {
  opacity: 0.7;
}

.pwa-banner__btn--install {
  background: #5e72e4;
  color: #fff;
}

.pwa-banner__btn--dismiss {
  background: transparent;
  color: #999;
  padding: 8px 10px;
}
