:root {
    --chat-bg: #f9f9fb;
    --chat-border: #e0e0e0;
    --chat-hover: #eef1f5;
    --chat-primary: #5c6bc0;
    --chat-secondary: #ffffff;
    --chat-text: #2d2d2d;
    --chat-timestamp: #999999;
    --chat-error: #e57373;
    --chat-success: #81c784;
    --text-color: #333;
    --background: #ffffff;
    --border-color: #e0e0e0;
}

/* Контейнер чата (сделаем его плавно анимированным) */
#chat-container {
	    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
	    top: auto;
    left: auto;
    width: 420px; /* или нужная ширина */
    min-height: 0;
}

/* Когда чат открыт */
#chat-container.open {
    width: 370px; /* Ширина раскрытого чата */
    height: auto; /* Высота меняется в зависимости от содержимого */
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
    background: var(--chat-secondary);
    transition: all 0.3s ease;
}

#chat-unread-badge,
.chat-unread-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    background: #ff4757;
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    position: absolute;
    top: 6px;
    right: 12px;
    z-index: 2;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    pointer-events: none;
}

/* Для chat-toggle badge */
#chat-toggle #chat-unread-badge {
    top: -8px;
    right: -8px;
    min-width: 22px;
    height: 22px;
    font-size: 13px;
    border-radius: 12px;
}
/* Внутренний контейнер чата */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

/* Окно сообщений */
.chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 420px;
    height: 600px;
    background: white;
    border-radius: 18px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
       opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1002;
}

/* Состояния видимости */
.chat-widget.chat-open .chat-toggle {
    display: none;
}

/* Показываем окно чата только если открыт класс .chat-open */
.chat-widget.chat-open .chat-window {
    display: flex;
	opacity: 1;
}

/* При открытом чате скрываем toggle полностью */
.chat-widget.chat-open {
    pointer-events: auto;
}

/* Заголовок чата */
.chat-header {
    padding: 15px 20px;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 18px;
    font-weight: 500;
}

.chat-header .close-chat {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    transition: transform 0.3s ease;
}

.chat-header .close-chat:hover {
    transform: rotate(90deg);
}

/* Список чатов */
.chat-body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

.chat-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 10px;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 8px;
    background: #f8f9fa;
}

.chat-item:hover {
    background: #e9ecef;
    transform: translateX(5px);
}

.chat-item img {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
    border: 2px solid #e3e3e3;
}

.chat-info {
    flex: 1;
    overflow: hidden;
}

.chat-name {
    display: block;
    font-weight: 500;
    color: #2c3e50;
    margin-bottom: 3px;
}

.last-message {
    display: block;
    font-size: 0.85em;
    color: #7f8c8d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Сообщения */
.chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow-y: auto;
    padding: 15px;
    background: var(--chat-bg);
    padding-bottom: 60px; /* Добавлено: чтобы последнее сообщение не перекрывалось input */
}

.message {
    padding: 10px 14px;
    border-radius: 12px;
    margin-bottom: 10px;
    max-width: 50%;
    font-size: 14px;
    position: relative;
    word-break: break-word;
}

.message.own {
    background: var(--chat-primary);
    color: white;
    margin-left: auto;
}

.message:not(.own) {
    background: #e8eaf6;
    color: var(--chat-text);
}

/* Message types */
.message.image .message-image {
    max-width: 200px;
    border-radius: 8px;
    cursor: pointer;
}

.message.file .message-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
}

.message.file .message-file i {
    color: #666;
}

.message.file .message-file a {
    color: #3498db;
    text-decoration: none;
}

.message.file .message-file a:hover {
    text-decoration: underline;
}

/* Message meta info */
.message-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #999;
}

.message .edited {
    font-style: italic;
}

.message .fa-check,
.message .fa-check-double {
    font-size: 12px;
}

.message .fa-check.sent {
    color: #bbb;
}

.message .fa-check-double.read {
    color: #3498db;
}

.timestamp {
    font-size: 11px;
    color: var(--chat-timestamp);
    position: absolute;
    bottom: 6px;
    right: 12px;
}

.message.selected {
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.6);
    background: #eef6ff;
}

.message.own.selected {
    background: #dfe9ff;
}
/* Ввод сообщения */
.chat-input {
    padding: 15px;
    border-top: 1px solid #eee;
    display: flex;
    flex-direction: column; /* ← СОГЛАСНО! */
    gap: 10px;
    background: #f8f9fa;
}
.chat-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-input-row input {
    flex: 1; /* чтобы инпут занимал всё доступное, а кнопка не переносилась */
}
.chat-input input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    outline: none;
    transition: border-color 0.3s ease;
}

