/* ==========================================
   TEZARIUS CHAT
========================================== */

.tez-chat-widget,
.tez-chat-widget * {
    box-sizing: border-box;
}

.tez-chat-widget {
    position: fixed;
    right: 15px;
    bottom: 96px;
    z-index: 999990;
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Arial,
        sans-serif;
}


/* ==========================================
   BUTTON
========================================== */

.tez-chat-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 112px;
    height: 54px;
    padding: 0 20px;
    border: 0;
    border-radius: 27px;
    background: linear-gradient(135deg, #3478f6 0%, #2563eb 100%);
    color: #ffffff;
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(37, 99, 235, 0.32);
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        opacity 0.18s ease,
        visibility 0.18s ease;
}

.tez-chat-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 34px rgba(37, 99, 235, 0.38);
}

.tez-chat-button:active {
    transform: translateY(0);
}

.tez-chat-button:focus-visible,
.tez-chat-close:focus-visible,
.tez-chat-send:focus-visible,
.tez-chat-load-more:focus-visible {
    outline: 3px solid rgba(52, 120, 246, 0.30);
    outline-offset: 3px;
}

.tez-chat-button-text {
    font-size: 15px;
    font-weight: 700;
}


/* ==========================================
   CHAT WINDOW
========================================== */

.tez-chat-window {
    position: absolute;
    right: 0;
    bottom: 68px;
    width: 360px;
    height: 520px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 20px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.20);
    opacity: 0;
    visibility: hidden;
    transform: translateY(15px) scale(0.98);
    pointer-events: none;
    transition:
        opacity 0.2s ease,
        transform 0.2s ease,
        visibility 0.2s ease;
}

.tez-chat-widget._opened .tez-chat-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}


/* ==========================================
   HEADER
========================================== */

.tez-chat-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #3478f6 0%, #2563eb 100%);
    color: #ffffff;
}

.tez-chat-header-info {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.tez-chat-avatar {
    display: flex;
    flex: 0 0 42px;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    font-size: 19px;
    font-weight: 700;
}

.tez-chat-title {
    font-size: 16px;
    font-weight: 700;
}

.tez-chat-status {
    margin-top: 2px;
    font-size: 12px;
    opacity: 0.82;
}

.tez-chat-close {
    display: flex;
    flex: 0 0 34px;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #ffffff;
    font-size: 28px;
    line-height: 30px;
    cursor: pointer;
    opacity: 0.8;
}

.tez-chat-close:hover {
    background: rgba(255, 255, 255, 0.12);
    opacity: 1;
}


/* ==========================================
   MESSAGES
========================================== */

.tez-chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 18px 15px;
    background: #f7f9fc;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.tez-chat-message {
    max-width: 82%;
    margin-bottom: 14px;
}

.tez-chat-message-system {
    margin-right: auto;
}

.tez-chat-message-user {
    margin-left: auto;
}

.tez-chat-message-text {
    padding: 11px 13px;
    border-radius: 14px 14px 14px 4px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
    color: #334155;
    font-size: 14px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.tez-chat-message-user .tez-chat-message-text {
    border-radius: 14px 14px 4px 14px;
    background: #2563eb;
    color: #ffffff;
}

.tez-chat-message-time {
    margin-top: 5px;
    padding: 0 4px;
    color: #94a3b8;
    font-size: 10px;
}

.tez-chat-message-user .tez-chat-message-time {
    text-align: right;
}

.tez-chat-message-link {
    color: #2563eb;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.tez-chat-message-user .tez-chat-message-link {
    color: inherit;
}

.tez-chat-message-file {
    display: block;
    margin-top: 8px;
}

.tez-chat-message-file:first-child {
    margin-top: 0;
}

.tez-chat-message-file img {
    display: block;
    width: auto;
    max-width: 100%;
    max-height: 230px;
    border-radius: 9px;
}

.tez-chat-load-more {
    display: block;
    margin: 0 auto 14px;
    padding: 7px 13px;
    border: 1px solid #dce1e8;
    border-radius: 999px;
    background: #ffffff;
    color: #2563eb;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.tez-chat-load-more:hover {
    background: #eff6ff;
}

.tez-chat-load-more:disabled,
.tez-chat-send:disabled {
    cursor: wait;
    opacity: 0.6;
}


/* ==========================================
   FOOTER
========================================== */

.tez-chat-footer {
    flex: 0 0 auto;
    padding: 12px;
    background: #ffffff;
    border-top: 1px solid #edf0f4;
}

.tez-chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.tez-chat-input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 44px;
    max-height: 110px;
    padding: 11px 13px;
    overflow-y: auto;
    resize: none;
    border: 1px solid #dce1e8;
    border-radius: 12px;
    outline: none;
    background: #ffffff;
    color: #222222;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.tez-chat-input:focus {
    border-color: #3478f6;
    box-shadow: 0 0 0 3px rgba(52, 120, 246, 0.10);
}

.tez-chat-input::placeholder {
    color: #9ca3af;
}

.tez-chat-send {
    display: flex;
    flex: 0 0 44px;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: #2563eb;
    color: #ffffff;
    cursor: pointer;
    transition:
        background 0.15s ease,
        transform 0.15s ease;
}

.tez-chat-send:hover {
    background: #1d4ed8;
}

.tez-chat-send:active {
    transform: scale(0.96);
}

.tez-chat-footer-note {
    margin-top: 7px;
    color: #a0a8b5;
    font-size: 10px;
    text-align: center;
}

.tez-chat-api-status {
    margin-top: 7px;
    color: #b45309;
    font-size: 11px;
    line-height: 1.35;
    text-align: center;
}


/* ==========================================
   MOBILE: FULL SCREEN
========================================== */

@media (max-width: 600px) {
    html:has(.tez-chat-widget._opened),
    body:has(.tez-chat-widget._opened) {
        overflow: hidden;
        overscroll-behavior: none;
    }

    .tez-chat-widget {
        right: 14px;
        bottom: 87px;
    }

    .tez-chat-button {
        width: 54px;
        min-width: 54px;
        padding: 0;
        border-radius: 50%;
    }

    .tez-chat-button-text {
        display: none;
    }

    .tez-chat-window {
        position: fixed;
        inset: 0;
        width: 100vw;
        max-width: none;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        transform: translateY(100%);
    }

    .tez-chat-widget._opened .tez-chat-window {
        transform: translateY(0);
    }

    .tez-chat-widget._opened .tez-chat-button {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }

    .tez-chat-header {
        padding-top: calc(14px + env(safe-area-inset-top));
        padding-right: calc(16px + env(safe-area-inset-right));
        padding-left: calc(16px + env(safe-area-inset-left));
    }

    .tez-chat-messages {
        padding-right: calc(15px + env(safe-area-inset-right));
        padding-left: calc(15px + env(safe-area-inset-left));
    }

    .tez-chat-message {
        max-width: 88%;
    }

    .tez-chat-footer {
        padding-right: calc(12px + env(safe-area-inset-right));
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        padding-left: calc(12px + env(safe-area-inset-left));
    }

    .tez-chat-input {
        /* 16px не позволяет iOS увеличивать страницу при фокусе. */
        font-size: 16px;
    }
}


/* ==========================================
   REDUCED MOTION
========================================== */

@media (prefers-reduced-motion: reduce) {
    .tez-chat-button,
    .tez-chat-window,
    .tez-chat-send {
        transition: none;
    }

    .tez-chat-messages {
        scroll-behavior: auto;
    }
}
