/* ========================================
   History Panel - Seamless Sliding Panel
======================================== */

/* History Toggle Button - Defined in layout.css */

/* History Panel Overlay */
.history-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
    z-index: 998;
}

.history-overlay.visible {
    opacity: 1;
    visibility: visible;
}

[data-theme="dark"] .history-overlay {
    background: rgba(0, 0, 0, 0.6);
}

/* ========================================
   History Panel
======================================== */
.history-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    max-width: 100vw;
    background: var(--bg-primary);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
}

[data-theme="dark"] .history-panel {
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
}

.history-panel.open {
    transform: translateX(0);
}

/* ========================================
   Panel Header
======================================== */
.history-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5) var(--space-6);
    flex-shrink: 0;
}

.history-panel-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.02em;
}

.history-close-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.history-close-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.history-close-btn svg {
    width: 20px;
    height: 20px;
}

/* ========================================
   Panel Tabs
======================================== */
.history-tabs {
    display: flex;
    gap: var(--space-1);
    padding: 0 var(--space-5);
    padding-bottom: var(--space-3);
}

.history-tab {
    flex: 1;
    padding: var(--space-3);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-tertiary);
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition-fast);
    position: relative;
}

.history-tab:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.history-tab.active {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

[data-theme="dark"] .history-tab.active {
    background: var(--bg-elevated);
}

/* ========================================
   Panel Content
======================================== */
.history-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4) var(--space-5);
}

.history-tab-content {
    display: none;
}

.history-tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

/* ========================================
   Sessions List
======================================== */
.sessions-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.session-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
}

[data-theme="dark"] .session-item {
    background: var(--bg-elevated);
}

.session-item:hover {
    background: var(--bg-hover);
    transform: translateX(4px);
}

.session-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--accent-subtle);
    color: var(--accent);
    flex-shrink: 0;
}

.session-icon svg {
    width: 18px;
    height: 18px;
}

.session-info {
    flex: 1;
    min-width: 0;
}

.session-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 var(--space-1) 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-meta {
    font-size: 12px;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.session-mode {
    text-transform: capitalize;
}

.session-delete-btn {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition-fast);
}

.session-item:hover .session-delete-btn {
    opacity: 1;
}

.session-delete-btn:hover {
    background: var(--destructive-subtle);
    color: var(--destructive);
}

.session-delete-btn svg {
    width: 14px;
    height: 14px;
}

/* ========================================
   Empty State
======================================== */
.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-10);
    text-align: center;
    color: var(--text-tertiary);
}

.history-empty svg {
    width: 56px;
    height: 56px;
    margin-bottom: var(--space-4);
    opacity: 0.4;
}

.history-empty p {
    margin: 0;
    font-size: 14px;
}

/* ========================================
   Activity Feed
======================================== */
.activity-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) 0;
}

.activity-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--accent-subtle);
    color: var(--text-secondary);
    flex-shrink: 0;
}

.activity-icon svg {
    width: 14px;
    height: 14px;
}

.activity-icon.problem {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.activity-icon.flashcard {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.activity-icon.topic {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
}

.activity-icon.session {
    background: rgba(249, 115, 22, 0.15);
    color: #f97316;
}

.activity-content {
    flex: 1;
    min-width: 0;
}

.activity-text {
    font-size: 13px;
    color: var(--text-primary);
    margin: 0 0 var(--space-1) 0;
    line-height: 1.5;
}

.activity-time {
    font-size: 11px;
    color: var(--text-tertiary);
}

/* ========================================
   Stats Dashboard
======================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.stat-card {
    padding: var(--space-5);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    text-align: center;
}

[data-theme="dark"] .stat-card {
    background: var(--bg-elevated);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
    letter-spacing: -0.02em;
}

.stat-label {
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

/* Streak Card */
.stat-card.streak {
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.12), rgba(249, 115, 22, 0.05));
}

.stat-card.streak .stat-value {
    color: #f97316;
}

/* ========================================
   Topics Section
======================================== */
.stats-section {
    margin-bottom: var(--space-6);
}

.stats-section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-4);
}

.topic-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.topic-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
}

[data-theme="dark"] .topic-item {
    background: var(--bg-elevated);
}

.topic-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    text-transform: capitalize;
}

.topic-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-subtle);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
}

/* ========================================
   Progress Bar
======================================== */
.progress-bar-container {
    margin-top: var(--space-3);
}

.progress-bar {
    height: 6px;
    background: var(--bg-hover);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover));
    border-radius: var(--radius-full);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   Loading State
======================================== */
.history-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-10);
}

.history-loading::after {
    content: '';
    width: 28px;
    height: 28px;
    border: 3px solid var(--bg-hover);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========================================
   Responsive
======================================== */
@media (max-width: 600px) {
    .history-panel {
        width: 100%;
    }

    .history-panel-header {
        padding: var(--space-4);
    }

    .history-close-btn {
        width: 44px;
        height: 44px;
    }

    .history-tabs {
        padding: 0 var(--space-4);
    }

    .history-tab {
        min-height: 44px;
    }

    .history-panel-content {
        padding: var(--space-4);
    }

    .stats-grid {
        gap: var(--space-3);
    }

    .session-item {
        padding: var(--space-3);
    }

    .session-delete-btn {
        opacity: 1;
        width: 36px;
        height: 36px;
    }

    .stat-card {
        padding: var(--space-4);
    }

    .stat-value {
        font-size: 1.75rem;
    }
}

/* ========================================
   Feature History Panels (practice, quiz, summarizer)
======================================== */

.fh-panel {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    z-index: 50;
}

.fh-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: var(--shadow-sm);
}

.fh-toggle-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-default);
}

.fh-panel.open .fh-toggle-btn {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: var(--accent);
}

.fh-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    width: 340px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-2);
}

.fh-panel.open .fh-dropdown {
    display: block;
    animation: fh-slideDown 0.15s ease;
}

@keyframes fh-slideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fh-loading {
    padding: var(--space-6) var(--space-4);
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.8125rem;
}

.fh-empty {
    padding: var(--space-6) var(--space-4);
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.8125rem;
}

.fh-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.12s ease;
}

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

.fh-item-content {
    flex: 1;
    min-width: 0;
}

.fh-item-title {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.fh-item-meta {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    margin-top: 1px;
}

.fh-item-stat {
    color: var(--accent);
    font-weight: 600;
}

.fh-sep {
    color: var(--text-quaternary);
}

.fh-item-delete {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    cursor: pointer;
    opacity: 0;
    transition: all 0.12s ease;
}

.fh-item:hover .fh-item-delete {
    opacity: 1;
}

.fh-item-delete:hover {
    background: var(--destructive-subtle);
    color: var(--destructive);
}

/* Position adjustments per section */
.flashcard-setup .fh-panel {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
}

.quiz-setup-card .fh-panel {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
}

.sum-page-shell .fh-panel {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
}

/* Ensure parent sections are positioned */
.flashcard-section {
    position: relative;
}

.sum-page-shell {
    position: relative;
}

@media (max-width: 640px) {
    .fh-dropdown {
        width: calc(100vw - 2 * var(--space-3));
        right: 0;
    }

    .fh-item-delete {
        opacity: 1;
    }
}

@media (max-width: 480px) {
    .history-panel {
        padding-bottom: calc(60px + env(safe-area-inset-bottom, 0));
    }

    .history-panel-header {
        touch-action: manipulation;
    }
}
