/* ═══════════════════════════════════════════════════════════════
	 StockFaves Stock Recommendations — Clean Light Theme
	 ═══════════════════════════════════════════════════════════════ */

/* ── Tokens ──────────────────────────────────────────────────── */
:root {
	--font-inter: 'Inter', ui-sans-serif, system-ui, sans-serif;
	--mono: 'Inter', ui-sans-serif, system-ui, sans-serif; /* Inter only — no monospace */

	/* Backgrounds */
	--bg:        #f4f6f9;
	--bg2:       #ffffff;
	--bg3:       #f0f2f5;
	--surface:   #ffffff;
	--surface-hover: #f7f9fc;

	/* Borders */
	--border:        #e2e6ed;
	--border-bright: #c8cfd9;

	/* Text */
	--text:       #374151;
	--text-muted: #6b7280;
	--text-dim:   #9ca3af;

	/* Accent */
	--accent:      #2563eb;
	--accent-glow: rgba(37, 99, 235, 0.15);
	--accent-bg:   rgba(37, 99, 235, 0.08);
	--accent2:     #7c3aed;

	/* Semantic */
	--red:      #dc2626;
	--red-bg:   rgba(220, 38, 38, 0.08);
	--red-border: rgba(220, 38, 38, 0.2);

	--orange:     #ea580c;
	--orange-bg:  rgba(234, 88, 12, 0.08);

	--yellow:     #d97706;
	--yellow-bg:  rgba(217, 119, 6, 0.08);

	--green:      #16a34a;
	--green-bg:   rgba(22, 163, 74, 0.08);
	--green-border: rgba(22, 163, 74, 0.2);

	/* Shadow */
	--shadow:    0 1px 4px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.04);
	--shadow-sm: 0 1px 3px rgba(0,0,0,0.08);

	--radius:    10px;
	--radius-sm: 6px;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
	height: 100vh;
	overflow: hidden;
}

body {
	font-family: var(--font-inter);
	background: var(--bg);
	color: var(--text);
	display: flex;
	flex-direction: column;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
	font-optical-sizing: auto;
}

/* ── Scrollbar (Wide, comfortable, easy to click on outer edge) ─ */
* {
	scrollbar-width: auto;
	scrollbar-color: #94a3b8 #edf2f7;
}

::-webkit-scrollbar {
	width: 14px;
	height: 12px;
}
::-webkit-scrollbar-track {
	background: #edf2f7;
	border-left: 1px solid #e2e8f0;
}
::-webkit-scrollbar-thumb {
	background: #94a3b8;
	border-radius: 7px;
	border: 3px solid #edf2f7;
	min-height: 48px;
}
::-webkit-scrollbar-thumb:hover {
	background: #64748b;
}
::-webkit-scrollbar-thumb:active {
	background: #475569;
}

/* ── Header ──────────────────────────────────────────────────── */
.header {
	flex-shrink: 0;
	background: #ffffff;
	border-bottom: 1px solid var(--border);
	padding: 0 14px;
	box-shadow: var(--shadow-sm);
}
.header-inner {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 7px 0;
	flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
	font-size: 1.8rem;
	line-height: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	user-select: none;
}
.brand-title {
	font-size: 1.15rem;
	font-weight: 600;
	color: var(--text);
	letter-spacing: -0.01em;
}
.brand-sub { font-size: 0.73rem; color: var(--text-muted); margin-top: 1px; }

.header-stats { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.stat-pill {
	display: flex;
	align-items: center;
	gap: 5px;
	padding: 5px 12px;
	background: var(--bg3);
	border: 1px solid var(--border);
	border-radius: 999px;
	font-size: 0.77rem;
}
.stat-label { color: var(--text-muted); }
.stat-value { font-weight: 500; font-family: var(--font-inter); color: var(--text); font-size: 0.77rem; }

.market-status { gap: 7px; }
.status-dot {
	width: 7px; height: 7px;
	border-radius: 50%;
	background: var(--text-dim);
	flex-shrink: 0;
}
.status-dot.live   { background: var(--green); animation: blink 1.5s ease-in-out infinite; }
.status-dot.closed { background: #9ca3af; }
.status-dot.pre    { background: var(--yellow); }

@keyframes blink {
	0%, 100% { opacity: 1; }
	50%       { opacity: 0.3; }
}

/* ── Controls Bar ────────────────────────────────────────────── */
.controls-bar {
	flex-shrink: 0;
	background: #ffffff;
	border-bottom: 1px solid var(--border);
	padding: 6px 14px;
	box-shadow: var(--shadow-sm);
}
.controls-inner {
	width: 100%;
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
}

/* Search */
.search-wrap {
	position: relative;
	display: flex;
	align-items: center;
	flex: 1;
	min-width: 220px;
	max-width: 340px;
}
.search-icon {
	position: absolute;
	left: 10px;
	font-size: 0.85rem;
	pointer-events: none;
	color: var(--text-muted);
	z-index: 1;
}
#searchInput {
	width: 100%;
	padding: 8px 32px 8px 32px;
	background: var(--bg3);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	color: var(--text);
	font-family: var(--font-inter);
	font-size: 0.85rem;
	outline: none;
	transition: border-color 0.15s, box-shadow 0.15s;
}
#searchInput::placeholder { color: var(--text-dim); }
#searchInput:focus {
	border-color: var(--accent);
	background: #fff;
	box-shadow: 0 0 0 3px var(--accent-glow);
}
.clear-btn {
	position: absolute;
	right: 8px;
	background: none;
	border: none;
	color: var(--text-dim);
	cursor: pointer;
	font-size: 0.78rem;
	padding: 4px;
	border-radius: 4px;
	transition: color 0.15s;
	display: none;
}
.clear-btn:hover { color: var(--text); }
.clear-btn.visible { display: block; }

