/* ===== 历史记录弹窗样式 ===== */

/* 弹窗遮罩层 */
.history-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.history-modal-overlay.active {
    opacity: 1;
}

/* 弹窗容器 */
.history-modal-container {
    background: var(--bg);
    border-radius: 16px;
    width: 100%;
    max-width: 680px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
    display: flex;
    flex-direction: column;
}

.history-modal-overlay.active .history-modal-container {
    transform: scale(1) translateY(0);
}

/* 弹窗头部 */
.history-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.history-modal-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.history-modal-title svg {
    color: var(--accent);
}

.history-modal-count {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-soft);
    background: var(--line);
    padding: 1px 8px;
    border-radius: 10px;
    margin-left: 4px;
}

.history-modal-close {
    background: none;
    border: none;
    color: var(--text-soft);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.history-modal-close:hover {
    background: var(--line);
    color: var(--text);
}

/* 弹窗主体 */
.history-modal-body {
    padding: 8px 16px 16px;
    overflow-y: auto;
    flex: 1;
}

/* 历史记录加载状态 */
.history-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--text-soft);
    font-size: 0.9rem;
}

.history-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: history-spin 0.8s linear infinite;
}

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

/* 历史记录空状态 */
.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--text-soft);
    text-align: center;
}

.history-empty svg {
    opacity: 0.4;
}

/* 历史记录错误 */
.history-error {
    padding: 20px;
    color: #dc3545;
    text-align: center;
    font-size: 0.9rem;
}

/* 时间线 */
.history-timeline {
    position: relative;
    padding: 10px 0;
    margin-top: 4px;
}

/* 时间线竖线 */
.history-timeline::before {
    content: '';
    position: absolute;
    left: 22px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--line);
}

/* 时间线条目 */
.history-timeline-item {
    position: relative;
    padding-left: 48px;
    padding-bottom: 14px;
}

.history-timeline-item:last-child {
    padding-bottom: 0;
}

/* 时间线圆点 */
.history-timeline-dot {
    position: absolute;
    left: 15px;
    top: 4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--bg);
    border: 2px solid;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 事件徽章 - 内联在内容卡片中 */
.history-event-badge {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 10px;
    white-space: nowrap;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    margin-bottom: 6px;
}

/* 时间线内容卡片 */
.history-timeline-content {
    background: var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    margin-top: 6px;
    transition: all 0.2s ease;
}

.history-timeline-content:hover {
    background: var(--selection-bg);
}

/* 事件头部 */
.history-event-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
    flex-wrap: wrap;
    gap: 4px;
}

.history-actor {
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--text);
}

.history-actor:hover .history-actor-name {
    color: var(--accent);
}

.history-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid var(--bg);
}

.history-actor-name {
    font-size: 0.78rem;
    font-weight: 600;
    transition: color 0.2s ease;
}

.history-event-time {
    font-size: 0.68rem;
    color: var(--text-soft);
}

/* 事件描述 */
.history-event-desc {
    font-size: 0.78rem;
    color: var(--text-soft);
    line-height: 1.4;
    word-break: break-word;
}

/* ===== 编辑内容Diff展示 ===== */
.history-event-diff {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.history-diff-section {
    margin-bottom: 4px;
}

.history-diff-section:last-child {
    margin-bottom: 0;
}

.history-diff-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.history-diff-removed {
    background: rgba(203, 36, 49, 0.08);
    border-left: 2px solid #cb2431;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    margin-bottom: 4px;
}

.history-diff-added {
    background: rgba(40, 167, 69, 0.08);
    border-left: 2px solid #28a745;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

/* Markdown渲染的diff内容区域 */
.history-diff-md-content {
    display: inline;
}

.history-diff-md-content p {
    margin: 0;
    display: inline;
}

.history-diff-md-content ul,
.history-diff-md-content ol {
    margin: 4px 0;
    padding-left: 20px;
}

.history-diff-md-content code {
    background: rgba(0,0,0,0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.85em;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

[data-theme="dark"] .history-diff-md-content code {
    background: rgba(255,255,255,0.1);
}

.history-diff-md-content strong {
    font-weight: 700;
}

.history-diff-md-content a {
    color: var(--accent);
    text-decoration: none;
}

.history-diff-md-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 8px 0;
}

.history-diff-marker {
    display: inline-block;
    width: 18px;
    font-weight: 700;
    user-select: none;
    flex-shrink: 0;
}

.history-diff-marker:empty::before {
    content: ' ';
}

.history-diff-removed .history-diff-marker {
    color: #cb2431;
}

.history-diff-added .history-diff-marker {
    color: #28a745;
}

.history-diff-more {
    font-size: 0.75rem;
    color: var(--text-soft);
    font-style: italic;
    padding: 4px 12px;
}

.history-diff-size {
    font-size: 0.8rem;
    color: var(--text-soft);
    padding: 6px 12px;
    background: var(--bg);
    border-radius: 4px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

/* ===== 网络状态指示器 ===== */
.network-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: default;
    transition: all 0.3s ease;
    margin-right: 8px;
}

.network-status.online {
    color: #28a745;
    background: rgba(40, 167, 69, 0.1);
}

.network-status.offline {
    color: #dc3545;
    background: rgba(220, 53, 69, 0.1);
    animation: pulse-offline 2s infinite;
}

@keyframes pulse-offline {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.network-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    transition: background 0.3s ease;
}

.network-status-text {
    white-space: nowrap;
}

/* ===== 离线通知 ===== */
.offline-notice {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: #dc3545;
    color: white;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

.offline-notice svg {
    flex-shrink: 0;
}

.offline-notice-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.8;
    margin-left: 8px;
}

.offline-notice-close:hover {
    opacity: 1;
}

/* ===== 缓存管理器 Modal ===== */
.cache-manager-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.cache-manager-overlay.active {
    opacity: 1;
}

.cache-manager-modal {
    background: var(--bg);
    border-radius: 16px;
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

.cache-manager-overlay.active .cache-manager-modal {
    transform: scale(1) translateY(0);
}

/* 缓存管理器头部 */
.cache-manager-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--line);
}

.cache-manager-header h2 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
}

.cache-manager-close {
    background: none;
    border: none;
    color: var(--text-soft);
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.cache-manager-close:hover {
    background: var(--line);
    color: var(--text);
}

/* 缓存管理器主体 */
.cache-manager-body {
    padding: 20px 24px 24px;
}

/* 概览卡片 */
.cache-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.cache-summary-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--line);
    border-radius: 12px;
    transition: all 0.2s ease;
}

