:root {
    --primary: #2563eb; --primary-hover: #1d4ed8; --primary-light: #eff6ff;
    --danger: #ef4444; --danger-hover: #dc2626;
    --success: #10b981; --success-hover: #059669;
    --magic: #8b5cf6; --magic-hover: #7c3aed;
    --warn: #f59e0b;
    --bg-main: #eef2f7;
    --bg-surface: #ffffff;
    --bg-sidebar: #f7f9fc;
    --text-main: #0f172a; --text-muted: #64748b;
    --border: #cbd5e1; --border-light: #e2e8f0;
    --sidebar-width: 272px;
    --navbar-h: 56px;
    --actionbar-h: 60px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.13);
    --radius: 10px;
    --radius-lg: 14px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-main);
    height: 100vh;
    display: flex; flex-direction: column;
    overflow: hidden;
    color: var(--text-main);
    font-size: 14px;
}

/* ===== NAVBAR ===== */
.top-navbar {
    flex-shrink: 0;
    height: var(--navbar-h);
    background: var(--bg-surface);
    padding: 0 18px;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 0 rgba(0,0,0,0.05), var(--shadow-sm);
    z-index: 100;
    gap: 10px;
}
.brand { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.btn-home-back {
    width: 30px; height: 30px;
    background: var(--primary-light); border: 1px solid #bfdbfe;
    border-radius: 7px; color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    text-decoration: none; font-size: 12px; transition: 0.15s; flex-shrink: 0;
}
.btn-home-back:hover { background: var(--primary); color: white; border-color: var(--primary); }
.brand-logo {
    width: 32px; height: 32px;
    border-radius: 8px; display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.brand-text { line-height: 1.2; }
.brand-title { font-size: 13px; font-weight: 700; color: var(--text-main); display: block; }
.brand-sub { font-size: 10.5px; color: var(--text-muted); font-weight: 500; }
.brand-badge {
    background: linear-gradient(135deg,#eff6ff,#f5f3ff);
    border: 1px solid #c7d2fe; color: #4f46e5;
    padding: 2px 8px; border-radius: 20px;
    font-size: 10px; font-weight: 800; letter-spacing: 0.4px;
}
.global-controls { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.undo-redo-group {
    display: flex; gap: 2px;
    background: var(--bg-main); border: 1px solid var(--border);
    border-radius: 8px; padding: 2px;
}
.btn-undoredo {
    width: 28px; height: 28px; border-radius: 6px; border: none;
    background: transparent; cursor: pointer; transition: 0.13s;
    display: flex; align-items: center; justify-content: center; font-size: 12px;
}
.btn-undoredo:hover:not(:disabled) { background: white; color: var(--primary); box-shadow: var(--shadow-sm); }
.btn-undoredo:disabled { opacity: 0.28; cursor: not-allowed; color: var(--text-muted); }
.btn-undoredo:not(:disabled) { color: var(--primary); }

input[type="text"], select {
    padding: 7px 10px; border-radius: 8px;
    border: 1px solid var(--border); font-size: 13px;
    font-family: inherit; font-weight: 500; outline: none;
    transition: 0.15s; background: #fff; color: var(--text-main);
}
input[type="text"]:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

/* ===== WORKSPACE ===== */
.workspace { flex-grow: 1; display: flex; overflow: hidden; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width); flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; z-index: 5;
}
.sidebar-top {
    padding: 10px;
    display: flex; gap: 6px;
    border-bottom: 1px solid var(--border-light);
    background: white;
}
.btn-upload-main {
    flex: 1;
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    color: white; border: none;
    padding: 9px 12px; border-radius: var(--radius);
    font-weight: 700; font-size: 13px;
    cursor: pointer; display: flex; align-items: center; gap: 7px;
    transition: 0.18s; box-shadow: 0 2px 10px rgba(37,99,235,0.28);
}
.btn-upload-main:hover { opacity: 0.93; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(37,99,235,0.38); }
.btn-upload-main i:first-child { font-size: 14px; }
.btn-scan-small {
    width: 38px; height: 38px;
    background: white; color: var(--text-muted);
    border: 1.5px solid var(--border);
    border-radius: var(--radius); font-size: 14px;
    cursor: pointer; display: flex; align-items: center; justify-content: center; transition: 0.15s;
}
.btn-scan-small:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

/* Upload dropdown */
.upload-menu {
    position: fixed; background: white;
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); z-index: 9999; min-width: 210px;
    overflow: hidden; animation: menuPop 0.14s ease;
}
@keyframes menuPop { from{opacity:0;transform:scale(0.94) translateY(-5px)} to{opacity:1;transform:scale(1) translateY(0)} }
.upload-menu-item {
    display: flex; align-items: center; gap: 11px;
    padding: 12px 15px; font-size: 13px; font-weight: 600;
    color: var(--text-main); cursor: pointer; transition: 0.13s;
    border: none; background: transparent; width: 100%; text-align: left; font-family: inherit;
}
.upload-menu-item:hover { background: var(--primary-light); color: var(--primary); }
.upload-menu-item i { width: 15px; font-size: 14px; color: var(--primary); }
.um-title { font-size: 13px; font-weight: 700; }
.um-sub { font-size: 11px; color: var(--text-muted); font-weight: 400; margin-top: 1px; }
.upload-menu-item + .upload-menu-item { border-top: 1px solid var(--border-light); }

.page-counter {
    padding: 6px 12px;
    background: linear-gradient(90deg,#eff6ff,#f5f3ff);
    border-bottom: 1px solid #ddd6fe;
    font-size: 11.5px; font-weight: 700; color: #4f46e5;
    display: flex; align-items: center; gap: 6px;
}
.thumb-list-container { flex: 1; overflow-y: auto; padding: 10px; }
.thumb-list { display: flex; flex-direction: column; gap: 9px; list-style: none; }
.thumb-item {
    background: white; border: 1.5px solid var(--border);
    border-radius: var(--radius); padding: 8px;
    cursor: grab; position: relative; transition: 0.16s;
    display: flex; flex-direction: column; align-items: center;
}
.thumb-item:hover { border-color: #93c5fd; box-shadow: 0 2px 8px rgba(37,99,235,0.08); }
.thumb-item.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.thumb-item.drag-over { border-top: 3px solid var(--primary); transform: scale(1.02); }
.thumb-item img { width: 100%; height: 96px; object-fit: contain; border-radius: 6px; background: #f1f5f9; pointer-events: none; }
.thumb-label { margin-top: 5px; font-size: 11px; font-weight: 700; color: var(--text-muted); }
.btn-del-thumb {
    position: absolute; top: -7px; right: -7px;
    background: var(--danger); color: white; border: none;
    width: 21px; height: 21px; border-radius: 50%; font-size: 9px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 5px rgba(239,68,68,0.3); transition: 0.13s;
}
.btn-del-thumb:hover { background: var(--danger-hover); transform: scale(1.1); }

/* ===== EDITOR AREA ===== */
.editor-area {
    flex-grow: 1; display: flex; flex-direction: column;
    background: var(--bg-main); overflow-y: auto; position: relative;
}
.editor-content { padding: 22px; max-width: 920px; margin: 0 auto; width: 100%; }

.empty-state {
    min-height: 65vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--text-muted); text-align: center; gap: 10px;
}
.empty-icon { font-size: 52px; color: #c7d2fe; margin-bottom: 4px; }
.empty-state h2 { font-size: 20px; font-weight: 700; color: #94a3b8; }
.empty-state p { font-size: 13px; color: #94a3b8; line-height: 1.6; }
.empty-hints {
    display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; justify-content: center;
}
.empty-hints span {
    background: white; border: 1px solid var(--border-light);
    padding: 5px 12px; border-radius: 20px;
    font-size: 12px; font-weight: 600; color: var(--text-muted);
    display: flex; align-items: center; gap: 5px;
}
.empty-hints span i { color: var(--primary); }

.page-layer {
    display: none; background: white;
    padding: 20px; border-radius: var(--radius-lg);
    box-shadow: 0 2px 12px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.04);
    border: 1px solid var(--border-light);
}
.page-layer.active { display: block; animation: fadeIn 0.22s ease; }
@keyframes fadeIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }

/* ===== EDITOR TOOLBAR ===== */
.editor-toolbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px; padding-bottom: 14px;
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap; gap: 10px;
}
.tools-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tools-divider {
    width: 1px; height: 28px; background: var(--border-light); margin: 0 2px;
}

/* Tool buttons */
.btn-icon {
    width: 36px; height: 36px; border-radius: 8px;
    border: 1.5px solid var(--border); background: #f8fafc;
    color: var(--text-muted); cursor: pointer; transition: 0.14s;
    display: inline-flex; align-items: center; justify-content: center; font-size: 14px;
    position: relative;
}
.btn-icon:hover { background: #f1f5f9; color: var(--text-main); border-color: #94a3b8; }
.btn-icon.active-tool {
    background: var(--primary); color: white;
    border-color: var(--primary-hover);
    box-shadow: 0 2px 8px rgba(37,99,235,0.3);
}
.btn-icon.btn-magic { background: #faf5ff; color: var(--magic); border-color: #d8b4fe; }
.btn-icon.btn-magic:hover { background: #f3e8ff; color: var(--magic-hover); border-color: #c084fc; }

/* ===== SLIDERS ROW ===== */
.sliders-row {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.range-group {
    display: flex; align-items: center; gap: 7px;
    background: #f8fafc; padding: 6px 10px;
    border-radius: 8px; border: 1px solid var(--border-light);
}
.range-group i { font-size: 12px; color: var(--text-muted); }
.range-group input[type="range"] {
    width: 80px; height: 4px; -webkit-appearance: none;
    background: var(--border); border-radius: 4px; outline: none; margin: 0;
}
.range-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 13px; height: 13px;
    border-radius: 50%; background: var(--primary); cursor: pointer;
}
.range-group .range-val {
    font-size: 11px; font-weight: 700; color: var(--text-muted);
    min-width: 28px; text-align: right;
}

/* ===== BLACK/GRAY DARK SLIDER ===== */
.dark-slider-group {
    display: flex; align-items: center; gap: 7px;
    background: #0f172a; padding: 6px 11px;
    border-radius: 8px; border: 1px solid #1e293b;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.4);
}
.dark-slider-group i { flex-shrink: 0; }
.dsg-label {
    font-size: 10px; font-weight: 700; color: #64748b;
    white-space: nowrap; flex-shrink: 0; min-width: 28px;
}
.dark-slider-group input[type="range"] {
    width: 76px; height: 4px; -webkit-appearance: none;
    background: #334155; border-radius: 4px; outline: none; margin: 0; flex-shrink: 0;
}
.dark-slider-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 13px; height: 13px;
    border-radius: 50%; background: #cbd5e1;
    cursor: pointer; border: 2px solid #475569;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
/* Black slider special gradient track */
#toolbar1 .dark-slider-group:last-child input[type="range"],
[id^="toolbar"] .dark-slider-group:last-child input[type="range"] {
    background: linear-gradient(90deg, #1e293b 0%, #cbd5e1 50%, #f8fafc 100%);
}
.dark-slider-group .range-val,
.dark-slider-group span.range-val {
    font-size: 11px; font-weight: 700; color: #64748b; min-width: 32px; text-align: right;
}
/* bp-preview-canvas stays on top */
.bp-preview-canvas { z-index: 5; }

/* ===== IMAGE AREA ===== */
.img-wrapper {
    width: 100%; height: 60vh; min-height: 380px;
    background: #0f172a; border-radius: var(--radius-lg);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; position: relative;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05), 0 4px 20px rgba(0,0,0,0.15);
    padding: 18px;
}
.perspective-container {
    position: relative; display: inline-block; line-height: 0;
    max-width: 100%; max-height: 100%; touch-action: none;
}
.perspective-container img {
    display: block; max-width: 100%; max-height: calc(60vh - 36px);
    width: auto; height: auto; pointer-events: none;
}
.persp-svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; display: none; touch-action: none; }
.persp-svg circle { cursor: grab; transition: r 0.13s; }
.persp-svg circle:hover { r: 14; }
.persp-svg circle:active { cursor: grabbing; }
.grid-line { stroke: rgba(255,255,255,0.45); stroke-dasharray: 4; stroke-width: 1.5; pointer-events: none; }

/* ===== ACTION BAR ===== */
.action-bar {
    flex-shrink: 0;
    min-height: var(--actionbar-h);
    background: var(--bg-surface);
    padding: 0 16px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    z-index: 10; box-shadow: 0 -1px 0 rgba(0,0,0,0.04), var(--shadow-sm);
    gap: 10px; flex-wrap: wrap;
}
.btn-reset {
    background: white; color: var(--danger);
    border: 1.5px solid #fca5a5;
    padding: 7px 13px; font-size: 13px; font-weight: 700;
    border-radius: 8px; cursor: pointer; transition: 0.15s;
    display: flex; align-items: center; gap: 6px;
}
.btn-reset:hover { background: var(--danger); color: white; border-color: var(--danger); }

.export-settings {
    display: flex; align-items: center; gap: 9px;
    background: var(--bg-main); padding: 6px 11px;
    border-radius: 8px; border: 1px solid var(--border-light);
}
.quality-group { display: flex; align-items: center; gap: 7px; }
.setting-label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.quality-val { font-size: 12px; font-weight: 700; color: var(--text-main); white-space: nowrap; }
#jpgQuality { width: 70px; height: 4px; -webkit-appearance: none; background: var(--border); border-radius: 4px; outline: none; }
#jpgQuality::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%; background: var(--primary); cursor: pointer; }
.size-badge {
    background: #eff6ff; color: var(--primary);
    padding: 4px 11px; border-radius: 14px;
    font-weight: 700; font-size: 12px; border: 1px solid #bfdbfe;
    min-width: 68px; text-align: center; white-space: nowrap;
}
.auto-compress-group {
    display: flex; align-items: center; gap: 3px;
    background: white; border: 1px solid var(--border); border-radius: 7px; padding: 2px;
}
.auto-compress-group input {
    border: none; padding: 5px 7px; width: 62px;
    font-weight: 600; outline: none; font-size: 12px; border-radius: 5px;
}
.auto-compress-group button {
    background: var(--primary); color: white; border: none;
    border-radius: 5px; padding: 5px 10px; cursor: pointer; font-size: 12px; transition: 0.13s;
}
.auto-compress-group button:hover { background: var(--primary-hover); }

.page-range-group {
    display: flex; align-items: center; gap: 6px;
    background: var(--bg-main); border: 1px solid var(--border-light);
    border-radius: 8px; padding: 6px 11px;
}
.page-range-group > i { color: var(--text-muted); font-size: 11px; }
.page-range-label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.range-dash { color: var(--text-muted); font-weight: 700; }
.page-range-group input[type="number"] {
    width: 50px; padding: 4px 6px; border-radius: 6px;
    border: 1px solid var(--border); font-size: 12px; font-weight: 700;
    text-align: center; outline: none; transition: 0.13s; -moz-appearance: textfield;
}
.page-range-group input[type="number"]::-webkit-inner-spin-button,
.page-range-group input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }
.page-range-group input[type="number"]:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.1); }
.page-range-group input[type="number"].active-range { border-color: var(--primary); background: #eff6ff; color: var(--primary); }
.btn-range-clear {
    width: 20px; height: 20px; border-radius: 50%;
    border: 1px solid var(--border); background: white;
    color: var(--text-muted); cursor: pointer; font-size: 9px;
    display: flex; align-items: center; justify-content: center; transition: 0.13s;
}
.btn-range-clear:hover { background: var(--danger); color: white; border-color: var(--danger); }

.action-buttons { display: flex; gap: 6px; align-items: center; }
.btn {
    padding: 8px 15px; border: none; font-size: 13px; font-weight: 700;
    border-radius: 8px; cursor: pointer; color: white;
    display: flex; align-items: center; gap: 6px; transition: 0.15s; white-space: nowrap;
}
.btn-pdf { background: linear-gradient(135deg,#2563eb,#1d4ed8); box-shadow: 0 2px 8px rgba(37,99,235,0.25); }
.btn-pdf:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(37,99,235,0.35); }
.btn-preview { background: linear-gradient(135deg,#10b981,#059669); box-shadow: 0 2px 8px rgba(16,185,129,0.22); }
.btn-preview:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(16,185,129,0.32); }
.btn-print { background: linear-gradient(135deg,#6366f1,#4f46e5); box-shadow: 0 2px 8px rgba(99,102,241,0.22); }
.btn-print:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,0.32); }
.btn-zip { background: linear-gradient(135deg,#f59e0b,#d97706); box-shadow: 0 2px 8px rgba(245,158,11,0.22); }
.btn-zip:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(245,158,11,0.32); }

/* ===== DRAG DROP ===== */
.drag-drop-overlay {
    position: fixed; top: 0; left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width)); height: 100%;
    background: rgba(37,99,235,0.08); display: none;
    justify-content: center; align-items: center;
    z-index: 10000; border: 5px dashed rgba(37,99,235,0.55);
    box-sizing: border-box; backdrop-filter: blur(4px); pointer-events: none;
}
.drop-inner {
    background: rgba(37,99,235,0.9);
    padding: 22px 44px; border-radius: 16px;
    display: flex; align-items: center; gap: 14px;
    font-size: 20px; font-weight: 700; color: white;
    box-shadow: 0 8px 32px rgba(37,99,235,0.35);
}
.drop-inner i { font-size: 34px; }

/* ===== LOADER ===== */
.loader-overlay, .preview-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15,23,42,0.85);
    display: none; justify-content: center; align-items: center;
    z-index: 9999; flex-direction: column;
    color: white; font-weight: 600; font-size: 15px;
    backdrop-filter: blur(8px);
}
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.spinner {
    border: 3px solid rgba(255,255,255,0.1);
    border-top: 3px solid #60a5fa;
    border-radius: 50%; width: 42px; height: 42px;
    animation: spin 0.75s linear infinite;
}
@keyframes spin { 0%{transform:rotate(0deg)} 100%{transform:rotate(360deg)} }

/* ===== PREVIEW ===== */
.preview-content {
    background: #f8fafc; padding: 22px; border-radius: var(--radius-lg);
    max-width: 90%; max-height: 95vh;
    display: flex; flex-direction: column; align-items: center; position: relative;
}
.close-preview {
    position: absolute; top: -13px; right: -13px;
    background: var(--danger); color: white; border: none;
    width: 36px; height: 36px; border-radius: 50%; font-size: 16px;
    cursor: pointer; transition: 0.13s; box-shadow: 0 3px 9px rgba(239,68,68,0.3);
    display: flex; align-items: center; justify-content: center;
}
.close-preview:hover { transform: scale(1.1); }
.preview-body { display: flex; align-items: center; gap: 18px; justify-content: center; margin-top: 10px; }
.preview-nav-btn {
    background: white; border: 1.5px solid var(--border); font-size: 17px; color: var(--primary);
    width: 42px; height: 42px; border-radius: 50%;
    cursor: pointer; transition: 0.13s; display: flex; align-items: center; justify-content: center;
}
.preview-nav-btn:hover:not(:disabled) { background: var(--primary); color: white; border-color: var(--primary); }
.preview-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }
#previewImageRender { max-width: 100%; max-height: 75vh; object-fit: contain; border-radius: 6px; box-shadow: var(--shadow-md); background: white; }
#previewPageText { margin-top: 10px; font-weight: 700; color: var(--text-main); font-size: 13px; text-align: center; }

/* ===== TOASTS ===== */
.toast-container { position: fixed; bottom: 68px; right: 18px; z-index: 99999; display: flex; flex-direction: column; gap: 7px; pointer-events: none; }
.toast {
    background: #1e293b; color: white;
    padding: 9px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
    box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 8px;
    animation: toastIn 0.22s ease, toastOut 0.22s ease 2.78s forwards;
    border-left: 3px solid var(--primary); max-width: 270px;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.warning { border-color: var(--warn); }
@keyframes toastIn { from{opacity:0;transform:translateX(22px)} to{opacity:1;transform:translateX(0)} }
@keyframes toastOut { from{opacity:1;transform:translateX(0)} to{opacity:0;transform:translateX(22px)} }

/* ===== HOME BACK ===== */
.btn-home-back { width: 30px; height: 30px; background: var(--primary-light); border: 1px solid #bfdbfe; border-radius: 7px; color: var(--primary); display: flex; align-items: center; justify-content: center; text-decoration: none; font-size: 12px; transition: 0.15s; }
.btn-home-back:hover { background: var(--primary); color: white; }

/* ===== MISC ===== */
input[type="file"] { display: none; }
.text-muted { color: var(--text-muted); }

/* ===== MOBILE ===== */
@media(max-width:768px) {
    :root { --sidebar-width: 180px; --navbar-h: auto; }
    body { height: 100dvh; }
    .top-navbar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; height: auto; }
    .brand-sub, .brand-badge { display: none; }
    .global-controls { width: 100%; justify-content: flex-end; flex-wrap: wrap; gap: 5px; }
    .global-controls input[type="text"] { flex: 1; min-width: 120px; }
    .workspace { flex-direction: column; overflow: hidden; }
    .sidebar { width: 100% !important; height: auto; flex-direction: row; border-right: none; border-bottom: 1px solid var(--border); flex-shrink: 0; }
    .sidebar-top { flex-shrink: 0; padding: 8px; border-bottom: none; border-right: 1px solid var(--border-light); flex-direction: column; justify-content: center; gap: 4px; }
    .btn-upload-main span { display: none; }
    .btn-upload-main { padding: 9px; justify-content: center; min-width: 38px; flex: none; }
    .page-counter { writing-mode: vertical-rl; transform: rotate(180deg); padding: 8px 4px; font-size: 10px; border-bottom: none; border-right: 1px solid #ddd6fe; flex-shrink: 0; }
    .thumb-list-container { flex: 1; overflow-x: auto; overflow-y: hidden; padding: 8px; }
    .thumb-list { flex-direction: row !important; gap: 8px; height: 100%; align-items: center; flex-wrap: nowrap; }
    .thumb-item { flex-shrink: 0; width: 70px; padding: 5px; }
    .thumb-item img { height: 60px; width: 100%; }
    .thumb-label { font-size: 10px; }
    .btn-del-thumb { width: 18px; height: 18px; font-size: 8px; top: -5px; right: -5px; }
    .editor-area { flex: 1; overflow-y: auto; }
    .editor-content { padding: 10px; }
    .page-layer { padding: 12px; }
    .editor-toolbar { flex-direction: column; align-items: flex-start; gap: 8px; padding-bottom: 10px; margin-bottom: 10px; }
    .sliders-row { width: 100%; gap: 6px; }
    .dark-slider-group { flex: 1; min-width: 0; padding: 5px 8px; }
    .dark-slider-group input[type="range"] { width: 100%; flex: 1; }
    .dsg-label { min-width: 20px; font-size: 9px; }
    .img-wrapper { height: 45vw; min-height: 200px; padding: 10px; }
    .perspective-container img { max-height: calc(45vw - 20px); }
    .action-bar { flex-direction: column; padding: 8px 10px; gap: 8px; align-items: stretch; height: auto; }
    .export-settings { justify-content: space-between; flex-wrap: wrap; gap: 6px; }
    .page-range-group { justify-content: center; }
    .auto-compress-group { justify-content: center; }
    .auto-compress-group input { flex: 1; }
    .action-buttons { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 6px; }
    .global-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; width: 100%; }
    .btn { justify-content: center; padding: 10px 8px; font-size: 12px; }
    .drag-drop-overlay { left: 0; width: 100%; }
    .toast-container { bottom: 10px; right: 10px; }
    .upload-menu { min-width: 180px; }
}

@media(max-width:480px) {
    .top-navbar { padding: 8px 10px; }
    .thumb-item { width: 60px; }
    .thumb-item img { height: 50px; }
    .sliders-row { flex-direction: column; }
    .dark-slider-group { width: 100%; }
    .img-wrapper { height: 40vw; min-height: 180px; }
    .perspective-container img { max-height: calc(40vw - 20px); }
}

@media(min-width:769px) {
    .thumb-list-container::-webkit-scrollbar { width: 5px; }
    .thumb-list-container::-webkit-scrollbar-track { background: transparent; }
    .thumb-list-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
    .thumb-list-container::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
    .editor-area::-webkit-scrollbar { width: 6px; }
    .editor-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
}

body.dark-mode {
    background-color: #0b1120 !important;
    color: #f8fafc !important;
}

/* All Panels, Bars, and Menus */
body.dark-mode .top-navbar,
body.dark-mode .sidebar,
body.dark-mode .action-bar,
body.dark-mode .upload-menu,
body.dark-mode .preview-content,
body.dark-mode .page-card,
body.dark-mode .toast,
body.dark-mode .empty-hints span,
body.dark-mode .page-layer {
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #f8fafc !important;
}

/* Editor Workspace Background */
body.dark-mode .editor-area,
body.dark-mode .workspace {
    background-color: #0f172a !important;
}

/* Inputs, Select Dropdowns, and Small Buttons */
body.dark-mode input,
body.dark-mode select,
body.dark-mode .btn-undoredo,
body.dark-mode .btn-scan-small,
body.dark-mode .btn-range-clear,
body.dark-mode .close-preview,
body.dark-mode .preview-nav-btn,
body.dark-mode .btn-icon,
body.dark-mode .range-group,
body.dark-mode .auto-compress-group,
body.dark-mode .page-range-group,
body.dark-mode .export-settings,
body.dark-mode .thumb-item {
    background-color: #0f172a !important;
    color: #f8fafc !important;
    border-color: #334155 !important;
}

/* Focus state for inputs */
body.dark-mode input:focus,
body.dark-mode select:focus {
    border-color: #6366f1 !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2) !important;
}

/* Text Colors */
body.dark-mode .brand-title,
body.dark-mode .empty-state h2,
body.dark-mode .um-title,
body.dark-mode .setting-label,
body.dark-mode .page-range-label,
body.dark-mode .quality-val {
    color: #f8fafc !important;
}

/* Muted Text Colors */
body.dark-mode .brand-sub,
body.dark-mode .empty-state p,
body.dark-mode .um-sub,
body.dark-mode .size-badge,
body.dark-mode .thumb-label,
body.dark-mode .btn-icon {
    color: #94a3b8 !important;
}

/* Hover States */
body.dark-mode .upload-menu-item:hover,
body.dark-mode .btn-undoredo:not(:disabled):hover,
body.dark-mode .btn-icon:hover {
    background-color: #334155 !important;
    color: #f8fafc !important;
}

body.dark-mode .thumb-item:hover {
     border-color: #6366f1 !important;
}

/* Special Button Overrides */
body.dark-mode .btn-icon.active-tool {
    background-color: #6366f1 !important;
    color: white !important;
    border-color: #4f46e5 !important;
}
body.dark-mode .btn-icon.btn-magic {
    background-color: rgba(167, 139, 250, 0.1) !important;
    color: #c084fc !important;
    border-color: #8b5cf6 !important;
}
body.dark-mode .btn-icon.btn-magic:hover {
    background-color: rgba(167, 139, 250, 0.2) !important;
}

/* Scrollbar customization for dark mode */
body.dark-mode ::-webkit-scrollbar-track {
    background: #0f172a !important; 
}
body.dark-mode ::-webkit-scrollbar-thumb {
    background: #475569 !important; 
}
body.dark-mode ::-webkit-scrollbar-thumb:hover {
    background: #64748b !important; 
}

/* =========================================
   SIDEBAR - DARK MODE ONLY
   ========================================= */

/* Main Sidebar & Top Section */
body.dark-mode .sidebar,
body.dark-mode .sidebar-top {
    background-color: #1e293b !important;
    border-color: #334155 !important;
}

/* Thumbnail Box (Uploaded Images) */
body.dark-mode .thumb-item {
    background-color: #0f172a !important;
    border-color: #334155 !important;
}

/* Thumbnail Hover Effect */
body.dark-mode .thumb-item:hover {
    border-color: #6366f1 !important;
}

/* Thumbnail Text */
body.dark-mode .thumb-label {
    color: #94a3b8 !important;
}

/* Scan Button inside Sidebar */
body.dark-mode .btn-scan-small {
    background-color: #0b1120 !important;
    color: #f8fafc !important;
    border-color: #334155 !important;
}

/* Sidebar Scrollbar */
body.dark-mode .thumb-list-container::-webkit-scrollbar-track {
    background: #0f172a !important; 
}
body.dark-mode .thumb-list-container::-webkit-scrollbar-thumb {
    background: #475569 !important; 
}
body.dark-mode .thumb-list-container::-webkit-scrollbar-thumb:hover {
    background: #64748b !important; 
}