/* ============================================================
   3C关键部件价格监控看板 — 自定义样式
   主题：macOS 风格浅色
   适配：Windows 11 / macOS / Android / iOS
   ============================================================ */

/* ---------- 全局基础 ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
}

body {
  background-color: #f5f5f7;
  color: #1d1d1f;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  min-height: 100dvh;
}

/* ---------- 演示模式提示条 ---------- */
.demo-banner {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  background: rgba(245, 158, 11, 0.08);
  border-bottom: 1px solid rgba(245, 158, 11, 0.2);
  font-size: 12px;
  color: #6b7280;
  position: relative;
}

.demo-banner-close {
  margin-left: auto;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  min-width: 28px;
  min-height: 28px;
  box-sizing: content-box;
}

.demo-banner-close:hover {
  color: #6b7280;
  background: rgba(0, 0, 0, 0.06);
}

/* ---------- 顶部导航栏 ---------- */
.header-bar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* ---------- 运行状态指示灯 ---------- */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-demo {
  background: #f59e0b;
  animation: dot-pulse 2.5s ease-in-out infinite;
}

.status-live {
  background: #22c55e;
  animation: dot-pulse 2s ease-in-out infinite;
}

.status-error {
  background: #ef4444;
}

@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ---------- 统计卡片 ---------- */
.stat-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  will-change: transform;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
}

/* ---------- 图表容器 ---------- */
.chart-wrapper {
  position: relative;
  height: 400px;
  width: 100%;
}

@media (max-width: 640px) {
  .chart-wrapper {
    height: 250px;
  }
}

.chart-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#chart-ph-error {
  pointer-events: auto;
}

/* ---------- 时间范围按钮 ---------- */
.time-btn {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
  min-height: 32px;
  min-width: 44px;
}

.time-btn:hover {
  color: #1d1d1f;
  background-color: #e5e7eb;
}

.time-btn.active {
  color: #000000;
  background-color: #f59e0b;
  font-weight: 600;
}

/* ---------- 播放按钮 ---------- */
.play-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background-color: #f59e0b;
  color: #000;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  min-height: 36px;
  min-width: 72px;
  transition: background 0.18s ease, box-shadow 0.18s ease;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.play-btn:hover {
  background-color: #fbbf24;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.3);
}

@keyframes pulse-ring {
  0%   { transform: scale(1);   opacity: 0.7; }
  80%  { transform: scale(1.6); opacity: 0;   }
  100% { transform: scale(1.6); opacity: 0;   }
}

.play-btn.is-playing::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 10px;
  border: 2px solid #f59e0b;
  animation: pulse-ring 1.4s ease-out infinite;
  pointer-events: none;
}

/* ---------- 部件输入框（iOS防缩放：font-size >= 16px） ---------- */
.component-input {
  font-size: 16px !important;
  padding: 10px 12px 10px 36px;
  background-color: #f9fafb;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  color: #1d1d1f;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
  width: 100%;
}

.component-input::placeholder {
  color: #9ca3af;
  font-size: 14px;
}

.component-input:focus {
  border-color: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
  background-color: #ffffff;
}

/* ---------- 添加按钮 ---------- */
.add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background-color: #f59e0b;
  color: #000;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
  min-width: 80px;
  white-space: nowrap;
  transition: background 0.18s ease;
  flex-shrink: 0;
}

.add-btn:hover {
  background-color: #fbbf24;
}

.add-btn:active {
  background-color: #d97706;
  transform: scale(0.97);
}

/* ---------- 搜索建议下拉 ---------- */
.search-suggestions {
  margin-bottom: 12px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  animation: suggestions-in 0.15s ease;
}

@keyframes suggestions-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.search-suggestions.hidden {
  display: none;
}

.suggestion-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid #f3f4f6;
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover {
  background: rgba(245, 158, 11, 0.05);
}

.suggestion-item:active {
  background: rgba(245, 158, 11, 0.1);
  transform: scale(0.99);
}

