/* Chat Widget Styles */
/* Colors:
   Primary: #2f4f8f - #4e657c
   Light bg: rgb(215, 228, 245) - #d7e4f5
   Accent/red: rgb(190, 0, 23) - #be0017
   Lighter bg: rgb(222, 233, 247) - #dee9f7
   Dark text: rgb(52, 58, 64) - #343a40
*/

/* Chat Button */
.chat-widget-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #2f4f8f;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(33, 59, 107, 0.4);
    z-index: 9997;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chat-widget-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(33, 59, 107, 0.5);
}

.chat-widget-btn svg {
    width: 28px;
    height: 28px;
    fill: white;
}

.chat-widget-btn .chat-close-icon {
    display: none;
}

.chat-widget-btn.is-open .chat-icon {
    display: none;
}

.chat-widget-btn.is-open .chat-close-icon {
    display: block;
}

/* Unread Badge (dot) */
.chat-widget-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background: rgb(190, 0, 23);
    border-radius: 50%;
    border: 2px solid white;
    animation: pulse-badge 2s infinite;
}

.chat-widget-badge.hidden {
    display: none;
}

@keyframes pulse-badge {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Chat Window */
/* Затемняющий фон — только на мобильных, под окном чата */
.chat-widget-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9997;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

@media (max-width: 991px) {
    .chat-widget-overlay.is-open {
        opacity: 1;
        visibility: visible;
    }
}

.chat-widget-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 360px;
    height: 480px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(33, 59, 107, 0.3);
    z-index: 9998;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.chat-widget-window.is-open {
    display: flex;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.chat-widget-header {
    background: linear-gradient(135deg, #2f4f8f, #213b6b);
    color: white;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-widget-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
    flex-shrink: 0;
}

.chat-widget-header-text {
    flex: 1 1 auto;
    min-width: 0;
}

.chat-widget-header-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
}

.chat-widget-header-subtitle {
    font-size: 11px;
    opacity: 0.8;
    margin-top: 1px;
}

.chat-widget-header-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    opacity: 0.8;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
}

.chat-widget-header-close:hover {
    opacity: 1;
}

.chat-widget-header-close svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Auth banner for anonymous users */
.chat-auth-banner {
    background: #fff;
    border: 1px solid rgb(215, 228, 245);
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 13px;
    line-height: 1.4;
    color: #555;
    text-align: center;
}
.chat-auth-banner a {
    color: #2f4f8f;
    font-weight: 600;
    text-decoration: underline;
}
.chat-auth-banner a:hover {
    color: rgb(52, 58, 64);
}
/* «Вернуться к чату» внизу экрана email */
.chat-email-back {
    display: block;
    margin: 14px auto 0;
    background: none;
    border: none;
    color: #2f4f8f;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    opacity: 0.85;
}
.chat-email-back:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Messages Container */
.chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f3f7fb;
}

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

.chat-widget-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-widget-messages::-webkit-scrollbar-thumb {
    background: #2f4f8f;
    border-radius: 3px;
}

/* Message */
.chat-message {
    display: flex;
    margin-bottom: 12px;
    animation: fadeIn 0.3s ease;
    max-width: 90%;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
    justify-content: flex-end;
    margin-left: auto;
}

.chat-message.operator,
.chat-message.system {
    justify-content: flex-start;
}

.chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
    border: 1px solid rgb(215, 228, 245);
    flex-shrink: 0;
    margin-right: 8px;
    align-self: flex-end;
}

.chat-message.user .chat-message-avatar {
    display: none;
}

