/* ============================================
   FOTOKONYV EDITOR - COMPLETE STYLESHEET
   ============================================ */

:root {
    --primary: #e67e22;
    --primary-dark: #d35400;
    --primary-light: #f39c12;
    --accent: #e67e22;
    --accent-light: #f39c12;
    --bg-workspace: #f2f2f2;
    --bg-sidebar: #ffffff;
    --bg-header: #e67e22;
    --text-dark: #333;
    --text-medium: #555;
    --text-light: #999;
    --border-light: #e5e5e5;
    --border-medium: #ccc;
    --white: #fff;
    --shadow-soft: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-medium: 0 4px 12px rgba(0,0,0,0.1);
    --selection-color: #e67e22;
    --handle-corner: #999999;
    --handle-rot: #3498db;
}

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

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    color: var(--text-dark);
    background: var(--bg-workspace);
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
}

/* ============================================
   HEADER
   ============================================ */
.editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    background: var(--bg-header);
    color: var(--white);
    padding: 10px 20px;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 100;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.5px;
    color: var(--white);
}

.logo svg { color: var(--white); }

.header-title-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.book-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--white);
}

.save-status {
    font-size: 11px;
    color: rgba(255,255,255,0.75);
    display: flex;
    align-items: center;
    gap: 5px;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4cd964;
    display: inline-block;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border-radius: 4px;
    border: 1px solid transparent;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
    white-space: nowrap;
    vertical-align: middle;
    align-self: center;
}

.btn svg { flex-shrink: 0; }

.btn-outline {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.3);
    color: var(--white);
}
.btn-outline:hover { background: rgba(255,255,255,0.2); }

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--accent);
    color: var(--white);
    border-color: var(--accent);
}
.btn-primary:hover { background: #2ecc71; }

/* ============================================
   LAYOUT
   ============================================ */
.editor-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ============================================
   LEFT SIDEBAR
   ============================================ */
.left-sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-medium);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    background: var(--text-dark);
    color: var(--white);
    text-align: center;
    padding: 12px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.sidebar-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.icon-menu {
    width: 72px;
    background: #f8fafc;
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 4px;
    gap: 6px;
    border: none;
    border-bottom: 1px solid var(--border-light);
    border-left: 3px solid transparent;
    background: none;
    font-size: 9px;
    font-weight: 600;
    color: var(--text-medium);
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
    font-family: inherit;
    text-transform: uppercase;
    white-space: nowrap;
}

.menu-item:hover {
    background: rgba(0,0,0,0.03);
    color: var(--text-dark);
}

.menu-item.active {
    background: var(--white);
    color: var(--primary);
    border-left-color: var(--accent);
}

.menu-item svg { flex-shrink: 0; }

.content-panel {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.size-selector {
    padding: 8px 0;
}

.size-selector label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-medium);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
}

.size-options {
    display: flex;
    gap: 4px;
}

.size-btn {
    flex: 1;
    padding: 6px 4px;
    border: 1px solid var(--border-light);
    background: var(--white);
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-medium);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    text-align: center;
}

.size-btn:hover {
    border-color: var(--accent);
    color: var(--primary);
}

.size-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--white);
}

/* Product list (dynamic, from old system) */
.product-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.product-item {
    display: flex;
    flex-direction: column;
    padding: 8px;
    border: 1px solid var(--border-light);
    background: var(--white);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}
.product-item:hover {
    border-color: var(--accent);
}
.product-item.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--white);
}
.product-item.active .product-name,
.product-item.active .product-category {
    color: var(--white);
}
.product-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dark);
}
.product-category {
    font-size: 10px;
    color: var(--text-light);
    margin-bottom: 4px;
}
.product-thumb {
    width: 100%;
    height: 60px;
    overflow: hidden;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-light);
}
.product-thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-placeholder {
    color: var(--text-light);
    font-size: 12px;
    text-align: center;
    padding: 30px 10px;
}

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px;
    background: #27ae60;
    color: var(--white);
    border: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 8px;
    font-family: inherit;
}

.upload-btn:hover { background: var(--primary); }

.upload-progress {
    width: 100%;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
    margin-bottom: 8px;
    overflow: hidden;
    display: none;
}

.upload-progress.visible { display: block; }

.progress-bar {
    width: 0%;
    height: 100%;
    background: var(--accent);
    transition: width 0.2s;
}

.gallery-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    padding: 0 2px;
}

.gallery-count {
    font-size: 11px;
    color: var(--text-medium);
    font-weight: 500;
}

.gallery-delete-all {
    font-size: 10px;
    padding: 3px 8px;
    border: 1px solid var(--border-light);
    background: var(--white);
    color: #c0392b;
    border-radius: 3px;
    cursor: pointer;
    font-family: inherit;
}

.gallery-delete-all:hover { background: #fdf2f2; }

.auto-layout-btn {
    width: 100%;
    padding: 8px 12px;
    /* margin: 6px 0 8px; */
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--white);
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.15s ease;
}
.auto-layout-btn:hover { background: var(--accent-light); border-color: var(--accent-light); }
.auto-layout-warning {
    font-size: 10px;
    color: var(--accent);
    text-align: center;
    padding: 4px 6px;
    margin-bottom: 4px;
    background: rgba(232,126,4,0.08);
    border-radius: 3px;
    font-weight: 500;
}
.auto-layout-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.image-tooltip {
    font-size: 10px;
    color: var(--text-light);
    text-align: center;
    margin-bottom: 10px;
    padding: 4px;
    background: rgba(0,0,0,0.04);
    border-radius: 3px;
}

.image-gallery {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.gallery-img {
    position: relative;
    aspect-ratio: 1;
    border-radius: 3px;
    overflow: hidden;
    cursor: grab;
    border: 2px solid transparent;
    transition: border-color 0.15s;
}

.gallery-img:hover { border-color: var(--accent); }

.gallery-img.uploading img { opacity: 0.5; }

.gallery-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-img .img-delete {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    background: rgba(192,57,43,0.85);
    color: #fff;
    border: none;
    border-radius: 3px;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    cursor: pointer;
    display: none;
    z-index: 2;
    padding: 0;
    font-family: inherit;
}

.gallery-img:hover .img-delete { display: block; }

.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px 10px;
    font-size: 11px;
    color: var(--text-light);
}

.img-check {
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 16px;
    height: 16px;
    background: var(--accent);
    color: var(--white);
    border-radius: 50%;
    font-size: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   WORKSPACE (CENTER)
   ============================================ */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-workspace);
    overflow: hidden;
}

.workspace-scroll {
    flex: 1;
    overflow: auto;
    position: relative;
    text-align: center;
}

.workspace-label {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(60,60,60,0.85);
    color: var(--white);
    padding: 5px 18px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.5px;
    z-index: 10;
}

.canvas-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    box-sizing: border-box;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

