/* ============================================================
   СТИЛИ ДЛЯ ОНЛАЙН-ЧАТА (ПУБЛИЧНАЯ ЧАСТЬ)
   ============================================================ */

.chat-box {
    max-width: 100%;
    border-radius: var(--radius10);
    overflow: hidden;
    border: 1px solid var(--gray-color);
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    background: #fff;
}

/* ============================================================
   ЗАГОЛОВОК ЧАТА
   ============================================================ */

.chat-box-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: var(--lilac-color);
}

.chat-box-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.chat-box-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    border: 2px solid #fff;
    float: none;
    display: block;
}

.chat-box-online {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #96ff4f;
    border-radius: 50%;
    border: 2px solid var(--lilac-color);
    box-shadow: 0 0 6px 2px rgba(150,255,79,0.5);
    animation: chatPulse 2.5s infinite;
}

@keyframes chatPulse {
    0%,100% {
        transform: scale(1);
        box-shadow: 0 0 6px 2px rgba(150,255,79,0.4);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 12px 4px rgba(150,255,79,0.6);
    }
}

.chat-box-info {
    flex: 1;
}

.chat-box-name {
    color: #fff;
    font-weight: 600;
    font-size: 16px;
}

.chat-box-status {
    color: rgba(255,255,255,0.7);
    font-size: 12px;
}

/* ============================================================
   СООБЩЕНИЯ
   ============================================================ */

.chat-box-messages {
    background: #f8f7f5;
    padding: 15px 18px;
    min-height: 280px;
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

.chat-msg-in {
    align-items: flex-start;
}

.chat-msg-out {
    align-items: flex-end;
    align-self: flex-end;
}

.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    position: relative;
    word-break: break-word;
}

.chat-msg-bubble-in {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 12px 12px 12px 4px;
}

.chat-msg-bubble-out {
    background: var(--lilac-color);
    border-radius: 12px 12px 4px 12px;
}

.chat-msg-bubble-out .chat-msg-text {
    color: #fff;
}

.chat-msg-text {
    font-size: 14px;
    line-height: 1.5;
    color: var(--darkgray);
}

.chat-msg-tail-in {
    position: absolute;
    bottom: -1px;
    left: -8px;
    border-right: 10px solid #fff;
    border-bottom: 10px solid transparent;
    width: 0;
    height: 0;
}

.chat-msg-tail-out {
    position: absolute;
    bottom: -1px;
    right: -8px;
    border-left: 10px solid var(--lilac-color);
    border-bottom: 10px solid transparent;
    width: 0;
    height: 0;
}

.chat-msg-time {
    font-size: 10px;
    color: var(--gray);
    margin-top: 2px;
}

.chat-msg-out .chat-msg-time {
    padding-right: 4px;
}

.chat-typing-indicator {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 5px 0;
    font-size: 12px;
    color: var(--gray);
}

.chat-typing-dots {
    display: flex;
    gap: 3px;
}

