/* Torrex Dashboard — Telemetry layout with Parallax dark theme */

:root {
    /* Parallax dark theme palette */

    /* Backgrounds — hsl(222 47% 8%) base */
    --bg-page: hsl(222, 47%, 8%);
    --bg-card: hsl(220, 40%, 13%);
    --bg-hover: hsl(220, 35%, 16%);
    --bg-active: hsl(217, 32%, 19%);
    --border: hsl(217, 32%, 20%);

    /* Text */
    --text-primary: hsl(220, 15%, 95%);
    --text-secondary: hsl(220, 15%, 60%);
    --text-muted: hsl(220, 15%, 45%);

    /* Structural accent — Parallax info blue */
    --accent-cyan: hsl(200, 80%, 60%);

    /* Return colors — Parallax success/error */
    --positive: hsl(142, 76%, 45%);
    --negative: hsl(0, 84%, 65%);
    --neutral: hsl(220, 15%, 60%);

    /* Quadrant colors — derived from Parallax rating scale */
    --quadrant-leaders: hsl(142, 76%, 55%);
    --quadrant-fading: hsl(38, 92%, 65%);
    --quadrant-recovering: hsl(200, 80%, 60%);
    --quadrant-laggards: hsl(0, 84%, 70%);

    /* New: panel and chip tokens */
    --panel-bg: linear-gradient(145deg, hsl(220,40%,13%) 0%, hsl(222,47%,10%) 100%);
    --panel-edge-soft: rgba(102, 187, 224, 0.3);
    --chip-bg: rgba(102, 187, 224, 0.12);
    --grid-line: rgba(102, 187, 224, 0.06);

    /* Layout */
    --header-height: 56px;
    --content-max-width: 1420px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    background: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
}

/* ─── Backdrop Grid ─── */
.backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 60px 60px;
    opacity: 0.14;
}

/* ─── App Shell ─── */
.app-shell {
    position: relative;
    z-index: 1;
    width: min(1420px, calc(100% - 32px));
    margin: 18px auto 34px;
    display: grid;
    gap: 14px;
}

/* ─── Panel Base ─── */
.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-edge-soft);
    border-radius: 14px;
    position: relative;
    overflow: visible;
    padding: 16px 20px;
}

.panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 14px;
    right: 14px;
    height: 1px;
    background: var(--accent-cyan);
    opacity: 0.5;
    border-radius: 1px;
}

.panel::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 24px;
    background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent);
    pointer-events: none;
    border-radius: 14px 14px 0 0;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.panel-head h2 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

/* ─── Topbar ─── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--accent-cyan);
}

.report-date {
    font-size: 13px;
    color: var(--text-secondary);
}

nav {
    display: flex;
    align-items: center;
    gap: 24px;
}

/* ─── Chip Buttons (timeframe, viz mode) ─── */
.chip {
    padding: 6px 14px;
    border: none;
    background: var(--chip-bg);
    color: var(--text-secondary);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    border-radius: 20px;
    transition: all 0.15s;
}

.chip.active {
    background: var(--accent-cyan);
    color: var(--bg-page);
    font-weight: 600;
}

.chip:hover:not(.active) {
    color: var(--text-primary);
    background: rgba(102, 187, 224, 0.2);
}

.timeframe-toggle {
    display: flex;
    gap: 4px;
}

.viz-mode-toggle {
    display: flex;
    gap: 4px;
}

/* Monday badge on WTD column header */
.monday-badge {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    background: rgba(251, 191, 36, 0.15);
    color: hsl(38, 92%, 65%);
    vertical-align: middle;
}

/* ─── Tape Conflict Panel ─── */
.tape-conflict-panel {
    padding: 10px 20px;
}

.tape-conflict-bar {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    min-height: 24px;
}

.signal-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.signal-badge.biggest_move { background: rgba(34, 211, 238, 0.1); color: var(--accent-cyan); }
.signal-badge.zscore_outlier { background: rgba(251, 191, 36, 0.1); color: var(--quadrant-fading); }
.signal-badge.market_move { background: rgba(96, 165, 250, 0.1); color: var(--quadrant-recovering); }
.signal-badge.trend_divergence { background: rgba(192, 132, 252, 0.1); color: hsl(270, 80%, 72%); }
.signal-badge.quiet { background: transparent; color: var(--text-muted); }
.signal-badge.kill-switch { background: rgba(248, 113, 113, 0.1); color: hsl(0, 84%, 70%); }

