:root {
  color-scheme: light;
  --ink: #172027;
  --ink-soft: #59636b;
  --paper: #f4f2ec;
  --surface: #fffefa;
  --surface-muted: #ece9e1;
  --line: #d7d3c8;
  --line-strong: #b8b2a5;
  --navy: #152630;
  --navy-soft: #24404c;
  --accent: #c54136;
  --accent-deep: #963129;
  --up: #c73f35;
  --down: #12805c;
  --neutral: #657078;
  --ma5: #d39a2c;
  --ma20: #3b76b5;
  --ma60: #8b5aa7;
  --shadow: 0 12px 30px rgb(33 42 46 / 8%);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgb(21 38 48 / 3%) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 32px;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
canvas:focus-visible {
  outline: 3px solid rgb(197 65 54 / 28%);
  outline-offset: 2px;
}

.topbar {
  min-height: 74px;
  padding: 0 4vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: white;
  background: var(--navy);
  border-bottom: 4px solid var(--accent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 35%);
  font-family: Georgia, "Songti SC", serif;
  font-size: 21px;
  font-weight: 700;
}

.brand-name,
.brand-subtitle {
  margin: 0;
}

.brand-name {
  font-family: Georgia, "Songti SC", serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.brand-subtitle {
  margin-top: 2px;
  color: #aab9c0;
  font-size: 9px;
  letter-spacing: 0.18em;
}

.database-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #cfdbdf;
  font-size: 13px;
}

.topbar-link {
  padding: 8px 13px;
  color: #eef4f6;
  border: 1px solid rgb(255 255 255 / 28%);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
}

.topbar-link:hover,
.topbar-link:focus-visible {
  color: white;
  background: rgb(255 255 255 / 8%);
  border-color: rgb(255 255 255 / 55%);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d69b2b;
  box-shadow: 0 0 0 4px rgb(214 155 43 / 16%);
}

.database-status.is-online .status-dot {
  background: #55c49a;
  box-shadow: 0 0 0 4px rgb(85 196 154 / 16%);
}

.database-status.is-error .status-dot {
  background: #f06d63;
  box-shadow: 0 0 0 4px rgb(240 109 99 / 16%);
}

.page-shell {
  width: min(1540px, 94vw);
  margin: 30px auto 48px;
}

.query-panel,
.dashboard > *,
.chart-panel,
.detail-panel,
.table-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.query-panel {
  padding: 24px 26px 18px;
  border-top: 3px solid var(--navy-soft);
}

.section-heading,
.panel-heading,
.instrument-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.compact-heading {
  align-items: flex-end;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent-deep);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: Georgia, "Songti SC", serif;
  line-height: 1.2;
}

h1 {
  font-size: clamp(22px, 2.2vw, 30px);
}

h2 {
  font-size: clamp(25px, 3vw, 38px);
}

h3 {
  font-size: 19px;
}

.query-help,
.date-caption {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.query-form {
  display: grid;
  grid-template-columns: minmax(125px, 0.45fr) minmax(240px, 1.15fr) minmax(160px, 0.7fr) minmax(160px, 0.7fr) auto;
  align-items: end;
  gap: 14px;
}

.field {
  min-width: 0;
}

.field label {
  display: block;
  margin-bottom: 7px;
  color: #374149;
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
}

.field input:hover,
.field select:hover {
  border-color: #817b70;
}

.symbol-input-wrap {
  position: relative;
}

.suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + 5px);
  right: 0;
  left: 0;
  max-height: 270px;
  overflow-y: auto;
  background: white;
  border: 1px solid var(--line-strong);
  box-shadow: 0 16px 32px rgb(18 27 31 / 16%);
}

.suggestion-button {
  width: 100%;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
  text-align: left;
  background: white;
  border: 0;
  border-bottom: 1px solid #ece9e2;
}

.suggestion-button:hover,
.suggestion-button:focus-visible {
  background: #f6f3ec;
}

.suggestion-button span:last-child {
  color: var(--ink-soft);
  font-size: 11px;
}

.primary-button {
  height: 44px;
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: white;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 2px;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-deep);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.range-presets {
  margin-top: 14px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 12px;
}

.range-presets button {
  padding: 5px 10px;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
}

.range-presets button:hover,
.range-presets button.is-active {
  color: var(--accent-deep);
  background: #f8e9e5;
  border-color: #ecc6bf;
}

.message {
  margin-top: 18px;
  padding: 14px 16px;
  color: #714f0a;
  background: #fff5d8;
  border-left: 4px solid #d29b2e;
  font-size: 14px;
}

.message.is-error {
  color: #7b2822;
  background: #fce8e5;
  border-left-color: var(--accent);
}

.dashboard {
  margin-top: 22px;
}

.instrument-header {
  padding: 24px 26px;
  align-items: center;
  border-bottom: 0;
}

