/* Dark Theme for Speech */

* {
    box-sizing: border-box;
}

body, html {
    height: 100vh; /* Use vh for full viewport height */
    margin: 0;
    font-family: 'Google Sans', sans-serif, system-ui;
    background-color: #36393f; /* Dark background */
    color: #dcddde; /* Light text */
    overflow: hidden; /* Prevent body scrolling */
}

.app-container {
    display: flex;
    height: 100%;
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: #2f3136;
}
::-webkit-scrollbar-thumb {
    background: #202225;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #1a1c1e;
}

/* --- Sidebar & Common --- */
.sidebar {
    width: 280px;
    background-color: #2f3136;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 18px 16px;
    font-weight: 500;
    font-size: 1.1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 2;
    flex-shrink: 0;
}

.search-container {
    padding: 10px 16px;
    position: relative;
}

#user-search {
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    background-color: #202225;
    color: #dcddde;
    font-size: 0.9rem;
    outline: none;
}

#search-results {
    position: absolute;
    background-color: #2f3136;
    width: calc(100% - 32px);
    border: 1px solid #202225;
    border-radius: 8px;
    top: 100%;
    left: 16px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.channel-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.channel-list h3, .dm-list h3 {
    padding: 8px 16px;
    margin: 0;
    font-size: 0.8rem;
    font-weight: 500;
    color: #8e9297;
    text-transform: uppercase;
}

.channel, .dm {
    display: flex;
    align-items: center;
    padding: 6px 16px;
    cursor: pointer;
    font-size: 0.95rem;
    color: #8e9297;
    border-radius: 4px;
    margin: 1px 8px;
}

.channel:hover, .dm:hover {
    background-color: #3a3c43;
    color: #dcddde;
}

.channel.active, .dm.active {
    background-color: #40444b;
    color: #fff;
    font-weight: 500;
}

.search-avatar, .chat-header-avatar, .user-avatar img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
    background-color: #36393f;
}

/* --- User Panel (Bottom Left) --- */
.user-panel {
    display: flex;
    align-items: center;
    padding: 8px;
    background-color: #292b2f;
    cursor: pointer;
    margin: 8px;
    border-radius: 6px;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.user-panel:hover {
    background-color: #3a3c43;
}

.user-panel .user-avatar img {
    width: 30px;
    height: 30px;
    margin-right: 10px;
}

.user-info .username {
    font-weight: 500;
    color: #fff;
    font-size: 0.9rem;
}

.user-info .status {
    font-size: 0.75rem;
    color: #b9bbbe;
}

/* --- Chat Area --- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-header {
    padding: 18px 24px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    font-size: 1.1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    z-index: 1;
    flex-shrink: 0;
}

.message-list {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.no-messages {
    text-align: center;
    padding: 40px;
    color: #72767d;
}

.no-messages h2 {
    margin: 0 0 8px 0;
    color: #fff;
}

/* --- Message Structure (FIXED) --- */
.message {
    display: flex;
    margin-top: 16px;
    position: relative;
}

.message-sender {
    width: 50px;
    margin-right: 12px;
    flex-shrink: 0;
}

.message-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
}

/* FIX: New container for bubble and username */
.message-body {
    display: flex;
    flex-direction: column;
    max-width: 80%; /* Controls the max width of a message */
}

.message-header {
    display: none; /* DM theme hides username by default */
}

.message-text {
    padding: 10px 60px 10px 16px;
    border-radius: 18px;
    background-color: #40444b;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;   /* Fix word breaking */
    word-break: break-word;  /* Fix word breaking */
}

.message.me {
    justify-content: flex-end;
}

.message.me .message-sender {
    display: none;
}

.message.me .message-body {
    align-items: flex-end;
}

.message.me .message-text {
    background-color: #4285F4;
    color: #fff;
}

.message-timestamp-in-bubble {
    position: absolute;
    bottom: 8px;
    right: 12px;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
}

.message.me .message-timestamp-in-bubble {
    color: rgba(255, 255, 255, 0.7);
}


/* --- Message Grouping --- */
.message.is-continuation {
    margin-top: 4px; /* Tighter spacing */
}

.message.is-continuation .message-sender {
    visibility: hidden; /* Hide avatar but keep the space */
}


/* --- Chat Input --- */
.chat-input {
    padding: 0 24px 24px 24px;
    flex-shrink: 0;
}

.message-input {
    display: flex;
    background-color: #40444b;
    border-radius: 8px;
    padding: 4px;
}

.message-input input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 18px;
    font-size: 1rem;
    outline: none;
    color: #dcddde;
}

/* Старый .icon-btn, будет заменен/дополнен */


/* --- Modals & Notifications --- */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200;
}

.call-modal {
    width: 280px;
    background-color: #2f3136;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    text-align: center;
}

.call-modal h3 {
    margin: 0 0 8px 0;
    font-size: 1.1rem;
    color: #fff;
}

.call-modal p {
    margin: 0 0 20px 0;
    color: #b9bbbe;
}

.modal-actions {
    display: flex;
    gap: 15px;
}

