#tlcwt-chat-widget {
    position: fixed;
    right: 24px;
    bottom: var(--tlcwt-desktop-bottom, 24px);
    z-index: 999999;
    font-family: inherit;
    direction: ltr;
    box-sizing: border-box;
    max-width: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* Visible viewport height. chat.js overrides this on iOS Safari while the keyboard is open. */
    --tlcwt-vh: 100vh;
    --tlcwt-kb: 0px;
}

@supports (height: 100dvh) {
    #tlcwt-chat-widget {
        --tlcwt-vh: 100dvh;
    }
}

#tlcwt-chat-widget *,
#tlcwt-chat-widget *::before,
#tlcwt-chat-widget *::after {
    box-sizing: border-box;
}

#tlcwt-chat-toggle {
    width: auto !important;
    height: 52px !important;
    min-width: 0;
    box-sizing: border-box !important;
    flex-shrink: 0;
    border: 0;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 22px 0 10px !important;
    background: var(--tlcwt-primary, #2aabee);
    color: #fff;
    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(42, 171, 238, 0.34);
    transition:
        transform 160ms ease,
        box-shadow 160ms ease;
    animation: tlcwt-telegram-nudge 3.6s ease-in-out infinite;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

#tlcwt-chat-toggle:hover,
#tlcwt-chat-toggle:focus-visible {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 14px 32px rgba(42, 171, 238, 0.42);
}

#tlcwt-chat-toggle img {
    width: 34px !important;
    height: 34px !important;
    max-width: none !important;
    border-radius: 50%;
    background: #fff;
    flex-shrink: 0;
}

#tlcwt-chat-toggle .tlcwt-toggle-text {
    color: #fff;
}

#tlcwt-chat-window {
    position: absolute;
    right: 0;
    bottom: 64px;
    width: min(var(--tlcwt-desktop-width, 380px), calc(100vw - 40px));
    height: min(var(--tlcwt-desktop-height, 560px), calc(100vh - 110px));
    height: min(max(var(--tlcwt-desktop-height, 560px), 520px), calc(var(--tlcwt-vh, 100vh) - 110px));
    max-width: calc(100vw - 40px);
    background: var(--tlcwt-panel, #fff);
    border: 1px solid rgba(42, 171, 238, 0.16);
    border-radius: 18px;
    box-shadow: 0 18px 48px rgba(16, 42, 67, 0.24);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    direction: ltr;
}

#tlcwt-chat-window[hidden] {
    display: none;
}

.tlcwt-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 18px;
    background: var(--tlcwt-primary, #2aabee);
    color: #fff;
    font-size: 17px;
}

.tlcwt-chat-header > div {
    flex: 1;
    min-width: 0;
}
#tlcwt-chat-title {
    display: block;
    text-align: start;
}

.tlcwt-status {
    display: block;
    margin-top: 4px;
    font-size: 13px;
    opacity: 0.9;
}

.tlcwt-status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 4px;
    border-radius: 50%;
    background: #4ade80;
}

#tlcwt-chat-close {
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 30px;
    cursor: pointer;
}

#tlcwt-chat-messages {
    flex: 1;
    min-height: 0;
    padding: 18px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    background: var(--tlcwt-panel, #f4f8fb);
}

