:root {
    --green: #51cf66;
    --green-dark: #40b056;
    --bg: #f5f5f5;
    --panel: #fff;
    --text: #333;
    --muted: #888;
    --line: #e0e0e0;
    --shadow: 0 2px 10px rgba(0,0,0,.1);
    --radius: 12px;
    --bubble-radius: 16px;
}

* { box-sizing: border-box; }

.chat-room-page {
    min-height: calc(100vh - 180px);
    background: var(--bg);
    padding: 10px;
    display: flex;
    flex-direction: column;
}

.back-button-container { margin-bottom: 12px; }

.btn-back {
    display: inline-block;
    background: var(--panel);
    color: var(--text);
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: .2s;
    box-shadow: 0 2px 5px rgba(0,0,0,.08);
}
.btn-back:hover { background: var(--green); color: #fff; }

.chat-room-container {
    width: min(98%, 800px);
    margin: 0 auto;
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
}

.chat-room-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.chat-room-contact-info { display: flex; align-items: center; }

.contact-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--green);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    margin-right: 12px;
    overflow: hidden;
}
.contact-avatar img { width: 100%; height: 100%; object-fit: cover; }

.contact-details { flex: 1; position: relative; }
.contact-name { font-weight: 600; font-size: 16px; color: var(--text); }
.contact-status { font-size: 12px; color: #4CAF50; margin-top: 2px; }

.chat-room-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg);
}

.loading-messages, .no-messages {
    text-align: center;
    color: var(--muted);
    padding: 40px;
}

.message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}
.message.sent { align-items: flex-end; }
.message.received { align-items: flex-start; }

.message-bubble {
    position: relative;
    max-width: 75%;
    min-width: 80px;
    padding: 8px 12px 20px;
    border-radius: var(--bubble-radius);
    word-break: break-word;
}

.message.sent .message-bubble {
    background: var(--green);
    color: #fff;
    box-shadow: 0 2px 6px rgba(81,207,102,.25);
}
.message.received .message-bubble {
    background: #e9ecef;
    color: #212529;
}

