/* ============================================
   ES Studio — Style (Wildberries Light Theme)
   ============================================ */

:root {
    /* Цветовая палитра WB */
    --wb-bg: #f6f6fa; /* Очень светлый серый фон страницы */
    --wb-text: #242424; /* Темно-серый для текста */
    --wb-text-muted: #808080;
    
    /* Фирменный градиент WB */
    --wb-gradient: linear-gradient(135deg, #cb11ab, #481173);
    --wb-accent: #cb11ab; /* Основной фиолетовый */
    --wb-accent-dark: #481173;
    
    /* Цвета сообщений */
    --msg-bot-bg: #f1e3f3; /* Светло-фиолетовый фон бота */
    --msg-user-bg: #ffffff; /* Белый фон пользователя */
    --msg-user-border: #cb11ab; /* Фиолетовая граница для пользователя */
    
    /* Общие переменные */
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --transition: 0.25s ease;
    --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.05);
    --shadow-header: 0 2px 8px rgba(0, 0, 0, 0.08);
}

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

body, html {
    width: 100%;
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--wb-bg);
    color: var(--wb-text);
    display: flex;
    justify-content: center;
    align-items: center;
    /* Убираем скролл на корне, скроллится только внутри чата */
    overflow: hidden; 
}

/* ============ LAYOUT ============ */

#chat-app {
    width: 100%;
    max-width: 500px;
    height: 100dvh; /* Mobile Safari fix */
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: none;
    border-radius: 0;
}

/* На больших экранах делаем вид окна приложения */
@media (min-width: 500px) {
    #chat-app {
        height: 90vh;
        border-radius: var(--radius-lg);
        overflow: hidden;
        box-shadow: var(--shadow-soft);
    }
}

/* ============ HEADER ============ */

#chat-header {
    background: var(--wb-gradient);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-header);
    z-index: 10;
    color: #ffffff;
}

.header-avatar {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.header-info h1 {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}

.header-info {
    flex: 1;
    min-width: 0;
}

#help-btn {
    flex-shrink: 0;
    min-height: 38px;
    padding: 8px 13px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

#help-btn:active {
    transform: scale(0.97);
}

/* ============ HELP PANEL ============ */

.help-overlay {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    justify-content: center;
    padding: 12px;
    background: rgba(28, 16, 36, 0.72);
    backdrop-filter: blur(4px);
}

.help-overlay[hidden] {
    display: none;
}

.help-sheet {
    width: min(680px, 100%);
    height: min(900px, 100%);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 24px 80px rgba(24, 8, 32, 0.32);
}

.help-sheet-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px;
    color: #fff;
    background: var(--wb-gradient);
}

.help-sheet-header h2 {
    margin: 2px 0 0;
    font-size: clamp(20px, 5vw, 28px);
    line-height: 1.15;
}

.help-kicker {
    color: rgba(255, 255, 255, 0.78);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

#help-close {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border: 1px solid rgba(255, 255, 255, 0.42);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
}

.help-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px;
    background: var(--wb-bg);
}

.help-step {
    margin-bottom: 18px;
    overflow: hidden;
    border: 1px solid rgba(72, 17, 115, 0.12);
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow-soft);
}

.help-step:last-child {
    margin-bottom: 0;
}

.help-step img {
    display: block;
    width: 100%;
    max-height: 520px;
    object-fit: contain;
    background: #eeeaf2;
}

.help-step-copy {
    padding: 16px;
}

