.bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    /* Sits on the visible viewport: the mobile keyboard insets it instead of
       covering it (--kb-inset is written by the inline text editor and by
       main.js when a control inside the sheet takes focus). */
    bottom: var(--kb-inset);
    background: var(--color-surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-sheet);
    z-index: 50;
    transform: translateY(100%);
    transition: transform var(--transition-med);
    /* Height stays content driven; JS caps it for the current viewport
       (--sheet-max) and reserves the real height from the work area
       (.app.sheet-open .app-body). Never a hard-coded share of the screen. */
    max-height: var(--sheet-max);
    display: flex;
    flex-direction: column;
    visibility: hidden;
    padding-bottom: var(--safe-bottom);
}

.bottom-sheet.open {
    transform: translateY(0);
    visibility: visible;
}

.sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-border-strong);
    margin: var(--space-3) auto var(--space-1);
    flex-shrink: 0;
}

.sheet-backdrop {
    position: fixed;
    inset: 0 0 var(--kb-inset) 0;
    background: rgba(15, 23, 42, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-med);
    z-index: 45;
}

.sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

/* Elements quick bar on mobile: see .el-quickbar in toolbar.css (single source) */

/* Filter chips */
.filter-chip {
    height: 38px;
    padding: 0 var(--space-3);
    border-radius: 19px;
    border: 1px solid var(--color-border-strong);
    background: var(--color-surface);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-muted);
    white-space: nowrap;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.filter-chip.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.chip-scroll {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding-bottom: var(--space-2);
}

.size-presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-2);
}

.size-preset {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-1);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-text-muted);
    transition: all var(--transition-fast);
}

.size-preset .ratio-box {
    width: 28px;
    height: 28px;
    border: 2px solid currentColor;
    border-radius: 4px;
    opacity: 0.7;
}

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

.size-preset.active {
    background: var(--color-primary-soft);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.size-preset-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-size-row {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.custom-size-field {
    flex: 1 1 0;
    min-width: 0;
}

.custom-size-field .input-num {
    width: 100%;
}

.spacer {
    flex: 1 1 auto;
}

/* Project browser modal (js/ui/ProjectsModal.js) */
.pd-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: 60;
}

.pd-modal[hidden] {
    display: none;
}

.pd-modal-card {
    width: min(560px, 100%);
    max-height: min(80vh, 720px);
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* Blocking confirmation dialog (replaces window.confirm). Same backdrop and
   card language as .pd-modal; the dialog cannot be dismissed by tapping the
   backdrop — only via its two buttons (or Escape, which cancels). */
.confirm-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: 80;
}

.confirm-dialog {
    width: min(340px, 100%);
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-5);
    text-align: center;
}

.confirm-message {
    margin: 0 0 var(--space-4);
    color: var(--color-text);
    font-size: var(--font-size-base);
    line-height: 1.6;
}

.confirm-actions {
    display: flex;
    gap: var(--space-2);
    justify-content: center;
}

.confirm-actions .btn-primary,
.confirm-actions .btn-ghost {
    flex: 1;
}

.pd-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.pd-modal-title {
    font-size: var(--font-size-lg);
    font-weight: 700;
}

.pd-modal-head-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.pd-project-list {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: var(--space-3) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.pd-project {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-muted);
}

.pd-project.current {
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
}

.pd-project-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.pd-project-info-edit {
    flex: 1 1 auto;
}

.pd-project-info-icon {
    display: flex;
    align-items: center;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.pd-project-info-text {
    min-width: 0;
}

.pd-project-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pd-project-meta {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.pd-badge {
    display: inline-block;
    margin-inline-start: var(--space-2);
    padding: 2px var(--space-2);
    border-radius: 999px;
    background: var(--color-primary);
    color: #fff;
    font-size: var(--font-size-xs);
    font-weight: 600;
}

.pd-project-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

.pd-modal-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-muted);
}

.pd-modal-note {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* Template gallery (js/ui/TemplateGallery.js): full-screen browser with
   search, category chips and a lazy thumbnail grid with infinite scroll. */
.tg-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: 70;
}

