/* ═══════════════════════════════════════════════════════════
   CHAT VIEW — повне вікно чату
   ═══════════════════════════════════════════════════════════ */

/* Контейнер вікна чату (flex-column, займає весь chat-area) */
.chat-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* ─── Список повідомлень ─────────────────────────────────── */
.messages-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}
.messages-scroll::-webkit-scrollbar { width: 5px; }
.messages-scroll::-webkit-scrollbar-track { background: transparent; }
.messages-scroll::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }

/* Кнопка «завантажити ще» */
.load-more-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0 auto 12px;
    padding: 8px 20px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--sidebar-bg);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.load-more-btn:hover { background: var(--hover-bg); color: var(--text-main); }
.load-more-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Рядок повідомлення ─────────────────────────────────── */
.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 72%;
    position: relative;
}
.msg-row.own {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.msg-row.other {
    align-self: flex-start;
}

/* Групування: скорочуємо відступ між повідомленнями одного автора */
.msg-row + .msg-row.same-sender { margin-top: 2px; }
.msg-row + .msg-row.same-sender .msg-avatar { visibility: hidden; }

/* ─── Аватар ─────────────────────────────────────────────── */
.msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #4338ca);
    color: white;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.msg-row.own .msg-avatar {
    background: linear-gradient(135deg, var(--primary-color), #4338CA);
}

/* ─── Бульбашка ──────────────────────────────────────────── */
.msg-bubble-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 100%;
    position: relative; /* Необхідно для позиціонування inline меню */
}
.msg-row.own .msg-bubble-wrap { align-items: flex-end; }
.msg-row.other .msg-bubble-wrap { align-items: flex-start; }

.msg-sender-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
    padding: 0 6px;
    margin-bottom: 2px;
}

.msg-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
    transition: background 0.15s;
}

/* Своє повідомлення — синій градієнт */
.msg-row.own .msg-bubble {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Чуже повідомлення — підкладка */
.msg-row.other .msg-bubble {
    background: var(--sidebar-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

/* Hover → показуємо кнопки дій */
.msg-row:hover .msg-actions { opacity: 1; pointer-events: all; }

/* ─── Timestamp і мета ───────────────────────────────────── */
.msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 6px;
}
.msg-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
.msg-edited-badge {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

/* ─── Кнопки дій (edit/delete) ───────────────────────────── */
.msg-actions {
    position: absolute;
    top: -36px;
    opacity: 0;
    pointer-events: none;
    display: flex;
    gap: 4px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    transition: opacity 0.15s;
    z-index: 10;
}
.msg-row.own .msg-actions { right: 0; }
.msg-row.other .msg-actions { left: 42px; }

.msg-action-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.msg-action-btn:hover { background: var(--hover-bg); color: var(--text-main); }
.msg-action-btn.delete:hover { background: #FEF2F2; color: #EF4444; }
body.dark-theme .msg-action-btn.delete:hover { background: rgba(239,68,68,0.1); }

/* ─── Зображення у повідомленні ──────────────────────────── */
.msg-image {
    max-width: 400px;
    max-height: 400px;
    border-radius: 12px;
    object-fit: contain;
    cursor: pointer;
    display: block;
    transition: filter 0.2s;
    background-color: var(--hover-bg); /* Add background in case image has transparency */
}
.msg-image:hover { filter: brightness(0.95); }

/* Image light-box overlay */
.img-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    cursor: zoom-out;
    animation: fadeIn 0.2s ease;
}
.img-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}

/* ─── Системні повідомлення ──────────────────────────────── */
.msg-system {
    align-self: center;
    background: var(--hover-bg);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    padding: 4px 14px;
    border-radius: 20px;
    margin: 8px 0;
    border: 1px solid var(--border-color);
}

/* ─── Видалене повідомлення ──────────────────────────────── */
.msg-bubble.redacted {
    opacity: 0.45;
    font-style: italic;
}

/* ─── Typing indicator ───────────────────────────────────── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 24px 10px;
    min-height: 36px;
    color: var(--text-muted);
    font-size: 13px;
}
.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}
.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Панель введення ────────────────────────────────────── */
.chat-input-bar {
    display: flex;
    align-items: center; /* Вирівнювання всього вмісту ідеально по центру */
    gap: 10px;
    padding: 0 16px;
    height: 68px; /* Жорстко фіксуємо висоту, щоб лінія ідеально збігалася з лівим меню (де 12+44+12=68) */
    box-sizing: border-box;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
}

.input-attach-btn {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    background: var(--hover-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.input-attach-btn:hover { background: var(--border-color); color: var(--text-main); }

.input-wrapper {
    flex: 1;
    background: var(--hover-bg);
    border: 1.5px solid var(--border-color);
    border-radius: 20px;
    display: flex;
    align-items: center; /* Центруємо текст по вертикалі */
    padding: 0 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
    height: 40px; /* Зафіксована висота панелі вводу */
    box-sizing: border-box;
}
.input-wrapper:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
    background: var(--sidebar-bg);
}

/* Textarea */
.msg-textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-main);
    font-size: 14px;
    line-height: 20px;
    height: 20px; /* Суворо під висоту одного рядка */
    padding: 0;
    margin: 0;
    resize: none;
    outline: none;
    overflow-y: auto;
    font-family: inherit;
    display: block;
}
.msg-textarea::placeholder { color: var(--text-muted); line-height: 20px; }
.msg-textarea::-webkit-scrollbar { width: 4px; }

.send-btn {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(59,130,246,0.3);
}
.send-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(59,130,246,0.4); }
.send-btn:active { transform: translateY(0); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

/* ─── Банер редагування ──────────────────────────────────── */
.editing-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: rgba(59,130,246,0.08);
    border-top: 1px solid rgba(59,130,246,0.2);
    color: var(--text-main);
    font-size: 13px;
}
.editing-banner-label {
    font-weight: 600;
    color: #3b82f6;
    white-space: nowrap;
}
.editing-banner-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
}
.editing-cancel-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    transition: background 0.15s;
}
.editing-cancel-btn:hover { background: var(--hover-bg); }

