/* ===== CSS Variables & Reset ===== */
:root {
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --primary-dark: #1d4ed8;
    --primary-glow: rgba(37, 99, 235, 0.15);
    --accent: #0ea5e9;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-body: #f0f4f8;
    --bg-card: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.72);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --shadow-glow: 0 0 20px var(--primary-glow);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --font: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg-body);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(37, 99, 235, 0.08), transparent),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(14, 165, 233, 0.06), transparent);
}

/* ===== Header ===== */
.app-header {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px 20px;
}

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

.logo-icon {
    font-size: 36px;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ===== Main ===== */
.app-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px 20px 100px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ===== Upload Zone ===== */
.upload-section {
    animation: fadeInUp 0.5s ease;
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-xl);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--bg-card);
    position: relative;
    overflow: hidden;
}

.upload-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--primary-glow), rgba(14, 165, 233, 0.05));
    opacity: 0;
    transition: var(--transition);
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.upload-zone:hover::before,
.upload-zone.drag-over::before {
    opacity: 1;
}

.upload-zone.drag-over {
    border-color: var(--primary);
    border-style: solid;
}

.upload-icon {
    color: var(--primary-light);
    margin-bottom: 16px;
    position: relative;
    z-index: 1;
}

.upload-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    position: relative;
    z-index: 1;
}

.upload-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.7;
    position: relative;
    z-index: 1;
}

/* ===== File List Section ===== */
.file-list-section {
    animation: fadeInUp 0.5s ease;
}

.section-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
}

.section-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.file-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ===== File Card ===== */
.file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    transition: var(--transition);
    cursor: grab;
    position: relative;
    overflow: hidden;
}

.file-card:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-sm);
}

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

.file-card.sortable-chosen {
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
    transform: scale(1.02);
    z-index: 10;
    background: #fafbff;
}

.file-card.sortable-ghost {
    opacity: 0.3;
}

.file-card .drag-handle {
    color: var(--text-muted);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    font-size: 1.1rem;
    cursor: grab;
    padding: 4px;
    user-select: none;
}

.file-card .file-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--border-light);
}

.file-card .file-icon.pdf { background: #fef2f2; }
.file-card .file-icon.image { background: #f0fdf4; }

.file-card .file-info {
    flex: 1;
    min-width: 0;
}

.file-card .file-name {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-card .file-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}

.file-card .status-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 999px;
    font-weight: 500;
}

.status-badge.unlocked {
    background: #ecfdf5;
    color: #059669;
}

.status-badge.locked {
    background: #fef3c7;
    color: #d97706;
}

.status-badge.processing {
    background: #eff6ff;
    color: #2563eb;
}

.file-card .btn-remove {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: var(--transition);
}

.file-card .btn-remove:hover {
    background: #fef2f2;
    color: var(--danger);
}

/* ===== Buttons ===== */
.btn {
    border: none;
    cursor: pointer;
    font-family: var(--font);
    font-weight: 500;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    padding: 14px 32px;
    border-radius: var(--radius-md);
    font-size: 1rem;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.45);
}

.btn-primary:active {
    transform: translateY(0);
}

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

.btn-text {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.btn-text:hover {
    background: #fef2f2;
    color: var(--danger);
}

.btn-clear {
    margin-top: 12px;
}

/* ===== Output Section ===== */
.output-section {
    animation: fadeInUp 0.5s ease;
}

.output-controls {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.filename-input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filename-input-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-wrapper {
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-wrapper input {
    flex: 1;
    border: none;
    outline: none;
    padding: 10px 14px;
    font-size: 0.95rem;
    font-family: var(--font);
    color: var(--text-primary);
    min-width: 0;
}

.input-suffix {
    padding: 10px 14px;
    background: var(--border-light);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    border-left: 1px solid var(--border);
    white-space: nowrap;
}

.btn-merge {
    width: 100%;
}

.btn-icon {
    font-size: 1.2rem;
}

/* ===== Progress ===== */
.progress-wrapper {
    margin-top: 16px;
    animation: fadeInUp 0.3s ease;
}

.progress-bar {
    height: 6px;
    background: var(--border-light);
    border-radius: 999px;
    overflow: hidden;
}

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

.progress-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 8px;
}

/* ===== Footer ===== */
.app-footer {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.78rem;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    box-shadow: var(--shadow-lg);
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: toastIn 0.35s ease, toastOut 0.35s ease 2.65s forwards;
    pointer-events: auto;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--primary); }

/* ===== Animations ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-12px);
    }
}

/* ===== Responsive ===== */
@media (min-width: 640px) {
    .app-main {
        padding: 32px 20px 100px;
        gap: 28px;
    }

    .upload-zone {
        padding: 64px 32px;
    }

    .output-controls {
        flex-direction: row;
        align-items: flex-end;
    }

    .filename-input-group {
        flex: 1;
    }

    .btn-merge {
        width: auto;
        white-space: nowrap;
    }
}

@media (max-width: 380px) {
    .logo-text h1 {
        font-size: 1.1rem;
    }

    .subtitle {
        font-size: 0.72rem;
    }

    .upload-zone {
        padding: 36px 16px;
    }

    .file-card {
        padding: 12px;
        gap: 8px;
    }

    .file-card .file-icon {
        width: 34px;
        height: 34px;
        font-size: 1.2rem;
    }
}
