:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --text: #171a1f;
  --muted: #66717f;
  --line: #dfe3e8;
  --line-strong: #c8ced6;
  --accent: #1457d9;
  --accent-soft: #e9f0ff;
  --up: #d0444a;
  --down: #118363;
  --warning: #a86b00;
  --shadow: 0 8px 24px rgba(25, 33, 45, 0.08);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.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; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 230px auto minmax(280px, 620px) 1fr;
  align-items: center;
  gap: 24px;
  min-height: 68px;
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 6px; background: #1d232d; color: #fff; font-size: 12px; font-weight: 700; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.product-nav { display: flex; align-items: center; gap: 3px; }
.product-nav a { padding: 8px 10px; border-radius: 5px; color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; white-space: nowrap; }
.product-nav a:hover { color: var(--text); background: var(--surface-soft); }
.product-nav a.active { color: var(--accent); background: var(--accent-soft); }

.stock-search { position: relative; display: grid; grid-template-columns: 34px 1fr auto; height: 42px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
.stock-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20, 87, 217, 0.12); }
.search-symbol { display: grid; place-items: center; color: var(--muted); font-size: 22px; }
.stock-search input { min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); }
.stock-search button { margin: 4px; padding: 0 18px; border: 0; border-radius: 4px; background: var(--accent); color: #fff; font-weight: 600; }
.suggestions { position: absolute; top: 47px; left: 0; right: 0; z-index: 30; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); }
.suggestion { display: grid; grid-template-columns: 1fr auto; width: 100%; padding: 11px 14px; border: 0; border-bottom: 1px solid var(--line); background: var(--surface); text-align: left; }
.suggestion:last-child { border-bottom: 0; }
.suggestion:hover, .suggestion:focus { background: var(--surface-soft); outline: 0; }
.suggestion span { color: var(--muted); font-variant-numeric: tabular-nums; }
.system-state { justify-self: end; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: #a7afb9; }
.state-dot.ok { background: var(--down); }
.state-dot.warn { background: var(--warning); }

.app-shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 68px); }
.watch-sidebar { padding: 20px 14px; background: #eceff2; border-right: 1px solid var(--line); }
.sidebar-title { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 12px; }
.sidebar-title h2 { margin: 0; font-size: 13px; text-transform: uppercase; }
.sidebar-title span { min-width: 24px; padding: 2px 6px; border-radius: 10px; background: #d9dee4; color: var(--muted); text-align: center; font-size: 11px; }
.watch-list { display: grid; gap: 3px; }
.watch-item { display: grid; grid-template-columns: 1fr 28px; align-items: center; min-height: 48px; border-radius: 5px; }
.watch-item.active { background: var(--surface); box-shadow: 0 1px 2px rgba(25, 33, 45, 0.08); }
.watch-main, .watch-remove { border: 0; background: transparent; }
.watch-main { min-width: 0; padding: 8px 9px; text-align: left; }
.watch-main strong, .watch-main span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-main strong { font-size: 13px; }
.watch-main span { margin-top: 3px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.watch-remove { width: 26px; height: 26px; color: #8a939e; font-size: 18px; line-height: 1; }
.watch-remove:hover { color: var(--up); }
.watch-empty { padding: 12px 8px; color: var(--muted); font-size: 12px; }
.quick-list { display: grid; gap: 4px; margin-top: 24px; padding: 14px 8px 0; border-top: 1px solid #d5dae0; }
.quick-list > span { margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.quick-list button { padding: 7px 0; border: 0; background: transparent; color: #3f4854; text-align: left; font-size: 12px; }
.quick-list button:hover { color: var(--accent); }

.workspace { min-width: 0; padding: 26px 30px 40px; }
.workspace > section, .workspace > footer, .workspace > .error-banner { width: min(100%, 1440px); margin-inline: auto; }
.error-banner { margin-bottom: 14px; padding: 10px 12px; border-left: 3px solid var(--warning); background: #fff7e8; color: #704b08; }

.quote-section { padding: 4px 0 24px; border-bottom: 1px solid var(--line); }
.quote-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.title-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.instrument-title h1 { margin: 0; font-size: 25px; line-height: 1.25; }
.term-help { display: inline-grid; place-items: center; flex: 0 0 auto; width: 15px; height: 15px; margin: 0 0 0 4px; padding: 0; border: 1px solid #aeb6c0; border-radius: 50%; background: #fff; color: #697583; font-size: 10px; font-weight: 700; line-height: 1; vertical-align: 1px; }
.term-help:hover, .term-help:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; box-shadow: 0 0 0 2px rgba(20, 87, 217, 0.12); }
.term-tooltip { position: fixed; z-index: 100; display: grid; gap: 6px; width: min(300px, calc(100vw - 20px)); padding: 12px 13px; pointer-events: none; border: 1px solid #bfc6cf; border-radius: 6px; background: #202733; box-shadow: 0 10px 28px rgba(22, 28, 37, 0.22); color: #f6f8fa; font-size: 12px; line-height: 1.55; }
.term-tooltip[hidden] { display: none !important; }
.term-tooltip strong { font-size: 13px; }
.term-tooltip span { display: block; }
.term-example { padding-top: 6px; border-top: 1px solid rgba(255,255,255,0.16); color: #cdd5df; }
.symbol-tag { padding: 3px 7px; border-radius: 4px; background: #e7eaee; color: #596473; font-size: 11px; font-variant-numeric: tabular-nums; }
.asset-type { padding: 3px 7px; border-radius: 4px; background: #e8f2ed; color: #1c6b54; font-size: 11px; font-weight: 700; }
.asset-type[hidden] { display: none !important; }
.star-button { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: #7a8490; font-size: 20px; }
.star-button.active { border-color: #d6a51b; background: #fff8dd; color: #aa7500; }
.timestamp { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }
.price-block { text-align: right; font-variant-numeric: tabular-nums; }
.price-block strong { display: block; font-size: 34px; line-height: 1; }
.price-block span { display: block; margin-top: 8px; font-weight: 600; }
.up { color: var(--up) !important; }
.down { color: var(--down) !important; }
.flat { color: var(--muted) !important; }

.quote-grid { display: grid; grid-template-columns: repeat(10, minmax(70px, 1fr)); gap: 0; margin: 24px 0 0; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.quote-grid > div { min-width: 0; padding: 11px 13px; border-right: 1px solid var(--line); }
.quote-grid > div:last-child { border-right: 0; }
.quote-grid dt { display: flex; align-items: center; color: var(--muted); font-size: 11px; }
.quote-grid dd { overflow: hidden; margin: 5px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }

.research-section { padding: 25px 0; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.section-heading h2 { display: flex; align-items: center; margin: 0; font-size: 17px; }
.section-meta { display: flex; align-items: center; margin-top: 5px; color: var(--muted); font-size: 11px; }
.source-label { padding: 4px 7px; border-radius: 4px; background: #e8f2ed; color: #1c6b54; font-size: 11px; }
.chart-heading { align-items: center; }
.chart-controls { display: flex; align-items: center; gap: 10px; }
.segmented { display: flex; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); }
.segmented button { min-width: 44px; height: 32px; padding: 0 10px; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 12px; }
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: #26303d; color: #fff; }
.chart-legend { display: flex; gap: 14px; height: 19px; color: var(--muted); font-size: 11px; }
.chart-legend .ma5 { color: #c27a00; }
.chart-legend .ma10 { color: #2474c8; }
.chart-legend .ma20 { color: #7953a9; }
.chart-shell { position: relative; height: clamp(360px, 48vw, 560px); overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
#priceChart { display: block; width: 100%; height: 100%; }
.chart-loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,0.9); color: var(--muted); }
.chart-loading[hidden] { display: none !important; }
.chart-tooltip { position: absolute; z-index: 4; width: 168px; padding: 9px 10px; pointer-events: none; border: 1px solid var(--line-strong); border-radius: 5px; background: rgba(255,255,255,0.96); box-shadow: var(--shadow); color: var(--text); font-size: 11px; line-height: 1.65; font-variant-numeric: tabular-nums; white-space: pre-line; }

.fundamental-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.fund-metric { min-width: 0; min-height: 92px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.fund-metric .label { display: flex; align-items: center; color: var(--muted); font-size: 11px; }
.fund-metric strong { display: block; overflow: hidden; margin-top: 10px; font-size: 21px; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
.fund-metric small { display: block; margin-top: 5px; color: var(--muted); }
.fund-not-applicable { grid-column: 1 / -1; display: grid; gap: 7px; padding: 16px; border: 1px solid #cfd8d3; border-radius: 6px; background: #f4f8f6; }
.fund-not-applicable strong { color: #255b4b; }
.fund-not-applicable span { color: var(--muted); line-height: 1.6; }

.profile-content { display: grid; gap: 12px; }
.profile-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.profile-field { min-width: 0; padding: 12px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.profile-field:nth-child(4n) { border-right: 0; }
.profile-field:nth-last-child(-n+4) { border-bottom: 0; }
.profile-field span { display: block; color: var(--muted); font-size: 11px; }
.profile-field strong, .profile-field a { display: block; overflow: hidden; margin-top: 6px; color: var(--text); font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.profile-field a { color: var(--accent); }
.business-summary { padding: 15px 16px; border-left: 3px solid var(--accent); background: var(--surface); }
.business-summary h3 { margin: 0 0 8px; font-size: 13px; }
.business-summary p { margin: 0; color: #3e4854; line-height: 1.75; }
.profile-details { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.profile-details summary { padding: 12px 14px; cursor: pointer; color: #37414e; font-weight: 600; }
.profile-detail-body { display: grid; gap: 16px; padding: 0 14px 15px; border-top: 1px solid var(--line); }
.profile-detail-body section { padding-top: 14px; }
.profile-detail-body h3 { margin: 0 0 7px; font-size: 12px; }
.profile-detail-body p { margin: 0; color: var(--muted); line-height: 1.75; }
.profile-unavailable { padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); color: var(--muted); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th { background: var(--surface-soft); color: var(--muted); font-size: 11px; font-weight: 500; }
th .term-help { vertical-align: 0; }
th:first-child, td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
.empty-row { padding: 30px; color: var(--muted); text-align: center !important; }

.data-footer { display: flex; justify-content: space-between; gap: 20px; padding-top: 18px; color: var(--muted); font-size: 11px; }
#toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; display: none; max-width: min(380px, calc(100vw - 44px)); padding: 11px 14px; border-radius: 5px; background: #202733; color: #fff; box-shadow: var(--shadow); }

@media (max-width: 1180px) {
  .topbar { grid-template-columns: 200px auto minmax(240px, 1fr) auto; gap: 14px; }
  .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .quote-grid { grid-template-columns: repeat(5, 1fr); }
  .quote-grid > div:nth-child(5) { border-right: 0; }
  .quote-grid > div:nth-child(-n+5) { border-bottom: 1px solid var(--line); }
  .fundamental-grid { grid-template-columns: repeat(2, 1fr); }
  .profile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-field:nth-child(4n) { border-right: 1px solid var(--line); }
  .profile-field:nth-child(2n) { border-right: 0; }
  .profile-field:nth-last-child(-n+4) { border-bottom: 1px solid var(--line); }
  .profile-field:nth-last-child(-n+2) { border-bottom: 0; }
}

@media (max-width: 820px) {
  .topbar { position: static; grid-template-columns: 1fr auto; padding: 10px 14px; }
  .product-nav { grid-column: 1 / -1; grid-row: 2; }
  .stock-search { grid-column: 1 / -1; grid-row: 3; }
  .system-state { grid-column: 2; grid-row: 1; }
  .app-shell { display: block; }
  .watch-sidebar { padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-title, .quick-list { display: none; }
  .watch-list { display: flex; overflow-x: auto; gap: 5px; }
  .watch-item { flex: 0 0 auto; grid-template-columns: auto 26px; min-width: 142px; background: rgba(255,255,255,0.55); }
  .workspace { padding: 20px 14px 32px; }
  .chart-heading, .quote-heading { align-items: flex-start; }
  .chart-heading { display: grid; }
  .chart-controls { flex-wrap: wrap; }
  .chart-shell { height: 420px; }
  .data-footer { display: grid; }
}

@media (max-width: 560px) {
  .brand strong { font-size: 13px; }
  .brand small { display: none; }
  .system-state { max-width: 120px; }
  #systemStatus { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .quote-heading { display: grid; }
  .price-block { text-align: left; }
  .price-block strong { font-size: 30px; }
  .quote-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quote-grid > div, .quote-grid > div:nth-child(5) { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .quote-grid > div:nth-child(even) { border-right: 0; }
  .quote-grid > div:nth-last-child(-n+2) { border-bottom: 0; }
  .fundamental-grid { grid-template-columns: 1fr 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
  .profile-field, .profile-field:nth-child(2n), .profile-field:nth-child(4n), .profile-field:nth-last-child(-n+2) { border-right: 0; border-bottom: 1px solid var(--line); }
  .profile-field:last-child { border-bottom: 0; }
  .fund-metric { min-height: 84px; padding: 12px; }
  .fund-metric strong { font-size: 18px; }
  .segmented button { min-width: 40px; padding: 0 8px; }
  #modeControl { display: none; }
  .chart-shell { height: 360px; }
}
