/* public/CSS/chat.css */
/* ВАРИАНТ: CLEAN MODERN + FIXED ICONS + TYPING + UNREAD BADGES */

:root {
    --primary-color: #ff8c42;
    --secondary-color: #7b61ff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --bg-gray: #f8fafc;
    --shadow-soft: 0 10px 40px rgba(0, 0, 0, 0.12);
    --radius-main: 24px;
    --radius-msg: 18px;
    --unread-red: #ef4444;
}

/* --- ВАЖНО: Шрифт --- */
.chat-widget, .chat-window {
    font-family: 'Poppins', sans-serif;
    box-sizing: border-box;
}
.chat-window * {
    box-sizing: border-box;
}

/* --- ПЛАВАЮЩИЙ ВИДЖЕТ --- */
.chat-widget {
    position: fixed;
    bottom: 30px;
    /* ИЗМЕНЕНИЕ: Сдвигаем влево, чтобы не перекрывать кнопку скролла (было 30px) */
    right: 95px; 
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 50%;
    box-shadow: 0 8px 24px rgba(123, 97, 255, 0.35);
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 28px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-widget:hover {
    transform: scale(1.1) rotate(-5deg);
    box-shadow: 0 12px 30px rgba(123, 97, 255, 0.5);
}

.widget-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--unread-red);
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid white;
}

/* --- ОКНО ЧАТА --- */
.chat-window {
    position: fixed;
    bottom: 110px;
    right: 30px; /* Окно оставляем справа, или тоже можно сдвинуть на 95px, если хотите */
    width: 380px;
    height: 600px;
    max-height: 80vh;
    background: #ffffff;
    border: 1px solid #eef2f6;
    border-radius: var(--radius-main);
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    opacity: 0;
    transform: translateY(20px) scale(0.98);
    pointer-events: none;
    transition: all 0.3s ease-in-out;
}

.chat-window.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* --- ХЕДЕР --- */
.chat-header {
    background: #ffffff;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f1f5f9;
}

.chat-header h3 {
    margin: 0;
    font-weight: 700;
    font-size: 18px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #f8fafc;
    color: var(--text-muted);
    cursor: pointer;
    transition: 0.2s;
    font-size: 16px;
}
.close-btn:hover {
    background: #fee2e2;
    color: var(--unread-red);
}

/* --- ВКЛАДКИ (TABS) --- */
.chat-tabs-wrapper {
    position: relative;
    background: #ffffff;
    padding: 10px 0;
    box-shadow: 0 4px 6px -4px rgba(0,0,0,0.05);
    z-index: 10;
}

.chat-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 0 45px;
    scroll-behavior: smooth;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.chat-tabs::-webkit-scrollbar { display: none; }

.chat-tab {
    position: relative;
    overflow: visible;  /* Важно, чтобы бейдж не обрезался */
    flex: 0 0 auto;
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13px;
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
}

.chat-tab:hover {
    background: #f8fafc;
    color: var(--secondary-color);
}

.chat-tab.active {
    background: linear-gradient(135deg, rgba(255, 140, 66, 0.1), rgba(123, 97, 255, 0.1));
    color: var(--secondary-color);
    border-color: rgba(123, 97, 255, 0.2);
}
.chat-tab i { margin-right: 6px; }

/* === ЦИФРОВОЙ БЕЙДЖ НА ВКЛАДКЕ === */
.tab-badge {
    position: absolute;
    top: -5px;      /* Поднимаем выше */
    right: -5px;    /* Сдвигаем правее */
    background: var(--unread-red);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 0 4px; /* Отступы для цифр */
    min-width: 18px;
    height: 18px;
    border-radius: 10px; /* Овальная форма */
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    border: 2px solid #ffffff; /* Белая обводка */
    z-index: 10;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

/* Кнопки скролла */
.scroll-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    background: #ffffff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 12px;
    z-index: 20;
    cursor: pointer;
    border: 1px solid #e2e8f0;
    transition: 0.2s;
}
.scroll-btn:hover {
    color: var(--secondary-color);
    border-color: var(--secondary-color);
}
#scroll-left { left: 10px; }
#scroll-right { right: 10px; }

/* --- ТЕЛО ЧАТА --- */
.chat-body {
    flex: 1;
    background: #fcfcfc;
    overflow-y: auto;
    padding: 20px;
    position: relative;
    display: flex;
    flex-direction: column;
}

