:root {
  /* The site's shared palette (/_assets/theme.css), light and dark. The tiles keep the
     same red-grey-green scale in both themes (format.js), as on TradingView. */
  --bg: var(--at-bg);
  --panel: var(--at-surface);
  --panel-2: var(--at-surface-2);
  --line: var(--at-border);
  --line-2: var(--at-border-strong);
  --text: var(--at-text);
  --text-strong: var(--at-text);
  --muted: var(--at-text-3);
  --up: var(--at-up);
  --down: var(--at-down);
  --accent: var(--at-accent);
  --warn: var(--at-warn);
  --hover: color-mix(in srgb, var(--at-text) 5%, transparent);
  --font: var(--at-font);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------- Top bar ---------------- */

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  min-height: 52px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 3;
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.bar-right {
  gap: 12px;
}

.seg button:focus-visible,
.icon-btn:focus-visible,
.ix:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.title {
  margin: 0;
  color: var(--text-strong);
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
}

.crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: -8px;
  color: var(--text-strong);
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
}

.crumb[hidden] {
  display: none;
}

.crumb-sep {
  color: var(--muted);
  font-weight: 400;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}

.icon-btn svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.6;
  stroke-linecap: round;
}

.icon-btn:hover {
  background: var(--panel-2);
}

.icon-btn:hover svg {
  stroke: var(--text-strong);
}