.tg-card {
    width: min(920px, 100%);
    max-height: min(92vh, 860px);
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.tg-head {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.tg-title {
    font-size: var(--font-size-lg);
    font-weight: 700;
    white-space: nowrap;
}

.tg-search {
    flex: 1 1 auto;
    height: 40px;
    padding: 0 var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    font-size: var(--font-size-sm);
    min-width: 0;
}

.tg-chips {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    overflow-x: auto;
    border-bottom: 1px solid var(--color-border);
    scrollbar-width: none;
}

.tg-chips-sub {
    padding-top: var(--space-1);
}

.tg-chips-sub:empty {
    display: none;
}

.tg-chips-sub .tg-chip {
    height: 30px;
    font-size: 12px;
}

.tg-chips::-webkit-scrollbar {
    display: none;
}

.tg-chip {
    flex: 0 0 auto;
    height: 36px;
    padding: 0 var(--space-4);
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-muted);
}

.tg-chip.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.tg-grid-wrap {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--space-4);
    min-height: 0;
}

.tg-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-2);
}

@media (min-width: 700px) {
    .tg-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: var(--space-3);
    }
}

@media (min-width: 1000px) {
    .tg-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Small phones (360px): tighter modal so the grid breathes. */
@media (max-width: 480px) {
    .tg-modal {
        padding: var(--space-2);
    }

    .tg-card {
        max-height: 94vh;
    }

    .tg-head {
        padding: var(--space-2) var(--space-3);
    }

    .tg-grid-wrap {
        padding: var(--space-2);
    }

    .tg-name {
        font-size: 11px;
    }
}

.tg-card-btn {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    text-align: center;
    border-radius: var(--radius-md);
}

.tg-thumb {
    display: block;
    aspect-ratio: 3 / 4;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
}

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

.tg-thumb-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}

.tg-name {
    font-size: var(--font-size-xs);
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 var(--space-1);
}

.tg-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--color-text-muted);
    padding: var(--space-6) 0;
}

.tg-sentinel {
    height: 1px;
}


.pd-btn {
    min-height: 38px;
}

.pd-icon-btn {
    min-width: 38px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.pd-icon-btn.danger {
    color: var(--color-danger);
}

@media (max-width: 1023px) {
    .pd-modal {
        padding: 0;
        align-items: flex-end;
    }

    .pd-modal-card {
        width: 100%;
        max-height: 88vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding-bottom: var(--safe-bottom);
    }

    .pd-project {
        flex-wrap: wrap;
    }
}

/* ===== Size panel - brand icons and subtle crop (scoped) ===== */
.panel[data-panel="size"] .brand-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 20px;
    flex: 0 0 auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.panel[data-panel="size"] .size-preset-dims {
    font-size: 10px;
    color: #888;
    direction: ltr;
}

.panel[data-panel="size"] .crop-subtle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    background: #fafafa;
    color: #333;
}

.panel[data-panel="size"] .crop-subtle-btn .crop-btn-icon {
    font-size: 14px;
}
/* ===== New elements: current size card, apply button ===== */
.panel[data-panel="size"] .current-size-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8f7ff;
    border-radius: 16px;
    padding: 14px 16px;
    margin-bottom: 8px;
}

.panel[data-panel="size"] .current-size-label {
    font-size: 13px;
    color: #666;
}

.panel[data-panel="size"] .current-size-value {
    font-size: 15px;
    font-weight: 700;
    color: #1a1a1a;
    direction: ltr;
}

.panel[data-panel="size"] .apply-size-btn {
    padding: 10px 24px;
    font-size: 14px;
    white-space: nowrap;
}

/* ===== Size Panel V3 - Balanced ===== */

/* Base: comfortable middle-ground fonts */
.size-panel {
    font-size: 0.9rem;
}
.size-panel .panel-subtitle {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: #111827;
}

/* Current size card */
.size-panel .current-size-card {
    background: #f5f0ff;
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 10px;
}

.size-panel .doc-icon {
    width: 28px;
    height: 38px;
    border: 2px solid #8b3dff;
    border-radius: 5px;
    background: white;
    flex-shrink: 0;
}

.size-panel .current-size-text h3 {
    font-size: 0.9rem;
    margin: 0 0 2px 0;
}
.size-panel .current-size-text p {
    font-size: 0.9rem;
    margin: 0;
}

/* Custom size - balanced */
.size-panel .custom-size-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.size-panel .input-group {
    flex: 1.5;
    position: relative;
}
.size-panel .input-group label {
    position: absolute;
    top: -9px;
    right: 10px;
    background: white;
    padding: 0 5px;
    font-size: 0.8rem;
    color: #6b7280;
    z-index: 1;
}
.size-panel .input-group .input-num {
    width: 100%;
    font-size: 1rem;
    padding: 12px;
    text-align: center;
    border: 1.5px solid #d1d5db;
    border-radius: 10px;
}
.size-panel .apply-size-btn {
    flex: 1;
    font-size: 0.95rem !important;
    padding: 12px 16px !important;
}

