/* ==================================================================
   1. 主题与变量 (Theme & Variables)
   ================================================================== */

/* --- 亮色模式 (默认) --- */
:root {
    --primary-color: #4a90e2;
    --primary-hover-color: #357abd;
    --background-color: #f0f2f5;
    --card-background-color: #ffffff;
    --text-color: #333333;
    --text-secondary-color: #6c757d;
    --border-color: #e9ecef;
    --success-color: #28a745;
    --error-color: #dc3545;
    --warning-color: #ffc107;
    --font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

/* --- 暗色模式 --- */
body.dark-mode {
    --background-color: #1a1a1a;
    --card-background-color: #2c2c2c;
    --text-color: #e0e0e0;
    --text-secondary-color: #888888;
    --border-color: #3a3a3a;
    --primary-color: #5a9ee2;
    --primary-hover-color: #7bb4e8;
}

/* --- 暗色模式下特定元素的微调 --- */
body.dark-mode .history-table thead th,
body.dark-mode .mod-status-table thead th {
    background-color: #333;
}

body.dark-mode .history-table tbody tr:hover,
body.dark-mode .mod-status-table tbody tr:hover {
    background-color: #383838;
}

body.dark-mode .metric-card {
    background-color: #222;
    border-color: var(--border-color);
}

body.dark-mode .mod-search-input,
body.dark-mode #mod-id {
    background-color: #333;
    color: var(--text-color);
    border-color: #444;
}


/* ==================================================================
   2. 全局样式 (Global Styles)
   ================================================================== */
body {
    font-family: var(--font-family);
    line-height: 1.6;
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
}

.container {
    max-width: 1100px;
    margin: 20px auto;
    padding: 0 15px;
}


/* ==================================================================
   3. 核心布局 (Core Layout)
   ================================================================== */

/* --- 头部与页脚 --- */
header, footer {
    text-align: center;
    margin-bottom: 30px;
    color: var(--text-secondary-color);
}

header h1 {
    color: var(--text-color);
    font-size: 2.5rem;
    margin-bottom: 10px;
}

footer {
    margin-top: 30px;
    font-size: 0.9rem;
}

/* --- 卡片布局 --- */
.card {
    background-color: var(--card-background-color);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 30px;
    margin-bottom: 24px;
    position: relative; /* 为加载动画定位 */
}

.card h2 {
    margin-top: 0;
    margin-bottom: 24px;
    font-size: 1.5rem;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

/* --- 卡片标题栏与交互 --- */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.card-header h2, .card-header h3 {
    margin: 0;
    flex-shrink: 0;
}

.controls-container {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-grow: 1;
    justify-content: flex-end;
}

#search-input, #status-filter {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    background-color: var(--card-background-color);
    color: var(--text-color);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#search-input {
    width: 220px;
}

#search-input:focus, #status-filter:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

body.dark-mode #search-input,
body.dark-mode #status-filter {
    background-color: #333;
    border-color: #444;
}

.history-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.switch-label {
    font-size: 0.9em;
    color: var(--text-secondary-color);
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.count-badge {
    background-color: var(--primary-color);
    color: white;
    padding: 0.2em 0.6em;
    border-radius: 10px;
    font-size: 0.9em;
    margin-left: 0.5rem;
}


/* ==================================================================
   4. UI 组件 (UI Components)
   ================================================================== */

/* --- 提交表单 --- */
#submit-form {
    display: flex;
    gap: 10px;
}

#mod-id {
    flex-grow: 1;
    padding: 12px 15px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#mod-id:focus {
    border-color: var(--primary-color);
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(74, 144, 226, 0.25);
}

#submit-button {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 25px;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background-color: var(--primary-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    min-width: 90px;
}

#submit-button:hover:not(:disabled) {
    background-color: var(--primary-hover-color);
    transform: translateY(-1px);
}

#submit-button:disabled {
    background-color: #9dbde2;
    cursor: not-allowed;
}

/* --- 按钮加载动画 --- */
.spinner {
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 3px solid #fff;
    width: 18px;
    height: 18px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- 表格加载动画 --- */
.table-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 12px;
    transition: opacity 0.3s ease;
}

body.dark-mode .table-loading-overlay {
    background-color: rgba(44, 44, 44, 0.7);
}

.table-loading-overlay .spinner {
    width: 40px;
    height: 40px;
    border-width: 4px;
    border-top-color: var(--primary-color);
    border-left-color: var(--primary-color);
    border-bottom-color: transparent;
    border-right-color: transparent;
}

