/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #7C3AED;
    --primary-dark: #6D28D9;
    --primary-light: #A78BFA;
    --primary-glow: rgba(124, 58, 237, 0.35);
    --accent: #06B6D4;
    --accent-dark: #0891B2;
    --accent-light: #67E8F9;
    --bg-body: #0B0D17;
    --bg-surface: #12141F;
    --bg-card: #1A1D2E;
    --bg-card-alt: #1F2237;
    --bg-hover: #252842;
    --text-white: #F8FAFC;
    --text-light: #CBD5E1;
    --text-muted: #64748B;
    --text-dim: #475569;
    --success: #10B981;
    --success-glow: rgba(16, 185, 129, 0.25);
    --error: #EF4444;
    --warning: #F59E0B;
    --border: rgba(124, 58, 237, 0.15);
    --border-light: rgba(203, 213, 225, 0.08);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.3);
    --shadow-lg: 0 20px 60px rgba(0,0,0,0.4);
    --shadow-glow: 0 0 40px var(--primary-glow);
    --radius: 14px;
    --radius-sm: 8px;
    --radius-xs: 5px;
    --speed: 0.25s;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-body);
    color: var(--text-white);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ===== ANIMATED BG ===== */
.bg-decor {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}
.bg-decor .blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.12;
    animation: blobDrift 25s ease-in-out infinite alternate;
}
.bg-decor .blob:nth-child(1) { width: 600px; height: 600px; background: var(--primary); top: -15%; left: -10%; }
.bg-decor .blob:nth-child(2) { width: 450px; height: 450px; background: var(--accent); bottom: -10%; right: -8%; animation-delay: -8s; }
.bg-decor .blob:nth-child(3) { width: 350px; height: 350px; background: #EC4899; top: 40%; left: 55%; animation-delay: -16s; }

@keyframes blobDrift {
    0%   { transform: translate(0, 0) scale(1); }
    33%  { transform: translate(50px, -60px) scale(1.08); }
    66%  { transform: translate(-30px, 40px) scale(0.95); }
    100% { transform: translate(20px, -20px) scale(1.03); }
}

/* ===== APP SHELL ===== */
.app-shell {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== HEADER ===== */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 24px;
    background: rgba(18, 20, 31, 0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 56px;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.brand-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: var(--shadow-glow);
}

.brand-name {
    font-size: 17px;
    font-weight: 700;
    white-space: nowrap;
}

.brand-name em {
    font-style: normal;
    background: linear-gradient(135deg, var(--primary-light), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ===== MAIN LAYOUT ===== */
.main-area {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ===== UPLOAD VIEW ===== */
.upload-view {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.drop-zone {
    width: 100%;
    max-width: 640px;
    padding: 56px 36px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    transition: all var(--speed) ease;
    background: rgba(26, 29, 46, 0.6);
    backdrop-filter: blur(10px);
    position: relative;
}

.drop-zone:hover, .drop-zone.drag-active {
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: var(--shadow-glow);
}

.drop-zone.drag-active {
    border-color: var(--accent);
    background: rgba(6, 182, 212, 0.04);
}

.drop-icon {
    width: 76px;
    height: 76px;
    margin: 0 auto 18px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 34px;
    box-shadow: 0 8px 30px var(--primary-glow);
    animation: gentlePulse 3s ease-in-out infinite;
}

@keyframes gentlePulse {
    0%, 100% { transform: scale(1); box-shadow: 0 8px 30px var(--primary-glow); }
    50% { transform: scale(1.06); box-shadow: 0 12px 40px var(--primary-glow); }
}

.drop-title {
    font-size: 21px;
    font-weight: 700;
    margin-bottom: 6px;
}

.drop-sub {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 20px;
}

.drop-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 26px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--speed) ease;
    box-shadow: 0 4px 16px var(--primary-glow);
}

.drop-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--primary-glow);
}

.drop-note {
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-dim);
}

/* ===== EDITOR VIEW ===== */
.editor-view {
    flex: 1;
    display: none;
    overflow: hidden;
}

.editor-view.active {
    display: flex;
}

/* ===== SIDEBAR (settings) ===== */
.sidebar {
    width: 320px;
    background: rgba(18, 20, 31, 0.9);
    backdrop-filter: blur(16px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-header .file-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #EF4444, #DC2626);
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-header .file-meta h4 {
    font-size: 13px;
    font-weight: 600;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-header .file-meta span {
    font-size: 11px;
    color: var(--text-muted);
}

/* ===== SIDEBAR SECTIONS ===== */
.sb-section {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-light);
}

.sb-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Form controls */
.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 10px;
}

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

.control-row label {
    font-size: 13px;
    color: var(--text-light);
    flex-shrink: 0;
}

.control-row select,
.control-row input[type="number"],
.control-row input[type="text"] {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-white);
    padding: 7px 10px;
    border-radius: var(--radius-xs);
    font-size: 13px;
    outline: none;
    transition: border var(--speed) ease;
    flex: 1;
    min-width: 0;
    max-width: 160px;
}

.control-row select:focus,
.control-row input:focus {
    border-color: var(--primary);
}

.control-row select option {
    background: var(--bg-card);
}

.control-row input[type="number"] {
    max-width: 80px;
}

/* Color picker */
.color-pick-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    max-width: 160px;
    justify-content: flex-end;
}

.color-pick-wrap input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    width: 32px;
    height: 32px;
    border: 2px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    background: none;
    padding: 2px;
}

.color-pick-wrap input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-pick-wrap input[type="color"]::-webkit-color-swatch { border: none; border-radius: 3px; }

.color-hex {
    font-size: 12px;
    color: var(--text-muted);
    font-family: monospace;
}

