/* Navigation Styles */
.top-nav, .bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    background: rgba(255,255,255,0.98);
    backdrop-filter: blur(10px);
    padding: 1rem 2rem;
    transform: translateY(-100%);
    transition: all 0.4s ease;
    z-index: 9999;
    box-shadow: 0 2px 20px rgba(0,0,0,0.1);
}

.bottom-nav {
    bottom: 0;
    top: auto;
    transform: translateY(100%);
}

.nav-visible .top-nav {
    transform: translateY(0);
}

.nav-visible .bottom-nav {
    transform: translateY(0);
}

.top-nav {
    display: flex;
    align-items: center;
    justify-content: flex-start; /* Align items to left side */
    top: 0;
    padding: 1rem; /* Proper padding for header height */
    width: 100%;
    min-height: 60px; /* Ensure adequate header height */
    gap: 1rem; /* Space between back button and title */
}

.back-button {
    background: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--card-border);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: var(--card-deck-font-body);
    font-size: 0.875rem;
    transition: all 0.15s ease;
    min-width: 120px; /* Match Previous button width */
    height: 40px; /* Match Previous button height */
    z-index: 15; /* Higher than show title */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0; /* Prevent shrinking */
    user-select: none; /* Prevent text selection */
}

.back-button:hover {
    background: var(--neutral-200);
}

.show-title {
    font-family: var(--card-deck-font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--section-heading);
    text-align: center;
    /* Center in entire viewport, not just remaining space */
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 10; /* Below back button */
    max-width: 85vw; /* Much wider constraint for better mobile experience */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    user-select: none; /* Prevent text selection */
}

.bottom-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
}

.bottom-nav-container {
    display: flex;
    align-items: center;
    gap: 2rem;
    background: rgba(255, 255, 255, 0.95);
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px);
}

.nav-button {
    min-width: 120px;
    height: 40px;
    border-radius: 20px;
    border: none;
    background: var(--footer-bg);
    color: var(--footer-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0 1rem;
    white-space: nowrap;
    transition: all 200ms ease;
}

.nav-button:hover:not(:disabled) {
    filter: brightness(1.1);
}

.nav-button:disabled {
    background: var(--neutral-400);
    cursor: not-allowed;
    opacity: 0.5;
}

.card-counter {
    font-size: 1rem;
    font-weight: 700;
    color: var(--section-heading);
}

/* Universal Index System */
.index-system {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 500; /* Below navigation (9999) but above cards */
    display: none;
}

/* Show index system only during reference browsing */
.nav-visible .index-system {
    display: block;
}

/* Index Tab - Always visible peek-out, attaches to side-sheet right edge */
.index-tab {
    position: absolute;
    top: 80px; /* Below back button location */
    left: 0; /* Default position when side-sheet closed */
    width: 40px;
    height: 120px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-left: none;
    border-radius: 0 8px 8px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94); /* Match side-sheet transition */
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    z-index: 502; /* Above side-sheet */
}

/* When side-sheet is active, move index tab to right edge and show active state */
.index-system.side-sheet-open .index-tab {
    left: 380px; /* Width of side-sheet */
    border-left: 1px solid var(--footer-bg);
    border-right: none;
    border-radius: 0 8px 8px 0; /* Keep corners on right side consistently */
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    background: var(--footer-bg); /* Active state background */
}

/* Active state text color */
.index-system.side-sheet-open .index-tab .index-tab-text {
    color: white;
    font-weight: 600;
}

/* Default hover state (when not active) */
.index-tab:hover:not(.index-system.side-sheet-open .index-tab) {
    background: var(--card-bg-hover);
    transform: translateX(4px); /* Move right when on left edge */
}

/* Active hover state (when side-sheet is open) */
.index-system.side-sheet-open .index-tab:hover {
    filter: brightness(1.1);
    transform: translateX(-4px); /* Move left when on right edge */
}

.index-tab-text {
    writing-mode: vertical-lr;
    text-orientation: mixed;
    font-family: var(--card-deck-font-body);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 2px;
    user-select: none;
}