.chat-message-bubble {
    max-width: 100%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: normal;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.chat-message.user .chat-message-bubble {
    background: #2f4f8f;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.operator .chat-message-bubble {
    background: #fff;
    color: rgb(52, 58, 64);
    border: 1px solid #e6eef6;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(20, 38, 64, 0.07);
}

.chat-message.system .chat-message-bubble {
    background: rgb(215, 228, 245);
    color: #2f4f8f;
    font-size: 12px;
    font-style: italic;
    max-width: 100%;
    text-align: center;
}

.chat-message-time {
    font-size: 10px;
    color: #2f4f8f;
    opacity: 0.7;
    margin-top: 4px;
}

.chat-message.user .chat-message-time {
    text-align: right;
}

/* Input Area */
.chat-widget-input {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid rgb(215, 228, 245);
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.chat-widget-input textarea {
    flex: 1;
    border: 1px solid rgb(215, 228, 245);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    line-height: 1.4;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
    color: rgb(52, 58, 64);
}

.chat-widget-input textarea:focus {
    border-color: #2f4f8f;
}

.chat-widget-input textarea::placeholder {
    color: #2f4f8f;
    opacity: 0.6;
}

.chat-widget-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #2f4f8f;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s;
    flex-shrink: 0;
}

.chat-widget-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
}

.chat-widget-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-widget-send-btn svg {
    width: 18px;
    height: 18px;
    fill: white;
}

/* Кнопка «Частые вопросы» (слева от поля ввода) — outline-стиль */
.chat-widget-faq-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid rgb(215, 228, 245);
    color: #2f4f8f;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.chat-widget-faq-btn:hover {
    background: rgb(222, 233, 247);
    border-color: #2f4f8f;
    transform: scale(1.05);
}

/* Empty State */
.chat-widget-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #2f4f8f;
    text-align: center;
    padding: 20px;
}

.chat-widget-empty svg {
    width: 60px;
    height: 60px;
    fill: rgb(215, 228, 245);
    margin-bottom: 16px;
}

.chat-widget-empty-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: rgb(52, 58, 64);
}

.chat-widget-empty-text {
    font-size: 14px;
    color: #2f4f8f;
}

/* Loading State */
.chat-widget-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.chat-widget-loading-dots {
    display: flex;
    gap: 4px;
}

.chat-widget-loading-dots span {
    width: 8px;
    height: 8px;
    background: #2f4f8f;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.chat-widget-loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.chat-widget-loading-dots span:nth-child(2) { animation-delay: -0.16s; }
.chat-widget-loading-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Responsive — на телефонах чат раскрывается на весь экран (модалка) */
@media (max-width: 575.98px) {
    .chat-widget-window {
        inset: 0;
        bottom: auto;
        right: auto;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-width: none;
        border-radius: 0;
    }

    .chat-widget-window.is-open {
        animation: fadeIn 0.25s ease;
    }

    /* учёт «чёлки»/жестовой зоны и мобильной клавиатуры */
    .chat-widget-header {
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .chat-widget-input {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .chat-widget-btn {
        width: 54px;
        height: 54px;
        bottom: 15px;
        right: 15px;
    }

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

/* Quick Reply Buttons */
.chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    animation: fadeIn 0.3s ease;
}

.chat-quick-reply-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: #fff;
    border: 1px solid rgba(33, 59, 107, 0.35);
    color: #2f4f8f;
    padding: 8px 14px;
    border-radius: 18px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.chat-quick-reply-btn i {
    font-size: 12px;
    opacity: 0.9;
}

.chat-quick-reply-btn:hover {
    background: rgb(222, 233, 247);
    border-color: #2f4f8f;
}

.chat-quick-reply-btn:active {
    transform: scale(0.95);
}

/* Выделенная кнопка «Написать в поддержку» — заливка */
.chat-quick-reply-btn--primary {
    background: #2f4f8f;
    border-color: #2f4f8f;
    color: #fff;
    font-weight: 600;
}

.chat-quick-reply-btn--primary:hover {
    background: rgb(62, 82, 102);
    border-color: rgb(62, 82, 102);
    color: #fff;
}

/* FAQ-пиллы тем (показываются контекстно, не висят постоянно) */
.chat-quick-replies-wrap {
    margin-top: 6px;
}

.chat-quick-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    color: #213b6b;
    margin-bottom: 10px;
}

.chat-quick-title-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #e7eefb;
    color: #2f4f8f;
    font-size: 11px;
    flex-shrink: 0;
}

.chat-quick-replies-wrap .chat-quick-replies {
    margin-top: 0;
    margin-bottom: 4px;
}

/* Мини-меню после ответа: «другие темы / остаться тут» */
.chat-faq-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    animation: fadeIn 0.3s ease;
}