.zoom-layer {
    transform-origin: center center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-spread {
    display: flex;
    background: var(--white);
    border-radius: 2px;
    box-shadow: var(--shadow-medium);
    position: relative;
    border: 1px solid var(--selection-color);
    padding: 4px;
    overflow: hidden;
}

.page {
    width: 560px;
    height: 420px;
    background: var(--white);
    position: relative;
    overflow: visible;
}

.page-left { border-radius: 2px 0 0 2px; }
.page-right { border-radius: 0 2px 2px 0; }

.page-content {
    width: 100%;
    height: 100%;
    position: relative;
    padding: 24px;
    overflow: visible;
}
.page-content::before {
    content: '';
    position: absolute;
    top: 12px; left: 12px; right: 12px; bottom: 12px;
    border: 1px dashed var(--selection-color);
    pointer-events: none;
    z-index: 1;
}

.page-content::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24' fill='none' stroke='%23cccccc' stroke-width='1.5'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpath d='M21 15l-5-5L5 21'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    pointer-events: none;
    z-index: 0;
    opacity: 0.6;
}

.page-content.has-content::after,
.page-front-cover .page-content::after {
    display: none !important;
}

.page-placeholder {
    position: absolute;
    border: 2px dashed #ddd;
    border-radius: 4px;
    background: rgba(0,0,0,0.02);
    pointer-events: none;
    cursor: default;
    user-select: none;
}

.page-placeholder::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24' fill='none' stroke='%23cccccc' stroke-width='1.5'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpath d='M21 15l-5-5L5 21'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

/* Cover page styling */
.page-back-cover,
.page-front-cover {
    background-color: #1a1a1a;
    color: #fff;
}
.page-back-cover {
    overflow: hidden;
}

.page-back-cover .page-number,
.page-front-cover .page-number {
    color: rgba(255,255,255,0.5);
}

.cover-logo-area {
    position: absolute;
    bottom: 8%;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 40px;
    background: rgba(255,255,255,0.9);
    border-radius: 4px;
    pointer-events: none;
}
.cover-barcode {
    position: absolute;
    bottom: 8%;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: auto;
    max-height: 36px;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
    z-index: 1;
}

.cover-photo-slot {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50%;
    transform: translate(-50%, -50%);
    border: 2px dashed #666;
    border-radius: 4px;
    background: rgba(255,255,255,0.05);
    pointer-events: none;
    cursor: default;
    user-select: none;
    aspect-ratio: 1 / 1;
}

.cover-photo-slot::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24' fill='none' stroke='%23666666' stroke-width='1.5'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpath d='M21 15l-5-5L5 21'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.spine {
    width: 6px;
    background: linear-gradient(to right, #e0e0e0, #bbb, #999, #bbb, #e0e0e0);
    flex-shrink: 0;
    box-shadow: 4px 0 10px rgba(0,0,0,0.25), -4px 0 10px rgba(0,0,0,0.15);
    position: relative;
    z-index: 15;
}

.page-number {
    position: absolute;
    bottom: 3px;
    font-size: 10px;
    color: #555;
    font-weight: 500;
    z-index: 4;
}
.page-left .page-number { left: 4px; }
.page-right .page-number { right: 4px; text-align: right; }

/* Elements on pages */
.spread-image {
    position: absolute;
    cursor: move;
    user-select: none;
    border: 2px solid transparent;
    transition: border-color 0.15s;
    z-index: 5;
}

.spread-text {
    position: absolute;
    cursor: move;
    user-select: none;
    border: none;
    z-index: 8; /* Text always above images */
}
.spread-text span {
    overflow: hidden;
    display: inline-block;
}

/* Panorama spans full spread behind pages */
.spread-image.panorama {
    z-index: 1 !important;
}

/* Page backgrounds sit above panorama but behind content */
.spread-image.bg-left,
.spread-image.bg-right {
    z-index: 2 !important;
}

/* Selected element comes to front, but backgrounds and user-set zindex stay behind */
.spread-image[data-selected="true"]:not(.panorama):not(.bg-left):not(.bg-right):not([data-user-zindex]) {
    z-index: 12 !important;
}

.spread-image[data-user-zindex="back"][data-selected="true"]:not(.panorama):not(.bg-left):not(.bg-right) {
    z-index: 3 !important;
}

.spread-image[data-user-zindex="front"][data-selected="true"]:not(.panorama):not(.bg-left):not(.bg-right) {
    z-index: 100 !important;
}

/* Text selection: no border, just a subtle shadow */
.spread-text[data-selected="true"]:not([data-user-zindex]) {
    z-index: 12 !important;
    filter: drop-shadow(0 0 3px rgba(0,180,220,0.5));
}

.spread-text[data-user-zindex="back"][data-selected="true"] {
    z-index: 3 !important;
    filter: drop-shadow(0 0 3px rgba(0,180,220,0.5));
}

.spread-text[data-user-zindex="front"][data-selected="true"] {
    z-index: 100 !important;
    filter: drop-shadow(0 0 3px rgba(0,180,220,0.5));
}

/* Backgrounds always stay behind even when selected */
.spread-image.panorama[data-selected="true"],
.spread-image.bg-left[data-selected="true"],
.spread-image.bg-right[data-selected="true"] {
    z-index: 1 !important;
}

.spread-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.spread-image.framed {
    border: 6px solid var(--white);
    box-shadow: 0 3px 10px rgba(0,0,0,0.15);
}

.spread-image.tilted {
    transform: rotate(-3deg);
}

/* Panorama: spans both pages */
.spread-image.panorama {
    position: absolute;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 1;
}

/* Background fill modes */
.spread-image.bg-left,
.spread-image.bg-right {
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
}

.spread-image.panorama img,
.spread-image.bg-left img,
.spread-image.bg-right img {
    object-fit: cover;
    width: 100%;
    height: 100%;
}

.spread-image .placeholder-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.5;
}

.spread-text {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-dark);
}

.spread-text h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-dark);
}

.spread-text p {
    font-size: 11px;
    line-height: 1.6;
    color: var(--text-medium);
}

/* Text tool panel */
.text-tool-section {
    margin-bottom: 12px;
}

.text-tool-section label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-medium);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 6px;
}

.text-tool-section .font-select,
.text-tool-section .text-input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-light);
    border-radius: 3px;
    font-size: 12px;
    font-family: inherit;
    color: var(--text-dark);
    background: var(--white);
}

.text-tool-section .text-input {
    font-size: 12px;
}

.text-color-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.text-color-row input[type="color"] {
    width: 36px;
    height: 28px;
    border: 1px solid var(--border-light);
    border-radius: 3px;
    cursor: pointer;
    padding: 2px;
}

.text-color-value {
    font-size: 11px;
    color: var(--text-medium);
    font-family: monospace;
}

.text-size-slider {
    width: 100%;
    margin-bottom: 4px;
}