/* --- Toast (浮动提示框) --- */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.toast {
    background-color: var(--card-background-color);
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-left: 5px solid;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.4s cubic-bezier(0.215, 0.610, 0.355, 1);
    min-width: 250px;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.success { border-left-color: var(--success-color); }
.toast.error { border-left-color: var(--error-color); }
.toast-icon { font-size: 1.5rem; }
.toast.success .toast-icon { color: var(--success-color); }
.toast.error .toast-icon { color: var(--error-color); }

/* --- 状态徽章 --- */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 10rem;
    color: #fff;
}

.status-badge.status-pending { background-color: var(--warning-color); color: #333; }
.status-badge.status-processing { background-color: var(--primary-color); }
.status-badge.status-success { background-color: var(--success-color); }
.status-badge.status-failed { background-color: var(--error-color); }
.status-badge.status-pending_deletion {
    background-color: var(--text-secondary-color);
    text-decoration: line-through;
}

/* Translation Statuses */
.status-badge.status-translating { background-color: #3498db; } /* Blue */
.status-badge.status-proofreading { background-color: #f39c12; } /* Orange */
.status-badge.status-completed { background-color: var(--success-color); } /* Green */
.status-badge.status-no_text { background-color: var(--text-secondary-color); } /* Gray */

/* --- 系统状态指示器 --- */
.system-status {
    margin-top: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-dot.success { background-color: var(--success-color); }
.status-dot.failed { background-color: var(--error-color); }

/* --- 核心指标 --- */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}

.metric-card {
    background-color: var(--background-color);
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.metric-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    display: block;
    margin-bottom: 8px;
}

.metric-label {
    font-size: 0.9rem;
    color: var(--text-secondary-color);
}

/* --- 刷新图标 --- */
.refresh-icon {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-secondary-color);
    cursor: pointer;
    transition: transform 0.5s ease, color 0.2s ease;
}

.refresh-icon:hover {
    color: var(--primary-color);
}

.refresh-icon.loading {
    transform: rotate(360deg);
}

/* --- 搜索输入框 --- */
.mod-search-input {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    width: 220px;
    font-size: 0.9rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.mod-search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

/* --- 提交历史表格 --- */

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.history-table th, .history-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.history-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.history-table thead th {
    background-color: var(--card-background-color); /* 适配暗色模式 */
    font-weight: 600;
    color: var(--text-secondary-color);
}

.history-table th.sortable {
    cursor: pointer;
    position: relative;
    padding-right: 25px;
    user-select: none;
}

.history-table th.sortable:hover {
    background-color: rgba(0,0,0,0.05);
}
body.dark-mode .history-table th.sortable:hover {
    background-color: rgba(255,255,255,0.05);
}


.history-table th.sortable::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    margin-top: -8px;
    border: 5px solid transparent;
    opacity: 0.3;
}

.history-table th.sort-asc::after { border-bottom-color: var(--text-color); opacity: 1; }
.history-table th.sort-desc::after { border-top-color: var(--text-color); opacity: 1; }

.history-table tbody tr:hover {
    background-color: #f8f9fa;
}

.history-table .col-id {
    color: var(--text-secondary-color);
    font-size: 0.85em;
    margin-top: 4px;
    display: block;
}

/* --- 分页容器 --- */
#pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 20px;
    gap: 5px;
}

.pagination-btn {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background-color: var(--card-background-color);
    color: var(--text-color);
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.pagination-btn:hover:not(:disabled) {
    background-color: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.pagination-btn.active {
    background-color: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
    font-weight: bold;
}

.pagination-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.pagination-ellipsis {
    padding: 8px;
    color: var(--text-secondary-color);
}

.mod-status-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
    /* table-layout: fixed; */ /* 移除固定布局，允许内容撑开 */
}

.mod-status-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.mod-status-table thead th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: var(--text-secondary-color);
}

.mod-status-table th, .mod-status-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    text-overflow: ellipsis;
}

.mod-status-table tbody tr:last-child td {
    border-bottom: none;
}

.mod-status-table tbody tr:hover {
    background-color: #f8f9fa;
}

/* 列宽定义 */
.mod-status-table th:nth-child(1),
.mod-status-table td:nth-child(1) {
    min-width: 300px; /* 为Mod名称设置最小宽度 */
    white-space: normal;
    word-break: break-word;
}

.mod-status-table th:nth-child(n+2),
.mod-status-table td:nth-child(n+2) {
    white-space: nowrap;
    text-align: right; /* 统一右对齐数字 */
}

/* 可排序表头 */
.mod-status-table th.sortable {
    cursor: pointer;
    position: relative;
    padding-right: 25px;
    user-select: none;
}