/* Presets vertical - readable */
.size-panel .vertical-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.size-panel .vertical-list .size-preset {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    border: none;
    width: 100%;
}
.size-panel .sect:nth-of-type(4) .vertical-list .size-preset {
    background: #e8f0fe;
}
.size-panel .sect:nth-of-type(5) .vertical-list .size-preset {
    background: #f3e8ff;
}
.size-panel .vertical-list .brand-icon {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.size-panel .vertical-list .size-preset-label {
    font-size: 0.9rem;
    font-weight: 600;
    flex: 1;
}
.size-panel .vertical-list .size-preset-dims {
    font-size: 0.85rem;
    color: #4b5563;
}
.size-panel .vertical-list .size-preset.active {
    box-shadow: 0 0 0 2px #8b3dff;
}

/* Radio cards for background */
.size-panel .radio-group {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}
.size-panel .radio-card {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border-radius: 12px;
    border: 2px solid #e5e7eb;
    background: white;
    cursor: pointer;
    transition: all 0.15s ease;
}
.size-panel .radio-card.selected {
    border-color: #8b3dff;
    background: #f5f0ff;
}
.size-panel .radio-card input[type="radio"] {
    accent-color: #8b3dff;
    width: 18px;
    height: 18px;
    margin: 0;
}
.size-panel .radio-card .radio-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #111827;
}

/* Crop button - clean style like reference */
.size-panel .crop-subtle-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 12px;
    background: #f3f4f6;
    color: #111827;
    border: 1px solid #e5e7eb;
    font-size: 0.9rem;
    font-weight: 600;
    width: 100%;
    cursor: pointer;
}
.size-panel .crop-subtle-btn:hover {
    background: #e5e7eb;
}
.size-panel .crop-subtle-btn .crop-btn-icon {
    font-size: 1.1rem;
    color: #6b7280;
}

/* ===== Navigation Drawer ===== */
.drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 220px;
    max-width: 85vw;
    background: var(--color-surface, #fff);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    box-shadow: 0 0 20px rgba(0,0,0,0.15);
}
/* RTL: drawer on right */
[dir="rtl"] .drawer {
    right: 0;
    transform: translateX(100%);
    border-radius: 20px 0 0 20px;
}
[dir="rtl"] .drawer.open {
    transform: translateX(0);
}
/* LTR: drawer on left */
[dir="ltr"] .drawer {
    left: 0;
    transform: translateX(-100%);
    border-radius: 0 20px 20px 0;
}
[dir="ltr"] .drawer.open {
    transform: translateX(0);
}

.drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

/* Push navigation - shift app content */
#app {
    transition: transform 0.3s ease;
}
[dir="rtl"] #app.drawer-open {
    transform: translateX(-220px);
}
[dir="ltr"] #app.drawer-open {
    transform: translateX(220px);
}
@media (max-width: 330px) {
    [dir="rtl"] #app.drawer-open { transform: translateX(-85vw); }
    [dir="ltr"] #app.drawer-open { transform: translateX(85vw); }
}

/* Drawer header */
.drawer-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 16px;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
}
.drawer-logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, #8b3dff, #6c2bd9);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
}
.drawer-title {
    flex: 1;
    font-weight: 800;
    font-size: 0.95rem;
}
.drawer-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: #f3f4f6;
    cursor: pointer;
    font-size: 1rem;
    color: #6b7280;
}

/* Drawer items */
.drawer-items {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}
.drawer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px;
    border-radius: 12px;
    border: none;
    background: none;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text, #111827);
    cursor: pointer;
    text-align: start;
    width: 100%;
}
.drawer-item:hover {
    background: #f3f4f6;
}
.drawer-item .drawer-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

/* Drawer footer */
.drawer-footer {
    padding: 16px;
    border-top: 1px solid var(--color-border, #e5e7eb);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.drawer-setting {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95rem;
    font-weight: 600;
}
.drawer-setting .drawer-icon {
    font-size: 1.2rem;
}
.drawer-setting span:nth-child(2) {
    flex: 1;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    border-radius: 28px;
    background: #d1d5db;
    transition: 0.2s;
    cursor: pointer;
}
.toggle-slider:before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: white;
    top: 3px;
    left: 3px;
    transition: 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-slider {
    background: #8b3dff;
}
.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}
[dir="rtl"] .toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(-20px);
}