.cache-summary-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.cache-summary-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.cache-summary-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cache-summary-label {
    font-size: 0.75rem;
    color: var(--text-soft);
    font-weight: 500;
}

.cache-summary-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.cache-summary-sub {
    font-size: 0.7rem;
    color: var(--text-soft);
}

/* 缓存区块 */
.cache-section {
    margin-bottom: 20px;
    padding: 16px;
    background: var(--line);
    border-radius: 12px;
}

.cache-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.cache-section-header h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 缓存详情列表 */
.cache-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.cache-detail-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 8px;
}

.cache-detail-label {
    font-size: 0.7rem;
    color: var(--text-soft);
    font-weight: 500;
}

.cache-detail-value {
    font-size: 0.85rem;
    color: var(--text);
    font-weight: 600;
}

/* 缓存说明 */
.cache-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 8px;
    font-size: 0.75rem;
    color: var(--text-soft);
    line-height: 1.4;
}

.cache-note svg {
    flex-shrink: 0;
    margin-top: 1px;
    opacity: 0.5;
}

/* 危险区块 */
.cache-section-danger {
    border: 1px solid rgba(220, 53, 69, 0.2);
}

.cache-danger-text {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-soft);
    line-height: 1.5;
}

/* 缓存操作按钮 */
.cache-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.clear-btn {
    background: var(--bg);
    color: var(--text);
}

.clear-btn:hover {
    background: var(--selection-bg);
    color: var(--accent);
}

.danger-btn {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}

.danger-btn:hover {
    background: #dc3545;
    color: white;
}

/* ===== 深色模式适配 ===== */
[data-theme="dark"] .history-timeline-content {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .history-timeline-content:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* 深色模式 - Diff展示 */
[data-theme="dark"] .history-event-diff {
    border-top-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .history-diff-removed {
    background: rgba(203, 36, 49, 0.12);
}

[data-theme="dark"] .history-diff-added {
    background: rgba(40, 167, 69, 0.12);
}

[data-theme="dark"] .history-diff-size {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .cache-summary-card,
[data-theme="dark"] .cache-section {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .cache-detail-item,
[data-theme="dark"] .cache-note {
    background: rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .cache-manager-modal {
    background: #1a1a2e;
}

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

[data-theme="dark"] .history-modal-container {
    background: #1a1a2e;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .clear-btn {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

[data-theme="dark"] .clear-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* ===== 响应式设计 ===== */

/* 平板 */
@media (max-width: 768px) {
    .cache-summary {
        grid-template-columns: 1fr;
    }

    .cache-details {
        grid-template-columns: 1fr;
    }

    .cache-manager-modal {
        max-height: 90vh;
        max-width: 100%;
        margin: 10px;
    }

    .history-event-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .history-timeline::before {
        left: 20px;
    }

    .history-timeline-item {
        padding-left: 48px;
    }

    .history-timeline-dot {
        left: 12px;
        width: 16px;
        height: 16px;
    }

    .history-event-badge {
        position: static;
        display: inline-block;
        margin-bottom: 8px;
    }

    .network-status-text {
        display: none;
    }

    .network-status {
        padding: 4px 8px;
    }
}

/* 手机 */
@media (max-width: 480px) {
    .cache-manager-body {
        padding: 16px;
    }

    .cache-manager-header {
        padding: 16px;
    }

    .cache-summary-card {
        padding: 12px;
    }

    .history-timeline-content {
        padding: 12px;
    }

    .history-timeline-item {
        padding-left: 40px;
        padding-bottom: 20px;
    }

    .history-timeline-dot {
        left: 8px;
        width: 14px;
        height: 14px;
    }
}

/* ===== 高分辨率屏幕适配 ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .history-avatar {
        border-width: 1px;
    }
}
