/* ==========================================================================
   SHELL — app frame: rail, status strip, main, mobile tab bar, footer.
   Prefix .sh-*. Layer: shell.
   ========================================================================== */
@layer shell {

/* Skip link */
.sh-skip {
  position: fixed; left: var(--s-3); top: -60px; z-index: var(--z-skip);
  padding: var(--s-2) var(--s-4); border-radius: var(--r-sm);
  background: var(--accent-fill); color: var(--accent-ink); font-weight: var(--fw-semibold);
  text-decoration: none; transition: top var(--dur-1) var(--ease-out);
}
.sh-skip:focus { top: var(--s-3); }

/* ---- Frame grid ------------------------------------------------------- */
.sh-app {
  --rail-cur: var(--rail-w);
  display: grid;
  grid-template-columns: var(--rail-cur) minmax(0, 1fr);
  grid-template-rows: var(--strip-h) minmax(0, 1fr);
  min-height: 100dvh;
}
:root[data-rail="pinned"] .sh-app { --rail-cur: var(--rail-w-open); }

/* ---- Rail ------------------------------------------------------------- */
.sh-rail {
  grid-column: 1;
  grid-row: 1 / span 2;
  position: sticky;
  top: 0;
  height: 100dvh;
  z-index: var(--z-rail);
}
.sh-rail-panel {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--rail-cur);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--line-1);
  overflow: hidden;
  transition: width var(--dur-2) var(--ease-out-strong), box-shadow var(--dur-2) var(--ease-out), background-color var(--dur-2);
}
.sh-rail[data-open] .sh-rail-panel {
  width: var(--rail-w-open);
  background: var(--surface-1);
  box-shadow: var(--shadow-3);
  border-right-color: var(--line-2);
}
:root[data-rail="pinned"] .sh-rail[data-open] .sh-rail-panel { box-shadow: none; background: var(--bg); border-right-color: var(--line-1); }

.sh-brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: var(--strip-h);
  padding: 0 0 0 24px;
  flex: none;
  color: var(--ink-1);
  text-decoration: none;
  border-bottom: 1px solid var(--line-1);
}
.sh-mark { width: 24px; height: 24px; flex: none; display: block; }
.sh-wordmark { display: flex; flex-direction: column; min-width: 0; white-space: nowrap; opacity: 0; transform: translateX(-4px); transition: opacity var(--dur-1) var(--ease-out), transform var(--dur-2) var(--ease-out); }
.sh-wordmark b { font-family: var(--font-serif); font-size: 15.5px; font-weight: 600; letter-spacing: -0.005em; color: var(--ink-1); line-height: 1.15; font-variation-settings: "opsz" 18; }
.sh-wordmark span { font-size: var(--fs-1); color: var(--ink-3); letter-spacing: var(--track-micro); text-transform: uppercase; font-weight: 600; margin-top: 2px; }

.sh-nav { display: flex; flex-direction: column; gap: 2px; padding: var(--s-3) 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; flex: 1 1 auto; }
.sh-nav::-webkit-scrollbar { display: none; }
.sh-nav-sep { height: 1px; background: var(--line-1); margin: var(--s-2) 16px; flex: none; }
.sh-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 40px;
  margin: 0 12px;
  padding: 0 13px;
  border-radius: var(--r-sm);
  color: var(--ink-3);
  text-decoration: none;
  font-size: var(--fs-4);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  flex: none;
  transition: background-color var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out);
}
.sh-nav-item .m-icon { --icon-size: 20px; flex: none; }
.sh-nav-label { opacity: 0; transition: opacity var(--dur-1) var(--ease-out); }
.sh-nav-item .m-kbd-group { margin-left: auto; opacity: 0; transition: opacity var(--dur-1); }
@media (hover: hover) {
  .sh-nav-item:hover { color: var(--ink-1); background: var(--line-1); transition-duration: var(--dur-0); }
}
.sh-nav-item[aria-current="page"] { color: var(--ink-1); background: var(--line-1); }
.sh-nav-item[aria-current="page"]::before {
  content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 2px;
  border-radius: 0 2px 2px 0; background: var(--accent);
}
.sh-nav-item[aria-current="page"] .m-icon { color: var(--accent); }
.sh-nav-item:focus-visible { outline-offset: -2px; }
.sh-rail[data-open] .sh-wordmark, .sh-rail[data-open] .sh-nav-label { opacity: 1; transform: none; }
.sh-rail[data-open] .sh-nav-item:hover .m-kbd-group { opacity: 1; }
.sh-rail-foot { flex: none; display: flex; flex-direction: column; gap: 2px; padding: var(--s-2) 0 var(--s-3); border-top: 1px solid var(--line-1); }
.sh-rail-foot .sh-nav-item { color: var(--ink-3); }
.sh-pin[aria-pressed="true"] .m-icon { color: var(--accent); }