.chat-typing-dot {
    width: 6px;
    height: 6px;
    background: var(--gray);
    border-radius: 50%;
    animation: chatDot 1.4s infinite both;
}
.chat-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.chat-typing-dot:nth-child(2) { animation-delay: -0.16s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes chatDot {
    0%,80%,100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ============================================================
   ФУТЕР ЧАТА (ФОРМА)
   ============================================================ */

.chat-box-footer {
    padding: 10px 15px;
    background: #fff;
    border-top: 1px solid #eee;
}

.chat-box-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-box-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: var(--radius10);
    font-size: 14px;
    font-family: "Tahoma","Arial",sans-serif;
    resize: vertical;
    min-height: 40px;
    background: #f9f9f9;
    box-sizing: border-box;
}

.chat-box-input:focus {
    outline: none;
    border-color: var(--lilac-color);
}

.chat-box-email {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: var(--radius10);
    font-size: 13px;
    font-family: "Tahoma","Arial",sans-serif;
    background: #f9f9f9;
    box-sizing: border-box;
}

.chat-box-email:focus {
    outline: none;
    border-color: var(--lilac-color);
}

.chat-box-hint {
    color: var(--gray);
    font-size: 0.75rem;
    padding-left: 4px;
}

.chat-box-btn {
    padding: 10px 18px;
    background: var(--lilac-color);
    color: #fff;
    border: none;
    border-radius: var(--radius10);
    font-size: 14px;
    cursor: pointer;
    font-family: "Tahoma","Arial",sans-serif;
    transition: background 0.3s;
}

.chat-box-btn:hover {
    background: #8d6f81;
}

.chat-box-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ============================================================
   УВЕДОМЛЕНИЯ
   ============================================================ */

.chat-box-notice {
    padding: 12px 18px;
    text-align: center;
    font-weight: 500;
}

.chat-box-notice.success {
    background: #e8f5e9;
    color: #2e7d32;
    border-left: 4px solid #4caf50;
}

.chat-box-notice.error {
    background: #ffebee;
    color: #c62828;
    border-left: 4px solid #e53935;
}

.chat-box-notice-info {
    padding: 6px 15px;
    background: #fff3cd;
    color: #856404;
    font-size: 12px;
    text-align: center;
    border-bottom: 1px solid #eee;
}

/* ============================================================
   СТИЛИ ДЛЯ АДМИН-ПАНЕЛИ (УПРАВЛЕНИЕ ЧАТАМИ)
   ============================================================ */

/* Контейнер админ-панели */
.chat-admin-container {
    background: #fff;
    border-radius: var(--radius10);
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* Заголовок админ-панели */
.chat-admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
    margin-bottom: 20px;
}

.chat-admin-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

.chat-admin-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.unread-badge {
    font-size: 13px;
    color: #555;
    padding: 5px 12px;
    background: #f5f5f5;
    border-radius: 20px;
}

/* ============================================================
   ВЕРТИКАЛЬНЫЕ ВКЛАДКИ ЧАТОВ (АДМИН)
   ============================================================ */

.chat-tabs-container {
    display: flex;
    gap: 0;
    background: #ffffff;
    border-radius: var(--radius10);
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    min-height: 500px;
}

.chat-tabs-list {
    flex: 0 0 280px;
    background: #f5f5f8;
    border-right: 1px solid #e8e8ed;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-tabs-scroll {
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    padding: 8px 0;
}

.chat-tabs-scroll::-webkit-scrollbar {
    width: 4px;
}

.chat-tabs-scroll::-webkit-scrollbar-thumb {
    background: var(--lilac-color);
    border-radius: 4px;
}

.chat-tabs-scroll::-webkit-scrollbar-track {
    background: #f0f0f0;
}

.chat-tabs-fade {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: linear-gradient(to top, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0) 100%);
    pointer-events: none;
    z-index: 2;
}

/* Вкладка */
.chat-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid #e8e8ed;
    transition: background 0.2s ease;
    background: #f5f5f8;
    position: relative;
}

.chat-tab:last-child {
    border-bottom: none;
}

.chat-tab:hover {
    background: #ececf0;
}

.chat-tab.active {
    background: #ffffff;
    border-left: 3px solid var(--lilac-color);
}

.chat-tab-avatar {
    font-size: 18px;
    flex-shrink: 0;
}

.chat-tab-name {
    font-weight: 600;
    font-size: 14px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-tab-unread {
    background: #e53935;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 12px;
    flex-shrink: 0;
    min-width: 20px;
    text-align: center;
}

.chat-tab-email {
    font-size: 11px;
    color: #999;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

.chat-tab-time {
    font-size: 10px;
    color: #bbb;
    flex-shrink: 0;
}

/* ============================================================
   ОКНО ЧАТА (правая часть, админ)
   ============================================================ */

.chat-tabs-content {
    flex: 1;
    background: #ffffff;
    min-height: 500px;
}

.chat-tab-pane {
    display: none;
    height: 100%;
    min-height: 500px;
}

.chat-tab-pane.active {
    display: block;
}

.chat-window {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 500px;
}

/* Заголовок окна чата */
.chat-window-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: var(--lilac-color);
    border-bottom: 2px solid #e0e0e0;
    flex-shrink: 0;
}

.chat-window-avatar-wrapper {
    position: relative;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
}

.chat-window-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    border: 2px solid #fff;
}

.chat-window-status-online {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    background: #96ff4f;
    border: 2px solid var(--lilac-color);
    border-radius: 50%;
    box-shadow: 0 0 0 2px #fff;
}

.chat-window-info {
    flex: 1;
}

.chat-window-name {
    color: #fff;
    font-weight: 600;
    font-size: 15px;
}

.chat-window-email {
    color: rgba(255,255,255,0.7);
    font-size: 12px;
}

.chat-window-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-window-actions .btn-view {
    background: rgba(255,255,255,0.2);
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 14px;
    text-decoration: none;
    transition: background 0.2s;
}