.chat-input input:focus {
    border-color: #3498db;
}

.send-message {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

.send-message:hover {
    transform: scale(1.1);
    background: linear-gradient(135deg, #2980b9, #2c3e50);
}

/* Прогресс-бар */
#progress-bar {
    display: none;
    height: 6px;
    background: var(--chat-border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 10px;
}

#progress-bar .progress {
    height: 100%;
    background: var(--chat-primary);
    width: 0;
    transition: width 0.3s;
}

/* Анимации */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scrollbar styling */
.chat-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

/* Состояния чата */
.chat-widget.open .chat-toggle {
    display: none;
}

.chat-widget.open .chat-window {
    display: flex;
}

/* Адаптивность */
@media (max-width: 1024px) {
    .chat-window {
        width: 600px;
        height: 900px;
    }
    .chat-header {
        padding: 38px 60px;
        font-size: 36px;
    }
    .chat-list {
        padding: 36px;
    }
    .chat-item {
        padding: 36px;
        margin-bottom: 28px;
    }
    .chat-item img,
    .chat-avatar {
        width: 110px;
        height: 110px;
        border-radius: 50%;
    }
    .chat-info {
        font-size: 32px;
    }
    .chat-name {
        font-size: 36px;
    }
    .last-message {
        font-size: 1em;
    }
    .chat-messages {
        font-size: 32px;
    }
    .message {
        margin-bottom: 32px;
        max-width: 90%;
        font-size: 32px;
    }
    .message.image .message-image {
        max-width: 520px;
        border-radius: 28px;
    }
    .message.file .message-file {
        gap: 28px;
        padding: 28px;
        border-radius: 28px;
        font-size: 32px;
    }
    .message-meta,
    .timestamp {
        font-size: 28px;
    }
    .chat-input {
        padding: 38px;
        gap: 32px;
    }
    .chat-input input {
        border-radius: 48px;
        font-size: 32px;
    }
    .chat-options-btn {
        padding: 20px;
        font-size: 36px;
    }
    .chat-options-modal {
        padding: 60px;
        border-radius: 28px;
    }
    .chat-options-modal button {
        padding: 36px;
        font-size: 32px;
    }
    .chat-date-divider {
        font-size: 32px;
        padding: 16px 48px;
        border-radius: 32px;
        margin: 48px auto 32px auto;
    }
    .back-to-list-btn {
        font-size: 48px;
        margin-right: 40px;
        padding: 16px 36px 16px 0;
    }
}

@media (max-width: 768px) {
    .chat-widget.chat-open {
        position: fixed;
        z-index: 10001;
        width: 100vw;
        height: 100vh;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        box-sizing: border-box;
        background: transparent;
    }
    .chat-widget.chat-open .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        z-index: 10002;
        display: flex;
        background: #fff;
    }
    .chat-header {
        padding: 15px;
        font-size: 16px;
    }
    .chat-messages {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
    }
    .chat-input {
        padding: 10px;
    }
    .chat-item {
        padding: 8px;
        border-radius: 8px;
        margin-bottom: 6px;
        background: #f8f9fa;
        min-height: 0;
    }
    .chat-item img,
    .chat-avatar {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        margin-right: 8px;
        border-width: 1px;
    }
    .chat-info {
        font-size: 13px;
        min-width: 0;
    }
    .chat-name {
        font-size: 14px;
        margin-bottom: 2px;
    }
    .last-message {
        font-size: 12px;
    }
    .chat-options-btn {
        padding: 2px;
        font-size: 18px;
        margin-left: 4px;
    }
    .chat-item-content {
        padding: 4px;
        gap: 6px;
    }
}

@media (max-width: 480px) {
    .chat-input input {
        font-size: 14px;
    }

    .message {
        max-width: 85%;
        font-size: 14px;
    }

    .chat-item {
        padding: 5px;
        border-radius: 6px;
        margin-bottom: 4px;
    }
    .chat-item img,
    .chat-avatar {
        width: 28px !important;
        height: 28px !important;
        margin-right: 6px;
    }
    .chat-info {
        font-size: 11px;
    }
    .chat-name {
        font-size: 12px;
    }
    .last-message {
        font-size: 10px;
    }
    .chat-options-btn {
        font-size: 15px;
        padding: 1px;
        margin-left: 2px;
    }
    .chat-item-content {
        padding: 2px;
        gap: 4px;
    }
    .message-meta,
    .timestamp {
        font-size: 10px !important;
    }
    .timestamp {
        bottom: 2px;
        right: 4px;
    }

    .chat-input {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        z-index: 10003 !important;
        background: #f8f9fa !important;
        border-top: 1px solid #eee !important;
        box-sizing: border-box !important;
        padding: 6px !important;
        border-radius: 0 !important;
    }

    .chat-messages {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        /* height/max-height убраны для корректного flex */
    }
}