.chat-sub-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    border-bottom: 2px solid #f1f5f9;
    color: var(--text-main);
    font-weight: 700;
    background: white;
}
.back-btn {
    color: var(--secondary-color);
    cursor: pointer;
    font-size: 13px;
    display: flex; align-items: center; gap: 5px;
    background: #f8fafc;
    padding: 6px 12px;
    border-radius: 8px;
    transition: 0.2s;
}
.back-btn:hover { background: #e0e7ff; }

/* --- СПИСОК КОНТАКТОВ --- */
.class-selector-list { display: flex; flex-direction: column; gap: 10px; }

.class-item-btn {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    transition: all 0.2s;
}

.class-item-btn:hover {
    border-color: var(--secondary-color);
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    transform: translateX(4px);
}

.item-icon {
    width: 44px; height: 44px;
    background: #f1f5f9;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    font-size: 18px;
}
.class-item-btn:hover .item-icon {
    background: var(--secondary-color);
    color: white;
}

.item-info { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.item-name { font-weight: 600; font-size: 15px; color: var(--text-main); }
.item-desc { font-size: 12px; color: var(--text-muted); }

/* === ЦИФРА НЕПРОЧИТАННЫХ ВНУТРИ СПИСКА === */
.unread-count {
    background: var(--unread-red);
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    padding: 0 6px;
    box-shadow: 0 2px 5px rgba(239, 68, 68, 0.4);
    margin-left: auto; /* Прижимает вправо */
}

/* --- СООБЩЕНИЯ --- */
.chat-messages-list { display: flex; flex-direction: column; gap: 16px; padding-bottom: 10px; }

.message {
    max-width: 80%;
    padding: 14px 18px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    animation: fadeIn 0.3s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.other-msg {
    align-self: flex-start;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    color: var(--text-main);
    border-radius: var(--radius-msg) var(--radius-msg) var(--radius-msg) 4px;
}

.my-msg {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-radius: var(--radius-msg) var(--radius-msg) 4px var(--radius-msg);
    box-shadow: 0 4px 10px rgba(123, 97, 255, 0.25);
    border: none;
}

.msg-author {
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--secondary-color);
    display: block;
}
.my-msg .msg-author { display: none; }

.msg-meta {
    font-size: 10px;
    opacity: 0.7;
    float: right;
    margin-top: 6px;
    margin-left: 10px;
}

/* --- TYPING --- */
.typing-indicator-container {
    padding: 0 15px 5px 15px;
    min-height: 20px;
    background: #ffffff;
    border-top: 1px solid transparent;
}
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #94a3b8;
    font-style: italic;
    animation: fadeIn 0.3s ease;
}
.typing-dots { display: flex; gap: 3px; }
.typing-dots span {
    width: 4px; height: 4px; background: #94a3b8; border-radius: 50%;
    animation: typingBlink 1.4s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBlink { 0% { opacity: 0.2; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.2); } 100% { opacity: 0.2; transform: scale(0.8); } }

/* --- ВВОД --- */
.chat-input-area {
    background: #ffffff;
    padding: 10px 15px 15px 15px;
    border-top: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    gap: 12px;
}

#chat-message-input {
    flex: 1;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 14px;
    color: var(--text-main);
    outline: none;
    transition: 0.2s;
}
#chat-message-input:focus {
    background: #ffffff;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(123, 97, 255, 0.1);
}

#chat-send-btn {
    width: 44px;
    height: 44px;
    background: var(--text-main);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: 0.2s;
}
#chat-send-btn:hover {
    background: var(--secondary-color);
    transform: scale(1.05);
}

.coming-soon {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}
.coming-soon i { font-size: 40px; margin-bottom: 10px; color: #cbd5e1; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 480px) {
    /* На мобильных окно чата на весь экран */
    .chat-window { width: 100%; height: 100%; bottom: 0; right: 0; border-radius: 0; max-height: 100vh; }
    
    /* ИЗМЕНЕНИЕ: Сдвигаем виджет влево и на мобильных */
    .chat-widget { 
        bottom: 20px; 
        right: 85px; 
    }
}

/* --- AI / BOT MESSAGES --- */
.message.bot-msg-fancy {
    background: linear-gradient(135deg, #f5faff, #f1edff); /* Очень легкий голубо-фиолетовый фон */
    border: 1px solid #e0daff; /* Легкая фиолетовая рамка */
    border-left: 4px solid var(--secondary-color); /* Акцентная полоса слева */
    border-radius: 6px 18px 18px 18px; /* Немного другая форма */
    padding: 0; /* Внутренние отступы регулируются в bot-bubble-content */
    overflow: hidden;
}

.bot-bubble-content {
    padding: 14px 18px;
}

.bot-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--secondary-color);
    margin-bottom: 8px;
    letter-spacing: 0.3px;
}

.bot-text {
    font-size: 14px;
    color: #334155;
    line-height: 1.6;
}