/* PlexiFrames Customize Page — Modern Contained Design */
/* Inherits design tokens from plexiframes-create.css */

body.plexiframes-customize {
    font-family: var(--font-body);
    background: var(--pf-bg);
    color: var(--pf-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===========================================
   Step indicator — completed state
   =========================================== */
.step.completed {
    color: var(--pf-text-muted);
}

.step.completed .step-number {
    color: var(--pf-text-muted);
}

.step.completed .step-number svg {
    width: 14px;
    height: 14px;
}

.step-connector.completed {
    background: var(--pf-border);
}

/* ===========================================
   Customize Main — Contained
   =========================================== */
.customize-main {
    flex: 1;
    padding: 1.5rem 2rem;
}

.customize-container {
    max-width: 1440px;
    margin: 0 auto;
}

/* Header */
.customize-header {
    text-align: center;
    margin-bottom: 2rem;
}

.customize-title {
    font-family: var(--font-body);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--pf-text);
    margin-bottom: 0.375rem;
}

.customize-subtitle {
    color: var(--pf-text-muted);
    font-size: 0.9375rem;
    line-height: 1.5;
}

/* ===========================================
   Customizer Component
   =========================================== */
.customizer {
    position: relative;
}

/* Loading & Error */
.customizer-loading,
.customizer-error {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    background: var(--pf-surface);
    border-radius: var(--pf-radius);
    padding: 2rem;
}

.customizer-error .error-message {
    text-align: center;
}

.customizer-error svg {
    width: 48px;
    height: 48px;
    color: var(--pf-error);
    margin-bottom: 1rem;
}

.customizer-error p {
    color: var(--pf-text-muted);
    margin-bottom: 1rem;
}

.customizer-error button {
    background: var(--pf-primary);
    color: var(--pf-white);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.875rem;
}

/* Saving indicator */
.saving-indicator {
    position: fixed;
    top: 70px;
    right: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--pf-surface);
    padding: 0.5rem 1rem;
    border-radius: 50px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    z-index: 100;
    font-size: 0.8125rem;
    color: var(--pf-text-muted);
}

.spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid var(--pf-border);
    border-top-color: var(--pf-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===========================================
   Two-Panel Layout: Photo Library + Order Builder
   =========================================== */
.customize-layout {
    display: grid;
    grid-template-columns: minmax(320px, 420px) 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* --- Photo Library (left panel) --- */
.photo-library {
    background: var(--pf-surface);
    border-radius: var(--pf-radius);
    padding: 1.25rem;
}

.library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.library-header-left {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.library-title {
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    color: var(--pf-text);
}

.library-count {
    font-size: 0.8125rem;
    color: var(--pf-text-muted);
}

.library-collapse-btn {
    display: none; /* Only visible on mobile */
    width: 32px;
    height: 32px;
    border: 1px solid var(--pf-border);
    border-radius: 8px;
    background: transparent;
    color: var(--pf-text-muted);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.library-collapse-btn:hover {
    border-color: var(--pf-accent);
    color: var(--pf-accent);
}

.library-collapse-btn svg {
    width: 18px;
    height: 18px;
}

.library-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.library-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: transparent;
    border: 1px solid var(--pf-border);
    border-radius: 50px;
    color: var(--pf-text-muted);
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.library-action-btn:hover {
    border-color: var(--pf-accent);
    color: var(--pf-accent);
}

.library-action-btn.danger:hover {
    border-color: var(--pf-error);
    color: var(--pf-error);
}

.library-action-btn svg {
    width: 14px;
    height: 14px;
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.625rem;
}

.library-photo {
    position: relative;
    aspect-ratio: 1;
    border-radius: 10px;
    overflow: hidden;
    background: var(--pf-bg);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 3px solid transparent;
}

.library-photo:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.library-photo.selected {
    border-color: var(--pf-accent);
    box-shadow: 0 0 0 1px var(--pf-accent);
}

.library-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.library-check {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    background: rgba(0, 0, 0, 0.25);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s;
    color: white;
}

.library-check.checked {
    background: var(--pf-accent);
    border-color: var(--pf-accent);
}

.library-check svg {
    width: 14px;
    height: 14px;
}

.library-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: all 0.2s;
}

.library-photo:hover .library-remove {
    opacity: 1;
}

.library-remove:hover {
    background: var(--pf-error);
}

.library-remove svg {
    width: 12px;
    height: 12px;
}

/* --- Order Builder (right panel) --- */
.order-builder {
    position: sticky;
    top: 1rem;
}

.order-builder-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    min-height: 300px;
    background: var(--pf-surface);
    border-radius: var(--pf-radius);
    padding: 2rem;
    text-align: center;
}

.order-builder-empty svg {
    width: 48px;
    height: 48px;
    color: var(--pf-border);
}

.order-builder-empty p {
    color: var(--pf-text-muted);
    font-size: 0.9375rem;
}

/* --- Selected Photos Strip --- */
.order-strip-section {
    background: var(--pf-surface);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.order-strip-title {
    font-family: var(--font-body);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--pf-text-muted);
    margin-bottom: 0.625rem;
}

.order-photos-strip {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 0.25rem;
}

.order-photos-strip::-webkit-scrollbar {
    height: 4px;
}

.order-photos-strip::-webkit-scrollbar-thumb {
    background: var(--pf-border);
    border-radius: 4px;
}

.strip-thumb {
    position: relative;
    flex-shrink: 0;
    width: 72px;
    height: 72px;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.2s;
}

.strip-thumb:hover {
    border-color: var(--pf-border);
}

.strip-thumb.active {
    border-color: var(--pf-success);
    box-shadow: 0 2px 10px rgba(16, 185, 129, 0.3);
}

.strip-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.strip-check svg {
    width: 10px;
    height: 10px;
}

.strip-badge {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--pf-accent);
    color: var(--pf-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5625rem;
    font-weight: 700;
}

/* ===========================================
   Image Customizer — Two Column
   =========================================== */
.image-customizer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    background: var(--pf-surface);
    border-radius: var(--pf-radius);
    padding: 1.25rem;
}

/* Preview Section */
.preview-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.preview-section .plexi-preview-wrapper {
    height: 400px;
}

.quantity-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.quantity-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--pf-text-muted);
}