.help-step-number {
    display: block;
    margin-bottom: 7px;
    color: var(--wb-accent);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.help-step-text {
    margin: 0;
    color: var(--wb-text);
    font-size: 15px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.help-state {
    padding: 36px 20px;
    color: var(--wb-text-muted);
    text-align: center;
    line-height: 1.5;
}

@media (max-width: 500px) {
    .help-overlay {
        padding: 0;
    }

    .help-sheet {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    .help-content {
        padding: 12px;
    }
}

/* На горизонтальных планшетах важнее доступная высота, чем оконные отступы. */
@media (orientation: landscape) and (min-width: 600px) and (max-height: 700px) {
    #chat-app {
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .help-overlay {
        padding: 0;
    }

    .help-sheet {
        width: min(680px, 100%);
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .help-sheet-header {
        padding: 12px 16px;
    }

    .help-sheet-header h2 {
        font-size: 20px;
    }

    .help-content {
        padding: 10px;
    }
}

#header-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
}

/* ============ MESSAGES AREA ============ */

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background-color: var(--wb-bg);
}

#messages-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Бот (слева) */
.message.bot {
    align-self: flex-start;
    background-color: var(--msg-bot-bg);
    color: var(--wb-text);
    border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 4px;
}

/* Пользователь (справа) */
.message.user {
    align-self: flex-end;
    background-color: var(--msg-user-bg);
    color: var(--wb-text);
    border: 1px solid var(--msg-user-border);
    border-radius: var(--radius-md) var(--radius-md) 4px var(--radius-md);
}

/* Время отправки */
.message .timestamp {
    display: block;
    font-size: 11px;
    color: rgba(0, 0, 0, 0.45);
    margin-top: 6px;
    text-align: right;
}

/* Картинки в сообщениях */
.message img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin-top: 8px;
    cursor: pointer;
    transition: transform var(--transition);
}

.message img:hover {
    transform: scale(1.02);
}

.chat-image-frame {
    position: relative;
    display: inline-block;
    max-width: 100%;
    margin-top: 8px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    line-height: 0;
}

.message .chat-image-frame img {
    display: block;
    margin-top: 0;
}

.preview-watermark {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 3;
    max-width: 90%;
    color: rgba(255, 255, 255, 0.78);
    font-size: clamp(17px, 5vw, 34px);
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.1;
    text-align: center;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.68);
    transform: translate(-50%, -50%) rotate(-18deg);
    white-space: nowrap;
    pointer-events: none;
    user-select: none;
}

/* Ссылки */
.message a {
    color: var(--wb-accent);
    text-decoration: underline;
    font-weight: 500;
}

/* Индикатор загрузки (typing) */
.message.typing {
    display: flex;
    gap: 5px;
    padding: 16px 20px;
}

.message.typing .dot {
    width: 8px;
    height: 8px;
    background: var(--wb-accent);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.message.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.message.typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============ BUTTONS BAR ============ */

#buttons-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px;
    min-height: 0;
    transition: all var(--transition);
    background: #ffffff;
}

#buttons-bar:not(:empty) {
    padding: 12px 16px;
    border-top: 1px solid #e0e0e0;
}

#buttons-bar .bot-btn {
    flex: 1 1 calc(50% - 8px);
    min-width: 140px;
    padding: 10px 18px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--wb-accent);
    background: #ffffff;
    border: 2px solid var(--wb-accent);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

#buttons-bar .bot-btn:hover {
    background: var(--wb-accent);
    color: #ffffff;
}

#buttons-bar .bot-btn:active {
    transform: scale(0.97);
}

/* ============ INPUT BAR ============ */

#chat-input-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #ffffff;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
}

#attach-btn, #home-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--wb-text-muted);
    cursor: pointer;
    border-radius: 50%;
    transition: all var(--transition);
    flex-shrink: 0;
    background: transparent;
    border: none;
    padding: 0;
}

#home-btn {
    font-size: 20px;
}

#attach-btn:hover, #home-btn:hover {
    color: var(--wb-accent);
    background: var(--wb-bg);
}

#attach-btn:disabled, #home-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(100%);
}

#text-input {
    flex: 1;
    min-width: 0; /* Чтобы инпут не ломал flexbox на узких экранах */
    min-height: 43px;
    display: flex;
    align-items: center;
    background: var(--wb-bg);
    border: 1px solid #d1d1d1;
    color: var(--wb-text);
    font-family: inherit;
    font-size: clamp(11px, 3.5vw, 14px);
    line-height: 1.2;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    cursor: default;
    user-select: none;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
}

/* Кастомный скроллбар */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* ============ MODAL (ZOOM) ============ */
.modal-overlay {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    overflow: hidden;
}

.modal-content {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
}

#modal-image-stage {
    width: 100%;
    height: 100%;
    min-width: 100%;
    min-height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

#modal-image {
    max-width: 90%;
    max-height: 90vh;
    object-fit: contain;
    display: block;
    flex: 0 0 auto;
    cursor: zoom-in;
    -webkit-user-drag: none;
    user-select: none;
}

#modal-image.zoomed {
    max-width: none;
    max-height: none;
    transform: none;
    cursor: zoom-out;
}

#modal-watermark {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    font-size: clamp(24px, 8vw, 72px);
    pointer-events: none;
}

#modal-watermark[hidden] {
    display: none;
}

#modal-close {
    position: fixed;
    top: 20px;
    right: 30px;
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

#modal-close:hover {
    color: #ddd;
}