.signal-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ─── Main Grid (7fr | 5fr) ─── */
.main-grid {
    display: grid;
    grid-template-columns: 7fr 5fr;
    gap: 14px;
}

.left-col {
    display: grid;
    gap: 14px;
    align-content: start;
}

.right-col {
    display: grid;
    gap: 14px;
    align-content: start;
    position: sticky;
    top: 90px;
    align-self: start;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
}

/* Scrollbar in right col */
.right-col::-webkit-scrollbar { width: 4px; }
.right-col::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── Regime Pill ─── */
.regime-pill {
    display: inline-block;
    padding: 3px 12px;
    border: 1px solid var(--accent-cyan);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: var(--accent-cyan);
    letter-spacing: 0.3px;
}

.regime-pill:empty { display: none; }

/* ─── Market Cards (The Pulse) ─── */
#pulse-container {
    position: relative;
}

.pulse-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    transition: all 0.3s ease;
}

.market-card.size-large {
    grid-column: span 2;
}

.pulse-grid.collapsed {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.pulse-grid.collapsed .market-card {
    padding: 6px 8px;
    min-height: 0;
}

.pulse-grid.collapsed .card-detail,
.pulse-grid.collapsed .card-movers,
.pulse-grid.collapsed .range-bar-container {
    display: none;
}

.pulse-grid.collapsed .market-card.size-large {
    grid-column: span 1;
}

.market-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 120px;
    position: relative;
}

.market-card:hover { background: var(--bg-hover); }

