/* Markets home (public/market-home.js), 2026-09-24.
   Reads the tokens in v3.css and never declares its own. Every rule is scoped
   under .mh so nothing leaks into the rest of the workspace. The layout follows
   the width of the box it is mounted in (container queries), not the window,
   because the workspace rails take a different share at every breakpoint. */

.mh {
  container: mh / inline-size;
  display: grid;
  gap: 14px;
  min-width: 0;
  color: var(--text);
  font: 400 13px/1.45 var(--ui);
  font-variant-numeric: tabular-nums;
}

.mh *,
.mh *::before,
.mh *::after {
  box-sizing: border-box;
}

.mh b {
  font-weight: 600;
}

.mh-up { color: var(--positive); }
.mh-down { color: var(--negative); }
.mh-flat { color: var(--muted-readable); }
.mh-muted { color: var(--muted); }
.mh-bg-up { background: var(--positive); }
.mh-bg-down { background: var(--negative); }
.mh-bg-flat { background: var(--rule-strong); }

/* ---------- top line: title, market state ---------- */

.mh-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  min-width: 0;
}

.mh-title {
  margin: 0;
  color: var(--text-strong);
  font: 500 24px/1.15 var(--display);
  letter-spacing: -.01em;
}

.mh-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  min-width: 0;
  color: var(--muted-readable);
  font-size: 12.5px;
}

.mh-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  color: var(--text-strong);
  background: var(--canvas-wash);
  font-weight: 600;
  white-space: nowrap;
}

.mh-state i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}

.mh-state.is-open { color: var(--positive); background: var(--positive-soft); }
.mh-state.is-open i { background: var(--positive); box-shadow: 0 0 0 3px color-mix(in srgb, var(--positive) 16%, transparent); }
.mh-state.is-closed i { background: var(--muted); }
.mh-state.is-unknown { color: var(--warning); background: var(--warning-soft); }
.mh-state.is-unknown i { background: var(--warning); }

.mh-status-msg { color: var(--muted); }
.mh-status-cap b { color: var(--text-strong); }
.mh-status-cap small { color: var(--muted); font-size: 11.5px; }

.mh-stale,
.mh-carried {
  margin: 0;
  padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--warning) 22%, transparent);
  border-radius: var(--radius-sm);
  color: var(--warning);
  background: var(--warning-soft);
  font-size: 12.5px;
}

.mh-carried {
  margin-top: 12px;
  font-size: 12px;
}

/* ---------- cards ---------- */

.mh-card {
  min-width: 0;
  padding: 16px 18px 16px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
}

.mh-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 12px;
  margin-bottom: 12px;
}

.mh-card-title {
  margin: 0;
  color: var(--text-strong);
  font: 600 15px/1.3 var(--ui);
  letter-spacing: -.005em;
}

.mh-meta {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.35;
}

.mh-foot-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11.5px;
}

.mh-empty {
  margin: 6px 0 2px;
  color: var(--muted);
  font-size: 12.5px;
}

.mh-unread {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 4px 0 2px;
  color: var(--muted-readable);
  font-size: 12.5px;
}

.mh-unread-mark {
  display: inline-grid;
  flex: 0 0 18px;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 50%;
  color: var(--warning);
  background: var(--warning-soft);
  font: 700 11px/1 var(--ui);
}

/* ---------- index card ---------- */

.mh-indices {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  margin: 0 -18px -16px;
  border-top: 1px solid var(--rule);
}

.mh-index {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 11px 18px 12px;
  border-bottom: 1px solid var(--rule);
}

.mh-index-top,
.mh-index-sub {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.mh-index-name {
  overflow: hidden;
  color: var(--text-strong);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mh-index-last {
  color: var(--text-strong);
  font: 600 15px/1.2 var(--ui);
  white-space: nowrap;
}

.mh-index-sub {
  font-size: 11.5px;
}

.mh-index-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0 9px;
  min-width: 0;
  color: var(--muted);
}

.mh-index-stats b {
  color: var(--text);
  font-weight: 600;
}

.mh-index-stats b.mh-up { color: var(--positive); }
.mh-index-stats b.mh-down { color: var(--negative); }

.mh-index-move {
  flex: 0 0 auto;
  font-weight: 600;
  white-space: nowrap;
}

.mh-range {
  display: grid;
  grid-template-columns: auto minmax(24px, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: var(--faint);
  font-size: 10.5px;
  line-height: 1;
}

.mh-range-track {
  position: relative;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--negative-soft), var(--canvas-wash) 50%, var(--positive-soft));
  box-shadow: inset 0 0 0 1px var(--rule);
}

