/* A股分析 - 响应式样式 */

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a1a1a;
  --text-sub: #71767f;
  --border: #e5e7eb;
  --brand: #4b3fe3;
  --up: #e8463a;    /* A股习惯：红涨 */
  --down: #1dc981;  /* 绿跌 */
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* 关键：display 类样式会覆盖 hidden 属性的 UA 默认样式，必须强制还原 */
[hidden] { display: none !important; }

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- 头部 ---------- */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 420px;
}

#searchInput {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  font-size: 14px;
  outline: none;
  background: var(--bg);
  transition: border-color .15s;
}

#searchInput:focus { border-color: var(--brand); }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
}

.search-results li {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.search-results li:hover { background: var(--bg); }
.search-results .r-code { color: var(--text-sub); font-size: 12px; }
.search-results .r-industry { color: var(--text-sub); font-size: 12px; margin-left: 8px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 16px;
}

/* 股票信息卡 */
.stock-card { padding: 16px; }

.stock-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.stock-name { font-size: 20px; font-weight: 700; }
.stock-code { font-size: 13px; color: var(--text-sub); font-weight: 400; margin-left: 4px; }
.stock-meta { font-size: 12px; color: var(--text-sub); margin-top: 6px; }

.stock-quote { text-align: right; }
.stock-price { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stock-change { font-size: 14px; margin-top: 2px; font-variant-numeric: tabular-nums; }

.price-up { color: var(--up); }
.price-down { color: var(--down); }

/* 区间切换 */
.range-tabs {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  overflow-x: auto;
}

.range-tabs button {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-sub);
  padding: 5px 14px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.range-tabs button.active {
  border-color: var(--brand);
  color: var(--brand);
  background: transparent;
  font-weight: 500;
}

/* ---------- 图表 ---------- */
.chart-card {
  padding: 12px 8px 8px;
  position: relative;
}

#chart { width: 100%; height: 480px; }

.chart-fallback {
  height: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  gap: 8px;
}

.chart-fallback .hint { font-size: 12px; opacity: .7; }

.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.7);
  color: var(--text-sub);
  font-size: 14px;
  border-radius: var(--radius);
}

/* ---------- 主 tab（行情/财报） ---------- */
.main-tabs {
  display: inline-flex;
  background: #e9eaf0;
  border-radius: 10px;
  padding: 3px;
  margin-top: 16px;
}

.main-tabs button {
  border: none;
  background: transparent;
  padding: 7px 22px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-sub);
  white-space: nowrap;
}

.main-tabs button.active {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

/* ---------- 财报页 ---------- */
.fin-state {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-sub);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.fin-state .fin-err { color: #d93026; }

.retry-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--brand);
  padding: 6px 24px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
}

.retry-btn:hover { border-color: var(--brand); }

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* 面板卡片 */
.panel { padding: 16px; }

.panel + .panel { margin-top: 12px; }

.panel-title {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-sub { font-size: 12px; font-weight: 400; color: var(--text-sub); }

.panel-foot {
  font-size: 11px;
  color: var(--text-sub);
  margin-top: 8px;
  line-height: 1.6;
}

/* 指标网格 */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
}

.m-label { font-size: 11px; color: var(--text-sub); }
.m-value { font-size: 16px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.m-value.up { color: var(--up); }
.m-value.down { color: var(--down); }
.m-note { font-size: 10px; color: var(--text-sub); margin-top: 2px; }

/* P1 估值与业绩 */
.p1-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }

.fin-sub-title { font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.fin-sub-date { font-size: 11px; color: var(--text-sub); font-weight: 400; margin-left: 6px; }

.fin-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
  color: var(--text-sub);
}

.fin-row b { font-size: 15px; color: var(--text); font-variant-numeric: tabular-nums; }

.yoy { font-size: 12px; font-variant-numeric: tabular-nums; margin-left: 8px; }
.yoy.up { color: var(--up); }
.yoy.down { color: var(--down); }
.yoy.muted { color: var(--text-sub); }

/* 摘要 chips 行 */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.chip {
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-sub);
  cursor: default;
}

.chip b { display: block; font-size: 15px; color: var(--text); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* CAGR 迷你表格 */
.cagr-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13px; }

.cagr-table th, .cagr-table td {
  text-align: center;
  padding: 8px 6px;
  border-bottom: 1px dashed var(--border);
}

.cagr-table th { color: var(--text-sub); font-weight: 500; font-size: 12px; }
.cagr-table td:first-child, .cagr-table th:first-child { text-align: left; }
.cagr-table td { font-variant-numeric: tabular-nums; font-weight: 600; }

/* 面板内双列（桌面端），移动端堆叠 */
.panel-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }

.fin-chart { width: 100%; height: 240px; }

.chart-cap { font-size: 12px; color: var(--text-sub); margin-bottom: 4px; font-weight: 600; }

/* ---------- 移动端适配 ---------- */
@media (max-width: 640px) {
  .header-inner { flex-wrap: wrap; padding: 10px 0; height: auto; }
  .logo { font-size: 16px; }
  .search-box { max-width: none; }

  #chart { height: 360px; }

  .stock-head { flex-direction: column; }
  .stock-quote { text-align: left; }
  .stock-price { font-size: 24px; }

  .p1-grid { grid-template-columns: 1fr; }
  .panel-2col { grid-template-columns: 1fr; }
  .fin-chart { height: 220px; }
}

/* ---------- 定制分析 ---------- */

/* 市盈率评估高亮 */
.m-value.score { color: var(--brand); }

/* 科目明细两列键值行 */
.inc-items { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 24px; margin-top: 12px; }
@media (max-width: 640px) {
  .inc-items { grid-template-columns: 1fr; }
}

/* 通用数据表格（外层横向滚动，适配手机） */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 12px; }
.k-table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.k-table th, .k-table td {
  padding: 8px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.k-table th { color: var(--text-sub); font-weight: 500; font-size: 12px; }
.k-table td { font-weight: 600; }
.k-table td:first-child, .k-table th:first-child { text-align: left; }
.k-table td.td-left { text-align: left; font-weight: 400; }
.k-table tr:last-child td { border-bottom: none; }

/* 机构 / 个人标签 */
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; }
.tag-inst { background: rgba(75, 63, 227, .08); color: var(--brand); }
.tag-person { background: #f2f3f5; color: var(--text-sub); }
