/* ===========================================================================
   САЙТТАҒЫ ЧАТ
   ---------------------------------------------------------------------------
   Өз файлы — site.css-ке тиіспейміз.
=========================================================================== */

.chat {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 950;

    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

/* ---------- қалқымалы түйме ---------- */

.chat-fab {
    position: relative;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 58px;
    height: 58px;

    border: 0;
    border-radius: 50%;
    background: #FF5A00;

    color: #fff;
    cursor: pointer;

    box-shadow:
        0 10px 28px rgba(255, 90, 0, .38),
        0 2px 6px rgba(0, 0, 0, .3);

    transition:
        transform .28s cubic-bezier(.34, 1.4, .5, 1),
        box-shadow .28s ease;
}

.chat-fab:hover { transform: translateY(-2px) scale(1.04); }
.chat-fab:active { transform: scale(.94); }

.chat-fab-icon {
    display: flex;
    width: 26px;
    height: 26px;

    transition: transform .3s cubic-bezier(.34, 1.4, .5, 1), opacity .2s ease;
}

.chat-fab-icon svg { width: 100%; height: 100%; }

/* Ашылғанда белгіше × болып ауысады */
.chat-fab-close {
    position: absolute;

    width: 18px;
    height: 18px;

    opacity: 0;
    transform: rotate(-90deg) scale(.6);

    transition: transform .3s cubic-bezier(.34, 1.4, .5, 1), opacity .2s ease;
}

.chat-fab-close::before,
.chat-fab-close::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;

    width: 100%;
    height: 2px;
    margin-top: -1px;

    border-radius: 2px;
    background: currentColor;
}

.chat-fab-close::before { transform: rotate(45deg); }
.chat-fab-close::after  { transform: rotate(-45deg); }

.chat.is-open .chat-fab-icon {
    opacity: 0;
    transform: rotate(90deg) scale(.6);
}

.chat.is-open .chat-fab-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* ---------- оқылмаған белгісі ---------- */

.chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;

    min-width: 20px;
    height: 20px;
    padding: 0 5px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 2px solid #0b0f14;
    border-radius: 999px;
    background: #3ddc84;

    color: #06240f;
    font-size: 11px;
    font-style: normal;
    font-weight: 900;

    animation: chat-pop .4s cubic-bezier(.34, 1.5, .5, 1);
}

/* display: flex жоғарыда тұр — сондықтан жасыруды нақты жазамыз */
.chat-badge[hidden] { display: none; }

@keyframes chat-pop {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}

/* ---------- терезе ---------- */

.chat-window {
    display: flex;
    flex-direction: column;

    width: 360px;
    max-width: calc(100vw - 32px);
    height: 480px;
    max-height: calc(100vh - 130px);

    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 20px;
    background: #0d1218;

    box-shadow: 0 28px 70px rgba(0, 0, 0, .55);
    overflow: hidden;

    opacity: 0;
    transform: translateY(16px) scale(.96);
    transform-origin: bottom right;

    transition:
        opacity .24s ease,
        transform .3s cubic-bezier(.34, 1.3, .5, 1);
}