.message-sender-name {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #daf4e4;
}
.message.received .message-sender-name { color: #868e96; }

.message-content { font-size: 14px; line-height: 1.4; }

.message-time {
    position: absolute;
    left: 10px;
    bottom: 3px;
    font-size: 10px;
}
.message.sent .message-time { color: rgba(255,255,255,.8); }
.message.received .message-time { color: #868e96; }

.checks {
    position: absolute;
    right: 10px;
    bottom: 3px;
    font-size: 11px;
}
.check-single::after { content: '✓'; }
.check-double::after { content: '✓✓'; font-weight: bold; }
.message.sent .checks { color: rgba(255,255,255,.8); }
.message.sent .checks.read { color: #fff; }

.chat-room-input {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 14px;
    border-top: 1px solid var(--line);
    background: var(--panel);
}

.input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.input-wrapper { flex: 1; }

.chat-room-input input[type="text"] {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
}
.chat-room-input input[type="text"]:focus { border-color: var(--green); }

.send-btn {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--green);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.send-btn:hover { background: var(--green-dark); }

.action-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
}
.action-buttons button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.action-buttons button:hover { background: #f0f0f0; }

.message-menu {
    position: fixed;
    min-width: 160px;
    max-width: 240px;
    z-index: 5000; /* Поверх всех панелей и сообщений */
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2), 0 2px 6px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    padding: 4px 0;
    border: 1px solid rgba(0, 0, 0, 0.08);
    animation: menuPopIn 0.15s ease-out;
}


@keyframes menuPopIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.menu-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #212529;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
}

.menu-item:hover {
    background: #f1f3f5;
}

.menu-item.delete {
    color: #e03131;
}

.menu-item.delete:hover {
    background: #fff5f5;
}

/*
.file-message { margin: 6px 0; }
.file-image { width: 100%; max-width: 240px; border-radius: 8px; cursor: pointer; display: block; }
.file-video { width: 100%; max-width: 240px; border-radius: 8px; }
.file-audio { width: 100%; max-width: 240px; height: 36px; }
*/

.file-message { 
    margin: 6px 0;
    display: flex;
    flex-direction: column;
}

.file-image { 
    width: 100%; 
    max-width: 240px; 
    border-radius: 8px; 
    cursor: pointer; 
    display: block; 
}

.file-video { 
    width: 100%; 
    max-width: 240px; 
    border-radius: 8px; 
}

.file-audio { 
    width: 100%; 
    max-width: 320px;
    min-width: 200px;
}

.file-audio audio {
    width: 100%;
    min-height: 40px;
}

.file-download {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f0f2f5;
    border-radius: 6px;
    color: #333;
    text-decoration: none;
    font-size: 13px;
}


.file-download {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f0f2f5;
    border-radius: 6px;
    color: #333;
    text-decoration: none;
    font-size: 13px;
}

.video-ring-player {
    position: relative;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    overflow: hidden;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.video-ring-video { width: 100%; height: 100%; object-fit: cover; }
.video-ring-playbtn {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
}

/* Модальные окна */
.modal, .image-fullscreen, .photo-modal, .stream-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal, .photo-modal, .stream-modal { background: rgba(0,0,0,.6); }
.image-fullscreen { background: rgba(0,0,0,.85); }

.photo-modal-content, .stream-modal-content {
    background: #fff;
    border-radius: 14px;
    width: min(90%, 480px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.photo-modal-header, .stream-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}
.photo-modal-header h3, .stream-modal-header h3 { margin: 0; font-size: 16px; }
.close-modal-btn, .stream-close-modal-btn, .fullscreen-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
}
.fullscreen-close { position: absolute; top: 16px; right: 16px; color: #fff; }

.photo-modal-body, .stream-modal-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.photo-modal-body video, .photo-modal-body img { max-width: 100%; max-height: 350px; border-radius: 8px; }
.stream-modal-body video { width: 240px; height: 240px; border-radius: 50%; object-fit: cover; background: #000; }

.photo-modal-footer, .stream-modal-footer {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    justify-content: center;
}
.photo-modal-footer button, .stream-modal-footer button {
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}
.btn-capture { background: var(--green); color: #fff; }
.btn-retake { background: #ffd43b; color: #333; }
.btn-send, .btn-send-video { background: #339af0; color: #fff; }
.btn-cancel, .btn-cancel-video { background: #f0f0f0; color: #666; }

/* Стили для модального окна пересылки */
.forward-modal-content {
    width: min(92%, 520px);
    max-height: 85vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
    display: flex;
    flex-direction: column;
}
.forward-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}
.forward-modal-header h3 { margin: 0; color: var(--text); font-size: 17px; }
.forward-preview {
    padding: 12px 18px;
    background: #f8f9fa;
    border-bottom: 1px solid var(--line);
}
.preview-label { margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 600; }
.preview-content {
    max-height: 90px;
    overflow-y: auto;
    padding: 9px 11px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    white-space: pre-wrap;
    word-break: break-word;
}
.forward-search { padding: 14px 18px 8px; }
.forward-search input {
    width: 100%;
    padding: 10px 13px;
    border: 1px solid #ced4da;
    border-radius: 9px;
    outline: none;
    font-size: 14px;
}
.forward-search input:focus { border-color: var(--green); }
.forward-contacts-list {
    max-height: 380px;
    overflow-y: auto;
    padding: 8px 18px 18px;
}
.forward-contact-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    margin-bottom: 7px;
    border: 1px solid var(--line);
    border-radius: 9px;
    cursor: pointer;
    transition: background .2s, border-color .2s;
}
.forward-contact-card:hover { background: #f3fff5; border-color: var(--green); }
.forward-contact-avatar {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--green);
    color: #fff;
    font-weight: 700;
}
.forward-contact-avatar img { width: 100%; height: 100%; object-fit: cover; }
.forward-contact-info { min-width: 0; }
.forward-contact-name { color: var(--text); font-size: 14px; font-weight: 600; }
.forward-contact-nickname { color: var(--muted); font-size: 12px; }
.loading-spinner { padding: 25px; color: var(--muted); text-align: center; }
.forward-error { padding: 20px; color: #d6336c; text-align: center; }

.chat-notification {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 4000;
    display: none;
}
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Разделитель по датам */
.chat-date-separator {
    text-align: center;
    margin: 16px 0 10px 0;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}
.chat-date-separator span {
    background: rgba(0, 0, 0, 0.15);
    color: #495057;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 12px;
    backdrop-filter: blur(4px);
}

/* Плашка пересланного сообщения */
.forwarded-header-badge {
    font-size: 11px;
    color: #666;
    font-style: italic;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.message.sent .forwarded-header-badge {
    color: rgba(255, 255, 255, 0.85);
}

.message-text-caption {
    margin-top: 4px;
    font-size: 14px;
    line-height: 1.35;
}

.contact-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    margin-top: 2px;
}
.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.status-indicator.online {
    background-color: #4CAF50;
    box-shadow: 0 0 6px #4CAF50;
}
.status-indicator.offline {
    background-color: #adb5bd;
}

/* Статус собеседника */
.contact-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    margin-top: 2px;
}

/* Круглый индикатор */
.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

/* Состояние: В СЕТИ */
.status-dot.online {
    background-color: #51cf66;
    box-shadow: 0 0 8px rgba(81, 207, 102, 0.8);
}
.status-text.online {
    color: #40c057;
    font-weight: 600;
}

/* Состояние: НЕ В СЕТИ */
.status-dot.offline {
    background-color: #adb5bd;
    box-shadow: none;
}
.status-text.offline {
    color: #868e96;
    font-weight: normal;
}

/* Плашка активного ответа над полем ввода */
.reply-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f1f3f5;
    border-left: 4px solid var(--green);
    padding: 6px 12px;
    border-radius: 6px;
    margin-bottom: 4px;
    animation: fadeIn .2s ease;
}
.reply-bar-content {
    flex: 1;
    overflow: hidden;
    padding-right: 8px;
}
.reply-bar-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--green-dark);
}
.reply-bar-text {
    font-size: 13px;
    color: #495057;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reply-bar-close {
    background: none;
    border: none;
    font-size: 16px;
    color: #868e96;
    cursor: pointer;
    padding: 0 4px;
}
.reply-bar-close:hover { color: #f03e3e; }

/* Цитата внутри пузыря сообщения */
.reply-quote {
    margin-bottom: 6px;
    padding: 6px 10px;
    border-left: 3px solid #2b8a3e;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}
.message.sent .reply-quote {
    border-left-color: #ffffff;
    background: rgba(255, 255, 255, 0.2);
}
.reply-quote:hover {
    background: rgba(0, 0, 0, 0.14);
}
.message.sent .reply-quote:hover {
    background: rgba(255, 255, 255, 0.3);
}
.reply-quote-author {
    font-size: 11px;
    font-weight: bold;
    color: #2b8a3e;
    margin-bottom: 2px;
}
.message.sent .reply-quote-author {
    color: #ffffff;
}
.reply-quote-content {
    font-size: 12px;
    color: #495057;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px;
}
.message.sent .reply-quote-content {
    color: rgba(255, 255, 255, 0.9);
}