/* ============================================================================
   БАЗОВЫЙ СТИЛЬ МЕССЕНДЖЕРА
   Тёмная тема, mobile-first, без фреймворков
   ============================================================================ */

/* ----------------------------------------------------------------------------
   Сброс
   ---------------------------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ----------------------------------------------------------------------------
   Базовые элементы
   ---------------------------------------------------------------------------- */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    color: #e0e0e0;
    background: #1a1a1a;
    max-width: 480px;
    margin: 0 auto;
    min-height: 100dvh;          /* dynamic viewport height — не прыгает на мобилках */
    display: flex;
    flex-direction: column;
}

input, button {
    font: inherit;
    padding: 10px 14px;
    border: 1px solid #333;
    border-radius: 8px;
    background: #2a2a2a;
    color: #e0e0e0;
    width: 100%;
    margin-bottom: 8px;
}

input:focus {
    outline: none;
    border-color: #4a9eff;
}

button {
    background: #333;
    cursor: pointer;
    font-weight: 600;
    width: auto;
}

button:active {
    background: #444;
}

h3 {
    font-size: 1.1em;
    margin: 16px 0 8px;
    color: #ccc;
}

/* ----------------------------------------------------------------------------
   Экраны (показываются/скрываются через JS)
   ---------------------------------------------------------------------------- */
.screen {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* ----------------------------------------------------------------------------
   Экран входа
   ---------------------------------------------------------------------------- */
#login-screen {
    padding: 24px 16px;
}

#login-screen h3 {
    margin-top: 24px;
}

#auth-result, #invite-result {
    font-size: 0.85em;
    margin-top: 8px;
    padding: 8px;
    background: #222;
    border-radius: 6px;
    word-break: break-all;
    white-space: pre-wrap;
}

/* ----------------------------------------------------------------------------
   Экран чатов
   ---------------------------------------------------------------------------- */
#chat-screen {
    padding: 0;
}

/* Верхняя панель */
#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: #1e1e1e;
    border-bottom: 1px solid #333;
    flex-wrap: wrap;
    gap: 6px;
}

#top-bar button {
    margin: 0;
    padding: 6px 12px;
    font-size: 0.85em;
    width: auto;
}

#my-name {
    font-weight: 600;
}

#my-role {
    font-size: 0.8em;
    color: #888;
    margin-left: 6px;
}

/* Блок приглашения (под верхней панелью) */
#invite-block {
    padding: 8px 16px;
    background: #1c1c1c;
    border-bottom: 1px solid #333;
}

/* Контейнер: список чатов + окно чата */
#chat-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Список чатов */
#chat-list {
    width: 35%;
    border-right: 1px solid #333;
    overflow-y: auto;
    background: #181818;
}

.chat-item {
    padding: 12px;
    border-bottom: 1px solid #222;
    cursor: pointer;
}

.chat-item:active {
    background: #222;
}

.chat-item.active {
    background: #2a2a2a;
    border-left: 3px solid #4a9eff;
}

.chat-item-title {
    font-size: 0.95em;
}

.chat-item-last {
    font-size: 0.8em;
    color: #888;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

/* Окно чата */
#chat-window {
    width: 65%;
    display: flex;
    flex-direction: column;
}

#current-chat-title {
    padding: 10px 12px;
    font-weight: 600;
    background: #1e1e1e;
    border-bottom: 1px solid #333;
    font-size: 0.95em;
}

/* Сообщения */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    word-break: break-word;
    font-size: 0.95em;
    position: relative;
}

.message.mine {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
}

.message.other {
    align-self: flex-start;
    background: #333;
}

.message.system {
    align-self: center;
    background: transparent;
    color: #666;
    font-size: 0.8em;
    font-style: italic;
    max-width: 100%;
    text-align: center;
    padding: 4px 8px;
}

.message-sender {
    font-size: 0.75em;
    color: #aaa;
    margin-bottom: 2px;
}

.message-time {
    font-size: 0.7em;
    color: #888;
    margin-top: 4px;
    text-align: right;
}

/* Форма отправки */
#send-form {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid #333;
    background: #1e1e1e;
}

#send-form input {
    flex: 1;
    margin: 0;
}

#send-form button {
    width: auto;
    margin: 0;
    padding: 10px 16px;
    background: #2563eb;
    border: none;
}

#send-form button:active {
    background: #1d4ed8;
}

/* Кнопки действий в чате */
#chat-actions {
    padding: 6px 12px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

#chat-actions button {
    font-size: 0.8em;
    padding: 6px 10px;
    margin: 0;
}

/* ----------------------------------------------------------------------------
   Утилиты
   ---------------------------------------------------------------------------- */
.text-small {
    font-size: 0.85em;
    color: #888;
}

.text-error {
    color: #f87171;
}