/*
layout.css
Role: gallery and app-shell layout styles.
Responsibility: reader shell, source rail, and shared content containers.
Note: Modify only from the latest local file.
*/
.reader-shell {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: var(--rail-width, 220px) 10px minmax(0, 1fr);
    gap: 0;
    align-items: stretch;
    padding-left: var(--space-sm);
}

.source-rail {
    position: sticky;
    top: 0;
    align-self: stretch;
    min-height: 0;
}

.rail-panel {
    --rail-indent: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 0;
    box-sizing: border-box;
}

.rail-section {
    padding-bottom: 0;
}

.rail-section:not(.is-collapsed) {
    padding-bottom: var(--space-sm);
}

.rail-section + .rail-section {
    margin-top: 2px;
}

.source-rail-inner {
    padding: var(--space-sm) 0;
    height: 100%;
    max-height: none;
}

.source-rail-actions {
    margin-bottom: var(--space-sm);
    text-align: center;
}

.source-rail-digest-row {
    padding: 0 var(--space-sm);
}

.source-rail-digest-row + .rail-section {
    margin-top: var(--space-sm);
}

.source-tree-link.mode-pill.is-active {
    clip-path: none;
}

.source-tree-link.mode-pill {
    display: inline-flex;
    width: 100%;
    justify-content: space-between;
    border: 1px solid var(--border);
    border-left: 1px solid var(--border);
    padding: 9px 8px;
}

.source-tree-digest-count {
    font-weight: 400;
    letter-spacing: 0;
    opacity: 0.7;
    min-width: 1em;
    text-align: right;
}

.source-rail-refresh-row {
    text-align: center;
    border-top: 1px solid var(--border);
    margin-top: 8px;
    padding-top: 3px;
    padding-bottom: 0;
}

.source-rail-refresh-link[hidden] {
    display: none !important;
}

.source-rail-refresh-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
    font: inherit;
    font-size: var(--text-meta);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    padding: 4px var(--space-sm);
    border-radius: var(--radius-sm);
    transition: color 0.12s ease, background 0.12s ease;
}

.source-rail-refresh-link::before {
    content: '↻';
    display: inline-block;
}

.source-rail-refresh-link.is-refreshing::before {
    animation: refresh-spin 0.7s linear infinite;
}

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

.source-rail-refresh-link.has-updates {
    color: var(--link-text, #5a8dee);
    animation: rail-refresh-pulse 2s ease-in-out infinite;
}

.source-rail-refresh-link.has-updates:hover {
    animation: none;
    color: var(--text);
    background: var(--link-bg);
}

@keyframes rail-refresh-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.45; }
}

@keyframes signalEngineModeLoad {
    0%   { transform: translateX(-120%); }
    100% { transform: translateX(360%); }
}

.source-rail-refresh-link:hover {
    color: var(--text);
    background: var(--link-bg);
}

.source-tree {
    display: grid;
    gap: 0;
}

.source-tree-all-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    align-items: center;
}

.source-tree-all-link {
    background: var(--button-bg);
    color: var(--button-text);
}

.source-tree-group {
    display: grid;
    gap: 6px;
    padding-top: 5px;
    padding-left: 12px;
}

.source-tree-parent-group {
    padding-left: 0;
}

.source-tree-parent-group > .source-tree-children > .source-tree-group {
    padding-left: 0;
}

.source-tree-group:first-of-type {
    padding-top: 0;
}

.source-tree-group-row {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 3px;
    align-items: center;
    position: relative;
}


/* Shared base for all rail filter/nav items */
.rail-item,
.source-tree-link {
    width: 100%;
    padding: 5px 12px 5px var(--rail-indent, 10px);
    font: inherit;
    border: none;
    border-left: 2px solid transparent;
    background: transparent;
    cursor: pointer;
    text-align: left;
    box-sizing: border-box;
    align-items: center;
}

/* Articles-specific rail item */
.source-tree-link {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-sm);
    color: var(--text);
    font-size: var(--text-ui);
}

.source-tree-link:hover {
    background: var(--link-bg);
    color: var(--link-text);
}

