/* Виджет чата */
.chat-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 9999;
    font-family: 'Gilroy', 'Arial', sans-serif;
}

/* Контейнер иконки с волнами */
.chat-icon-wrapper {
    position: relative;
    width: 70px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Эффект волн (камень в воду) */
.wave {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid #e70000;
    opacity: 0;
    animation: waveEffect 3s infinite;
    display: block !important;
}

.wave-1 {
    animation-delay: 0s;
}

.wave-2 {
    animation-delay: 1s;
}

.wave-3 {
    animation-delay: 2s;
}

@keyframes waveEffect {
    0% {
        transform: scale(0.8);
        opacity: 0.7;
    }

    50% {
        opacity: 0.4;
    }

    100% {
        transform: scale(1.8);
        opacity: 0;
    }
}

/* Скрываем волны если чат отключен */
.chat-widget.no-waves .wave {
    display: none !important;
}

/* Зеленый кружок "в сети" сверху иконки */
.online-indicator {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 12px;
    height: 12px;
    background: #4cff4c;
    border-radius: 50%;
    border: 2px solid white;
    z-index: 11;
    animation: pulseDot 2s infinite;
}

@keyframes pulseDot {
    0% {
        box-shadow: 0 0 0 0 rgba(76, 255, 76, 0.7);
    }

    70% {
        box-shadow: 0 0 0 8px rgba(76, 255, 76, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(76, 255, 76, 0);
    }
}

/* Основная иконка */
.chat-icon {
    width: 60px;
    height: 60px;
    background: #e70000;
    border-radius: 50%;
    box-shadow: 0 6px 25px rgba(231, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 10;
}

.chat-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 30px rgba(231, 0, 0, 0.5);
}

/* Подпись "Я онлайн" (всегда видна) */
.online-status {
    position: absolute;
    top: -35px;
    right: 0;
    background: white;
    padding: 6px 12px;
    border-radius: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    opacity: 1;
    transform: translateY(0);
    transition: all 0.3s ease;
}

.online-dot {
    width: 8px;
    height: 8px;
    background: #4cff4c;
    border-radius: 50%;
    animation: pulseDot 2s infinite;
}

/* Иконки мессенджеров СВЕРХУ */
.messenger-icons-top {
    position: absolute;
    bottom: 80px;
    right: 0;
    display: none;
    flex-direction: column;
    gap: 15px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    z-index: 9;
}

.messenger-icons-top.show {
    opacity: 1;
    transform: translateY(0);
}

/* Подпись над иконками мессенджеров */
.messenger-label {
    position: absolute;
    top: -30px;
    right: 0;
    background: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

/* Иконки мессенджеров */
.messenger-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    transform: scale(0.8);
    opacity: 0;
    animation: fadeInUp 0.3s forwards;
}

.messenger-icon:nth-child(2) {
    animation-delay: 0.1s;
}

.messenger-icon:nth-child(3) {
    animation-delay: 0.2s;
}

.messenger-icon:nth-child(4) {
    animation-delay: 0.3s;
}

@keyframes fadeInUp {
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Стили для конкретных мессенджеров */
.messenger-icon.whatsapp {
    background: #25D366;
    box-shadow: 0 4px 15px rgba(37, 211, 102, 0.3);
}

.messenger-icon.vk {
    background: #4C75A3;
    box-shadow: 0 4px 15px rgba(76, 117, 163, 0.3);
}

.messenger-icon.telegram {
    background: #2AABEE;
    box-shadow: 0 4px 15px rgba(42, 171, 238, 0.3);
}

.messenger-icon:hover {
    transform: scale(1.15);
}

/* Панель чата и форма СЛЕВА */
.chat-panel,
.feedback-form {
    position: absolute;
    bottom: 0;
    right: 80px;
    width: 320px;

    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.3s ease;
    z-index: 1000;
    /* Максимальная высота на больших экранах */
    max-height: min(600px, 80vh);
    min-height: 500px;
}

.chat-panel.active,
.feedback-form.active {
    opacity: 1;
    transform: translateX(0);
}

/* Заголовок */
.chat-header,
.feedback-header {
    background: #e70000;
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.feedback-header h4 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.chat-manager {
    display: flex;
    align-items: center;
    gap: 12px;
}

.manager-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid white;
    flex-shrink: 0;
}

.manager-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.manager-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.manager-name {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.manager-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.chat-close,
.feedback-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
    opacity: 0.8;
    transition: opacity 0.2s;
    flex-shrink: 0;
    margin-left: 10px;
    background-color: white;
}

.chat-close:hover,
.feedback-close:hover {
    opacity: 1;
}

/* Основной контейнер для чата */
.chat-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Контейнер сообщений с фиксированным заголовком */
.chat-messages-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Сообщения - фиксированный блок с прокруткой */
.chat-messages {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Для прижатия первого сообщения к верху */
.chat-messages:after {
    content: '';
    flex: 1;
    min-height: 10px;
}

.message {
    margin-bottom: 15px;
    max-width: 85%;
    flex-shrink: 0;
}

.manager-message {
    align-self: flex-start;
}

.user-message {
    align-self: flex-end;
}

.message-text {
    background: #f5f5f5;
    padding: 12px 16px;
    border-radius: 18px 18px 18px 4px;
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    word-break: break-word;
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
}

.user-message .message-text {
    background: #e70000;
    color: white;
    border-radius: 18px 18px 4px 18px;
}

.message-time {
    font-size: 11px;
    color: #888;
    margin-top: 4px;
    text-align: right;
}

.manager-message .message-time {
    text-align: left;
}

/* Поле ввода - всегда внизу */
.chat-input-area {
    padding: 15px 20px;
    display: flex;
    gap: 10px;
    background: white;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

.chat-input-area textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    resize: none;
    min-height: 44px;
    max-height: 100px;
    font-family: inherit;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.chat-input-area textarea:focus {
    border-color: #e70000;
}

.send-btn {
    width: 44px;
    height: 44px;
    background: #e70000;
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: #cc0000;
    transform: scale(1.05);
}

/* Форма обратной связи */
.feedback-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 10px
}

.feedback-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.feedback-content p {
    margin: 0 0 20px 0;
    color: #666;
    font-size: 14px;
    line-height: 1.5;
}

.form-group {
    margin-bottom: 15px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: #e70000;
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.submit-btn {
    width: 100%;
    padding: 14px;
    background: #e70000;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: auto;
}

.submit-btn:hover {
    background: #cc0000;
}

/* ===== АДАПТИВНОСТЬ ===== */

/* Планшеты и маленькие ноутбуки */
@media (max-width: 1024px) {
    .chat-widget {
        bottom: 25px;
        right: 25px;
    }
}

/* Большие мобильные устройства */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 20px;
        right: 20px;
    }

    .chat-icon-wrapper {
        width: 60px;
        height: 60px;
    }

    .chat-icon {
        width: 50px;
        height: 50px;
    }

    .online-indicator {
        width: 10px;
        height: 10px;
        top: 4px;
        right: 4px;
    }

    .online-status {
        top: -30px;
        font-size: 11px;
        padding: 5px 10px;
    }

    .messenger-icons-top {
        bottom: 70px;
        gap: 12px;
    }

    .messenger-icon {
        width: 45px;
        height: 45px;
    }

    .messenger-label {
        font-size: 11px;
        padding: 5px 10px;
        top: -25px;
    }

    .chat-panel,
    .feedback-form {
        width: calc(100vw - 100px);
        max-width: 320px;
        right: 70px;
        max-height: min(500px, 80vh);
        min-height: 250px;
    }

    .chat-header,
    .feedback-header {
        padding: 15px;
    }

    .manager-avatar {
        width: 42px;
        height: 42px;
    }

    .manager-name {
        font-size: 15px;
    }

    .chat-messages {
        padding: 15px;
    }

    .feedback-content {
        padding: 15px;
    }

    .chat-input-area {
        padding: 12px 15px;
    }

    .message-text {
        padding: 10px 14px;
        font-size: 13px;
    }
}

/* Средние мобильные устройства */
@media (max-width: 640px) {
    .chat-widget {
        bottom: 15px;
        right: 15px;
    }

    .chat-panel,
    .feedback-form {
        width: calc(100vw - 90px);
        right: 65px;
        max-height: min(450px, 80vh);
        min-height: 220px;
    }

    .messenger-icons-top {
        bottom: 65px;
        gap: 10px;
    }

    .messenger-icon {
        width: 42px;
        height: 42px;
    }

    .send-btn {
        width: 40px;
        height: 40px;
    }
}

/* Маленькие мобильные устройства */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 10px;
        right: 10px;
    }

    .chat-icon-wrapper {
        width: 55px;
        height: 55px;
    }

    .chat-icon {
        width: 45px;
        height: 45px;
    }

    .online-indicator {
        width: 9px;
        height: 9px;
        top: 3px;
        right: 3px;
    }

    .online-status {
        top: -25px;
        font-size: 10px;
        padding: 4px 8px;
    }

    .messenger-icons-top {
        bottom: 60px;
        gap: 8px;
    }

    .messenger-icon {
        width: 40px;
        height: 40px;
    }

    .messenger-label {
        font-size: 10px;
        padding: 4px 8px;
        top: -22px;
    }

    .chat-panel,
    .feedback-form {
        width: calc(100vw - 80px);
        right: 60px;
        max-height: min(400px, 80vh);
        min-height: 200px;
        bottom: 0;
    }

    .chat-header,
    .feedback-header {
        padding: 12px;
    }

    .manager-avatar {
        width: 38px;
        height: 38px;
    }

    .manager-name {
        font-size: 14px;
    }

    .manager-status {
        font-size: 11px;
    }

    .chat-messages {
        padding: 12px;
    }

    .feedback-content {
        padding: 12px;
    }

    .feedback-content p {
        font-size: 13px;
        margin-bottom: 15px;
    }

    .form-group {
        margin-bottom: 12px;
    }

    .form-group input,
    .form-group textarea {
        padding: 10px 14px;
        font-size: 13px;
    }

    .form-group textarea {
        min-height: 70px;
    }

    .submit-btn {
        padding: 12px;
        font-size: 15px;
    }

    .chat-input-area {
        padding: 10px 12px;
    }

    .chat-input-area textarea {
        padding: 10px 14px;
        font-size: 13px;
        min-height: 40px;
    }

    .send-btn {
        width: 38px;
        height: 38px;
    }

    .message-text {
        padding: 8px 12px;
        font-size: 12px;
    }

    .message-time {
        font-size: 10px;
    }
}

/* Очень маленькие устройства */
@media (max-width: 360px) {
    .chat-widget {
        bottom: 8px;
        right: 8px;
    }

    .chat-icon-wrapper {
        width: 50px;
        height: 50px;
    }

    .chat-icon {
        width: 40px;
        height: 40px;
    }

    .messenger-icons-top {
        bottom: 55px;
    }

    .messenger-icon {
        width: 38px;
        height: 38px;
    }

    .chat-panel,
    .feedback-form {
        width: calc(100vw - 70px);
        right: 55px;
        max-height: min(380px, 80vh);
        min-height: 180px;
    }

    .chat-header,
    .feedback-header {
        padding: 10px;
    }

    .manager-avatar {
        width: 36px;
        height: 36px;
    }

    .manager-name {
        font-size: 13px;
    }

    .chat-messages {
        padding: 10px;
    }

    .feedback-content {
        padding: 10px;
    }

    .form-group input,
    .form-group textarea {
        padding: 8px 12px;
        font-size: 12px;
    }

    .submit-btn {
        padding: 10px;
        font-size: 14px;
    }
}

/* Ландшафтная ориентация мобильных устройств */
@media (max-height: 600px) and (orientation: landscape) {

    .chat-panel,
    .feedback-form {
        max-height: min(300px, 80vh);
        min-height: 150px;
    }

    .chat-messages {
        padding: 10px;
    }

    .feedback-content {
        padding: 10px;
    }

    .messenger-icons-top {
        bottom: 60px;
        gap: 6px;
    }

    .messenger-icon {
        width: 35px;
        height: 35px;
    }

    .messenger-label {
        top: -20px;
        font-size: 9px;
        padding: 3px 6px;
    }

    .chat-input-area {
        padding: 8px 10px;
    }

    .chat-input-area textarea {
        min-height: 36px;
        padding: 8px 12px;
    }
}

/* Специальные стили для очень высоких устройств */
@media (min-height: 1000px) {

    .chat-panel,
    .feedback-form {
        max-height: min(700px, 80vh);
    }
}

/* Поддержка устройств с notch (вырезом) */
@supports (padding: max(0px)) {
    .chat-widget {
        right: max(30px, env(safe-area-inset-right));
        bottom: max(30px, env(safe-area-inset-bottom));
    }

    @media (max-width: 768px) {
        .chat-widget {
            right: max(20px, env(safe-area-inset-right));
            bottom: max(20px, env(safe-area-inset-bottom));
        }
    }

    @media (max-width: 480px) {
        .chat-widget {
            right: max(10px, env(safe-area-inset-right));
            bottom: max(10px, env(safe-area-inset-bottom));
        }
    }
}

/* Улучшенная поддержка touch-устройств */
@media (hover: none) and (pointer: coarse) {
    .chat-icon:hover {
        transform: none;
    }

    .send-btn:hover,
    .submit-btn:hover,
    .messenger-icon:hover {
        transform: none;
    }

    .chat-close:hover,
    .feedback-close:hover {
        opacity: 0.8;
    }

    /* Увеличиваем область клика для мобильных */
    .chat-icon {
        min-width: 44px;
        min-height: 44px;
    }

    .messenger-icon {
        min-width: 44px;
        min-height: 44px;
    }

    .send-btn {
        min-width: 44px;
        min-height: 44px;
    }

    /* Увеличиваем тач-зоны для полей ввода */
    .chat-input-area textarea,
    .form-group input,
    .form-group textarea {
        font-size: 16px;
        /* Предотвращает масштабирование iOS */
        touch-action: manipulation;
    }
}

/* Стили для скроллбара */
.chat-messages::-webkit-scrollbar,
.feedback-content::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.feedback-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb,
.feedback-content::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.feedback-content::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Firefox */
.chat-messages,
.feedback-content {
    scrollbar-width: thin;
    scrollbar-color: #ccc #f1f1f1;
}