.text-size-value {
    font-size: 11px;
    color: var(--text-medium);
    display: block;
    text-align: right;
}

/* Selection */
.spread-image[data-selected="true"],
.spread-text[data-selected="true"] {
    border: 1px solid var(--selection-color);
    box-shadow: 0 0 0 1px rgba(255,255,255,0.8), 0 0 8px rgba(0,180,220,0.4);
}

.selection-handles {
    position: absolute;
    top: -2px; left: -2px; right: -2px; bottom: -2px;
    pointer-events: none;
    display: none;
}

.spread-image[data-selected="true"] .selection-handles,
.spread-text[data-selected="true"] .selection-handles {
    display: block;
}

/* Hide handles on background-locked images unless in edit mode */
.spread-image[data-bg-locked="true"]:not([data-bg-edit="true"]) .selection-handles {
    display: none !important;
}

/* Hide selection border on locked background images */
.spread-image[data-bg-locked="true"]:not([data-bg-edit="true"])[data-selected="true"] {
    border: none !important;
    box-shadow: none !important;
}

.handle {
    position: absolute;
    width: 24px;
    height: 24px;
    background: var(--white);
    border: 3px solid var(--handle-corner);
    border-radius: 50%;
    pointer-events: auto;
    z-index: 100;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
    transition: transform 0.1s, background 0.1s;
    transform: scale(var(--inverse-scale, 1));
}

.handle:hover {
    transform: scale(calc(var(--inverse-scale, 1) * 1.25));
    background: var(--handle-corner);
    border-color: var(--white);
}

.handle.tl { top: -14px; left: -14px; cursor: nwse-resize; }
.handle.tr { top: -14px; right: -14px; cursor: nesw-resize; }
.handle.bl { bottom: -14px; left: -14px; cursor: nesw-resize; }
.handle.br { bottom: -14px; right: -14px; cursor: nwse-resize; }

/* Center pan handle - moves object-position (crop) */
.handle.center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(var(--inverse-scale, 1));
    cursor: grab;
    width: 48px;
    height: 48px;
    background: rgba(255,255,255,0.3);
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.handle.center::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    transform: translate(-50%, -50%);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M12 5L12 19' stroke='%23444' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M9 17L12 20L15 17' stroke='%23444' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M15 7L12 4L9 7' stroke='%23444' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M5 12L19 12' stroke='%23444' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M17 15L20 12L17 9' stroke='%23444' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M7 9L4 12L7 15' stroke='%23444' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.95;
}
.handle.center:hover {
    transform: translate(-50%, -50%) scale(calc(var(--inverse-scale, 1) * 1.25));
}

/* Mask decoration center handle = upload icon (only when empty) */
.mask-decoration .handle.center:not([data-uploaded="true"])::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpolyline points='17 8 12 3 7 8'/%3E%3Cline x1='12' y1='3' x2='12' y2='15'/%3E%3C/svg%3E");
    width: 24px;
    height: 24px;
    opacity: 1;
}
.mask-decoration {
    container-type: size;
    container-name: mask;
}
/* Empty masks: hide the black SVG preview image and show a subtle grey background in the mask shape */
.mask-decoration:not([data-has-image="true"]) .mask-inner {
    background: rgba(0, 0, 0, 0.6) !important;
}
.mask-decoration:not([data-has-image="true"]) .mask-inner > img {
    opacity: 0 !important;
}
/* Always show center upload handle on empty masks (even when not selected) */
.mask-decoration:not([data-has-image="true"]) .selection-handles {
    display: block !important;
}
.mask-decoration:not([data-has-image="true"]):not([data-selected="true"]) .selection-handles::before,
.mask-decoration:not([data-has-image="true"]):not([data-selected="true"]) .selection-handles .handle:not(.center) {
    display: none;
}
@container mask (max-width: 120px) or (max-height: 120px) {
    .mask-decoration .handle.center:not([data-uploaded="true"]) {
        width: 24px;
        height: 24px;
    }
    .mask-decoration .handle.center:not([data-uploaded="true"])::before {
        width: 14px;
        height: 14px;
    }
    /* Hide upload text when mask is too small */
    .mask-decoration:not([data-has-image="true"])::after {
        display: none;
    }
}

/* Ghost transparency while panning crop */
.spread-image.panning-crop > img {
    opacity: 0.45 !important;
}
.spread-image.panning-crop .selection-handles {
    opacity: 1 !important;
}
/* Ensure panning-crop opacity persists during zoom/transform */
.zoom-layer .spread-image.panning-crop > img {
    opacity: 0.45 !important;
}

/* Rotate handle with connecting line */
.handle.rot {
    top: -22px;
    left: 50%;
    transform: translateX(-50%) scale(var(--inverse-scale, 1));
    cursor: grab;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    background: var(--handle-rot);
    border-color: var(--white);
}

.handle.rot:hover {
    transform: translateX(-50%) scale(calc(var(--inverse-scale, 1) * 1.25));
}

.mask-decoration .handle.rot {
    top: -32px;
}
.mask-decoration .selection-handles::before {
    top: -16px;
}
.selection-handles::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%) scaleY(var(--inverse-scale, 1));
    width: 2px;
    height: 10px;
    background: var(--handle-rot);
    pointer-events: none;
}

/* ============================================
   PAGE NAVIGATION
   ============================================ */
.page-nav {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.9);
    padding: 6px 14px;
    border-radius: 20px;
    box-shadow: var(--shadow-soft);
}

.nav-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--text-medium);
    transition: all 0.15s;
}

.nav-btn:hover { background: rgba(0,0,0,0.05); color: var(--text-dark); }

.page-indicator {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-medium);
    min-width: 50px;
    text-align: center;
}

/* ============================================
   ZOOM CONTROL
   ============================================ */
.zoom-control {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.9);
    padding: 6px 12px;
    border-radius: 20px;
    box-shadow: var(--shadow-soft);
}

.zoom-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-medium);
}

.zoom-slider {
    width: 80px;
    height: 3px;
    accent-color: var(--accent);
    cursor: pointer;
}

.zoom-value {
    font-size: 11px;
    color: var(--text-medium);
    min-width: 34px;
}

/* ============================================
   RIGHT SIDEBAR
   ============================================ */
.right-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border-medium);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.right-sidebar .sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.right-sidebar.collapsed .properties-content {
    display: none !important;
}
.right-sidebar.collapsed {
    width: auto;
    min-width: auto;
}

.close-sidebar {
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    border-radius: 3px;
}
.close-sidebar:hover { background: rgba(0,0,0,0.05); color: var(--text-medium); }

.properties-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 10px 10px;
}

.prop-section {
    border-bottom: 1px solid var(--border-light);
    padding: 8px 0;
}

.prop-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

.prop-header h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-medium);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.toggle-btn {
    width: 22px;
    height: 22px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    border-radius: 3px;
}
.toggle-btn:hover { background: rgba(0,0,0,0.05); }