.source-tree-link.is-active {
    background: color-mix(in srgb, var(--link-bg) 55%, transparent 45%);
    color: var(--link-text);
    border-left-color: var(--border-accent);
}

.source-tree-link-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.source-tree-link-sublabel {
    font-size: 0.78em;
    font-weight: 400;
    /* intentional em unit — scales relative to parent source-tree-link size */
    opacity: 0.6;
}

/* First grid cell wrapper: holds the (ellipsis-clipping) label + the optional private lock so
   they share ONE grid track — keeps the row a 2-column grid (label | count) and the lock rides
   at the end of the name without forcing the count to wrap. */
.source-tree-link-main {
    min-width: 0;
    display: flex;
    align-items: center;
}
/* Private-source badge — small muted lock after the label on viewer-gated (non-public) sources. */
.source-tree-private {
    flex: 0 0 auto;
    margin-left: 4px;
    font-size: 0.7em;
    opacity: 0.55;
    line-height: 1;
    cursor: default;
}

.source-tree-count {
    min-width: 1.5em;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.source-tree-link.is-active .source-tree-link-label,
.source-tree-link:hover .source-tree-link-label {
    color: inherit;
}

.source-tree-link.is-active .source-tree-count,
.source-tree-link:hover .source-tree-count {
    color: inherit;
}

.source-tree-all-link,
.source-tree-group-link {
    font-weight: 600;
}

.source-tree-children {
    display: grid;
    gap: 0;
}

.source-tree-children[hidden],
.source-tree-group.is-collapsed .source-tree-children,
[data-group-children][hidden],
.rail-section.is-collapsed [data-group-children] {
    display: none !important;
}

.source-tree-source-link {
    font-size: var(--text-base);
    color: var(--muted);
    width: 100%;
    justify-self: stretch;
    padding-left: 11px;
}

.source-tree-source-link.is-active {
    color: var(--button-text);
}

.source-tree-group-link {
    background: transparent;
    box-shadow: none;
}

.source-tree-subgroup-link {
    width: 100%;
    justify-self: stretch;
    font-size: var(--text-base);
    color: var(--text-soft);
    background: transparent;
}

.source-tree-subchildren {
    display: grid;
    gap: 0;
}

.source-tree-live-source-row {
    display: flex;
    align-items: center;
    transition: background 0.12s ease, color 0.12s ease;
}

.source-tree-live-source-row[hidden] {
    display: none !important;
}

.source-tree-live-source-row:hover {
    background: var(--link-bg);
    color: var(--link-text);
}

.source-tree-live-source-row:has(.source-tree-live-source-link.is-active) {
    background: color-mix(in srgb, var(--link-bg) 55%, transparent 45%);
    color: var(--link-text);
    border-left: 2px solid var(--border-accent);
}

.source-tree-live-source-link {
    font-size: var(--text-base);
    color: var(--muted);
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    justify-self: stretch;
    padding-left: 11px;
}

.source-tree-live-source-link:hover,
.source-tree-live-source-link.is-active {
    background: transparent;
    color: inherit;
    border-left-color: transparent;
}

.source-tree-live-fav-btn {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.95rem;
    padding: 0;
    color: var(--muted);
    opacity: 0.2;
    transition: opacity 0.15s, color 0.15s, transform 0.12s;
    border-radius: var(--radius-sm);
    line-height: 1;
}

.source-tree-live-source-row:hover .source-tree-live-fav-btn {
    opacity: 0.75;
}

.source-tree-live-fav-btn.is-favorite {
    opacity: 1;
    color: #e8a020;
}

.source-tree-live-fav-btn:hover {
    transform: scale(1.18);
}

.source-tree-live-source-label {
    display: block;
    width: 100%;
    padding: 7px 9px;
    font-size: var(--text-base);
    color: var(--muted);
    cursor: default;
    user-select: none;
}

/* Local News per-state filter (built by tv.js initLocalStateFilter) */
.rail-state-filter {
    position: relative;
    margin: var(--space-xs) 0;
    padding: 0 9px;
}

/* The state-filter toggle IS a collapsible section header — it carries the `section-header`
   class and reuses `.rail-section-chevron`, inheriting size/spacing/chevron/height/shadow-reset.
   Only the deltas from a full-width header are declared here: it's nested (narrower, with a
   border + radius like a popover trigger) and intentionally LIGHTER weight + sentence-case to
   read as a control rather than a section label. Keep this list minimal — do NOT re-copy header
   properties; fix the base `.section-header` instead. */
.rail-state-filter-toggle.section-header {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    border-bottom: 1px solid var(--border);  /* override section-header's accent bottom-border */
    font-weight: 400;                        /* lighter than the 500 group headers — deliberate (reads as a control) */
    text-transform: none;
    letter-spacing: normal;
    color: var(--text);
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.rail-state-filter-toggle.section-header:hover {
    border-color: var(--border-accent);
}

/* Collapsible rotate: chevron points down when open (aria-expanded=true), right when closed. */
.rail-state-filter-toggle[aria-expanded="false"] .rail-section-chevron {
    transform: rotate(-90deg) scale(2);
}

.rail-state-filter-panel {
    position: absolute;
    left: 9px;
    right: 9px;
    top: calc(100% + 2px);
    z-index: 30;
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden;          /* states never need horizontal scroll — kills the stray h-scrollbar */
    box-sizing: border-box;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    /* Horizontal is the standard space-sm inset (unchanged); only the vertical is kept tight so
       options sit close together with no dead gap above the first row. */
    padding: 4px var(--space-sm);
}

.rail-state-option {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    /* Vertical kept tight (rows close together); horizontal is the standard space-sm inset. */
    padding: 4px var(--space-sm);
    font-size: var(--text-sm);
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: none;
    background: transparent;
    text-align: left;
}

.rail-state-option:hover {
    background: var(--link-bg);
}

.rail-state-option input {
    flex: 0 0 auto;
    margin: 0;
    cursor: pointer;
}

.rail-state-option-count {
    margin-left: auto;
    color: var(--muted);
    font-size: var(--text-sm);
}

/* "All Selected" rail row — directly below the state dropdown; plays the union of checked states.
   Hidden (JS toggles [hidden]) until a selection exists. */
.rail-all-selected[hidden] {
    display: none !important;
}

.rail-all-selected {
    font-weight: 600;
}

.rail-state-filter-empty {
    padding: var(--space-sm);
    font-size: var(--text-sm);
    color: var(--muted);
    font-style: italic;
}

/* State filter hides non-live (Videos RSS) Local rows by toggling [hidden] on the link button. */
.source-tree-source-link[data-state-title][hidden] {
    display: none !important;
}

.source-tree-parent-link {
    background: var(--button-bg);
    color: var(--button-text);
    font-weight: 600;
}

.source-tree-parent-link:hover {
    background: var(--button-bg-hover);
    color: var(--button-text);
}

.source-tree-parent-link.is-active {
    background: var(--button-bg-hover);
    color: var(--button-text);
}

.source-tree-parent-group + .source-tree-parent-group {
    margin-top: 3px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}




.reader-content,
.debug-content {
    min-width: 0;
    min-height: 0;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: var(--space-sm);
    padding-top: var(--space-sm);
    padding-bottom: var(--space-md);
    flex: 1 1 auto;
}

.reader-content-shell {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

body.modal-open .reader-content,
body.modal-open .signal-shell {
    overflow: hidden !important;
}

.view-shell-header {
    margin-bottom: 16px;
    padding: 4px 4px 2px 0;
    text-align: center;
}

.view-shell-title {
    margin: 0;
    font-size: clamp(1.45rem, 1.15rem + 0.82vw, 2.05rem);
    line-height: 1.08;
}

.debug-view-shell {
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    overflow-y: auto;
}

.debug-content {
    flex: 1 1 auto;
    padding-left: var(--space-sm);
}

.debug-link-row {
    margin-bottom: var(--space-sm);
}

.queue-resize-handle,
.source-rail-divider {
    cursor: col-resize;
    align-self: stretch;
    position: relative;
}

.queue-resize-handle::after,
.source-rail-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 80px;
    border-radius: var(--radius-sm);
    background: var(--border);
    transition: background-color 120ms ease;
}

.queue-resize-handle:hover::after,
.source-rail-divider:hover::after {
    background: var(--border-accent);
}

body.queue-resizing {
    cursor: col-resize !important;
    user-select: none !important;
}

.source-tree-link.is-stream-dead .source-tree-link-label::after {
    content: " ⚠";
    font-size: 0.72em;
    color: #d97706;
    vertical-align: middle;
}

/* ── Shared section header utilities ────────────────────────
   Canonical pattern for any labeled section divider row.
   .section-hd       all-caps label; flex row, space-between
   .section-hd-note  right-side companion: inherits font size,
                     resets caps/letter-spacing, slightly muted
─────────────────────────────────────────────────────────── */
.section-hd {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--muted);
}

.section-hd-note {
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    color: var(--muted-2);
    margin-left: auto;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    padding: 5px 12px 5px var(--rail-indent, 10px);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 500;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--muted);
    background: color-mix(in srgb, var(--border) 55%, var(--panel-soft) 45%);
    border: none;
    border-bottom: 1px solid var(--border);
    box-sizing: border-box;
    gap: 8px;
    text-shadow: var(--text-shadow-header);
    box-shadow: var(--shadow-header);
}