/* ─── Завантаження / порожній стан ──────────────────────── */
.chat-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    flex-direction: column;
    gap: 12px;
    font-size: 14px;
}
.chat-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Контекстне меню (правок клік) ─── */
.custom-context-menu {
    position: fixed;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 1000;
    min-width: 150px;
    animation: scaleIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.custom-context-menu.inline-context {
    position: absolute;
    bottom: calc(100% + 5px); /* Зверху повідомлення */
    right: 0;
    top: auto;
    z-index: 10000;
}
.msg-row.other .custom-context-menu.inline-context {
    right: auto;
    left: 42px; /* Зсув від аватарки */
}
.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    color: var(--text-main);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}
.context-menu-item:hover { background: var(--hover-bg); }
.context-menu-item.danger { color: #EF4444; }
.context-menu-item.danger:hover { background: #FEF2F2; }
body.dark-theme .context-menu-item.danger:hover { background: rgba(239, 68, 68, 0.1); }
.context-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ─── Медіа запити ───────────────────────────────────────── */
@media (max-width: 768px) {
    .messages-scroll { padding: 12px 12px 8px; }
    .chat-input-bar { padding: 10px 12px 14px; }
    .msg-row { max-width: 88%; }
    .msg-image { max-width: 220px; }
}

.recording-ripple {
    animation: ripple 1.5s infinite;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
}
@keyframes ripple {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    100% {
        box-shadow: 0 0 0 15px rgba(239, 68, 68, 0);
    }
}

.custom-audio-player {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 6px 14px 6px 6px;
    width: 260px;
    color: inherit;
}

.custom-audio-player .play-btn {
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s, background 0.2s;
}
.custom-audio-player .play-btn:hover {
    transform: scale(1.05);
    background: #2563eb;
}
.msg-bubble.own .custom-audio-player .play-btn {
    background: white;
    color: #3b82f6;
}

.audio-waveform-container {
    flex-grow: 1;
    position: relative;
    height: 6px;
    border-radius: 3px;
    cursor: pointer;
    background: rgba(0,0,0,0.1);
    overflow: hidden;
}
.msg-bubble.own .audio-waveform-container {
    background: rgba(255,255,255,0.3);
}

.audio-waveform-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: #3b82f6;
    border-radius: 3px;
    pointer-events: none;
    transition: width 0.1s linear;
}
.msg-bubble.own .audio-waveform-fill {
    background: white;
}

.audio-time {
    font-size: 12px;
    font-weight: 500;
    min-width: 32px;
    text-align: right;
    opacity: 0.9;
}
