:root {
  color-scheme: light;
  font-family: ui-sans-serif, -apple-system, system-ui, "Segoe UI", "Microsoft YaHei UI", "PingFang SC", sans-serif;
  color: var(--text);
  background: var(--surface);
  --text: var(--gray-1000);
  --muted: var(--gray-500);
  --surface: var(--gray-0);
  --panel: var(--gray-50);
  --line: var(--gray-150);
  --border: var(--gray-200);
  --hover: var(--gray-75);
  --selected: var(--gray-100);
  --primary: var(--gray-900);
  --primary-hover: var(--gray-700);
  --link: var(--blue-600);
  --focus: var(--blue-500);
  --danger: var(--red-700);
  --positive: var(--green-700);
  --warning: var(--orange-700);
  --chart-grid: var(--gray-150);
  --chart-line: var(--gray-800);
  --mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-size: 16px; line-height: 1.55; }
[hidden] { display: none !important; }
a { color: var(--link); text-underline-offset: .22em; }
h1, h2, h3, p, pre { margin: 0; }
h1 { font-size: clamp(1.8rem, 3vw, 2.5rem); line-height: 1.18; font-weight: 650; letter-spacing: -.035em; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
code, pre { font-family: var(--mono); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .6; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
main:focus { outline: none; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link:focus { position: fixed; z-index: 5; inset: 8px auto auto 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { width: min(100%, 1440px); min-height: 64px; padding: 8px 32px; margin-inline: auto; display: flex; align-items: center; gap: 24px; }
.brand { font-weight: 650; letter-spacing: -.035em; color: var(--text); text-decoration: none; white-space: nowrap; }
.main-nav { display: flex; gap: 4px; align-items: center; }
.main-nav a, .section-nav a { min-height: 44px; display: flex; align-items: center; padding: 8px 12px; border-radius: 8px; font-size: .875rem; color: var(--muted); text-decoration: none; white-space: nowrap; }
.main-nav .nav-current, .section-nav a[aria-current="page"] { background: var(--selected); color: var(--text); font-weight: 600; }
.main-nav a:hover, .section-nav a:hover { background: var(--hover); color: var(--text); }
#logout { margin-left: auto; white-space: nowrap; }
.shell { width: min(100%, 1440px); min-height: calc(100vh - 65px); margin: 0 auto; display: grid; grid-template-columns: 216px minmax(0, 1fr); }
.section-nav { display: flex; flex-direction: column; gap: 3px; padding: 24px 16px; border-right: 1px solid var(--line); background: var(--panel); }
.page-content { min-width: 0; max-width: 1120px; padding: 40px clamp(22px, 4vw, 60px) 64px; }
.page-heading { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 24px; }
.reference-section { margin-top: 24px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; min-width: 0; }
label { font-size: .875rem; font-weight: 550; }
label code { padding-left: 4px; color: var(--muted); font-size: .8rem; }
input, select { min-height: 44px; width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; background: var(--surface); color: var(--text); }
input::placeholder { color: var(--muted); }
.primary, .secondary, .quiet { min-height: 44px; border: 1px solid transparent; border-radius: 9999px; padding: 8px 16px; font-size: .875rem; font-weight: 550; transition: background-color 160ms ease, border-color 160ms ease; }
.primary { background: var(--primary); color: var(--surface); }
.primary:hover { background: var(--primary-hover); }
.secondary { border-color: var(--border); color: var(--text); background: var(--surface); white-space: nowrap; }
.secondary:hover, .quiet:hover { background: var(--hover); }
.quiet { background: transparent; color: var(--text); }
.form-message { margin-bottom: 16px; font-size: .875rem; color: var(--danger); }
.form-message:empty { display: none; }
.market-note { color: var(--muted); font-size: .875rem; margin: 8px 0; }

.try-grid { display: grid; grid-template-columns: minmax(220px, .85fr) minmax(0, 1.15fr); gap: 16px; }
.request-card { padding: 20px; }
.card-heading { margin-bottom: 12px; }
.request-card select { margin: 6px 0 16px; }
.request-preview { padding: 10px 12px; margin: 12px 0 0; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); overflow: auto; white-space: nowrap; font-size: .82rem; }
#copy-message { display: block; margin-top: 6px; overflow-wrap: anywhere; font-size: .82rem; color: var(--muted); }
.code-panel { border-radius: 16px; border: 1px solid var(--line); background: var(--panel); min-width: 0; overflow: hidden; }
.code-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.code-heading span { color: var(--muted); font-size: .8rem; }
.code-heading .failure { color: var(--danger); }
.code-heading .success { color: var(--positive); }
.code-panel pre { min-height: 160px; max-height: 300px; padding: 16px; overflow: auto; font-size: .82rem; line-height: 1.65; }
.code-panel pre:focus-visible { outline-offset: -3px; }

.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: .875rem; font-variant-numeric: tabular-nums; }
thead { background: var(--panel); color: var(--muted); }
th, td { padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td code { color: var(--text); font-size: .82rem; overflow-wrap: anywhere; }
.api-fields { min-width: 650px; }
.api-fields tbody th { font-weight: 500; overflow-wrap: anywhere; text-align: left; }
.market-list th, .market-list td { white-space: nowrap; }
#quotes table { min-width: 590px; }
#quotes td small { display: block; color: var(--muted); font: .75rem var(--mono); }
.filter-label { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.filter-label input { width: min(30vw, 200px); }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric { display: flex; flex-direction: column; gap: 6px; padding: 16px; }
.metric span, .metric small, .quote-heading p { color: var(--muted); font-size: .82rem; }
.metric strong { font-variant-numeric: tabular-nums; font-size: 1.7rem; line-height: 1.28; }
.metric .time-metric { font-size: 1.15rem; overflow-wrap: anywhere; }
.pill { display: inline-block; padding: 3px 8px; border-radius: 9999px; background: var(--selected); color: var(--text); font-size: .75rem; font-weight: 550; white-space: nowrap; }
.pill.warn { background: var(--orange-25); color: var(--warning); }
.run-list { padding: 0 16px; }
.run-list > p { padding: 12px 0; color: var(--muted); }
.run-entry { border-bottom: 1px solid var(--line); }
.run-entry:last-child { border-bottom: 0; }
.run-entry summary, .market-details summary { padding: 10px 0; min-height: 44px; cursor: pointer; }
.run-entry summary .pill { margin-left: 8px; }
.run-entry ul { margin-top: 0; color: var(--muted); font-size: .875rem; }

.market-section-title { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.market-section-title > span, .market-section-title div > span { color: var(--muted); font-size: .875rem; }
.market-section-title > .warn { color: var(--warning); }
.quote-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.quote-card { padding: 18px; display: grid; align-content: start; gap: 4px; min-height: 136px; }
.quote-card strong { font-size: clamp(1.35rem, 3vw, 2.6rem); font-variant-numeric: tabular-nums; letter-spacing: -.035em; }
.quote-card > span { font-size: .875rem; font-weight: 550; }
.quote-card small, .forecast-row small { color: var(--muted); font-size: .8rem; }
.forecast-card, .market-chart-block, .market-list { padding: 20px 24px; }
.forecast-date { color: var(--muted); margin-bottom: 8px; }
.forecast-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.forecast-row:last-child { border-bottom: 0; padding-bottom: 0; }
.market-chart-block select, .regional-heading select { width: min(60%, 184px); }
.market-chart { min-height: 218px; color: var(--chart-line); border-color: var(--chart-grid); }
.market-chart > p { display: grid; min-height: 218px; place-items: center; color: var(--muted); }
.market-chart canvas { display: block; width: 100%; height: 218px; }
.market-details { border-top: 1px solid var(--line); margin-top: 4px; font-size: .875rem; }
.market-list ul { list-style: none; padding: 0; margin: 0; }
.market-list li { padding: 12px 0; display: flex; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.market-list li:last-child { border: 0; }
.market-list li time { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.increase { color: var(--danger); }
.decrease { color: var(--positive); }

.login-shell { max-width: 460px; margin: clamp(40px, 12vh, 120px) auto 48px; }
.login-shell .page-content { padding: 24px; }
.login-content h1 { margin-bottom: 24px; }
.login-content input { margin: 6px 0 16px; }
.login-content .primary { margin-top: 8px; width: 100%; }
.traffic-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; justify-content: flex-start; }
.traffic-controls select, .traffic-controls input { width: auto; }
.traffic-controls input { width: 86px; }
.traffic-controls label select, .traffic-controls label input { display: block; margin-top: 4px; }
.traffic-controls > p { margin-right: auto; }
.traffic-pagination { margin-top: 16px; }
.traffic-log { min-width: 740px; }
.traffic-log td { white-space: nowrap; }

@media (max-width: 960px) {
  .shell { grid-template-columns: 176px minmax(0, 1fr); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .topbar-inner { padding-inline: 12px; gap: 8px; min-height: 56px; flex-wrap: wrap; }
  .main-nav a, #logout { padding-inline: 8px; }
  .topbar-inner .brand { margin-right: auto; }
  .shell { display: block; }
  .section-nav { flex-direction: row; padding: 6px 12px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .section-nav a { flex: none; }
  .page-content { padding: 24px 16px 48px; }
  .try-grid { grid-template-columns: 1fr; }
  .quote-grid { gap: 6px; }
  .quote-card { padding: 10px; min-height: 120px; }
  .forecast-card, .market-chart-block, .market-list { padding: 14px; }
  th, td { padding-inline: 10px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