.chat-window-actions .btn-view:hover {
    background: rgba(255,255,255,0.35);
    color: #fff;
    text-decoration: none;
}

/* Тело окна чата (сообщения) */
.chat-window-body {
    flex: 1;
    padding: 15px 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #f8f7f5;
    min-height: 300px;
    max-height: 500px;
}

.chat-window-body .chat-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

.chat-window-body .chat-message-in {
    align-items: flex-start;
}

.chat-window-body .chat-message-out {
    align-items: flex-end;
    align-self: flex-end;
}

.chat-window-body .chat-message-bubble {
    position: relative;
    padding: 8px 14px;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    max-width: 100%;
}

.chat-window-body .chat-message-bubble-in {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 12px 12px 12px 4px;
}

.chat-window-body .chat-message-bubble-out {
    background: var(--lilac-color);
    border-radius: 12px 12px 4px 12px;
}

.chat-window-body .chat-message-text {
    font-size: 14px;
    line-height: 1.5;
    color: var(--darkgray);
    word-break: break-word;
}

.chat-window-body .chat-message-out .chat-message-text {
    color: #fff;
}

.chat-window-body .chat-message-tail-in {
    position: absolute;
    bottom: -1px;
    left: -8px;
    width: 0;
    height: 0;
    border-right: 10px solid #fff;
    border-bottom: 10px solid transparent;
}

.chat-window-body .chat-message-tail-out {
    position: absolute;
    bottom: -1px;
    right: -8px;
    width: 0;
    height: 0;
    border-left: 10px solid var(--lilac-color);
    border-bottom: 10px solid transparent;
}

.chat-window-body .chat-message-time {
    font-size: 10px;
    color: var(--gray);
    margin-top: 2px;
    padding-left: 4px;
}

.chat-window-body .chat-message-out .chat-message-time {
    padding-right: 4px;
    padding-left: 0;
}

.chat-window-body .chat-message-unread-dot {
    color: #e53935;
    font-size: 10px;
    margin-left: 4px;
}

