#chat-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-family: "Manrope", sans-serif;
}

/* Кнопка открытия */
#chat-open-wrap {
    display: block;
}

#chat-open-btn {
    width: 62px;
    height: 62px;
    border: 1px solid rgba(205, 160, 98, 0.28);
    border-radius: 999px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;

    /* премиальный бронзово-золотой стеклянный градиент */
    background:
        linear-gradient(145deg,
            rgba(255, 248, 236, 0.42) 0%,
            rgba(217, 181, 122, 0.28) 20%,
            rgba(180, 132, 72, 0.92) 55%,
            rgba(101, 65, 28, 0.96) 100%);

    box-shadow:
        0 18px 40px rgba(0, 0, 0, 0.36),
        inset 0 1px 0 rgba(255, 255, 255, 0.34),
        inset 0 -10px 18px rgba(0, 0, 0, 0.18),
        0 0 0 1px rgba(255, 255, 255, 0.04);

    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    transition: transform .25s ease, box-shadow .25s ease, filter .25s ease;
}

/* блик сверху */
#chat-open-btn::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 30% 25%,
            rgba(255, 255, 255, 0.45) 0%,
            rgba(255, 255, 255, 0.18) 18%,
            rgba(255, 255, 255, 0) 45%);
    pointer-events: none;
}

/* мягкое 3D свечение по краю */
#chat-open-btn::after {
    content: "";
    position: absolute;
    inset: 2px;
    border-radius: inherit;
    border: 1px solid rgba(255, 236, 204, 0.16);
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.12),
        inset 0 -8px 14px rgba(0, 0, 0, 0.12);
    pointer-events: none;
}

#chat-open-btn:hover {
    transform: translateY(-2px) scale(1.03);
    filter: brightness(1.04);
    box-shadow:
        0 22px 46px rgba(0, 0, 0, 0.42),
        inset 0 1px 0 rgba(255, 255, 255, 0.36),
        inset 0 -10px 18px rgba(0, 0, 0, 0.16),
        0 0 24px rgba(217, 181, 122, 0.15);
}

#chat-open-btn:active {
    transform: translateY(0) scale(0.98);
}

/* иконка внутри кнопки — теперь не мультяшная, а премиальная */
#chat-open-btn span {
    position: relative;
    z-index: 1;
    display: block;
    width: 22px;
    height: 22px;
    color: #fff6ea;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
    opacity: .98;
}

#chat-open-btn svg {
    width: 30px;
    height: 30px;
    display: block;
    fill: none;
    stroke: #fff6ea;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

/* окно чата */
#chat-box {
    width: 360px;
    height: 540px; /* фиксированная высота для десктопа */
    max-height: calc(100vh - 48px);
    max-width: calc(100vw - 24px);
    margin-bottom: 12px;
    border-radius: 24px;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(255,255,255,.38), rgba(255,255,255,.22));
    border: 1px solid rgba(255,255,255,.08);
    box-shadow: 0 20px 60px rgba(0,0,0,.45);
    backdrop-filter: blur(90px);
    -webkit-backdrop-filter: blur(18px);
    display: flex;
    flex-direction: column;
}


.chat-box-hidden {
    display: none !important;
}

.chat-box-open {
    display: flex;
}

.chat-box-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    padding: 16px 18px;
    background: rgba(10, 10, 10, .72);
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    flex: 0 0 auto;
}

.chat-box-title {
    font-family: "Cormorant Garamond", serif;
    font-size: 28px;
    line-height: 1;
    color: #f5f0e8;
}

.chat-box-subtitle {
    margin-top: 4px;
    font-size: 13px;
    color: #a8a29a;
}

#chat-close-btn {
    background: transparent;
    border: 0;
    color: #f5f0e8;
    font-size: 34px;
    line-height: 1;
    cursor: pointer;
    opacity: .85;
    padding: 0;
}

#chat-close-btn:hover {
    opacity: 1;
}

.chat-box-body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1 1 auto;
    min-height: 0;
    box-sizing: border-box;
    background: rgba(12, 12, 12, .60);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}


/* стартовая форма */
#chat-start-form {
    display: grid;
    gap: 10px;
    flex: 1 1 auto;
    align-content: start;
}

.chat-field {
    display: grid;
    gap: 6px;
}

.chat-field-hint {
    display: none;
    font-size: 12px;
    line-height: 1.35;
    color: #ffcccc;
    padding-left: 2px;
}

.chat-field-hint.valid {
    color: #d9b57a;
}

.chat-field-hint.invalid {
    color: #ffcccc;
}

#chat-start-form input,
#chat-start-form textarea,
#chat-reply-form textarea {
    width: 100%;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(0,0,0,.2);
    color: #fff;
    padding: 12px 14px;
    outline: none;
    font-family: "Manrope", sans-serif;
    font-size: 15px;
    transition: .2s ease;
    box-sizing: border-box;
}

#chat-start-form input::placeholder,
#chat-start-form textarea::placeholder,
#chat-reply-form textarea::placeholder {
    color: rgba(255,255,255,.45);
}

#chat-start-form input:focus,
#chat-start-form textarea:focus,
#chat-reply-form textarea:focus {
    border-color: #d9b57a;
    box-shadow: 0 0 0 3px rgba(217,181,122,.12);
}

#chat-start-form input.is-invalid,
#chat-start-form textarea.is-invalid,
#chat-reply-form textarea.is-invalid {
    border-color: rgba(255, 99, 99, .55);
    box-shadow: 0 0 0 3px rgba(255, 99, 99, .10);
}