.tlcwt-message {
    max-width: 85%;
    margin-bottom: 12px;
    padding: 12px 15px;
    border-radius: 14px;
    line-height: 1.6;
    font-size: 15px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.tlcwt-message-admin {
    background: var(--tlcwt-panel, #fff);
    margin-right: auto;
    box-shadow: 0 2px 8px rgba(27, 58, 82, 0.08);
}

.tlcwt-message-user {
    background: var(--tlcwt-primary, #2aabee);
    color: #fff;
    margin-left: auto;
}

.tlcwt-message-system {
    background: #fff3cd;
    color: #664d03;
    margin-right: auto;
}

#tlcwt-chat-form {
    display: flex;
    direction: ltr;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid #eee;
    background: #fff;
    min-width: 0;
}

#tlcwt-chat-input {
    order: 1;
    direction: auto;
    flex: 1;
    resize: none;
    min-height: 56px;
    max-height: 120px;
    padding: 11px 12px;
    border: 1px solid #d5e3eb;
    border-radius: 10px;
    font-family: inherit;
    font-size: 15px;
    outline: none;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
}

#tlcwt-chat-input:focus {
    border-color: var(--tlcwt-primary, #2aabee);
    box-shadow: 0 0 0 3px rgba(42, 171, 238, 0.12);
}

#tlcwt-chat-send {
    order: 2;
    display: grid;
    place-items: center;
    width: 56px !important;
    height: 56px !important;
    box-sizing: border-box !important;
    flex-shrink: 0;
    border: 0;
    border-radius: 12px;
    background: #fff;
    color: #fff;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition:
        transform 160ms ease,
        background 160ms ease;
}

#tlcwt-chat-send:hover,
#tlcwt-chat-send:focus-visible {
    transform: translateY(-1px);
    background: #e9f7fd;
}

#tlcwt-chat-send img {
    width: 30px !important;
    height: 30px !important;
    max-width: none !important;
}

@keyframes tlcwt-telegram-nudge {
    0%,
    88%,
    100% {
        transform: translateX(0) rotate(0);
    }
    90% {
        transform: translateX(-2px) rotate(-4deg);
    }
    92% {
        transform: translateX(2px) rotate(4deg);
    }
    94% {
        transform: translateX(-1px) rotate(-2deg);
    }
    96% {
        transform: translateX(1px) rotate(2deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    #tlcwt-chat-toggle {
        animation: none;
    }
}

#tlcwt-chat-widget.tlcwt-position-left {
    left: 24px;
    right: auto;
}
#tlcwt-chat-widget.tlcwt-position-right #tlcwt-chat-window {
    left: auto;
    right: 0;
}
#tlcwt-chat-widget.tlcwt-position-left #tlcwt-chat-window {
    left: 0;
    right: auto;
}

@media (max-width: 480px) {
    #tlcwt-chat-widget {
        right: 12px;
        bottom: var(--tlcwt-mobile-bottom, 72px);
    }

    #tlcwt-chat-window {
        position: fixed;
        left: 12px;
        right: auto;
        bottom: calc(var(--tlcwt-mobile-bottom, 72px) + 64px);
        width: min(var(--tlcwt-mobile-width, 380px), calc(100vw - 24px));
        height: min(var(--tlcwt-mobile-height, 480px), calc(100vh - 110px));
        max-height: none;
    }

    #tlcwt-chat-widget.tlcwt-position-left {
        left: 15px;
        right: auto;
    }
    #tlcwt-chat-widget.tlcwt-position-right {
        right: 12px;
        left: auto;
    }
    #tlcwt-chat-widget.tlcwt-position-right #tlcwt-chat-window {
        left: auto;
        right: 12px;
    }
    #tlcwt-chat-widget.tlcwt-position-left #tlcwt-chat-window {
        left: 12px;
        right: auto;
    }
}

/*
 * iOS Safari fixes.
 * - 100vw/100vh on iOS Safari do not match the visible area (toolbars, keyboard),
 *   so the fixed panel is sized from the fixed containing block (100%) and the
 *   dynamic viewport height instead. Older browsers keep the vw/vh rules above.
 */
