/* ═══════════════════════════════════════════════════════
   History — Cinematic scene-card design
   ═══════════════════════════════════════════════════════ */

#historySection {
    display: flex;
    flex-direction: column;
    max-height: 55%;
    overflow: hidden;
    overflow-y: auto;
    overflow-x: hidden;
    transition: max-height var(--ease-medium);
    scrollbar-width: none;
}

#historySection.fold {
    max-height: 32px;
}

/* ── Header ── */

.history-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    cursor: pointer;
    user-select: none;
    gap: var(--gap-sm);
}

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

.history-header-left .history-icon {
    font-size: 0.7rem;
    opacity: 0.5;
    transition: transform var(--ease-fast);
    display: inline-flex;
}

#historySection.fold .history-icon {
    transform: rotate(-90deg);
}

.history-header-left .bold {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.45;
}

.history-count {
    font-size: 0.6rem;
    background: var(--color-accent);
    color: var(--color-text);
    padding: 1px 6px;
    border-radius: 10px;
    opacity: 0.7;
    font-weight: 600;
    line-height: 1.4;
}

#historyClearBtn {
    all: unset;
    cursor: pointer;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.3;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    transition: opacity var(--ease-fast), background-color var(--ease-fast), color var(--ease-fast);
}

#historyClearBtn:hover {
    opacity: 1;
    background-color: var(--color-danger);
    color: white;
}

/* ── List ── */

#historyList {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--color-muted) transparent;
    padding: 2px 0;
    max-width: 100%;
}

.history-empty {
    font-size: 0.72rem;
    opacity: 0.25;
    padding: 16px 0 8px;
    text-align: center;
    font-style: italic;
}

/* ── Scene card entry ── */

.history-item {
    all: unset;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    min-height: 42px;
    box-sizing: border-box;
    max-width: 100%;
    overflow: hidden;
    border-left: 2px solid transparent;
    transition:
        background-color var(--ease-fast),
        border-color var(--ease-fast),
        transform var(--ease-fast);
}

.history-item:hover {
    background-color: rgba(255, 255, 255, 0.04);
    border-left-color: var(--color-accent);
    transform: translateX(2px);
}

.history-item:active {
    transform: translateX(2px) scale(0.99);
}

/* Type indicator accent — YouTube gets purple, local gets warm */
.history-item[data-type="youtube"] {
    border-left-color: rgba(112, 63, 161, 0.3);
}

.history-item[data-type="youtube"]:hover {
    border-left-color: var(--color-accent);
}

.history-item[data-type="local"] {
    border-left-color: rgba(255, 255, 255, 0.06);
}

.history-item[data-type="local"]:hover {
    border-left-color: rgba(255, 255, 255, 0.2);
}

/* ── Thumbnail ── */

.history-thumb {
    width: 40px;
    height: 28px;
    min-width: 40px;
    border-radius: 4px;
    overflow: hidden;
    background-color: rgba(255, 255, 255, 0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
}

.history-thumb::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    pointer-events: none;
}

.history-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
    filter: brightness(0.9) contrast(1.05);
    transition: filter var(--ease-fast);
}

.history-item:hover .history-thumb img {
    filter: brightness(1) contrast(1.1);
}

.history-thumb-icon {
    font-size: 0.75rem;
    line-height: 1;
    opacity: 0.4;
}

/* ── Info column ── */

.history-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1 1 auto;
    min-width: 0;
    gap: 1px;
}

.history-title {
    font-size: 0.73rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.8;
    transition: opacity var(--ease-fast);
    letter-spacing: 0.01em;
}

.history-item:hover .history-title {
    opacity: 1;
}

.history-meta {
    font-size: 0.6rem;
    opacity: 0.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.02em;
}

.history-item:hover .history-meta {
    opacity: 0.5;
}

/* ── Type badge ── */

.history-type-badge {
    font-size: 0.52rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 1px 5px;
    border-radius: 3px;
    opacity: 0.5;
    flex-shrink: 0;
    font-weight: 600;
    line-height: 1.5;
}

.history-type-badge.yt {
    background: rgba(112, 63, 161, 0.25);
    color: #c9a0e8;
}

.history-type-badge.local {
    background: rgba(255, 255, 255, 0.06);
    color: var(--color-text);
}

/* ── Delete button ── */

.history-delete {
    all: unset;
    width: 18px;
    height: 18px;
    min-width: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    opacity: 0;
    cursor: pointer;
    border-radius: 50%;
    transition:
        opacity var(--ease-fast),
        background-color var(--ease-fast),
        color var(--ease-fast);
    color: var(--color-muted);
    line-height: 1;
    flex-shrink: 0;
}

.history-item:hover .history-delete {
    opacity: 0.4;
}

.history-delete:hover {
    opacity: 1 !important;
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--color-danger);
}

/* ── Nav collapsed — hide history ── */

.navContainerHidden #historySection {
    display: none !important;
}

/* ── Stagger entrance animation ── */

@keyframes historySlideIn {
    from {
        opacity: 0;
        transform: translateX(-6px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.history-item {
    animation: historySlideIn 200ms ease-out both;
}

.history-item:nth-child(1) { animation-delay: 0ms; }
.history-item:nth-child(2) { animation-delay: 30ms; }
.history-item:nth-child(3) { animation-delay: 60ms; }
.history-item:nth-child(4) { animation-delay: 90ms; }
.history-item:nth-child(5) { animation-delay: 120ms; }
.history-item:nth-child(n+6) { animation-delay: 150ms; }

/* ── Mobile touch targets ── */

@media (max-width: 768px) {
    .history-item {
        min-height: 48px;
        padding: 8px 10px;
        gap: 10px;
    }

    .history-thumb {
        width: 48px;
        height: 34px;
        min-width: 48px;
    }

    .history-title {
        font-size: 0.8rem;
    }

    .history-meta {
        font-size: 0.65rem;
    }

    .history-delete {
        width: 28px;
        height: 28px;
        min-width: 28px;
        opacity: 0.3;
    }

    #historyClearBtn {
        font-size: 0.65rem;
        padding: 4px 10px;
    }
}