.section-header:hover {
    color: var(--text);
    background: color-mix(in srgb, var(--border) 70%, var(--panel-soft) 30%);
}

[data-group-node]:has([data-group-children] .is-active) > .section-header {
    border-left: 2px solid var(--border-accent);
    color: var(--text);
}

.rail-section-chevron {
    display: inline-block;
    flex-shrink: 0;
    font-size: var(--text-ui);
    line-height: 1;
    margin: 0 var(--space-xs) 0 0;
    transform: scale(2);
    transform-origin: center center;
    transition: transform 0.15s ease;
    /* The header text-shadow (a double white+dark shadow) smears the 2×-scaled glyph into a
       ghosted/doubled look. Reset it here so the chevron stays crisp; the header TEXT keeps its shadow. */
    text-shadow: none;
}

[data-group-node].is-collapsed .rail-section-chevron {
    transform: rotate(-90deg) scale(2);
}


/* ── Tab bar component ───────────────────────────────────────────────
   Generic raised-card tab navigation. Use .tab-bar + .tab + .tab-panel.
   .tab-export-row / .tab-export-btn for inline export link rows.
   .tab-panel-loading / .tab-panel-error for panel state messages.
─────────────────────────────────────────────────────────────────── */


.tab-panel {
    padding: var(--space-sm) 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 var(--radius) var(--radius) var(--radius);
    margin-bottom: var(--space-md);
}

.tab-export-row {
    display: flex;
    gap: var(--space-md);
    align-items: center;
    flex-wrap: wrap;
    padding: var(--space-xs) 0 var(--space-sm);
    margin-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border);
}

.tab-export-btn {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
}

.tab-export-btn:hover {
    color: var(--link-text);
    text-decoration: underline;
}

.tab-panel-loading {
    padding: var(--space-lg) 0;
    color: var(--muted);
    font-size: var(--text-ui);
}

.tab-panel-error {
    padding: var(--space-sm) var(--space-md);
    background: var(--warning-bg);
    color: var(--warning-text);
    border-radius: var(--radius);
    font-size: var(--text-ui);
    margin-bottom: var(--space-sm);
}

/* ── Mode content loading placeholder ──────────────────────────────────────
   Shown immediately after shell paint while async content is in flight.
   Each mode's JS hides it once content (or an error) is ready.
─────────────────────────────────────────────────────────────────────────── */
.mode-content-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--muted);
    font-size: var(--text-ui);
    gap: var(--space-xs);
}

.mode-content-loading::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--muted);
    border-radius: 50%;
    animation: chart-spin 0.7s linear infinite;
    flex-shrink: 0;
}

.mode-content-loading[hidden] { display: none !important; }