/* Плавающая кнопка для чата (когда он свернут) */
#floating-chat-icon {
    font-size: 30px;
    color: white;
    transition: transform 0.3s ease;
}

/* Стили для иконки в закрытом и открытом состоянии */
#chat-container.open #floating-chat-icon {
    font-size: 18px;
    transition: all 0.3s ease;
}

/* Скрытие кнопки при открытом чате */
#chat-container.open #floating-chat-icon {
    display: none;
}

/* Новые стили */
.chat-item-content {
    display: flex;
    align-items: center;
    padding: 10px;
    gap: 10px;
    width: 100%;
}

.chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-options-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    margin-left: auto;
}

.chat-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.chat-options-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px;
    border-radius: 8px;
    z-index: 101;
}

.chat-options-modal .modal-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-options-modal button {
    padding: 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.chat-options-modal .report-btn {
    background: #ff4444;
    color: white;
}

.chat-options-modal .delete-chat-btn {
    background: #666;
    color: white;
}

.chat-options-modal .close-modal-btn {
    background: #eee;
}
.chat-date-divider {
    display: block;
    text-align: center;
    margin: 18px auto 10px auto;
    color: #888;
    font-size: 13px;
    font-weight: 500;
    background: #f1f3f7;
    border-radius: 12px;
    padding: 4px 16px;
    width: fit-content;
}
.back-to-list-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    margin-right: 12px;
    cursor: pointer;
    padding: 4px 10px 4px 0;
    display: inline-flex;
    align-items: center;
    transition: background 0.2s, color 0.2s;
}
.back-to-list-btn:hover {
    color: #3498db;
    background: rgba(52, 152, 219, 0.08);
    border-radius: 50%;
}

@media (max-width: 480px) {
    .chat-options-modal {
        position: fixed;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: 92vw !important;
        max-width: 98vw !important;
        min-width: 0 !important;
        padding: 10px !important;
        border-radius: 12px !important;
        z-index: 101 !important;
        box-sizing: border-box;
    }
    .chat-options-modal .modal-content {
        gap: 6px;
    }
    .chat-options-modal button {
        font-size: 1em;
        padding: 10px 0;
    }
}

/* Message actions (options button, reply preview, deleted state) */
/* three-dots actions button inside a message */
.message-opts {
    position: absolute; /* place inside message box */
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.04);
    border: 0;
    color: #444;
    cursor: pointer;
    font-size: 14px;
    padding: 6px 8px;
    border-radius: 6px;
    display: none; /* shown on hover */
    z-index: 6;
}
.message:hover .message-opts { display: inline-flex; align-items:center; justify-content:center; }
/* Mobile: make the options visible as a small inline control (no hover) */
@media (max-width: 720px) {
    .message-opts { display: inline-flex; opacity: 0.9; }
}

.message.deleted {
    opacity: 0.7;
}
.message.deleted .message-content {
    color: #888;
}

/* reply/forward preview shown above the input (full-width, won't push the input sideways) */
#reply-preview {
    border: 1px solid #e6e9ee;
    background: #fbfbfd;
    width: 100%;
    box-sizing: border-box;
    display: none; /* hidden until used */
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
}

/* Inline snippet inside message when rendering forwarded/replied previews */
.message-meta-snippet {
    display: block;
    font-size: 13px;
    color: #444;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(0,0,0,0.03);
    margin-bottom: 8px;
    line-height: 1.3;
    border: 1px solid rgba(0,0,0,0.04);
}
.message .forward-preview {
    padding: 8px;
    border-radius: 8px;
    background: rgba(250,246,246,0.9);
    margin-bottom: 8px;
    border: 1px solid rgba(0,0,0,0.04);
    color: #222;
}
.message .reply-preview {
    padding: 8px;
    border-radius: 8px;
    background: rgba(244,246,249,0.95);
    margin-bottom: 8px;
    border: 1px solid rgba(0,0,0,0.04);
    color: #222;
}

.message .message-content {
    /* leave space for the top-right action button */
    padding-right: 44px;
}

#reply-preview[data-type="forward"]::before {
    content: 'Переслано';
    font-size: 12px;
    color: #667085;
    font-weight: 700;
    margin-right: 8px;
}

#reply-preview[data-type="reply"]::before {
    content: 'Ответ';
    font-size: 12px;
    color: #667085;
    font-weight: 700;
    margin-right: 8px;
}