.suggestion-type-badge {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.suggestion-name {
  font-size: 13px;
  font-weight: 600;
  color: #1d1d1f;
}

.suggestion-meta {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 1px;
}

.suggestion-price {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
  color: #1d1d1f;
  white-space: nowrap;
}

/* ---------- 快捷预设按钮 ---------- */
.preset-btn {
  background: none;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  cursor: pointer;
  padding: 3px 8px;
  font-size: 11px;
  font-family: inherit;
  color: #6b7280;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
  min-height: 28px;
}

.preset-btn:hover {
  border-color: #f59e0b;
  color: #92400e;
  background: rgba(245, 158, 11, 0.06);
}

/* ---------- 部件卡片 ---------- */
.component-card {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 14px 14px 12px;
  position: relative;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  will-change: transform;
}

.component-card:hover {
  border-color: #d1d5db;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.component-card:active {
  transform: scale(0.98);
}

/* 激活状态 */
.component-card.active {
  border-color: var(--card-line, #f59e0b);
}

.component-card.active::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: var(--card-fill, rgba(245, 158, 11, 0.04));
  pointer-events: none;
}

/* ---------- 链接已更替标识 ---------- */
.healed-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 999px;
  font-size: 10px;
  color: #2563eb;
  white-space: nowrap;
}

/* ---------- 删除按钮 ---------- */
.delete-btn {
  width: 24px;
  height: 24px;
  padding: 10px;
  margin: -10px;
  position: absolute;
  top: 14px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #9ca3af;
  background: transparent;
  border: none;
  outline: none;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease;
  z-index: 1;
  box-sizing: content-box;
  line-height: 1;
}

.delete-btn:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* ---------- 价格涨跌颜色 ---------- */
.text-gain { color: #ef4444; } /* 红 = 涨价 */
.text-loss { color: #22c55e; } /* 绿 = 降价（对消费者有利！） */
.text-flat { color: #6b7280; }

.badge-gain { background: rgba(239, 68, 68, 0.10); }
.badge-loss { background: rgba(34, 197, 94, 0.10); }
.badge-flat { background: rgba(107, 114, 128, 0.10); }

/* ---------- 活跃指示点 ---------- */
.active-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f59e0b;
  flex-shrink: 0;
  animation: dot-pulse 2s ease-in-out infinite;
}

/* ---------- 图例标签 ---------- */
.legend-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 11px;
  color: #374151;
  cursor: pointer;
  transition: background 0.18s ease, opacity 0.18s ease;
  white-space: nowrap;
  user-select: none;
}

.legend-tag:hover {
  background: rgba(0, 0, 0, 0.08);
}

.chart-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---------- Toast 通知 ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  max-width: calc(100vw - 32px);
  white-space: nowrap;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  color: #1d1d1f;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: #22c55e; }
.toast.error   { border-color: #ef4444; }
.toast.info    { border-color: #f59e0b; }

/* ---------- 自愈记录条目 ---------- */
.recovery-item {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  background: #f9fafb;
  border: 1px solid #f3f4f6;
  border-radius: 8px;
}

.recovery-item-icon {
  color: #3b82f6;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ---------- 骨架加载动画 ---------- */
@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position:  400px 0; }
}

.skeleton {
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
  background-size: 800px 100%;
  animation: shimmer 1.6s infinite linear;
  border-radius: 4px;
}

/* ---------- 滚动条美化（非iOS） ---------- */
::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: #f5f5f7; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ---------- 无障碍：键盘焦点 ---------- */
button:focus-visible,
input:focus-visible {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
}

/* ---------- 移动端专项优化 ---------- */
@media (max-width: 640px) {
  .time-btn {
    padding: 6px 8px;
    min-height: 38px;
    font-size: 12px;
  }

  #stat-total,
  #stat-days,
  #stat-max-rise,
  #stat-max-drop {
    font-size: 1.35rem;
  }

  #chart-panel,
  #watchlist-panel {
    padding: 12px;
  }

  .toast {
    bottom: max(24px, env(safe-area-inset-bottom, 24px));
  }

  main {
    padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  }
}
