/* ==========================================================================
   传输历史抽屉
   依赖 style.css 的设计变量与通用类（.hidden / .btn / .input / .t-icon / .icon-btn）
   ========================================================================== */

body.history-lock {
    overflow: hidden;
}

.history-drawer {
    position: fixed;
    inset: 0;
    z-index: 1100;
}

.history-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(5, 8, 14, 0.62);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.history-panel {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: min(420px, 100%);
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(30, 36, 48, 0.98), rgba(21, 26, 37, 0.98));
    border-left: 1px solid var(--border-strong);
    box-shadow: -24px 0 70px rgba(0, 0, 0, 0.5), var(--inner-hi);
}

@media (prefers-reduced-motion: no-preference) {
    .history-drawer:not(.hidden) .history-backdrop {
        animation: history-fade 0.2s ease;
    }

    .history-drawer:not(.hidden) .history-panel {
        animation: history-slide-in 0.28s var(--ease-out);
    }

    @keyframes history-fade {
        from {
            opacity: 0;
        }

        to {
            opacity: 1;
        }
    }

    @keyframes history-slide-in {
        from {
            opacity: 0.6;
            transform: translateX(24px);
        }

        to {
            opacity: 1;
            transform: translateX(0);
        }
    }
}

/* ---------- 头部 ---------- */

.history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border);
    flex: none;
}

.history-head-main {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
}

.history-head h2 {
    font-size: 1.02rem;
    font-weight: 650;
    white-space: nowrap;
}

.history-count {
    font-size: 0.76rem;
    color: var(--text-3);
    font-family: var(--font-mono);
    white-space: nowrap;
}

/* ---------- 工具栏 ---------- */

.history-toolbar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    flex: none;
}

.history-search {
    position: relative;
    display: flex;
    align-items: center;
}

.history-search svg {
    position: absolute;
    left: 11px;
    color: var(--text-3);
    pointer-events: none;
}

.history-search .input {
    width: 100%;
    padding-left: 34px;
}

.history-filters {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.history-chips {
    display: inline-flex;
    gap: 4px;
    padding: 3px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.history-chip {
    padding: 5px 12px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-2);
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
    white-space: nowrap;
}

.history-chip:hover {
    color: var(--text-1);
    background: var(--surface-2);
}

.history-chip.active {
    color: var(--text-1);
    background: var(--accent-soft);
    box-shadow: var(--inner-hi);
}

.history-status-select {
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-2);
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
}

.history-status-select:focus-visible {
    outline: none;
    border-color: var(--border-strong);
}

.history-status-select option {
    background: var(--bg-solid);
    color: var(--text-1);
}

/* ---------- 列表 ---------- */

.history-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.h-group {
    position: sticky;
    top: 0;
    z-index: 1;
    flex: none;
    padding: 12px 4px 4px;
    margin-top: -4px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--text-3);
    background: linear-gradient(180deg, rgba(21, 26, 37, 0.96) 70%, rgba(21, 26, 37, 0));
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.h-item {
    flex: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.h-item:hover {
    border-color: var(--border-strong);
}

.h-item.expanded {
    border-color: rgba(79, 141, 255, 0.32);
}

.h-row {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    padding: 11px 12px;
    border: none;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.h-row:hover {
    background: var(--surface-2);
}

.h-row:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.h-icon {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    color: var(--text-2);
}

/* 方向决定图形，结果决定颜色 */
.h-item[data-status="done"] .h-icon {
    background: var(--success-soft);
    color: var(--success);
}

.h-item[data-status="failed"] .h-icon,
.h-item[data-status="rejected"] .h-icon {
    background: var(--danger-soft);
    color: var(--danger);
}

.h-item[data-status="cancelled"] .h-icon,
.h-item[data-status="interrupted"] .h-icon {
    background: var(--surface-2);
    color: var(--text-3);
}

.h-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.h-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.h-name {
    min-width: 0;
    font-size: 0.87rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.h-size {
    flex: none;
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: var(--text-2);
}

.h-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    margin-top: 3px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    line-height: 1.6;
    color: var(--text-3);
}

.h-meta>*+*::before {
    content: '·';
    margin: 0 6px;
    opacity: 0.55;
}

.h-status {
    font-weight: 600;
}

.h-item[data-status="done"] .h-status {
    color: var(--success);
}

.h-item[data-status="failed"] .h-status,
.h-item[data-status="rejected"] .h-status {
    color: var(--danger);
}

.h-item[data-status="cancelled"] .h-status,
.h-item[data-status="interrupted"] .h-status {
    color: var(--warning);
}

.h-perf {
    margin-top: 3px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-3);
}

.h-chevron {
    flex: none;
    display: inline-flex;
    color: var(--text-3);
    transition: transform 0.2s ease;
}

.h-item.expanded .h-chevron {
    transform: rotate(180deg);
}

/* ---------- 展开详情 ---------- */

.h-detail {
    padding: 12px 14px 13px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.16);
}

.h-detail-list {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 6px 10px;
    font-size: 0.78rem;
}

.h-detail-list dt {
    color: var(--text-3);
    white-space: nowrap;
}

.h-detail-list dd {
    margin: 0;
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    word-break: break-word;
}

.h-detail-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.h-detail-spacer {
    flex: 1;
}

/* ---------- 加载更多 / 空态 ---------- */

.h-more {
    flex: none;
    margin: 4px auto 0;
    padding: 8px 18px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.18s ease;
}

.h-more:hover {
    background: var(--surface-2);
    color: var(--text-1);
    border-color: var(--border-strong);
}

.h-empty {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 240px;
    padding: 24px;
    text-align: center;
}

.h-empty-icon {
    color: var(--text-3);
    opacity: 0.7;
}

.h-empty-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-2);
}

.h-empty-hint {
    font-size: 0.78rem;
    color: var(--text-3);
    max-width: 260px;
}

/* ---------- 底部 ---------- */

.history-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    flex: none;
}

.history-local {
    font-size: 0.72rem;
    color: var(--text-3);
}

.history-foot-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.history-clear-confirm {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.76rem;
    color: var(--text-2);
}

.history-foot .history-clear:hover {
    color: var(--danger);
    border-color: rgba(242, 109, 109, 0.35);
    background: var(--danger-soft);
}

/* ---------- 文件面板："本次传输 / 查看历史" ---------- */

.pane-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex: none;
}

.pane-head-title {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-3);
}

.link-btn {
    padding: 0;
    border: none;
    background: none;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.18s ease, opacity 0.18s ease;
}

.link-btn:hover {
    color: var(--accent-2);
}

/* ---------- 响应式 ---------- */

@media (max-width: 767px) {
    .history-panel {
        width: 100%;
        border-left: none;
    }

    .history-head {
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
    }

    .history-toolbar {
        padding: 10px 14px;
    }

    .history-list {
        padding: 4px 12px 14px;
    }

    .history-foot {
        padding-left: 14px;
        padding-right: 14px;
    }

    .h-row {
        padding: 12px 11px;
    }
}

@media (max-width: 420px) {
    .h-perf {
        display: none;
    }

    .h-detail-list {
        grid-template-columns: 64px minmax(0, 1fr);
    }
}
