/* 2026-07-21 funnyai/list_grid_history.php 美化
 *
 * 设计目标：
 *   1. 现代化页面布局：顶栏 / 文档元信息卡 / 时间线 / 分页
 *   2. 时间线展示历史版本，每个版本是一张卡片
 *   3. 卡片可展开查看内容变更 diff（绿增 / 红删 / 黄改）
 *   4. 暗色模式友好
 *   5. 响应式
 */

:root {
    --history-bg: #f5f7fa;
    --history-card-bg: #ffffff;
    --history-card-border: #e5e7eb;
    --history-card-shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.04);
    --history-card-shadow-hover: 0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
    --history-text: #1f2937;
    --history-muted: #6b7280;
    --history-link: #2563eb;
    --history-accent: #8b5cf6;
    --history-timeline: #d1d5db;
    --history-add: #16a34a;
    --history-del: #dc2626;
    --history-mod: #f59e0b;
    --history-radius: 12px;
}

body {
    background: var(--history-bg);
    color: var(--history-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    margin: 0;
}

/* 顶部导航（覆盖默认的 #top_nav_view） */
.history-topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-bottom: 1px solid var(--history-card-border);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

.history-topbar__title {
    font-size: 17px;
    font-weight: 600;
    color: var(--history-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-topbar__title svg {
    width: 20px;
    height: 20px;
    color: var(--history-accent);
}

.history-topbar__back {
    color: var(--history-muted);
    text-decoration: none;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.history-topbar__back:hover {
    background: rgba(37, 99, 235, 0.08);
    color: var(--history-link);
}

.history-topbar__search {
    flex: 1;
    min-width: 220px;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
}

.history-topbar__search input[type="text"] {
    flex: 1;
    height: 34px;
    padding: 0 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    background: #ffffff;
    color: var(--history-text);
    transition: all 0.15s ease;
}

.history-topbar__search input[type="text"]:focus {
    outline: none;
    border-color: var(--history-link);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.history-topbar__search input[type="submit"] {
    height: 34px;
    padding: 0 16px;
    border: 1px solid var(--history-link);
    border-radius: 6px;
    background: var(--history-link);
    color: #ffffff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.history-topbar__search input[type="submit"]:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.history-topbar__user {
    color: var(--history-muted);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-topbar__user a {
    color: var(--history-link);
    text-decoration: none;
}

.history-topbar__user a:hover {
    text-decoration: underline;
}

/* 文档元信息卡（顶部） */
.history-doc-card {
    max-width: 900px;
    margin: 24px auto 0;
    background: var(--history-card-bg);
    border: 1px solid var(--history-card-border);
    border-radius: var(--history-radius);
    box-shadow: var(--history-card-shadow);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.history-doc-card__icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--history-accent) 0%, #6366f1 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    flex-shrink: 0;
}

.history-doc-card__icon svg {
    width: 24px;
    height: 24px;
}

.history-doc-card__info {
    flex: 1;
    min-width: 0;
}

.history-doc-card__name {
    font-size: 18px;
    font-weight: 600;
    color: var(--history-text);
    margin: 0 0 4px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-doc-card__meta {
    font-size: 13px;
    color: var(--history-muted);
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}

.history-doc-card__meta strong {
    color: var(--history-text);
    font-weight: 600;
}

.history-doc-card__actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.history-doc-card__btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 32px;
    padding: 0 12px;
    border-radius: 6px;
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: var(--history-text);
}

.history-doc-card__btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.history-doc-card__btn--primary {
    background: var(--history-link);
    border-color: var(--history-link);
    color: #ffffff;
}

.history-doc-card__btn--primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

/* 时间线容器 */
.history-timeline {
    max-width: 900px;
    margin: 24px auto 80px;
    padding: 0 24px;
    position: relative;
}

.history-timeline::before {
    content: "";
    position: absolute;
    top: 8px;
    bottom: 8px;
    left: 38px;
    width: 2px;
    background: var(--history-timeline);
}

.history-timeline__empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--history-muted);
    background: var(--history-card-bg);
    border: 1px dashed var(--history-card-border);
    border-radius: var(--history-radius);
    margin-top: 20px;
}

.history-timeline__empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.4;
}

/* 单个历史记录节点 */
.history-item {
    position: relative;
    padding-left: 60px;
    margin-bottom: 18px;
}

.history-item__dot {
    position: absolute;
    left: 28px;
    top: 18px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--history-card-bg);
    border: 3px solid var(--history-accent);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.12);
    z-index: 1;
}

.history-item.is-current .history-item__dot {
    background: var(--history-accent);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.25);
}

.history-item__card {
    background: var(--history-card-bg);
    border: 1px solid var(--history-card-border);
    border-radius: var(--history-radius);
    box-shadow: var(--history-card-shadow);
    transition: all 0.15s ease;
    overflow: hidden;
}

.history-item__card:hover {
    box-shadow: var(--history-card-shadow-hover);
    border-color: #cbd5e1;
}

.history-item__head {
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    cursor: pointer;
    user-select: none;
}

.history-item__head:hover {
    background: #f8fafc;
}

