/* === MLP Evening: Chat Styles (Dark Glassmorphism Theme) === */

/* --- 1. Top Bar & User Menu --- */
.chat-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px; 
    background: rgba(30, 20, 50, 0.42);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    backdrop-filter: blur(5px);
    height: 60px;
}

/* User Menu in Chat Header */
.chat-user-menu {
    display: flex;
    align-items: center;
    flex: 1;
}

.user-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.profile-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #ce93d8;
    font-weight: bold;
    font-size: 0.95em;
    padding: 4px 12px 4px 4px;
    border-radius: 30px;
    transition: all 0.2s;
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.05);
}
.profile-link:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
    border-color: rgba(255,255,255,0.2);
    box-shadow: 0 0 15px rgba(206, 147, 216, 0.15);
}

.avatar-mini img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgba(255,255,255,0.2);
    vertical-align: middle;
    display: block;
}

.login-btn-chat {
    color: #fff;
    text-decoration: none;
    font-weight: bold;
    background: rgba(186, 104, 200, 0.2);
    padding: 8px 20px;
    border-radius: 20px;
    border: 1px solid rgba(186, 104, 200, 0.4);
    transition: all 0.2s;
    font-size: 0.9em;
}
.login-btn-chat:hover {
    background: rgba(186, 104, 200, 0.4);
    box-shadow: 0 0 10px rgba(186, 104, 200, 0.3);
    border-color: #e1bee7;
}

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

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
    color: #aaa;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}
.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}
.icon-btn.active {
    color: #ba68c8;
    background: rgba(186, 104, 200, 0.1);
}

.online-badge {
    background: rgba(0,0,0,0.3);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.85em;
    color: #aaa;
    margin-right: 5px;
    cursor: help;
    border: 1px solid rgba(255,255,255,0.05);
}

/* --- 2. Media (Images & Video) --- */
.chat-img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 6px;
    margin-top: 5px;
    cursor: zoom-in;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    transition: transform 0.2s;
    border: 1px solid rgba(255,255,255,0.05);
}
.chat-img:hover { transform: scale(1.02); }

.chat-link {
    color: #ba68c8;
    font-weight: bold;
    text-decoration: none;
    transition: color 0.2s;
}
.chat-link:hover {
    color: #e1bee7;
    text-decoration: underline;
}

.video-embed {
    position: relative;
    width: 100%;
    max-width: 350px;
    margin-top: 5px;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    background: #000;
}
.video-embed iframe { width: 100%; aspect-ratio: 16/9; border: none; }
.video-embed video { width: 100%; max-height: 300px; display: block; object-fit: contain; }