/* Tooltip (for 🛒 Корзина) */
.btn-with-tooltip {
    position: relative;
}
.btn-with-tooltip::after {
    content: attr(title);
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: pre-wrap;
    width: max-content;
    max-width: 250px;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 100;
    pointer-events: none;
}
.btn-with-tooltip:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ============ EDITOR MODAL (WB STYLE 2.0) ============ */

#editor-modal {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    height: var(--app-viewport-height, 100dvh);
    z-index: 10000;
    background-color: #f1f1f5;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

.editor-workspace {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

#fabric-container {
    flex-grow: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: visible;
    position: relative;
    touch-action: none;
    overscroll-behavior: none;
}

.editor-workspace canvas,
.editor-workspace .canvas-container {
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    flex-shrink: 0; /* ПРЕДОТВРАЩАЕТ СЖАТИЕ ХОЛСТА (ИСКАЖЕНИЕ ПРОПОРЦИЙ) */
    touch-action: none;
}

.editor-photo-handles {
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
    overflow: visible;
}

.editor-photo-handles[hidden] {
    display: none;
}

.editor-photo-handle {
    position: absolute;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 3px solid #ffffff;
    border-radius: 50%;
    background: #cb11ab;
    box-shadow: 0 2px 9px rgba(0, 0, 0, 0.38);
    transform: translate(-50%, -50%);
    cursor: nwse-resize;
    pointer-events: auto;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.editor-photo-handle[data-corner="tr"],
.editor-photo-handle[data-corner="bl"] {
    cursor: nesw-resize;
}

.editor-photo-handle:active {
    background: #9b0d83;
}

#editor-close {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 32px;
    color: #888;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
    background: rgba(255,255,255,0.8);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    z-index: 10;
}

#editor-close:hover {
    color: #cb11ab;
}

#editor-close.is-disabled {
    color: #aaa;
    cursor: wait;
    opacity: 0.55;
    pointer-events: none;
}

.editor-coverage-warning {
    width: auto;
    margin: 10px 20px 0;
    padding: 9px 12px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    color: #67430b;
    background: rgba(255, 249, 232, 0.96);
    border: 1px solid rgba(218, 154, 45, 0.48);
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(74, 49, 11, 0.12);
    font-size: 12px;
    line-height: 1.35;
    box-sizing: border-box;
}

.editor-coverage-warning[hidden] {
    display: none;
}

.editor-coverage-warning-icon {
    flex: 0 0 auto;
}

.editor-coverage-warning-toggle {
    display: none;
}