.mod-status-table th.sortable:hover {
    background-color: #e9ecef;
}

.mod-status-table th.sortable::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    margin-top: -8px;
    border: 5px solid transparent;
    opacity: 0.3;
}

.mod-status-table th.sort-asc::after { border-bottom-color: var(--text-color); opacity: 1; }
.mod-status-table th.sort-desc::after { border-top-color: var(--text-color); opacity: 1; }

/* 表格内链接和ID样式 */
.mod-name-link {
    display: block;
    color: var(--text-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

.mod-name-link:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

.mod-status-table .col-id {
    color: var(--text-secondary-color);
    font-size: 0.9em;
}

/* --- 美化滚动条 --- */
#history-container::-webkit-scrollbar,
.table-scroll-wrapper::-webkit-scrollbar {
    width: 8px;
}

#history-container::-webkit-scrollbar-track,
.table-scroll-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

#history-container::-webkit-scrollbar-thumb,
.table-scroll-wrapper::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 10px;
}

#history-container::-webkit-scrollbar-thumb:hover,
.table-scroll-wrapper::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* --- 页脚链接 --- */
.footer-links {
    margin-bottom: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px 15px;
}

.footer-links a {
    color: var(--text-secondary-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer-links a:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

.footer-links span {
    color: var(--border-color);
}

.copyright {
    font-size: 0.85rem;
    margin: 0;
}

/* --- 主题切换按钮 --- */
#theme-toggle {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    background-color: var(--card-background-color);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

#theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

body:not(.dark-mode) #icon-moon {
    display: none;
}

body.dark-mode #icon-sun {
    display: none;
}


/* ==================================================================
   5. 响应式设计 (Responsive Design)
   ================================================================== */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    .container {
        margin: 10px auto;
        padding: 0 10px;
    }
    .card {
        padding: 20px;
    }
    header h1 {
        font-size: 2rem;
    }
    #submit-form {
        flex-direction: column;
    }

    .controls-container {
        flex-direction: column;
        width: 100%;
        gap: 10px;
        margin-top: 10px;
    }
    #search-input, #status-filter {
        width: 100%;
        box-sizing: border-box;
    }
    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    /* 隐藏PC端的表头 */
    .history-table thead,
    .mod-status-table thead {
        display: none;
    }

    /* 让 <tr> 表现得像一个卡片 */
    .history-table tr,
    .mod-status-table tr {
        display: block;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin-bottom: 15px;
        padding: 15px;
    }
    .history-table tr:last-child,
    .mod-status-table tr:last-child {
        margin-bottom: 0;
    }

    /* 让 <td> 垂直排列，并占据整行 */
    .history-table td,
    .mod-status-table td {
        display: block;
        text-align: right;
        padding: 8px 0;
        border-bottom: none;
        position: relative;
        padding-left: 50%;
        overflow: visible;
        text-overflow: clip;
    }
    .mod-status-table td:nth-child(1) {
        text-align: left;
        padding-left: 0;
        font-weight: bold;
        font-size: 1.1em;
        margin-bottom: 10px;
        width: auto; /* 覆盖桌面端的 width: 45% */
        white-space: normal; /* 确保长名称可以正常换行 */
    }
    .history-table td:nth-child(1) {
        text-align: left;
        padding-left: 0;
    }
    .history-table td:nth-child(3) {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-left: 0; /* 移除内边距，因为flex会处理对齐 */
    }
    .history-table td:nth-child(3)::before {
        position: static; /* 移除绝对定位，让它成为flex item */
        width: auto;     /* 宽度自适应 */
    }


    /* 使用 ::before 伪元素添加数据标签，模拟表头 */
    .history-table td::before,
    .mod-status-table td::before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: bold;
        color: var(--text-secondary-color);
    }
    
    .history-table td:nth-child(2)::before { content: "提交时间:"; }
    .history-table td:nth-child(3)::before { content: "状态:"; }
    .history-table td:nth-child(4)::before { content: "待翻译:"; }
    .history-table td:nth-child(5)::before { content: "待校对:"; }
    .history-table td:nth-child(6)::before { content: "总条目:"; }

    .mod-status-table td:nth-child(2)::before { content: "Mod ID:"; }
    .mod-status-table td:nth-child(3)::before { content: "待翻译:"; }
    .mod-status-table td:nth-child(4)::before { content: "待校对:"; }
    .mod-status-table td:nth-child(5)::before { content: "总条目:"; }

    /* 状态徽章不再需要 float */
    .status-badge {
        float: none;
    }
}