/* Selects */
.filter-group { display: flex; gap: 8px; flex-wrap: wrap; }
.select-styled {
	padding: 8px 28px 8px 10px;
	background: var(--bg3);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	color: var(--text);
	font-family: var(--font-inter);
	font-size: 0.83rem;
	outline: none;
	cursor: pointer;
	appearance: none;
	-webkit-appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 6px center;
	background-size: 15px;
	transition: border-color 0.15s;
}
.select-styled:focus { border-color: var(--accent); background-color: #fff; }

/* Refresh button */
.refresh-btn {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 8px 16px;
	background: var(--accent);
	border: none;
	border-radius: var(--radius-sm);
	color: #fff;
	font-family: var(--font-inter);
	font-size: 0.83rem;
	font-weight: 500;
	cursor: pointer;
	transition: background 0.15s, transform 0.1s;
	white-space: nowrap;
}
.refresh-btn:hover  { background: #1d4ed8; }
.refresh-btn:active { transform: scale(0.97); }
.refresh-icon { font-size: 1rem; display: inline-block; }
.refresh-btn.spinning .refresh-icon { animation: spin 0.8s linear infinite; }

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

/* ── Main ────────────────────────────────────────────────────── */
.main {
	flex: 1;
	min-height: 0;
	width: 100%;
	padding: 0;
	display: flex;
	flex-direction: column;
	position: relative; /* anchors .table-loader */
}

/* ── Refresh loader over the table ───────────────────────────── */
/* Anchored to .main, not .table-wrap: .table-wrap is the scroll container, so
	 an overlay inside it would scroll away with the rows. */
.table-loader {
	position: absolute;
	inset: 0;
	z-index: 30; /* above the sticky thead */
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(244, 246, 249, 0.6);
	backdrop-filter: blur(1.5px);
	-webkit-backdrop-filter: blur(1.5px);
	animation: fade-in 0.15s ease;
}
.table-loader-box {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 14px;
	padding: 26px 34px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}
.table-loader-text {
	font-size: 0.85rem;
	font-weight: 500;
	color: var(--text-muted);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ── Loading State ───────────────────────────────────────────── */
.loading-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 80px 20px;
	text-align: center;
	gap: 14px;
}
.spinner {
	width: 40px; height: 40px;
	border: 3px solid var(--border);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: spin 0.9s linear infinite;
}
.loading-text { font-size: 1rem; font-weight: 500; color: var(--text); }
.loading-sub  { font-size: 0.83rem; color: var(--text-muted); }

.progress-bar-wrap {
	width: 260px; height: 3px;
	background: var(--border);
	border-radius: 2px;
	overflow: hidden;
}
.progress-bar {
	height: 100%;
	width: 0%;
	background: var(--accent);
	border-radius: 2px;
	transition: width 0.4s ease;
}

/* ── Error / Empty ───────────────────────────────────────────── */
.error-state, .empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 80px 20px;
	text-align: center;
	gap: 10px;
}
.error-icon, .empty-icon { font-size: 2.5rem; }
.error-text { font-size: 1.1rem; font-weight: 600; color: var(--red); }
.error-sub, .empty-sub { font-size: 0.83rem; color: var(--text-muted); max-width: 360px; }
.empty-text { font-size: 1rem; font-weight: 500; }

/* ── Table wrapper ───────────────────────────────────────────── */
.table-wrap {
	flex: 1;
	min-height: 0;
	width: 100%;
	background: var(--surface);
	border-top: 1px solid var(--border);
	border-bottom: 1px solid var(--border);
	border-left: none;
	border-right: none;
	border-radius: 0;
	box-shadow: none;
	overflow-y: auto;
	overflow-x: auto;
}

table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.85rem;
}

/* ── Table Head ──────────────────────────────────────────────── */
thead { background: var(--bg3); }
thead tr { border-bottom: 2px solid var(--border); }

