/* ============================================
   万能文档工具箱 - Styles
   ============================================ */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #222536;
    --bg-card-hover: #2a2e42;
    --bg-surface: #161925;
    --bg-input: #1e2235;
    --border-color: #2e3348;
    --border-active: #6c5ce7;
    --text-primary: #e8eaf0;
    --text-secondary: #8b90a5;
    --text-muted: #5a5f78;
    --accent-pdf: #e74c3c;
    --accent-pdf-light: #ff6b6b;
    --accent-img: #6c5ce7;
    --accent-img-light: #a29bfe;
    --accent-success: #00b894;
    --accent-warning: #fdcb6e;
    --accent-info: #74b9ff;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ---- App Layout ---- */
#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ---- Header ---- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 32px;
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-title {
    font-size: 22px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: color var(--transition);
}

.app-title:hover {
    color: var(--accent-pdf-light);
}

.title-icon {
    font-size: 28px;
    color: var(--accent-pdf);
}

.back-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
}

.back-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-img);
}

/* ---- Page Navigation ---- */
.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

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

/* ---- Tool Section ---- */
.tool-section {
    margin-bottom: 48px;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}

.section-icon {
    font-size: 28px;
}

.pdf-icon { color: var(--accent-pdf); }
.img-icon { color: var(--accent-img); }

.section-header h2 {
    font-size: 20px;
    font-weight: 600;
}

/* ---- Tools Grid ---- */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.tool-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.tool-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: transparent;
    transition: background var(--transition);
}

.tool-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-active);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.tool-card:hover::before {
    background: linear-gradient(90deg, var(--accent-pdf), var(--accent-img));
}

.tool-icon-wrap {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.tool-icon-wrap .material-icons-round {
    font-size: 24px;
    color: #fff;
}

.pdf-gradient {
    background: linear-gradient(135deg, var(--accent-pdf), #c0392b);
}

.img-gradient {
    background: linear-gradient(135deg, var(--accent-img), #5b4cdb);
}

.tool-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;
}

.tool-card p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ---- Tool Page ---- */
.tool-page-inner {
    max-width: 800px;
    margin: 0 auto;
}

.tool-page-header {
    text-align: center;
    margin-bottom: 32px;
}

.tool-page-header .material-icons-round {
    font-size: 48px;
    color: var(--accent-pdf);
    margin-bottom: 12px;
}

.tool-page-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.tool-page-header p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ---- Upload Area ---- */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-xl);
    padding: 48px 32px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-surface);
    position: relative;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--accent-img);
    background: rgba(108, 92, 231, 0.05);
}

.upload-area.dragover {
    transform: scale(1.01);
}

.upload-icon {
    font-size: 48px;
    color: var(--accent-img);
    margin-bottom: 12px;
    display: block;
}

.upload-content h3 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
}

.upload-content p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ---- File Preview ---- */
.file-preview {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-top: 16px;
}

.file-info-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
}

.file-info-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-info-left .material-icons-round {
    color: var(--accent-pdf);
    font-size: 20px;
}

.file-name {
    font-size: 14px;
    font-weight: 500;
}

.file-size {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-input);
    padding: 2px 8px;
    border-radius: 4px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: rgba(231, 76, 60, 0.15);
    color: var(--accent-pdf);
}

/* ---- PDF Preview ---- */
.preview-container {
    padding: 16px;
}

.pdf-pages {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.pdf-page-thumb {
    background: #fff;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.pdf-page-thumb canvas {
    display: block;
    max-width: 180px;
    height: auto;
}

.pdf-page-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 11px;
    text-align: center;
    padding: 2px;
}

/* ---- Image Thumbnails ---- */
.img-thumbnails {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.img-thumb {
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.img-thumb img {
    display: block;
    max-width: 180px;
    max-height: 180px;
    object-fit: contain;
}

.img-thumb-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 11px;
    text-align: center;
    padding: 2px;
}

/* ---- Options Panel ---- */
.options-panel {
    margin-top: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.option-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.option-row:last-child {
    margin-bottom: 0;
}

.option-label {
    font-size: 14px;
    font-weight: 500;
    min-width: 80px;
    color: var(--text-secondary);
}

.option-input {
    flex: 1;
    height: 40px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    padding: 0 12px;
    outline: none;
    transition: border-color var(--transition);
}

.option-input:focus {
    border-color: var(--accent-img);
}

.option-select {
    flex: 1;
    height: 40px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    padding: 0 12px;
    outline: none;
    cursor: pointer;
}

.range-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.range-input {
    flex: 1;
    -webkit-appearance: none;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    outline: none;
}

.range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-img);
    border-radius: 50%;
    cursor: pointer;
}

.range-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-img-light);
    min-width: 36px;
    text-align: right;
}

/* ---- Watermark Selection ---- */
.watermark-select-area {
    margin-top: 20px;
    text-align: center;
}

.watermark-canvas-wrap {
    position: relative;
    display: inline-block;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: crosshair;
}

.watermark-canvas-wrap canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.selection-box {
    position: absolute;
    border: 2px dashed var(--accent-warning);
    background: rgba(253, 203, 110, 0.15);
    pointer-events: none;
}

.watermark-hint {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ---- Progress Area ---- */
.progress-area {
    margin-top: 24px;
    text-align: center;
}

.progress-bar {
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-img), var(--accent-pdf));
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ---- Action Area ---- */
.action-area {
    margin-top: 24px;
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.btn .material-icons-round {
    font-size: 20px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-img), #5b4cdb);
    color: #fff;
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(108, 92, 231, 0.4);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-success {
    background: linear-gradient(135deg, var(--accent-success), #00a381);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 184, 148, 0.3);
}

.btn-success:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 184, 148, 0.4);
}

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-outline:hover {
    background: var(--bg-card);
    border-color: var(--accent-img);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

.btn-sm .material-icons-round {
    font-size: 16px;
}

/* ---- Result Area ---- */
.result-area {
    margin-top: 32px;
    text-align: center;
    background: var(--bg-card);
    border: 1px solid rgba(0, 184, 148, 0.3);
    border-radius: var(--radius-lg);
    padding: 32px;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

.result-header .material-icons-round {
    font-size: 28px;
    color: var(--accent-success);
}

.result-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--accent-success);
}

.result-preview {
    margin-bottom: 20px;
}

.result-preview img {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.result-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---- Loading Overlay ---- */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 17, 23, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

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

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

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

.loading-overlay p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ---- Toast ---- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    transition: transform 0.3s ease;
    font-size: 14px;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
}

.toast .material-icons-round {
    font-size: 20px;
}

.toast.success .material-icons-round { color: var(--accent-success); }
.toast.error .material-icons-round { color: var(--accent-pdf); }
.toast.info .material-icons-round { color: var(--accent-info); }

/* ---- Utility ---- */
.hidden {
    display: none !important;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    #app {
        padding: 0 16px;
    }

    .app-title {
        font-size: 18px;
    }

    .tools-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 12px;
    }

    .tool-card {
        padding: 16px;
    }

    .tool-icon-wrap {
        width: 40px;
        height: 40px;
    }

    .tool-icon-wrap .material-icons-round {
        font-size: 20px;
    }

    .tool-card h3 {
        font-size: 14px;
    }

    .tool-card p {
        font-size: 12px;
    }

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

    .option-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .option-label {
        min-width: unset;
    }

    .option-input,
    .option-select,
    .range-wrap {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .tools-grid {
        grid-template-columns: 1fr 1fr;
    }

    .tool-page-header .material-icons-round {
        font-size: 36px;
    }

    .tool-page-header h2 {
        font-size: 20px;
    }
}