.chat.is-open .chat-window {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ---------- бас жағы ---------- */

.chat-head {
    display: flex;
    align-items: center;
    gap: 11px;

    padding: 14px 16px;

    border-bottom: 1px solid rgba(255, 255, 255, .08);
    background: linear-gradient(180deg, rgba(255, 90, 0, .12), transparent);

    flex: 0 0 auto;
}

.chat-avatar {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 36px;
    height: 36px;
    flex: 0 0 36px;

    border-radius: 50%;
    background: rgba(255, 255, 255, .06);
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.chat-head-text {
    display: flex;
    flex-direction: column;
    gap: 2px;

    flex: 1 1 auto;
    min-width: 0;
}

.chat-head-text strong {
    color: #fff;
    font-size: 14px;
    font-weight: 900;
}

.chat-head-text small {
    color: rgba(255, 255, 255, .5);
    font-size: 11px;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-hide {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;

    border: 0;
    border-radius: 9px;
    background: rgba(255, 255, 255, .05);

    color: rgba(255, 255, 255, .6);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;

    transition: background .2s ease, color .2s ease;
}

.chat-hide:hover { background: rgba(255, 255, 255, .1); color: #fff; }

/* ---------- хабарлар ---------- */

.chat-body {
    flex: 1 1 auto;

    display: flex;
    flex-direction: column;
    gap: 8px;

    padding: 16px;

    overflow-y: auto;
    overscroll-behavior: contain;

    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .15) transparent;
}

.chat-body::-webkit-scrollbar { width: 6px; }

.chat-body::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(255, 255, 255, .15);
}

.chat-msg {
    max-width: 82%;
    padding: 10px 13px;

    border-radius: 15px;

    font-size: 13.5px;
    line-height: 1.5;

    animation: chat-in .32s cubic-bezier(.22, .61, .36, 1);
}

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

.chat-msg p {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-msg.is-admin {
    align-self: flex-start;

    border-bottom-left-radius: 5px;
    background: rgba(255, 255, 255, .07);

    color: rgba(255, 255, 255, .92);
}

.chat-msg.is-client {
    align-self: flex-end;

    border-bottom-right-radius: 5px;
    background: #FF5A00;

    color: #fff;
}

.chat-hello {
    max-width: 100%;
    background: rgba(255, 90, 0, .1);
    border: 1px solid rgba(255, 90, 0, .22);
    color: rgba(255, 255, 255, .8);
}

.chat-time {
    display: block;
    margin-top: 4px;

    font-size: 10px;
    opacity: .6;
    text-align: right;
}

.chat-msg.is-admin .chat-time { text-align: left; }

/* ---------- ескерту ---------- */

.chat-note {
    margin: 0;
    padding: 9px 16px;

    background: rgba(255, 92, 92, .12);

    color: #ff9a9a;
    font-size: 12px;

    flex: 0 0 auto;
}

/* ---------- форма ---------- */

.chat-form {
    padding: 12px;

    border-top: 1px solid rgba(255, 255, 255, .08);
    background: rgba(255, 255, 255, .02);

    flex: 0 0 auto;
}

/* Боттарға арналған жасырын өріс */
.chat-hp {
    position: absolute !important;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.chat-name {
    width: 100%;
    min-height: 36px;
    padding: 8px 12px;
    margin-bottom: 8px;

    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 10px;
    background: rgba(255, 255, 255, .04);

    color: #fff;
    font: inherit;
    font-size: 12.5px;
}

.chat-name::placeholder { color: rgba(255, 255, 255, .35); }

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chat-input {
    flex: 1 1 auto;

    min-height: 42px;
    max-height: 120px;
    padding: 11px 13px;

    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 12px;
    background: rgba(255, 255, 255, .04);

    color: #fff;
    font: inherit;
    font-size: 13.5px;
    line-height: 1.4;

    resize: none;
    overflow-y: auto;

    transition: border-color .2s ease, background .2s ease;
}

.chat-input::placeholder { color: rgba(255, 255, 255, .35); }

.chat-name:focus,
.chat-input:focus {
    border-color: rgba(255, 90, 0, .5);
    background: rgba(255, 255, 255, .06);
    outline: none;
}

.chat-send {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 42px;
    height: 42px;
    flex: 0 0 42px;

    border: 0;
    border-radius: 12px;
    background: #FF5A00;

    color: #fff;
    cursor: pointer;

    transition: transform .2s cubic-bezier(.34, 1.4, .5, 1), filter .2s ease;
}

.chat-send svg { width: 19px; height: 19px; }

.chat-send:hover { filter: brightness(1.1); }
.chat-send:active { transform: scale(.9); }

.chat-send:disabled {
    opacity: .5;
    cursor: default;
    transform: none;
}

.chat.is-sending .chat-send svg {
    animation: chat-fly .7s ease infinite;
}

@keyframes chat-fly {
    0%, 100% { transform: translate(0, 0); }
    50%      { transform: translate(3px, -3px); }
}

/* ---------- телефон ---------- */

@media (max-width: 560px) {

    .chat {
        right: 14px;
        bottom: 14px;
        left: 14px;

        align-items: flex-end;
    }

    .chat-window {
        width: 100%;
        height: calc(100vh - 150px);
        max-height: 540px;
    }

    .chat-fab {
        width: 54px;
        height: 54px;
    }

    .chat-msg { max-width: 88%; font-size: 14px; }
}

/* Терезе жабық тұрғанда мүлдем болмауы керек.
   [hidden] атрибуты жалғыз жеткіліксіз: .chat-window-дегі display: flex
   оны басып кетеді — сондықтан нақты жазамыз. */
.chat-window[hidden] { display: none; }

.chat[data-state="closed"] .chat-window { pointer-events: none; }

@media (prefers-reduced-motion: reduce) {

    .chat-window,
    .chat-fab,
    .chat-fab-icon,
    .chat-fab-close { transition: none; }

    .chat-msg,
    .chat-badge { animation: none; }

    .chat.is-sending .chat-send svg { animation: none; }
}

/* ---------- дайын жауаптар (бот түймелері) ---------- */

.chat-options {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;

    padding: 0 16px 12px;

    flex: 0 0 auto;
}

.chat-options[hidden] { display: none; }

.chat-option {
    padding: 8px 14px;

    border: 1px solid rgba(255, 90, 0, .4);
    border-radius: 999px;
    background: rgba(255, 90, 0, .08);

    color: #ff8a3d;
    font: inherit;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;

    animation: chat-option-in .3s cubic-bezier(.34, 1.3, .5, 1) backwards;

    transition:
        background .2s ease,
        color .2s ease,
        transform .2s cubic-bezier(.34, 1.4, .5, 1);
}

.chat-option:nth-child(2) { animation-delay: .05s; }
.chat-option:nth-child(3) { animation-delay: .1s; }
.chat-option:nth-child(4) { animation-delay: .15s; }

@keyframes chat-option-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-option:hover {
    background: rgba(255, 90, 0, .16);
    color: #fff;
}

.chat-option:active { transform: scale(.94); }

/* ---------- боттың хабары ---------- */

.chat-msg.is-bot {
    align-self: flex-start;

    border-bottom-left-radius: 5px;
    background: rgba(255, 255, 255, .07);

    color: rgba(255, 255, 255, .92);
}

.chat-msg.is-bot .chat-time { text-align: left; }

@media (prefers-reduced-motion: reduce) {
    .chat-option { animation: none; }
}

/* ===========================================================================
   ЧАТ: АНИМАЦИЯЛАР
=========================================================================== */

/* ---------- бот жазып жатыр ---------- */

.chat-typing {
    display: flex !important;
    align-items: center;
    gap: 5px;

    width: auto;
    max-width: 64px;
    padding: 14px 15px;
}

.chat-typing span {
    width: 7px;
    height: 7px;

    border-radius: 50%;
    background: rgba(255, 255, 255, .55);

    animation: chat-dot 1.25s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: .16s; }
.chat-typing span:nth-child(3) { animation-delay: .32s; }

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

/* ---------- көпіршік өз жағынан шығады ---------- */

.chat-msg.is-client {
    transform-origin: bottom right;
    animation: chat-pop-right .34s cubic-bezier(.34, 1.3, .5, 1);
}

.chat-msg.is-admin,
.chat-msg.is-bot {
    transform-origin: bottom left;
    animation: chat-pop-left .34s cubic-bezier(.34, 1.3, .5, 1);
}

@keyframes chat-pop-right {
    from { opacity: 0; transform: translate(12px, 6px) scale(.92); }
    to   { opacity: 1; transform: translate(0, 0) scale(1); }
}

@keyframes chat-pop-left {
    from { opacity: 0; transform: translate(-12px, 6px) scale(.92); }
    to   { opacity: 1; transform: translate(0, 0) scale(1); }
}

/* ---------- "онлайн" нүктесі ---------- */

.chat-live {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 5px;

    border-radius: 50%;
    background: #3ddc84;

    animation: chat-live 2.4s ease-in-out infinite;
}

@keyframes chat-live {
    0%, 100% { opacity: 1;  box-shadow: 0 0 0 0 rgba(61, 220, 132, .5); }
    50%      { opacity: .7; box-shadow: 0 0 0 4px rgba(61, 220, 132, 0); }
}

/* ---------- әлі ашпағандарға жұмсақ шақыру ---------- */

.chat-fab::after {
    content: "";
    position: absolute;
    inset: -3px;

    border: 2px solid rgba(255, 90, 0, .55);
    border-radius: 50%;

    opacity: 0;
    pointer-events: none;
}

.chat[data-fresh="1"] .chat-fab::after {
    animation: chat-ring 2.8s cubic-bezier(.22, .61, .36, 1) infinite;
}

@keyframes chat-ring {
    0%       { transform: scale(.92); opacity: .75; }
    55%      { transform: scale(1.45); opacity: 0; }
    100%     { transform: scale(1.45); opacity: 0; }
}

/* ---------- терезе ашылғанда ішіндегісі де қозғалады ---------- */

.chat.is-open .chat-head {
    animation: chat-slide-down .4s cubic-bezier(.22, .61, .36, 1);
}

.chat.is-open .chat-form {
    animation: chat-slide-up .4s cubic-bezier(.22, .61, .36, 1);
}

@keyframes chat-slide-down {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes chat-slide-up {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- жіберу түймесі ---------- */

.chat.is-sending .chat-send svg {
    animation: chat-send-fly .55s cubic-bezier(.4, 0, .2, 1);
}

@keyframes chat-send-fly {
    0%   { transform: translate(0, 0) scale(1);      opacity: 1; }
    45%  { transform: translate(22px, -22px) scale(.6); opacity: 0; }
    55%  { transform: translate(-16px, 16px) scale(.6); opacity: 0; }
    100% { transform: translate(0, 0) scale(1);      opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {

    .chat-typing span,
    .chat-live,
    .chat-fab::after,
    .chat.is-open .chat-head,
    .chat.is-open .chat-form,
    .chat.is-sending .chat-send svg { animation: none; }

    .chat-msg.is-client,
    .chat-msg.is-admin,
    .chat-msg.is-bot { animation: none; }

    .chat-typing span { opacity: .6; }
}

/* ---------------------------------------------------------------------------
   Телефонда чатқа жазғанда бет жақындап кетпесін.
   iOS Safari 16px-тен кіші өріске басқанда бетті үлкейтеді.
--------------------------------------------------------------------------- */

@media (max-width: 860px) {

    .chat-input,
    .chat-name {
        font-size: 16px !important;
    }

    .chat-input { min-height: 46px; }
}

/* ---------------------------------------------------------------------------
   Жазу өрісіндегі жылжыту жолағын жасырамыз.

   Windows-та ол жоғары-төмен көрсеткіші бар ақ жолақ болып шығады да,
   өрістің ішінде бөтен зат сияқты тұрады. Өріс жазған сайын өзі
   созылатындықтан (chat.js), оның қажеті жоқ. Ең ұзын күйіне
   жеткенде тінтуірмен де, саусақпен де айналдыра беруге болады —
   тек жолақ көрінбейді.
--------------------------------------------------------------------------- */

.chat-input {
    scrollbar-width: none;          /* Firefox */
    -ms-overflow-style: none;       /* ескі Edge */
}

.chat-input::-webkit-scrollbar { width: 0; height: 0; display: none; }