.quantity-controls {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    background: var(--pf-bg);
    border-radius: 50px;
    padding: 0.25rem;
}

.qty-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--pf-surface);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--pf-text);
}

.qty-btn:hover:not(:disabled) {
    background: var(--pf-primary);
    color: var(--pf-white);
}

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

.qty-btn svg {
    width: 16px;
    height: 16px;
}

.qty-value {
    width: 36px;
    text-align: center;
    font-weight: 600;
    font-size: 1rem;
}

.btn-edit-crop {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: var(--pf-bg);
    border: 1px solid var(--pf-border);
    border-radius: 50px;
    color: var(--pf-text);
    font-family: var(--font-body);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-edit-crop:hover {
    background: var(--pf-primary);
    color: var(--pf-white);
    border-color: var(--pf-primary);
}

.btn-edit-crop svg {
    width: 16px;
    height: 16px;
}

/* Expand 3D Preview Button */
.btn-expand-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 1rem;
    background: var(--pf-bg);
    border: 1px solid var(--pf-border);
    border-radius: 50px;
    color: var(--pf-text-muted);
    font-family: var(--font-body);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-expand-preview:hover {
    background: var(--pf-primary);
    color: var(--pf-white);
    border-color: var(--pf-primary);
}

.btn-expand-preview svg {
    width: 16px;
    height: 16px;
}

/* Expanded 3D Preview Modal */
.preview-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.preview-modal {
    position: relative;
    width: 90vw;
    max-width: 1100px;
    border-radius: var(--pf-radius);
    overflow: hidden;
}

.preview-modal .plexi-preview-wrapper {
    height: 80vh;
    border-radius: var(--pf-radius);
}

.preview-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 1010;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.preview-modal-close:hover {
    background: rgba(0, 0, 0, 0.9);
    border-color: white;
    transform: scale(1.1);
}

.preview-modal-close svg {
    width: 22px;
    height: 22px;
}

/* Controls Section */
.controls-section {
    min-width: 0;
}

/* ===========================================
   Size Selector
   =========================================== */
.size-selector {
    background: var(--pf-bg);
    border-radius: 12px;
    padding: 1.25rem;
}

.size-selector-title {
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    color: var(--pf-text);
    margin-bottom: 1rem;
}

/* Orientation tabs */
.size-orientation-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
}

