/**
 * CrowPay - PWA Stylesheet
 * Safe-areas, standalone optimizations, install prompts & native feel
 */

:root {
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

/* 1. Suporte a Standalone e Safe Areas */
html.is-standalone-pwa body {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html.is-standalone-pwa .sx-nav,
html.is-standalone-pwa .appbar-tigger {
  padding-top: calc(var(--sat) + 2px) !important;
}

html.is-standalone-pwa .sx-drawer {
  padding-bottom: calc(var(--sab) + 16px) !important;
}

/* 2. Banner de Instalação PWA */
.crowpay-pwa-banner {
  position: fixed;
  bottom: calc(16px + var(--sab));
  right: 16px;
  max-width: 400px;
  width: calc(100% - 32px);
  background: rgba(18, 16, 24, 0.96);
  border: 1px solid #332742;
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(165, 72, 243, 0.15);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 99999;
  animation: pwaSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  color: #fff;
}

@keyframes pwaSlideUp {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.crowpay-pwa-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
  background: #09070c;
  border: 1px solid #3b3046;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crowpay-pwa-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.crowpay-pwa-info {
  flex: 1;
  min-width: 0;
}

.crowpay-pwa-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
  line-height: 1.25;
  margin-bottom: 2px;
}

.crowpay-pwa-desc {
  font-size: 11px;
  color: #9d94a8;
  line-height: 1.3;
}

.crowpay-pwa-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.crowpay-btn-install {
  background: #a548f3;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.crowpay-btn-install:hover {
  background: #8b16d9;
}

.crowpay-btn-install:active {
  transform: scale(0.96);
}

.crowpay-btn-dismiss {
  background: transparent;
  color: #71687c;
  border: none;
  padding: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 0.15s ease;
}

.crowpay-btn-dismiss:hover {
  color: #fff;
}

/* 3. Modal Guia de Instalação iOS */
.crowpay-ios-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  animation: pwaFadeIn 0.25s ease-out;
}

@keyframes pwaFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.crowpay-ios-modal {
  background: #14101c;
  border: 1px solid #332742;
  border-radius: 20px;
  width: 100%;
  max-width: 440px;
  padding: 24px;
  color: #fff;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.8);
  margin-bottom: var(--sab);
  animation: pwaSheetUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes pwaSheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.crowpay-ios-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.crowpay-ios-steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 22px;
}

.crowpay-ios-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13px;
  line-height: 1.45;
  color: #c8c0d2;
}

.crowpay-ios-step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(165, 72, 243, 0.2);
  color: #bf7dff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.crowpay-ios-step strong {
  color: #fff;
}

/* 4. Notificação de Rede / Atualização */
.crowpay-pwa-toast {
  position: fixed;
  top: calc(16px + var(--sat));
  left: 50%;
  transform: translateX(-50%);
  background: #191424;
  border: 1px solid #3d2f50;
  border-radius: 30px;
  padding: 8px 18px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 100001;
  animation: pwaToastIn 0.3s ease-out;
}

@keyframes pwaToastIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.crowpay-pwa-toast.is-online { border-color: #00bb7f; }
.crowpay-pwa-toast.is-offline { border-color: #f99c00; }

/* 5. Prevenção de duplo clique em botões de formulário */
button.is-submitting {
  opacity: 0.7 !important;
  pointer-events: none !important;
  cursor: wait !important;
}

/* 6. Item de menu PWA (Gaveta / Barra) */
.pwa-install-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: #bf7dff;
  background: rgba(165, 72, 243, 0.1);
  border: 1px solid rgba(165, 72, 243, 0.2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  margin: 6px 12px;
  transition: all 0.15s ease;
}

.pwa-install-menu-item:hover {
  background: rgba(165, 72, 243, 0.2);
  color: #fff;
}

/* Safeguards for small mobile screens (320px - 480px) */
@media (max-width: 480px) {
  .crowpay-pwa-banner {
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    bottom: calc(12px + var(--sab)) !important;
    padding: 12px 14px !important;
  }
  .crowpay-pwa-icon {
    width: 38px !important;
    height: 38px !important;
  }
  .crowpay-pwa-title {
    font-size: 13px !important;
  }
  .crowpay-pwa-desc {
    font-size: 10.5px !important;
  }
  .crowpay-btn-install {
    padding: 6px 12px !important;
    font-size: 11.5px !important;
  }
  .crowpay-ios-modal {
    padding: 18px 16px !important;
  }
}
