/* 历史版本功能样式 */
.history-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #d0d7de;
    background: transparent;
    color: #656d76;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.history-btn:hover {
    background: #f6f8fa;
    color: #24292f;
    border-color: #1f232826;
}

@media (max-width: 768px) {
    .editor-footer .history-btn {
        padding: 3px 7px;
        border-radius: 6px;
        font-size: 11px;
        gap: 3px;
    }

    .editor-footer .history-btn .material-symbols-outlined {
        font-size: 13px !important;
    }
}

/* 历史版本弹窗 */
.history-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6) !important;
    z-index: 10005;
    /* 高于编辑器(9999)和AI窗口(10002) */
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.history-box {
    width: 90%;
    max-width: 1100px;
    height: 85vh;
    max-height: 800px;
    background: #ffffff;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.history-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e1e4e8;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f6f8fa;
}

.history-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #24292f;
}

.history-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: #656d76;
}

.history-close-btn:hover {
    background: #d0d7de;
    color: #24292f;
}

.history-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.history-list {
    width: 280px;
    border-right: 1px solid #e1e4e8;
    overflow-y: auto;
    background: #ffffff;
}

.history-empty {
    padding: 40px 20px;
    text-align: center;
    color: #656d76;
}

.history-item {
    padding: 14px 20px;
    border-bottom: 1px solid #f6f8fa;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.history-item:hover {
    background: #f6f8fa;
}

.history-item.active {
    background: #ddf4ff;
    border-left: 3px solid #0969da;
}

.history-item.active::before {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    background: #0969da;
    border-radius: 50%;
}

.history-time {
    font-size: 14px;
    font-weight: 500;
    color: #24292f;
    margin-bottom: 4px;
}

.history-meta {
    font-size: 12px;
    color: #656d76;
}

.history-diff-view {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background: #ffffff;
}

.history-diff-placeholder {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #656d76;
}

.history-diff-placeholder svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Diff 样式 */
.diff-view {
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.diff-line {
    padding: 4px 8px;
    margin: 1px 0;
    border-radius: 3px;
}

.diff-added {
    background-color: #dafbe1;
    color: #0e4429;
}

.diff-removed {
    background-color: #ffebe9;
    color: #82071e;
    text-decoration: line-through;
}

.diff-same {
    color: #24292f;
}

/* 底部操作栏 */
.history-footer {
    padding: 16px 24px;
    border-top: 1px solid #e1e4e8;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: #f6f8fa;
}

.history-footer .btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid #d0d7de;
    background: #ffffff;
    color: #24292f;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.history-footer .btn:hover {
    background: #f6f8fa;
    border-color: #1f232826;
}

.history-footer .btn-primary {
    background: #0969da;
    border-color: #0969da;
    color: #ffffff;
    padding: 8px 16px;
}

.history-footer .btn-primary:hover {
    background: #0860ca;
    border-color: #0860ca;
}

.history-footer .btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 暗黑模式适配 */
@media (prefers-color-scheme: dark) {
    .history-box {
        background: #0d1117;
    }

    .history-header {
        background: #161b22;
        border-bottom-color: #30363d;
    }

    .history-header h3 {
        color: #c9d1d9;
    }

    .history-close-btn {
        color: #8b949e;
    }

    .history-close-btn:hover {
        background: #30363d;
        color: #c9d1d9;
    }

    .history-list {
        background: #0d1117;
        border-right-color: #30363d;
    }

    .history-item {
        border-bottom-color: #21262d;
    }

    .history-item:hover {
        background: #161b22;
    }

    .history-item.active {
        background: #1c2d41;
        border-left-color: #58a6ff;
    }

    .history-item.active::before {
        background: #58a6ff;
    }

    .history-time {
        color: #c9d1d9;
    }

    .history-meta {
        color: #8b949e;
    }

    .history-diff-view {
        background: #0d1117;
    }

    .diff-added {
        background-color: rgba(46, 160, 67, 0.2);
        color: #3fb950;
    }

    .diff-removed {
        background-color: rgba(248, 81, 73, 0.2);
        color: #ff7b72;
    }

    .diff-same {
        color: #c9d1d9;
    }

    .history-footer {
        background: #161b22;
        border-top-color: #30363d;
    }

    .history-footer .btn {
        background: #21262d;
        border-color: #30363d;
        color: #c9d1d9;
    }

    .history-footer .btn:hover {
        background: #30363d;
    }

    .history-footer .btn-primary {
        background: #1f6feb;
        border-color: #1f6feb;
    }

    .history-footer .btn-primary:hover {
        background: #388bfd;
    }
}

/* ========== 移动端响应式布局 ========== */
@media (max-width: 768px) {
    .history-modal {
        align-items: flex-end;
        /* 底部对齐，或者根据需要居中 */
        padding-top: env(safe-area-inset-top);
        /* 适配刘海屏 */
    }

    .history-box {
        width: 100%;
        height: 80vh;
        /* 稍微留出一点顶部空间 */
        max-height: none;
        border-radius: 16px 16px 0 0;
        /* 底部直角 */
    }

    .history-header {
        padding: 16px 20px;
    }

    .history-header h3 {
        font-size: 16px;
    }

    .history-body {
        flex-direction: column;
    }

    /* 左侧列表改为较小的固定高度 */
    .history-list {
        width: 100%;
        height: 180px;
        min-height: 180px;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid #e1e4e8;
        flex-shrink: 0;
    }

    .history-item {
        padding: 12px 16px;
    }

    .history-time {
        font-size: 13px;
    }

    .history-meta {
        font-size: 11px;
    }

    /* 右侧预览区域占据剩余空间 */
    .history-diff-view {
        flex: 1;
        padding: 16px;
        overflow-y: auto;
    }

    .history-footer {
        padding: 12px 16px;
        gap: 8px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        /* 适配底部安全区 */
    }

    .history-footer .btn {
        padding: 8px 12px;
        font-size: 13px;
        flex: 1;
    }

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

/* 超小屏幕（<480px）优化 */
@media (max-width: 480px) {
    .history-box {
        width: 98%;
        height: 80vh;
        border-radius: 12px;
        margin-bottom: env(safe-area-inset-bottom);
    }

    .history-header {
        padding: 12px 16px;
    }

    .history-header h3 {
        font-size: 15px;
    }

    /* 进一步减小左侧列表高度 */
    .history-list {
        height: 150px;
        min-height: 150px;
        max-height: 160px;
    }

    .history-item {
        padding: 10px 12px;
    }

    .history-time {
        font-size: 12px;
    }

    .history-diff-view {
        padding: 12px;
    }

    .diff-view {
        font-size: 12px;
    }

    .history-footer {
        padding: 10px 12px;
        flex-direction: column;
    }

    .history-footer .btn {
        width: 100%;
    }
}