/* ============================================
   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-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);
}

/* Ссылки */
.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 на узких экранах */
    background: var(--wb-bg);
    border: 1px solid #d1d1d1;
    color: var(--wb-text);
    font-family: inherit;
    font-size: 14px;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    outline: none;
    transition: border-color var(--transition);
}

#text-input::placeholder {
    color: var(--wb-text-muted);
}

#text-input:focus {
    border-color: var(--wb-accent);
}

#text-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#send-btn {
    width: 44px;
    height: 44px;
    background: var(--wb-gradient);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(203, 17, 171, 0.3);
}

#send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 10px rgba(203, 17, 171, 0.4);
}

#send-btn:active {
    transform: scale(0.95);
}

#send-btn:disabled {
    background: #cccccc;
    color: #ffffff;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* Кастомный скроллбар */
::-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 {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    position: relative;
}

#modal-image {
    max-width: 90%;
    max-height: 90vh;
    object-fit: contain;
    transition: transform 0.2s ease;
    cursor: zoom-in;
}

#modal-image.zoomed {
    transform: scale(2.2);
    cursor: zoom-out;
}

#modal-close {
    position: absolute;
    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;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10000;
    background-color: #f1f1f5;
    display: flex;
    flex-direction: column;
}

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

#fabric-container {
    flex-grow: 1;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

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

#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);
}

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

.editor-bottom-sheet {
    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;
}

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

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

.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;
}

.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: 20px;
    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);
}


/* 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;
    z-index: 20000;
    background-color: #1e1e1e;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    font-family: 'Inter', sans-serif;
    user-select: 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) {
    .inpaint-tool-btn,
    .inpaint-action-btn,
    .inpaint-cancel-btn,
    .inpaint-apply-btn {
        padding: 7px 8px;
        font-size: 11px;
    }
}