.prop-body {
    padding-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.prop-body.collapsed { display: none; }

.prop-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.prop-row.compact {
    gap: 6px;
}
.prop-row.dual-slider {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}
.slider-pair {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.slider-pair label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-medium);
}
.slider-pair .prop-slider {
    width: 100%;
}

.prop-subheader {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-medium);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    text-align: center;
    padding: 6px 0;
    margin-top: 4px;
    border-top: 1px solid var(--border-light);
    background: rgba(0,0,0,0.03);
    border-radius: 3px;
}

/* Accordion for image properties */
.prop-accordion-section {
    margin-bottom: 2px;
}
.prop-accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-color);
    background: rgba(0,0,0,0.04);
    border-radius: 6px;
    user-select: none;
    transition: background 0.2s ease;
}
.prop-accordion-header:hover {
    background: rgba(0,0,0,0.08);
}
.prop-accordion-header i {
    font-size: 10px;
    color: var(--text-light);
    transition: transform 0.3s ease;
}
.prop-accordion-section.open .prop-accordion-header i {
    transform: rotate(180deg);
}
.prop-accordion-body {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.25s ease;
    padding: 0 4px;
}
.prop-accordion-section.open .prop-accordion-body {
    max-height: 800px;
    opacity: 1;
    padding: 8px 4px 4px;
}

.prop-select {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--border-light);
    border-radius: 3px;
    font-size: 12px;
    font-family: inherit;
    background: var(--white);
    color: var(--text-dark);
    cursor: pointer;
}

.prop-select.full { width: 100%; flex: none; }
.prop-select.size-select { max-width: 70px; }

.prop-toolbar {
    display: flex;
    gap: 4px;
    justify-content: center;
    position: relative;
}

.tool-btn {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border-light);
    background: var(--white);
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-medium);
    font-size: 13px;
    transition: all 0.1s;
    padding: 0;
}
.tool-btn i {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.tool-btn:hover { border-color: var(--accent); color: var(--primary); }
.tool-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--white);
}

.align-toolbar .tool-btn { width: 32px; }

.color-toolbar {
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
}
.color-toolbar .tool-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    padding: 0;
}
.color-toolbar .tool-btn.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(0,180,220,0.3);
}

.bg-mode-toolbar {
    gap: 8px;
    margin-top: 4px;
}
.bg-mode-toolbar .tool-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 14px;
}
.bg-mode-toolbar .tool-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--white);
}

.bg-mode-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.bg-mode-label {
    font-size: 9px;
    color: var(--text-medium);
    text-align: center;
    white-space: nowrap;
}

.prop-toolbar .prop-btn-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.prop-toolbar .prop-btn-label {
    font-size: 9px;
    color: var(--text-medium);
    text-align: center;
    white-space: nowrap;
}

.spacing-row {
    align-items: center;
}
.spacing-row label {
    font-size: 11px;
    color: var(--text-light);
    min-width: 50px;
}

.prop-slider {
    flex: 1;
    accent-color: var(--accent);
    cursor: pointer;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.modal-overlay.visible { display: flex; }
.modal-box {
    background: var(--white);
    border-radius: 8px;
    width: 340px;
    max-width: 90vw;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    overflow: hidden;
    animation: modalIn 0.2s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-sidebar);
}
.modal-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
}
.modal-close {
    width: 26px;
    height: 26px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-light);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-close:hover { background: rgba(0,0,0,0.05); color: var(--text-medium); }
.modal-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-row { display: flex; align-items: center; gap: 10px; }
.modal-row label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-medium);
    min-width: 100px;
}
.modal-row select,
.modal-row input[type="range"] {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid var(--border-light);
    border-radius: 3px;
    font-size: 12px;
    font-family: inherit;
}
.modal-row input[type="range"] { padding: 0; }
.modal-value {
    font-size: 11px;
    color: var(--text-light);
    min-width: 36px;
    text-align: right;
}
.modal-checkbox { gap: 6px; }
.modal-checkbox input { margin: 0; }
.modal-checkbox label { min-width: auto; cursor: pointer; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-sidebar);
}
.modal-btn {
    padding: 7px 14px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
}
.modal-btn-primary {
    background: var(--accent);
    color: var(--white);
    border-color: var(--accent);
}
.modal-btn-primary:hover { background: var(--accent-light); }
.modal-btn-secondary {
    background: var(--white);
    color: var(--text-medium);
    border-color: var(--border-light);
}
.modal-btn-secondary:hover { background: var(--bg-sidebar); }

/* Saves Modal */
.save-empty {
    text-align: center;
    color: var(--text-light);
    font-size: 13px;
    padding: 24px;
}
.save-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    margin-bottom: 8px;
    background: var(--white);
    transition: box-shadow 0.15s;
}
.save-item:hover {
    box-shadow: var(--shadow-soft);
}
.save-thumb {
    width: 80px;
    height: 54px;
    border-radius: 4px;
    object-fit: cover;
    background: var(--bg-sidebar);
    border: 1px solid var(--border-light);
    flex-shrink: 0;
}
.save-info {
    flex: 1;
    min-width: 0;
}
.save-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.save-date {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 2px;
}
.save-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.save-actions button {
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border-light);
    background: var(--white);
    color: var(--text-medium);
    transition: all 0.15s;
}
.save-actions button:hover {
    background: var(--bg-sidebar);
    color: var(--text-dark);
}
.save-actions .btn-load {
    background: var(--accent);
    color: var(--white);
    border-color: var(--accent);
}
.save-actions .btn-load:hover {
    background: var(--accent-light);
}

/* Wizard Modal */
.modal-box.wizard { width: 520px; }
.wizard-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px;
}
.wizard-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    color: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}
.wizard-body { padding: 0 16px 14px; display: flex; flex-direction: column; gap: 14px; }
.wizard-section { border-bottom: 1px solid var(--border-light); padding-bottom: 12px; }
.wizard-section:last-child { border-bottom: none; padding-bottom: 0; }
.wizard-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-medium);
    margin-bottom: 8px;
}
.wizard-options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.wizard-opt {
    padding: 7px 14px;
    border: 1px solid var(--border-light);
    background: var(--white);
    border-radius: 20px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-medium);
    font-family: inherit;
    transition: all 0.15s;
}
.wizard-opt:hover { border-color: var(--accent); color: var(--accent); }
.wizard-opt.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--white);
}
.wizard-toggles { display: flex; flex-wrap: wrap; gap: 10px; }
.wizard-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-dark);
}
.wizard-toggle input { display: none; }
.wizard-toggle-track {
    width: 36px;
    height: 20px;
    background: #ccc;
    border-radius: 10px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}