.market-card.active {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 1px var(--accent-cyan);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.market-code {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.market-flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 16px;
    border-radius: 2px;
    font-size: 9px;
    font-weight: 700;
    color: var(--bg-page);
    background: var(--text-secondary);
}

.card-return {
    font-size: 20px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.card-detail {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.card-movers {
    font-size: 11px;
    line-height: 1.6;
}

.card-movers .mover-up { color: var(--positive); }
.card-movers .mover-down { color: var(--negative); }
.mover-label {
    display: inline-block;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}
.market-card.size-large .mover-label {
    max-width: 180px;
}

/* Range bar */
.range-bar-container {
    margin-top: 8px;
    height: 14px;
    position: relative;
}

.range-bar-svg {
    width: 100%;
    height: 14px;
}

/* Collapse button */
.collapse-btn {
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 16px;
    border: 1px solid var(--border);
    border-radius: 0 0 6px 6px;
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: color 0.15s;
}

.collapse-btn:hover { color: var(--text-primary); }
.collapse-btn.flipped svg { transform: rotate(180deg); }

/* Floating tooltip — positioned by JS */
.floating-tooltip {
    position: fixed;
    background: hsl(220, 40%, 11%);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 11px;
    line-height: 1.6;
    white-space: nowrap;
    z-index: 9999;
    pointer-events: none;
    display: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    color: var(--text-primary);
}

.floating-tooltip .mover-up { color: var(--positive); }
.floating-tooltip .mover-down { color: var(--negative); }

/* ─── Commentary Panel ─── */
.commentary-panel {
    border-left: 3px solid var(--accent-cyan);
}

.commentary-body {
    font-size: 0.94rem;
    color: var(--text-secondary);
    line-height: 1.55;
}

.commentary-body p {
    margin-bottom: 10px;
}

.commentary-body p:last-child {
    margin-bottom: 0;
}

.commentary-headline {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 12px;
}

.commentary-placeholder {
    color: var(--text-muted);
    font-style: italic;
    font-size: 13px;
}

/* Kill switch badge */
.kill-switch-badge {
    border: 1px solid rgba(248, 113, 113, 0.3);
    background: rgba(248, 113, 113, 0.06);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    color: hsl(0, 84%, 70%);
    margin-bottom: 12px;
    line-height: 1.4;
}

.kill-switch-label {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.5px;
    margin-right: 6px;
}

/* ─── Raw Tape Panel ─── */
.legacy-tape {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', 'Monaco', monospace;
    font-size: 11px;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 480px;
    padding: 4px 0;
    tab-size: 4;
    letter-spacing: 0.02em;
}

.legacy-tape::-webkit-scrollbar { width: 4px; }
.legacy-tape::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.tape-header {
    display: block;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.3px;
    margin-top: 4px;
}

.tape-col-header {
    display: block;
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 1px solid rgba(102, 187, 224, 0.08);
    padding-bottom: 2px;
    margin-bottom: 2px;
}

.tape-pos { color: var(--positive); }
.tape-neg { color: var(--negative); }

/* ─── Compact Tables (Leaders / Laggards / Divergences) ─── */
.table-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.compact-table h4 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

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

.compact-table td {
    padding: 4px 4px;
    border-bottom: 1px solid rgba(30, 41, 59, 0.3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.compact-table td:first-child {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.compact-table td:last-child {
    text-align: right;
    font-weight: 500;
}

.compact-table tr {
    cursor: pointer;
    transition: background 0.1s;
}

.compact-table tr:hover {
    background: var(--bg-hover);
}

.compact-table .div-type {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    padding: 1px 5px;
    border-radius: 3px;
}

.compact-table .div-type.rebound {
    background: rgba(52, 211, 153, 0.12);
    color: var(--positive);
}

.compact-table .div-type.fatigue {
    background: rgba(248, 113, 113, 0.12);
    color: var(--negative);
}

/* ─── Regime Weather Heat Grid ─── */
.weather-board {
    padding: 4px 0;
}

.weather-header {
    display: grid;
    grid-template-columns: 60px repeat(4, 1fr);
    gap: 4px;
    margin-bottom: 4px;
}

.weather-header span {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    text-align: center;
    color: var(--text-muted);
}

.weather-header span:first-child {
    text-align: left;
}

.weather-row {
    display: grid;
    grid-template-columns: 60px repeat(4, 1fr);
    gap: 4px;
    margin-bottom: 3px;
}

.weather-row .weather-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
}

.weather-cell {
    text-align: center;
    padding: 6px 4px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.weather-cell.tone-pos {
    background: rgba(52, 211, 153, var(--cell-alpha, 0.15));
    color: var(--positive);
}

.weather-cell.tone-neg {
    background: rgba(248, 113, 113, var(--cell-alpha, 0.15));
    color: var(--negative);
}

.weather-cell.tone-neutral {
    background: rgba(148, 163, 184, 0.06);
    color: var(--text-muted);
}

/* ─── Rankings Section (full-width, collapsible) ─── */
.rankings-section {
    background: var(--panel-bg);
    border: 1px solid var(--panel-edge-soft);
    border-radius: 14px;
    overflow: hidden;
}

.rankings-collapse-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.rankings-collapse-header:hover {
    background: rgba(102, 187, 224, 0.04);
}

.rankings-collapse-header h2 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

.rankings-chevron {
    color: var(--text-muted);
    transition: transform 0.2s;
}

.rankings-section.collapsed .rankings-chevron {
    transform: rotate(180deg);
}

.rankings-section.collapsed #rankings-container {
    display: none;
}

#rankings-container {
    border-top: 1px solid var(--border);
}

/* Rankings market filter pills */
.rankings-market-pills {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.rankings-market-pills .rpill {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.rankings-market-pills .rpill:hover:not(.active) {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.rankings-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.rankings-search {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-page);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    width: 180px;
    outline: none;
    transition: border-color 0.15s;
    margin-left: auto;
}

.rankings-search:focus {
    border-color: var(--accent-cyan);
}

.rankings-search::placeholder {
    color: var(--text-muted);
}

.rankings-market-pills .rpill.active {
    border-color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.1);
    color: var(--accent-cyan);
    font-weight: 600;
}

/* ─── Active Market Banner ─── */
.active-market-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 20px;
    background: rgba(34, 211, 238, 0.08);
    border: 1px solid rgba(34, 211, 238, 0.2);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-cyan);
    letter-spacing: 0.3px;
}

.active-market-banner.hidden { display: none; }

.banner-clear {
    cursor: pointer;
    font-weight: 400;
    font-size: 12px;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.banner-clear:hover { opacity: 1; }

/* ─── Scope Badge (on Commentary / Raw Tape) ─── */
.scope-badge {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 10px;
    border-radius: 10px;
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-muted);
    white-space: nowrap;
}

.scope-badge.filtered {
    background: rgba(34, 211, 238, 0.12);
    color: var(--accent-cyan);
}

/* ─── Active Card Deselect Hint ─── */
.market-card.active::after {
    content: '\00d7 click to clear';
    position: absolute;
    top: 4px;
    right: 8px;
    font-size: 9px;
    color: var(--accent-cyan);
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}

.market-card.active:hover::after {
    opacity: 0.7;
}

.filter-indicator {
    padding: 8px 16px;
    background: rgba(34, 211, 238, 0.05);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: var(--accent-cyan);
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-indicator.hidden { display: none; }
.filter-clear {
    cursor: pointer;
    text-decoration: underline;
    opacity: 0.7;
}
.filter-clear:hover { opacity: 1; }

.table-wrapper {
    overflow-x: auto;
}

#rankings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

#rankings-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

#rankings-table th {
    padding: 10px 12px;
    text-align: right;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: hsl(220, 40%, 13%);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    user-select: none;
}

#rankings-table th.col-rank { text-align: center; width: 40px; }
#rankings-table th.col-market { text-align: center; width: 50px; }
#rankings-table th.col-name { text-align: left; min-width: 180px; }
#rankings-table th.col-stocks { text-align: center; width: 50px; }

#rankings-table th.sortable { cursor: pointer; }
#rankings-table th.sortable:hover { color: var(--text-primary); }
#rankings-table th.sort-active { color: var(--accent-cyan); }

#rankings-table th.sort-active::after {
    content: '';
    display: inline-block;
    margin-left: 4px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
}

#rankings-table th.sort-active.sort-desc::after {
    border-top: 5px solid var(--accent-cyan);
}

#rankings-table th.sort-active.sort-asc::after {
    border-bottom: 5px solid var(--accent-cyan);
}