.modal-actions .btn {
    border: none;
    border-radius: 20px;
    padding: 8px 20px;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.modal-actions .btn:hover { opacity: 0.8; }
.btn-accept { background-color: #3ba55d; color: white; }
.btn-decline, .btn-cancel { background-color: #DB4437; color: white; }

/* --- НОВЫЕ СТИЛИ ДЛЯ МЕНЮ ЧАТА --- */
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.chat-settings-container {
    position: relative;
}

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 5px);
    background-color: #36393f; /* var(--background-secondary-alt) */
    border: 1px solid #202225; /* var(--background-tertiary) */
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    min-width: 220px;
    padding: 8px;
    z-index: 100;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 4px;
    cursor: pointer;
    color: #dcddde; /* var(--text-primary) */
    font-size: 14px;
    white-space: nowrap;
}

.dropdown-menu-item:hover {
    background-color: #40444b; /* var(--background-modifier-hover) */
}

.dropdown-menu-item.danger {
    color: #f04747;
}

.dropdown-menu-item.danger:hover {
    background-color: #f04747;
    color: #fff;
}

.dropdown-divider {
    height: 1px;
    background-color: #40444b; /* var(--background-modifier-accent) */
    margin: 8px 0;
}

.btn-icon {
    background: none;
    border: none;
    padding: 6px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b9bbbe;
}

.btn-icon:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.btn-icon img {
    width: 24px;
    height: 24px;
}

/* Оверлей блокировки */
.blocked-chat-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #36393f; /* var(--background-primary) */
    padding: 16px;
    text-align: center;
    border-top: 1px solid #2f3136; /* var(--background-tertiary) */
    z-index: 5;
}

.blocked-chat-overlay p {
    margin: 0 0 10px 0;
}

.blocked-chat-overlay .btn {
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    background-color: #4285F4;
    color: white;
}

/* --- Стили для кнопки смайликов --- */
#emoji-btn {
    font-size: 1.5rem; /* Увеличиваем размер самого символа смайлика */
    padding: 0 12px;   /* Добавляем отступы по бокам */
    border-radius: 6px;
    transition: background-color 0.2s ease; /* Плавный переход для наведения */
}

#emoji-btn:hover {
    background-color: #484c54; /* Немного светлее, чем фон поля ввода */
}

/* Скрываем стандартный синий контур при фокусе в Chrome */
#emoji-btn:focus {
    outline: none;
}

/* --- Twemoji Styling --- */
.message-text .emoji {
    height: 1.3em; /* Slightly larger than the text font size */
    width: 1.3em;
    margin: 0 .05em 0 .1em;
    vertical-align: -0.2em; /* Fine-tune vertical alignment */
    display: inline-block; /* Ensure it stays in the text flow */
}

/* --- Message Context Menu --- */
#message-context-menu {
    position: absolute; /* Needed for positioning near the message */
    z-index: 1050;      /* Needs to be on top of everything */
    width: auto;        /* Auto-width based on content */
    min-width: 180px;   /* A sensible minimum width */
    padding: 8px;
    background-color: #18191c; /* Darker background like other menus */
    border: 1px solid #000;
    border-radius: 8px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.24);
}

#message-context-menu .reaction-bar {
    display: flex;
    justify-content: space-around;
    padding: 4px 8px 8px;
}

#message-context-menu .reaction-bar .reaction {
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: transform 0.1s ease-out, background-color 0.2s;
}

#message-context-menu .reaction-bar .reaction:hover {
    transform: scale(1.2);
    background-color: #3a3c43;
}

/* --- Call Status & Ringing Styles --- */

/* Индикатор звонка в списке чатов */
.chat-item.ringing p {
    animation: text-pulse 1.5s infinite;
}

/* Системное сообщение о звонке в чате */
.system-message.call-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    margin: 12px auto;
    width: fit-content;
    font-size: 0.9em;
}

.dark-theme .system-message.call-status,
.aurora-theme .system-message.call-status {
    background-color: var(--background-modifier-accent);
    color: var(--text-muted);
}

.light-theme .system-message.call-status {
    background-color: #e9ecef;
    color: #495057;
}

.system-message.call-status img {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

/* Плашка входящего звонка в шапке чата */
#in-chat-call-notification {
    display: none; /* Скрыто по умолчанию */
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    width: 100%;
    animation: fade-in-down 0.3s ease-out;
}

.dark-theme #in-chat-call-notification,
.aurora-theme #in-chat-call-notification {
    background-color: var(--background-secondary-alt);
    border-bottom: 1px solid var(--background-tertiary);
}

.light-theme #in-chat-call-notification {
    background-color: #e0f2ff;
    border-bottom: 1px solid #bde0fe;
}

#in-chat-caller-name {
    font-weight: 600;
    animation: text-pulse 1.5s infinite;
}

.dark-theme #in-chat-caller-name,
.aurora-theme #in-chat-caller-name {
    color: var(--header-primary);
}

.light-theme #in-chat-caller-name {
    color: #0d47a1;
}

#in-chat-call-notification .actions {
    display: flex;
    gap: 10px;
}

/* Ключевая-анимация для мигания текста */
@keyframes text-pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

@keyframes fade-in-down {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