/* ---- Status strip ------------------------------------------------------ */
.sh-strip {
  grid-column: 2;
  grid-row: 1;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--s-4);
  height: var(--strip-h);
  padding: 0 var(--gutter);
  background: var(--bg);
  border-bottom: 1px solid var(--line-1);
  min-width: 0;
}
.sh-strip-mark { display: none; }
.sh-strip-group { display: flex; align-items: center; gap: var(--s-2_5); min-width: 0; white-space: nowrap; }
.sh-strip-sep { width: 1px; height: 20px; background: var(--line-1); flex: none; }
.sh-strip-spacer { flex: 1 1 auto; min-width: var(--s-2); }
.sh-quote { text-decoration: none; color: inherit; border-radius: var(--r-sm); flex: none; }
.sh-ticker { font-family: var(--font-mono); font-size: var(--fs-3); font-weight: 500; color: var(--ink-1); letter-spacing: 0.04em; }
.sh-last { font-family: var(--font-mono); font-size: 15px; font-weight: 500; color: var(--ink-1); font-variant-numeric: tabular-nums; border-radius: var(--r-xs); padding: 1px 2px; margin: -1px -2px; }
.sh-vol { font-family: var(--font-mono); font-size: var(--fs-2); color: var(--ink-3); white-space: nowrap; }
.sh-vol b { color: var(--ink-2); font-weight: 400; }
.sh-chip-label { font-size: var(--fs-2); color: var(--ink-3); }
.sh-airborne .m-icon, .sh-next .m-icon { --icon-size: 15px; color: var(--ink-3); }
.sh-airborne b { font-family: var(--font-mono); font-weight: 500; color: var(--ink-1); font-size: var(--fs-4); }
.sh-airborne[data-on] .m-icon { color: var(--live); }
.sh-next { text-decoration: none; color: var(--ink-2); font-size: var(--fs-3); max-width: 360px; border-radius: var(--r-sm); }
.sh-next-title { overflow: hidden; text-overflow: ellipsis; min-width: 0; color: var(--ink-2); }
@media (hover: hover) { .sh-next:hover .sh-next-title, .sh-quote:hover .sh-ticker { color: var(--ink-1); text-decoration: underline; text-decoration-color: var(--line-3); text-underline-offset: 0.2em; } }
.sh-next m-countdown { font-size: var(--fs-3); }
.sh-fresh { display: inline-flex; align-items: center; gap: var(--s-2); height: 30px; line-height: 1; padding: 0 var(--s-2); border-radius: var(--r-sm); color: var(--ink-3); font-size: var(--fs-2); cursor: pointer; white-space: nowrap; flex: none; }
@media (hover: hover) { .sh-fresh:hover { background: var(--line-1); color: var(--ink-1); } }
.sh-search {
  display: inline-flex; align-items: center; gap: var(--s-2);
  height: 32px; flex: none; width: 220px; padding: 0 var(--s-1_5) 0 var(--s-2_5);
  border-radius: var(--r-sm);
  border: 1px solid var(--line-2);
  background: var(--surface-1);
  color: var(--ink-3);
  font-size: var(--fs-3);
  cursor: pointer;
  transition: border-color var(--dur-2) var(--ease-out), color var(--dur-2);
}
.sh-search .m-icon { --icon-size: 15px; }
.sh-search > span:first-of-type { flex: 1; text-align: left; }
.sh-search .m-kbd { height: 1.15rem; min-width: 1.15rem; font-size: 11px; background: transparent; }
@media (hover: hover) { .sh-search:hover { border-color: var(--line-3); color: var(--ink-1); } }
.sh-search-icon { display: none; }
.sh-account { display: inline-flex; align-items: center; gap: var(--s-2); height: 34px; padding: 0 var(--s-1) 0 var(--s-1); border-radius: var(--r-pill); cursor: pointer; color: var(--ink-2); }
@media (hover: hover) { .sh-account:hover { background: var(--line-1); color: var(--ink-1); } }
.sh-avatar { position: relative; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-2); color: var(--ink-2); }
.sh-avatar .m-icon { --icon-size: 17px; }
.sh-account[data-tier="paid"] .sh-avatar { box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent); background: var(--accent-soft); }
.sh-account .m-chip { margin-right: 2px; }
.sh-offline { display: none; }
:root[data-offline] .sh-offline { display: inline-flex; }

