/* ===== 自选股价格监控 PWA - 全局样式 ===== */

/* --- CSS 变量 / 主题 --- */
:root {
  /* 深色主题 (默认) */
  --bg: #121212;
  --bg-card: #1e1e1e;
  --bg-input: #2a2a2a;
  --border: #2a2a2a;
  --text: #e0e0e0;
  --text-secondary: #888;
  --text-muted: #555;
  --accent: #00c48c;
  --accent-bg: rgba(0,196,140,0.1);
  --up-color: #ef4444;    /* A股涨红 */
  --down-color: #22c55e;  /* A股跌绿 */
  --danger: #ef4444;
  --danger-bg: rgba(239,68,68,0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245,158,11,0.1);
  --shadow: none;
  --card-radius: 12px;
  --font-mono: 'Consolas', 'Courier New', 'SF Mono', monospace;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --bg-card: #ffffff;
  --bg-input: #f0f0f0;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-secondary: #666;
  --text-muted: #aaa;
  --accent: #00a878;
  --accent-bg: rgba(0,168,120,0.08);
  --up-color: #dc2626;
  --down-color: #16a34a;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* --- 全局重置 --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* --- 页面容器 --- */
.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  padding-bottom: 80px;
  -webkit-overflow-scrolling: touch;
}
.page.active {
  display: block;
}

/* --- 页面头部 --- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  flex-shrink: 0;
}
.page-title {
  font-size: 20px;
  font-weight: 700;
}
.page-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.header-actions {
  display: flex;
  gap: 8px;
}

/* --- 底部导航 --- */
.bottom-nav {
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0 4px;
  font-size: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s;
  border: none;
  background: none;
}
.nav-item svg {
  width: 24px;
  height: 24px;
  margin-bottom: 2px;
}
.nav-item.active {
  color: var(--accent);
}

/* --- 按钮 --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  transition: all 0.2s;
  white-space: nowrap;
}
.btn:active {
  transform: scale(0.96);
}
.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
}
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

/* --- 股票卡片 --- */
.stock-card {
  background: var(--bg-card);
  border-radius: var(--card-radius);
  border: 1px solid var(--border);
  padding: 10px 12px;
  margin-bottom: 10px;
  position: relative;
  box-shadow: var(--shadow);
  transition: border-color 0.3s;
}
.stock-card.confirming-delete {
  border-color: var(--danger);
  background: var(--danger-bg);
}
.stock-card.confirming-move {
  border-color: var(--warning);
  background: var(--warning-bg);
}

/* 卡片头部 */
.stock-card .card-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.stock-card .card-left {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.stock-card .card-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 股票信息 */
.stock-card .stock-info-main {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.stock-card .stock-name {
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  color: #4da6ff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stock-card .stock-code {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* 涨跌幅纯文字 */
.change-text {
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font-mono);
  white-space: nowrap;
}
.change-text.up { color: var(--up-color); }
.change-text.down { color: var(--down-color); }
.change-text.zero { color: var(--text-secondary); }

/* 操作按钮 */
.stock-card .card-actions {
  display: flex;
  gap: 2px;
}
.stock-card .card-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 16px;
  border-radius: 4px;
}
.stock-card .card-actions button:active { background: var(--bg-input); }

/* 数据行 - 4列 */
.stock-data-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  margin: 0 -2px;
}
.data-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  padding: 0 2px;
  text-align: center;
  border-right: 1px solid var(--border);
}
.data-col:last-child { border-right: none; }
.data-col .data-label {
  font-size: 10px;
  color: var(--text-secondary);
}
.data-col .data-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}
.data-value.bold { font-weight: 700; }

/* 底部 */
.card-footer-compact {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--text-secondary);
  padding-top: 6px;
  border-top: 1px solid var(--border);
  margin-top: 2px;
}
.stock-time {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 11px;
}
.stock-note {
  background: rgba(128,128,128,0.12);
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  cursor: pointer;
  font-size: 11px;
  max-width: 100%;
}

/* 实时倍数 - 灰底红色加粗 */
.data-badge-multiple {
  display: inline-block;
  background: rgba(128,128,128,0.15);
  border-radius: 4px;
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  color: var(--up-color);
}
}

/* --- 空状态 --- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.4;
}
.empty-state p {
  font-size: 14px;
  line-height: 1.6;
}

/* --- 加载 & 错误 --- */
.loading-indicator {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
  font-size: 13px;
}
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-text {
  color: var(--danger);
  font-size: 12px;
  padding: 4px 0;
}
.inline-msg {
  text-align: center;
  padding: 8px;
  font-size: 12px;
  border-radius: 8px;
  margin: 4px 0;
}
.inline-msg.success { background: var(--accent-bg); color: var(--accent); }
.inline-msg.error { background: var(--danger-bg); color: var(--danger); }