.wizard-toggle-thumb {
    width: 16px;
    height: 16px;
    background: var(--white);
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: left 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.wizard-toggle input:checked + .wizard-toggle-track { background: var(--accent); }
.wizard-toggle input:checked + .wizard-toggle-track .wizard-toggle-thumb { left: 18px; }
.wizard-toggle-label { font-size: 12px; color: var(--text-dark); }
.wizard-slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.wizard-slider-row label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-medium);
    min-width: 90px;
}
.wizard-slider-row input[type="range"] { flex: 1; }
.wizard-slider-val {
    font-size: 11px;
    color: var(--text-light);
    min-width: 36px;
    text-align: right;
}
.wizard-slider-row.disabled label,
.wizard-slider-row.disabled .wizard-slider-val {
    color: #bbb;
}
.wizard-slider-row.disabled input[type="range"] {
    opacity: 0.4;
    pointer-events: none;
}

/* Toggle switch */
.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

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

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border-medium);
    border-radius: 20px;
    transition: 0.2s;
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background: var(--white);
    border-radius: 50%;
    transition: 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider:before { transform: translateX(16px); }

/* ============================================
   BOTTOM STRIP
   ============================================ */
.bottom-strip {
    height: auto;
    min-height: 72px;
    background: #333;
    display: flex;
    align-items: center;
    gap: 0;
    padding: 6px 12px;
    border-top: 1px solid #444;
    flex-shrink: 0;
}

