:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  line-height: 1.55;
  --canvas: #f5f6fa;
  --sidebar: #fbfcff;
  --surface: #fff;
  --subtle: #f2f4f9;
  --hover: #f1f3f9;
  --line: #e1e5ee;
  --input-line: #cdd3e1;
  --ink: #1d2437;
  --muted: #57627a;
  --accent: #4146b5;
  --accent-soft: #ebedff;
  --button: #4c50c5;
  --button-hover: #3a3ea7;
  --button-ink: #fff;
  --focus: #565ce0;
  --up: #ad354d;
  --down: #3e51a8;
  --trend-line: #5c63d5;
  --trend-fill: #656ce62b;
  --alert-bg: #fff1e5;
  --alert-ink: #853b16;
  --success-bg: #eaedff;
  --success-ink: #363b9b;
  --shadow: 0 3px 12px #17234b08;
  background: var(--canvas);
  color: var(--ink);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #10131d;
  --sidebar: #141824;
  --surface: #1a1f2e;
  --subtle: #212737;
  --hover: #252b3c;
  --line: #323a4d;
  --input-line: #424d65;
  --ink: #eef0fb;
  --muted: #a7b1c8;
  --accent: #b8bcff;
  --accent-soft: #2c3151;
  --button: #b2b6ff;
  --button-hover: #c6c9ff;
  --button-ink: #171b3a;
  --focus: #b7baff;
  --up: #ff9caf;
  --down: #adbaff;
  --trend-line: #a4a8ff;
  --trend-fill: #8d93ff42;
  --alert-bg: #392820;
  --alert-ink: #ffba8f;
  --success-bg: #2c3151;
  --success-ink: #c3c7ff;
  --shadow: 0 3px 12px #0002;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, h3, p, form { margin: 0; }