/* --- 模态弹窗 --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.show {
  display: flex;
}
.modal {
  background: var(--bg-card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}
.modal .form-group {
  margin-bottom: 14px;
}
.modal .form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.modal .form-group input,
.modal .form-group textarea,
.modal .form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.modal .form-group input:focus,
.modal .form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.modal .form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.modal .form-actions .btn {
  flex: 1;
}

/* --- 个股详情页 --- */
.detail-page {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: none;
  flex-direction: column;
  width: 100%;
  max-width: none;
  margin: 0;
  left: 0;
  transform: none;
}
.detail-page.show {
  display: flex;
}
.detail-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.detail-header .back-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}
.detail-header .stock-info {
  flex: 1;
}
.detail-header .stock-info .name {
  font-size: 20px;
  font-weight: 700;
}
.detail-header .stock-info .code {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}
.header-price {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
  margin-left: auto;
}
.header-price-value {
  font-size: 22px;
  font-weight: 800;
  font-family: var(--font-mono);
  line-height: 1.1;
}
.header-price-change {
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-mono);
  line-height: 1.2;
}
.detail-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px 80px;
  -webkit-overflow-scrolling: touch;
}
.detail-price {
  text-align: center;
  padding: 12px 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
}
.detail-price .price {
  font-size: 42px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.detail-price .price.up { color: var(--up-color); }
.detail-price .price.down { color: var(--down-color); }
.detail-price .change {
  font-size: 16px;
  font-family: var(--font-mono);
}
.chart-container {
  width: 100%;
  height: 55vh;
  min-height: 380px;
  margin: 0;
  background: var(--bg-card);
  border-radius: var(--card-radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* K线上方指标面板 */
.chart-before {
  margin: 0 0 8px;
}
.chart-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-card);
  border-radius: var(--card-radius) var(--card-radius) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  gap: 4px;
}
.indicator-panel {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

/* 指标面板每一行 */
.ind-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.ind-line-date {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 2px;
}
.ind-line-quote { gap: 10px; }
.ind-line-ma { gap: 6px; }
.ind-line-boll { gap: 8px; }
.ind-line-macd { gap: 8px; }

/* 指标标签 */
.ind-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 3px 7px;
  background: var(--bg-input);
  border-radius: 4px;
  white-space: nowrap;
  line-height: 1.5;
}
.ind-tag b {
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
}
.ind-tag-close, .ind-tag-change, .ind-tag-vol {
  font-size: 13px;
  padding: 4px 9px;
}
.ind-tag-close b, .ind-tag-change b, .ind-tag-vol b {
  font-size: 15px;
}
.ind-tag-change b {
  font-size: 15px;
}

/* 锁定按钮 */
.zoom-lock-badge {
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  padding: 6px 12px;
  background: var(--bg-input);
  border-radius: 6px;
  user-select: none;
  -webkit-user-select: none;
  border: 1px solid transparent;
  transition: all 0.2s;
}
.zoom-lock-badge:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.zoom-lock-badge.locked {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger);
}
.chart-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--bg-card);
  border-radius: 0 0 var(--card-radius) var(--card-radius);
  border: 1px solid var(--border);
  border-top: none;
}
.chart-hint {
  font-size: 11px;
  color: var(--text-muted);
}
.ai-section {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--card-radius);
  border: 1px solid var(--border);
}
.ai-section h4 {
  font-size: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-result {
  font-size: 13px;
  line-height: 1.7;
  max-height: 400px;
  overflow-y: auto;
}
.ai-result p { margin-bottom: 8px; }
.ai-result strong { color: var(--accent); }

/* AI分析结果样式 */
.ai-main-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  margin: 12px 0 8px 0;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.ai-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 10px 0 6px 0;
}
.ai-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12px;
}
.ai-table th {
  padding: 6px 8px;
  background: var(--bg-input);
  font-weight: 600;
  color: var(--accent);
  text-align: left;
  border: 1px solid var(--border);
}
.ai-table td {
  padding: 6px 8px;
  border: 1px solid var(--border);
  text-align: left;
}
.ai-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}
.ai-list {
  margin: 8px 0;
  padding-left: 16px;
}
.ai-list li {
  margin: 4px 0;
  color: var(--text-secondary);
}
.ai-quote {
  margin: 10px 0;
  padding: 10px 12px;
  background: var(--bg-input);
  border-left: 3px solid var(--accent);
  font-size: 12px;
  color: var(--text-secondary);
}
.ai-loading {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
}

/* --- 设置页 --- */
.settings-section {
  margin-bottom: 24px;
}
.settings-section h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--accent);
}
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.settings-item .label {
  font-size: 14px;
}
.settings-item .value {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}
.settings-item input[type="number"] {
  width: 80px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-mono);
  text-align: center;
}
.settings-item input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* Toggle 开关 */
.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  background: var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.3s;
}
.toggle.active {
  background: var(--accent);
}
.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s;
}
.toggle.active::after {
  transform: translateX(20px);
}

/* 时间标签 */
.time-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.time-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-family: var(--font-mono);
  background: var(--bg-input);
  border: 1px solid var(--border);
}
.time-chip .remove-time {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
}
.add-time-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.add-time-row input {
  width: 60px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-mono);
  text-align: center;
}

/* CSV 导入 */
.csv-preview {
  background: var(--bg-card);
  border-radius: var(--card-radius);
  border: 1px solid var(--border);
  padding: 16px;
  margin: 16px 0;
}
.csv-preview table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
}
.csv-preview th,
.csv-preview td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.csv-preview th {
  color: var(--text-secondary);
  font-weight: 600;
}
.csv-preview .import-stats {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* 下拉刷新 */
.pull-indicator {
  text-align: center;
  padding: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

/* 滚动条 */
::-webkit-scrollbar { width: 0; }

/* iOS 安全区域适配 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav { padding-bottom: env(safe-area-inset-bottom); }
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 300;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  animation: toastIn 0.3s ease;
  max-width: 90%;
  text-align: center;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.toast.success { border-color: var(--accent); color: var(--accent); }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.toast-long {
  max-height: 200px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.5;
}

/* 备注弹窗 */
.note-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.note-dialog-content {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  margin: 20px;
  max-width: 90%;
  max-height: 70vh;
  overflow-y: auto;
  border: 1px solid var(--border);
}
.note-dialog-text {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text);
  word-break: break-all;
  margin-bottom: 16px;
}
.note-dialog-close {
  display: block;
  margin: 0 auto;
}