/* Language button */
.lang-btn {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid #e5e7eb;
    background: white;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}
.lang-btn:hover {
    border-color: #8b3dff;
}

/* Drawer dark mode fixes */
[data-theme="dark"] .drawer {
    background: #1f2937;
    color: #f9fafb;
}
[data-theme="dark"] .drawer-title {
    color: #f9fafb;
}
[data-theme="dark"] .drawer-item {
    color: #f9fafb;
}
[data-theme="dark"] .drawer-item:hover {
    background: #374151;
}
[data-theme="dark"] .drawer-header {
    border-bottom-color: #374151;
}
[data-theme="dark"] .drawer-footer {
    border-top-color: #374151;
}
[data-theme="dark"] .drawer-setting {
    color: #f9fafb;
}
[data-theme="dark"] .drawer-close {
    background: #374151;
    color: #d1d5db;
}
[data-theme="dark"] .lang-btn {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
}

/* Header: menu button at far edge */
.app-header {
    display: flex;
    align-items: center;
    gap: 8px;
}
#btnMenu {
    flex-shrink: 0;
}
.header-brand {
    flex-shrink: 0;
}
.header-actions {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
}

/* Mirror undo/redo icons in RTL */
[dir="rtl"] #btnUndo svg,
[dir="rtl"] #btnRedo svg {
    transform: scaleX(-1);
}

/* Drawer font matches app */
.drawer {
    font-family: inherit;
}
.drawer-item {
    font-size: 0.85rem !important;
}
.drawer-title {
    font-size: 0.9rem !important;
}
.drawer-setting {
    font-size: 0.85rem !important;
}

/* Dark mode footer fix - ensure footer is visible */
[data-theme="dark"] .drawer-footer {
    background: #1f2937;
    border-top: 1px solid #374151;
}
[data-theme="dark"] .drawer-setting .drawer-icon {
    color: #f9fafb;
}

/* Drawer layout fix - footer always visible */
.drawer-items {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
}
.drawer-footer {
    flex-shrink: 0 !important;
    min-height: fit-content;
}
.drawer-header {
    flex-shrink: 0 !important;
}

/* Toggle button fix - simpler, more robust */
.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
    display: inline-block;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    border-radius: 24px;
    background: #d1d5db;
    transition: background 0.2s;
    cursor: pointer;
}
.toggle-slider:before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    top: 3px;
    inset-inline-start: 3px;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle-switch input:checked + .toggle-slider {
    background: #8b3dff;
}
.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}
[dir="rtl"] .toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(-20px);
}