h1 { font-size: clamp(28px, 3.3vw, 44px); line-height: 1.2; font-weight: 700; letter-spacing: -.035em; overflow-wrap: anywhere; }
h2 { font-size: 18px; line-height: 1.4; font-weight: 675; }
h3 { font-size: 15px; font-weight: 650; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: .22em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.layout { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  display: flex;
  flex-direction: column;
  position: sticky;
  align-self: start;
  top: 0;
  height: 100vh;
  padding: 23px 15px 18px;
  background: var(--sidebar);
  border-inline-end: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; padding: 0 7px; width: fit-content; color: var(--ink); font-size: 17px; font-weight: 700; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
}
.sidebar nav { display: grid; gap: 5px; margin-top: 37px; }
.sidebar nav a { display: flex; align-items: center; gap: 9px; min-height: 44px; padding: 8px 11px; color: var(--muted); border-radius: 9px; font-size: 14px; font-weight: 550; white-space: nowrap; }
.sidebar nav a:hover { background: var(--hover); color: var(--ink); text-decoration: none; }
.sidebar nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav-icon { display: inline-grid; place-items: center; width: 18px; font-size: 16px; line-height: 1; }
.sidebar-actions { display: grid; gap: 12px; margin-top: auto; padding: 12px 4px 0; border-top: 1px solid var(--line); }
.sidebar-actions .tag { justify-self: start; }

.main { width: 100%; min-width: 0; max-width: 1330px; margin: 0 auto; padding: 42px clamp(24px, 4vw, 58px) 48px; }
.page-head, .section-head, .card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.page-head { margin-bottom: 28px; flex-wrap: wrap; }
.page-head > div { min-width: 0; }
.page-head .button { flex: 0 0 auto; }
.eyebrow { margin-bottom: 9px; color: var(--muted); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.eyebrow span { display: inline-block; color: var(--accent); padding: 0 4px; }
.section { margin-top: 27px; scroll-margin-top: 16px; }
.section-head { margin-bottom: 12px; }
.section-head a { color: var(--accent); font-size: 13px; font-weight: 550; }
.card-head { align-items: flex-start; }
.note { margin-top: 8px; }
small, .muted, .note { font-size: 12px; color: var(--muted); }
.empty { padding: 25px 18px; color: var(--muted); white-space: normal; }
.fred-notice { margin-top: 27px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 11px; line-height: 1.65; }

.panel { min-width: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.padded { padding: 20px; }
.metrics, .pairs { display: grid; gap: 14px; }
.research-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pairs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metric { padding: clamp(14px, 2vw, 21px); }
.metric-head, .metric-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px 12px; }
.metric-head h2 { color: var(--ink); font-size: 14px; font-weight: 640; }
.ticker, .tag { display: inline-block; width: fit-content; padding: 3px 7px; border-radius: 6px; background: var(--subtle); color: var(--muted); font-size: 10px; font-weight: 650; white-space: nowrap; letter-spacing: .03em; }
.metric-body { display: grid; grid-template-columns: minmax(min-content, 1fr) minmax(0, .85fr); gap: 6px; align-items: end; min-height: 79px; padding: 10px 0 13px; }
.metric-value { min-width: max-content; }
.metric-value strong { display: block; font-size: clamp(24px, 2.6vw, 37px); font-weight: 695; line-height: 1.15; letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
.metric-change { display: inline-block; margin-top: 5px; color: var(--muted); font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.trend { display: block; width: 100%; min-width: 0; height: 48px; }
.metric-foot { flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--line); }
.metric-foot small, .metric-foot a { font-size: 11px; }
.metric-foot a { flex: 0 0 auto; }
.context-card { min-height: 113px; }
.context-card h2 { margin-bottom: 10px; }
.context-card p { overflow-wrap: anywhere; }
.context-card a { font-weight: 650; }
.research-list article + article { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.research-list article p { margin-top: 5px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.research-list article small { flex-shrink: 0; }
.research-empty { padding: 11px 0; }
.research-copy p { margin: 6px 0 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.research-copy :is(h2, h3) { margin-top: 15px; }
.research-copy > h2:first-child { margin-top: 0; }
.research-links { margin-bottom: 0; padding-left: 20px; font-size: 13px; overflow-wrap: anywhere; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--button);
  color: var(--button-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 640;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--button-hover); text-decoration: none; }
button.secondary, .button.secondary { border-color: var(--line); background: var(--surface); color: var(--ink); }
button.secondary:hover, .button.secondary:hover { border-color: var(--input-line); background: var(--hover); }
button.link { border-color: transparent; background: transparent; color: var(--muted); }
button.link:hover { background: var(--hover); color: var(--ink); }

.theme-switch { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--subtle); }
.theme-switch button { flex: 1 1 auto; gap: 5px; min-height: 30px; padding: 3px 8px; border-radius: 7px; background: transparent; color: var(--muted); font-size: 12px; }
.theme-switch button:hover { color: var(--ink); }
.theme-switch button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 1px 4px #151e3a17; }
.theme-switch button span { font-size: 14px; line-height: 1; }

.fields { display: grid; gap: 13px; }
.fields button { justify-self: start; }
.inline-form { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 560; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 7px 10px;
  border: 1px solid var(--input-line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}
input::placeholder { color: var(--muted); opacity: .86; }
.search-research { margin-bottom: 12px; }

.page-jump { display: flex; gap: 7px; flex-wrap: wrap; }
.page-jump a { padding: 6px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); font-size: 13px; }
.page-jump a:hover { background: var(--hover); color: var(--ink); text-decoration: none; }
.page-jump a[aria-current="page"] { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 650; }
.flash { margin-bottom: 14px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 10px; font-size: 13px; }
.flash.error { background: var(--alert-bg); color: var(--alert-ink); }
.flash.success { background: var(--success-bg); color: var(--success-ink); }
.login { width: min(410px, calc(100% - 32px)); margin: clamp(26px, 11vh, 120px) auto 24px; }
.login-appearance { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.login .panel { padding: 26px; }
.login h1 { margin: 12px 0 19px; font-size: 24px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; }
th, td { padding: 11px clamp(10px, 1.3vw, 16px); border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
th { background: var(--subtle); color: var(--muted); font-size: 12px; font-weight: 640; }
td small { display: block; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--hover); }
.table-wrap button { min-height: 32px; padding: 4px 9px; font-size: 12px; }
.fund-table, #overseas .table-wrap { margin-top: 9px; }
.latest-price strong { font-size: 15px; }
.price-up { color: var(--up); }
.price-down { color: var(--down); }

@media (max-width: 1050px) {
  .layout { grid-template-columns: 178px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .main { padding-inline: 23px; }
}

@media (max-width: 820px) {
  .layout { display: block; }
  .sidebar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "brand actions" "nav nav";
    gap: 11px 7px;
    height: auto;
    position: static;
    padding: 12px 16px 9px;
    border-inline-end: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { grid-area: brand; padding: 0; align-self: center; }
  .sidebar-actions { grid-area: actions; display: flex; align-items: center; gap: 4px; margin: 0; padding: 0; border: 0; }
  .sidebar-actions button.link { min-height: 34px; padding: 4px 5px; font-size: 11px; }
  .sidebar nav { grid-area: nav; display: flex; gap: 4px; margin: 0; overflow-x: auto; }
  .sidebar nav a { min-height: 36px; padding: 6px 10px; font-size: 13px; }
  .main { padding: 26px 16px 34px; }
  .page-head { margin-bottom: 20px; }
}

@media (max-width: 620px) {
  .research-metrics, .pairs { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .metric-head h2 { font-size: 14px; }
  .metric-body { grid-template-columns: minmax(min-content, 1fr) minmax(0, 40%); min-height: 62px; padding: 8px 0 10px; }
  .metric-value strong { font-size: 28px; }
  .metric-foot { padding-top: 9px; }
  .context-card { min-height: 0; }
  .section { margin-top: 22px; }
  .fund-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .fund-table table, .fund-table tbody { display: block; }
  .fund-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 14px; padding: 13px 14px; border-bottom: 1px solid var(--line); }
  .fund-table tr:last-child { border-bottom: 0; }
  .fund-table td { display: block; padding: 0; border: 0; white-space: normal; }
  .fund-table td[data-label]::before { display: block; content: attr(data-label); color: var(--muted); font-size: 11px; }
  .fund-table .fund-name, .fund-table .empty { grid-column: 1/-1; }
  .fund-table .fund-name { padding-bottom: 3px; }
  .fund-table tbody tr:hover td { background: transparent; }
}

@media (max-width: 390px) {
  .brand { gap: 6px; font-size: 15px; }
  .brand-mark { width: 31px; height: 31px; font-size: 18px; }
  .theme-switch button { padding-inline: 6px; }
  .theme-switch button span, .nav-icon { display: none; }
}
