/* ===== 全局样式 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

:root {
    --primary: #e74c3c;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --border: #e1e8ed;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-hover: 0 8px 30px rgba(0,0,0,0.12);
    --transition: 0.25s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== 导航栏 ===== */
.navbar {
    background: white;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.navbar-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    font-size: 18px;
    font-weight: 700;
}

.btn-home {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
}

.btn-home:hover { background: var(--bg); }

/* ===== 主容器 ===== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ===== 视图切换 ===== */
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== 首页 ===== */
.hero {
    text-align: center;
    padding: 48px 0 36px;
}

.hero h1 {
    font-size: 36px;
    font-weight: 800;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #e74c3c, #9b59b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    color: var(--text-light);
    font-size: 16px;
}

/* ===== 卡片网格 ===== */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    padding-bottom: 40px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 32px 24px;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    box-shadow: var(--shadow);
    text-align: center;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    border-color: var(--card-color, var(--primary));
}

.card-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    color: var(--card-color, var(--primary));
}

.card-icon svg { width: 100%; height: 100%; }

.card h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
}

.card p {
    font-size: 14px;
    color: var(--text-light);
    line-height: 1.5;
}

/* ===== 工具页头 ===== */
.tool-header {
    text-align: center;
    padding: 32px 0 24px;
}

.tool-header h2 { font-size: 28px; font-weight: 700; }
.tool-header p { color: var(--text-light); margin-top: 8px; }

/* ===== 上传区域 ===== */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    transition: var(--transition);
    background: white;
    cursor: pointer;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary);
    background: #fef5f5;
}

.upload-area.half {
    flex: 1;
    padding: 32px 16px;
}

.upload-content p { margin: 16px 0 4px; font-size: 15px; color: var(--text-light); }
.upload-content small { color: var(--text-light); font-size: 13px; }

.upload-btn {
    color: var(--primary);
    cursor: pointer;
    font-weight: 600;
    text-decoration: underline;
}

.file-name {
    margin-top: 8px;
    font-size: 13px;
    color: var(--primary);
    font-weight: 600;
    word-break: break-all;
}

.diff-upload-row {
    display: flex;
    gap: 16px;
}

/* ===== 工作区 ===== */
.workspace {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    margin-top: 16px;
    box-shadow: var(--shadow);
}

.workspace-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.workspace-action-btn {
    white-space: nowrap;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-light);
}

.toolbar select, .toolbar input[type="text"] {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.page-range-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-range-input input {
    width: 160px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}

/* ===== 按钮 ===== */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
}

.btn:hover { background: var(--bg); }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover { background: #c0392b; }

.btn-lg { padding: 12px 32px; font-size: 16px; }

.btn-danger { color: #e74c3c; border-color: #e74c3c; }
.btn-danger:hover { background: #fef5f5; }

.selected-count {
    font-size: 13px;
    color: var(--text-light);
    margin-left: auto;
}

/* ===== 页面网格 ===== */
.page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    padding: 16px 0;
    min-height: 100px;
}

.page-thumb {
    position: relative;
    border: 2px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    background: white;
}

.page-thumb:hover { border-color: #aaa; }

.page-thumb.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.2);
}

.page-thumb canvas {
    width: 100%;
    display: block;
    background: white;
    transform-origin: center center;
    transition: transform 0.2s ease;
}

.page-thumb.is-loading canvas {
    min-height: 180px;
    background: linear-gradient(90deg, #eef2f5 25%, #f7f9fb 50%, #eef2f5 75%);
    background-size: 220% 100%;
    animation: thumbShimmer 1.2s linear infinite;
}

.page-thumb.thumb-error canvas {
    min-height: 180px;
    background: #fdf1f0;
}

@keyframes thumbShimmer {
    from { background-position: 200% 0; }
    to { background-position: -20% 0; }
}

.page-thumb .page-num {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.6);
    color: white;
    text-align: center;
    font-size: 12px;
    padding: 4px;
}

.page-thumb .rotation-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--primary);
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
}

.hint {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 8px;
}

/* ===== 操作栏 ===== */
.action-bar {
    text-align: center;
    padding: 24px 0 8px;
}