@media (max-width: 800px) {
    .editor-coverage-warning {
        position: absolute;
        top: 6px;
        right: 10px;
        z-index: 4;
        width: 40px;
        min-height: 40px;
        margin: 0;
        padding: 0;
        gap: 0;
        color: #67430b;
        background: transparent;
        border: 0;
        border-radius: 10px;
        box-shadow: none;
    }

    .editor-coverage-warning-icon-desktop,
    .editor-coverage-warning-message {
        display: none;
    }

    .editor-coverage-warning-toggle {
        width: 40px;
        height: 40px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        color: #67430b;
        background: #fff9e8;
        border: 1px solid rgba(218, 154, 45, 0.58);
        border-radius: 10px;
        box-shadow: 0 2px 8px rgba(74, 49, 11, 0.12);
        font: inherit;
        font-size: 18px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .editor-coverage-warning.is-expanded {
        width: 40px;
    }

    .editor-coverage-warning.is-expanded .editor-coverage-warning-message {
        display: block;
        position: absolute;
        top: 46px;
        right: 0;
        width: min(340px, calc(100vw - 20px));
        padding: 10px 12px;
        color: #67430b;
        background: #fff9e8;
        border: 1px solid rgba(218, 154, 45, 0.48);
        border-radius: 12px;
        box-shadow: 0 4px 14px rgba(74, 49, 11, 0.14);
        font-size: 11px;
        line-height: 1.4;
        box-sizing: border-box;
    }
}

.editor-bottom-sheet {
    position: relative;
    background: #ffffff;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    max-height: 45vh;
    max-height: 45dvh;
    min-height: 0;
    flex: 0 0 auto;
    overflow: hidden;
}

@media (min-width: 801px) {
    .editor-bottom-sheet {
        border-radius: 0; /* Remove top radius on desktop */
        border-top: 1px solid #e0e0e0;
    }

    .editor-tabs-scroll {
        min-height: 64px;
        padding-right: min(570px, calc(100% - 300px));
        box-sizing: border-box;
    }

    .editor-coverage-warning {
        position: absolute;
        top: 4px;
        right: 10px;
        z-index: 4;
        width: min(560px, calc(100% - 310px));
        min-height: 56px;
        max-height: 56px;
        margin: 0;
        padding: 6px 10px;
        align-items: center;
        font-size: 11px;
        line-height: 1.25;
        overflow: hidden;
    }
}

.editor-tabs-scroll {
    width: 100%;
    flex: 0 0 auto;
    overflow-x: auto;
    border-bottom: 1px solid #e0e0e0;
}

@media (max-width: 800px) {
    .editor-tabs-scroll {
        padding-right: 58px;
        box-sizing: border-box;
    }
}

.editor-tabs-header {
    display: flex;
    min-width: max-content;
}

.tab-btn {
    padding: 15px 20px;
    font-size: 15px;
    font-weight: 500;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tab-btn.active {
    color: #cb11ab;
    font-weight: 700;
    border-bottom-color: #cb11ab;
}

.tab-btn:hover:not(.active) {
    color: #333;
    background: #f9f9f9;
}

.editor-controls-wb {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.editor-save-footer {
    display: flex;
    flex: 0 0 auto;
    justify-content: center;
    padding: 10px 20px calc(12px + env(safe-area-inset-bottom, 0px));
    background: #ffffff;
    border-top: 1px solid #eeeeee;
}

.tab-content {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: center;
}

.tab-content.active {
    display: flex;
}

.size-category {
    font-size: 14px;
    font-weight: 500;
    color: #444;
    margin-top: 10px;
    margin-bottom: 8px;
    align-self: flex-start;
    width: 100%;
}

.editor-size-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
    justify-content: flex-start;
    margin-bottom: 10px;
}

.size-btn, .filter-btn, .tool-btn {
    background: #f5f5f5;
    color: #242424;
    border: none;
    padding: 12px 18px;
    min-height: 44px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s ease;
}

.size-btn:hover, .filter-btn:hover, .tool-btn:hover {
    background: #e0e0e0;
}

.size-btn.active, .filter-btn.active {
    background: #cb11ab;
    color: #fff;
}

.size-btn {
    flex: 1 1 76px;
    max-width: 110px;
    box-sizing: border-box;
    white-space: nowrap;
}

.styled-select, .styled-color {
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #ddd;
    font-family: inherit;
    background: #f9f9f9;
}

.save-btn-wb {
    background: #cb11ab;
    color: #fff;
    border: none;
    padding: 16px 24px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    max-width: 400px;
    margin-top: 0;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 8px 20px rgba(203, 17, 171, 0.3);
}

.save-btn-wb:hover {
    background: #b00d92;
}
.save-btn-wb:active {
    transform: scale(0.98);
}

.save-btn-wb:disabled,
.save-btn-wb:disabled:hover,
.save-btn-wb:disabled:active {
    background: #b8b8b8;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.72;
    transform: none;
}

@media (max-width: 800px) {
    .editor-bottom-sheet {
        max-height: 58vh;
        max-height: 58dvh;
    }

    #editor-close {
        top: calc(12px + env(safe-area-inset-top, 0px));
        right: calc(12px + env(safe-area-inset-right, 0px));
    }

    .editor-controls-wb {
        padding: 14px 12px;
    }

    .editor-save-footer {
        padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-height: 500px) {
    .editor-bottom-sheet {
        max-height: 72vh;
        max-height: 72dvh;
    }

    .editor-controls-wb {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .editor-save-footer {
        padding-top: 6px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    }

    .save-btn-wb {
        padding-top: 11px;
        padding-bottom: 11px;
        font-size: 16px;
    }

    .editor-photo-handle {
        width: 28px;
        height: 28px;
    }
}


/* Editor Loading Spinner Overlay */
.editor-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    gap: 15px;
}
.editor-loading-overlay .spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top-color: #cb11ab;
    border-radius: 50%;
    animation: editor-spin 1s ease-in-out infinite;
}
@keyframes editor-spin {
    to { transform: rotate(360deg); }
}

/* ============ PHOTOSHOP-STYLE OBJECT REMOVAL MODAL ============ */
#inpaint-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    height: var(--app-viewport-height, 100dvh);
    z-index: 20000;
    background-color: #1e1e1e;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    font-family: 'Inter', sans-serif;
    user-select: none;
    overscroll-behavior: none;
    touch-action: none;
}

.inpaint-header {
    height: 60px;
    background-color: #2d2d2d;
    border-bottom: 1px solid #3d3d3d;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    flex-shrink: 0;
    gap: 15px;
    overflow-x: auto;
    overscroll-behavior: contain;
}

