/* ==========================================================================
   CryptoWatchHub Core — component styles
   Shipped with the plugin, not the theme: these belong to the shortcodes that
   render them, and the host disables the theme file editor, so plugin-owned
   CSS is the only way to style new components without replacing the whole
   theme directory. Uses the theme's design tokens (--accent, --up, --down …)
   and is enqueued only on pages whose shortcodes need it.
   ========================================================================== */

/* Utilities the theme does not define. */
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }

/* Flows evenly whether there are four tool cards or six. */
.grid4.cwh-tools { grid-template-columns: repeat(auto-fit, minmax(236px, 1fr)); }

/* The theme's page template only goes full-width for shortcodes it knows
   about, so widen it here for the liquidation dashboard instead of editing
   the theme. */
.page-layout:has(.cwh-liq) { grid-template-columns: minmax(0, 1fr); }
.page-layout:has(.cwh-liq) .page-aside { display: none; }
.page-layout:has(.cwh-liq) .page-body > p,
.page-layout:has(.cwh-liq) .page-body > h2,
.page-layout:has(.cwh-liq) .page-body > h3,
.page-layout:has(.cwh-liq) .page-body > ul,
.page-layout:has(.cwh-liq) .page-body > ol,
.page-layout:has(.cwh-liq) .page-body > details { max-width: 820px; }

/* ---------- Liquidations ---------- */

.cwh-liq { display: flex; flex-direction: column; gap: 18px; margin: 18px 0 8px; }

.liq-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.liq-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.liq-status {
	display: inline-flex; align-items: center; gap: 8px;
	padding: 5px 13px;
	border: 1px solid var(--border-strong); border-radius: var(--radius-full);
	background: var(--card);
	font-size: 0.78rem; font-weight: 650;
}
.liq-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.liq-status[data-state="live"] .liq-dot { background: var(--up); animation: cwhPulse 2s var(--ease-standard) infinite; }
.liq-status[data-state="wait"] .liq-dot { background: var(--color-warning-500); }
.liq-status[data-state="off"] { color: var(--muted); }
.liq-status[data-state="off"] .liq-dot { background: var(--down); }
@keyframes cwhPulse { 50% { box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.22); } }

.liq-tiles .v { font-size: 1.35rem; }
.liq-long { color: var(--down); }
.liq-short { color: var(--up); }
.liq-long > .tri, .liq-short > .tri { font-size: 0.62em; vertical-align: 12%; margin-right: 3px; }

.liq-split {
	display: flex; height: 10px;
	background: var(--bg-soft);
	border: 1px solid var(--border);
	border-radius: var(--radius-full); overflow: hidden;
}
.liq-bar-long, .liq-bar-short { width: 50%; transition: width var(--duration-normal) var(--ease-standard); }
.liq-bar-long { background: linear-gradient(90deg, var(--color-down-600), var(--color-down-400)); }
.liq-bar-short { background: linear-gradient(90deg, var(--color-up-400), var(--color-up-600)); }
.liq-split-legend {
	display: flex; justify-content: space-between; gap: 12px;
	margin-top: 7px;
	font-size: 0.78rem; font-weight: 600;
}

