/* ====================================
   Global Header Styles
======================================= */

.global-header {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--color-background);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-md) 0;
    box-sizing: border-box;
}

.global-header-inner {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    gap: var(--space-md);
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 0 var(--space-lg);
    box-sizing: border-box;
}

.global-header-title {
    text-decoration: none;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
    min-width: 0;
    -webkit-flex: 1 1 auto;
    flex: 1 1 auto;
}

.global-header-title .global-header-title-text {
    /* Was an <h1>; the page's own heading is the only h1 now. Kept block so
       the mobile rule's overflow/text-overflow ellipsis still applies. */
    display: block;
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text-primary);
    transition: opacity var(--transition-base);
    line-height: 1.3;
    letter-spacing: -0.02em;
}

.global-header-title:hover .global-header-title-text {
    opacity: 0.8;
}

.global-header-controls {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: var(--space-md);
    -webkit-flex: 0 0 auto;
    flex: 0 0 auto;
    -webkit-flex-wrap: nowrap;
    flex-wrap: nowrap;
    min-width: 0;
    -webkit-justify-content: flex-end;
    justify-content: flex-end;
    box-sizing: border-box;
}

/* Search container in global header — flex row so mobile cancel stays inline when shown */
.global-header .search-container {
    -webkit-flex: 0 1 320px;
    flex: 0 1 320px;
    min-width: 180px;
    box-sizing: border-box;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: row;
    flex-direction: row;
    -webkit-align-items: center;
    align-items: center;
    gap: var(--space-xs);
}

.global-header .search-box {
    -webkit-flex: 1;
    flex: 1;
    min-width: 0;
    height: var(--form-control-height);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    background: var(--color-surface);
    box-sizing: border-box;
    transition: border-color var(--transition-base);
}

.global-header .search-box:focus-within {
    border-color: var(--color-text-secondary);
}

/* Match search field type scale */
.global-header .search-input {
    padding-top: 0;
    padding-bottom: 0;
    height: 100%;
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Global Navigation */
.global-nav {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: var(--space-sm);
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}

.global-nav-link {
    display: -webkit-inline-flex;
    display: inline-flex;
    -webkit-align-items: center;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--border-radius-md);
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--transition-base), color var(--transition-base);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.4;
    box-sizing: border-box;
    /* Cross-browser resets */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.global-nav-link i {
    font-size: 1rem;
    line-height: 1;
}

.global-nav-link:hover {
    background: var(--color-surface-alt);
    color: var(--color-text-primary);
}

.global-nav-link.active,
.global-nav-link[aria-current="page"] {
    background: var(--color-surface-alt);
    color: var(--color-text-primary);
}

/* Global search results wrapper */
.global-search-results-wrapper {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

.global-search-results-wrapper .episodes-list {
    margin-top: var(--space-md);
}

/* Index page specific controls */
.index-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
}

.index-controls .update-form {
    margin: 0;
    order: -1;
}

.index-controls .sorting-controls {
    margin-left: auto;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .global-header {
        padding: var(--space-sm) 0;
    }
    
    .global-header-inner {
        gap: var(--space-sm);
        padding: 0 var(--space-md);
    }
    
    .global-header-title .global-header-title-text {
        font-size: 1.25rem;
    }
    
    .global-header-controls {
        gap: var(--space-sm);
    }
    
    .global-header .search-container {
        flex: 1;
        min-width: 120px;
        max-width: none;
    }
    
    .global-nav {
        gap: 4px;
    }
    
    /* Hide labels on tablet for nav links */
    .global-nav-link span {
        display: none;
    }
    
    .global-nav-link {
        padding: 8px;
    }

    .global-nav-link i {
        font-size: 1rem;
    }
}

@media (max-width: 768px) {
    .global-search-results-wrapper {
        padding: 0 var(--space-md);
    }
}

@media (max-width: 480px) {
    .global-header-inner {
        padding-left: max(var(--space-md), var(--safe-area-left));
        padding-right: max(var(--space-md), var(--safe-area-right));
    }

    .global-header-title .global-header-title-text {
        font-size: 1.25rem;
    }

    .global-header .search-container {
        min-width: 100px;
    }

    .global-search-results-wrapper {
        padding: 0 var(--space-md);
    }
}

