/* ===== 变量 ===== */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --success: #10b981;
    --success-light: #d1fae5;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-light: #64748b;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -2px rgba(0,0,0,.03);
}

/* ===== 重置 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
svg { display: block; }

/* ===== 容器 ===== */
.container { max-width: 960px; margin: 0 auto; padding: 0 20px; }

/* ===== 头部 ===== */
.site-header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 58px;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--primary);
    font-size: 1.15rem;
    font-weight: 700;
}
.api-link {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: .82rem;
    color: var(--text-light);
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: all .2s;
}
.api-link:hover {
    color: var(--primary);
    border-color: var(--primary);
    text-decoration: none;
}

/* ===== 主内容 ===== */
#main-content { padding: 32px 20px 60px; }

/* ===== 区块标题 ===== */
.section-label {
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 14px;
}

/* ===== 工具网格 ===== */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
}
.tool-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    cursor: pointer;
    transition: all .2s;
    display: flex;
    align-items: flex-start;
    gap: 14px;
}
.tool-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.tool-card.active {
    border-color: var(--primary);
    background: var(--primary-light);
}
.tool-icon {
    width: 38px; height: 38px;
    background: var(--primary-light);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--primary);
}
.tool-info h3 { font-size: .9rem; font-weight: 600; margin-bottom: 3px; }
.tool-info p { font-size: .78rem; color: var(--text-light); }

/* ===== 工作区 ===== */
.workspace {
    margin-top: 28px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    animation: fadeUp .3s ease;
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.workspace-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
    background: #fafbfc;
}
.workspace-header h2 {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}
.workspace-body { padding: 22px; }

/* ===== 关闭按钮 ===== */
.btn-close {
    width: 32px; height: 32px;
    border: 1px solid var(--border);
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    transition: all .2s;
}
.btn-close:hover {
    background: var(--danger-light);
    border-color: var(--danger);
    color: var(--danger);
}

/* ===== 上传区域 ===== */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 44px 24px;
    text-align: center;
    cursor: pointer;
    transition: all .2s;
    background: #fafbfc;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.upload-zone input[type="file"] { display: none; }
.upload-icon {
    width: 60px; height: 60px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
    box-shadow: var(--shadow);
    color: var(--primary);
}
.upload-zone h3 { font-size: .95rem; margin-bottom: 5px; }
.upload-zone p { font-size: .82rem; color: var(--text-light); }

/* ===== 文件列表 ===== */
.file-list { margin-top: 12px; }
.file-item {
    display: flex;
    align-items: center;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    background: white;
    gap: 12px;
}
.file-item-icon {
    width: 34px; height: 34px;
    background: var(--primary-light);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    flex-shrink: 0;
}
.file-item-info { flex: 1; min-width: 0; }
.file-item-name {
    font-weight: 600;
    font-size: .88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-item-size { font-size: .76rem; color: var(--text-light); }
.file-item-remove {
    width: 28px; height: 28px;
    border: none;
    background: var(--danger-light);
    color: var(--danger);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all .2s;
}
.file-item-remove:hover { background: var(--danger); color: white; }

/* ===== 选项面板 ===== */
.options-panel {
    margin-top: 20px;
    padding: 18px;
    background: #f8fafc;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.options-panel h4 {
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.option-group { margin-bottom: 14px; }
.option-group:last-child { margin-bottom: 0; }
.option-group label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    margin-bottom: 5px;
}
.option-group input[type="text"],
.option-group input[type="number"],
.option-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .88rem;
    background: white;
    transition: border-color .2s;
}
.option-group input:focus, .option-group select:focus {
    outline: none;
    border-color: var(--primary);
}
.option-row { display: flex; gap: 12px; }
.option-row .option-group { flex: 1; }

/* ===== 滑块 ===== */
.slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
}
.slider-row input[type="range"] {
    flex: 1;
    accent-color: var(--primary);
    cursor: pointer;
}
.slider-val {
    min-width: 40px;
    text-align: right;
    font-size: .82rem;
    font-weight: 600;
    color: var(--primary);
}

/* ===== 颜色选择 ===== */
.color-row, .color-picker-row { display: flex; align-items: center; gap: 12px; }
.color-row input[type="color"],
.color-picker-row input[type="color"] {
    width: 40px; height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
    cursor: pointer;
    background: white;
}

/* ===== 单选/复选 ===== */
.radio-group, .checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.radio-item, .checkbox-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: .85rem;
    background: white;
    transition: all .2s;
    user-select: none;
}
.radio-item:has(input:checked),
.checkbox-item:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}
.radio-item input, .checkbox-item input { accent-color: var(--primary); cursor: pointer; }

