/**
 * PWA-specific styles
 * Styles that only apply when running in PWA mode or for PWA UI elements
 */

/* ============================================================
   PWA SIDEBAR INSTALL BUTTON
   ============================================================ */
#pwa-install-sidebar-item {
  /* Highlight the install button */
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 6px;
  margin: 4px 8px;
  transition: all 0.3s ease;
  cursor: pointer !important;
}

#pwa-install-sidebar-item:hover {
  transform: translateX(4px);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  cursor: pointer !important;
}

#pwa-install-sidebar-item .sidebar-item-label {
  color: #ffffff !important;
  font-weight: 500;
  cursor: pointer !important;
}

#pwa-install-sidebar-item .sidebar-item-icon svg {
  color: #ffffff !important;
  stroke: #ffffff !important;
  cursor: pointer !important;
}

#pwa-install-sidebar-item a {
  padding: 10px 12px !important;
  cursor: pointer !important;
}

#pwa-install-sidebar-item * {
  cursor: pointer !important;
}

/* Animation pulse effect */
@keyframes pulse-pwa {
  0%, 100% {
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  }
  50% {
    box-shadow: 0 2px 16px rgba(102, 126, 234, 0.5);
  }
}

#pwa-install-sidebar-item {
  animation: pulse-pwa 2s ease-in-out infinite;
}

/* ============================================================
   PWA MODE DETECTION - Only applies in standalone mode
   ============================================================ */
@media (display-mode: standalone) {
  body.pwa-mode {
    /* Adjust layout for PWA */
    --bottom-nav-height: 60px;
  }

  /* Hide elements not needed in PWA mode */
  .hidden-in-pwa {
    display: none !important;
  }

  /* Adjust main content area */
  .layout-main-section-wrapper {
    margin-bottom: var(--bottom-nav-height);
  }

  /* Fix for Frappe desk layout */
  .page-container {
    padding-bottom: calc(var(--bottom-nav-height) + 20px) !important;
  }
}

/* ============================================================
   BOTTOM NAVIGATION BAR (PWA Mode)
   ============================================================ */
.pwa-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #ffffff;
  border-top: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  padding: 0 8px;
}

.pwa-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-decoration: none;
  color: #6c757d;
  transition: all 0.2s ease;
  padding: 8px 4px;
  border-radius: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.pwa-nav-item:hover,
.pwa-nav-item:focus {
  background: rgba(0, 102, 204, 0.05);
  color: #0066cc;
  outline: none;
}

.pwa-nav-item.active {
  color: #0066cc;
  font-weight: 600;
}

.pwa-nav-icon {
  width: 24px;
  height: 24px;
  margin-bottom: 4px;
}

.pwa-nav-label {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70px;
}

/* ============================================================
   INSTALL BUTTON (Browser Mode)
   ============================================================ */
.pwa-install-button {
  position: fixed;
  bottom: 80px;
  right: 20px;
  background: #0066cc;
  color: white;
  border: none;
  border-radius: 50px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0, 102, 204, 0.3);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  z-index: 999;
  transition: all 0.3s ease;
  animation: slideInUp 0.5s ease;
}

.pwa-install-button:hover {
  background: #0052a3;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 102, 204, 0.4);
}

.pwa-install-button:active {
  transform: translateY(0);
}

.pwa-install-button.hidden {
  display: none;
}

.pwa-install-button svg {
  width: 20px;
  height: 20px;
}

