/* AI 产业链投研看板 - 样式
   拆分自 build_html.py 的内联 <style>，所有 {{ }} 已还原为真实花括号。 */

:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #173b73;
  --brand-2: #24549a;
  --warn: #d97706;
  --risk: #dc2626;
  --up: #dc2626;
  --down: #059669;
  --flat: #6b7280;
  --ok: #15803d;
  --ok-bg: #ecfdf5;
  --pending: #6b7280;
  --pending-bg: #f3f4f6;
  --fail: #b91c1c;
  --fail-bg: #fef2f2;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* 加载骨架 */
.skeleton { background: linear-gradient(90deg, #e5e7eb 0%, #f3f4f6 50%, #e5e7eb 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.load-error { margin: 60px auto; max-width: 640px; background: #fff; border: 1px solid #fecaca; border-radius: 8px; padding: 24px; color: #7f1d1d; }
.load-error h2 { margin: 0 0 8px; color: var(--risk); font-size: 18px; }
.load-error a { color: var(--brand-2); }

.header { background: #102a53; color: #fff; padding: 24px 40px 20px; border-bottom: 1px solid rgba(255,255,255,.12); }
.header-top { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
h1 { margin: 0 0 8px; font-size: 28px; letter-spacing: 0; }
.subtitle { color: rgba(255,255,255,.82); font-size: 14px; }
.status-strip { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; max-width: 560px; }
.status-pill { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); border-radius: 6px; padding: 7px 10px; font-size: 12px; color: rgba(255,255,255,.88); display: inline-flex; align-items: center; gap: 6px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #6b7280; display: inline-block; }
.status-pill[data-state="ok"] .status-dot { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,.25); }
.status-pill[data-state="pending"] .status-dot { background: #f59e0b; }
.status-pill[data-state="fail"] .status-dot { background: var(--risk); }
.status-pill[data-state="ok"] { background: rgba(34,197,94,.16); border-color: rgba(34,197,94,.4); }
.status-pill[data-state="fail"] { background: rgba(220,38,38,.18); border-color: rgba(220,38,38,.45); }

.stats { display: grid; grid-template-columns: repeat(6, minmax(92px, 1fr)); gap: 12px; margin-top: 20px; }
.stat { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); border-radius: 8px; padding: 12px; }
.stat-num { display: block; font-weight: 700; font-size: 24px; }
.stat-label { display: block; color: rgba(255,255,255,.78); font-size: 12px; margin-top: 2px; }

.toolbar { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.96); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding: 14px 40px; display: grid; grid-template-columns: minmax(220px, 420px) 1fr; gap: 12px; align-items: start; }
.search { width: 100%; border: 1px solid #d1d5db; border-radius: 7px; padding: 10px 12px; font-size: 14px; outline: none; }
.search:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(36,84,154,.12); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.filter-btn { min-height: 38px; border: 1px solid #d1d5db; background: #fff; color: #374151; border-radius: 7px; padding: 8px 13px; cursor: pointer; font-size: 13px; }
.filter-btn:hover { border-color: var(--brand-2); color: var(--brand-2); }
.filter-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.summary-band { margin: 18px 40px 0; display: grid; grid-template-columns: 1.2fr .8fr; gap: 14px; }
.focus-panel, .market-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.panel-title { margin: 0 0 10px; font-size: 15px; color: #1f2937; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panel-title small { color: var(--muted); font-weight: 400; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid #fbbf24; background: #fffbeb; color: #7c2d12; border-radius: 999px; padding: 6px 11px; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip:hover { background: #fef3c7; }

.market-list { display: grid; gap: 6px; }
.market-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 6px 8px; border-radius: 5px; }
.market-row:hover { background: #f8fafc; }
.market-status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.market-status .status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pending); }

.layer-section { margin: 24px 40px; }
.layer-title { display: flex; align-items: center; gap: 10px; color: var(--brand); font-size: 22px; font-weight: 700; padding-bottom: 8px; border-bottom: 2px solid var(--brand); }
.layer-badge { background: #e8eef8; color: var(--brand); border-radius: 5px; padding: 4px 9px; font-size: 13px; font-weight: 600; }
.subcat-block { margin: 18px 0 26px; }
.subcat-title { border-left: 3px solid #9ca3af; padding-left: 9px; margin-bottom: 12px; font-size: 15px; font-weight: 700; color: #4b5563; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(286px, 1fr)); gap: 12px; }

.card { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid #9ca3af; border-radius: 8px; padding: 14px; cursor: pointer; min-width: 0; box-shadow: 0 1px 2px rgba(15,23,42,.05); transition: transform .14s ease, box-shadow .14s ease; }
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(15,23,42,.1); }
.card:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.card.level-1 { border-left-color: #d1d5db; } .card.level-2 { border-left-color: #93c5fd; } .card.level-3 { border-left-color: #60a5fa; } .card.level-4 { border-left-color: #f59e0b; } .card.level-5 { border-left-color: var(--risk); border-color: #facc15; }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card-name { font-weight: 700; font-size: 16px; min-width: 0; overflow-wrap: anywhere; }
.stars { color: #f59e0b; white-space: nowrap; font-size: 13px; }
.card-bottleneck { color: #4b5563; font-size: 12px; margin: 8px 0 10px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.stock-mini { display: flex; gap: 6px; flex-wrap: wrap; }

/* 股票 pill：状态三色（成功 / 待更新 / 失败） */
.stock-pill { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; background: var(--pending-bg); border-radius: 6px; padding: 5px 7px; font-size: 12px; color: #374151; border: 1px solid transparent; }
.stock-pill[data-status="ok"] { background: var(--ok-bg); border-color: rgba(21,128,61,.2); }
.stock-pill[data-status="pending"] { background: var(--pending-bg); border-color: #e5e7eb; color: var(--muted); }
.stock-pill[data-status="fail"] { background: var(--fail-bg); border-color: rgba(185,28,28,.3); color: var(--fail); }
.stock-pill .status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.stock-code { font-weight: 700; color: var(--brand); }
.stock-pill[data-status="fail"] .stock-code { color: var(--fail); }
.stock-pill[data-status="pending"] .stock-code { color: var(--muted); }

.quote-up { color: var(--up); font-weight: 700; } .quote-down { color: var(--down); font-weight: 700; } .quote-flat { color: var(--flat); font-weight: 600; }
.stock-pill[data-status="pending"] .quote-up,
.stock-pill[data-status="pending"] .quote-down { color: var(--muted); font-weight: 500; }

.card-foot { display: flex; justify-content: space-between; gap: 10px; color: #9ca3af; font-size: 11px; margin-top: 10px; align-items: center; }
.card-foot .status-tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border-radius: 4px; font-size: 11px; }
.card-foot .status-tag .status-dot { width: 6px; height: 6px; border-radius: 50%; }
.card-foot .status-tag[data-status="ok"] { background: var(--ok-bg); color: var(--ok); }
.card-foot .status-tag[data-status="pending"] { background: var(--pending-bg); color: var(--pending); }
.card-foot .status-tag[data-status="fail"] { background: var(--fail-bg); color: var(--fail); }

.empty-state { margin: 28px 40px; background: #fff; border: 1px dashed #cbd5e1; border-radius: 8px; padding: 28px; color: #64748b; text-align: center; }

/* 行情部分失败 banner（仅当 meta.failed > 0 时出现） */
.quote-banner { margin: 0; padding: 10px 40px; background: #fff7ed; border-bottom: 1px solid #fed7aa; color: #9a3412; font-size: 13px; }
.quote-banner strong { color: #c2410c; margin-right: 6px; }

.modal-bg { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 100; align-items: center; justify-content: center; padding: 28px; }
.modal-bg.open { display: flex; }
body.modal-open { overflow: hidden; }
.modal { background: #fff; width: min(920px, 100%); max-height: 90vh; overflow: auto; border-radius: 10px; padding: 26px 30px; position: relative; box-shadow: 0 24px 60px rgba(15,23,42,.25); }
.modal-close { position: absolute; top: 12px; right: 14px; border: 0; background: transparent; font-size: 26px; color: #6b7280; cursor: pointer; width: 36px; height: 36px; border-radius: 6px; }
.modal-close:hover { background: #f3f4f6; color: var(--text); }
.modal h2 { margin: 0 34px 5px 0; color: var(--brand); font-size: 26px; }
.meta-line { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.modal-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 14px 0 18px; }
.summary-card { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 10px; }
.summary-label { display: block; color: #64748b; font-size: 11px; }
.summary-value { display: block; margin-top: 3px; font-weight: 700; color: #1f2937; overflow-wrap: anywhere; }

.modal-section { margin-top: 18px; }
.modal-section h3 { margin: 0 0 8px; color: #475569; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.modal-section p, .modal-section li { font-size: 14px; line-height: 1.72; }

.stock-item { display: grid; grid-template-columns: minmax(120px, 1fr) auto; gap: 10px; align-items: center; background: #f8fafc; border: 1px solid #e5e7eb; padding: 12px; border-radius: 7px; margin-bottom: 7px; font-size: 13px; position: relative; padding-right: 80px; /* 始终为右上角 badge 留位 */ }
.stock-item[data-status="fail"] { border-color: rgba(185,28,28,.35); background: #fff7f7; }
.stock-item[data-status="pending"] { opacity: .9; }
.stock-item .status-badge { position: absolute; top: 8px; right: 10px; font-size: 10px; padding: 2px 7px; border-radius: 999px; }
.stock-item .status-badge[data-status="ok"] { background: var(--ok-bg); color: var(--ok); }
.stock-item .status-badge[data-status="pending"] { background: var(--pending-bg); color: var(--pending); }
.stock-item .status-badge[data-status="fail"] { background: var(--fail-bg); color: var(--fail); }
.stock-main strong { color: var(--brand); }
.quote-box { text-align: right; white-space: nowrap; }

.event-item { background: #fff8e1; border-left: 3px solid #f59e0b; padding: 10px 13px; border-radius: 0 7px 7px 0; margin-bottom: 8px; font-size: 13px; }
.event-date { display: inline-block; min-width: 70px; color: #92400e; font-weight: 700; }

a { color: var(--brand-2); }
a:hover { text-decoration: underline; }
.detail-link { background: none; border: 0; padding: 0; color: var(--brand-2); cursor: pointer; font: inherit; }
.detail-link:hover { text-decoration: underline; }

/* 自定义 tooltip：hover 显示股票完整行情 */
[data-tooltip] { position: relative; }
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  font-size: 12px;
  padding: 6px 9px;
  border-radius: 5px;
  white-space: pre;
  z-index: 30;
  pointer-events: none;
  box-shadow: 0 6px 16px rgba(0,0,0,.2);
}

@media (max-width: 900px) {
  .header { padding: 20px 16px; }
  .header-top { display: block; }
  .status-strip { justify-content: flex-start; margin-top: 12px; max-width: none; }
  .status-pill { font-size: 11px; padding: 6px 8px; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .toolbar { grid-template-columns: 1fr; padding: 12px 16px; }
  .filters { justify-content: flex-start; flex-wrap: wrap; overflow-x: visible; padding-bottom: 0; }
  .filter-btn { white-space: nowrap; }
  .summary-band { margin: 14px 16px 0; grid-template-columns: 1fr; }
  .layer-section { margin: 20px 16px; }
  .cards-grid { grid-template-columns: 1fr; }
  .modal-bg { padding: 12px; align-items: flex-start; }
  .modal { width: calc(100vw - 24px); max-height: calc(100vh - 24px); padding: 22px 16px; }
  .modal-summary { grid-template-columns: repeat(2, 1fr); }
  .stock-item { grid-template-columns: 1fr; }
  .quote-box { text-align: left; }
}
@media (max-width: 520px) {
  h1 { font-size: 22px; }
  .subtitle { font-size: 12px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat-num { font-size: 21px; }
  .card { padding: 13px; }
  .modal-summary { grid-template-columns: 1fr; }
  .status-strip { gap: 6px; }
  .status-pill { font-size: 10.5px; padding: 5px 7px; }
}
@media (max-width: 380px) {
  /* iPhone SE 等极窄屏：单列堆叠状态条 */
  .status-strip { flex-direction: column; align-items: flex-start; }
  .status-pill { width: 100%; }
}

/* 移动端无 hover 时不显示 tooltip（避免触摸后残留） */
@media (hover: none) {
  [data-tooltip]:hover::after, [data-tooltip]:focus-visible::after { display: none; }
}

/* 深色模式 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --panel: #111827;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #1f2937;
    --pending-bg: #1f2937;
    --ok-bg: #052e1a;
    --fail-bg: #2a0a0a;
  }
  .header { background: #060d1a; }
  .toolbar { background: rgba(11, 18, 32, 0.92); }
  .subcat-title { color: #d1d5db; }
  .card { background: var(--panel); }
  .summary-card { background: #0b1220; }
  .stock-item { background: #0b1220; }
  .stock-pill[data-status="pending"] { background: #1f2937; }
  .modal { background: #111827; color: var(--text); }
  .modal h2 { color: #93c5fd; }
  .modal-close { color: #9ca3af; }
  .modal-close:hover { background: #1f2937; color: var(--text); }
  .filter-btn { background: #1f2937; color: #d1d5db; border-color: #374151; }
  .filter-btn:hover { color: #fff; border-color: var(--brand-2); }
}
