/* ========================================
   PWA样式
   安装按钮 + 离线模式 + 独立应用模式
   ======================================== */

/* ===== PWA安装按钮 ===== */
.pwa-install-button {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.5rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 999px;
  font-size: 0.9375rem;
  font-weight: 600;
  box-shadow: 
    0 4px 20px rgba(102, 126, 234, 0.4),
    0 0 0 0 rgba(102, 126, 234, 0.4);
  cursor: pointer;
  z-index: 9999;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: pulse-install 2s infinite;
}

.pwa-install-button:hover {
  transform: translateX(-50%) translateY(-2px);
  box-shadow: 
    0 6px 30px rgba(102, 126, 234, 0.5),
    0 0 0 8px rgba(102, 126, 234, 0.1);
}

.pwa-install-button:active {
  transform: translateX(-50%) translateY(0);
}

.pwa-install-button svg {
  width: 20px;
  height: 20px;
}

@keyframes pulse-install {
  0%, 100% {
    box-shadow: 
      0 4px 20px rgba(102, 126, 234, 0.4),
      0 0 0 0 rgba(102, 126, 234, 0.4);
  }
  50% {
    box-shadow: 
      0 4px 20px rgba(102, 126, 234, 0.4),
      0 0 0 20px rgba(102, 126, 234, 0);
  }
}

/* ===== 独立应用模式 ===== */
body.standalone-mode {
  /* 添加顶部安全区域 */
  padding-top: env(safe-area-inset-top);
}

body.standalone-mode .mobile-header {
  top: env(safe-area-inset-top);
}

/* 隐藏某些元素 */
body.standalone-mode .pwa-install-button {
  display: none !important;
}

/* ===== 离线模式 ===== */
body.offline-mode {
  position: relative;
}

body.offline-mode::before {
  content: '⚠️ 离线模式';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 0.5rem;
  background: #f59e0b;
  color: white;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  z-index: 10001;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(0);
  }
}

body.offline-mode .main {
  margin-top: 2.5rem;
}

/* 离线时禁用某些功能 */
body.offline-mode button:not(.offline-safe),
body.offline-mode a[href^="http"]:not(.offline-safe) {
  opacity: 0.5;
  pointer-events: none;
  position: relative;
}

body.offline-mode button:not(.offline-safe)::after,
body.offline-mode a[href^="http"]:not(.offline-safe)::after {
  content: '离线不可用';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

body.offline-mode button:not(.offline-safe):hover::after,
body.offline-mode a[href^="http"]:not(.offline-safe):hover::after {
  opacity: 1;
}

/* ===== 更新提示 ===== */
.update-notification {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  max-width: 320px;
  padding: 1rem 1.25rem;
  background: rgba(16, 185, 129, 0.95);
  backdrop-filter: blur(10px);
  color: white;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  z-index: 10000;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.update-notification.show {
  transform: translateY(0);
  opacity: 1;
}

.update-notification-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.update-notification-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.update-notification button {
  flex: 1;
  padding: 0.5rem;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.update-notification .btn-primary {
  background: white;
  color: #10b981;
}

.update-notification .btn-secondary {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

/* ===== 安装成功动画 ===== */
@keyframes installSuccess {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.install-success-badge {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100px;
  height: 100px;
  background: #10b981;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  animation: installSuccess 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.install-success-badge svg {
  width: 60px;
  height: 60px;
  stroke: white;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===== 移动端优化 ===== */
@media (max-width: 768px) {
  .pwa-install-button {
    bottom: 5rem;
    font-size: 0.875rem;
    padding: 0.75rem 1.25rem;
  }
  
  .update-notification {
    bottom: 5rem;
    right: 1rem;
    left: 1rem;
    max-width: none;
  }
  
  body.offline-mode::before {
    padding-top: env(safe-area-inset-top);
  }
}

/* ===== 打印模式 ===== */
@media print {
  .pwa-install-button,
  .update-notification,
  body.offline-mode::before {
    display: none !important;
  }
}

/* ===== iOS特定样式 ===== */
@supports (-webkit-touch-callout: none) {
  .pwa-install-button {
    /* iOS Safari专用样式 */
    -webkit-backdrop-filter: blur(10px);
  }
  
  body.standalone-mode {
    /* iOS独立应用模式 */
    padding-top: max(20px, env(safe-area-inset-top));
  }
}

/* ===== Android特定样式 ===== */
@media (display-mode: standalone) {
  body {
    /* Android独立应用模式 */
    background: var(--bg-start);
  }
}

/* ===== 加载骨架屏（离线时显示）===== */
.offline-skeleton {
  display: none;
}

body.offline-mode .offline-skeleton {
  display: block;
  padding: 2rem;
}

.skeleton-card {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.1) 0%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0.1) 100%
  );
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
  border-radius: 12px;
  height: 200px;
  margin-bottom: 1rem;
}