.strip-nav {
    width: 32px;
    height: 50px;
    border: none;
    background: rgba(255,255,255,0.08);
    color: var(--white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    flex-shrink: 0;
    transition: background 0.15s;
}

.strip-nav:hover { background: rgba(255,255,255,0.15); }

.strip-scroll {
    flex: 1;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px 4px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #555 #333;
}

.strip-scroll::-webkit-scrollbar { height: 5px; }
.strip-scroll::-webkit-scrollbar-track { background: #333; }
.strip-scroll::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

.strip-thumb {
    position: relative;
    min-width: 110px;
    height: auto;
    border-radius: 3px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s;
    background: #444;
    padding: 3px;
}

.strip-thumb:hover { border-color: var(--accent-light); }
.strip-thumb.active { border-color: var(--accent); }
.strip-thumb.dragging-thumb { opacity: 0.5; border-color: var(--accent); }
.strip-thumb.drag-over { border-color: #00d2ff !important; box-shadow: 0 0 0 3px rgba(0,210,255,0.3); }

.strip-add-btn {
    min-width: 50px !important;
    background: var(--accent) !important;
    color: var(--white);
    font-size: 24px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    border-radius: 4px;
    padding: 0;
    transition: background 0.15s, transform 0.1s;
}
.strip-add-btn:hover {
    background: var(--accent-light) !important;
    transform: scale(1.05);
}
.thumb-delete {
    position: absolute !important;
    top: 2px !important;
    right: 2px !important;
    width: 18px;
    height: 18px;
    background: rgba(231, 76, 60, 0.85);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    opacity: 0.75;
    transition: opacity 0.15s, background 0.15s, transform 0.1s;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.strip-thumb:hover .thumb-delete,
.thumb-delete:hover {
    opacity: 1;
    background: #e74c3c;
}
.thumb-delete:hover {
    background: #c0392b;
    transform: scale(1.1);
}
.thumb-delete:disabled {
    background: #999;
    cursor: not-allowed;
    opacity: 0.3;
    transform: none;
}

.strip-thumb span {
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: var(--white);
    background: rgba(0,0,0,0.5);
    padding: 1px 6px;
    border-radius: 3px;
    z-index: 2;
}

/* Mini spread inside strip thumbnails */
.mini-spread {
    display: flex;
    width: 100%;
    height: auto;
    min-height: 40px;
    background: var(--white);
    border-radius: 2px;
    overflow: hidden;
    aspect-ratio: var(--thumb-aspect, 2.68);
}

.mini-page {
    flex: 1;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.strip-thumb.active .mini-page .mini-mirror { opacity: 1; }

.mini-spine {
    width: 2px;
    background: linear-gradient(to right, #ddd, #aaa, #ddd);
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.mini-mirror {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;
    width: 420px;
    height: 560px;
    transform: scale(0.13);
    pointer-events: none;
}

.price-box {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 0 16px;
    flex-shrink: 0;
    border-left: 1px solid #444;
    margin-left: 8px;
}

.price-label {
    font-size: 11px;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.price-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent-light);
}

/* ============================================
   CONTEXT MENUS
   ============================================ */
.context-menu {
    position: fixed;
    background: var(--white);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    box-shadow: var(--shadow-medium);
    padding: 6px 0;
    min-width: 160px;
    z-index: 1000;
    display: none;
    font-size: 12px;
}

.context-menu.visible { display: block; }

.ctx-title {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    padding: 4px 14px 6px;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 4px;
}

.ctx-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 14px;
    cursor: pointer;
    color: var(--text-dark);
    transition: background 0.1s;
}

.ctx-item:hover { background: rgba(92,179,184,0.1); }

.ctx-item svg { color: var(--text-light); }

.ctx-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    cursor: pointer;
    color: var(--text-dark);
    font-size: 12px;
}

.ctx-checkbox:hover { background: rgba(92,179,184,0.1); }
.ctx-checkbox input { cursor: pointer; }

.ctx-divider {
    height: 1px;
    background: var(--border-light);
    margin: 4px 10px;
}

.ctx-danger { color: #c0392b; }
.ctx-danger:hover { background: rgba(192,57,43,0.08); }
.ctx-danger svg { color: #c0392b; }

.ctx-item > svg:first-child,
.ctx-item > span + svg { flex-shrink: 0; }
.ctx-item > span { flex: 1; margin-left: 6px; }
.ctx-item:not(.has-submenu) > span { margin-right: auto; }

/* ============================================
   TOOLTIPS
   ============================================ */
.editor-tooltip {
    position: fixed;
    background: rgba(50,50,50,0.9);
    color: var(--white);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 11px;
    z-index: 2000;
    display: none;
    pointer-events: none;
    max-width: 200px;
    line-height: 1.4;
}
.editor-tooltip.visible { display: block; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1200px) {
    .left-sidebar { width: 190px; min-width: 190px; }
    .right-sidebar { width: 220px; min-width: 220px; }
    .page { width: 360px; height: 480px; }
}

@media (max-width: 900px) {
    .editor-layout { flex-direction: column; }
    .left-sidebar, .right-sidebar {
        width: 100%;
        min-width: 100%;
        max-height: 200px;
        flex-direction: column;
    }
    .left-sidebar .sidebar-body { flex-direction: row; }
    .icon-menu { flex-direction: row; width: auto; border-right: none; border-bottom: 1px solid var(--border-light); }
    .menu-item { border-bottom: none; border-left: none; border-right: 3px solid transparent; padding: 8px 10px; }
    .menu-item.active { border-right-color: var(--accent); }
    .content-panel { flex: 1; }
    .image-gallery { grid-template-columns: repeat(4, 1fr); }
    .page { width: 300px; height: 400px; }
    .bottom-strip {height: 59px;min-height: 80px;}
}

.panel-close-btn { display: none; }

/* Mobile optimization */
@media (max-width: 768px) {
    .editor-header { padding: 3px 8px; min-height: 36px; }
    .editor-header .header-left { gap: 4px; }
    .logo { display: none; }
    .editor-header { justify-content: center; }
    .editor-header .header-actions { gap: 6px; justify-content: center; flex: 1; }
    .editor-header .btn { padding: 6px 10px; font-size: 11px; }
    .sidebar-header { display: none; }
    .left-sidebar { max-height: none; height: auto; min-height: 0; }
    .right-sidebar { max-height: 120px; }
    .left-sidebar .sidebar-body { flex-direction: column; }
    .icon-menu { flex-direction: row; width: 100%; padding: 1px; gap: 1px; border-bottom: 1px solid var(--border-light); border-right: none; justify-content: center; }
    .menu-item { padding: 3px 5px; font-size: 7px; line-height: 1.1; display: flex; flex-direction: column; align-items: center; gap: 1px; border-right-width: 2px; border-bottom: none; border-left: none; }
    .menu-item.active { border-right-color: var(--accent); border-bottom-color: transparent; }
    .menu-item svg { width: 25px; height: 25px; }
    .left-sidebar .content-panel {
        position: relative;
        width: 100%;
        height: 180px;
        /* margin-top: 10px; */
        z-index: 150;
        background: var(--bg-sidebar);
        border-bottom: 1px solid var(--border-light);
        display: none;
        overflow: hidden;
        flex-shrink: 0;
    }
    .panel-close-btn {
        position: absolute;
        top: 4px;
        right: 4px;
        width: 24px;
        height: 24px;
        border: none;
        background: rgba(0,0,0,0.15);
        color: #666;
        border-radius: 4px;
        font-size: 12px;
        cursor: pointer;
        z-index: 10;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .panel-close-btn:hover { background: rgba(0,0,0,0.25); color: #333; }
    .left-sidebar .content-panel.active .tab-panel {flex-direction: column;flex-wrap: nowrap;align-content: stretch;overflow-y: auto;padding: 8px;margin-top: 17px;gap: 6px;}
    .left-sidebar .content-panel.active .tab-panel.active { display: flex; flex-direction: column; }
    .left-sidebar .content-panel.active {display: flex;}
    .left-sidebar .content-panel.active .image-gallery {
        display: flex;
        flex-wrap: nowrap;
        gap: 6px;
        overflow-x: auto;
        padding-bottom: 4px;
        grid-template-columns: none;
    }
    .left-sidebar .content-panel.active .gallery-img {
        flex: 0 0 64px;
        width: 64px;
        height: 64px;
        aspect-ratio: 1;
    }
    .left-sidebar .content-panel.active .product-list {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 6px;
    }
    .left-sidebar .content-panel.active .product-item {
        flex: 0 0 120px;
        min-width: 120px;
    }
    .left-sidebar .content-panel.active .size-options {
        flex-wrap: nowrap;
        overflow-x: auto;
    }
    .left-sidebar .content-panel.active #templateCategories,
    .left-sidebar .content-panel.active #templateGrid {
        display: flex;
        flex-direction: row !important;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 6px;
        padding-bottom: 4px;
    }
    .left-sidebar .content-panel.active .category-card {
        flex: 0 0 120px;
        min-width: 120px;
        flex-direction: column;
        align-items: center;
        padding: 8px;
    }
    .left-sidebar .content-panel.active .template-card {
        flex: 0 0 100px;
        min-width: 100px;
    }
    .left-sidebar .content-panel.active .btn-row {
        display: flex;
        flex-direction: row;
        gap: 6px;
        width: 100%;
    }
    .left-sidebar .content-panel.active .btn-row .upload-btn,
    .left-sidebar .content-panel.active .btn-row .auto-layout-btn {
        flex: 1 1 50%;
        /* font-size: 11px; */
        padding: 8px;
        margin-bottom: 0;
        white-space: nowrap;
    }
    .left-sidebar .content-panel.active #panel-images .gallery-toolbar,
    .left-sidebar .content-panel.active #panel-images .upload-progress,
    .left-sidebar .content-panel.active #panel-images .auto-layout-warning,
    .left-sidebar .content-panel.active #panel-images .image-tooltip {
        width: 100%;
        flex-shrink: 0;
    }
    .left-sidebar .content-panel.active #panel-text {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 4px 8px;
        padding: 6px;
        align-content: flex-start;
    }
    .left-sidebar .content-panel.active #panel-text .upload-btn {
        padding: 6px;
        font-size: 11px;
        margin-bottom: 0;
        width: 100%;
    }
    .left-sidebar .content-panel.active #panel-text .text-tool-section {
        margin-bottom: 0;
        flex: 1 1 auto;
        min-width: 80px;
        display: flex;
        flex-direction: column;
        gap: 2px;
    }
    .left-sidebar .content-panel.active #panel-text .text-tool-section label {
        font-size: 8px;
        margin-bottom: 0;
        letter-spacing: 0.2px;
        white-space: nowrap;
    }
    .left-sidebar .content-panel.active #panel-text .font-select {
        padding: 2px 4px;
        font-size: 10px;
        width: 100%;
    }
    .left-sidebar .content-panel.active #panel-text .text-input {
        display: block;
        width: 100%;
        min-height: 40px;
        max-height: 60px;
        padding: 4px 6px;
        font-size: 12px;
        resize: none;
    }
    .left-sidebar .content-panel.active #panel-text .text-color-row {
        gap: 4px;
        align-items: center;
    }
    .left-sidebar .content-panel.active #panel-text .text-color-row input[type="color"] {
        width: 22px;
        height: 20px;
        padding: 0;
    }
    .left-sidebar .content-panel.active #panel-text .text-color-value {
        font-size: 9px;
        display: none;
    }
    .left-sidebar .content-panel.active #panel-text .text-size-slider {
        margin-bottom: 0;
        flex: 1;
    }
    .left-sidebar .content-panel.active #panel-text .text-size-value {
        font-size: 8px;
        text-align: left;
    }
    .workspace { padding: 2px; width: 100%; flex: 1; display: flex; flex-direction: column; min-height: 0; }
    .workspace-scroll { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; min-height: 0; }
    .canvas-wrapper { padding: 4px; width: 100%; display: flex; justify-content: center; align-items: center; overflow: visible; }
    .book-spread { padding: 1px; gap: 1px; width: calc(100vw - 8px); max-width: none; flex-shrink: 0; min-width: 0; }
    .page { width: calc(50vw - 6px) !important; height: auto !important; aspect-ratio: var(--page-ratio, 4/3) !important; max-width: none; min-width: 0; }
    .page-content { padding: 3px; }
    .bottom-strip { min-height: 36px; padding: 1px 4px; gap: 2px; }
    .strip-nav { width: 18px; height: 26px; padding: 0; flex-shrink: 0; }
    .strip-scroll { padding: 1px; gap: 2px; flex: 1; }
    .strip-thumb {flex: 0 0 80px;width: 80px;aspect-ratio: 3/2;height: auto;padding: 1px;}
    .strip-thumb img, .strip-thumb canvas { width: 100%; height: 100%; object-fit: cover; }
    .strip-add-btn { min-width: 28px !important; font-size: 14px; height: auto; aspect-ratio: 3/2; flex-shrink: 0; }
    .price-box { display: flex; flex-direction: column; align-items: flex-end; padding: 0 16px; flex-shrink: 0; border-left: 1px solid #444; margin-left: 8px; }
    .price-label { font-size: 8px; color: #aaa; }
    .price-value { font-size: 13px; color: var(--accent-light); }
    .spread-image { min-width: 24px; min-height: 24px; }
    .spread-text { min-width: 24px; min-height: 14px; }
    .toolbar { padding: 2px 4px; gap: 1px; }
    .tool-btn { width: 24px; height: 24px; font-size: 10px; }
    .workspace-label { display: none !important; }
    .bottom-toolbar { display: flex; flex-wrap: wrap; gap: 4px 8px; padding: 4px 8px; }
    .bottom-toolbar .page-nav,
    .bottom-toolbar .undo-redo-bar,
    .bottom-toolbar .snap-toggle-bar,
    .bottom-toolbar .zoom-control { display: flex; align-items: center; }
    .bottom-toolbar .page-nav { gap: 2px; padding: 2px 6px; order: 1; }
    .bottom-toolbar .undo-redo-bar { gap: 2px; order: 2; }
    .bottom-toolbar .zoom-control { gap: 4px; order: 3; }
    .bottom-toolbar .snap-toggle-bar { gap: 2px; order: 4; flex: 1 1 auto; justify-content: center; }
    .bottom-toolbar .page-indicator { display: none; }
    .bottom-toolbar .nav-btn { width: 24px; height: 24px; }
    .bottom-toolbar .nav-btn svg { width: 16px; height: 16px; }
    .bottom-toolbar .undo-redo-bar .tool-btn { width: 24px; height: 24px; font-size: 11px; }
    .bottom-toolbar .wizard-toggle-label { font-size: 9px; }
    .bottom-toolbar .wizard-toggle-track { width: 28px; height: 16px; }
    .bottom-toolbar .wizard-toggle-thumb { width: 12px; height: 12px; }
    .bottom-toolbar .wizard-toggle input:checked + .wizard-toggle-track .wizard-toggle-thumb { left: 14px; }
    .bottom-toolbar .zoom-btn { width: 20px; height: 20px; }
    .bottom-toolbar .zoom-btn svg { width: 12px; height: 12px; }
    .bottom-toolbar .zoom-slider { width: 60px; }
    .bottom-toolbar .zoom-value { font-size: 9px; min-width: 28px; }
    .right-sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        min-width: 100%;
        height: 0;
        max-height: none;
        border-left: none;
        border-top: 1px solid var(--border-medium);
        border-radius: 8px 8px 0 0;
        transform: translateY(100%);
        transition: transform 0.25s ease, height 0.25s ease;
        z-index: 200;
        overflow: hidden;
    }
    .right-sidebar.mobile-open {
        height: 35vh;
        max-height: 275px;
        transform: translateY(0);
    }
    .right-sidebar .sidebar-header {
        padding: 6px 10px;
        min-height: 32px;
        background: var(--text-dark);
    }
    .right-sidebar .sidebar-header h2 {
        font-size: 11px;
        font-weight: 600;
        letter-spacing: 0.5px;
        text-transform: uppercase;
    }
    .right-sidebar .properties-content {
        overflow-y: auto;
        padding: 6px;
        -webkit-overflow-scrolling: touch;
    }
    .prop-section {
        padding: 6px;
        border-bottom: none;
        border-right: none;
    }
    .prop-section:last-child { border-right: none; }
    .prop-body { flex-direction: column; gap: 4px; }
    .image-props .prop-body {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 6px;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }
    .image-props .prop-accordion-section {
        flex: 0 0 auto;
        width: 240px;
        scroll-snap-align: start;
        margin-bottom: 0;
    }
    .image-props.cover-mode .prop-body {
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
    }
    .image-props.cover-mode .prop-accordion-section {
        width: 100%;
        flex: 0 0 auto;
        scroll-snap-align: none;
    }
    .prop-accordion-section { margin-bottom: 4px; }
    .prop-accordion-header { font-size: 10px; padding: 3px 6px; }
    .prop-accordion-body { max-height: none !important; overflow: visible !important; opacity: 1 !important; padding: 4px 0 !important; }
    .prop-header { padding: 2px 0; min-height: 0; }
    .prop-header h3 { font-size: 9px; }
    .prop-toolbar {
        gap: 2px;
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
        padding-bottom: 2px;
    }
    .prop-toolbar .prop-btn-group { flex-shrink: 0; }
    .prop-toolbar .tool-btn { width: 24px; height: 24px; font-size: 10px; flex-shrink: 0; }
    .prop-btn-label { font-size: 7px; }
    .align-toolbar .tool-btn { width: 24px; }
    .color-toolbar .tool-btn { width: 18px; height: 18px; }
    .prop-row { gap: 4px; padding: 2px 0; }
    .prop-select { padding: 2px 4px; font-size: 10px; }
    .prop-input { padding: 2px 4px; font-size: 10px; }
    .prop-subheader { font-size: 8px; padding: 2px 0; }
    .thumb-delete { width: 14px; height: 14px; font-size: 9px; line-height: 14px; }
    .image-tooltip { display: none; }
    .handle { width: 14px; height: 14px; border-width: 2px; }
    .handle.tl { top: -8px; left: -8px; }
    .handle.tr { top: -8px; right: -8px; }
    .handle.bl { bottom: -8px; left: -8px; }
    .handle.br { bottom: -8px; right: -8px; }
    .handle.center { width: 28px; height: 28px; }
    .handle.center::before { width: 12px; height: 12px; }
    .handle.rot { top: -13px; width: 12px; height: 12px; }
    .selection-handles::before { top: -5px; height: 5px; }
}