/* ---- Main + outlet ------------------------------------------------------ */
.sh-main {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  display: flex;
  flex-direction: column;
  outline: none;
}
.sh-outlet {
  flex: 1 0 auto;
  width: 100%;
  min-height: calc(100dvh - var(--strip-h));   /* footer always starts below the fold: no CLS when a view mounts */
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--gutter) var(--s-16);
  view-transition-name: main;
}
.view { min-width: 0; }
.sh-progress {
  position: fixed; left: 0; top: 0; z-index: var(--z-toast); height: 2px; width: 100%;
  background: var(--accent); transform-origin: left; transform: scaleX(0); opacity: 0;
  transition: transform 1.2s var(--ease-out), opacity var(--dur-2);
  pointer-events: none;
}
.sh-progress[data-on] { opacity: 1; transform: scaleX(0.7); }

/* ---- Footer -------------------------------------------------------------- */
.sh-foot {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-6) var(--gutter) var(--s-10);
  border-top: 1px solid var(--line-1);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s-4) var(--s-8);
  font-size: var(--fs-2);
  color: var(--ink-3);
  line-height: 1.6;
}
.sh-foot p { max-width: 86ch; }
.sh-foot strong { color: var(--ink-2); font-weight: var(--fw-semibold); }
.sh-foot nav { display: flex; gap: var(--s-4); flex-wrap: wrap; align-items: flex-start; }
.sh-foot a, .sh-foot-btn { color: var(--ink-3); text-decoration: none; font: inherit; line-height: inherit; cursor: pointer; }
@media (hover: hover) { .sh-foot a:hover, .sh-foot-btn:hover { color: var(--ink-1); text-decoration: underline; } }

/* ---- Mobile tab bar --------------------------------------------------------- */
.sh-tabbar {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: var(--z-tabbar);
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface-1);
  border-top: 1px solid var(--line-2);
}
.sh-tabs { display: grid; grid-template-columns: repeat(5, 1fr); height: var(--tabbar-h); }
.sh-tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--ink-3);
  font-size: var(--fs-2);
  font-weight: var(--fw-medium);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.sh-tab .m-icon { --icon-size: 22px; }
.sh-tab[aria-current="page"], .sh-tab[aria-expanded="true"] { color: var(--ink-1); }
.sh-tab[aria-current="page"] .m-icon { color: var(--accent); }
.sh-tab[aria-current="page"]::before { content: ""; position: absolute; top: -1px; left: 50%; width: 24px; height: 2px; margin-left: -12px; border-radius: 0 0 2px 2px; background: var(--accent); }
.sh-tab:active { background: var(--line-1); }
.sh-tab:focus-visible { outline-offset: -3px; }

/* More sheet grid */
.sh-more { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); padding-top: var(--s-1); }
.sh-more-item {
  display: flex; flex-direction: column; gap: var(--s-1); padding: var(--s-3) var(--s-3);
  border-radius: var(--r-md); border: 1px solid var(--line-1); background: var(--surface-2);
  color: var(--ink-1); text-decoration: none; min-height: 76px;
}
.sh-more-item .m-icon { --icon-size: 20px; color: var(--ink-3); }
.sh-more-item[aria-current="page"] { border-color: var(--accent-line); }
.sh-more-item[aria-current="page"] .m-icon { color: var(--accent); }
.sh-more-item b { font-weight: var(--fw-medium); font-size: var(--fs-4); }
.sh-more-item span { color: var(--ink-3); font-size: var(--fs-2); line-height: 1.35; }
.sh-more-row { display: flex; gap: var(--s-2); flex-wrap: wrap; margin-top: var(--s-4); padding-top: var(--s-4); border-top: 1px solid var(--line-1); }

/* Shortcuts sheet */
.sh-keys { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s-6) var(--s-8); }
.sh-keys h3 { margin-bottom: var(--s-2); }
.sh-keys dl { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 var(--s-4); margin: 0; }
.sh-keys dt, .sh-keys dd { padding: 7px 0; border-bottom: 1px solid var(--line-1); margin: 0; font-size: var(--fs-3); }
.sh-keys dt { color: var(--ink-2); }
.sh-keys dd { text-align: right; }

/* Freshness popover */
.sh-fresh-pop { min-width: 300px; padding: var(--s-2); }
.sh-fresh-pop .m-kv { max-height: 46vh; overflow: auto; }
.sh-fresh-pop dd .m-pip { justify-content: flex-end; }

/* Account popover */
.sh-acct-head { display: flex; gap: var(--s-3); align-items: center; padding: var(--s-2) var(--s-2_5) var(--s-3); }
.sh-acct-head .sh-avatar { width: 36px; height: 36px; }
.sh-acct-head b { display: block; color: var(--ink-1); font-weight: var(--fw-medium); font-size: var(--fs-4); }
.sh-acct-head span { display: block; color: var(--ink-3); font-size: var(--fs-2); }

