/**
 * Stock Market Chart — front-end styles.
 *
 * Tokens first, components second. Every colour below is a validated step:
 * marks clear 3:1 against their surface, text clears 4.5:1, and the up/down
 * pair is never the only channel carrying direction — a ▲/▼ glyph and a signed
 * number ride alongside it, because green vs red is the worst pair under
 * deuteranopia (ΔE 4.1). The optional colour-blind-safe palette swaps up to
 * blue, a pair that clears every separation check (ΔE 23.8 light / 25.7 dark).
 */

/* -------------------------------------------------------------------------
 * Tokens
 * ---------------------------------------------------------------------- */

.smc {
	color-scheme: light;

	--smc-surface: #fcfcfb;
	--smc-plane: #f9f9f7;
	--smc-ink: #0b0b0b;
	--smc-ink-2: #52514e;
	--smc-muted: #898781;
	--smc-grid: #e1e0d9;
	--smc-axis: #c3c2b7;
	--smc-border: rgba(11, 11, 11, 0.1);

	/* Marks — 3:1 minimum against the surface. */
	--smc-accent: #2a78d6;
	--smc-up: #0ca30c;
	--smc-down: #d03b3b;
	--smc-flat: #898781;

	/* Text steps of the same roles — 4.5:1 minimum. */
	--smc-up-text: #006300;
	--smc-down-text: #d03b3b;
	--smc-flat-text: #52514e;

	--smc-radius: 10px;
	--smc-gap: 12px;
	--smc-font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* The dark column is the same roles re-stepped for the dark surface, chosen
   and measured against it — never an automatic inversion of the light one. */
@media (prefers-color-scheme: dark) {
	:root:where(:not([data-theme="light"])) .smc {
		color-scheme: dark;

		--smc-surface: #1a1a19;
		--smc-plane: #0d0d0d;
		--smc-ink: #ffffff;
		--smc-ink-2: #c3c2b7;
		--smc-muted: #898781;
		--smc-grid: #2c2c2a;
		--smc-axis: #383835;
		--smc-border: rgba(255, 255, 255, 0.1);

		--smc-accent: #3987e5;
		--smc-up: #0ca30c;
		--smc-down: #d03b3b;

		--smc-up-text: #0ca30c;
		--smc-down-text: #e66767;
		--smc-flat-text: #c3c2b7;
	}
}

:root[data-theme="dark"] .smc,
body.dark-mode .smc,
.smc.smc--dark {
	color-scheme: dark;

	--smc-surface: #1a1a19;
	--smc-plane: #0d0d0d;
	--smc-ink: #ffffff;
	--smc-ink-2: #c3c2b7;
	--smc-muted: #898781;
	--smc-grid: #2c2c2a;
	--smc-axis: #383835;
	--smc-border: rgba(255, 255, 255, 0.1);

	--smc-accent: #3987e5;
	--smc-up: #0ca30c;
	--smc-down: #d03b3b;

	--smc-up-text: #0ca30c;
	--smc-down-text: #e66767;
	--smc-flat-text: #c3c2b7;
}

/* Opt-in palette for red/green colour blindness: up becomes blue. Blue vs red
   clears every separation check (ΔE 23.8 light / 25.7 dark) where green vs red
   does not (ΔE 4.1 under deuteranopia). */
.smc--cvd-safe,
body.smc-cvd-safe .smc {
	--smc-up: #2a78d6;
	--smc-up-text: #1c5cab;
}

@media (prefers-color-scheme: dark) {
	:root:where(:not([data-theme="light"])) .smc--cvd-safe,
	:root:where(:not([data-theme="light"])) body.smc-cvd-safe .smc {
		--smc-up: #3987e5;
		--smc-up-text: #6da7ec;
	}
}

:root[data-theme="dark"] .smc--cvd-safe,
:root[data-theme="dark"] body.smc-cvd-safe .smc,
body.dark-mode.smc-cvd-safe .smc,
.smc--cvd-safe.smc--dark {
	--smc-up: #3987e5;
	--smc-up-text: #6da7ec;
}

/* -------------------------------------------------------------------------
 * Shell
 * ---------------------------------------------------------------------- */

.smc {
	background: var(--smc-surface);
	border: 1px solid var(--smc-border);
	border-radius: var(--smc-radius);
	box-sizing: border-box;
	color: var(--smc-ink);
	font-family: var(--smc-font);
	font-size: 15px;
	line-height: 1.45;
	margin: 0 0 1.5em;
	padding: 16px;
}

.smc *,
.smc *::before,
.smc *::after {
	box-sizing: inherit;
}

.smc a {
	color: inherit;
	text-decoration: none;
}

.smc a:hover,
.smc a:focus-visible {
	text-decoration: underline;
}

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

.smc__title {
	font-size: 15px;
	font-weight: 600;
	letter-spacing: -0.01em;
	margin: 0 0 var(--smc-gap);
}

.smc__meta {
	color: var(--smc-ink-2);
	font-size: 12px;
	margin: 0;
}

.smc__empty {
	color: var(--smc-ink-2);
	font-size: 14px;
	margin: 0;
	padding: 8px 0;
}

/* Administrator-only diagnostic. Deliberately looks like a note rather than
   part of the design — it is scaffolding for whoever configures the site, and
   no visitor ever sees it. */
.smc__hint {
	background: var(--smc-plane);
	border-inline-start: 3px solid var(--smc-accent);
	border-radius: 4px;
	color: var(--smc-ink-2);
	font-size: 12px;
	line-height: 1.5;
	margin: 4px 0 0;
	padding: 8px 10px;
}

.smc__hint a {
	color: var(--smc-accent);
	text-decoration: underline;
}

.smc__sr {
	border: 0;
	clip-path: inset(50%);
	height: 1px;
	overflow: hidden;
	position: absolute;
	white-space: nowrap;
	width: 1px;
}

/* -------------------------------------------------------------------------
 * Price figures & direction
 * ---------------------------------------------------------------------- */

.smc-price {
	font-size: 30px;
	font-weight: 600;
	letter-spacing: -0.02em;
	line-height: 1.1;
}

.smc-symbol {
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.smc-name {
	color: var(--smc-ink-2);
	font-size: 13px;
}

/* Direction is carried by three channels at once — glyph, sign and colour —
   so it survives colour blindness, greyscale print and forced-colours. */
.smc-delta {
	align-items: center;
	display: inline-flex;
	font-size: 14px;
	font-weight: 600;
	gap: 4px;
	white-space: nowrap;
}

.smc-delta__glyph {
	font-size: 11px;
	line-height: 1;
}

.smc-delta--up {
	color: var(--smc-up-text);
}

.smc-delta--down {
	color: var(--smc-down-text);
}

.smc-delta--flat {
	color: var(--smc-flat-text);
}

/* -------------------------------------------------------------------------
 * Quote card
 * ---------------------------------------------------------------------- */

.smc-quote__head {
	align-items: flex-start;
	display: flex;
	flex-wrap: wrap;
	gap: var(--smc-gap);
	justify-content: space-between;
}

.smc-quote__figures {
	align-items: baseline;
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin-top: 4px;
}

.smc-quote__spark {
	block-size: 48px;
	inline-size: 100%;
	max-inline-size: 160px;
}

.smc-quote__stats {
	border-top: 1px solid var(--smc-border);
	display: grid;
	gap: 8px 16px;
	grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
	margin-top: var(--smc-gap);
	padding-top: var(--smc-gap);
}

.smc-stat__label {
	color: var(--smc-ink-2);
	display: block;
	font-size: 11px;
	letter-spacing: 0.03em;
	text-transform: uppercase;
}

.smc-stat__value {
	display: block;
	font-size: 14px;
	font-variant-numeric: tabular-nums;
	font-weight: 600;
}

/* -------------------------------------------------------------------------
 * Chart
 * ---------------------------------------------------------------------- */

.smc-chart__figure {
	margin: var(--smc-gap) 0 0;
	position: relative;
}

.smc-chart__canvas {
	display: block;
	inline-size: 100%;
	touch-action: pan-y;
}

.smc-chart__tooltip {
	background: var(--smc-surface);
	border: 1px solid var(--smc-border);
	border-radius: 8px;
	box-shadow: 0 4px 16px rgb(0 0 0 / 12%);
	color: var(--smc-ink);
	font-size: 12px;
	font-variant-numeric: tabular-nums;
	inset-block-start: 0;
	inset-inline-start: 0;
	line-height: 1.5;
	padding: 8px 10px;
	pointer-events: none;
	position: absolute;
	white-space: nowrap;
	z-index: 5;
}

.smc-chart__tooltip[hidden] {
	display: none;
}

.smc-chart__tooltip-date {
	color: var(--smc-ink-2);
	display: block;
	margin-bottom: 2px;
}

.smc-chart__ranges {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	margin-top: var(--smc-gap);
}

.smc-chart__range {
	background: transparent;
	border: 1px solid var(--smc-border);
	border-radius: 999px;
	color: var(--smc-ink-2);
	cursor: pointer;
	font: inherit;
	font-size: 12px;
	padding: 3px 10px;
}

.smc-chart__range[aria-pressed="true"] {
	background: var(--smc-accent);
	border-color: var(--smc-accent);
	color: #ffffff;
}

/* The table is the chart's accessible equivalent, not a fallback: it is always
   present, collapsed, and holds every plotted value. */
.smc-table-toggle {
	color: var(--smc-ink-2);
	cursor: pointer;
	font-size: 12px;
	margin-top: var(--smc-gap);
}

.smc-table-wrap {
	max-height: 320px;
	margin-top: 8px;
	overflow: auto;
}

.smc-table {
	border-collapse: collapse;
	font-size: 12px;
	font-variant-numeric: tabular-nums;
	inline-size: 100%;
}

.smc-table th,
.smc-table td {
	border-bottom: 1px solid var(--smc-border);
	padding: 4px 8px;
	text-align: end;
}

.smc-table th:first-child,
.smc-table td:first-child {
	text-align: start;
}

.smc-table thead th {
	background: var(--smc-surface);
	color: var(--smc-ink-2);
	font-weight: 600;
	position: sticky;
	inset-block-start: 0;
}

/* -------------------------------------------------------------------------
 * Quote lists (movers, indices, watchlist)
 * ---------------------------------------------------------------------- */

.smc-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

/* Flex, not grid: a row has three children or five depending on whether it
   carries a logo and a remove control, and a fixed column template drops the
   extras onto a second line. */
.smc-row {
	align-items: center;
	border-bottom: 1px solid var(--smc-border);
	display: flex;
	gap: 12px;
	padding: 10px 0;
}

.smc-row:last-child {
	border-bottom: 0;
}

.smc-row__id {
	flex: 1 1 auto;
	min-inline-size: 0;
}

/* Logo well: the monogram sits underneath, the image covers it when one
   loads, so a missing or broken logo falls back to initials. */
.smc-row__logo {
	background: var(--smc-plane);
	block-size: 34px;
	border: 1px solid var(--smc-border);
	border-radius: 8px;
	/* Explicit display so the box has a size even outside a flex parent —
	   an inline span ignores width, and the absolutely positioned monogram
	   then escapes and lands on top of the next column. */
	display: inline-block;
	flex: 0 0 auto;
	inline-size: 34px;
	overflow: hidden;
	position: relative;
	vertical-align: middle;
}

.smc-mono {
	align-items: center;
	color: var(--smc-ink-2);
	display: flex;
	font-size: 12px;
	font-weight: 600;
	inset: 0;
	justify-content: center;
	letter-spacing: 0.02em;
	position: absolute;
}

.smc-row__logo-img {
	background: #ffffff;
	block-size: 100%;
	inline-size: 100%;
	inset: 0;
	object-fit: contain;
	padding: 3px;
	position: absolute;
}

.smc-row__name {
	color: var(--smc-ink-2);
	display: block;
	font-size: 12px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.smc-row__price {
	flex: 0 0 auto;
	font-size: 14px;
	font-variant-numeric: tabular-nums;
	font-weight: 600;
}

.smc-row__delta {
	flex: 0 0 auto;
	justify-content: flex-end;
	min-inline-size: 96px;
}

/* Recessive until you reach for it: a destructive control should not be the
   loudest thing in a row of prices. Full-strength on hover and focus, and a
   44px-ish target on touch where there is no hover to reveal it. */
.smc-row__remove {
	align-items: center;
	background: none;
	block-size: 28px;
	border: 1px solid transparent;
	border-radius: 6px;
	color: var(--smc-muted);
	cursor: pointer;
	display: inline-flex;
	flex: 0 0 auto;
	inline-size: 28px;
	justify-content: center;
	opacity: 0.65;
	padding: 0;
	transition: opacity 120ms ease, color 120ms ease, background-color 120ms ease;
}

.smc-row:hover .smc-row__remove,
.smc-row__remove:focus-visible {
	opacity: 1;
}

.smc-row__remove:hover,
.smc-row__remove:focus-visible {
	background: var(--smc-plane);
	border-color: var(--smc-border);
	color: var(--smc-down-text);
}

.smc-row__remove-icon {
	display: block;
}

@media (hover: none) {
	.smc-row__remove {
		opacity: 1;
	}
}

@media (prefers-reduced-motion: reduce) {
	.smc-row__remove {
		transition: none;
	}
}

/* -------------------------------------------------------------------------
 * Tabbed market table
 * ---------------------------------------------------------------------- */

.smc-tabs {
	overflow: hidden;
	padding: 0;
}

.smc-tabs__strip {
	background: var(--smc-plane);
	border-bottom: 1px solid var(--smc-border);
	display: flex;
	gap: 2px;
	padding: 0 6px;
	/* `overflow-x: auto` alone is not enough: once one axis is not `visible`,
	   the other computes from `visible` to `auto`, which is where the stray
	   vertical scrollbar came from. Pin the block axis explicitly. */
	overflow-x: auto;
	overflow-y: hidden;
	scrollbar-width: thin;
}

.smc-tabs__tab {
	flex: 0 0 auto;
}

.smc-tabs__tab {
	background: none;
	border: 0;
	/* Selection is marked by an accent bar *and* a weight change, so the state
	   never rests on hue alone. */
	border-bottom: 2px solid transparent;
	color: var(--smc-ink-2);
	cursor: pointer;
	font: inherit;
	font-size: 14px;
	letter-spacing: -0.01em;
	margin-bottom: -1px;
	padding: 12px 14px;
	transition: color 120ms ease, border-color 120ms ease;
	white-space: nowrap;
}

.smc-tabs__tab:hover {
	color: var(--smc-ink);
}

.smc-tabs__tab[aria-selected="true"] {
	background: var(--smc-surface);
	border-bottom-color: var(--smc-accent);
	color: var(--smc-ink);
	font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
	.smc-tabs__tab {
		transition: none;
	}
}

.smc-tabs__panel:focus-visible {
	outline: 2px solid var(--smc-accent);
	outline-offset: -2px;
}

.smc-tabs__table {
	border-collapse: collapse;
	inline-size: 100%;
	table-layout: auto;
}

.smc-tabs__row {
	transition: background-color 120ms ease;
}

.smc-tabs__row:hover {
	background: var(--smc-plane);
}

.smc-tabs__table td {
	border-bottom: 1px solid var(--smc-border);
	padding: 11px 14px;
	vertical-align: middle;
}

.smc-tabs__row:last-child td {
	border-bottom: 0;
}

/* The name column absorbs the slack; every other column sizes to content. */
.smc-tabs__name {
	inline-size: 100%;
	min-inline-size: 0;
}

.smc-tabs__name-inner {
	align-items: center;
	display: flex;
	gap: 10px;
	min-inline-size: 0;
}

.smc-tabs__label {
	font-weight: 500;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.smc-tabs__symbol {
	color: var(--smc-ink-2);
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.04em;
	white-space: nowrap;
}

/* Numbers line up on the decimal: right-aligned, tabular figures, and each
   column only as wide as it needs to be. */
.smc-tabs__price,
.smc-tabs__change,
.smc-tabs__percent {
	font-variant-numeric: tabular-nums;
	text-align: end;
	white-space: nowrap;
}

.smc-tabs__price {
	font-weight: 600;
}

.smc-tabs__percent {
	min-inline-size: 84px;
}

.smc-tabs__arrow {
	display: inline-block;
	font-size: 10px;
	margin-inline-start: 5px;
}

.smc-tabs__change.smc-delta--up,
.smc-tabs__percent.smc-delta--up {
	color: var(--smc-up-text);
}

.smc-tabs__change.smc-delta--down,
.smc-tabs__percent.smc-delta--down {
	color: var(--smc-down-text);
}

.smc-tabs__change.smc-delta--flat,
.smc-tabs__percent.smc-delta--flat {
	color: var(--smc-flat-text);
}

@media (max-width: 480px) {
	.smc-tabs__table td {
		padding: 8px 6px;
	}

	.smc-tabs__symbol {
		display: none;
	}
}

/* -------------------------------------------------------------------------
 * Ticker tape
 * ---------------------------------------------------------------------- */

.smc-ticker {
	overflow: hidden;
	padding: 10px 0;
}

.smc-ticker__track {
	animation: smc-ticker-scroll var(--smc-ticker-speed, 40s) linear infinite;
	display: flex;
	gap: 28px;
	inline-size: max-content;
	will-change: transform;
}

.smc-ticker:hover .smc-ticker__track,
.smc-ticker:focus-within .smc-ticker__track {
	animation-play-state: paused;
}

.smc-ticker__item {
	align-items: baseline;
	display: flex;
	gap: 6px;
	white-space: nowrap;
}

@keyframes smc-ticker-scroll {
	from {
		transform: translateX(0);
	}

	to {
		transform: translateX(-50%);
	}
}

@media (prefers-reduced-motion: reduce) {
	.smc-ticker {
		overflow-x: auto;
	}

	.smc-ticker__track {
		animation: none;
	}
}

/* -------------------------------------------------------------------------
 * Market status
 * ---------------------------------------------------------------------- */

.smc-status {
	align-items: center;
	display: inline-flex;
	font-size: 14px;
	font-weight: 600;
	gap: 8px;
}

.smc-status__dot {
	block-size: 10px;
	border-radius: 50%;
	display: inline-block;
	inline-size: 10px;
}

.smc-status--regular .smc-status__dot {
	background: var(--smc-up);
}

.smc-status--pre .smc-status__dot,
.smc-status--post .smc-status__dot {
	background: #fab219;
}

.smc-status--closed .smc-status__dot {
	background: var(--smc-flat);
}

/* -------------------------------------------------------------------------
 * News
 * ---------------------------------------------------------------------- */

.smc-news__item {
	border-bottom: 1px solid var(--smc-border);
	display: flex;
	gap: var(--smc-gap);
	padding: 10px 0;
}

.smc-news__item:last-child {
	border-bottom: 0;
}

.smc-news__thumb {
	block-size: 56px;
	border-radius: 6px;
	flex: 0 0 auto;
	inline-size: 76px;
	object-fit: cover;
}

.smc-news__headline {
	font-size: 14px;
	font-weight: 600;
	margin: 0 0 2px;
}

.smc-news__meta {
	color: var(--smc-ink-2);
	font-size: 12px;
}

/* -------------------------------------------------------------------------
 * Company profile
 * ---------------------------------------------------------------------- */

.smc-company__head {
	align-items: center;
	display: flex;
	gap: var(--smc-gap);
}

.smc-company__logo {
	block-size: 44px;
	border-radius: 8px;
	inline-size: 44px;
	object-fit: contain;
}

.smc-company__description {
	color: var(--smc-ink-2);
	font-size: 13px;
	margin: var(--smc-gap) 0 0;
}

.smc-company__facts {
	display: grid;
	gap: 8px 16px;
	grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
	margin-top: var(--smc-gap);
}

/* -------------------------------------------------------------------------
 * Search
 * ---------------------------------------------------------------------- */

.smc-search {
	position: relative;
}

.smc-search__input {
	background: var(--smc-plane);
	border: 1px solid var(--smc-border);
	border-radius: 8px;
	color: var(--smc-ink);
	font: inherit;
	inline-size: 100%;
	padding: 9px 12px;
}

.smc-search__results {
	list-style: none;
	margin: 8px 0 0;
	max-height: 280px;
	overflow: auto;
	padding: 0;
}

.smc-search__result {
	border-bottom: 1px solid var(--smc-border);
}

.smc-search__button {
	background: none;
	border: 0;
	color: inherit;
	cursor: pointer;
	display: block;
	font: inherit;
	inline-size: 100%;
	padding: 8px 4px;
	text-align: start;
}

.smc-search__button:hover,
.smc-search__button:focus-visible {
	background: var(--smc-plane);
}

/* -------------------------------------------------------------------------
 * Attribution
 * ---------------------------------------------------------------------- */

.smc-disclaimer {
	color: #52514e;
	font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
	font-size: 11px;
	margin: -1em 0 1.5em;
}

@media (prefers-color-scheme: dark) {
	:root:where(:not([data-theme="light"])) .smc-disclaimer {
		color: #c3c2b7;
	}
}

:root[data-theme="dark"] .smc-disclaimer,
body.dark-mode .smc-disclaimer {
	color: #c3c2b7;
}

/* -------------------------------------------------------------------------
 * Forced colours — hue is gone, so lean on the glyphs and borders.
 * ---------------------------------------------------------------------- */

@media (forced-colors: active) {
	.smc {
		border: 1px solid CanvasText;
	}

	.smc-delta--up,
	.smc-delta--down,
	.smc-delta--flat {
		color: CanvasText;
	}

	.smc-status__dot {
		border: 2px solid CanvasText;
	}
}
