/* History Panel Styles */

.history-panel {
    position: fixed;
    top: 0;
    right: -320px;
    /* Hidden by default */
    width: 320px;
    height: 100vh;
    height: 100dvh;

    /* Role Sidebar Glass Match */
    background: var(--glass-bg) !important;
    backdrop-filter: blur(20px) saturate(160%) !important;
    -webkit-backdrop-filter: blur(20px) saturate(160%) !important;

    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.05);
    border-left: 1px solid rgba(255, 255, 255, 0.2) !important;
    /* 🚀 性能补丁：入场动画硬件加速 */
    transform: translateZ(0);
    will-change: right;
    transition: right 0.4s cubic-bezier(0.16, 1, 0.3, 1);

    display: flex;
    flex-direction: column;
}

.history-panel.open {
    right: 0;
    /* Slide in */
    box-shadow: -15px 0 50px rgba(0, 0, 0, 0.1);
}

/* Match Settings Panel Dark Mode (Sidebar style) */
/* Match Settings Panel Dark Mode (Sidebar style) */
body:not(.light-theme) .history-panel {
    background: var(--glass-bg) !important;
    border-left: 1px solid var(--glass-border) !important;
}

/* Mobile Responsiveness for History Panel - Apply Sidebar Mobile Logic */
@media (max-width: 768px) {
    .history-panel {
        width: 85%;
        right: -85%;

        /* Mobile Light Theme (Default) */
        background: var(--glass-bg) !important;
        backdrop-filter: blur(20px) saturate(180%) !important;
        -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
        border-left: 1px solid rgba(255, 255, 255, 0.2) !important;
    }

    /* Mobile Dark Theme */
    body:not(.light-theme) .history-panel {
        background: var(--glass-bg) !important;
        backdrop-filter: blur(25px) saturate(150%) !important;
        -webkit-backdrop-filter: blur(25px) saturate(150%) !important;
        border-left: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
}

/* History Content Styles */
.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    /* 🚀 核心优化：强制 GPU 渲染 */
    transform: translateZ(0);
    -webkit-overflow-scrolling: touch;
}

.history-card {
    background: var(--surface-color);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.history-card-content {
    flex: 1;
    cursor: pointer;
}

.history-card:hover {
    background: var(--surface-light);
    border-color: var(--primary-color);
}

.history-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.history-card-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.history-card-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.history-card-preview {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
}

.history-card-delete {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.2s;
}

.history-card-delete:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* ==================== History Sort Button + Panel ==================== */

/* 排序按钮包装器 */
.history-sort-wrapper {
    position: relative;
    margin-left: 8px;
}

/* 排序触发按钮 */
.history-sort-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.history-sort-btn ion-icon {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.history-sort-btn .sort-chevron {
    font-size: 0.7rem;
    transition: transform 0.3s ease;
}

.history-sort-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

.history-sort-btn.active {
    background: rgba(var(--primary-color-rgb), 0.15);
    border-color: var(--primary-color);
}

.history-sort-btn.active .sort-chevron {
    transform: rotate(180deg);
}

/* 浮动排序面板 */
.history-sort-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 200px;
    background: var(--surface-color);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    /* 🚀 GPU 渲染 */
    transform: translateY(-10px) scale(0.95) translateZ(0);
    will-change: transform, opacity;

    /* 默认隐藏 */
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.history-sort-panel.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* 面板内部区块 */
.sort-panel-section {
    padding: 4px 0;
}

.sort-panel-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    padding-left: 4px;
}

.sort-panel-divider {
    height: 1px;
    background: linear-gradient(to right, transparent, var(--glass-border), transparent);
    margin: 10px 0;
}

/* 排序选项按钮 */
.sort-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* 排序顺序水平排列 */
.sort-options.order-options {
    flex-direction: row;
    gap: 8px;
}

.sort-options.order-options .sort-option {
    flex: 1;
    justify-content: center;
    padding: 8px 0;
}

.sort-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
}

.sort-option ion-icon {
    font-size: 1.1rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.sort-option:hover {
    background: rgba(255, 255, 255, 0.06);
}

.sort-option.active {
    background: rgba(var(--primary-color-rgb), 0.15);
    color: var(--primary-color);
}

.sort-option.active ion-icon {
    color: var(--primary-color);
}

/* 移动端适配 */
@media (max-width: 480px) {
    .history-sort-btn {
        padding: 4px 10px;
        font-size: 0.75rem;
    }

    .history-sort-btn span {
        max-width: 60px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .history-sort-panel {
        min-width: 180px;
        right: 0;
        left: auto;
    }
}