.inpaint-title {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
}

.inpaint-tools, .inpaint-actions, .inpaint-brush-settings, .inpaint-zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.inpaint-tool-btn, .inpaint-action-btn, .inpaint-zoom-btn, .inpaint-cancel-btn, .inpaint-apply-btn {
    background: #3a3a3a;
    color: #ffffff;
    border: 1px solid #4a4a4a;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.inpaint-tool-btn:hover, .inpaint-action-btn:hover, .inpaint-zoom-btn:hover, .inpaint-cancel-btn:hover {
    background: #4a4a4a;
    border-color: #5a5a5a;
}

.inpaint-tool-btn.active {
    background: #0078d4;
    border-color: #0086f4;
    color: #ffffff;
    box-shadow: 0 0 8px rgba(0, 120, 212, 0.4);
}

.inpaint-apply-btn {
    background: #cb11ab;
    border-color: #cb11ab;
    font-weight: 700;
}
.inpaint-apply-btn:hover {
    background: #e013bc;
}

.inpaint-zoom-btn {
    padding: 4px 10px;
    font-size: 16px;
    font-weight: bold;
}
#inpaint-zoom-label {
    font-size: 12px;
    width: 45px;
    text-align: center;
    color: #aaaaaa;
}

.inpaint-workspace {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: #141414;
    background-image: linear-gradient(45deg, #181818 25%, transparent 25%), linear-gradient(-45deg, #181818 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #181818 75%), linear-gradient(-45deg, transparent 75%, #181818 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#inpaint-canvas {
    cursor: grab;
    max-width: 100%;
    max-height: 100%;
    touch-action: none;
}
#inpaint-canvas.drawing-mode {
    cursor: crosshair;
}
#inpaint-canvas.panning-mode {
    cursor: grabbing;
}

.inpaint-footer-hint {
    height: 36px;
    background: #252525;
    border-top: 1px solid #333;
    display: flex;
    align-items: center;
    padding: 0 15px;
    font-size: 12px;
    color: #a8a8a8;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 700px) {
    .inpaint-header {
        height: auto;
        max-height: 42dvh;
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch;
        justify-content: stretch;
        gap: 8px;
        padding: calc(8px + env(safe-area-inset-top, 0px)) 8px 8px;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .inpaint-title {
        min-width: 0;
        font-size: 14px;
        line-height: 1.25;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .inpaint-tools,
    .inpaint-actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }

    .inpaint-brush-settings {
        width: 100%;
        min-width: 0;
        gap: 8px;
        padding: 8px;
        border-radius: 8px;
        background: #252525;
        box-sizing: border-box;
    }

    .inpaint-brush-settings input[type="range"] {
        flex: 1;
        min-width: 0;
    }

    .inpaint-tool-btn,
    .inpaint-action-btn,
    .inpaint-cancel-btn,
    .inpaint-apply-btn {
        min-width: 0;
        min-height: 42px;
        justify-content: center;
        padding: 8px 10px;
        font-size: 12px;
        line-height: 1.2;
        text-align: center;
        white-space: normal;
    }

    .inpaint-zoom-controls {
        grid-column: 1 / -1;
        justify-content: center;
        width: 100%;
        min-width: 0;
        padding: 2px 0;
    }

    .inpaint-zoom-btn {
        min-width: 44px;
        min-height: 36px;
        justify-content: center;
    }

    #inpaint-zoom-label {
        width: auto;
        min-width: 52px;
    }

    .inpaint-workspace {
        min-height: 0;
    }

    .inpaint-footer-hint {
        height: auto;
        min-height: 38px;
        align-items: flex-start;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
        line-height: 1.25;
        white-space: normal;
    }

    #inpaint-loading-text {
        max-width: calc(100vw - 32px);
        padding: 0 16px;
        box-sizing: border-box;
        text-align: center;
        line-height: 1.3;
    }

    #inpaint-abort-btn {
        max-width: calc(100vw - 32px);
        justify-content: center;
        text-align: center;
    }
}

@media (max-width: 380px) {
    #chat-input-bar {
        gap: 8px;
        padding: 10px;
    }

    #attach-btn,
    #home-btn {
        width: 36px;
        height: 36px;
    }

    #text-input {
        min-height: 39px;
        padding: 10px 8px;
    }

    .inpaint-tool-btn,
    .inpaint-action-btn,
    .inpaint-cancel-btn,
    .inpaint-apply-btn {
        padding: 7px 8px;
        font-size: 11px;
    }
}