.mh-range-track i {
  position: absolute;
  top: 50%;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--text-strong);
  box-shadow: 0 0 0 1px var(--rule-strong);
}

/* ---------- breadth band ---------- */

.mh-breadth {
  display: grid;
  gap: 14px;
}

.mh-breadth .mh-card-head {
  margin-bottom: 10px;
}

.mh-ad-bar {
  display: flex;
  gap: 2px;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--canvas-wash);
}

.mh-ad-bar i {
  display: block;
  min-width: 2px;
}

.mh-ad-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 14px;
  margin-top: 8px;
  color: var(--muted-readable);
  font-size: 12.5px;
}

.mh-ad-legend b {
  color: var(--text-strong);
  font-size: 15px;
}

.mh-ad-legend b.mh-up { color: var(--positive); }
.mh-ad-legend b.mh-down { color: var(--negative); }

.mh-breadth-side {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.mh-stat {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--paper-sunk);
  box-shadow: inset 0 0 0 1px var(--rule);
}

.mh-stat b {
  color: var(--text-strong);
  font: 600 20px/1.1 var(--ui);
  letter-spacing: -.01em;
}

.mh-stat b.mh-up { color: var(--positive); }
.mh-stat b.mh-down { color: var(--negative); }

.mh-stat span {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.3;
}

/* ---------- grid of cards ---------- */

.mh-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* One column: the column wrappers step aside and the cards take the reader's
   order (sectors, movers, highs/lows, most active, flows, IPOs, calendar). */
.mh-col {
  display: contents;
}

.mh-area-sectors { order: 1; }
.mh-area-movers { order: 2; }
.mh-area-highs { order: 3; }
.mh-area-active { order: 4; }
.mh-area-flows { order: 5; }
.mh-area-ipos { order: 6; }
.mh-area-calendar { order: 7; }

/* ---------- tabs ---------- */

.mh-tabs {
  display: flex;
  gap: 2px;
  max-width: 100%;
  margin: -2px 0 10px;
  padding: 3px;
  overflow-x: auto;
  border-radius: 9px;
  background: var(--canvas-wash);
  scrollbar-width: none;
}

.mh-tabs::-webkit-scrollbar {
  display: none;
}