/* Side-Sheet - Slides from behind card */
.index-side-sheet {
    position: absolute;
    top: 80px; /* Match index tab position */
    bottom: 100px; /* Above footer navigation */
    left: -400px; /* Hidden by default */
    width: 380px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-left: none;
    border-radius: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    pointer-events: auto;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    z-index: 500; /* Behind cards */
    display: flex;
    flex-direction: column;
}

.index-side-sheet.active {
    left: 0;
}

.side-sheet-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--quote-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--quote-bg-start) 0%, var(--quote-bg-end) 100%);
    border-radius: 0 12px 0 0;
}

.side-sheet-title {
    font-family: var(--card-deck-font-heading);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.side-sheet-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.side-sheet-close:hover {
    background: var(--card-bg-hover);
    color: var(--text-primary);
}

.side-sheet-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

/* Index List Styles */
.index-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.index-item {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--card-border);
    cursor: pointer;
    transition: all 0.15s ease;
}

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

.index-item:last-child {
    border-bottom: none;
}

.index-item.active {
    background: var(--footer-bg);
    color: white;
    font-weight: 600;
}

.index-item.active .index-item-title,
.index-item.active .index-item-subtitle {
    color: white;
}

.index-item-title {
    font-family: var(--card-deck-font-body);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.index-item-subtitle {
    font-family: var(--card-deck-font-body);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Desktop default-open behavior */
@media (min-width: 1200px) {
    /* Auto-open side-sheet on large desktop screens when space allows */
    .index-system.desktop-auto-open .index-side-sheet {
        left: 0;
    }

    .index-system.desktop-auto-open .index-tab {
        left: 380px; /* Width of side-sheet */
        border-left: 1px solid var(--card-border);
        border-right: none;
        border-radius: 8px 0 0 8px;
        box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .index-side-sheet {
        left: -100vw;
        width: 100vw;
        border-radius: 0;
        border: none;
        border-top: 1px solid var(--card-border);
    }

    .index-side-sheet.active {
        left: 0;
    }

    .side-sheet-header {
        border-radius: 0;
    }

    /* Fix INDEX tab transparency issue on mobile after manual close */
    .index-tab {
        background: var(--card-bg) !important;
        width: auto; /* Auto width to accommodate "INDEX - X results" text */
        min-width: 24px; /* Minimum width for collapsed state */
        height: auto; /* Allow dynamic height for longer text content */
        min-height: 80px; /* Minimum height for basic visibility */
        padding: 0.5rem 0.25rem; /* Add horizontal padding for text */
    }

    /* Adjust INDEX tab text layout for mobile */
    .index-tab-text {
        writing-mode: vertical-lr; /* Rotate text 90 degrees to flow down the page */
        text-orientation: mixed;
        font-size: 0.65rem; /* Smaller font for mobile */
        font-weight: 600;
        letter-spacing: 1px; /* Reduce letter spacing */
        line-height: 1.2;
        text-align: center;
        white-space: nowrap; /* Prevent text wrapping - let tab grow taller instead */
    }

    /* Hide INDEX tab on mobile when side-sheet is open to save space */
    .index-system.side-sheet-open .index-tab {
        display: none;
    }

    /* Fix navigation text overflow on mobile - keep single line */
    .top-nav {
        flex-wrap: nowrap;
        align-items: center;
        padding: 0.75rem;
        min-height: 60px;
        gap: 0.5rem;
    }

    /* Hide results count on mobile - it will be shown in INDEX tab instead */
    .top-nav .results-count {
        display: none !important;
    }

    .show-title {
        flex: 1;
        min-width: 0; /* Allow flex item to shrink */
        font-size: 0.9rem; /* Smaller text on mobile */
        line-height: 1.3;
        text-align: center;
        max-width: none; /* Remove the 85vw constraint for better space usage */
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .search-query-display {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .search-filters-applied {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem;
        margin-top: 0.25rem;
    }

    .filter-chip {
        font-size: 0.8rem;
        padding: 0.15rem 0.5rem;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}