.size-orientation-tab {
    flex: 1;
    padding: 7px 0;
    border: 1.5px solid var(--pf-border, #e5e5e5);
    border-radius: 8px;
    background: #fff;
    color: var(--pf-text-muted, #525252);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-body);
}

.size-orientation-tab:hover {
    border-color: #a3a3a3;
    color: var(--pf-text);
}

.size-orientation-tab.active {
    background: var(--pf-primary);
    border-color: var(--pf-primary);
    color: #fff;
}

.size-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.625rem;
}

.size-card {
    position: relative;
    background: var(--pf-surface);
    border: 2px solid var(--pf-border);
    border-radius: 12px;
    padding: 1rem 0.625rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.size-card:hover:not(:disabled) {
    border-color: #a3a3a3;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.size-card.selected {
    border-color: var(--pf-primary);
    background: #f0f4f8;
}

.size-card.unavailable {
    opacity: 0.4;
    cursor: not-allowed;
}

.size-card .size-name {
    font-family: var(--font-body);
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--pf-primary);
    margin-bottom: 0.25rem;
}

.size-card .size-dimensions {
    font-size: 0.6875rem;
    color: var(--pf-text-muted);
    margin-bottom: 0.5rem;
}

.size-pricing {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
}

.sale-price {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--pf-primary);
}

.list-price {
    font-size: 0.6875rem;
    color: var(--pf-text-muted);
    text-decoration: line-through;
}

.unavailable-reason {
    font-size: 0.625rem;
    color: var(--pf-error);
    margin-top: 0.25rem;
    font-weight: 500;
}

.selected-check {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    background: var(--pf-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 2px 6px rgba(26, 35, 50, 0.2);
}

.selected-check svg {
    width: 12px;
    height: 12px;
}

.size-selector-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.875rem;
    border-top: 1px solid var(--pf-border);
}

.discount-badge {
    background: var(--pf-accent);
    color: var(--pf-primary);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.25rem 0.625rem;
    border-radius: 50px;
}

.discount-text {
    font-size: 0.8125rem;
    color: var(--pf-text-muted);
}

/* ===========================================
   Cropper Section
   =========================================== */
.cropper-section {
    background: var(--pf-bg);
    border-radius: 12px;
    padding: 1.25rem;
}

.cropper-header {
    text-align: center;
    margin-bottom: 0.75rem;
}

.cropper-header h3 {
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    color: var(--pf-text);
    margin-bottom: 0.25rem;
}

.cropper-header p {
    font-size: 0.8125rem;
    color: var(--pf-text-muted);
}

.cropper-actions {
    display: flex;
    gap: 0.625rem;
    margin-top: 1rem;
}

