/* One design for the public page and the client area: a news-site frame (utility bar, masthead,
   market strip), unboxed modules under a heavy top rule, hairline tables. Benchmarked on Reuters
   (layout), Axios (short briefs, chart titles that state the finding) and EIA (sources, release dates).
   System fonts only: web fonts don't load reliably in mainland China. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-alt: #f4f4f2;
  --surface: #ffffff;
  --ink: #111111;
  --ink-2: #3d3d3d;
  --muted: #6b6b6b;
  --rule: #e3e3e0;
  --rule-strong: #111111;
  --grid: #ececea;
  --brand: #d4470f;
  --link: #1556b8;
  --up: #c62828;
  --down: #1b7f3b;
  --up-bg: #fdecea;
  --down-bg: #e5f3e9;
  --flat-bg: #efefed;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --footer-bg: #111111;
  --footer-ink: #d7d7d4;
  --danger: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121212; --bg-alt: #1b1b1a; --surface: #181818; --ink: #f2f2f0; --ink-2: #d2d2ce; --muted: #9c9c97;
    --rule: #2c2c2a; --rule-strong: #f2f2f0; --grid: #262624; --brand: #f06a2f; --link: #7fb0ff;
    --up: #f07171; --down: #4cc27a; --up-bg: #3a1f1f; --down-bg: #17321f; --flat-bg: #262624;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --footer-bg: #0b0b0b; --footer-ink: #bdbdb8; --danger: #f97066;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212; --bg-alt: #1b1b1a; --surface: #181818; --ink: #f2f2f0; --ink-2: #d2d2ce; --muted: #9c9c97;
  --rule: #2c2c2a; --rule-strong: #f2f2f0; --grid: #262624; --brand: #f06a2f; --link: #7fb0ff;
  --up: #f07171; --down: #4cc27a; --up-bg: #3a1f1f; --down-bg: #17321f; --flat-bg: #262624;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --footer-bg: #0b0b0b; --footer-ink: #bdbdb8; --danger: #f97066;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; scrollbar-gutter: stable; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1160px; margin: 0 auto; padding: 0 16px; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }

/* Utility bar, masthead, section nav */
.utility { background: var(--bg-alt); border-bottom: 1px solid var(--rule); font-size: 13px; color: var(--muted); }
.utility .wrap { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 34px; }
.utility a { color: var(--ink-2); }
.masthead { background: var(--bg); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 5; }
.masthead .wrap { display: flex; align-items: center; gap: 28px; min-height: 60px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; font-size: 19px; letter-spacing: .02em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .mark { width: 22px; height: 22px; border-radius: 4px; background: var(--brand); position: relative; flex-shrink: 0; }
.brand .mark::after { content: ""; position: absolute; left: 6px; right: 6px; bottom: 5px; height: 9px; border-radius: 50% 50% 45% 45%; background: var(--bg); }
.brand .tag { font-size: 12px; font-weight: 600; color: var(--brand); border: 1px solid var(--brand); border-radius: 3px; padding: 0 6px; letter-spacing: 0; }
.sections { display: flex; gap: 22px; overflow-x: auto; scrollbar-width: none; font-size: 15px; font-weight: 600; }
.sections::-webkit-scrollbar { display: none; }
.sections a { color: var(--ink-2); white-space: nowrap; padding: 18px 0 16px; border-bottom: 3px solid transparent; }
.sections a:hover, .sections a[aria-current="page"] { color: var(--ink); text-decoration: none; border-bottom-color: var(--brand); }
.masthead .right { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.btn {
  display: inline-block; border: 1px solid var(--rule); border-radius: 4px; padding: 6px 14px; background: var(--surface);
  color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; line-height: 1.4;
}
.btn:hover { border-color: var(--ink); text-decoration: none; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { opacity: .88; }

/* Market strip */
.ticker { border-bottom: 1px solid var(--rule); background: var(--bg); }
.ticker .wrap { display: flex; overflow-x: auto; scrollbar-width: none; }
.ticker .wrap::-webkit-scrollbar { display: none; }
.tick { display: flex; align-items: baseline; gap: 8px; padding: 9px 18px 9px 0; margin-right: 18px; border-right: 1px solid var(--rule); white-space: nowrap; color: var(--ink); font-size: 14px; }
.tick:last-child { border-right: 0; }
.tick:hover { text-decoration: none; }
.tick .sym { font-weight: 700; }
.tick .px { font-variant-numeric: tabular-nums; }
.chg { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 0 6px; border-radius: 3px; background: var(--flat-bg); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.chg.up { background: var(--up-bg); color: var(--up); }
.chg.down { background: var(--down-bg); color: var(--down); }

/* Page sections */
main { padding: 8px 0 48px; }
.kicker { font-size: 13px; font-weight: 700; color: var(--brand); letter-spacing: .04em; margin: 0 0 6px; }
.rule-top { border-top: 3px solid var(--rule-strong); padding-top: 12px; }
.lead { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 40px; padding: 28px 0 32px; border-bottom: 1px solid var(--rule); }
.story h1 { font-size: 34px; line-height: 1.25; margin: 0 0 10px; font-weight: 800; letter-spacing: -.005em; }
.dateline { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.brief { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.brief li { font-size: 17px; line-height: 1.7; color: var(--ink-2); padding-left: 16px; border-left: 3px solid var(--rule); }
.brief b { color: var(--ink); margin-right: 8px; }
.side h2 { font-size: 15px; font-weight: 800; margin: 0 0 6px; }
.release { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }

.modules { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 40px; padding: 32px 0 0; }
.module { min-width: 0; padding: 32px 0 0; }
.modules .module { padding-top: 0; }
.mod-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.mod-head h2 { font-size: 22px; line-height: 1.35; margin: 0; font-weight: 800; }
.dek { font-size: 14px; color: var(--muted); margin: 4px 0 0; }
.source { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
.note { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; }

.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; flex-shrink: 0; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; padding: 4px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* Charts (assets/charts.js) */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 12px; font-family: inherit; }
.chart .label { fill: var(--ink-2); font-size: 12px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--ink-2); margin: 0 0 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--rule); border-radius: 4px;
  padding: 6px 10px; font-size: 13px; color: var(--ink); white-space: nowrap; box-shadow: 0 2px 10px rgba(0, 0, 0, .1); display: none; z-index: 2;
}
.tip .d { color: var(--muted); font-size: 12px; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.empty { color: var(--muted); font-size: 14px; padding: 24px 0; text-align: center; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 12px 8px 0; border-bottom: 1px solid var(--rule); white-space: nowrap; }
th { font-weight: 700; color: var(--muted); font-size: 12.5px; border-bottom: 1px solid var(--ink); }
td.up, span.up { color: var(--up); }
td.down, span.down { color: var(--down); }
tr:last-child td { border-bottom: 0; }
td.name { font-weight: 600; white-space: normal; }

/* Methodology */
.method-title { font-size: 22px; line-height: 1.35; margin: 0 0 16px; font-weight: 800; }
.method { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 32px; }
.method h3 { font-size: 15px; margin: 0 0 6px; font-weight: 800; }
.method p, .method li { font-size: 14px; color: var(--ink-2); margin: 0; }
.method ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }

/* Footer */
.site-footer { background: var(--footer-bg); color: var(--footer-ink); font-size: 13px; padding: 28px 0 36px; margin-top: 48px; border-top: 1px solid var(--rule); }
.site-footer .wrap { display: grid; gap: 8px; }
.site-footer .brand { color: #fff; font-size: 16px; }
.site-footer .brand .mark::after { background: var(--footer-bg); }
.site-footer a { color: var(--footer-ink); text-decoration: underline; }
.site-footer p { margin: 0; }

/* Client area: tiles, the card, products */
.page-head { padding: 26px 0 6px; }
.page-head h1 { font-size: 28px; line-height: 1.3; margin: 0 0 4px; font-weight: 800; }
.page-head p { margin: 0; color: var(--muted); font-size: 14px; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; margin: 14px 0 6px; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.tile { padding: 12px 16px 12px 0; min-width: 0; }
.tile + .tile { border-left: 1px solid var(--rule); padding-left: 16px; }
.tile .k { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.tile .v { font-size: 24px; font-weight: 800; margin: 2px 0; }
.tile .s { font-size: 12.5px; color: var(--muted); }
.v.up { color: var(--up); }
.v.down { color: var(--down); }
.window { font-size: 15px; color: var(--ink-2); margin: 0 0 14px; }
.products { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border-top: 1px solid var(--rule); }
.product { padding: 14px 18px 14px 0; min-width: 0; }
.product + .product { border-left: 1px solid var(--rule); padding-left: 18px; }
.product h3 { margin: 0 0 8px; font-size: 16px; font-weight: 800; }
.badge { display: inline-block; border-radius: 3px; padding: 1px 10px; font-size: 14px; font-weight: 700; background: var(--flat-bg); color: var(--ink); }
.badge.more { background: var(--up-bg); color: var(--up); }
.badge.less { background: var(--down-bg); color: var(--down); }
.product p { margin: 8px 0 0; font-size: 14px; color: var(--ink-2); }
.product ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
section.card { padding: 30px 0 0; }
section.card > .card-head { border-top: 3px solid var(--rule-strong); padding-top: 12px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 20px; font-weight: 800; }
.card-head p { margin: 4px 0 0; font-size: 14px; color: var(--muted); }

/* Login */
.login { max-width: 380px; margin: 64px auto; padding: 0; }
.login h1 { margin: 0 0 4px; font-size: 26px; font-weight: 800; }
.login p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin: 14px 0 6px; }
.login input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 4px; background: var(--surface); color: var(--ink); font: inherit;
}
.login input:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
.login .btn { width: 100%; margin-top: 22px; padding: 10px; }
.login .err { color: var(--danger); font-size: 13px; margin: 12px 0 0; min-height: 1em; }

/* Chat */
.chat { max-width: 780px; }
.chat-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 26px 0 10px; border-bottom: 1px solid var(--rule); }
.chat-head h1 { margin: 0 0 4px; font-size: 26px; font-weight: 800; }
.chat-head p { margin: 0; color: var(--muted); font-size: 14px; }
.chat-head .btn { white-space: nowrap; flex-shrink: 0; }
.log { display: flex; flex-direction: column; gap: 14px; padding: 16px 0; }
.msg { max-width: 88%; }
.msg .body { white-space: pre-wrap; word-break: break-word; padding: 10px 14px; border-radius: 6px; font-size: 15px; line-height: 1.75; }
.msg.user { align-self: flex-end; }
.msg.user .body { background: var(--ink); color: var(--bg); }
.msg.assistant { align-self: flex-start; }
.msg.assistant .body { background: var(--bg-alt); border-left: 3px solid var(--brand); border-radius: 0 6px 6px 0; }
.msg.pending .body { color: var(--muted); }
.msg .meta { font-size: 12px; color: var(--muted); margin: 4px 4px 0; }
.rate { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 4px 0; }
.rate-btn { min-height: 32px; border: 1px solid var(--rule); background: transparent; color: var(--muted); border-radius: 16px; padding: 2px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.rate-btn:hover { border-color: var(--ink); color: var(--ink); }
.rate-btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.rate-status { font-size: 12px; color: var(--muted); }
.rate-note { display: flex; gap: 6px; width: 100%; }
.rate-note[hidden] { display: none; }
.rate-note input { flex: 1; min-width: 0; border: 1px solid var(--rule); background: var(--surface); color: var(--ink); border-radius: 6px; padding: 6px 10px; font: inherit; font-size: 16px; }
.rate-note input:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
.starters { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip { border: 1px solid var(--rule); background: var(--surface); color: var(--ink-2); border-radius: 16px; padding: 6px 12px; font: inherit; font-size: 14px; cursor: pointer; }
.chip:hover { border-color: var(--ink); color: var(--ink); }
.ask { display: flex; gap: 8px; align-items: flex-end; position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; border-top: 1px solid var(--rule); }
.ask textarea {
  flex: 1; resize: vertical; min-height: 46px; max-height: 200px; padding: 10px 12px; border: 1px solid var(--rule);
  border-radius: 4px; background: var(--surface); color: var(--ink); font: inherit;
}
.ask textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
.ask .btn { height: 46px; }
.chat .err { color: var(--danger); font-size: 13px; margin: 4px 0 0; min-height: 1em; }

@media (max-width: 860px) {
  .lead { grid-template-columns: 1fr; gap: 28px; padding-top: 20px; }
  .modules { grid-template-columns: 1fr; gap: 0; padding-top: 0; }
  .modules .module { padding-top: 32px; }
  .method { grid-template-columns: 1fr; gap: 18px; }
  .story h1 { font-size: 26px; }
  .brief li { font-size: 16px; }
  .masthead .wrap { gap: 18px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile:nth-child(3) { border-left: 0; padding-left: 0; }
  .tile:nth-child(n + 3) { border-top: 1px solid var(--rule); }
  .products { grid-template-columns: 1fr; }
  .product + .product { border-left: 0; padding-left: 0; border-top: 1px solid var(--rule); }
}
@media (max-width: 560px) {
  .utility .hide-sm, .masthead .hide-sm { display: none; }
  .brand { font-size: 17px; }
  .masthead .wrap { flex-wrap: wrap; gap: 0 18px; min-height: 0; padding-top: 10px; }
  .sections { order: 3; width: 100%; gap: 18px; }
  .sections a { padding: 10px 0 8px; }
  .masthead .right { margin-left: auto; }
  .mod-head h2 { font-size: 19px; }
  .tile .v { font-size: 20px; }
}

/* Phones first: touch targets, scrubbing charts with a finger, tables that turn into small cards */
.chart svg { touch-action: pan-y; }
@media (max-width: 560px) {
  .seg button { padding: 8px 12px; font-size: 14px; }
  .utility .wrap { min-height: 38px; }
  .tick { padding: 10px 14px 10px 0; margin-right: 14px; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 10px 0; border-bottom: 1px solid var(--rule); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; border: 0; padding: 3px 0; white-space: normal; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex-shrink: 0; }
  table.stack td.empty { display: block; text-align: center; }
  table.stack td.empty::before { content: none; }
  .ask { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .hide-sm { display: none; }
  html { scroll-padding-top: 112px; }
}
.nw { white-space: nowrap; }