.chat-faq-action {
    background: #2f4f8f;
    border: 1px solid #2f4f8f;
    color: #fff;
    padding: 8px 14px;
    border-radius: 18px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.chat-faq-action:hover {
    opacity: 0.88;
}

.chat-faq-action--ghost {
    background: #fff;
    color: #2f4f8f;
}

.chat-faq-action--ghost:hover {
    background: rgb(222, 233, 247);
    opacity: 1;
}

/* Links in auto-replies */
.chat-message.operator .chat-message-bubble a {
    color: #2f4f8f;
    text-decoration: underline;
    font-weight: 500;
}

.chat-message.operator .chat-message-bubble a:hover {
    color: rgb(52, 58, 64);
}

/* Auth screen for anonymous users */
.chat-widget-email-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 24px 20px;
    text-align: center;
}
.chat-widget-email-screen.hidden {
    display: none;
}
.chat-email-content {
    max-width: 260px;
}
.chat-email-icon {
    font-size: 36px;
    margin-bottom: 10px;
}
.chat-email-title {
    font-size: 17px;
    font-weight: 700;
    color: #343a40;
    line-height: 1.4;
    margin-bottom: 6px;
}
.chat-email-text {
    font-size: 14px;
    line-height: 1.4;
    color: #888;
    margin-bottom: 20px;
}
.chat-auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}
.chat-auth-btn {
    display: block;
    padding: 11px 20px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    text-align: center;
    transition: background .2s, border-color .2s;
}
.chat-auth-btn-primary {
    background: #2f4f8f;
    color: #fff;
    border: 2px solid #2f4f8f;
}
.chat-auth-btn-primary:hover {
    background: rgb(52, 72, 94);
    border-color: rgb(52, 72, 94);
    color: #fff;
}
.chat-auth-btn-secondary {
    background: #fff;
    color: #2f4f8f;
    border: 2px solid #2f4f8f;
}
.chat-auth-btn-secondary:hover {
    background: rgb(222, 233, 247);
}
.chat-email-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}
.chat-email-field {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #c5d0dc;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
    box-sizing: border-box;
}
.chat-email-field:focus {
    border-color: #2f4f8f;
}
.chat-email-privacy {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 11px;
    line-height: 1.4;
    color: #555;
    cursor: pointer;
    text-align: left;
}
.chat-email-privacy input[type="checkbox"] {
    margin-top: 2px;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    cursor: pointer;
}
.chat-email-privacy a {
    color: #2f4f8f;
    text-decoration: underline;
}
.chat-email-submit {
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    background: #2f4f8f;
    color: #fff;
    border: none;
    cursor: pointer;
    transition: background .15s, opacity .15s;
}
.chat-email-submit:hover:not(:disabled) {
    background: rgb(52, 72, 94);
}
.chat-email-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.chat-email-error {
    font-size: 12px;
    color: #be0017;
}
.chat-email-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    color: #aaa;
    font-size: 12px;
}
.chat-email-divider::before,
.chat-email-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #ddd;
}

/* ===== Проактивный тизер скидки ===== */
.chat-proactive-teaser {
    position: fixed;
    right: 20px;
    bottom: 92px; /* над кнопкой чата (60px + 20px + зазор) */
    z-index: 9996;
    max-width: 280px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid rgba(190, 0, 23, 0.18);
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(33, 59, 107, 0.18);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    cursor: pointer;
}

.chat-proactive-teaser.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.chat-proactive-teaser-avatar {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-proactive-teaser-text {
    flex: 1 1 auto;
    font-size: 14px;
    line-height: 1.35;
    color: #343a40;
}

.chat-proactive-teaser-close {
    flex: 0 0 auto;
    align-self: flex-start;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    background: transparent;
    color: #9aa3ad;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
}

.chat-proactive-teaser-close:hover {
    color: #be0017;
    background: rgba(190, 0, 23, 0.08);
}

@media (max-width: 575.98px) {
    .chat-proactive-teaser {
        right: 12px;
        left: 12px;
        max-width: none;
        bottom: 84px;
    }
}

/* Dark mode - disabled to keep site colors consistent */