.index-quote {
  display: flex;
  align-items: baseline;
  gap: 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.iq-ltp {
  color: var(--text-strong);
  font-size: 18px;
  font-weight: 600;
}

.iq-chg {
  font-size: 14px;
  font-weight: 500;
}

.up {
  color: var(--up);
}

.down {
  color: var(--down);
}

.breadth {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.breadth[hidden] {
  display: none;
}

.b-adv {
  color: var(--up);
}

.b-dec {
  color: var(--down);
}

.b-bar {
  display: flex;
  width: 72px;
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--line-2);
}

.b-bar i {
  display: block;
  height: 100%;
  transition: width 0.4s ease;
}

.b-adv-bar {
  background: var(--up);
}

.b-dec-bar {
  margin-left: auto;
  background: var(--down);
}

.seg {
  display: flex;
  padding: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 6px;
}

.seg button {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.seg button:hover {
  color: var(--text-strong);
}

.seg button[aria-pressed="true"] {
  background: var(--line-2);
  color: var(--text-strong);
}

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status[data-tone="live"] .dot {
  background: var(--up);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: pulse 2s ease-out infinite;
}

.status[data-tone="warn"] .dot {
  background: var(--warn);
}

.status[data-tone="error"] .dot {
  background: var(--down);
}

.status[data-tone="wait"] .dot {
  animation: blink 1s ease-in-out infinite alternate;
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

@keyframes blink {
  to {
    opacity: 0.3;
  }
}


/* ---------------- Body: index list | map ---------------- */

.body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.side {
  display: flex;
  flex: none;
  flex-direction: column;
  width: 248px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 46px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--line);
}

.side-title {
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 600;
}

.seg-sm button {
  height: 24px;
  padding: 0 8px;
  font-size: 11px;
}

.side-list {
  flex: 1;
  min-height: 0;
  padding: 0 0 12px;
  overflow-y: auto;
  scrollbar-color: var(--line-2) transparent;
  scrollbar-width: thin;
}

.side-group {
  padding: 14px 14px 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ix {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 32px;
  padding: 0 12px 0 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.ix:hover {
  background: var(--hover);
  color: var(--text-strong);
}

.ix[aria-current="true"] {
  background: var(--panel-2);
  color: var(--text-strong);
}

.ix[aria-current="true"]::before {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
}

.ix-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ix-chg {
  padding: 2px 0;
  border-radius: 3px;
  background: rgb(42, 46, 57);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.side-toggle {
  display: none;
  width: 32px;
  height: 32px;
  margin-right: -8px;
}

.side-toggle svg {
  width: 16px;
  height: 16px;
}

.side-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1001; /* the drawer covers the whole screen, the site header too (z-index 1000) */
  background: rgba(0, 0, 0, 0.5);
}

.side-backdrop[hidden] {
  display: none;
}

/* ---------------- Map ---------------- */

.map {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 6px 8px 0;
  overflow: hidden;
  user-select: none;
}

.sector-head {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
  overflow: hidden;
  color: var(--at-text-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: zoom-in;
}

.sector-head:hover {
  color: var(--text-strong);
}

.zoomed .sector-head {
  cursor: zoom-out;
}

.sector-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sector-chg {
  flex: none;
  font-weight: 500;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.sector-chg.up {
  color: var(--up);
}

.sector-chg.down {
  color: var(--down);
}

.sector-frame {
  position: absolute;
  pointer-events: none;
  border: 1px solid transparent;
  border-radius: 2px;
  z-index: 1;
}

.sector-frame.hot {
  border-color: color-mix(in srgb, var(--text-strong) 55%, transparent);
}

.tile {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  overflow: hidden;
  color: #fff;
  text-align: center;
  line-height: 1.15;
  cursor: pointer;
  transition: background-color 0.5s ease;
}

.tile:hover {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.85);
}

.tile:focus {
  outline: none;
}

.tile:focus-visible {
  box-shadow: inset 0 0 0 2px #fff;
}

.sector-head:focus {
  outline: none;
}

.sector-head:focus-visible {
  border-radius: 2px;
  box-shadow: inset 0 0 0 2px var(--accent);
  color: var(--text-strong);
}

.tile span {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
  font-variant-numeric: tabular-nums;
}

.t-sym {
  font-weight: 600;
}

.t-chg {
  margin-top: 0.15em;
  opacity: 0.95;
}

.t-ltp {
  margin-top: 0.3em;
  opacity: 0.75;
}

.loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  z-index: 2;
}

.loader[hidden] {
  display: none;
}

.loader.error {
  color: var(--down);
}

.loader.error .spinner {
  display: none;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line-2);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------------- Footer ---------------- */

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 36px;
  padding: 0 8px;
  flex: none;
}

.legend {
  display: flex;
  gap: 2px;
  flex: none;
}

.lg {
  width: 44px;
  padding: 3px 0;
  border-radius: 2px;
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.lg[data-p="-3"] {
  background: rgb(246, 53, 56);
}
.lg[data-p="-2"] {
  background: rgb(191, 64, 69);
}
.lg[data-p="-1"] {
  background: rgb(139, 68, 78);
}
.lg[data-p="0"] {
  background: rgb(65, 69, 84);
}
.lg[data-p="1"] {
  background: rgb(53, 118, 78);
}
.lg[data-p="2"] {
  background: rgb(47, 158, 79);
}
.lg[data-p="3"] {
  background: rgb(48, 204, 90);
}

.foot-note {
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------- Index value beside a % chip ---------------- */

.chip-tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1003; /* beside a chip of the drawer, which covers the site header */
  min-width: 132px;
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  box-shadow: var(--at-shadow-lg);
  pointer-events: none;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.chip-tip[hidden] {
  display: none;
}

/* A small arrow pointing back at the chip. */
.chip-tip::before {
  content: "";
  position: absolute;
  top: var(--arrow-y, 50%);
  left: -5px;
  width: 8px;
  height: 8px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line-2);
  border-left: 1px solid var(--line-2);
  transform: translateY(-50%) rotate(45deg);
}

.chip-tip.detached::before {
  display: none;
}

.chip-tip-name {
  color: var(--muted);
  font-size: 11px;
}

.chip-tip-ltp {
  margin-top: 2px;
  color: var(--text-strong);
  font-size: 16px;
  font-weight: 600;
}

.chip-tip-chg {
  margin-top: 1px;
  font-size: 12px;
  font-weight: 500;
}

/* ---------------- Tooltip ---------------- */

.tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  width: 320px;
  padding: 12px 0 6px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  box-shadow: var(--at-shadow-lg);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.tip[hidden] {
  display: none;
}

.tip-head {
  padding: 0 14px 10px;
  border-bottom: 1px solid var(--line);
}

.tip-sector {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tip-name {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.tip-sym {
  color: var(--text-strong);
  font-size: 15px;
  font-weight: 700;
}

.tip-co {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tip-price {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 6px;
}

.tip-ltp {
  color: var(--text-strong);
  font-size: 20px;
  font-weight: 600;
}

.tip-chg {
  font-size: 13px;
  font-weight: 500;
}

.tip-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin-top: 8px;
  font-size: 12px;
}

.tip-facts dt {
  color: var(--muted);
}

.tip-facts dd {
  margin: 0;
  text-align: right;
}

.tip-returns {
  padding: 8px 14px 4px;
}

.ret-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 68px;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
  font-size: 12px;
}

.ret-head {
  padding-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ret-label {
  color: var(--text);
}

.ret-from {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: pre;
}

.ret-val {
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 600;
  text-align: right;
}

.ret-val.up {
  color: var(--up);
}

.ret-val.down {
  color: var(--down);
}

.ret-val.loading::after {
  content: "";
  display: inline-block;
  width: 44px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--line) 0%, var(--line-2) 50%, var(--line) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.1s linear infinite;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.tip-hint {
  margin: 4px 14px 2px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.ret-error {
  padding: 4px 0 2px;
  color: var(--warn);
  font-size: 11px;
}

.clock {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.clock-date {
  color: var(--muted);
  font-size: 12px;
}

.clock-time {
  color: var(--text-strong);
  font-size: 14px;
  font-weight: 600;
}

@media (max-width: 900px) {
  .side-toggle {
    display: grid;
  }
  .side {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1002;
    width: min(260px, 80vw);
    box-shadow: var(--at-shadow-lg);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .side-open .side {
    transform: none;
  }
}

@media (max-width: 720px) {
  .bar {
    padding: 8px 12px;
  }
  .bar-group {
    gap: 12px;
    flex-wrap: wrap;
  }
  .breadth,
  .foot-note,
  .clock-date {
    display: none;
  }
  .lg {
    width: 36px;
  }
  .map {
    margin: 6px 4px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .b-bar i,
  .side {
    transition: none;
  }
  .ret-val.loading::after {
    animation: none;
  }
  .status .dot {
    animation: none !important;
  }
}