/* Global pages: 404, error, search */
.sh-page { display: flex; flex-direction: column; gap: var(--s-6); padding: var(--s-16) 0 var(--s-8); max-width: 760px; }
.sh-page .t-display { font-size: clamp(2.25rem, 1.6rem + 2.6vw, 4rem); }
.sh-page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--s-2); }
.sh-page-link { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3); border-radius: var(--r-md); border: 1px solid var(--line-1); background: var(--surface-1); text-decoration: none; color: var(--ink-1); }
.sh-page-link .m-icon { --icon-size: 18px; color: var(--ink-3); margin-top: 2px; }
.sh-page-link span { display: block; font-size: var(--fs-2); color: var(--ink-3); margin-top: 2px; }
@media (hover: hover) { .sh-page-link:hover { border-color: var(--line-3); } }
.sh-code { font-family: var(--font-mono); font-size: var(--fs-2); color: var(--ink-3); background: var(--surface-sunken); border: 1px solid var(--line-1); border-radius: var(--r-sm); padding: var(--s-3); overflow: auto; max-height: 160px; }

/* ---- View transitions: chrome stays put, content crossfades ---------------- */
::view-transition-old(root), ::view-transition-new(root) { animation: none; }
::view-transition-old(main) { animation: sh-vt-out 120ms var(--ease-exit) both; }
::view-transition-new(main) { animation: sh-vt-in 240ms var(--ease-out) both; }
@keyframes sh-vt-out { to { opacity: 0; } }
@keyframes sh-vt-in { from { opacity: 0; transform: translateY(6px); } }

/* ---- Responsive ------------------------------------------------------------- */
@media (max-width: 1279px) {
  .sh-search { width: auto; padding: 0 var(--s-2); }
  .sh-search > span:first-of-type { display: none; }
  .sh-account .m-chip { display: none; }
}
@media (max-width: 1100px) {
  .sh-next-title { max-width: 140px; }
}
@media (max-width: 1100px) {
  .sh-vol, .sh-quote + .sh-strip-sep { display: none; }
}
@media (max-width: 959px) {
  .sh-next, .sh-next + .sh-strip-sep { display: none; }
  .sh-fresh-label { display: none; }
}
@media (max-width: 719px) {
  .sh-app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .sh-rail { display: none; }
  .sh-strip { grid-column: 1; gap: var(--s-3); padding: 0 var(--s-2) 0 var(--gutter); padding-top: var(--safe-t); height: calc(var(--strip-h) + var(--safe-t)); }
  .sh-strip-mark { display: flex; align-items: center; flex: none; }
  .sh-strip-mark .sh-mark { width: 22px; height: 22px; }
  .sh-main { grid-column: 1; }
  .sh-outlet { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--s-10)); }
  .sh-foot { grid-template-columns: 1fr; padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--s-6)); }
  .sh-tabbar { display: block; }
  .sh-vol, .sh-vol + .sh-strip-sep, .sh-airborne-label, .sh-fresh, .sh-fresh + .sh-strip-sep { display: none; }
  .sh-airborne { display: none; }
  .sh-search { border: 0; background: transparent; width: 44px; height: 44px; justify-content: center; padding: 0; flex: none; }
  .sh-search .m-kbd-group { display: none; }
  .sh-search .m-icon { --icon-size: 19px; }
  .sh-account { padding: 0 var(--s-2); height: 44px; min-width: 44px; justify-content: center; flex: none; }
  .sh-strip-mark { width: 44px; height: 44px; justify-content: center; margin-left: -11px; }
  .sh-strip-sep { display: none; }
  .sh-last { font-size: 14px; }
}
/* Touch: every control at least 44 x 44 (spec §2) on touch devices and below 800px */
@media (pointer: coarse), (max-width: 799px) {
  .sh-nav-item { height: 44px; }
  .sh-quote, .sh-airborne, .sh-next { min-height: 44px; }
  .sh-fresh { height: 44px; min-width: 44px; justify-content: center; }
  .sh-search { height: 44px; min-width: 44px; justify-content: center; flex: none; }
  .sh-account { height: 44px; min-width: 44px; justify-content: center; flex: none; }
  .sh-foot nav a, .sh-foot-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; }
  .sh-foot nav { gap: 0 var(--s-4); }
}
@media (max-width: 420px) {
  .sh-strip { gap: var(--s-1_5); }
  .sh-quote { gap: var(--s-2); }
  .sh-quote .m-pip > span:not(.m-pip-dot) { display: none; }
}
@media (max-width: 340px) {
  .sh-quote .m-delta { display: none; }
}
@media print {
  .sh-rail, .sh-strip, .sh-tabbar, .sh-skip, .m-toasts { display: none !important; }
  .sh-app { display: block; }
}
}