/* ====================================
   Mobile: Hide top nav links, show bottom tab bar
======================================= */
@media (max-width: 767px) {
    .global-header {
        padding-top: var(--safe-area-top);
        padding-bottom: 0;
    }

    .global-header-inner {
        position: relative;
        min-height: 56px;
        gap: var(--space-sm);
        padding-left: max(var(--space-md), var(--safe-area-left));
        padding-right: max(var(--space-md), var(--safe-area-right));
        -webkit-align-items: center;
        align-items: center;
    }

    .global-header-title .global-header-title-text {
        font-size: 1.25rem;
        line-height: 1.2;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Hide nav links from top bar — they move to bottom tab bar */
    .global-nav-link {
        display: none;
    }

    /* Compact action with label */
    .global-nav {
        gap: 0;
        -webkit-flex-shrink: 0;
        flex-shrink: 0;
    }

    /* Hide search from header on mobile — moved to bottom tab bar trigger */
    .global-header .search-container {
        display: none;
    }

    /* When search is activated via bottom tab, show it as an overlay in the header */
    .global-header .search-container.search-focused {
        display: flex;
    }
}

/* ====================================
   Mobile Search Expand-on-Focus
   Cancel is [hidden] on desktop; never takes a second row in the header bar.
======================================= */

.global-header .search-cancel[hidden] {
    display: none !important;
}

@media (max-width: 767px) {
    .global-header .search-cancel {
        background: none;
        border: none;
        color: var(--color-text-primary);
        font-size: 0.9rem;
        font-weight: 500;
        padding: 0 var(--space-xs);
        cursor: pointer;
        white-space: nowrap;
        -webkit-flex-shrink: 0;
        flex-shrink: 0;
        min-height: var(--touch-target-min);
        -webkit-align-items: center;
        align-items: center;
        -webkit-appearance: none;
        appearance: none;
        font-family: inherit;
    }

    /* When visible (no [hidden]), sit inline with the field */
    .global-header .search-cancel:not([hidden]) {
        display: -webkit-inline-flex !important;
        display: inline-flex !important;
    }

    /* Push header content down to make room for the search row above the title */
    .global-header-inner:has(.search-container.search-focused) {
        padding-top: 48px;
    }

    .global-header .search-container.search-focused {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        z-index: 10;
        display: -webkit-flex;
        display: flex;
        gap: var(--space-xs);
        -webkit-align-items: center;
        align-items: center;
        max-width: none;
        min-width: 0;
        height: 44px;
        padding: 0 var(--space-md);
        box-sizing: border-box;
    }

    .global-header .search-container.search-focused .search-box {
        -webkit-flex: 1;
        flex: 1;
        min-width: 0;
    }
}

@media (max-width: 480px) {
    .global-header .search-container.search-focused {
        padding-left: max(var(--space-md), var(--safe-area-left));
        padding-right: max(var(--space-md), var(--safe-area-right));
    }
}

/* ====================================
   Bottom Tab Bar
======================================= */
.bottom-tab-bar {
    display: none;
}

@media (max-width: 767px) {
    .bottom-tab-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1001;
        height: var(--bottom-nav-height);
        padding-bottom: var(--safe-area-bottom);
        background: var(--color-surface);
        border-top: 1px solid var(--color-border);
        box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.06);
        align-items: stretch;
        justify-content: space-around;
    }

    .bottom-tab {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        gap: 2px;
        padding: 6px 0;
        color: var(--color-text-tertiary);
        text-decoration: none;
        font-size: 0.65rem;
        font-weight: 500;
        transition: color var(--transition-base), transform 280ms var(--ease-out);
        -webkit-tap-highlight-color: transparent;
        min-width: 0;
        position: relative;
    }

    .bottom-tab i {
        font-size: 1.15rem;
        line-height: 1;
    }

    .bottom-tab span {
        line-height: 1;
        white-space: nowrap;
    }

    .bottom-tab:hover,
    .bottom-tab.active,
    .bottom-tab[aria-current="page"] {
        color: var(--color-text-primary);
    }

    .bottom-tab.active,
    .bottom-tab[aria-current="page"] {
        font-weight: 600;
    }

    .bottom-tab.active::before,
    .bottom-tab[aria-current="page"]::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 24px;
        height: 2px;
        background: var(--color-text-primary);
        border-radius: 0 0 2px 2px;
    }

    /* Press: fast down, springy release */
    .bottom-tab:active {
        transform: scale(0.88);
        transition: transform 50ms ease-out;
    }
}

@media (max-width: 767px) and (prefers-color-scheme: dark) {
    .bottom-tab-bar {
        background: var(--color-dark-surface);
        border-color: var(--color-dark-border);
        box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.3);
    }
}



/* ====================================
   Desktop Navigation Rail
   Replaces the global header >=769px; mobile keeps the slim top
   header + bottom tab bar untouched.
======================================= */

.nav-rail {
    display: none;
}

@media (min-width: 769px) {
    .nav-rail {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--nav-rail-width);
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        padding: 14px 0 16px;
        background: var(--color-surface);
        border-right: 1px solid var(--color-border);
        z-index: 100;
        box-sizing: border-box;
    }

    /* Keep the bottom rail item clear of the fixed audio player. */
    body:has(.nts-audio-player.visible) .nav-rail,
    body:has(.youtube-player.visible) .nav-rail {
        padding-bottom: calc(var(--nts-player-offset) + 16px);
    }

    .nav-rail-logo {
        width: 34px;
        height: 34px;
        border-radius: 9px;
        background: var(--color-text-primary);
        color: var(--color-surface);
        font-weight: 800;
        font-size: 15px;
        line-height: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 14px;
        text-decoration: none;
        flex-shrink: 0;
        transition: transform var(--duration-fast) var(--ease-out);
    }

    .nav-rail-logo:hover {
        transform: scale(1.06);
    }

    .nav-rail-link {
        width: 52px;
        padding: 8px 0 7px;
        border-radius: var(--border-radius-lg);
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        color: var(--color-text-tertiary, var(--color-text-secondary));
        text-decoration: none;
        flex-shrink: 0;
        transition: background-color var(--transition-base), color var(--transition-base);
    }

    .nav-rail-link i {
        font-size: 17px;
    }

    .nav-rail-link span {
        font-size: 9px;
        font-weight: 600;
        letter-spacing: 0.02em;
    }

    .nav-rail-link:hover,
    .nav-rail-link.active,
    .nav-rail-link[aria-current="page"] {
        color: var(--color-text-primary);
        background: var(--color-surface-alt);
    }

    /* The keyboard-shortcuts button wears the link styling. */
    button.nav-rail-link {
        margin: 0;
        border: none;
        background: none;
        font: inherit;
        cursor: pointer;
    }

    .nav-rail-spacer {
        flex: 1 1 auto;
    }

    /* The rail owns primary navigation on desktop. */
    .global-header {
        display: none;
    }

    #page-content {
        margin-left: var(--nav-rail-width);
    }

    /* No sticky header above the content anymore — sticky page elements
     * (tracklist headers etc.) anchor to the viewport top. */
    :root {
        --global-header-sticky-offset: var(--safe-area-top);
    }
}