/* --- 3. Context Menu --- */
.chat-context-menu {
    position: absolute;
    z-index: 1000;
    background: #2b2b3b;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    border-radius: 6px;
    padding: 5px 0;
    min-width: 150px;
    color: #eee;
    backdrop-filter: blur(10px);
}
.chat-context-menu li {
    padding: 8px 15px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #eee;
}
.chat-context-menu li:hover { background-color: rgba(255, 255, 255, 0.1); }
.chat-context-menu li.danger { color: #ff8a80; }
.chat-context-menu li.danger:hover { background-color: rgba(244, 67, 54, 0.2); }
.chat-context-menu li.warning { color: #ffd54f; }
.chat-context-menu li.warning:hover { background-color: rgba(255, 193, 7, 0.2); }
.chat-context-menu .separator {
    height: 1px;
    background: rgba(255,255,255,0.1);
    margin: 5px 0;
    padding: 0;
}

/* --- 4. Markdown Styles --- */
.md-bold { font-weight: bold; color: #e1bee7; }
.md-italic { font-style: italic; }
.md-strike { text-decoration: line-through; opacity: 0.7; }
.md-code {
    font-family: monospace;
    background: rgba(0,0,0,0.3);
    padding: 2px 4px;
    border-radius: 3px;
    color: #f48fb1;
    font-size: 0.9em;
    border: 1px solid rgba(255,255,255,0.1);
}
.md-spoiler {
    background: #444;
    color: #444;
    padding: 0 2px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
}
.md-spoiler:hover, .md-spoiler.revealed { background: rgba(255,255,255,0.1); color: inherit; }
.md-mention {
    font-weight: bold;
    color: #ce93d8;
    background: rgba(156, 39, 176, 0.2);
    padding: 0 4px;
    border-radius: 4px;
    cursor: pointer;
}
.md-mention:hover { background: rgba(156, 39, 176, 0.4); text-decoration: underline; }
.md-quote {
    display: block;
    margin: 5px 0;
    padding: 5px 10px;
    border-left: 3px solid #7b1fa2;
    background: rgba(0,0,0,0.2);
    color: #aaa;
    font-style: italic;
    border-radius: 0 4px 4px 0;
}
.message-mentioned {
    background-color: rgba(255, 235, 59, 0.15);
    border-left: 3px solid #ffeb3b !important;
}
.message-mentioned:hover { background-color: rgba(255, 235, 59, 0.2); }

/* --- Mobile Compact Mode --- */
.chat-mobile-fab {
    display: none;
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7b1fa2, #4a148c);
    color: white;
    font-size: 24px;
    border: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    cursor: pointer;
    z-index: 90;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}
.chat-mobile-fab:active { transform: scale(0.95); }

.chat-mobile-input-box {
    background: #2b2b3b;
    width: 100%;
    padding: 15px;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.5);
    border-top: 1px solid rgba(255,255,255,0.1);
    animation: slideUp 0.2s ease-out;
    position: relative; /* Fix for absolute children (stickers) */
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.chat-mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    color: #ce93d8;
    font-weight: bold;
}
.chat-mobile-close {
    background: none;
    border: none;
    color: #aaa;
    font-size: 24px;
    padding: 0 10px;
    cursor: pointer;
}

#chat-mobile-input {
    width: 100%;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: white;
    padding: 10px;
    resize: none;
    font-family: inherit;
    margin-bottom: 10px;
}
.chat-mobile-actions {
    display: flex;
    justify-content: flex-end;
}

/* Responsive Trigger */
@media (max-width: 768px), (max-height: 500px) and (orientation: landscape) {
    .chat-input-area { display: none; } /* Hide standard input */
    .chat-mobile-fab { display: flex; } /* Show FAB */
    .chat-messages { padding-bottom: 80px; } /* Space for FAB */
}

.chat-input-area {
    padding: 15px;
    background: rgba(30, 20, 50, 0.4);
    border-top: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(5px);
    flex-shrink: 0; /* Не сжимать */
}

#chat-form { display: flex; gap: 10px; }
#chat-input {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.1);
    resize: none;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    background: rgba(0,0,0,0.3);
    color: #fff;
    transition: all 0.2s;
    max-height: 120px;
}
#chat-input:focus {
    border-color: rgba(186, 104, 200, 0.5);
    background: rgba(0,0,0,0.4);
    box-shadow: 0 0 15px rgba(186, 104, 200, 0.1);
}
#chat-form button {
    padding: 0 24px;
    background: linear-gradient(135deg, #7b1fa2, #4a148c);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
#chat-form button:hover {
    background: linear-gradient(135deg, #8e24aa, #6a1b9a);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.4);
}

.chat-login-prompt { text-align: center; color: #aaa; font-size: 0.9em; }
.chat-login-prompt a { color: #e1bee7; font-weight: bold; }

/* Toolbar */
.chat-toolbar {
    display: flex;
    gap: 5px;
    margin-bottom: 8px; /* Чуть больше отступ */
    align-items: center;
}
.chat-format-btn {
    background: transparent;
    border: 1px solid transparent;
    color: #aaa;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
    min-width: 28px;
}
.chat-format-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.toolbar-separator { width: 1px; height: 16px; background: rgba(255,255,255,0.1); margin: 0 5px; }

/* --- 6. Messages List (RESTORED STRUCTURE) --- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.chat-message {
    display: flex;
    align-items: flex-start; /* Avatar top alignment */
    padding: 5px 0;
    line-height: 1.4;
    transition: background 0.1s;
    border-radius: 8px;
    border-left: 3px solid transparent;
}

.chat-message:hover {
    background: rgba(255,255,255,0.03);
}

/* Avatar Wrapper */
.chat-avatar-wrapper {
    flex-shrink: 0;
    margin-right: 12px;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.1);
    transition: border-color 0.2s;
    cursor: pointer;
}
.chat-message:hover .chat-avatar {
    border-color: rgba(255,255,255,0.3);
}

/* Content Wrapper */
.chat-content {
    flex-grow: 1;
    min-width: 0; /* Fix flex overflow */
}

/* Header: User Info + Meta (Actions & Time) */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.username {
    font-family: 'Philosopher', sans-serif;
    font-weight: bold;
    font-size: 16px;
    color: #ce93d8; /* Dark theme purple */
    cursor: pointer;
    text-shadow: 0 0 10px rgba(255,255,255,0.1);
}
.username:hover { text-decoration: underline; }

/* Meta Info: Actions + Time */
.meta-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-actions {
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    gap: 5px;
}
.chat-message:hover .chat-actions { opacity: 1; }

.chat-action-btn {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 13px;
    padding: 0 2px;
    line-height: 1;
}
.chat-action-btn:hover { color: #fff; }
.chat-action-btn.delete-btn:hover { color: #ff5252; }
.chat-action-btn.restore-btn:hover { color: #69f0ae; }

.timestamp {
    font-family: 'Philosopher', sans-serif;
    font-size: 12px;
    color: #888;
}

.chat-text {
    font-family: 'Open Sans', sans-serif;
    font-size: 15px;
    color: #e0e0e0;
    word-wrap: break-word;
}

.edited-mark {
    font-size: 0.75em;
    color: #777;
    font-style: italic;
    margin-left: 6px;
    cursor: help;
}

.chat-welcome { text-align: center; color: #888; margin-top: 20px; font-style: italic; }

/* --- 7. Quoting & Stickers UI --- */
.quote-card {
    background: rgba(0,0,0,0.2);
    border-left: 3px solid #ba68c8;
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 0 6px 6px 0;
    font-size: 0.95em;
    cursor: pointer;
    transition: background 0.2s;
}
.quote-card:hover { background: rgba(255,255,255,0.05); }
.quote-header {
    display: flex;
    justify-content: space-between; /* Автор слева, кнопка справа */
    align-items: center; /* Выравнивание по центру */
    font-size: 0.85em;
    color: #aaa;
    margin-bottom: 4px;
}

.quote-author { 
    font-weight: bold; 
    color: #ce93d8; 
    margin-right: 10px; /* Отступ от кнопки, если имя длинное */
}

.quote-link-btn { 
    background: none; 
    border: none; 
    color: #aaa; 
    cursor: pointer; 
    font-size: 1.1em; 
    line-height: 1; 
    padding: 2px; /* Чуть увеличим область клика */
    text-decoration: none !important; /* Убираем полоску */
    display: inline-flex;
    align-items: center;
    opacity: 0.7;
    transition: opacity 0.2s, color 0.2s;
}

.quote-link-btn:hover { 
    color: #fff; 
    opacity: 1;
}
.quote-content { color: #ddd; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

#quote-preview-area {
    padding: 8px 15px;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    display: flex;
    flex-direction: column;
    gap: 8px; /* Разделяем блоки цитат */
}

.quote-preview-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(186, 104, 200, 0.15); /* Легкий фиолетовый оттенок */
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid rgba(186, 104, 200, 0.3); /* Тонкая рамка в тон */
    font-size: 0.9em;
    color: #eee;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.quote-preview-remove { background: none; border: none; color: #aaa; cursor: pointer; font-size: 18px; margin-left: 10px; }
.quote-preview-remove:hover { color: #ff8a80; }

@keyframes highlightFade {
    0% { background-color: rgba(186, 104, 200, 0.4); }
    100% { background-color: transparent; }
}
.message-highlight { animation: highlightFade 2s ease-out; }

.chat-sticker {
    max-width: 250px; /* Увеличили ширину для горизонтальных стикеров */
    max-height: 128px; /* Высоту держим, чтобы лента не рвалась */
    width: auto;
    height: auto;
    display: block;
    margin-top: 5px;
    cursor: pointer;
    /* transition: transform 0.1s; - убираем транзишн трансформации, раз мы ее отключаем */
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
    transition: filter 0.2s; /* Оставим плавность для тени, если захотим менять */
}
/* .chat-sticker:hover { transform: scale(1.05); } - УБРАЛИ увеличение */
.chat-sticker:hover {
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5)); /* Просто чуть усилим тень вместо зума */
}

.sticker-picker {
    height: 250px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    background: #2b2b3b;
    position: absolute;
    bottom: 100%;
    left: 0;
    width: 100%;
    z-index: 50;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.5);
    border-radius: 6px 6px 0 0;
    border: 1px solid rgba(255,255,255,0.15);
}

/* Mobile Picker Override (Inside Mobile Box) */
.chat-mobile-input-box .sticker-picker {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%; /* Cover input area */
    border-radius: 16px 16px 0 0;
    border-top: none;
    z-index: 100;
}

.sticker-close-btn {
    display: none; /* Hidden on desktop */
}
.chat-mobile-input-box .sticker-close-btn {
    display: block;
    background: none;
    border: none;
    color: #aaa;
    font-size: 24px;
    padding: 0 15px;
    cursor: pointer;
    margin-left: auto;
}
.sticker-tabs {
    display: flex;
    overflow-x: auto;
    background: rgba(0,0,0,0.2);
    padding: 5px;
    gap: 5px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    scrollbar-width: thin;
    scrollbar-color: #666 transparent;
}
.sticker-tab-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: background 0.2s;
    flex-shrink: 0;
}
.sticker-tab-btn img { width: 24px; height: 24px; display: block; }
.sticker-tab-btn:hover { background: rgba(255,255,255,0.1); }
.sticker-tab-btn.active { background: rgba(255,255,255,0.15); box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.sticker-grid {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 10px;
    align-content: start;
    scrollbar-color: #666 #2b2b3b;
}
.picker-sticker {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    cursor: pointer;
    transition: transform 0.1s;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
    user-select: none;
    -webkit-user-select: none; /* Safari */
    -webkit-touch-callout: none; /* iOS Safari - disable context menu/magnifier */
    -webkit-tap-highlight-color: transparent;
}
.picker-sticker:hover { transform: scale(1.1); }

/* Sticker Zoom Preview */
#sticker-zoom-preview {
    position: fixed; /* FIXED positioning relative to viewport */
    top: 50%; /* Center vertically */
    left: 50%;
    transform: translate(-50%, -50%);
    width: auto;           /* Авто ширина по контенту */
    height: auto;          /* Авто высота по контенту */
    background: rgba(43, 31, 67, 0.95); /* Темный фон, как у темы */
    border: 1px solid rgba(186, 104, 200, 0.8); /* Фиолетовая рамка */
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
    backdrop-filter: blur(15px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999; /* MAXIMUM Z-Index */
    pointer-events: none;
    padding: 15px; /* Отступ внутри рамки */
}

#sticker-zoom-preview img {
    display: block;
    width: auto;
    height: auto;
    min-width: 50px;       /* Чтобы совсем точки не были */
    max-width: 250px;      /* Как в чате (по просьбе) */
    max-height: 250px;     /* Ограничим высоту разумно, чтобы не перекрыл пол экрана */
    object-fit: contain;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* --- 8. Core Chat Layout --- */
.chat-container {
    display: flex;
    flex-direction: column;
    background: rgba(20, 15, 30, 0.42); 
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.6);
    overflow: hidden;
    height: 100%;
    position: relative;
    color: #eee;
}

.chat-notification {
    position: absolute;
    top: 10px;
    left: 15px;
    right: 15px;
    padding: 12px;
    border-radius: 8px;
    color: white;
    text-align: center;
    font-size: 14px;
    font-weight: bold;
    z-index: 100;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    display: none;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.1);
}
.chat-notification.success { background: rgba(76, 175, 80, 0.9); }
.chat-notification.error { background: rgba(244, 67, 54, 0.9); }

/* Overlays */
.chat-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    border-radius: 0;
}
.chat-confirm-box {
    background: #2b2b3b;
    padding: 25px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    max-width: 85%;
    border: 1px solid rgba(255,255,255,0.1);
    animation: popIn 0.2s ease-out;
    color: #eee;
}
.chat-confirm-box p { color: #eee; margin-bottom: 20px; }
@keyframes popIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.chat-confirm-buttons { display: flex; justify-content: center; gap: 10px; }
