/* =========================================================
   Палитра
   ========================================================= */
:root {
    --cw-ivory: #FBF9F6;
    --cw-ivory-soft: #F3EFE8;
    --cw-charcoal: #2b2a28;
    --cw-charcoal-soft: #46443f;
    --cw-line: #d9d2c3;
    --cw-muted: #8a8378;
    --cw-accent: #b3452f;
}

/* =========================================================
   Кнопка запуска чата
   ========================================================= */
#chat-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: var(--cw-ivory);
    border: 1px solid var(--cw-line);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cw-charcoal);
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(43,42,40,0.18);
    z-index: 9999;
    transition: transform 0.15s, box-shadow 0.15s, bottom 0.25s ease;
}

#chat-btn svg {
    width: 24px;
    height: 24px;
}

#chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(43,42,40,0.24);
}

/* Когда снизу выезжает панель "В корзину" — кнопка чата поднимается
   и встаёт над ней (высота панели приходит из JS через переменную) */
body.sticky-cart-visible #chat-btn {
    bottom: calc(20px + var(--sticky-cart-height, 64px) + 12px);
}

/* =========================================================
   Окно чата
   ========================================================= */
#chat-window {
    position: fixed;
    bottom: 86px;
    right: 20px;
    width: 340px;
    max-width: calc(100vw - 16px);
    height: 480px;
    max-height: calc(100vh - 110px);
    background: var(--cw-ivory);
    border: 1px solid var(--cw-line);
    border-radius: 4px;
    box-shadow: 0 16px 40px rgba(43,42,40,0.22);
    display: none;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
}

@media (max-width: 400px) {
    #chat-window {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }
    #chat-btn {
        bottom: 16px;
        right: 16px;
    }
}

/* =========================================================
   Шапка чата
   ========================================================= */
#chat-header {
    background: var(--cw-ivory);
    color: var(--cw-charcoal);
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--cw-line);
    flex-shrink: 0;
}

#chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

#chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--cw-ivory-soft);
    border: 1px solid var(--cw-line);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
}

#chat-avatar svg {
    width: 100%;
    height: 100%;
}

#chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

#chat-header-name {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 15px;
    letter-spacing: 0.3px;
    font-weight: 400;
    line-height: 1;
    color: var(--cw-charcoal);
}

#chat-header-status {
    font-size: 10.5px;
    font-weight: 400;
    letter-spacing: 0.3px;
    color: var(--cw-muted);
}

#chat-header button {
    background: none;
    border: none;
    color: var(--cw-charcoal);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.15s;
}

#chat-header button:hover {
    opacity: 1;
}

/* =========================================================
   Лента сообщений
   ========================================================= */
#chat-messages {
    flex: 1;
    padding: 14px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 9px;
    min-height: 0;
    background: var(--cw-ivory);
}

.msg-bot, .msg-user {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 2px;
    font-size: 14.5px;
    line-height: 1.5;
    word-break: break-word;
}

.msg-bot {
    background: var(--cw-ivory-soft);
    border: 1px solid var(--cw-line);
    color: var(--cw-charcoal);
    align-self: flex-start;
}

.msg-user {
    background: var(--cw-charcoal);
    color: var(--cw-ivory);
    align-self: flex-end;
}

.msg-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    align-self: flex-start;
    padding: 2px 0;
}

.quick-btn {
    padding: 7px 15px;
    border-radius: 20px;
    border: 1px solid var(--cw-charcoal);
    color: var(--cw-charcoal);
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    letter-spacing: 0.2px;
    transition: background 0.15s, color 0.15s;
}

.quick-btn:hover {
    background: var(--cw-charcoal);
    color: var(--cw-ivory);
}

/* =========================================================
   Поле ввода
   ========================================================= */
#chat-input-area {
    padding: 12px 14px;
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--cw-line);
    flex-shrink: 0;
    align-items: center;
    background: var(--cw-ivory);
}

#chat-input {
    flex: 1;
    padding: 9px 4px;
    border: none;
    border-bottom: 1px solid var(--cw-line);
    background: transparent;
    outline: none;
    font-size: 14.5px;
    color: var(--cw-charcoal);
    min-width: 0;
    transition: border-color 0.15s;
}

#chat-input::placeholder {
    color: var(--cw-muted);
}

#chat-input:focus {
    border-bottom-color: var(--cw-charcoal);
}

#chat-input-area button {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: var(--cw-charcoal);
    color: var(--cw-ivory);
    border: none;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

#chat-input-area button:hover {
    background: var(--cw-charcoal-soft);
}

/* =========================================================
   Индикатор "печатает"
   ========================================================= */
.msg-typing {
    background: var(--cw-ivory-soft);
    border: 1px solid var(--cw-line);
    align-self: flex-start;
    padding: 11px 16px;
    border-radius: 2px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.msg-typing span {
    width: 6px;
    height: 6px;
    background: var(--cw-muted);
    border-radius: 50%;
    animation: typing-dot 1.2s infinite;
}

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

@keyframes typing-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* =========================================================
   Модальное окно "Заказать звонок"
   ========================================================= */
#callback-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(30, 28, 25, 0.45);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#callback-modal {
    position: relative;
    background: var(--cw-ivory);
    width: 100%;
    max-width: 360px;
    padding: 40px 32px 32px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

#callback-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: none;
    border: none;
    font-size: 16px;
    color: var(--cw-muted);
    cursor: pointer;
}

#callback-title {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 22px;
    letter-spacing: 0.5px;
    color: var(--cw-charcoal);
    margin: 0 0 12px;
}

#callback-subtitle {
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--cw-muted);
    margin: 0 0 26px;
}

#callback-phone {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--cw-line);
    background: transparent;
    padding: 8px 4px;
    font-size: 15px;
    text-align: center;
    color: var(--cw-charcoal);
    outline: none;
    transition: border-color .2s;
}

#callback-phone:focus {
    border-bottom-color: var(--cw-charcoal);
}

#callback-error {
    min-height: 18px;
    font-size: 12px;
    color: var(--cw-accent);
    margin-top: 8px;
}

#callback-submit {
    margin-top: 22px;
    width: 100%;
    padding: 12px;
    background: var(--cw-charcoal);
    color: var(--cw-ivory);
    border: none;
    font-size: 13px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: background .2s;
}

#callback-submit:hover {
    background: var(--cw-charcoal-soft);
}

#callback-submit:disabled {
    opacity: 0.6;
    cursor: default;
}