/* PDF Merger & Editor — style.css */

/* ── Tokens ─────────────────────────────────────────────── */
:root {
    --bg: #0F1117;
    --bg2: #16181F;
    --surface: #1E2028;
    --surface2: #252830;
    --border: #2E3040;
    --primary: #4F8EF7;
    --accent: #7C5CFC;
    --danger: #EF4444;
    --success: #34D399;
    --warning: #FBBF24;
    --text: #E4E6EF;
    --muted: #6B7280;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

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

html {
    scroll-behavior: smooth;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ── Header ──────────────────────────────────────────────── */
header {
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 14px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

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

.logo-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 4px 14px rgba(79, 142, 247, 0.3);
}

.logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.logo h1 span {
    color: var(--primary);
}

.tagline {
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 2px;
}

.privacy-badge {
    background: rgba(52, 211, 153, 0.08);
    border: 1px solid rgba(52, 211, 153, 0.25);
    color: var(--success);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
}

/* ── Toolbar ──────────────────────────────────────────────── */
.toolbar {
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 10px 0;
}

.toolbar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-group:nth-child(2) {
    flex: 1;
    flex-wrap: wrap;
    justify-content: center;
}

.split-range-wrap {
    display: flex;
    gap: 4px;
}

.txt-input {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 7px;
    padding: 6px 10px;
    font-size: 0.78rem;
    outline: none;
    width: 160px;
    transition: border-color 0.2s;
}

.txt-input:focus {
    border-color: var(--primary);
}

.txt-input::placeholder {
    color: var(--muted);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.18s;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed !important;
}

.btn:active:not(:disabled) {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #3d7ae3;
    box-shadow: 0 3px 12px rgba(79, 142, 247, 0.35);
}

.btn-accent {
    background: var(--accent);
    color: #fff;
}

.btn-accent:hover:not(:disabled) {
    background: #6848e0;
    box-shadow: 0 3px 12px rgba(124, 92, 252, 0.35);
}

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    border-color: #4B5563;
    background: #2D3140;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.btn-danger:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.2);
}

.btn-danger-sm {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 5px 10px;
    font-size: 0.75rem;
    border-radius: 6px;
    cursor: pointer;
}

.btn-danger-sm:hover {
    background: rgba(239, 68, 68, 0.2);
}

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    color: var(--text);
    border-color: #4B5563;
}

/* ── Drop Zone ───────────────────────────────────────────── */
#drop-zone {
    margin: 30px auto;
    max-width: 600px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s;
}

#drop-zone:hover,
#drop-zone.drag-over {
    border-color: var(--primary);
    background: rgba(79, 142, 247, 0.05);
}

#drop-zone.hidden {
    display: none;
}

.drop-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.drop-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    mb: 6px;
}

.drop-sub {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 8px;
}

.drop-privacy {
    font-size: 0.76rem;
    color: var(--success);
    margin-top: 16px;
    background: rgba(52, 211, 153, 0.06);
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid rgba(52, 211, 153, 0.2);
}

/* ── File Summary Bar ────────────────────────────────────── */
.file-summary-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.file-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.75rem;
    color: var(--text);
}

.file-chip .file-name {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-chip .file-size {
    color: var(--muted);
}

.file-chip .remove-file {
    color: var(--muted);
    cursor: pointer;
    padding: 0 2px;
    transition: color 0.15s;
    border: none;
    background: transparent;
}

.file-chip .remove-file:hover {
    color: var(--danger);
}

/* ── Page Grid ───────────────────────────────────────────── */
.page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 80px;
    /* space for action bar */
}

/* ── Page Card ───────────────────────────────────────────── */
.page-card {
    position: relative;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: grab;
    transition: border-color 0.18s, box-shadow 0.18s, transform 0.15s;
    user-select: none;
}

.page-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(79, 142, 247, 0.2);
}

.page-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 142, 247, 0.25);
}

.page-card.drag-over-card {
    border-color: var(--accent);
    transform: scale(1.02);
}

.page-card.dragging {
    opacity: 0.4;
    cursor: grabbing;
}

.page-thumb {
    width: 100%;
    aspect-ratio: 0.707;
    /* A4 ratio */
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: #666;
    overflow: hidden;
}

.page-thumb canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.page-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.65), transparent);
}

.page-overlay input[type=checkbox] {
    accent-color: var(--primary);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.page-actions {
    display: flex;
    gap: 3px;
}

.page-btn {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    border-radius: 4px;
    padding: 2px 5px;
    font-size: 0.65rem;
    cursor: pointer;
    transition: background 0.15s;
}

.page-btn:hover {
    background: rgba(79, 142, 247, 0.6);
}

.page-footer {
    padding: 5px 8px;
    border-top: 1px solid var(--border);
    font-size: 0.65rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface2);
}

.page-num-badge {
    font-weight: 600;
    color: var(--text);
    font-size: 0.68rem;
}

.rotate-indicator {
    position: absolute;
    bottom: 28px;
    right: 4px;
    background: rgba(79, 142, 247, 0.7);
    color: #fff;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.62rem;
    display: none;
}

/* ── Action Bar ──────────────────────────────────────────── */
.action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    z-index: 90;
}

.action-bar.hidden {
    display: none;
}

.count-label {
    font-size: 0.78rem;
    color: var(--muted);
    flex: 1;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.hidden {
    display: none;
}

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
}

.preview-modal-box {
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.modal-title {
    font-size: 0.9rem;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1.1rem;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--text);
}

.preview-canvas {
    max-width: 80vw;
    max-height: 75vh;
    border-radius: var(--radius);
    object-fit: contain;
}

/* ── Loading ──────────────────────────────────────────────── */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
}

#loading-overlay.hidden {
    display: none;
}

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

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

.loading-msg {
    color: var(--text);
    font-size: 0.85rem;
}

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

/* ── Toast ───────────────────────────────────────────────── */
#toast-wrap {
    position: fixed;
    bottom: 72px;
    right: 20px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 0.83rem;
    color: var(--text);
    max-width: 280px;
    box-shadow: var(--shadow);
    animation: toast-in 0.22s ease;
}

.toast.success {
    border-color: rgba(52, 211, 153, 0.4);
    color: var(--success);
}

.toast.error {
    border-color: rgba(239, 68, 68, 0.35);
    color: var(--danger);
}

@keyframes toast-in {
    from {
        transform: translateX(30px);
        opacity: 0;
    }
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
    .page-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    }

    .toolbar-inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .split-range-wrap {
        flex-wrap: wrap;
    }
}