/* ===== 按钮 ===== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(37,99,235,.25);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(37,99,235,.3);
}
.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 2px 8px rgba(16,185,129,.25);
}
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-outline {
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-lg { padding: 12px 28px; font-size: .98rem; }
.btn-group { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.btn-full { width: 100%; }

/* ===== 下载区 ===== */
.download-area {
    margin-top: 22px;
    padding: 30px;
    background: var(--success-light);
    border: 2px solid var(--success);
    border-radius: var(--radius);
    text-align: center;
}
.download-icon { color: var(--success); margin: 0 auto 12px; }
.download-area h3 { font-size: 1.05rem; margin-bottom: 14px; color: #065f46; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* ===== 多图下载 ===== */
.multi-download {
    margin-top: 22px;
    padding: 22px;
    background: var(--primary-light);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
}
.multi-info { margin-bottom: 14px; }
.multi-count { font-size: 1rem; font-weight: 700; color: var(--primary); }
.multi-hint { font-size: .82rem; color: var(--text-light); margin-top: 3px; }

/* ===== 图片网格 ===== */
.img-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    margin-top: 16px;
}
.img-thumb {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    text-align: center;
}
.img-thumb img {
    width: 100%;
    height: 150px;
    object-fit: contain;
    background: #f1f5f9;
}
.img-thumb-label {
    padding: 4px 8px;
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-light);
    background: #f8fafc;
    border-top: 1px solid var(--border);
}
.img-thumb-actions {
    padding: 6px;
    display: flex;
    gap: 4px;
    border-top: 1px solid var(--border);
}
.img-thumb-actions button {
    flex: 1;
    padding: 5px 4px;
    border: 1px solid var(--border);
    background: white;
    border-radius: 6px;
    font-size: .75rem;
    cursor: pointer;
    transition: all .2s;
}
.img-thumb-actions button:hover { background: var(--primary); color: white; border-color: var(--primary); }

/* ===== 文本预览 ===== */
.text-preview {
    margin-top: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.text-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-size: .82rem;
    font-weight: 600;
}
.text-preview pre {
    padding: 14px;
    font-size: .8rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
    background: white;
    font-family: 'Consolas', 'Courier New', monospace;
}

/* ===== PDF预览 ===== */
.pdf-preview {
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.pdf-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-size: .82rem;
    font-weight: 600;
}
.pdf-preview-pages {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px;
    max-height: 400px;
    overflow-y: auto;
    justify-content: center;
    background: #f1f5f9;
}
.pdf-page-thumb {
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all .2s;
}
.pdf-page-thumb:hover { transform: scale(1.04); box-shadow: var(--shadow-md); }
.pdf-page-thumb canvas { display: block; }
.pdf-page-thumb-label {
    padding: 3px 6px;
    text-align: center;
    font-size: .7rem;
    font-weight: 600;
    color: var(--text-light);
    background: white;
}

/* Sortable 拖拽样式 */
.pdf-page-thumb.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}
.pdf-page-thumb.selected .pdf-page-thumb-label {
    background: var(--primary);
    color: white;
}
.sortable-ghost {
    opacity: 0.4;
    background: var(--primary-light);
}
.sortable-chosen {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    transform: scale(1.05) rotate(2deg);
}
.sortable-drag {
    opacity: 1 !important;
}

/* ===== 表格预览 ===== */
.table-list { margin-top: 14px; }
.table-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    overflow: hidden;
}
.table-item-header {
    padding: 9px 14px;
    background: #f8fafc;
    font-size: .82rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}
.table-item-body { padding: 10px; overflow-x: auto; }
.table-item-body table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.table-item-body td, .table-item-body th {
    border: 1px solid var(--border);
    padding: 5px 9px;
    text-align: left;
}

/* ===== 分隔线 ===== */
.divider { height: 1px; background: var(--border); margin: 18px 0; }

/* ===== 提示框 ===== */
.notice {
    padding: 11px 14px;
    border-radius: 8px;
    font-size: .83rem;
    margin: 14px 0;
    border-left: 4px solid;
}
.notice-info { background: #eff6ff; border-color: var(--primary); color: #1e40af; }
.notice-warning { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.notice-success { background: var(--success-light); border-color: var(--success); color: #065f46; }

/* ===== 隐藏 ===== */
.hidden { display: none !important; }

/* ===== 加载遮罩 ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.75);
    backdrop-filter: blur(3px);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
}
.loading-spinner {
    width: 44px; height: 44px;
    border: 4px solid rgba(255,255,255,.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin-bottom: 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: .95rem; font-weight: 500; }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 76px;
    right: 18px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 9px;
}
.toast {
    min-width: 290px;
    max-width: 390px;
    padding: 13px 16px;
    background: white;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: flex-start;
    gap: 11px;
    animation: slideIn .3s ease;
    border-left: 4px solid;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}
.toast-icon {
    width: 26px; height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: .82rem;
    color: white;
}
.toast-body { flex: 1; }
.toast-title { font-weight: 700; font-size: .88rem; margin-bottom: 2px; }
.toast-msg { font-size: .8rem; color: var(--text-light); }
.toast-close {
    width: 22px; height: 22px;
    border: none;
    background: transparent;
    color: var(--text-light);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    flex-shrink: 0;
}
.toast-close:hover { background: #f1f5f9; color: var(--text); }
.toast-success { border-color: var(--success); }
.toast-success .toast-icon { background: var(--success); }
.toast-error { border-color: var(--danger); }
.toast-error .toast-icon { background: var(--danger); }
.toast-info { border-color: var(--primary); }
.toast-info .toast-icon { background: var(--primary); }
.toast-warning { border-color: #f59e0b; }
.toast-warning .toast-icon { background: #f59e0b; }

/* ===== 响应式 ===== */
@media (max-width: 640px) {
    .tools-grid { grid-template-columns: 1fr 1fr; }
    .option-row { flex-direction: column; }
    .workspace-body { padding: 14px; }
    .toast { min-width: auto; }
    .img-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
}