.instrument-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.st-badge {
  padding: 2px 6px;
  color: white;
  background: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.date-caption {
  margin-top: 7px;
}

.quote-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.latest-close {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: clamp(34px, 4vw, 54px);
  font-weight: 700;
  letter-spacing: -0.05em;
}

.change-pill {
  padding: 6px 10px;
  border: 1px solid currentColor;
  border-radius: 2px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
}

.positive {
  color: var(--up) !important;
}

.negative {
  color: var(--down) !important;
}

.neutral {
  color: var(--neutral) !important;
}

.metric-strip {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  border-bottom: 0;
}

.metric-strip > div {
  min-width: 0;
  padding: 17px 20px;
  border-right: 1px solid var(--line);
}

.metric-strip > div:last-child {
  border-right: 0;
}

.metric-strip dt,
.detail-list dt {
  color: var(--ink-soft);
  font-size: 11px;
}

.metric-strip dd {
  margin: 6px 0 0;
  overflow: hidden;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 18px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  margin-top: 16px;
}

.chart-panel,
.detail-panel,
.table-panel {
  min-width: 0;
}

.chart-panel,
.detail-panel {
  padding: 20px;
}

.panel-heading {
  align-items: center;
  margin-bottom: 15px;
}

.chart-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 11px;
  color: var(--ink-soft);
  font-size: 11px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-legend i {
  width: 12px;
  height: 2px;
  display: inline-block;
  background: currentColor;
}

.legend-up { color: var(--up); }
.legend-down { color: var(--down); }
.legend-ma5 { color: var(--ma5); }
.legend-ma20 { color: var(--ma20); }
.legend-ma60 { color: var(--ma60); }

.chart-wrap {
  position: relative;
  height: 520px;
  min-height: 340px;
  background: #fff;
  border-top: 1px solid var(--line);
}

#klineChart {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 164px;
  padding: 9px 10px;
  pointer-events: none;
  color: #f3f6f7;
  background: rgb(21 38 48 / 94%);
  border: 1px solid rgb(255 255 255 / 18%);
  box-shadow: 0 8px 18px rgb(20 28 32 / 18%);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
  line-height: 1.55;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
}

.detail-panel time {
  color: var(--ink-soft);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
}

.detail-list {
  margin: 0;
  border-top: 1px solid var(--line);
}

.detail-list > div {
  padding: 10px 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid #e8e5de;
}

.detail-list dd {
  margin: 0;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}

.data-note {
  margin: 15px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.6;
}

.table-panel {
  margin-top: 16px;
  padding: 20px;
}

.table-heading {
  margin-bottom: 12px;
}

.table-count {
  color: var(--ink-soft);
  font-size: 12px;
}

.table-scroll {
  max-height: 470px;
  overflow: auto;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

th,
td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid #e8e5de;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  position: sticky;
  z-index: 2;
  top: 0;
  color: #455058;
  background: #eeece6;
  font-size: 11px;
  letter-spacing: 0.04em;
}

td {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

tbody tr:hover {
  background: #f8f5ee;
}

.loading-row td,
.empty-row td {
  padding: 32px 12px;
  color: var(--ink-soft);
  text-align: center;
  font-family: inherit;
}

footer {
  width: min(1540px, 94vw);
  margin: 0 auto 28px;
  padding-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  color: #68737a;
  border-top: 1px solid var(--line-strong);
  font-size: 11px;
}

@media (max-width: 1080px) {
  .query-form {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .symbol-field {
    grid-column: 1 / -1;
  }

  .primary-button {
    grid-column: 3;
  }

  .metric-strip {
    grid-template-columns: repeat(3, 1fr);
  }

  .metric-strip > div:nth-child(3) {
    border-right: 0;
  }

  .metric-strip > div:nth-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }

  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .detail-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    column-gap: 24px;
  }
}

@media (max-width: 680px) {
  .topbar {
    min-height: 66px;
    padding: 10px 4vw;
  }

  .brand-subtitle,
  .database-status span:last-child {
    display: none;
  }

  .page-shell {
    width: 94vw;
    margin-top: 18px;
  }

  .query-panel,
  .instrument-header,
  .chart-panel,
  .detail-panel,
  .table-panel {
    padding: 17px;
  }

  .compact-heading,
  .instrument-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .query-help {
    display: none;
  }

  .query-form {
    grid-template-columns: 1fr 1fr;
  }

  .symbol-field,
  .primary-button {
    grid-column: 1 / -1;
  }

  .metric-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric-strip > div:nth-child(odd) {
    border-right: 1px solid var(--line);
  }

  .metric-strip > div:nth-child(even) {
    border-right: 0;
  }

  .metric-strip > div:nth-child(-n + 4) {
    border-bottom: 1px solid var(--line);
  }

  .quote-block {
    width: 100%;
    justify-content: space-between;
  }

  .chart-legend {
    display: none;
  }

  .chart-wrap {
    height: 390px;
  }

  .detail-list {
    display: block;
  }

  footer {
    flex-direction: column;
    gap: 5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
