/* Shared color tokens. Native system preference still works when JavaScript is off. */
:root {
  color-scheme: light;
  --bg:#eceef1;--panel:#ffffff;--surface-inset:#f6f7f9;--button:#ffffff;--hover:#e4e7ec;
  --selected:#eef0f3;--selected-edge:#a7adb6;--edge:#ccd1d8;--control-edge:#858d98;
  --text:#171c24;--secondary:#303843;--muted:#515b69;--gold:#79550e;
  --good:#176343;--bad:#a13026;--on-accent:#ffffff;--accent-hover:#5e4205;
  --warning-bg:#fff0ce;--warning-text:#704900;--chart-live:#146247;--chart-history:#885b15;
}
@media (prefers-color-scheme:dark) {
  :root:not([data-theme=light]) {
    color-scheme:dark;
    --bg:#111719;--panel:#192226;--surface-inset:#111a1e;--button:#263239;--hover:#34464f;
    --selected:#30362e;--selected-edge:#8c805b;--edge:#3d4c53;--control-edge:#71858e;
    --text:#e5edef;--secondary:#c4d2d8;--muted:#a6b7bf;--gold:#e3c482;
    --good:#99d8b4;--bad:#ffb3a3;--on-accent:#161c1f;--accent-hover:#f0d49d;
    --warning-bg:#392d17;--warning-text:#ffe2a5;--chart-live:#7be1b5;--chart-history:#e2b96e;
  }
}
:root[data-theme=dark] {
  color-scheme:dark;
  --bg:#111719;--panel:#192226;--surface-inset:#111a1e;--button:#263239;--hover:#34464f;
  --selected:#30362e;--selected-edge:#8c805b;--edge:#3d4c53;--control-edge:#71858e;
  --text:#e5edef;--secondary:#c4d2d8;--muted:#a6b7bf;--gold:#e3c482;
  --good:#99d8b4;--bad:#ffb3a3;--on-accent:#161c1f;--accent-hover:#f0d49d;
  --warning-bg:#392d17;--warning-text:#ffe2a5;--chart-live:#7be1b5;--chart-history:#e2b96e;
}
@media screen {
  html { background:var(--bg);scroll-padding-top:76px;scroll-padding-bottom:150px; }
  body { background:var(--bg);color:var(--text); }
  .visually-hidden { position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0; }
  .appearance-control { display:flex;align-items:center;gap:8px;margin-left:auto;font-size:11px;color:var(--muted);flex:none; }
  .appearance-control select { width:108px;margin:0;min-height:36px;font:13px system-ui,sans-serif;padding:6px 8px;background:var(--surface-inset);color:var(--text);border:1px solid var(--control-edge);border-radius:4px; }
  .appearance-row { display:flex;justify-content:flex-end;margin:0 0 18px; }
  .workspace-shell .appearance-control ~ .shell-account { margin-left:0; }
  :where(a,button,input,select,textarea,summary,[tabindex]):focus-visible { outline:2px solid var(--gold);outline-offset:3px; }
  :where(input,select,textarea) { accent-color:var(--gold); }
  :where(input,textarea)::placeholder { color:var(--muted);opacity:1; }
  :where(button,.button,summary) { touch-action:manipulation; }
  :where(.table-scroll,.scroll) { max-width:100%;overscroll-behavior-x:contain; }
  :where(.table-scroll,.scroll)[tabindex] { scrollbar-gutter:stable; }
  .scroll-hint { margin:0 0 6px;font:11px/1.5 system-ui,sans-serif;color:var(--muted); }
  :where(pre,code) { overflow-wrap:anywhere; }
  .primary { color:var(--on-accent); }
  .primary:hover { background:var(--accent-hover);border-color:var(--accent-hover);color:var(--on-accent); }
  dialog { max-height:calc(100vh - 24px);max-height:calc(100dvh - 24px);overscroll-behavior:contain; }
  #document-dialog { max-height:calc(100dvh - 24px); }
  .paper { color-scheme:light; }
}
@media screen and (max-width:750px), screen and (any-pointer:coarse) {
  /* Readable editing without disabling browser zoom. Keep desktop density intact. */
  body :where(input:not([type=checkbox]):not([type=radio]),select,textarea) { font-size:max(16px,1rem)!important;min-height:44px!important; }
  body :where(button,.button,summary) { min-height:44px; }
  body input:is([type=checkbox],[type=radio]):not(.bands input) { min-width:22px;min-height:22px; }
  body .check { min-height:44px; }
  .workspace-shell .shell-header { gap:10px; }
  .workspace-shell .shell-account { min-height:44px; }
  .appearance-control > span { position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%); }
  .appearance-control select { width:104px;min-height:44px; }
  .workspace-shell .shell-menu-heading button,.workspace-shell .prediction-nav a { min-height:44px; }
  body:not(.workspace-shell):not(.login-page) > header { height:auto;min-height:62px;flex-wrap:wrap;gap:8px 12px; }
  body:not(.workspace-shell) > header .appearance-control { margin-left:0; }
  body .feedline { align-items:center;gap:8px; }
  body .feedline button { flex:none;min-width:44px; }
  body .cost { grid-template-columns:minmax(0,1fr) minmax(84px,100px) auto; }
  body .cost button { padding-inline:8px; }
  body .paper input,body .paper select { min-height:0; }
}
@media screen and (max-width:420px) {
  .workspace-shell .shell-header { padding:0 8px;gap:8px; }
  .workspace-shell .shell-header .brand { font-size:16px;letter-spacing:.5px; }
  .workspace-shell .shell-account { font-size:11px;padding:6px 8px; }
  .appearance-control select { width:96px; }
  body .terms-bar { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (prefers-reduced-motion:reduce) {
  *,*::before,*::after { scroll-behavior:auto!important;animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important; }
}
/* Light is a paper-and-ink workspace, not a tint of the dark palette.
   Explicit scope keeps the accepted dark design and printed documents intact. */
@media screen {
  :root[data-theme=light] body { font-size:14px; }
  :root[data-theme=light] .workspace-shell .shell-header { background:#fff; }
  :root[data-theme=light] .workspace-shell .shell-nav { background:#f8f9fa; }
  :root[data-theme=light] .workspace-shell .shell-link { font-size:13px;font-weight:500; }
  :root[data-theme=light] .workspace-shell .shell-link[aria-current=page],
  :root[data-theme=light] .workspace-shell .shell-more.is-current { background:#252c36;color:#fff;box-shadow:none; }
  :root[data-theme=light] .workspace-shell .shell-link[aria-current=page] svg { color:#e3c482; }
  :root[data-theme=light] .workspace-shell .shell-nav .nav-label { color:var(--muted);font-size:10px;font-weight:600;letter-spacing:1.2px; }
  :root[data-theme=light] .workspace-shell .shell-header .descriptor { font-size:11px;letter-spacing:.7px; }
  :root[data-theme=light] .workspace-shell .shell-account { color:var(--text);font-weight:600;border-color:var(--control-edge); }
  :root[data-theme=light] :where(button,.button) { font-weight:550;border-radius:4px; }
  :root[data-theme=light] .primary { background:#252c36;border-color:#252c36;color:#fff; }
  :root[data-theme=light] .primary:hover { background:#111820;border-color:#111820; }
  :root[data-theme=light] button:disabled { opacity:1;background:#edf0f3;border-color:#d3d8df;color:#626c7a; }
  :root[data-theme=light] :where(input,select,textarea) { background:#fff;border-radius:4px; }
  :root[data-theme=light] .appearance-control select { background:#f6f7f9; }
  :root[data-theme=light] h1 { font-size:25px;font-weight:700;letter-spacing:-.6px; }
  :root[data-theme=light] h2 { font-size:12px;font-weight:700;letter-spacing:.7px; }
  :root[data-theme=light] .eyebrow { font-size:10px;font-weight:600;letter-spacing:1.1px; }
  :root[data-theme=light] .draft-chip { font-size:9px;letter-spacing:.6px;background:#fff;color:var(--muted);border:1px solid var(--edge); }
  :root[data-theme=light] .market-strip { background:#fff; }
  :root[data-theme=light] .quote strong { font-size:17px;font-weight:600;letter-spacing:-.5px; }
  :root[data-theme=light] .quote small { font-size:11px;color:var(--secondary); }
  :root[data-theme=light] .quote small:last-child { font-size:10px;color:var(--muted); }
  :root[data-theme=light] .feedline { background:#f8f9fa;font-size:11px; }
  :root[data-theme=light] .panel { border-color:var(--edge);border-radius:6px; }
  :root[data-theme=light] .workflow-help { background:transparent;border:0;border-left:2px solid var(--edge);padding:5px 12px; }
  :root[data-theme=light] .workflow-help summary { color:var(--secondary);font-weight:500; }
  :root[data-theme=light] :is(.terms,.item-entry,.item-details,.cost) label { color:var(--secondary);font-size:12px;font-weight:550; }
  :root[data-theme=light] :is(.terms,.item-entry,.item-details,.cost) :is(input,select) { background:#fff;font-size:14px;min-height:38px;padding:8px; }
  :root[data-theme=light] .terms { padding:14px 16px; }
  :root[data-theme=light] .reference-editor { font-size:12px; }
  :root[data-theme=light] #reference-note { font-size:11px; }
  :root[data-theme=light] .item-panel>.section-head { background:#f6f7f9;padding-block:12px; }
  :root[data-theme=light] #item-count { background:#e2e6ec;color:var(--secondary);font-size:11px; }
  :root[data-theme=light] .item-head strong { font-size:11px;color:var(--secondary);font-weight:600; }
  :root[data-theme=light] .item-head button { font-size:11px; }
  :root[data-theme=light] .line-value { font-size:13px;font-weight:600;color:var(--text); }
  :root[data-theme=light] .entry-hint { font-size:11px;background:#f8f9fa; }
  :root[data-theme=light] .summary { border-top:3px solid #a37a27;padding-top:16px; }
  :root[data-theme=light] .summary h2 { color:var(--text); }
  :root[data-theme=light] .summary h2 span { color:var(--muted);font-weight:500;font-size:11px; }
  :root[data-theme=light] .metric { font-size:12px; }
  :root[data-theme=light] .metric.offer { border-color:var(--edge); }
  :root[data-theme=light] .metric.offer span { font-size:12px;color:var(--secondary); }
  :root[data-theme=light] .metric.offer b { color:var(--text);font-weight:650; }
  :root[data-theme=light] .metric.net { background:#edf6f0;margin-top:10px;padding:12px 10px;border:0;border-radius:4px; }
  :root[data-theme=light] .summary .muted { font-size:11px;line-height:1.65; }
  :root[data-theme=light] .document-context { background:#fff;border-color:var(--edge);border-left:3px solid #a37a27;color:var(--secondary); }
  :root[data-theme=light] th { background:#f2f4f7;color:var(--secondary);font-size:12px;font-weight:600; }
  :root[data-theme=light] :is(.news-card-time,.news-read-link,.news-editorial,.news-byline,.news-disclosure) { font-size:12px; }
  :root[data-theme=light] .news-card .news-summary { font-size:14px; }
  :root[data-theme=light] .news-card h2 { font-size:21px;letter-spacing:-.3px; }
  :root[data-theme=light] .news-archive-notice { background:#fff;border-color:var(--edge);border-left-color:#a37a27; }
}
@media screen and (max-width:1150px) {
  :root[data-theme=light] .quote strong { font-size:16px; }
}
@media screen and (max-width:750px) {
  :root[data-theme=light] h1 { font-size:23px; }
  :root[data-theme=light] .workspace-shell .shell-nav { background:#fff; }
  :root[data-theme=light] .workspace-shell .shell-nav .shell-link { font-size:10px; }
  :root[data-theme=light] .workspace-shell .shell-menu-links .shell-link { font-size:13px; }
  :root[data-theme=light] .terms { padding:12px; }
  :root[data-theme=light] .feedline { font-size:10px; }
  :root[data-theme=light] .summary .metric.offer span { font-size:11px; }
  :root[data-theme=light] .metric.net { margin-top:0;padding:8px; }
  :root[data-theme=light] .workspace-shell #mobile-deal { background:#fff;border-color:#a37a27;gap:16px; }
  :root[data-theme=light] #mobile-deal small { font-size:9px; }
  :root[data-theme=light] #mobile-deal strong { color:var(--text);font-weight:650; }
  :root[data-theme=light] #mobile-deal #mobile-net { color:var(--good); }
  :root[data-theme=light] #mobile-deal button { background:#f6f7f9;color:var(--text);border-color:var(--control-edge);font-size:11px; }
  :root[data-theme=light] .news-card h2 { font-size:19px; }
}
/* Calculator-first spacing shared by both appearances. DOM order also places
   item entry before terms/reference/help, preserving a logical keyboard flow. */
@media screen {
  .workspace-shell main { padding:16px 20px; }
  #trade>.section-head { margin-bottom:10px; }
  #trade>.section-head h1 { margin:0;font-size:22px; }
  #trade .workbench { gap:14px; }
  #trade .panel { margin-bottom:10px; }
  #trade .item-panel>.section-head { padding:8px 12px; }
  #trade .item { padding:10px 12px; }
  #trade .item-head { margin-bottom:6px; }
  #trade .item-entry { gap:8px; }
  #trade .item-details { margin-top:8px;gap:8px; }
  #trade .entry-hint { padding:8px 12px; }
  #trade .terms { padding:10px 12px;margin:0 0 10px; }
  #trade .reference-editor { margin-bottom:10px; }
  #trade .reference-editor summary { padding-bottom:8px; }
  #trade .summary { padding:14px; }
  #trade .summary h2 { margin-bottom:12px; }
  #trade .metric { padding-block:7px; }
  #trade .metric.offer { padding-top:0;padding-bottom:12px; }
  #trade .metric.net { padding-block:10px; }
  #trade .summary .full { margin-top:10px;padding:9px; }
  #trade .summary .muted { margin-bottom:0; }
  #trade>.workflow-help { margin-top:8px;padding:4px 12px; }
  #documents .panel { padding:16px; }
  .news-card { padding:16px 18px; }
}
@media screen and (max-width:750px) {
  .workspace-shell main { padding:8px 10px 12px; }
  .workspace-shell[data-screen=trade] .market-strip { padding:0 8px;scrollbar-width:thin; }
  .workspace-shell[data-screen=trade] .quote { display:flex;flex-direction:column;align-items:flex-start;justify-content:center;min-width:103px;padding:5px 8px;gap:0; }
  .workspace-shell[data-screen=trade] .quote small { font-size:10px; }
  .workspace-shell[data-screen=trade] .quote strong { font-size:15px; }
  .workspace-shell[data-screen=trade] .quote small:last-child { display:none; }
  .workspace-shell[data-screen=trade] .feedline { padding:0 10px; }
  #trade>.section-head { display:flex;flex-wrap:nowrap;align-items:center;gap:8px;margin-bottom:6px; }
  #trade>.section-head>div:first-child { min-width:0; }
  #trade>.section-head>div:last-child { flex:none; }
  #trade>.section-head .eyebrow { display:none; }
  #trade>.section-head h1 { font-size:20px;overflow-wrap:anywhere; }
  #trade .workbench { gap:6px; }
  #trade .item-panel>.section-head { padding:4px 10px; }
  #trade .item { padding:4px 10px 10px; }
  #trade .item-head { margin-bottom:2px;gap:4px; }
  #trade .item-head>div { gap:6px; }
  #trade .item-entry { gap:6px 8px; }
  #trade :is(.item-entry,.item-details,.terms) label { font-size:12px;line-height:1.25; }
  #trade :is(.item-entry,.item-details,.terms) :is(input,select) { margin-top:4px;padding:7px; }
  #trade .purity-control>label+label { margin-top:6px; }
  #trade .entry-hint { padding:6px 10px;font-size:10px; }
  #trade .terms { gap:8px;padding:10px;grid-template-columns:1fr 1fr; }
  #trade .terms label:last-child { grid-column:1/-1;display:grid;grid-template-columns:auto 1fr;align-items:center;gap:10px; }
  #trade .terms label:last-child select { margin:0; }
  #trade .reference-editor summary { padding-bottom:4px; }
  #trade .summary { padding:12px; }
  #trade .summary .full { min-height:44px; }
  #documents .panel { padding:12px; }
  .news-card { padding:12px; }
}
@media print {
  :root,:root[data-theme],:root:not([data-theme=light]) { color-scheme:light;--bg:#fff;--panel:#fff;--surface-inset:#fff;--text:#111;--secondary:#222;--muted:#444;--gold:#333;--good:#111;--bad:#111;--edge:#bbb; }
  dialog::backdrop { display:none!important;background:transparent!important; }
  .appearance-control,.appearance-row,#appearance-status,.scroll-hint { display:none!important; }
}