th {
	padding: 9px 12px;
	text-align: left;
	font-weight: 500;
	font-size: 0.73rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-muted);
	white-space: nowrap;
	user-select: none;
	position: sticky;
	top: 0;
	background: var(--bg3);
	z-index: 20;
	box-shadow: 0 2px 4px rgba(0,0,0,0.06);
}
th:first-child { padding-left: 16px; }
th:last-child  { padding-right: 16px; }
th[data-sort] { cursor: pointer; transition: color 0.15s; }
th[data-sort]:hover { color: var(--text); }
th.sort-active { color: var(--accent); }

.sort-arrow { margin-left: 4px; font-size: 0.78rem; color: var(--text-dim); }
.sort-arrow.active-asc,
.sort-arrow.active-desc,
th.sort-active .sort-arrow { color: var(--accent); }

/* ── Table Rows ──────────────────────────────────────────────── */
tbody tr {
	border-bottom: 1px solid var(--border);
	transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-hover); }

td {
	padding: 8px 12px;
	vertical-align: middle;
	white-space: nowrap;
}
td:first-child { padding-left: 16px; }
td:last-child  { padding-right: 16px; }

/* Columns */
.col-rank { width: 48px; text-align: center; }
td.col-rank {
	font-family: var(--font-inter);
	font-size: 0.78rem;
	color: var(--text-dim);
	font-weight: 400;
	text-align: center;
}
tbody tr:nth-child(1) td.col-rank { color: #f59e0b; font-size: 0.9rem; }
tbody tr:nth-child(2) td.col-rank { color: #6b7280; font-size: 0.85rem; }
tbody tr:nth-child(3) td.col-rank { color: #b45309; font-size: 0.82rem; }

.col-symbol { width: 110px; }
td.col-symbol {
	font-family: var(--font-inter);
	font-weight: 500;
	color: var(--accent);
	font-size: 0.84rem;
	letter-spacing: 0.01em;
}

.col-name { min-width: 180px; max-width: 260px; white-space: normal; }
td.col-name { font-size: 0.84rem; color: var(--text-muted); font-weight: 400; line-height: 1.3; }

.col-sector { width: 120px; }

.col-price, .col-dayhigh, .col-low, .col-high { width: 110px; text-align: right; }
td.col-price, td.col-dayhigh, td.col-low, td.col-high {
	font-family: var(--font-inter);
	font-size: 0.84rem;
	font-weight: 400;
	text-align: right;
	color: var(--text);
}
/* The live price is the one number that moves, so it wears a badge */
.price-badge {
	display: inline-block;
	padding: 3px 9px;
	border-radius: 6px;
	font-size: 0.85rem;
	font-weight: 600;
	border: 1px solid var(--border);
	background: var(--bg3);
	color: var(--text);
	white-space: nowrap;
}
.price-badge.up {
	background: var(--green-bg);
	border-color: var(--green-border);
	color: var(--green);
}
.price-badge.down {
	background: var(--red-bg);
	border-color: var(--red-border);
	color: var(--red);
}

/* ── Buy / sell / stop levels ────────────────────────────────── */
.col-levels { width: 150px; }
td.col-levels { padding: 8px 14px; }

.levels-cell { display: flex; flex-direction: column; gap: 2px; }
.lv {
	display: grid;
	grid-template-columns: 30px 1fr auto;
	gap: 5px;
	align-items: baseline;
	font-size: 0.76rem;
	white-space: nowrap;
}
.lv-k { color: var(--text-dim); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.03em; }
.lv-v { font-weight: 600; text-align: right; }
.lv-p { font-size: 0.68rem; color: var(--text-dim); text-align: right; }

/* Trading convention: buy and sell are the two sides of the trade, not a
	 gain and a loss. Buy is the live price, so it stays neutral; sell is red
	 the way an exit always is. Green is left for the headroom badge alone. */
.lv-buy  .lv-v { color: var(--text); }
.lv-sell .lv-v { color: var(--red); }

.lv-rr {
	margin-top: 3px;
	font-size: 0.68rem;
	font-weight: 600;
	align-self: flex-start;
	padding: 1px 7px;
	border-radius: 4px;
}
/* Headroom to the next resistance is always a gain, so it always reads green */
.lv-rr.good { background: var(--green-bg); color: var(--green); }

.col-day { width: 88px; text-align: right; }
td.col-day {
	font-family: var(--font-inter);
	font-size: 0.84rem;
	font-weight: 500;
	text-align: right;
}
td.col-day.up   { color: var(--green); }
td.col-day.down { color: var(--red); }

/* ── 3:01 PM snapshot section (separated by vertical border) ── */
.sep-left {
	border-left: 2px solid var(--border-bright) !important;
}

.col-301pm { width: 96px; text-align: right; }
td.col-301pm {
	font-family: var(--font-inter);
	font-size: 0.84rem;
	font-weight: 500;
	text-align: right;
	color: var(--text-muted);
}

.col-now { width: 96px; text-align: right; }
td.col-now {
	font-family: var(--font-inter);
	font-size: 0.84rem;
	font-weight: 600;
	text-align: right;
}

.col-drop { width: 100px; text-align: right; }
td.col-drop {
	font-family: var(--font-inter);
	font-size: 0.84rem;
	font-weight: 600;
	text-align: right;
}
td.col-drop.down { color: var(--red); }
td.col-drop.up   { color: var(--green); }

.col-crash { width: 120px; text-align: right; }
td.col-crash { text-align: right; }

/* ── Rule metric columns ─────────────────────────────────────── */
.col-ebitda, .col-wct { width: 96px; text-align: right; }
td.col-ebitda, td.col-wct {
	font-family: var(--font-inter);
	font-size: 0.84rem;
	font-weight: 500;
	text-align: right;
}
td.metric-pass { color: var(--green); }
td.metric-fail { color: var(--text-muted); }
td.metric-na   { color: var(--text-dim); font-weight: 400; }

/* ── Recommendation summary badges (in the header) ───────────── */
.summary-inner {
	display: flex;
	align-items: center;
	gap: 6px;
	flex-wrap: wrap;
	padding-right: 10px;
	margin-right: 4px;
	border-right: 1px solid var(--border);
}
.summary-inner.loading { opacity: 0.65; }

.summary-badge {
	display: flex;
	align-items: baseline;
	gap: 6px;
	padding: 4px 11px;
	border-radius: 999px;
	border: 1px solid var(--border);
	background: var(--bg3);
	cursor: pointer;
	font-family: inherit;
	transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}
.summary-badge:hover {
	border-color: var(--border-bright);
}
.summary-badge.active {
	box-shadow: 0 0 0 2px var(--accent-glow);
}
.sb-count {
	font-size: 0.92rem;
	font-weight: 700;
	line-height: 1;
}
.sb-label {
	font-size: 0.73rem;
	font-weight: 500;
	color: var(--text-muted);
	white-space: nowrap;
}
.sb-BUY        { background: rgba(59, 130, 246, 0.09); border-color: rgba(59, 130, 246, 0.25); }
.sb-BUY .sb-count { color: #1d4ed8; }
.sb-BUY:hover  { background: rgba(59, 130, 246, 0.18); border-color: rgba(59, 130, 246, 0.50); }

.sb-HOLD       { background: rgba(217, 119, 6, 0.08);  border-color: rgba(217, 119, 6, 0.22); }
.sb-HOLD .sb-count { color: #b45309; }
.sb-HOLD:hover { background: rgba(217, 119, 6, 0.16);  border-color: rgba(217, 119, 6, 0.45); }

.sb-SELL       { background: rgba(220, 38, 38, 0.08);  border-color: rgba(220, 38, 38, 0.22); }
.sb-SELL .sb-count { color: #b91c1c; }
.sb-SELL:hover { background: rgba(220, 38, 38, 0.16);  border-color: rgba(220, 38, 38, 0.45); }

.sb-NO_DATA    { background: var(--bg3); }
.sb-NO_DATA .sb-count { color: var(--text-dim); }
.sb-NO_DATA:hover { background: var(--bg2); border-color: var(--border-bright); }

/* Quality, growth and technical metric columns */
.col-roce, .col-roe { width: 84px; text-align: right; }
.col-cfo { width: 84px; text-align: right; }
td.col-roce, td.col-roe, td.col-cfo {
	font-family: var(--font-inter);
	font-size: 0.84rem;
	font-weight: 500;
	text-align: right;
}
.col-cagr { width: 92px; text-align: right; }
.col-rsi  { width: 70px; text-align: right; }
.col-trend { width: 86px; text-align: right; }
td.col-cagr, td.col-rsi {
	font-family: var(--font-inter);
	font-size: 0.84rem;
	font-weight: 500;
	text-align: right;
}
td.metric-hot { color: var(--orange); }

.trend-cell { display: flex; gap: 4px; justify-content: flex-end; }
.pip {
	display: inline-block;
	min-width: 30px;
	text-align: center;
	padding: 1px 5px;
	border-radius: 4px;
	font-size: 0.68rem;
	font-weight: 600;
	border: 1px solid transparent;
}
.pip-up   { background: var(--green-bg); color: var(--green); border-color: var(--green-border); }
.pip-down { background: var(--red-bg);   color: var(--red);   border-color: var(--red-border); }
.pip-na   { background: var(--bg3);      color: var(--text-dim); border-color: var(--border); }

/* ── 52-Week Low screener columns ───────────────────────────── */
.col-low52w, .col-high52w { width: 105px; text-align: right; }
td.col-low52w, td.col-high52w {
	font-family: var(--font-inter);
	font-size: 0.84rem;
	text-align: right;
	color: var(--text-muted);
}

.col-abovelow { width: 130px; text-align: right; }
td.col-abovelow { text-align: right; padding: 8px 12px; }

.above-low-badge {
	display: inline-block;
	padding: 3px 9px;
	border-radius: 6px;
	font-size: 0.84rem;
	font-weight: 700;
	letter-spacing: 0.01em;
	font-family: var(--font-inter);
	white-space: nowrap;
}

.above-low-badge.low-target {
	background: rgba(16, 185, 129, 0.18);
	border: 1px solid rgba(16, 185, 129, 0.45);
	color: #10b981;
}

.above-low-badge.low-good {
	background: rgba(59, 130, 246, 0.15);
	border: 1px solid rgba(59, 130, 246, 0.4);
	color: #3b82f6;
}

.above-low-badge.low-mod {
	background: rgba(245, 158, 11, 0.14);
	border: 1px solid rgba(245, 158, 11, 0.35);
	color: #f59e0b;
}

.above-low-badge.low-far {
	background: var(--bg3);
	border: 1px solid var(--border);
	color: var(--text-muted);
}

.col-pe { width: 75px; text-align: right; }
td.col-pe { font-family: var(--font-inter); font-size: 0.84rem; text-align: right; color: var(--text); }
.rec-SELL {
	background: rgba(220, 38, 38, 0.08);
	color: #b91c1c;
	border: 1px solid rgba(220, 38, 38, 0.22);
}
.rec-NO_DATA {
	background: var(--bg3);
	color: var(--text-dim);
	border: 1px solid var(--border);
}

.rec-score {
	font-size: 0.71rem;
	font-weight: 600;
	color: var(--text-muted);
	letter-spacing: 0.01em;
}

.rec-detail {
	font-size: 0.71rem;
	color: var(--text-dim);
	line-height: 1.3;
	letter-spacing: 0.01em;
}

.rec-na { color: var(--text-dim); font-size: 0.8rem; }
.rec-unver { color: var(--orange); }
.rec-LOADING {
	background: var(--accent-bg);
	color: var(--accent);
	border: 1px solid rgba(37, 99, 235, 0.25);
}

/* ── Toggle label ────────────────────────────────────────────── */
.toggle-label {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 0.82rem;
	color: var(--text-muted);
	cursor: pointer;
	white-space: nowrap;
	padding: 4px 0;
	user-select: none;
}
.toggle-label input[type="checkbox"] {
	width: 14px; height: 14px;
	accent-color: var(--accent);
	cursor: pointer;
}
.toggle-label:hover { color: var(--text); }

/* ── Print button ────────────────────────────────────────────── */
.print-btn {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 8px 16px;
	background: var(--bg3);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	color: var(--text-muted);
	font-family: var(--font-inter);
	font-size: 0.83rem;
	font-weight: 500;
	cursor: pointer;
	transition: all 0.15s;
	white-space: nowrap;
}
.print-btn:hover {
	background: var(--border);
	color: var(--text);
}

/* ── Corporate action warning ────────────────────────────────── */
.ca-warn {
	display: block;
	margin-top: 3px;
	font-size: 0.68rem;
	color: #b45309;
	background: rgba(217, 119, 6, 0.08);
	border: 1px solid rgba(217, 119, 6, 0.2);
	border-radius: 4px;
	padding: 1px 6px;
	cursor: help;
	width: fit-content;
}

/* ── Print / PDF styles ──────────────────────────────────────── */
/* The cover note only exists on paper */
.print-cover { display: none; }

@media print {
	/* Hide everything interactive */
	.controls-bar,
	.footer,
	.print-btn,
	.refresh-btn,
	.toast,
	.header { display: none !important; }

	/* Reset backgrounds so nothing burns ink */
	.table-loader { display: none !important; }
	body, .main, .table-wrap { background: #fff !important; box-shadow: none !important; }
	body { font-size: 6.5pt !important; line-height: 1.25 !important; }

	/* ── Cover note ── */
	.print-cover {
		display: block !important;
		margin: 0 0 5px;
		padding: 0 0 4px;
		border-bottom: 1pt solid #333;
	}
	.print-title { font-size: 11pt; font-weight: 700; color: #111; margin-bottom: 2px; }
	.print-what, .print-warn, .print-meta {
		font-size: 5.8pt;
		line-height: 1.32;
		color: #333;
		margin-bottom: 1.5px;
	}
	.print-meta { font-weight: 600; color: #111; }
	.print-warn { color: #555; font-style: italic; }

	/* ── Table ──
		 The screen layout pins several columns to pixel widths. On paper those
		 push the table past the page edge, so every one is cleared before the
		 print percentages are applied. */
	.main { padding: 0 !important; }
	.table-wrap {
		border: 0.75pt solid #999 !important;
		border-radius: 0 !important;
		overflow: visible !important;
	}
	table {
		width: 100% !important;
		table-layout: fixed !important;
		border-collapse: collapse !important;
	}
	th, td, .col-name, .col-sector, .col-price, .col-dayhigh, .col-day, .col-crash,
	.col-roce, .col-roe, .col-rsi, .col-trend, .col-levels, .col-rec,
	.col-rank, .col-symbol {
		min-width: 0 !important;
		max-width: none !important;
	}

	/* One type size for the whole table, so nothing looks pasted in */
	th, td, td * { font-size: 6pt !important; line-height: 1.25 !important; }
	th { font-size: 5.6pt !important; font-weight: 700 !important; letter-spacing: 0 !important; }
	th, td { padding: 1.5pt 2.5pt !important; overflow: hidden !important; word-break: break-word; }
	thead { background: #eee !important; display: table-header-group; }
	tbody tr:nth-child(even) { background: #f7f7f7 !important; }
	tr { page-break-inside: avoid; }

	/* Every column prints, including any hidden on narrow screens */
	.col-name, .col-sector, .col-dayhigh, .col-roce, .col-roe,
	.col-rsi, .col-trend, .col-levels, .col-rec { display: table-cell !important; }

	/* Widths total 100%, tuned for A4 landscape */
	.col-rank   { width: 3%  !important; }
	.col-symbol { width: 8%  !important; }
	.col-name   { width: 11% !important; }
	.col-sector { width: 7%  !important; }
	.col-price  { width: 7%  !important; }
	.col-dayhigh { width: 5% !important; }
	.col-day    { width: 5%  !important; }
	.col-crash  { width: 6%  !important; }
	.col-roce   { width: 5%  !important; }
	.col-roe    { width: 5%  !important; }
	.col-rsi    { width: 4%  !important; }
	.col-trend  { width: 9%  !important; }
	.col-levels { width: 11% !important; }
	.col-rec    { width: 14% !important; }

	/* Compact the stacked cells without shrinking their type */
	.rec-cell, .levels-cell, .trend-cell { gap: 1pt !important; }
	.rec-badge {
		padding: 0 3pt !important;
		border-radius: 2pt !important;
		font-weight: 700 !important;
	}
	.lv { grid-template-columns: 14pt 1fr !important; gap: 2pt !important; }
	.lv-rr { padding: 0 3pt !important; margin-top: 1pt !important; align-self: flex-start; }
	.pip { min-width: 0 !important; padding: 0 2pt !important; border-radius: 2pt !important; }
	.price-badge { border: 0.5pt solid #ccc !important; background: #fff !important; padding: 0 3pt !important; }
	.sector-pill { padding: 0 3pt !important; }
	.sort-arrow { display: none !important; }

	@page {
		margin: 8mm 6mm;
		size: A4 landscape;
	}
}

/* ── Colour helpers ──────────────────────────────────────────── */
.up      { color: var(--green); }
.down    { color: var(--red); }
.neutral { color: var(--text-muted); }

/* ── Price flash ─────────────────────────────────────────────── */
@keyframes flash-up   { 0% { background: rgba(22,163,74,0.12); }  100% { background: transparent; } }
@keyframes flash-down { 0% { background: rgba(220,38,38,0.10); }  100% { background: transparent; } }
.flash-up   { animation: flash-up   1.2s ease-out; }
.flash-down { animation: flash-down 1.2s ease-out; }

/* ── Crash % badge ───────────────────────────────────────────── */
.crash-badge {
	display: inline-flex;
	align-items: center;
	justify-content: flex-end;
	gap: 5px;
	font-family: var(--font-inter);
	font-size: 0.79rem;
	font-weight: 500;
	padding: 3px 10px;
	border-radius: 999px;
	min-width: 76px;
	border: 1px solid transparent;
}
.crash-badge.danger  { background: var(--red-bg);    color: var(--red);    border-color: var(--red-border); }
.crash-badge.warning { background: var(--orange-bg); color: var(--orange); }
.crash-badge.moderate{ background: var(--yellow-bg); color: var(--yellow); }
.crash-badge.safe    { background: var(--green-bg);  color: var(--green);  border-color: var(--green-border); }

/* ── Sector pill ─────────────────────────────────────────────── */
.sector-pill {
	display: inline-block;
	padding: 2px 8px;
	border-radius: 4px;
	font-size: 0.71rem;
	font-weight: 500;
	background: var(--bg3);
	border: 1px solid var(--border);
	color: var(--text-muted);
	white-space: nowrap;
}

/* ── Hidden ──────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
	position: fixed;
	bottom: 20px;
	right: 20px;
	padding: 10px 18px;
	background: var(--text);
	color: #fff;
	border-radius: var(--radius-sm);
	font-size: 0.83rem;
	box-shadow: var(--shadow);
	z-index: 1000;
	animation: slide-in 0.3s ease;
	max-width: 280px;
}
@keyframes slide-in {
	from { transform: translateX(110%); opacity: 0; }
	to   { transform: translateX(0);    opacity: 1; }
}

/* ── Footer ──────────────────────────────────────────────────── */
.footer {
	flex-shrink: 0;
	border-top: 1px solid var(--border);
	padding: 6px 10px;
	background: var(--bg2);
	text-align: center;
}
/* ── Rules explainer ─────────────────────────────────────────── */
.rules-box {
	width: 100%;
	margin: 0 0 14px;
	text-align: left;
}
.rules-title {
	font-size: 0.82rem;
	font-weight: 600;
	color: var(--text);
	margin-bottom: 12px;
	text-align: center;
	letter-spacing: 0.01em;
}
.rules-grid {
	display: grid;
	grid-template-columns: repeat(6, minmax(0, 1fr));
	gap: 14px;
	align-items: stretch;
}
@media (max-width: 1500px) { .rules-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 860px)  { .rules-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px)  { .rules-grid { grid-template-columns: 1fr; } }
.rules-tier {
	background: var(--bg3);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 12px 14px;
	display: flex;
	flex-direction: column;
}
/* Push each panel's footnote to the bottom so the row of cards lines up */
.rules-tier .tier-note { margin-top: auto; }
.rules-tier ul {
	list-style: none;
	margin: 8px 0 0;
	padding: 0;
}
/* The hard rules are numbered because they are checked in this order */
.rules-tier ol.hard-rules {
	margin: 8px 0 0;
	padding-left: 18px;
}
.rules-tier ol.hard-rules li {
	font-size: 0.75rem;
	color: var(--text-muted);
	line-height: 1.7;
}
.rules-tier ol.hard-rules li b { color: var(--text); font-weight: 600; }

/* A tier whose rules the current data source cannot support */
.rules-tier.paused { opacity: 0.72; border-style: dashed; }
.rules-tier.paused li { text-decoration: line-through; }
.rules-tier li {
	font-size: 0.75rem;
	color: var(--text-muted);
	line-height: 1.7;
}
.rules-tier li b { color: var(--text); font-weight: 600; }
.tier-note {
	font-size: 0.69rem;
	color: var(--text-dim);
	margin-top: 8px;
	padding-top: 8px;
	border-top: 1px dashed var(--border);
	line-height: 1.4;
}
.tier-tag {
	display: inline-block;
	padding: 2px 9px;
	border-radius: 999px;
	font-size: 0.68rem;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}
.tier-A { background: rgba(22, 163, 74, 0.12);  color: #15803d; }
.tier-B { background: rgba(59, 130, 246, 0.12); color: #1d4ed8; }
.tier-C { background: rgba(124, 58, 237, 0.12); color: #6d28d9; }
.tier-D { background: rgba(13, 148, 136, 0.12); color: #0f766e; }
.tier-E { background: rgba(202, 138, 4, 0.14);  color: #a16207; }
.tier-R { background: rgba(220, 38, 38, 0.12);  color: #b91c1c; }
.tier-V { background: rgba(107, 114, 128, 0.14); color: #4b5563; }

.tier-q {
	font-size: 0.71rem;
	font-style: italic;
	color: var(--text-dim);
	margin-top: 7px;
}

.rules-caveat {
	margin-top: 14px;
	padding: 11px 14px;
	border: 1px solid var(--border);
	border-left: 3px solid var(--orange);
	border-radius: 6px;
	background: var(--orange-bg);
	font-size: 0.73rem;
	line-height: 1.6;
	color: var(--text-muted);
}
.rules-caveat b { color: var(--text); }

.footer-note { font-size: 0.71rem; color: var(--text-dim); }

/* ── Chart Modal Dialog ─────────────────────────────────────── */
.chart-modal {
	position: fixed;
	inset: 0;
	z-index: 9999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
	animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.chart-modal.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
	from { transform: translateY(24px) scale(0.98); opacity: 0; }
	to   { transform: translateY(0) scale(1);       opacity: 1; }
}

.chart-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(10, 14, 23, 0.78);
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
}

.chart-panel {
	position: relative;
	width: min(96vw, 1320px);
	height: min(90vh, 780px);
	max-height: 94vh;
	background: #111827;
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 16px;
	box-shadow: 0 30px 80px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.05);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Modal Header */
.chart-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 20px;
	border-bottom: 1px solid rgba(255, 255, 255, 0.08);
	background: #161f30;
	flex-shrink: 0;
	gap: 12px;
}

.chart-title-wrap {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
	flex-wrap: wrap;
}

.chart-symbol {
	font-family: var(--font-mono);
	font-size: 1.15rem;
	font-weight: 700;
	color: #60a5fa;
	letter-spacing: 0.02em;
}

.chart-name {
	font-size: 0.88rem;
	color: #94a3b8;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 380px;
}

.chart-sector-pill {
	font-size: 0.72rem;
	font-weight: 600;
	padding: 2px 8px;
	border-radius: 999px;
	background: rgba(99, 102, 241, 0.18);
	color: #818cf8;
	border: 1px solid rgba(99, 102, 241, 0.35);
}

.chart-actions {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-shrink: 0;
}

/* Live Today's Price Stats Pill Group in Modal Header */
.chart-today-stats {
	display: flex;
	align-items: center;
	gap: 6px;
	flex-wrap: wrap;
	margin-left: 6px;
	padding-left: 10px;
	border-left: 1px solid rgba(255, 255, 255, 0.12);
}

.today-stat {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	background: rgba(255, 255, 255, 0.05);
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: 6px;
	padding: 3px 8px;
	font-size: 0.76rem;
	white-space: nowrap;
}

.today-lbl {
	color: #94a3b8;
	font-size: 0.69rem;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	font-weight: 500;
}

.today-val {
	color: #f1f5f9;
	font-weight: 600;
	font-family: var(--font-inter);
}

.today-val.badge-green { color: #34d399; }
.today-val.badge-red   { color: #f87171; }

.chart-close {
	width: 32px;
	height: 32px;
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.05);
	color: #94a3b8;
	font-size: 1.05rem;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.15s ease;
}
.chart-close:hover {
	background: rgba(239, 68, 68, 0.2);
	border-color: rgba(239, 68, 68, 0.4);
	color: #f87171;
}

/* Quick Metrics Ribbon */
.chart-ribbon {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(95px, 1fr));
	gap: 8px;
	padding: 10px 20px;
	background: #0f172a;
	border-bottom: 1px solid rgba(255, 255, 255, 0.06);
	flex-shrink: 0;
}

.ribbon-item {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.ribbon-label {
	font-size: 0.68rem;
	color: #64748b;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	font-weight: 500;
}

.ribbon-val {
	font-size: 0.85rem;
	font-weight: 600;
	color: #f1f5f9;
	font-family: var(--font-inter);
}

.ribbon-val.badge-green { color: #10b981; }
.ribbon-val.badge-red   { color: #f87171; }

/* Toolbar: Ranges & Legend */
.chart-toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 20px;
	background: #131d2e;
	border-bottom: 1px solid rgba(255, 255, 255, 0.06);
	flex-shrink: 0;
	gap: 12px;
	flex-wrap: wrap;
}

.range-group {
	display: flex;
	gap: 3px;
	background: rgba(0, 0, 0, 0.35);
	border-radius: 8px;
	padding: 3px;
	border: 1px solid rgba(255, 255, 255, 0.08);
}

.range-btn {
	padding: 5px 12px;
	border: none;
	border-radius: 6px;
	font-size: 0.76rem;
	font-weight: 600;
	font-family: var(--font-inter);
	background: transparent;
	color: #94a3b8;
	cursor: pointer;
	transition: all 0.15s ease;
}

.range-btn:hover {
	color: #f1f5f9;
	background: rgba(255, 255, 255, 0.06);
}

.range-btn.active {
	background: #3b82f6;
	color: #ffffff;
	box-shadow: 0 2px 6px rgba(59, 130, 246, 0.4);
}

.chart-legend-pills {
	display: flex;
	gap: 12px;
	align-items: center;
	font-size: 0.72rem;
	font-weight: 500;
}

.leg-item { display: flex; align-items: center; gap: 4px; }
.leg-price  { color: #38bdf8; }
.leg-high   { color: #f87171; }
.leg-low    { color: #34d399; }
.leg-dma50  { color: #fbbf24; }
.leg-dma200 { color: #a855f7; }

/* Canvas Body */
.chart-body {
	position: relative;
	flex: 1;
	min-height: 420px;
	max-height: none;
	padding: 16px 20px 20px;
	background: #0b1120;
}

.chart-body canvas {
	width: 100% !important;
	height: 100% !important;
}

.chart-loader {
	position: absolute;
	inset: 0;
	background: rgba(11, 17, 32, 0.85);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	color: #94a3b8;
	font-size: 0.85rem;
	z-index: 10;
	transition: opacity 0.2s ease;
}
.chart-loader.hidden { opacity: 0; pointer-events: none; }

/* Clickable table rows */
#stockTable tbody tr {
	cursor: pointer;
	transition: background 0.12s ease;
}
#stockTable tbody tr:hover {
	background: rgba(59, 130, 246, 0.08) !important;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
	.col-name { display: none; }
	.col-high { display: none; }
}
@media (max-width: 768px) {
	.header   { padding: 0 16px; }
	.controls-bar { padding: 8px 16px; top: 57px; }
	.main     { padding: 12px 16px 60px; }
	.footer   { padding: 12px 16px; }
	.col-sector { display: none; }
	.col-dayhigh { display: none; }
	.chart-panel { width: 98vw; max-height: 95vh; }
	.chart-header { padding: 10px 14px; }
	.chart-ribbon { grid-template-columns: repeat(3, 1fr); padding: 8px 14px; }
	.chart-toolbar { padding: 8px 14px; }
	.range-btn { padding: 4px 8px; font-size: 0.7rem; }
	.chart-legend-pills { display: none; }
	.chart-body { min-height: 300px; padding: 10px 14px 14px; }
}
@media (max-width: 540px) {
	.header-stats { display: none; }
	.col-low { display: none; }
	.chart-name { display: none; }
}