/* Prevent text wrap in settings */
.drawer-setting span:nth-child(2) {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Drawer stability fix - prevent jump on touch */
.drawer {
    height: 100vh;
    height: 100dvh;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}
.drawer-backdrop {
    height: 100vh;
    height: 100dvh;
}

/* Brand logo */
.brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== Image Panel - Google Mockup Style ===== */

/* Dashed add-image button (like Google mockup) */
.panel .add-image-dashed {
    width: 100%;
    padding: 20px 16px;
    border: 2px dashed var(--border-color, #d1d5db);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: transparent;
    color: var(--text-secondary, #6b7280);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.panel .add-image-dashed:hover {
    border-color: var(--accent, #3b82f6);
    color: var(--accent, #3b82f6);
    background: color-mix(in srgb, var(--accent, #3b82f6) 5%, transparent);
}

.panel .add-image-dashed svg {
    width: 28px;
    height: 28px;
}

[data-theme="dark"] .panel .add-image-dashed {
    border-color: #4b5563;
    color: #9ca3af;
}

[data-theme="dark"] .panel .add-image-dashed:hover {
    border-color: #3b82f6;
    color: #3b82f6;
}

/* Modern section headers (like Google mockup) */
.panel .img-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary, #6b7280);
    margin-bottom: 12px;
}

/* Card-style control groups */
.panel .img-card {
    background: var(--bg-secondary, #f3f4f6);
    border-radius: 12px;
    padding: 12px;
}

[data-theme="dark"] .panel .img-card {
    background: #252525;
}

/* Transform grid (4 columns like mockup) */
.panel .transform-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.panel .transform-grid .icon-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 4px;
    border-radius: 8px;
    background: var(--bg-secondary, #f3f4f6);
    font-size: 10px;
}

[data-theme="dark"] .panel .transform-grid .icon-btn {
    background: #252525;
}

.panel .transform-grid .icon-btn:hover {
    background: var(--bg-hover, #e5e7eb);
}

[data-theme="dark"] .panel .transform-grid .icon-btn:hover {
    background: #374151;
}

/* Ratio chips (like mockup) */
.panel .ratio-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.panel .ratio-chip {
    padding: 6px 16px;
    border-radius: 999px;
    background: var(--bg-secondary, #f3f4f6);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

[data-theme="dark"] .panel .ratio-chip {
    background: #252525;
    color: #d1d5db;
}

.panel .ratio-chip.active {
    background: var(--accent, #3b82f6);
    color: white;
}

/* Circular filter previews (like mockup) */
.panel .filter-strip {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none;
}

.panel .filter-strip::-webkit-scrollbar {
    display: none;
}

.panel .filter-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.panel .filter-item:hover,
.panel .filter-item.active {
    opacity: 1;
}

.panel .filter-item .filter-thumb {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
}

.panel .filter-item.active .filter-thumb {
    outline: 2px solid var(--accent, #3b82f6);
    outline-offset: 2px;
}

.panel .filter-item .filter-label {
    font-size: 12px;
}

.panel .filter-item.active .filter-label {
    color: var(--accent, #3b82f6);
    font-weight: 600;
}

/* Shape selector (3 columns like mockup) */
.panel .shape-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.panel .shape-grid button {
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border-radius: 8px;
    background: var(--bg-secondary, #f3f4f6);
    font-size: 12px;
}

[data-theme="dark"] .panel .shape-grid button {
    background: #252525;
    color: #d1d5db;
}

.panel .shape-grid button.active {
    background: var(--accent, #3b82f6);
    color: white;
}

/* ===== Image Panel - Colorful Playful Style (Wael feedback) ===== */

/* 2. Image grid (compact, no label) */
.panel .img-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.panel .img-grid-item {
    aspect-ratio: 1;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    background: var(--bg-secondary, #f3f4f6);
}

.panel .img-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.panel .img-grid-item.selected {
    border-color: var(--accent, #3b82f6);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, #3b82f6) 30%, transparent);
}

/* 3. Colorful replace button */
.panel .replace-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    background: linear-gradient(135deg, #8b5cf6, #3b82f6);
    color: white;
    font-size: 12px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.panel .replace-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

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

/* 1. Colorful transform icons */
.panel .transform-grid .icon-btn:nth-child(1) svg { color: #f59e0b; } /* rotate left - amber */
.panel .transform-grid .icon-btn:nth-child(2) svg { color: #f59e0b; } /* rotate right - amber */
.panel .transform-grid .icon-btn:nth-child(3) svg { color: #8b5cf6; } /* flip H - purple */
.panel .transform-grid .icon-btn:nth-child(4) svg { color: #8b5cf6; } /* flip V - purple */
.panel .transform-grid .icon-btn:nth-child(5) svg { color: #10b981; } /* duplicate - green */
.panel .transform-grid .icon-btn:nth-child(6) svg { color: #3b82f6; } /* forward - blue */
.panel .transform-grid .icon-btn:nth-child(7) svg { color: #3b82f6; } /* backward - blue */
.panel .transform-grid .icon-btn:nth-child(8) svg { color: #ef4444; } /* lock - red */

/* 5. Section header split (title right, reset left) */
.panel .section-header-split {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.panel .section-header-split .panel-subtitle {
    margin-bottom: 0;
}

.panel .reset-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-secondary, #f3f4f6);
    border: none;
    cursor: pointer;
    color: var(--text-secondary, #6b7280);
    transition: all 0.2s;
}

.panel .reset-btn:hover {
    background: #fef3c7;
    color: #f59e0b;
    transform: rotate(-30deg);
}

[data-theme="dark"] .panel .reset-btn {
    background: #252525;
}

/* 4,6. Slider with read-only value */
.panel .field-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.panel .slider-val {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent, #3b82f6);
    min-width: 44px;
    text-align: end;
}

.panel .range-wrap-single input[type="range"] {
    width: 100%;
}

/* 7. Colorful shape buttons */
.panel .shape-field .chip-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.panel .shape-field .chip {
    padding: 12px 8px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.panel .shape-field .chip:nth-child(1) {
    background: #dbeafe;
    color: #1d4ed8;
}

.panel .shape-field .chip:nth-child(2) {
    background: #fce7f3;
    color: #be185d;
}

.panel .shape-field .chip:nth-child(3) {
    background: #d1fae5;
    color: #047857;
}

[data-theme="dark"] .panel .shape-field .chip:nth-child(1) {
    background: #1e3a8a33;
    color: #93c5fd;
}

[data-theme="dark"] .panel .shape-field .chip:nth-child(2) {
    background: #83184333;
    color: #f9a8d4;
}

[data-theme="dark"] .panel .shape-field .chip:nth-child(3) {
    background: #065f4633;
    color: #6ee7b7;
}

.panel .shape-field .chip.active {
    border-color: currentColor;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transform: scale(1.02);
}

/* 8. Section icons with colors */
.panel .section-title-with-icon {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.panel .section-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
}

.panel .section-icon.border-icon {
    background: #dbeafe;
    color: #2563eb;
}

.panel .section-icon.shadow-icon {
    background: #e0e7ff;
    color: #4f46e5;
}

[data-theme="dark"] .panel .section-icon.border-icon {
    background: #1e3a8a55;
    color: #93c5fd;
}

[data-theme="dark"] .panel .section-icon.shadow-icon {
    background: #312e8155;
    color: #a5b4fc;
}

/* 9. Clear delete button */
.panel .delete-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    margin-top: 16px;
    border-radius: 12px;
    background: #fef2f2;
    color: #dc2626;
    font-size: 14px;
    font-weight: 600;
    border: 1px solid #fecaca;
    cursor: pointer;
    transition: all 0.2s;
}

.panel .delete-btn:hover {
    background: #fee2e2;
    border-color: #fca5a5;
}

[data-theme="dark"] .panel .delete-btn {
    background: #7f1d1d33;
    border-color: #7f1d155;
    color: #fca5a5;
}

.panel .delete-btn svg {
    width: 18px;
    height: 18px;
}

/* ===== Image Panel - Font sizes matching Size menu (Wael feedback) ===== */

/* 1. Clone Size menu font sizes */
.panel[data-panel="image"] .panel-subtitle,
.panel .img-section-title {
    font-size: 0.9rem !important; /* Same as size-panel */
    font-weight: 700;
}

.panel[data-panel="image"] .field-label,
.panel .field-label-row .field-label {
    font-size: 0.85rem !important;
    font-weight: 600;
}

.panel[data-panel="image"] {
    font-size: 0.9rem;
}

/* 2. Fix flip icons visibility (were white/invisible) */
.panel .transform-grid .icon-btn svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

/* Ensure flip icons are visible in both modes */
.panel .transform-grid .icon-btn:nth-child(3),
.panel .transform-grid .icon-btn:nth-child(4) {
    background: #f3e8ff;
}

[data-theme="dark"] .panel .transform-grid .icon-btn:nth-child(3),
[data-theme="dark"] .panel .transform-grid .icon-btn:nth-child(4) {
    background: #4c1d9533;
}

.panel .transform-grid .icon-btn:nth-child(3) svg,
.panel .transform-grid .icon-btn:nth-child(4) svg {
    color: #7c3aed !important;
    stroke-width: 2;
}

/* Add labels under icons are already there, make them visible */
.panel .transform-grid .icon-btn span {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-primary, #111827);
}

[data-theme="dark"] .panel .transform-grid .icon-btn span {
    color: #e5e7eb;
}

/* 3. Replace button margin */
.panel .replace-btn {
    margin-inline-start: 12px;
}

/* 4. Add image icon color fix + hover */
.panel .add-image-dashed svg {
    color: var(--accent, #3b82f6);
    transition: transform 0.2s ease, color 0.2s ease;
}

.panel .add-image-dashed:hover svg,
.panel .add-image-dashed:active svg {
    transform: scale(1.15);
    color: #2563eb;
}

.panel .add-image-dashed:active {
    transform: scale(0.98);
    background: color-mix(in srgb, var(--accent, #3b82f6) 10%, transparent);
}

/* Touch feedback for mobile */
@media (hover: none) {
    .panel .add-image-dashed:active svg {
        transform: scale(1.2);
    }
}