.liq-card { padding: 0; overflow: hidden; }
.liq-card-head {
	display: flex; align-items: baseline; justify-content: space-between;
	gap: 12px; flex-wrap: wrap;
	padding: 13px 18px; border-bottom: 1px solid var(--border);
}
.liq-card-head h3 {
	margin: 0;
	font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em;
	color: var(--muted);
}
.liq-scroll { overflow-x: auto; }
.liq-table { width: 100%; min-width: 420px; border-collapse: collapse; font-size: 0.85rem; }
.liq-table th {
	text-align: left; padding: 9px 14px;
	font-size: 0.68rem; font-weight: 650;
	text-transform: uppercase; letter-spacing: 0.05em;
	color: var(--faint);
	border-bottom: 1px solid var(--border);
	white-space: nowrap;
}
.liq-table td { padding: 8px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.liq-table tbody tr:last-child td { border-bottom: none; }
.liq-table tbody tr:hover { background: var(--bg-soft); }
.liq-table .num, .liq-table th.num {
	text-align: right;
	font-family: var(--font-mono);
	font-variant-numeric: tabular-nums lining-nums;
	letter-spacing: var(--tracking-mono);
}
.liq-table .liq-sym { font-weight: 700; }
.liq-wait td { padding: 22px 16px; text-align: center; color: var(--faint); white-space: normal; }

.liq-fund-cols { display: grid; grid-template-columns: 1fr 1fr; }
.liq-fund-cols > div + div { border-left: 1px solid var(--border); }
.liq-sub {
	margin: 14px 18px 4px;
	font-size: 0.74rem; font-weight: 650;
	text-transform: uppercase; letter-spacing: 0.04em;
	color: var(--muted);
}
.liq-note { margin: 0; padding: 12px 18px 15px; border-top: 1px solid var(--border); }
.liq-source { max-width: 860px; }

.liq-venue { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.liq-venue img { border-radius: 50%; flex: none; }
.liq-share {
	display: inline-block; width: 52px; height: 6px;
	margin-right: 9px; vertical-align: middle;
	background: var(--bg-soft); border-radius: var(--radius-full); overflow: hidden;
}
.liq-share span { display: block; height: 100%; background: var(--accent); }

/* ---------- Liquidation price calculator ---------- */

.cwh-liqcalc { margin: 18px 0; }
.lc-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.lc-field { display: flex; flex-direction: column; gap: 6px; position: relative; }
.lc-field label {
	font-size: 0.72rem; font-weight: 650;
	text-transform: uppercase; letter-spacing: 0.04em;
	color: var(--muted);
}
.lc-field input, .lc-field select {
	width: 100%; padding: 10px 12px;
	border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
	background: var(--bg-base); color: var(--text);
	font: inherit;
}
.lc-field input { font-family: var(--font-mono); }
.lc-suffix { position: absolute; right: 13px; bottom: 11px; color: var(--faint); font-size: 0.85rem; pointer-events: none; }

.lc-out {
	display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
	margin: 18px 0 6px; padding: 16px 18px;
	background: var(--bg-soft);
	border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.lc-primary { display: flex; flex-direction: column; gap: 1px; min-width: 200px; }
.lc-primary .k {
	font-size: 0.72rem; font-weight: 650;
	text-transform: uppercase; letter-spacing: 0.05em;
	color: var(--muted);
}
.lc-liq { font-size: 2rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; }
.lc-primary .muted { font-size: 0.82rem; }
.lc-side-stats { display: grid; grid-template-columns: repeat(3, auto); gap: 22px; margin-left: auto; }
.lc-side-stats > div { display: flex; flex-direction: column; gap: 2px; }
.lc-side-stats .muted { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; }
.lc-side-stats strong { font-size: 1.05rem; }

/* ---------- Heatmaps ---------- */

/* Same trick as the liquidation dashboard: widen the theme's page template
   without editing it. */
.page-layout:has(.cwh-heatmap) { grid-template-columns: minmax(0, 1fr); }
.page-layout:has(.cwh-heatmap) .page-aside { display: none; }
.page-layout:has(.cwh-heatmap) .page-body > p,
.page-layout:has(.cwh-heatmap) .page-body > h2,
.page-layout:has(.cwh-heatmap) .page-body > h3,
.page-layout:has(.cwh-heatmap) .page-body > ul,
.page-layout:has(.cwh-heatmap) .page-body > ol,
.page-layout:has(.cwh-heatmap) .page-body > details { max-width: 820px; }

.cwh-heatmap { margin: 18px 0 8px; }
.hm-head {
	display: flex; align-items: center; justify-content: space-between;
	gap: 14px; flex-wrap: wrap; margin-bottom: 10px;
}
.hm-ranges { display: inline-flex; gap: 2px; padding: 3px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.hm-rangebtn {
	border: none; background: transparent; cursor: pointer;
	padding: 6px 13px; border-radius: var(--radius-md);
	font-size: 0.82rem; font-weight: 650; color: var(--muted);
}
.hm-rangebtn:hover { color: var(--text); }
.hm-rangebtn[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* Aspect ratio matches the layout units the treemap was solved in (1600×700),
   so tiles keep the near-square proportions that make areas comparable. */
.hm-box {
	position: relative;
	aspect-ratio: 1600 / 700;
	width: 100%;
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	overflow: hidden;
	background: var(--bg-soft);
}
.hm-tile {
	position: absolute;
	display: flex; flex-direction: column; align-items: center; justify-content: center;
	gap: 1px; overflow: hidden;
	background: var(--hm, #4b5563);
	color: #fff; text-decoration: none !important;
	border: 1px solid rgba(0, 0, 0, 0.28);
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
	transition: filter var(--duration-fast) var(--ease-standard);
	line-height: 1.15;
}
.hm-tile:hover, .hm-tile:focus-visible { filter: brightness(1.22); z-index: 3; }
.hm-sym { font-weight: 800; letter-spacing: -0.01em; }
.hm-chg { font-weight: 650; opacity: 0.95; }

.hm-lg .hm-sym { font-size: clamp(0.95rem, 1.5vw, 1.6rem); }
.hm-lg .hm-chg { font-size: clamp(0.7rem, 0.95vw, 1rem); }
.hm-md .hm-sym { font-size: clamp(0.72rem, 1vw, 1rem); }
.hm-md .hm-chg { font-size: clamp(0.6rem, 0.75vw, 0.78rem); }
.hm-sm .hm-sym { font-size: clamp(0.55rem, 0.72vw, 0.76rem); }
.hm-sm .hm-chg { font-size: 0.58rem; opacity: 0.85; }
.hm-xs .hm-sym { font-size: 0.5rem; opacity: 0.9; }
.hm-xs .hm-chg { display: none; }

/* The tail of the market at equal size: proportional area would render these
   as unreadable slivers, so only colour carries the data here. */
.hm-resttitle {
	margin: 18px 0 8px;
	font-size: 0.78rem; font-weight: 650;
	text-transform: uppercase; letter-spacing: 0.05em;
	color: var(--muted);
}
.hm-rest { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 5px; }
.hm-cell {
	display: flex; flex-direction: column; align-items: center; justify-content: center;
	gap: 1px; padding: 9px 6px;
	background: var(--hm, #4b5563);
	color: #fff; text-decoration: none !important;
	border-radius: var(--radius-sm);
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
	transition: filter var(--duration-fast) var(--ease-standard);
}
.hm-cell:hover, .hm-cell:focus-visible { filter: brightness(1.22); }
.hm-cell .hm-sym { font-size: 0.8rem; }
.hm-cell .hm-chg { font-size: 0.72rem; }

.hm-legend { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-top: 14px; }
.hm-key { width: 26px; height: 10px; border-radius: 2px; flex: none; }
.hm-legend-note { margin-left: auto; }

/* ---------- Sector tiles ---------- */

.cwh-sectors {
	display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
	gap: 10px; margin: 16px 0 10px;
}
.sec-tile {
	display: flex; flex-direction: column; gap: 2px;
	padding: 13px 15px;
	background: var(--card);
	border: 1px solid var(--border);
	border-left: 4px solid var(--hm, #4b5563);
	border-radius: var(--radius-lg);
}
.sec-name { font-weight: 650; font-size: 0.92rem; }
.sec-chg { font-weight: 750; font-size: 1.15rem; color: var(--hm, var(--text)); }

/* ---------- Fear & Greed history ---------- */

/* The index page ships a full-width chart and two side-by-side tables, so it
   drops the theme's sidebar the same way the other data pages do. */
.page-layout:has(.cwh-fng-history) { grid-template-columns: minmax(0, 1fr); }
.page-layout:has(.cwh-fng-history) .page-aside { display: none; }
.page-layout:has(.cwh-fng-history) .page-body > p,
.page-layout:has(.cwh-fng-history) .page-body > h2,
.page-layout:has(.cwh-fng-history) .page-body > h3,
.page-layout:has(.cwh-fng-history) .page-body > ul,
.page-layout:has(.cwh-fng-history) .page-body > ol,
.page-layout:has(.cwh-fng-history) .page-body > details { max-width: 820px; }

.fng-chartwrap { padding: 16px 18px 10px; }
.fng-chart { width: 100%; height: auto; display: block; color: var(--text); }

.fng-dot {
	display: inline-block; width: 9px; height: 9px;
	margin-right: 7px; border-radius: 2px;
	vertical-align: baseline; flex: none;
}

.fng-zonelist { padding: 6px 18px 4px; }
.fng-zonerow {
	display: grid;
	grid-template-columns: 132px minmax(0, 1fr) 52px 84px 56px;
	align-items: center; gap: 12px;
	padding: 9px 0;
	border-bottom: 1px solid var(--border);
}
.fng-zonelist .fng-zonerow:last-child { border-bottom: none; }
.fng-zonename { font-weight: 650; font-size: 0.9rem; white-space: nowrap; }
.fng-zonebar { height: 9px; background: var(--bg-soft); border-radius: var(--radius-full); overflow: hidden; }
.fng-zonebar span { display: block; height: 100%; border-radius: var(--radius-full); }
.fng-zonepct { font-weight: 700; text-align: right; }
.fng-zonedays { text-align: right; }
.fng-zoneyear { text-align: right; color: var(--muted); }

.fng-forward th[scope="row"] { white-space: nowrap; font-weight: 650; text-align: left; }
.fng-forward .fng-subhead th {
	font-size: 0.62rem; font-weight: 600;
	border-bottom: 1px solid var(--border-strong);
	padding-top: 0;
}

@media (max-width: 700px) {
	.fng-zonerow { grid-template-columns: 108px minmax(0, 1fr) 48px; }
	.fng-zonedays, .fng-zoneyear { display: none; }
}

/* ---------- Returns matrix ---------- */

.page-layout:has(.ret-matrix) { grid-template-columns: minmax(0, 1fr); }
.page-layout:has(.ret-matrix) .page-aside { display: none; }
.page-layout:has(.ret-matrix) .page-body > p,
.page-layout:has(.ret-matrix) .page-body > h2,
.page-layout:has(.ret-matrix) .page-body > h3,
.page-layout:has(.ret-matrix) .page-body > ul,
.page-layout:has(.ret-matrix) .page-body > ol,
.page-layout:has(.ret-matrix) .page-body > details { max-width: 820px; }

.ret-matrix { min-width: 760px; }
.ret-matrix th { text-align: right; }
.ret-matrix th:first-child { text-align: left; }
.ret-rowhead {
	font-weight: 700; color: var(--text);
	background: var(--card);
	position: sticky; left: 0; z-index: 1;
	text-align: left !important;
}
.ret {
	background: var(--hm, transparent);
	color: #fff;
	text-align: right;
	font-weight: 650;
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
	border-right: 1px solid rgba(0, 0, 0, 0.18);
}
.ret-na { background: transparent; }
.ret.ret-pale { color: #06140e; text-shadow: none; }
.ret-live { outline: 2px solid var(--accent); outline-offset: -2px; }
.ret-yearcol { border-left: 2px solid var(--border-strong); font-weight: 800; }

/* ---------- ROI calculator ---------- */

.cwh-roi { margin: 18px 0; }
.roi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 620px; }

/* ---------- TradingView embed ---------- */

.cwh-tv { margin: 16px 0 8px; }
/* Deliberately NOT a flex container: TradingView's iframe is sized with
   height:100%, which collapses to content height inside a centred flex line.
   The placeholder does its own centring instead. */
.cwh-tv-host {
	display: block;
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	overflow: hidden;
	background: var(--bg-soft);
}
.cwh-tv-host iframe { display: block; }
.cwh-tv-ph {
	display: flex; align-items: center; justify-content: center;
	height: 100%; margin: 0; font-size: 0.9rem;
}
.cwh-tv-foot {
	display: flex; align-items: baseline; justify-content: space-between;
	gap: 12px; flex-wrap: wrap; margin-top: 8px;
}

/* ---------- Responsive ---------- */

@media (max-width: 1024px) {
	.lc-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 820px) {
	/* A wide treemap is unreadable on a phone: give it a taller box. The tiles
	   stretch, but the ranking and the colours still read correctly. */
	.hm-box { aspect-ratio: 4 / 5; }
	.hm-legend-note { margin-left: 0; flex-basis: 100%; }
}

@media (max-width: 900px) {
	.grid2 { grid-template-columns: 1fr; }
	.liq-fund-cols { grid-template-columns: 1fr; }
	.liq-fund-cols > div + div { border-left: none; border-top: 1px solid var(--border); }
}

@media (max-width: 768px) {
	.lc-grid { grid-template-columns: 1fr 1fr; }
	.lc-side-stats { grid-template-columns: 1fr 1fr; gap: 14px 22px; margin-left: 0; }
	.ret-matrix { font-size: 0.78rem; }
	.ret-matrix td, .ret-matrix th { padding: 6px 8px; }
}

@media (max-width: 560px) {
	.lc-grid { grid-template-columns: 1fr; }
	.lc-liq { font-size: 1.55rem; }
	.liq-tiles .v { font-size: 1.1rem; }
	.liq-head { gap: 8px; }
}

/* Browsers without :has() keep the theme's two-column page: the dashboard
   still works, it is just narrower. */
@supports not selector(:has(*)) {
	.cwh-liq .liq-table { font-size: 0.8rem; }
}