/* Position grid */
.position-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-top: 4px;
}

.pos-cell {
    padding: 10px 4px;
    background: var(--bg-card);
    border: 2px solid transparent;
    border-radius: var(--radius-xs);
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--speed) ease;
    user-select: none;
}

.pos-cell:hover {
    background: var(--bg-hover);
    color: var(--text-light);
}

.pos-cell.active {
    background: rgba(124, 58, 237, 0.15);
    border-color: var(--primary);
    color: var(--primary-light);
}

/* Page range */
.range-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    max-width: 160px;
}

.range-inputs input {
    width: 55px !important;
    max-width: 55px !important;
    text-align: center;
}

.range-inputs span {
    color: var(--text-muted);
    font-size: 13px;
}

/* Checkbox toggle */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

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

.toggle-row label {
    font-size: 13px;
    color: var(--text-light);
    cursor: pointer;
}

.toggle-switch {
    position: relative;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    cursor: pointer;
    transition: var(--speed);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-muted);
    top: 2px;
    left: 3px;
    transition: var(--speed);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(17px);
    background: white;
}

/* Format preview */
.format-preview {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    text-align: center;
    margin-top: 12px;
}

.format-preview-label {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.format-preview-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-light);
}

/* ===== SIDEBAR ACTIONS ===== */
.sidebar-actions {
    padding: 16px 20px;
    margin-top: auto;
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--speed) ease;
    white-space: nowrap;
}

.btn-lg {
    padding: 12px 20px;
    font-size: 14px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 16px var(--primary-glow);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 24px var(--primary-glow);
}

.btn-success {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
    box-shadow: 0 4px 12px var(--success-glow);
}
.btn-success:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px var(--success-glow);
}

.btn-outline {
    background: transparent;
    color: var(--text-light);
    border: 1px solid var(--border);
}
.btn-outline:hover {
    border-color: var(--primary);
    color: var(--text-white);
    background: rgba(124, 58, 237, 0.08);
}

.btn-ghost {
    background: rgba(239, 68, 68, 0.08);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-ghost:hover {
    background: rgba(239, 68, 68, 0.15);
}

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

.btn-block { width: 100%; }

/* ===== PREVIEW PANEL ===== */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-surface);
}

/* Preview toolbar */
.preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: rgba(18, 20, 31, 0.7);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    gap: 12px;
}

.preview-toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.preview-toolbar-center {
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.page-nav-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-light);
    cursor: pointer;
    transition: var(--speed);
    font-size: 14px;
}

.page-nav-btn:hover { border-color: var(--primary); color: var(--text-white); }
.page-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.page-indicator {
    font-size: 13px;
    color: var(--text-light);
    min-width: 80px;
    text-align: center;
}

.page-indicator strong {
    color: var(--text-white);
}

.zoom-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.zoom-label {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 36px;
    text-align: center;
}

/* Preview canvas area */
.preview-canvas-area {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px;
    background: repeating-conic-gradient(rgba(255,255,255,0.02) 0% 25%, transparent 0% 50%) 50% / 24px 24px;
}

.preview-canvas-area::-webkit-scrollbar { width: 8px; height: 8px; }
.preview-canvas-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.preview-page-wrap {
    position: relative;
    box-shadow: var(--shadow-lg);
    border-radius: 4px;
    overflow: hidden;
    background: white;
    line-height: 0;
}

.preview-page-wrap canvas {
    display: block;
}

/* Page number overlay on preview */
.preview-number-overlay {
    position: absolute;
    pointer-events: none;
    z-index: 5;
}

/* ===== PROGRESS OVERLAY ===== */
.processing-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 13, 23, 0.88);
    backdrop-filter: blur(10px);
    z-index: 500;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.processing-overlay.active {
    display: flex;
}

.processing-overlay .spinner-ring {
    width: 56px;
    height: 56px;
    border: 4px solid var(--border);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.processing-overlay .proc-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-light);
}

.processing-overlay .proc-sub {
    font-size: 13px;
    color: var(--text-muted);
}

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

/* ===== TOAST ===== */
.toast-stack {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast-item {
    pointer-events: auto;
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    backdrop-filter: blur(16px);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 500;
    animation: toastSlideIn 0.35s ease;
    max-width: 360px;
}

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

.toast-item.leaving {
    animation: toastSlideOut 0.3s ease forwards;
}

@keyframes toastSlideIn  { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastSlideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(110%); opacity: 0; } }

/* ===== LOADING SCREEN ===== */
.boot-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-body);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    transition: opacity 0.5s ease;
}

.boot-screen.done { opacity: 0; pointer-events: none; }

.boot-screen .boot-title {
    font-size: 22px;
    font-weight: 700;
}

.boot-screen .boot-title em {
    font-style: normal;
    background: linear-gradient(135deg, var(--primary-light), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.boot-screen .spinner-ring {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===== FOOTER ===== */
.bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 24px;
    background: rgba(18, 20, 31, 0.85);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-dim);
}

.bottom-bar-right {
    display: flex;
    gap: 16px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    .main-area { flex-direction: column; }

    .sidebar {
        width: 100%;
        max-height: 45vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .preview-canvas-area { padding: 16px; }
}

@media (max-width: 600px) {
    .top-bar { padding: 8px 14px; }
    .brand-name { font-size: 14px; }
    .sb-section { padding: 14px 14px; }
    .sidebar { max-height: 50vh; }
    .preview-toolbar { padding: 8px 12px; flex-wrap: wrap; }
    .control-row label { font-size: 12px; }
    .position-grid { gap: 4px; }
    .pos-cell { padding: 8px 2px; font-size: 10px; }
}

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