#rankings-table td {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(30, 41, 59, 0.5);
    text-align: right;
    white-space: nowrap;
}

#rankings-table td.col-rank {
    text-align: center;
    color: var(--text-muted);
    font-size: 11px;
}

#rankings-table td.col-market {
    text-align: center;
    font-weight: 600;
    font-size: 11px;
}

#rankings-table td.col-name {
    text-align: left;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

#rankings-table td.col-stocks {
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
}

#rankings-table tbody tr {
    cursor: pointer;
    transition: background 0.1s;
}

#rankings-table tbody tr:hover {
    background: var(--bg-hover);
}

#rankings-table tbody tr.row-active {
    background: rgba(34, 211, 238, 0.05);
}

/* Top/bottom accent borders */
#rankings-table tbody tr.rank-top {
    border-left: 3px solid var(--positive);
}

#rankings-table tbody tr.rank-bottom {
    border-left: 3px solid var(--negative);
}

/* Return cell coloring */
.return-positive { color: var(--positive); }
.return-negative { color: var(--negative); }
.return-neutral { color: var(--text-muted); }

/* ─── Drawer — % width, scales with window ─── */
.drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: clamp(320px, 35vw, 500px);
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 200;
    transition: transform 0.25s ease;
    transform: translateX(100%);
    overflow-y: auto;
    padding: 0;
}

.drawer.open { transform: translateX(0); }

.drawer-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 190;
}

.drawer-overlay.open { display: block; }

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 5;
}

.drawer-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100% - 40px);
}

.drawer-close-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
}

.drawer-close-btn:hover { color: var(--text-primary); }

#drawer-content {
    padding: 16px 20px;
}

.drawer-section {
    margin-bottom: 20px;
}