#chat-start-form input.is-valid,
#chat-start-form textarea.is-valid {
    border-color: rgba(217,181,122,.40);
}

#chat-start-form textarea {
    min-height: 190px;
    resize: vertical;
}

#chat-start-form button {
    width: 100%;
    border: 0;
    border-radius: 14px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #e6c28c, #bf8f4f);
    color: #16120d;
    font-weight: 700;
    cursor: pointer;
    transition: .25s ease;
}

#chat-start-form button:hover {
    transform: translateY(-2px);
    filter: brightness(1.03);
}

/* чат */
.chat-thread {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    width: 100%;
    flex: 1 1 auto;
    overflow: hidden;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0;
    min-height: 0;
    flex: 1 1 auto;
    width: 100%;

    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chat-messages::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.chat-bubble {
    border-radius: 16px;
    padding: 10px 12px;
    line-height: 1.35;
    font-size: 14px;
    width: 88%;
    max-width: 88%;
    box-sizing: border-box;
    word-wrap: break-word;
    white-space: pre-wrap;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-bubble-name {
    font-size: 12px;
    margin: 0;
    line-height: 1.2;
    font-weight: 600;
    opacity: .95;
}

.chat-bubble-visitor .chat-bubble-name {
    color: #e0c18a; /* тёплый цвет для пользователя */
}

.chat-bubble-admin .chat-bubble-name {
    color: #9fb7ff; /* холодный цвет для админа */
}

.chat-bubble-text {
    color: #fff;
    margin: 0;
    line-height: 1.35;
}

.chat-bubble-visitor {
    align-self: flex-end;
    background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.02));
    border: 1px solid var(--line);
}

.chat-bubble-admin {
    align-self: flex-start;
    background: linear-gradient(180deg, rgba(180, 200, 255, .16), rgba(130, 150, 190, .06));
    border: 1px solid rgba(180, 200, 255, .22);
}

.chat-system-message {
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 13px;
    color: #f1dfc1;
    background: rgba(217,181,122,.08);
    border: 1px solid rgba(217,181,122,.20);
}

.chat-bubble-time {
    margin: 0;
    font-size: 9px;
    line-height: 1.1;
    opacity: .6;
    align-self: flex-end;
    margin-left: auto;
    text-align: right;
}

/* === НОВЫЙ РЕЙЛАЙТ ДЛЯ ОТВЕТА: textarea + кнопка справа === */
.chat-reply-form {
    display: block;
    width: 100%;
    flex: 0 0 auto;
}

.chat-reply-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    width: 100%;
    min-width: 0;
}

.chat-reply-input-wrap textarea {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 40px;
    max-height: 240px;
    resize: none;
    overflow-y: hidden;
    line-height: 1.35;
    font-size: 15px;
    padding: 11px 12px;
    border-radius: 16px;
    box-sizing: border-box;

    background: rgba(0,0,0,.2);
    color: #fff;
    border: 1px solid rgba(255,255,255,.12);
    outline: none;
    font-family: "Manrope", sans-serif;

    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chat-reply-input-wrap textarea::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.chat-reply-input-wrap textarea::placeholder {
    color: rgba(255,255,255,.45);
}

.chat-reply-input-wrap textarea:focus {
    border-color: #d9b57a;
    box-shadow: 0 0 0 3px rgba(217,181,122,.12);
}

.chat-reply-input-wrap button {
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    min-width: 46px;
    border: 0;
    border-radius: 16px;
    padding: 0;
    background: linear-gradient(135deg, #e6c28c, #bf8f4f);
    color: #16120d;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: .25s ease;
    box-shadow: 0 8px 18px rgba(0,0,0,.22);
}

.chat-reply-input-wrap button:hover {
    transform: translateY(-1px);
    filter: brightness(1.03);
}

.chat-reply-input-wrap button:active {
    transform: translateY(0) scale(0.98);
}

.chat-reply-input-wrap button svg {
    width: 20px;
    height: 20px;
    display: block;
    fill: currentColor;
}

.chat-message {
    margin-top: 12px;
    border-radius: 14px;
    padding: 12px 14px;
    line-height: 1.6;
    font-size: 14px;
}

.chat-success {
    display: block;
    border: 1px solid rgba(217,181,122,.35);
    color: #f1dfc1;
    background: rgba(217,181,122,.08);
}

.chat-error {
    display: block;
    border: 1px solid rgba(255,99,99,.35);
    color: #ffcccc;
    background: rgba(255,99,99,.08);
}

.hidden-message {
    display: none !important;
}

@media (max-width: 480px) {
    #chat-widget {
        right: 12px;
        bottom: 12px;
    }

    #chat-box {
        width: min(360px, calc(100vw - 24px));
        height: 72vh; /* фиксированная высота на мобильных */
        max-height: calc(100vh - 24px);
    }

    .chat-box-body {
        padding: 12px;
    }

    .chat-messages {
        min-height: 0;
    }

    .chat-bubble {
        width: 80%;
        max-width: 80%;
    }

    #chat-open-btn {
        width: 58px;
        height: 58px;
    }

    #chat-open-btn span,
    #chat-open-btn svg {
        width: 28px;
        height: 28px;
    }

    .chat-reply-input-wrap textarea {
        min-height: 40px;
        font-size: 14px;
    }

    .chat-reply-input-wrap button {
        width: 44px;
        height: 44px;
        min-width: 44px;
        border-radius: 14px;
    }

    .chat-box-title {
        font-size: 24px;
    }
    
    #chat-start-form textarea {
        min-height: 170px;
    }
}