@media (max-width: 480px) {
    /*
     * Keyboard-safe mobile layout. When the virtual keyboard opens,
     * chat.js puts the visible viewport height in --tlcwt-vh and the
     * keyboard height in --tlcwt-kb. The panel must use the visible
     * viewport itself, not subtract the keyboard a second time.
     * Otherwise the chat window becomes tiny and the visitor loses sight
     * of the text they are typing.
     */
    #tlcwt-chat-window {
        /* Mobile: use almost the full screen width, with a small 8px gutter.
         * Do not let the saved mobile-width setting make the chat narrow. */
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        max-width: none !important;
        height: min(600px, calc(var(--tlcwt-vh, 100vh) - 16px));
        bottom: calc(var(--tlcwt-kb, 0px) + 8px);
    }

    #tlcwt-chat-window[data-view="chat"] {
        min-height: 260px;
    }
}


/*
 * iOS Safari zooms the whole page when a field with a font size below 16px
 * is focused, and does not zoom back out. That leaves the page wider than the
 * screen and lets it slide sideways. Keep the field at 16px on touch devices.
 */
@media (max-width: 480px), (hover: none) and (pointer: coarse) {
    #tlcwt-chat-input {
        font-size: 16px;
    }
}

.tlcwt-status-offline .tlcwt-status-dot {
    background: #f51818;
}

/*
 * Two-step flow.
 * data-view="prechat": name / e-mail / message form is shown.
 * data-view="chat":    the conversation (messages + reply box) is shown.
 */
#tlcwt-chat-window[data-view="prechat"] #tlcwt-chat-messages,
#tlcwt-chat-window[data-view="prechat"] #tlcwt-chat-form,
#tlcwt-chat-window[data-view="chat"] #tlcwt-prechat-form {
    display: none;
}

#tlcwt-prechat-form {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--tlcwt-panel, #fff);
}

.tlcwt-prechat-scroll {
    flex: 1 1 auto;
    min-height: 0;
    padding: 20px 18px 8px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.tlcwt-prechat-intro {
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: 14px;
    background: #f1f7fb;
    color: #1b3a52;
    font-size: 15px;
    line-height: 1.55;
}

.tlcwt-field {
    display: block;
    margin: 0 0 14px;
}

.tlcwt-field > span {
    display: block;
    margin: 0 0 6px;
    color: #1b3a52;
    font-size: 14px;
    font-weight: 600;
}

.tlcwt-field input,
.tlcwt-field textarea {
    display: block;
    width: 100%;
    margin: 0;
    padding: 12px 14px;
    border: 1px solid #d5e3eb;
    border-radius: 10px;
    background: #fff;
    color: #1b3a52;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.4;
    outline: none;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
}

.tlcwt-field textarea {
    min-height: 90px;
    max-height: 200px;
    resize: none;
}

.tlcwt-field input:focus,
.tlcwt-field textarea:focus {
    border-color: var(--tlcwt-primary, #2aabee);
    box-shadow: 0 0 0 3px rgba(42, 171, 238, 0.14);
}

.tlcwt-field.tlcwt-invalid input,
.tlcwt-field.tlcwt-invalid textarea {
    border-color: #d63638;
}

.tlcwt-prechat-error {
    margin: 0 0 10px;
    color: #b32d2e;
    font-size: 14px;
    line-height: 1.4;
}

.tlcwt-prechat-error[hidden] {
    display: none;
}

.tlcwt-prechat-actions {
    padding: 12px 18px 18px;
    background: var(--tlcwt-panel, #fff);
}

#tlcwt-prechat-submit {
    display: block;
    width: 100%;
    height: 50px;
    border: 0;
    border-radius: 12px;
    background: var(--tlcwt-primary, #2aabee);
    color: #fff;
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: filter 160ms ease, transform 160ms ease;
}

#tlcwt-prechat-submit:hover,
#tlcwt-prechat-submit:focus-visible {
    filter: brightness(0.95);
    transform: translateY(-1px);
}

#tlcwt-prechat-submit:disabled {
    opacity: 0.65;
    cursor: default;
    transform: none;
}

@media (max-width: 480px), (hover: none) and (pointer: coarse) {
    .tlcwt-field input,
    .tlcwt-field textarea {
        font-size: 16px;
    }
}