.compress-action-bar {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* ===== 文件列表 ===== */
.file-list {
    min-height: 80px;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: grab;
    transition: var(--transition);
}

.file-item:active { cursor: grabbing; }

.file-item.sortable-ghost {
    opacity: 0.4;
    background: #dfe6e9;
}

.file-item .drag-handle {
    color: #bdc3c7;
    cursor: grab;
    font-size: 18px;
    width: 18px;
    text-align: center;
    flex: 0 0 18px;
}

.file-item .file-order {
    min-width: 42px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-light);
}

.file-item .file-info {
    flex: 1;
}

.file-item .file-info .name {
    font-weight: 500;
    font-size: 14px;
    word-break: break-all;
}

.file-item .file-info .meta {
    font-size: 12px;
    color: var(--text-light);
}

.file-item .file-preview {
    width: 48px;
    height: 48px;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid var(--border);
}

.file-item .btn-remove {
    background: none;
    border: none;
    color: #bdc3c7;
    cursor: pointer;
    font-size: 20px;
    padding: 4px 8px;
    transition: var(--transition);
}

.file-item .btn-remove:hover { color: #e74c3c; }

/* ===== 压缩选项 ===== */
.compress-options {
    padding: 16px 0;
}

.compress-options h3 {
    font-size: 16px;
    margin-bottom: 12px;
}

.radio-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.radio-card {
    flex: 1;
    min-width: 160px;
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.radio-card:hover { border-color: #aaa; }

.radio-card.active,
.radio-card:has(input:checked) {
    border-color: var(--primary);
    background: #fef5f5;
}

.radio-card input { display: none; }

.radio-content strong { display: block; margin-bottom: 4px; }
.radio-content span { font-size: 13px; color: var(--text-light); }

.compress-target {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 16px;
    transition: var(--transition);
}

.compress-target label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-light);
}

.compress-target.is-disabled {
    opacity: 0.55;
}

.compress-target input[type="number"] {
    width: 88px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}

.compress-file-card {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: linear-gradient(135deg, #f7fbf8, #eef7f1);
}

.compress-file-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: #dff3e6;
    color: #1f8f52;
    flex-shrink: 0;
}

.compress-file-body {
    min-width: 0;
}

.compress-file-label {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 4px;
}

.compress-file-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    word-break: break-all;
}

.compress-file-meta {
    margin-top: 4px;
    font-size: 13px;
    color: var(--text-light);
}

.compress-guide {
    margin-bottom: 18px;
    padding: 16px 18px;
    border: 1px solid #f4d4b8;
    border-radius: 12px;
    background: linear-gradient(135deg, #fff9f2, #fff2e3);
}

.compress-guide-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.compress-guide-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(230, 126, 34, 0.14);
    color: #c96f1c;
    font-size: 12px;
    font-weight: 700;
}

.compress-guide-text {
    margin: 0;
    font-size: 14px;
    color: var(--text);
    line-height: 1.7;
}

.compress-guide-note {
    margin: 8px 0 0;
    font-size: 13px;
    color: var(--text-light);
    line-height: 1.6;
}

.compress-guide-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.size-compare {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 24px;
}

.size-box { text-align: center; }

.compress-result-actions {
    display: flex;
    justify-content: center;
    padding: 0 24px 24px;
}

.size-label {
    display: block;
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 4px;
}

.size-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}

.size-arrow {
    font-size: 28px;
    color: var(--text-light);
}

/* ===== 转换标签页 ===== */
.convert-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.tab-btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.tab-btn:hover:not(.active) { background: var(--bg); }

.convert-panel { display: none; }
.convert-panel.active { display: block; }

.text-result {
    width: 100%;
    min-height: 300px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.8;
    resize: vertical;
    font-family: inherit;
}

/* ===== 差异比较 ===== */
.diff-view {
    display: flex;
    gap: 12px;
}

.diff-col {
    flex: 1;
    text-align: center;
}

.diff-col h4 {
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-light);
}

.diff-col canvas {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 4px;
}