@keyframes slideInUp {
  from {
    transform: translateY(100px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ============================================================
   MORE MENU POPUP
   ============================================================ */
.pwa-more-menu-content {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 250px;
}

.pwa-menu-item {
  padding: 12px 16px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: #333;
  font-size: 14px;
  text-decoration: none;
  display: block;
  transition: background 0.2s ease;
  border-bottom: 1px solid #f0f0f0;
}

.pwa-menu-item:last-child {
  border-bottom: none;
}

.pwa-menu-item:hover,
.pwa-menu-item:focus {
  background: #f8f9fa;
  outline: none;
}

/* ============================================================
   PWA STATUS INDICATORS
   ============================================================ */
.pwa-status-badge {
  position: fixed;
  top: 60px;
  right: 10px;
  background: #ffc107;
  color: #000;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  z-index: 1001;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  animation: fadeInDown 0.3s ease;
}

.pwa-status-badge.online {
  background: #28a745;
  color: white;
}

.pwa-status-badge.offline {
  background: #ffc107;
  color: #000;
}

@keyframes fadeInDown {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ============================================================
   PULL TO REFRESH INDICATOR
   ============================================================ */
.pwa-pull-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 102, 204, 0.9);
  color: white;
  padding: 8px 16px;
  border-radius: 0 0 20px 20px;
  font-size: 12px;
  z-index: 1002;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.pwa-pull-indicator.active {
  opacity: 1;
}

/* ============================================================
   RESPONSIVE - Mobile optimizations
   ============================================================ */
@media (max-width: 768px) {
  /* Make bottom nav more compact on small screens */
  .pwa-bottom-nav {
    height: 55px;
  }

  .pwa-nav-icon {
    width: 22px;
    height: 22px;
  }

  .pwa-nav-label {
    font-size: 10px;
  }

  /* Install button adjustment */
  .pwa-install-button {
    bottom: 70px;
    right: 15px;
    padding: 10px 16px;
    font-size: 13px;
  }

  .pwa-install-button svg {
    width: 18px;
    height: 18px;
  }
}

@media (min-width: 769px) {
  /* Hide bottom nav on desktop even in PWA mode */
  @media (display-mode: standalone) {
    .pwa-bottom-nav {
      display: none;
    }

    body.pwa-mode {
      --bottom-nav-height: 0;
    }
  }
}

/* ============================================================
   DARK MODE SUPPORT (if Frappe has dark mode)
   ============================================================ */
@media (prefers-color-scheme: dark) {
  .pwa-bottom-nav {
    background: #1a1a1a;
    border-top-color: #333;
  }

  .pwa-nav-item {
    color: #b0b0b0;
  }

  .pwa-nav-item:hover,
  .pwa-nav-item:focus {
    background: rgba(0, 102, 204, 0.2);
    color: #4d9fff;
  }

  .pwa-nav-item.active {
    color: #4d9fff;
  }

  .pwa-menu-item {
    color: #e0e0e0;
    border-bottom-color: #333;
  }

  .pwa-menu-item:hover,
  .pwa-menu-item:focus {
    background: #2a2a2a;
  }
}

/* ============================================================
   LANDSCAPE MODE ADJUSTMENTS
   ============================================================ */
@media (orientation: landscape) and (max-height: 500px) {
  .pwa-bottom-nav {
    height: 50px;
  }

  .pwa-nav-icon {
    width: 20px;
    height: 20px;
    margin-bottom: 2px;
  }

  .pwa-nav-label {
    font-size: 9px;
  }
}

/* ============================================================
   SAFE AREA INSETS (for notched devices)
   ============================================================ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .pwa-bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(60px + env(safe-area-inset-bottom));
  }

  @media (display-mode: standalone) {
    body.pwa-mode {
      --bottom-nav-height: calc(60px + env(safe-area-inset-bottom));
    }
  }
}

/* ============================================================
   LOADING SPINNER FOR PWA
   ============================================================ */
.pwa-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
}

.pwa-spinner {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #0066cc;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ============================================================
   CUSTOM FRAPPE OVERRIDES IN PWA MODE
   ============================================================ */
@media (display-mode: standalone) {
  /* Make forms more mobile-friendly in PWA */
  .form-control {
    font-size: 16px !important; /* Prevent zoom on iOS */
  }

  /* Better spacing for list views */
  .list-row {
    padding: 12px 15px !important;
  }

  /* Larger tap targets */
  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }

  /* Better contrast for buttons */
  .btn-primary {
    background-color: #0066cc !important;
    border-color: #0066cc !important;
  }

  /* Improve modal positioning */
  .modal-dialog {
    margin: 20px auto;
  }

  /* Better mobile sidebar */
  .desk-sidebar {
    width: 280px;
  }
}

/* ============================================================
   PWA-ONLY UTILITY CLASSES
   ============================================================ */
.show-in-pwa-only {
  display: none;
}

@media (display-mode: standalone) {
  .show-in-pwa-only {
    display: block;
  }

  .hide-in-pwa {
    display: none !important;
  }
}