@media (max-width: 480px) {
    .editor-header { min-height: 32px; }
    .page { width: calc(50vw - 4px); height: auto; }
    .page-content { padding: 2px; }
    .bottom-strip {min-height: 44px;}
    .strip-thumb {flex: 2 0 48px;min-width: 80px;}
    .strip-nav { width: 16px; height: 22px; }
    .price-value { font-size: 11px; }
    .spread-image { min-width: 20px; min-height: 20px; }
    .left-sidebar .content-panel.active .gallery-img { flex: 0 0 52px; width: 52px; height: 52px; }
    .left-sidebar .content-panel.active .product-item { flex: 0 0 100px; min-width: 100px; }
}

/* Preview Modal */
.preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(30,30,30,0.95);
    display: none;
    flex-direction: column;
    z-index: 10000;
}
.preview-overlay.visible { display: flex; }
.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: rgba(0,0,0,0.3);
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.preview-header h3 {
    color: var(--white);
    font-size: 16px;
    margin: 0;
}
.preview-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: var(--white);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.preview-close:hover { background: rgba(255,255,255,0.2); }
/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}
.loading-card {
    background: rgba(30,30,30,0.85);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 16px;
    padding: 40px 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 40px rgba(0,0,0,0.35);
    min-width: 260px;
}
.loading-spinner {
    width: 56px;
    height: 56px;
    border: 5px solid rgba(255,255,255,0.15);
    border-top-color: var(--accent);
    border-right-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
    color: var(--white);
    margin-top: 20px;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.loading-percent {
    color: var(--accent);
    margin-top: 6px;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.loading-subtext {
    color: rgba(255,255,255,0.55);
    margin-top: 10px;
    font-size: 13px;
    font-weight: 400;
}
.loading-progress-track {
    width: 100%;
    height: 5px;
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
    margin-top: 18px;
    overflow: hidden;
}
.loading-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.35s ease;
}

.preview-body {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.preview-spread {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotateY(-90deg);
    transform-origin: center center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s ease;
    perspective: 1200px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
}
.preview-spread.active {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) rotateY(0deg);
}

.preview-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px;
    background: rgba(0,0,0,0.3);
    border-top: 1px solid rgba(255,255,255,0.1);
}
.preview-nav {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: var(--white);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.preview-nav:hover { background: rgba(255,255,255,0.2); }
.preview-nav:disabled { opacity: 0.3; cursor: not-allowed; }

/* Snap alignment guides */
.snap-guide {
    position: absolute;
    background: var(--accent);
    pointer-events: none;
    z-index: 9999;
    opacity: 0.7;
}
.snap-guide-h { height: 1px; left: 0; right: 0; }
.snap-guide-v { width: 1px; top: 0; bottom: 0; }
.preview-page-num {
    color: var(--white);
    font-size: 13px;
    font-weight: 500;
    min-width: 60px;
    text-align: center;
}

/* Drag state */
.dragging { opacity: 0.6; cursor: grabbing !important; }
.drag-over { border: 2px dashed var(--accent) !important; }

/* Help tooltip */
.help-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-dark);
    color: var(--white);
    font-size: 11px;
    line-height: 1.4;
    padding: 8px 10px;
    border-radius: 6px;
    width: 220px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    text-align: left;
}
.help-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--text-dark);
}
.help-tooltip.tooltip-below::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: var(--text-dark);
}
.help-tooltip.visible { display: block; }