/* ===== 编辑器 ===== */
.editor-toolbar {
    flex-wrap: wrap;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tool-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.tool-options {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tool-options input[type="text"] {
    width: 120px;
}

.tool-options input[type="color"] {
    width: 32px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
}

.tool-options input[type="number"] {
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.range-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-light);
}

.range-inline input[type="range"] {
    width: 120px;
}

.range-inline input[type="number"] {
    width: 72px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-variant-numeric: tabular-nums;
}

#editorColorPick.is-active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.canvas-container {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: #e8e8e8;
    min-height: 400px;
}

.canvas-container canvas {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

#editorCanvasBg { z-index: 1; }
#editorCanvasFg {
    z-index: 2;
    cursor: crosshair;
    touch-action: none;
}
#editorCanvasText {
    z-index: 3;
    pointer-events: none;
}
#editorCanvasUi {
    z-index: 4;
    pointer-events: none;
}

.editor-text-layer {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    pointer-events: none;
    touch-action: none;
}

.editor-text-layer.text-tool-active {
    pointer-events: none;
}

.editor-text-layer:not(.text-tool-active) .editor-text-item {
    pointer-events: none;
}

.editor-text-item {
    position: absolute;
    display: inline-block;
    margin: 0;
    padding: 0;
    white-space: pre;
    line-height: 1;
    user-select: none;
    pointer-events: auto;
    cursor: move;
    border-radius: 2px;
    transform-origin: top left;
}

.editor-hit-text {
    display: block;
    white-space: pre;
    line-height: inherit;
    letter-spacing: inherit;
    color: transparent;
    opacity: 0;
    pointer-events: none;
    user-select: none;
}

.editor-inline-input {
    display: block;
    width: 100%;
    min-width: 100%;
    height: 100%;
    min-height: 100%;
    box-sizing: border-box;
    border: none;
    outline: none;
    background: transparent;
    color: inherit;
    caret-color: currentColor;
    font: inherit;
    line-height: inherit;
    letter-spacing: inherit;
    padding: 0;
    margin: 0;
}

.editor-text-item.selected {
    outline: 1px dashed rgba(231, 76, 60, 0.9);
    background: rgba(255, 255, 255, 0.18);
    box-shadow: 0 0 0 1px rgba(231, 76, 60, 0.16);
}

/* ===== 水印设置 ===== */
.watermark-settings {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 24px;
    padding: 16px 0;
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.setting-row label {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    min-width: 80px;
}

.setting-row input[type="text"] {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}

.setting-row input[type="number"],
.setting-row select {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
}

.setting-row input[type="range"] {
    flex: 1;
}

.setting-row input[type="color"] {
    width: 40px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
}

.setting-row span {
    font-size: 13px;
    color: var(--text-light);
    min-width: 36px;
}

.preview-area {
    text-align: center;
    padding: 16px 0;
}

.preview-area h4 {
    margin-bottom: 8px;
    color: var(--text-light);
}

.preview-area canvas {
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.page-number-settings {
    padding-bottom: 8px;
}

.page-number-summary {
    grid-column: 1 / -1;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-light);
    font-size: 14px;
}

.preview-toolbar {
    justify-content: center;
    margin-bottom: 12px;
}

.preview-toolbar span {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

/* ===== 加载遮罩 ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.progress-bar {
    width: 240px;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    margin: 12px auto 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}

.loading-cancel-btn {
    margin-top: 16px;
}

/* ===== Toast 通知 ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

.toast.success { background: #2ecc71; }
.toast.error { background: #e74c3c; }
.toast.info { background: #3498db; }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .container { padding: 16px; }
    .hero { padding: 32px 0 24px; }
    .hero h1 { font-size: 28px; }
    .cards-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
    .card { padding: 24px 16px; }
    .diff-upload-row { flex-direction: column; }
    .diff-view { flex-direction: column; }
    .radio-group { flex-direction: column; }
    .watermark-settings { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-actions { margin-left: 0; justify-content: center; }
    .page-range-input { flex-wrap: wrap; }
    .editor-toolbar .tool-group { width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
    .cards-grid { grid-template-columns: 1fr; }
    .page-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}