.history-item__version {
    font-size: 12px;
    font-weight: 600;
    color: var(--history-accent);
    background: rgba(139, 92, 246, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    flex-shrink: 0;
}

.history-item__title {
    font-size: 14px;
    font-weight: 500;
    color: var(--history-text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item__time {
    font-size: 12px;
    color: var(--history-muted);
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
    flex-shrink: 0;
}

.history-item__author {
    font-size: 12px;
    color: var(--history-muted);
    flex-shrink: 0;
}

.history-item__public {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    flex-shrink: 0;
    font-weight: 500;
}

.history-item__public.is-public-0 {
    background: #fee2e2;
    color: #b91c1c;
}

.history-item__public.is-public-1 {
    background: #d1fae5;
    color: #065f46;
}

.history-item__public.is-public-2 {
    background: #dbeafe;
    color: #1e40af;
}

.history-item__actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.history-item__btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 28px;
    padding: 0 10px;
    border-radius: 5px;
    font-size: 12px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: var(--history-text);
}

.history-item__btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.history-item__btn--primary {
    background: var(--history-link);
    border-color: var(--history-link);
    color: #ffffff;
}

.history-item__btn--primary:hover {
    background: #1d4ed8;
}

.history-item__btn--restore {
    background: var(--history-add);
    border-color: var(--history-add);
    color: #ffffff;
}

.history-item__btn--restore:hover {
    background: #15803d;
}

.history-item__toggle {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--history-muted);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.history-item__toggle svg {
    width: 14px;
    height: 14px;
}

.history-item__card.is-open .history-item__toggle {
    transform: rotate(180deg);
}

/* 展开的内容区 */
.history-item__body {
    display: none;
    padding: 0 18px 18px;
    border-top: 1px solid var(--history-card-border);
}

.history-item__card.is-open .history-item__body {
    display: block;
}

.history-diff {
    margin-top: 14px;
    border: 1px solid var(--history-card-border);
    border-radius: 8px;
    overflow: hidden;
    background: #fafbfc;
}

.history-diff__head {
    padding: 8px 12px;
    background: #f3f4f6;
    border-bottom: 1px solid var(--history-card-border);
    font-size: 12px;
    color: var(--history-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-diff__head strong {
    color: var(--history-text);
}

.history-diff__body {
    padding: 12px;
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
    font-size: 12px;
    line-height: 1.6;
    max-height: 360px;
    overflow: auto;
}

.history-diff__line {
    padding: 2px 6px;
    border-radius: 3px;
    white-space: pre-wrap;
    word-break: break-all;
}

.history-diff__line.is-add {
    background: rgba(22, 163, 74, 0.1);
    color: #166534;
    border-left: 3px solid var(--history-add);
}

.history-diff__line.is-del {
    background: rgba(220, 38, 38, 0.1);
    color: #991b1b;
    border-left: 3px solid var(--history-del);
}

.history-diff__line.is-mod {
    background: rgba(245, 158, 11, 0.1);
    color: #92400e;
    border-left: 3px solid var(--history-mod);
}

.history-diff__line.is-context {
    color: var(--history-muted);
}

/* 分页 */
.history-pagination {
    max-width: 900px;
    margin: 32px auto 60px;
    padding: 0 24px;
    text-align: center;
}

.history-pagination .mj_pagefoot_green {
    display: inline-block;
}

/* 暗色模式 */
body[data-theme="dark"] {
    --history-bg: #111827;
    --history-card-bg: #1f2937;
    --history-card-border: #374151;
    --history-text: #e5e7eb;
    --history-muted: #9ca3af;
    --history-timeline: #4b5563;
}

body[data-theme="dark"] .history-topbar {
    background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
}

body[data-theme="dark"] .history-topbar__search input[type="text"],
body[data-theme="dark"] .history-doc-card__btn,
body[data-theme="dark"] .history-item__btn {
    background: #111827;
    color: #e5e7eb;
    border-color: #374151;
}

body[data-theme="dark"] .history-item__head:hover {
    background: rgba(255, 255, 255, 0.04);
}

body[data-theme="dark"] .history-diff {
    background: #111827;
}

body[data-theme="dark"] .history-diff__head {
    background: #1f2937;
    border-color: #374151;
}

body[data-theme="dark"] .history-diff__line.is-add {
    background: rgba(22, 163, 74, 0.15);
    color: #86efac;
}

body[data-theme="dark"] .history-diff__line.is-del {
    background: rgba(220, 38, 38, 0.15);
    color: #fca5a5;
}

body[data-theme="dark"] .history-diff__line.is-mod {
    background: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
}

body[data-theme="dark"] .history-item__public.is-public-0 {
    background: rgba(220, 38, 38, 0.2);
    color: #fca5a5;
}

body[data-theme="dark"] .history-item__public.is-public-1 {
    background: rgba(22, 163, 74, 0.2);
    color: #86efac;
}

body[data-theme="dark"] .history-item__public.is-public-2 {
    background: rgba(37, 99, 235, 0.2);
    color: #93c5fd;
}

/* 响应式 */
@media (max-width: 768px) {
    .history-topbar {
        padding: 10px 14px;
        gap: 10px;
    }
    .history-topbar__title {
        font-size: 15px;
    }
    .history-doc-card {
        margin: 16px 14px 0;
        padding: 16px;
    }
    .history-doc-card__name {
        font-size: 16px;
    }
    .history-timeline {
        padding: 0 14px;
    }
    .history-timeline::before {
        left: 22px;
    }
    .history-item {
        padding-left: 40px;
    }
    .history-item__dot {
        left: 12px;
        width: 18px;
        height: 18px;
    }
    .history-item__head {
        padding: 10px 12px;
        gap: 8px;
    }
    .history-item__title {
        font-size: 13px;
    }
    .history-item__body {
        padding: 0 12px 12px;
    }
}