.mh-tab {
  display: inline-flex;
  flex: 1 0 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  color: var(--muted-readable);
  background: transparent;
  font: 600 12.5px/1 var(--ui);
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.mh-tab:hover {
  color: var(--text-strong);
}

.mh-tab[aria-selected="true"] {
  color: var(--text-strong);
  background: var(--paper);
  box-shadow: var(--shadow-xs), 0 0 0 1px var(--rule);
}

.mh-tab:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.mh-tab-count {
  padding: 2px 6px;
  border-radius: 999px;
  color: var(--muted-readable);
  background: color-mix(in srgb, var(--text-strong) 6%, transparent);
  font-size: 11px;
}

.mh-tab[aria-selected="true"] .mh-tab-count {
  color: var(--brand-strong);
  background: var(--brand-soft);
}

/* ---------- lists of securities ---------- */

.mh-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.mh-list {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.mh-list-title {
  margin: 0 0 2px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
  font: 600 11px/1.2 var(--ui);
  letter-spacing: .07em;
  text-transform: uppercase;
}

.mh-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  margin: 0 -8px;
  padding: 6px 8px;
  border-top: 1px solid var(--rule);
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
  transition: background-color 100ms ease;
}

.mh-list-title + .mh-row,
.mh-list > .mh-row:first-child {
  border-top: 0;
}

.mh-row:hover {
  background: var(--paper-sunk);
}

.mh-row:hover .mh-id b {
  color: var(--brand);
}

.mh-row:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.mh-id {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.mh-id b {
  overflow: hidden;
  color: var(--text-strong);
  font: 600 13px/1.25 var(--ui);
  letter-spacing: .01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mh-id small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mh-quote {
  display: grid;
  justify-items: end;
  gap: 1px;
  min-width: 76px;
  text-align: right;
  white-space: nowrap;
}

.mh-quote b {
  color: var(--text-strong);
  font: 500 13px/1.25 var(--ui);
}

.mh-quote small {
  font: 600 12px/1.3 var(--ui);
}

.mh-quote .mh-quote-note {
  color: var(--muted);
  font-weight: 400;
  font-size: 11px;
}

.mh-cols {
  display: grid;
  align-items: end;
  gap: 12px;
  padding: 0 0 6px;
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  font: 600 10.5px/1.2 var(--ui);
  letter-spacing: .05em;
  text-transform: uppercase;
}

.mh-cols span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mh-cols-active,
.mh-row-active {
  grid-template-columns: minmax(0, 1fr) minmax(150px, 220px) auto;
}

.mh-cols-hl,
.mh-row-hl {
  grid-template-columns: minmax(0, 1fr) 96px auto;
}

.mh-cols-active span:nth-child(n + 2),
.mh-cols-hl span:nth-child(n + 2) {
  text-align: right;
}

.mh-cols + .mh-list > .mh-row:first-child {
  border-top: 0;
}

.mh-hl-level {
  color: var(--muted-readable);
  font-size: 12.5px;
  text-align: right;
  white-space: nowrap;
}

.mh-check {
  font-weight: 500 !important;
  cursor: help;
}

.mh-value {
  display: grid;
  grid-template-columns: minmax(16px, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}

.mh-value b {
  color: var(--text-strong);
  font: 500 12.5px/1.2 var(--ui);
}

.mh-value-bar {
  display: block;
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--canvas-wash);
}

.mh-value-bar i {
  display: block;
  height: 100%;
  margin-left: auto;
  border-radius: inherit;
  background: var(--brand);
  opacity: .55;
}

/* ---------- sectors ---------- */

.mh-sector-head,
.mh-sector {
  display: grid;
  grid-template-columns: minmax(84px, 1.1fr) minmax(40px, 1fr) 58px 52px;
  align-items: center;
  gap: 10px;
}

.mh-sector-head {
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  font: 600 10.5px/1.2 var(--ui);
  letter-spacing: .07em;
  text-transform: uppercase;
}

.mh-sector-head span:nth-child(n + 3) {
  text-align: right;
}

.mh-sectors {
  display: grid;
}

.mh-sector {
  min-height: 30px;
  border-bottom: 1px solid var(--rule);
}

.mh-sector:last-child {
  border-bottom: 0;
}

.mh-sector-name {
  overflow: hidden;
  color: var(--text-strong);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mh-sector-bar {
  position: relative;
  height: 8px;
}

.mh-sector-bar::before {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: 50%;
  width: 1px;
  background: var(--rule-strong);
  content: "";
}

.mh-sector-bar i {
  position: absolute;
  top: 0;
  bottom: 0;
  min-width: 2px;
  border-radius: 2px;
  opacity: .85;
}

.mh-sector-pct,
.mh-sector-year {
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

/* No opacity on the year figure: at .82 its green and red fell to 4.05:1
   and 4.25:1 on white (2026-10-18). Weight and size set it apart. */
.mh-sector-year {
  font-weight: 500;
  font-size: 12px;
}

/* ---------- FII / DII ---------- */

.mh-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.mh-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.mh-table th,
.mh-table td {
  padding: 8px 0 8px 10px;
  border-bottom: 1px solid var(--rule);
  text-align: right;
  white-space: nowrap;
}

.mh-table th:first-child {
  padding-left: 0;
  text-align: left;
}

.mh-table thead th {
  padding-top: 0;
  color: var(--muted);
  font: 600 10.5px/1.2 var(--ui);
  letter-spacing: .07em;
  text-transform: uppercase;
}

.mh-table thead th:first-child {
  letter-spacing: 0;
  text-transform: none;
}

.mh-table tbody th {
  color: var(--text-strong);
  font-weight: 600;
}

.mh-table tbody tr:last-child th,
.mh-table tbody tr:last-child td {
  border-bottom: 0;
}

.mh-table td b {
  font-weight: 700;
}

/* ---------- IPOs ---------- */

.mh-cols-ipo,
.mh-ipo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px 68px 80px;
  align-items: center;
  gap: 10px;
}

.mh-cols-ipo span:nth-child(n + 2) {
  text-align: right;
}

.mh-ipo {
  min-height: 44px;
  padding: 6px 0;
  border-bottom: 1px solid var(--rule);
}

.mh-ipo .mh-id b {
  font-weight: 600;
  letter-spacing: 0;
}

.mh-ipo-dates,
.mh-ipo-band,
.mh-ipo-last {
  color: var(--text);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
}

.mh-ipo-last {
  font-weight: 600;
}

.mh-ipo-last .mh-muted {
  font-weight: 400;
}

.mh-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--brass-strong);
  background: var(--brass-soft);
  font: 600 10px/1.5 var(--ui);
  letter-spacing: .04em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.mh-tag.is-results {
  color: var(--brand-strong);
  background: var(--brand-soft);
}

/* ---------- calendar ---------- */

.mh-days {
  display: grid;
  gap: 4px;
}

.mh-day-title {
  margin: 6px 0 0;
  padding: 4px 0;
  color: var(--muted-readable);
  font: 600 11px/1.3 var(--ui);
  letter-spacing: .06em;
  text-transform: uppercase;
}

.mh-day:first-child .mh-day-title {
  margin-top: 0;
}

.mh-row.mh-event {
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 42px;
}

.mh-day-title + .mh-row {
  border-top: 1px solid var(--rule);
}

.mh-event-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 4px 6px;
  max-width: 180px;
  text-align: right;
}

.mh-event-purpose {
  color: var(--muted);
  font-size: 11.5px;
}

/* "Show all" lists: rows past the first few wait for the button. */
.mh-more {
  display: none !important;
}

.is-expanded .mh-more {
  display: grid !important;
}

.is-expanded .mh-day.mh-more {
  display: block !important;
}

.mh-more-button {
  display: block;
  width: 100%;
  min-height: 36px;
  margin-top: 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  color: var(--brand-strong);
  background: var(--paper);
  font: 600 12.5px/1 var(--ui);
}

.mh-more-button:hover {
  border-color: var(--rule-strong);
  background: var(--paper-sunk);
}

/* ---------- footer ---------- */

.mh-foot {
  display: grid;
  gap: 4px;
  padding: 2px 2px 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
}

.mh-foot p {
  margin: 0;
}

.mh-foot a {
  color: var(--muted-readable);
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
  text-underline-offset: 2px;
}

.mh-foot a:hover {
  color: var(--brand);
}

.mh-foot-unread {
  color: var(--warning);
}

/* ---------- loading ---------- */

.mh-loading-text {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.mh-skeleton {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.mh-skeleton i {
  display: block;
  height: 120px;
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--canvas-wash), var(--paper-sunk), var(--canvas-wash));
  background-size: 200% 100%;
  animation: mh-shimmer 1.4s ease-in-out infinite;
}

@keyframes mh-shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

/* ---------- widths ---------- */

@container mh (min-width: 520px) {
  .mh-indices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mh-index:nth-child(odd) {
    border-right: 1px solid var(--rule);
  }

  .mh-split {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px;
  }

  .mh-breadth {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    align-items: center;
    gap: 22px;
  }
}

@container mh (min-width: 760px) {
  .mh-indices {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mh-index:nth-child(odd) {
    border-right: 0;
  }

  .mh-index:not(:nth-child(3n)) {
    border-right: 1px solid var(--rule);
  }

  .mh-index:nth-last-child(-n + 3):nth-child(3n + 1),
  .mh-index:nth-last-child(-n + 3):nth-child(3n + 1) ~ .mh-index {
    border-bottom: 0;
  }
}

@container mh (min-width: 900px) {
  .mh-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
    align-items: start;
  }

  .mh-col {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
  }
}

@container mh (max-width: 519px) {
  .mh-index:last-child {
    border-bottom: 0;
  }

  .mh-breadth-side .mh-stat {
    padding: 8px 10px;
  }

  .mh-stat b {
    font-size: 17px;
  }

  .mh-cols-active,
  .mh-row-active {
    grid-template-columns: minmax(0, 1fr) minmax(84px, 110px) auto;
    gap: 8px;
  }

  .mh-value {
    grid-template-columns: auto;
    justify-items: end;
    gap: 3px;
  }

  .mh-value-bar {
    height: 4px;
  }

  .mh-cols-hl,
  .mh-row-hl {
    grid-template-columns: minmax(0, 1fr) 82px auto;
    gap: 8px;
  }

  .mh-cols-ipo,
  .mh-ipo {
    grid-template-columns: minmax(0, 1fr) 58px 80px;
  }

  .mh-sector-head,
  .mh-sector {
    grid-template-columns: minmax(0, 1.5fr) minmax(32px, .8fr) 58px 50px;
    gap: 8px;
  }

  .mh-cols-ipo span:nth-child(3),
  .mh-ipo .mh-ipo-band {
    display: none;
  }
}

@media (pointer: coarse) {
  .mh-tab {
    min-height: 44px;
  }

  .mh-row,
  .mh-more-button {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mh-skeleton i {
    animation: none;
  }

  .mh-tab,
  .mh-row {
    transition: none;
  }
}

@media (forced-colors: active) {
  .mh-range-track i,
  .mh-ad-bar i,
  .mh-sector-bar i,
  .mh-value-bar i {
    forced-color-adjust: none;
  }
}