.drawer-section h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.drawer-meta {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.meta-badge {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.meta-badge.quadrant-Leaders { background: rgba(52, 211, 153, 0.15); color: var(--quadrant-leaders); }
.meta-badge.quadrant-Fading { background: rgba(251, 191, 36, 0.15); color: var(--quadrant-fading); }
.meta-badge.quadrant-Recovering { background: rgba(96, 165, 250, 0.15); color: var(--quadrant-recovering); }
.meta-badge.quadrant-Laggards { background: rgba(248, 113, 113, 0.15); color: var(--quadrant-laggards); }

.drawer-returns {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.return-box {
    background: var(--bg-page);
    border-radius: 6px;
    padding: 8px;
    text-align: center;
}

.return-box .label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 2px;
}

.return-box .value {
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.member-list {
    list-style: none;
}

.member-list li {
    padding: 6px 0;
    border-bottom: 1px solid rgba(30, 41, 59, 0.3);
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.member-list li:last-child { border-bottom: none; }

.member-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.member-ticker {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

/* ─── Factor Score Badges ─── */
.score-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.score-badge {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.score-badge.score-high { background: rgba(52, 211, 153, 0.15); color: var(--positive); }
.score-badge.score-mid  { background: rgba(251, 191, 36, 0.12); color: hsl(38, 92%, 65%); }
.score-badge.score-low  { background: rgba(248, 113, 113, 0.12); color: hsl(0, 84%, 70%); }
.score-badge.score-na   { background: rgba(148, 163, 184, 0.08); color: var(--text-secondary); }

.scored-coverage {
    font-size: 11px;
    color: var(--text-muted);
}

/* ─── Member Scores Table ─── */
.member-scores-wrap { overflow-x: auto; }

.member-scores-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.member-scores-table th {
    padding: 6px 6px;
    text-align: right;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.member-scores-table th.mst-name,
.member-scores-table td.mst-name {
    text-align: left;
    min-width: 80px;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.member-scores-table td {
    padding: 5px 6px;
    text-align: right;
    border-bottom: 1px solid rgba(30, 41, 59, 0.3);
}

.member-scores-table td.score-high { color: var(--positive); }
.member-scores-table td.score-mid  { color: hsl(38, 92%, 65%); }
.member-scores-table td.score-low  { color: hsl(0, 84%, 70%); }
.member-scores-table td.score-na   { color: var(--text-secondary); }

/* ─── Drawer Footer Link ─── */
.drawer-footer {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    text-align: center;
}

.drawer-footer a {
    color: var(--accent-cyan);
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    opacity: 0.8;
    transition: opacity 0.15s;
}

.drawer-footer a:hover {
    opacity: 1;
    text-decoration: underline;
}

/* ─── Rotation Chart ─── */
.market-pills {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.rotation-view-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.market-pill {
    padding: 6px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.market-pill.active {
    border-color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.1);
    color: var(--accent-cyan);
}

.market-pill:hover:not(.active) {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

/* Rotation pills — tab-underline style, distinct from global filter pills */
.rotation-pills .market-pill {
    border: none;
    border-radius: 0;
    padding: 4px 12px 6px;
    border-bottom: 2px solid transparent;
    font-size: 12px;
}

.rotation-pills .market-pill.active {
    background: transparent;
    border-bottom-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.rotation-pills .market-pill:hover:not(.active) {
    background: transparent;
    border-bottom-color: var(--text-muted);
    color: var(--text-primary);
}

#rotation-chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    margin-bottom: 14px;
}

#rotation-chart {
    width: 100%;
    height: auto;
    min-height: 440px;
    max-height: 70vh;
}

.rotation-dot {
    cursor: pointer;
    transition: r 0.15s;
}

.rotation-dot:hover {
    filter: brightness(1.3);
}

.rotation-tooltip {
    position: fixed;
    background: hsl(220, 40%, 11%);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-primary);
    pointer-events: none;
    z-index: 9999;
    white-space: nowrap;
    display: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.quadrant-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 14px;
}

.quadrant-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    text-align: center;
}

.quadrant-card .q-name {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
}

.quadrant-card .q-count {
    font-size: 20px;
    font-weight: 700;
}

.quadrant-card .q-avg {
    font-size: 11px;
    color: var(--text-secondary);
}

.quadrant-card.Leaders .q-name { color: var(--quadrant-leaders); }
.quadrant-card.Fading .q-name { color: var(--quadrant-fading); }
.quadrant-card.Recovering .q-name { color: var(--quadrant-recovering); }
.quadrant-card.Laggards .q-name { color: var(--quadrant-laggards); }

#migration-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}

#migration-container h3 {
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

#migration-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

#migration-table th {
    padding: 8px 12px;
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

#migration-table td {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(30, 41, 59, 0.3);
}

.migration-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ─── Responsive ─── */

/* Tablet: single column, right col unsticks */
@media (max-width: 1120px) {
    .main-grid {
        grid-template-columns: 1fr;
    }

    .right-col {
        position: static;
        max-height: none;
        overflow-y: visible;
    }

    .legacy-tape {
        min-height: 200px;
    }

    .table-grid {
        grid-template-columns: 1fr;
    }

    #rotation-chart-container {
        max-width: 100%;
    }
}

/* Mobile landscape */
@media (max-width: 768px) {
    .topbar {
        flex-direction: column;
        gap: 8px;
        padding: 10px 16px;
    }

    nav { width: 100%; justify-content: center; }

    .chip {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .pulse-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .market-card.size-large {
        grid-column: span 1;
    }

    .quadrant-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .drawer {
        width: 100%;
        transform: translateX(100%);
    }

    #rankings-table td.col-name {
        max-width: 140px;
    }

    .app-shell {
        width: calc(100% - 20px);
    }

    .legacy-tape {
        min-height: 200px;
    }
}

/* Mobile portrait */
@media (max-width: 480px) {
    .pulse-grid {
        grid-template-columns: 1fr;
    }

    .app-shell {
        width: calc(100% - 14px);
    }
}