.btn-cancel-crop {
    flex: 1;
    padding: 0.625rem 1rem;
    background: var(--pf-surface);
    color: var(--pf-text-muted);
    border: 1px solid var(--pf-border);
    border-radius: 50px;
    font-family: var(--font-body);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel-crop:hover {
    background: var(--pf-bg);
    color: var(--pf-text);
}

.btn-done-cropping {
    flex: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: var(--pf-primary);
    color: var(--pf-white);
    border: none;
    border-radius: 50px;
    font-family: var(--font-body);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-done-cropping:hover {
    background: var(--pf-primary-light);
}

.btn-done-cropping svg {
    width: 16px;
    height: 16px;
}

/* ===========================================
   Disabled / Already-Added Size Cards
   =========================================== */
.size-card.already-added {
    opacity: 0.5;
    cursor: not-allowed;
    border-style: dashed;
}

.size-card.already-added:hover {
    transform: none;
    box-shadow: none;
    border-color: var(--pf-border);
}

.already-added-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: var(--pf-text-muted);
    color: var(--pf-white);
    font-size: 0.625rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 50px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ===========================================
   Back to Sizes Button (when adding another)
   =========================================== */
.btn-back-to-sizes {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: none;
    border: none;
    color: var(--pf-text-muted);
    font-family: var(--font-body);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0 0 0.75rem;
    transition: color 0.2s;
}

.btn-back-to-sizes:hover {
    color: var(--pf-primary);
}

.btn-back-to-sizes svg {
    width: 14px;
    height: 14px;
}

/* ===========================================
   Entries List (multi-size per image)
   =========================================== */
.entries-list {
    background: var(--pf-bg);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.entries-title {
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    color: var(--pf-text);
    margin-bottom: 0.25rem;
}

/* --- Entry Card --- */
.entry-card {
    background: var(--pf-surface);
    border: 2px solid var(--pf-border);
    border-radius: 12px;
    padding: 0.875rem 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.entry-card:hover {
    border-color: var(--pf-accent);
}

.entry-card.active {
    border-color: var(--pf-primary);
    box-shadow: 0 2px 8px rgba(26, 35, 50, 0.08);
}

.entry-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.entry-size {
    font-family: var(--font-body);
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--pf-primary);
}

.entry-price {
    font-size: 1rem;
    font-weight: 700;
    color: var(--pf-primary);
    margin-left: auto;
}

.btn-entry-remove {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--pf-border);
    border-radius: 50%;
    color: var(--pf-text-muted);
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
}

.btn-entry-remove:hover {
    background: var(--pf-error);
    border-color: var(--pf-error);
    color: var(--pf-white);
}

.btn-entry-remove svg {
    width: 14px;
    height: 14px;
}

.entry-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.entry-quantity {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--pf-bg);
    border-radius: 50px;
    padding: 0.15rem;
}

.entry-quantity .qty-btn {
    width: 28px;
    height: 28px;
}

.entry-quantity .qty-value {
    width: 28px;
    font-size: 0.875rem;
}

.btn-entry-edit {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: none;
    border: 1px solid var(--pf-border);
    border-radius: 50px;
    padding: 0.375rem 0.75rem;
    color: var(--pf-text);
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-entry-edit:hover {
    background: var(--pf-primary);
    color: var(--pf-white);
    border-color: var(--pf-primary);
}

.btn-entry-edit svg {
    width: 14px;
    height: 14px;
}

/* --- Add Another Size Button --- */
.btn-add-size {
    width: 100%;
    padding: 0.875rem 1rem;
    background: transparent;
    border: 2px dashed var(--pf-border);
    border-radius: 12px;
    color: var(--pf-accent);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-add-size:hover {
    border-color: var(--pf-accent);
    background: rgba(0, 0, 0, 0.02);
    transform: translateY(-1px);
}

.btn-add-size svg {
    width: 18px;
    height: 18px;
}

/* --- Multi-size badge on photo grid thumbnail --- */
.multi-size-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 22px;
    height: 22px;
    background: var(--pf-accent);
    color: var(--pf-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6875rem;
    font-weight: 700;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

/* ===========================================
   Image Cropper Component
   =========================================== */
.image-cropper {
    width: 100%;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.cropper-container {
    position: relative;
    width: 100%;
    background: #1a1a1a;
    border-radius: 8px;
    overflow: hidden;
    touch-action: none;
    -webkit-overflow-scrolling: touch;
    isolation: isolate;
}

.cropper-container.cropping {
    cursor: grabbing;
}

.cropper-container.cropping .crop-area {
    cursor: grabbing;
}

.cropper-image {
    display: block;
    width: 100%;
    height: auto;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

.crop-overlay {
    position: absolute;
    background: rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

/* Top: full width, from top down to crop */
.crop-overlay-top    { top: 0; left: 0; right: 0; height: 0; }
/* Bottom: full width, from crop bottom to container bottom */
.crop-overlay-bottom { left: 0; right: 0; height: 0; }
/* Left/Right: same height as crop area, flush to sides */
.crop-overlay-left   { left: 0; width: 0; }
.crop-overlay-right  { right: 0; width: 0; }

.crop-area {
    position: absolute;
    border: 2px solid white;
    cursor: move;
    touch-action: none;
    will-change: transform;
    z-index: 1;
}

.crop-grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
    contain: strict;
}

.grid-line {
    position: absolute;
    background: rgba(255, 255, 255, 0.3);
}

.grid-line-h1,
.grid-line-h2 {
    left: 0;
    right: 0;
    height: 1px;
}

.grid-line-h1 { top: 33.33%; }
.grid-line-h2 { top: 66.66%; }

.grid-line-v1,
.grid-line-v2 {
    top: 0;
    bottom: 0;
    width: 1px;
}

.grid-line-v1 { left: 33.33%; }
.grid-line-v2 { left: 66.66%; }

.resize-handle {
    position: absolute;
    width: 20px;
    height: 20px;
    background: white;
    border: 2px solid var(--pf-primary);
    border-radius: 50%;
    z-index: 10;
    touch-action: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.resize-nw { top: -2px; left: -2px; cursor: nwse-resize; }
.resize-ne { top: -2px; right: -2px; cursor: nesw-resize; }
.resize-sw { bottom: -2px; left: -2px; cursor: nesw-resize; }
.resize-se { bottom: -2px; right: -2px; cursor: nwse-resize; }

@media (pointer: coarse), (max-width: 768px) {
    .resize-handle {
        width: 32px;
        height: 32px;
    }

    .resize-nw { top: -4px; left: -4px; }
    .resize-ne { top: -4px; right: -4px; }
    .resize-sw { bottom: -4px; left: -4px; }
    .resize-se { bottom: -4px; right: -4px; }

    .crop-area {
        border-width: 3px;
    }
}

/* ===========================================
   Navigation — Back + Add to Cart
   =========================================== */
.customizer-nav {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--pf-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--pf-text-muted);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: color 0.2s;
}

.btn-back:hover {
    color: var(--pf-primary);
}

.btn-back svg {
    width: 16px;
    height: 16px;
}

.btn-add-to-cart {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--pf-primary);
    color: var(--pf-white);
    padding: 0.75rem 1.75rem;
    border-radius: 10px;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.btn-add-to-cart:hover:not(:disabled) {
    background: var(--pf-primary-light);
    transform: translateY(-1px);
}

.btn-add-to-cart:active:not(:disabled) {
    transform: translateY(0);
}

.btn-add-to-cart:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-add-to-cart svg {
    width: 20px;
    height: 20px;
}

/* ===========================================
   Validation & Error
   =========================================== */
.cart-validation-warning {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.cart-validation-warning svg {
    flex-shrink: 0;
    width: 1.25rem;
    height: 1.25rem;
    color: #d97706;
    margin-top: 0.1rem;
}

.cart-validation-warning p {
    margin: 0;
    line-height: 1.4;
}

.validation-content {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.validation-thumbs {
    display: flex;
    gap: 0.375rem;
    flex-wrap: wrap;
}

.validation-thumb {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid #f59e0b;
    cursor: pointer;
    transition: all 0.2s;
}

.validation-thumb:hover {
    border-color: #d97706;
    transform: translateY(-1px);
}

.validation-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cart-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--pf-error);
    padding: 0.75rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    text-align: center;
}

/* ===========================================
   Responsive
   =========================================== */

/* Stack to single column below 1024px */
@media (max-width: 1024px) {
    .customize-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .order-builder {
        position: static;
    }

    .library-collapse-btn {
        display: flex;
    }

    .photo-library.collapsed .library-header {
        margin-bottom: 0;
    }

    .library-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    }
}

@media (max-width: 768px) {
    .customize-main {
        padding: 1.5rem 1rem;
    }

    .customize-header {
        margin-bottom: 1.5rem;
    }

    .customize-title {
        font-size: 1.5rem;
    }

    .customize-subtitle {
        font-size: 0.875rem;
    }

    .image-customizer {
        grid-template-columns: 1fr;
        padding: 1rem;
        border-radius: 12px;
    }

    .preview-section .plexi-preview-wrapper {
        height: 320px;
        border-radius: 12px;
    }

    .size-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .quantity-section {
        flex-wrap: wrap;
        gap: 0.625rem;
    }

    .btn-edit-crop {
        width: 100%;
    }

    .cropper-section {
        padding: 1rem;
        border-radius: 10px;
    }

    .photo-library {
        padding: 1rem;
    }

    /* Sticky continue bar on mobile */
    .customizer-nav {
        position: sticky;
        bottom: 0;
        padding: 1rem;
        margin: 0 -1rem;
        width: calc(100% + 2rem);
        background: var(--pf-surface);
        border-top: 1px solid var(--pf-border);
        border-radius: 0;
        z-index: 50;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
    }

    .btn-add-to-cart {
        padding: 0.75rem 1.5rem;
        font-size: 0.9375rem;
    }
}

@media (max-width: 480px) {
    .customize-main {
        padding: 1.25rem 0.75rem;
    }

    .customize-title {
        font-size: 1.25rem;
    }

    .image-customizer {
        padding: 0.75rem;
        border-radius: 10px;
        gap: 0.75rem;
    }

    .preview-section .plexi-preview-wrapper {
        height: 260px;
        border-radius: 10px;
    }

    .size-selector {
        padding: 1rem 0.75rem;
    }

    .size-grid {
        gap: 0.5rem;
    }

    .size-card {
        padding: 0.75rem 0.5rem;
        border-radius: 8px;
    }

    .size-card .size-name {
        font-size: 0.9375rem;
    }

    .sale-price {
        font-size: 1rem;
    }

    .entry-card {
        padding: 0.75rem;
    }

    .entry-controls {
        flex-wrap: wrap;
    }

    .saving-indicator {
        top: auto;
        bottom: 5rem;
        right: 0.75rem;
    }

    .cropper-actions {
        flex-direction: column;
    }

    .btn-cancel-crop,
    .btn-done-cropping {
        flex: auto;
    }

    .photo-library {
        padding: 0.75rem;
    }

    .library-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }

    .customizer-nav {
        margin: 0 -0.75rem;
        width: calc(100% + 1.5rem);
        padding: 0.875rem 0.75rem;
    }
}

@media (max-width: 360px) {
    .size-grid {
        grid-template-columns: 1fr 1fr;
    }

    .library-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===========================================
   Responsive — Additional Coverage
   =========================================== */

/* ── Wide desktop 1440px+ ── */
@media (min-width: 1440px) {
    .customize-main {
        padding: 2rem 3rem;
    }

    .customize-layout {
        gap: 2rem;
    }

    .photo-library {
        padding: 1.5rem;
    }

    .image-customizer {
        padding: 1.5rem;
        gap: 1.5rem;
    }

    .preview-section .plexi-preview-wrapper {
        height: 460px;
    }
}

/* ── Mid-desktop 1025px–1280px ──
   2-col main layout but right panel only ~516–770px wide,
   too narrow for a 2-col image-customizer (size cards end up ~62px).
   Collapse inner grid to single column until 1280px. */
@media (min-width: 1025px) and (max-width: 1280px) {
    .image-customizer {
        grid-template-columns: 1fr;
    }

    .preview-section .plexi-preview-wrapper {
        height: 340px;
    }

    .size-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ── Tablet landscape 769px–1024px ──
   Single-column main layout, image-customizer fills full width.
   Slightly taller preview, ensure size-grid stays 3-col. */
@media (min-width: 769px) and (max-width: 1024px) {
    .preview-section .plexi-preview-wrapper {
        height: 360px;
    }

    .size-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ── Small mobile ≤640px ── */
@media (max-width: 640px) {
    /* Condense the 3D preview interaction hint pill */
    .preview-hint {
        gap: 1rem;
        padding: 0.5rem 1rem;
    }

    .hint-phase-rotate {
        padding-right: 1rem;
    }

    /* Hide text labels — icons alone are enough on small screens */
    .hint-label {
        display: none;
    }

    /* Smaller strip thumbs to show more at once */
    .strip-thumb {
        width: 60px;
        height: 60px;
    }

    .order-strip-section {
        padding: 0.625rem 0.75rem;
    }

    /* Library action buttons wrap on very narrow panels */
    .library-actions {
        flex-wrap: wrap;
    }
}

/* ── Very small phones ≤380px ── */
@media (max-width: 380px) {
    .library-action-btn {
        padding: 0.3rem 0.625rem;
        font-size: 0.6875rem;
    }

    /* Prevent hint pill from overflowing preview on 320px screens */
    .preview-hint {
        gap: 0.5rem;
        padding: 0.4rem 0.75rem;
    }

    .hint-phase-rotate {
        padding-right: 0.75rem;
    }
}