/* Футер окна чата (ответ) */
.chat-window-footer {
    padding: 10px 15px;
    background: #fff;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

.chat-reply-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-reply-textarea {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: var(--radius10);
    font-size: 14px;
    font-family: "Tahoma", "Arial", sans-serif;
    resize: vertical;
    min-height: 40px;
    background: #f9f9f9;
    line-height: 1.5;
}

.chat-reply-textarea:focus {
    outline: none;
    border-color: var(--lilac-color);
    box-shadow: 0 0 0 3px rgba(160, 131, 150, 0.2);
}

.chat-reply-send {
    flex-shrink: 0;
    padding: 8px 18px;
    height: 40px;
}

/* ============================================================
   АДАПТИВНОСТЬ (общая)
   ============================================================ */

@media (max-width: 992px) {
    .chat-tabs-list {
        flex: 0 0 220px;
    }
    .chat-tab {
        padding: 8px 12px;
    }
    .chat-tab-name {
        font-size: 13px;
    }
    .chat-tab-email {
        max-width: 80px;
        font-size: 10px;
    }
}

@media (max-width: 768px) {
    .chat-tabs-container {
        flex-direction: column;
        min-height: auto;
    }
    .chat-tabs-list {
        flex: none;
        max-height: 250px;
        border-right: none;
        border-bottom: 1px solid #e8e8ed;
    }
    .chat-tabs-scroll {
        max-height: 250px;
    }
    .chat-tabs-content {
        min-height: 400px;
    }
    .chat-tab-pane {
        min-height: 400px;
    }
    .chat-window {
        min-height: 400px;
    }
    .chat-window-body {
        max-height: 350px;
        min-height: 200px;
    }
    .chat-reply-wrapper {
        flex-direction: column;
        align-items: stretch;
    }
    .chat-reply-send {
        width: 100%;
    }
    .chat-admin-header {
        flex-direction: column;
        align-items: stretch;
    }
    .chat-admin-actions {
        flex-wrap: wrap;
    }
    .chat-window-actions .btn-view {
        font-size: 12px;
        padding: 3px 8px;
    }
}

@media (max-width: 576px) {
    .chat-admin-container {
        padding: 12px;
    }
    .chat-tabs-list {
        max-height: 200px;
    }
    .chat-tabs-scroll {
        max-height: 200px;
    }
    .chat-tab {
        padding: 6px 10px;
    }
    .chat-tab-name {
        font-size: 12px;
    }
    .chat-tab-email {
        display: none;
    }
    .chat-tab-time {
        font-size: 9px;
    }
    .chat-window-body {
        max-height: 280px;
        min-height: 150px;
        padding: 10px 12px;
    }
    .chat-window-body .chat-message {
        max-width: 95%;
    }
    .chat-window-body .chat-message-text {
        font-size: 13px;
    }
    .chat-window-header {
        padding: 10px 14px;
    }
    .chat-window-name {
        font-size: 14px;
    }
    .chat-window-actions {
        gap: 4px;
    }
    .chat-window-actions .btn-view {
        font-size: 11px;
        padding: 2px 6px;
    }
}

/* ============================================================
   АДАПТИВНОСТЬ ДЛЯ ПУБЛИЧНОГО ЧАТА (МОБИЛЬНЫЕ)
   ============================================================ */

/* Для планшетов и небольших ноутбуков */
@media (max-width: 992px) {
    .chat-box-messages {
        min-height: 240px;
        max-height: 350px;
    }
}

/* Для мобильных телефонов */
@media (max-width: 768px) {
    .chat-box {
        width: 100%;
        max-width: 100%;
        border-radius: 8px;
    }

    .chat-box-messages {
        min-height: 200px;
        max-height: 300px;
        padding: 12px 14px;
    }

    .chat-box-header {
        padding: 10px 14px;
    }

    .chat-box-avatar {
        width: 36px;
        height: 36px;
    }

    .chat-box-avatar-img {
        width: 36px;
        height: 36px;
    }

    .chat-box-online {
        width: 10px;
        height: 10px;
        border-width: 2px;
    }

    .chat-box-name {
        font-size: 14px;
    }

    .chat-box-status {
        font-size: 11px;
    }

    .chat-msg {
        max-width: 90%;
    }

    .chat-msg-bubble {
        padding: 8px 12px;
        font-size: 13px;
    }

    .chat-msg-text {
        font-size: 13px;
    }

    .chat-msg-tail-in {
        left: -6px;
        border-right-width: 8px;
        border-bottom-width: 8px;
    }

    .chat-msg-tail-out {
        right: -6px;
        border-left-width: 8px;
        border-bottom-width: 8px;
    }

    .chat-box-footer {
        padding: 8px 12px;
    }

    .chat-box-input {
        font-size: 13px;
        padding: 6px 10px;
        min-height: 36px;
    }

    .chat-box-email {
        font-size: 12px;
        padding: 6px 10px;
    }

    .chat-box-btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    .chat-box-hint {
        font-size: 0.7rem;
    }

    .chat-box-notice-info {
        font-size: 11px;
        padding: 4px 10px;
    }
}

/* Для очень маленьких телефонов */
@media (max-width: 576px) {
    .chat-box-messages {
        min-height: 160px;
        max-height: 250px;
        padding: 10px 12px;
    }

    .chat-msg {
        max-width: 95%;
    }

    .chat-msg-bubble {
        padding: 6px 10px;
        font-size: 12px;
        border-radius: 10px;
    }

    .chat-msg-text {
        font-size: 12px;
        line-height: 1.4;
    }

    .chat-box-name {
        font-size: 13px;
    }

    .chat-box-avatar {
        width: 32px;
        height: 32px;
    }

    .chat-box-avatar-img {
        width: 32px;
        height: 32px;
    }

    .chat-box-online {
        width: 9px;
        height: 9px;
        border-width: 1.5px;
        right: -1px;
        bottom: -1px;
    }

    .chat-box-input {
        font-size: 12px;
        padding: 5px 8px;
        min-height: 32px;
        border-radius: 8px;
    }

    .chat-box-email {
        font-size: 12px;
        padding: 5px 8px;
        border-radius: 8px;
    }

    .chat-box-btn {
        padding: 6px 12px;
        font-size: 12px;
        border-radius: 8px;
    }

    .chat-box-footer {
        padding: 6px 10px;
    }

    .chat-box-notice {
        padding: 8px 12px;
        font-size: 12px;
    }

    .chat-box-notice-info {
        font-size: 10px;
        padding: 3px 8px;
    }

    .chat-msg-time {
        font-size: 9px;
    }

    .chat-msg-tail-in {
        left: -5px;
        border-right-width: 7px;
        border-bottom-width: 7px;
    }

    .chat-msg-tail-out {
        right: -5px;
        border-left-width: 7px;
        border-bottom-width: 7px;
    }
}