/* Scrollbars */
.sidebar-content::-webkit-scrollbar,
.properties-content::-webkit-scrollbar { width: 5px; }
.sidebar-content::-webkit-scrollbar-track,
.properties-content::-webkit-scrollbar-track { background: transparent; }
.sidebar-content::-webkit-scrollbar-thumb,
.properties-content::-webkit-scrollbar-thumb { background: var(--border-medium); border-radius: 3px; }

/* Order Success Overlay */
.order-success-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}
.order-success-box {
    background: var(--white);
    border-radius: 8px;
    padding: 32px;
    text-align: center;
    max-width: 360px;
    box-shadow: var(--shadow-medium);
}
.order-success-icon {
    font-size: 48px;
    color: #28a745;
    margin-bottom: 12px;
}
.order-success-box h3 {
    margin: 0 0 8px;
    font-size: 18px;
    color: var(--text-dark);
}
.order-success-box p {
    margin: 0 0 20px;
    color: var(--text-medium);
    font-size: 14px;
}
.order-success-btn {
    background: var(--accent);
    color: var(--white);
    border: none;
    border-radius: 4px;
    padding: 10px 32px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.order-success-btn:hover { background: var(--accent-light); }

/* Editor Toast */
.editor-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(40,40,40,0.92);
    color: var(--white);
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    z-index: 99998;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    display: none;
    opacity: 0;
    align-items: center;
    gap: 8px;
    max-width: 90vw;
    white-space: nowrap;
}
.editor-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.editor-toast .toast-icon {
    font-size: 14px;
    flex-shrink: 0;
}
.editor-toast.toast-info .toast-icon { color: #3498db; }
.editor-toast.toast-success .toast-icon { color: #2ecc71; }
.editor-toast.toast-warning .toast-icon { color: #f39c12; }
.editor-toast.toast-error .toast-icon { color: #e74c3c; }

/* ============================================
   TEMPLATE PREVIEW MODAL (hover)
   ============================================ */
.template-preview-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.template-preview-modal.visible {
    opacity: 1;
    pointer-events: auto;
}
.template-preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
}
.template-preview-content {
    position: relative;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
    width: 95vw;
    max-width: 1400px;
    max-height: 85vh;
    overflow: auto;
    padding: 18px 22px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.template-preview-footer {
    display: flex;
    justify-content: center;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
}
.template-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 10px;
}
.template-preview-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
}
.template-preview-close {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    color: var(--text-light);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.template-preview-close:hover {
    background: rgba(0,0,0,0.06);
    color: var(--text-dark);
}
.template-preview-body {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
}
.preview-spread-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.preview-spread-row {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 0;
}
.preview-page-box {
    background: #fff;
    overflow: hidden;
    position: relative;
    border: 1px solid #ddd;
    flex-shrink: 0;
}
.preview-page-box:first-child {
    border-radius: 2px 0 0 2px;
    border-right: none;
}
.preview-page-box:last-child {
    border-radius: 0 2px 2px 0;
    border-left: none;
}
.preview-spine {
    width: 3px;
    background: linear-gradient(to right, #e0e0e0, #bbb, #999, #bbb, #e0e0e0);
    flex-shrink: 0;
}
/* Loading overlay for template preview */
.template-preview-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.9);
    z-index: 10;
    font-size: 14px;
    color: var(--text-light);
    gap: 12px;
}
.template-preview-loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-light);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.preview-spread-label {
    font-size: 10px;
    color: var(--text-light);
    text-align: center;
    font-weight: 500;
}
/* In preview modal, show mask shapes normally */
.preview-page-inner .mask-decoration:not([data-has-image="true"]) .mask-inner {
    background: transparent !important;
}
.preview-page-inner .mask-decoration:not([data-has-image="true"]) .mask-inner > img {
    opacity: 1 !important;
}