/* ============================================
   云卡栈 - 高级感UI系统 v20.0
   性能体验增强20项（第341-360项）
   总计360项高级感优化
   ============================================ */

/* ========== 341. 图片懒加载 ========== */
.lazy-image {
  background: var(--bg-secondary);
  position: relative;
  overflow: hidden;
}

.lazy-image::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-card) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: lazyShimmer 1.5s infinite;
}

@keyframes lazyShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.lazy-image.loaded::before {
  display: none;
}

.lazy-image img {
  opacity: 0;
  transition: opacity 0.5s ease;
}

.lazy-image.loaded img {
  opacity: 1;
}

/* ========== 342. 无障碍优化 ========== */
:focus-visible {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary-500);
  color: white;
  padding: 8px 16px;
  z-index: 10000;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
  :root {
    --text-primary: #000;
    --text-secondary: #333;
    --border-light: #000;
  }
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========== 344. PWA离线缓存 ========== */
.pwa-install-prompt {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: var(--shadow-2xl);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 9999;
  animation: pwaPromptIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 90%;
}

@keyframes pwaPromptIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.pwa-install-icon {
  font-size: 32px;
}

.pwa-install-info {
  flex: 1;
}

.pwa-install-title {
  font-size: 14px;
  font-weight: 600;
}

.pwa-install-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

.pwa-install-btn {
  padding: 8px 16px;
  background: var(--gradient-primary);
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.pwa-install-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-tertiary);
  font-size: 16px;
}

.offline-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #f59e0b;
  color: white;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  z-index: 10000;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

.offline-indicator.show {
  transform: translateY(0);
}

/* ========== 345. 多语言支持 ========== */
.lang-switcher {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 2px;
}

.lang-option {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-secondary);
}

.lang-option.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ========== 346. 主题定制 ========== */
.theme-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 16px;
}

.theme-color {
  aspect-ratio: 1;
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
  border: 3px solid transparent;
}

.theme-color:hover {
  transform: scale(1.1);
}

.theme-color.active {
  border-color: var(--text-primary);
}

.theme-color.active::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 18px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* ========== 348. 动画GPU加速 ========== */
.gpu-accelerated {
  transform: translateZ(0);
  will-change: transform, opacity;
  backface-visibility: hidden;
  perspective: 1000px;
}

/* ========== 349. 响应式增强 ========== */
/* 平板适配 */
@media (min-width: 768px) and (max-width: 1024px) {
  .app-container {
    max-width: 768px;
    margin: 0 auto;
  }
}

/* 折叠屏适配 */
@media (min-width: 1024px) {
  .app-container {
    max-width: 480px;
    margin: 0 auto;
    box-shadow: var(--shadow-2xl);
    min-height: 100vh;
  }
}

/* 横屏适配 */
@media (orientation: landscape) and (max-height: 500px) {
  .app-header {
    padding: 8px 16px;
  }
  .app-content {
    padding-bottom: 60px;
  }
}

/* ========== 350. 手势操作 ========== */
.swipe-item {
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
}

.swipe-item-content {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  transition: transform 0.3s ease;
}

.swipe-item-actions {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  z-index: 0;
}

.swipe-action {
  width: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 12px;
  cursor: pointer;
}

.swipe-action.delete {
  background: #ef4444;
}

.swipe-action.edit {
  background: #3b82f6;
}

.pull-refresh-container {
  position: relative;
  overflow: hidden;
}

.pull-refresh-indicator {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  transition: top 0.2s ease;
}

.pull-refresh-indicator.show {
  top: 12px;
}

.pull-refresh-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--bg-secondary);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: paymentSpin 0.8s linear infinite;
}

/* ========== 351. 触觉反馈 ========== */
.haptic-btn {
  transition: transform 0.1s ease;
}

.haptic-btn:active {
  transform: scale(0.95);
}

/* ========== 353. 离线模式 ========== */
.offline-mode {
  opacity: 0.7;
  pointer-events: none;
}

.offline-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f59e0b;
  color: white;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
}

/* ========== 355. 错误处理 ========== */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 40px 20px;
  text-align: center;
}

.error-code {
  font-size: 80px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-400), var(--primary-600));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}

.error-title {
  font-size: 20px;
  font-weight: 600;
  margin: 16px 0 8px;
}

.error-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  max-width: 300px;
}

.error-actions {
  display: flex;
  gap: 12px;
}

.error-btn {
  padding: 10px 24px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.error-btn.primary {
  background: var(--gradient-primary);
  color: white;
}

.error-btn.secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.error-illustration {
  font-size: 80px;
  margin-bottom: 16px;
  animation: errorFloat 3s ease-in-out infinite;
}

@keyframes errorFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* ========== 356. 渐进加载 ========== */
.progressive-image {
  position: relative;
  overflow: hidden;
  background: var(--bg-secondary);
}

.progressive-image-placeholder {
  position: absolute;
  inset: 0;
  filter: blur(20px);
  transform: scale(1.1);
  transition: opacity 0.5s ease;
}

.progressive-image.loaded .progressive-image-placeholder {
  opacity: 0;
}

.progressive-image-full {
  position: relative;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.progressive-image.loaded .progressive-image-full {
  opacity: 1;
}

/* ========== 357. 虚拟列表 ========== */
.virtual-list {
  position: relative;
  overflow-y: auto;
  contain: strict;
}

.virtual-list-phantom {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  z-index: -1;
}

.virtual-list-content {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
}

.virtual-list-item {
  position: absolute;
  left: 0;
  right: 0;
  will-change: transform;
}

/* ========== 359. 安全增强 ========== */
/* 防止文本选择（敏感信息） */
.no-select {
  user-select: none;
  -webkit-user-select: none;
}

/* 防止图片拖拽 */
.no-drag {
  -webkit-user-drag: none;
  user-drag: none;
}

/* 敏感信息遮罩 */
.sensitive-mask {
  filter: blur(4px);
  cursor: pointer;
  transition: filter 0.2s ease;
}

.sensitive-mask:hover {
  filter: blur(0);
}

/* ========== 360. 行为埋点 ========== */
/* 点击热区可视化（开发模式） */
[data-track]:hover {
  position: relative;
}

[data-track]:hover::after {
  content: attr(data-track);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 10px;
  white-space: nowrap;
  z-index: 9999;
  pointer-events: none;
}

/* 性能监控指示器 */
.perf-monitor {
  position: fixed;
  bottom: 10px;
  left: 10px;
  background: rgba(0,0,0,0.7);
  color: #10b981;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-family: monospace;
  z-index: 9999;
  pointer-events: none;
}

.perf-monitor .fps {
  color: #10b981;
}

.perf-monitor .fps.low {
  color: #f59e0b;
}

.perf-monitor .fps.critical {
  color: #ef4444;
}

/* 通用性能优化 */
* {
  -webkit-tap-highlight-color: transparent;
}

img {
  content-visibility: auto;
}

/* 滚动性能 */
.scroll-container {
  -webkit-overflow-scrolling: touch;
  overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* 文字渲染优化 */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* 响应式图片 */
img {
  max-width: 100%;
  height: auto;
}

/* 打印优化 */
@media print {
  .no-print {
    display: none !important;
  }
  
  body {
    background: white;
    color: black;
  }
}
