/* ============================================================
   P2P Мессенджер — стили
   Вынесено из index.html в v77 (разрез файлов, шаг 1).
   Тема: светлая по умолчанию, тёмная через [data-theme="dark"].
   Переменные и переключение темы — client-main.js (initTheme).
   ============================================================ */

:root {
    --bg-color: #f9f9f9;
    --text-color: #000;
    --section-bg: #fff;
    --border-color: #ddd;
    --input-bg: #fff;
    --btn-bg: #e0e0e0;
    --btn-hover: #d0d0d0;

    --msg-their-bg: #fff;
    --msg-their-border: #eee;
    --chat-bg: #fafafa;
    --time-color: #999;
    --sys-bg: #f0f0f0;
    --sys-text: #666;
    --reply-bg: #e3f2fd;

    --msg-pending-bg: #e0e0e0;
    --msg-pending-text: #666;
    --msg-sent-bg: #fff3cd;
    --msg-sent-text: #856604;
    --msg-read-bg: #dcf8c6;
    --msg-read-text: #000;
}

[data-theme="dark"] {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --section-bg: #1e1e1e;
    --border-color: #333;
    --input-bg: #2d2d2d;
    --btn-bg: #333;
    --btn-hover: #444;

    --msg-their-bg: #202c33;
    --msg-their-border: #202c33;
    --chat-bg: #0b141a;
    --time-color: #888;
    --sys-bg: #182229;
    --sys-text: #888;
    --reply-bg: #2a3942;

    --msg-pending-bg: #2d2d2d;
    --msg-pending-text: #999;
    --msg-sent-bg: #4a3f1e;
    --msg-sent-text: #d4b35b;
    --msg-read-bg: #005c4b;
    --msg-read-text: #e0e0e0;
}

/* ---------- База ---------- */
body { font-family: system-ui, sans-serif; max-width: 800px; margin: 1rem auto; padding: 0 1rem; background: var(--bg-color); color: var(--text-color); transition: background 0.3s, color 0.3s; }
.section { background: var(--section-bg); border: 1px solid var(--border-color); padding: 1rem; margin-bottom: 1rem; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
input, button { padding: 0.5rem; margin: 0.25rem 0; border: 1px solid var(--border-color); border-radius: 4px; font-family: inherit; background: var(--input-bg); color: var(--text-color); }
button { cursor: pointer; background: var(--btn-bg); }
button:hover { background: var(--btn-hover); }

/* ---------- Табы ---------- */
.tabs { display: flex; margin-bottom: 1rem; }
.tab { flex: 1; padding: 0.5rem; text-align: center; cursor: pointer; border: 1px solid var(--border-color); background: var(--btn-bg); }
.tab.active { background: var(--section-bg); font-weight: bold; border-bottom: 2px solid #007bff; }

/* ---------- Видео звонка ---------- */
#videos { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; justify-content: center; }
video { flex: 1; min-width: 250px; max-width: 100%; aspect-ratio: 4 / 3; background: #222; border-radius: 8px; object-fit: cover; }
@media (max-width: 600px) { video { min-width: 100%; } }

/* ---------- Чат ---------- */
#chat-box { height: 250px; overflow-y: auto; border: 1px solid var(--border-color); padding: 0.5rem; margin: 0.5rem 0; background: var(--chat-bg); border-radius: 4px; }

.message { margin: 0.25rem 0; padding: 0.4rem 0.6rem; border-radius: 8px; display: inline-block; clear: both; max-width: 80%; word-wrap: break-word; }
.message.their { background: var(--msg-their-bg); border: 1px solid var(--msg-their-border); float: left; color: var(--text-color); }

.message.my { float: right; }
.message.my.pending { background: var(--msg-pending-bg); color: var(--msg-pending-text); }
.message.my.sent, .message.my.delivered { background: var(--msg-sent-bg); color: var(--msg-sent-text); }
.message.my.read { background: var(--msg-read-bg); color: var(--msg-read-text); }

.msg-time { display: block; font-size: 0.7em; color: var(--time-color); margin-top: 2px; text-align: right; }
.message.system { background: var(--sys-bg); color: var(--sys-text); font-size: 0.85em; text-align: center; display: block; float: none; clear: both; margin: 0.5rem auto; padding: 0.3rem 0.8rem; border-radius: 12px; max-width: fit-content; }

/* ---------- Друзья ---------- */
.friend-item { padding: 0.5rem; cursor: pointer; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.friend-item:hover { background: var(--btn-hover); }
.friend-item.active { background: var(--reply-bg); font-weight: bold; border-left: 4px solid #007bff; }

.hidden { display: none !important; }
/* Шапка чата — две строки: имя+крестик сверху, статус+действия снизу */
.status-bar {
    font-size: 0.9em;
    color: var(--sys-text);
    margin-bottom: 0.5rem;
    font-weight: bold;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.status-bar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.status-bar-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}

.status-bar-close {
    flex-shrink: 0;
    padding: 0.2rem 0.6rem;
    font-size: 0.95em;
    line-height: 1;
    margin: 0;
}

.status-bar-bottom {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-weight: normal;
}

#friend-status {
    font-size: 0.85em;
    color: gray;
    text-align: left;
    white-space: normal;
    word-break: break-word;
    flex: 1 1 120px;
    min-width: 0;
}

.status-bar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: auto;
}

.status-bar-actions label {
    font-size: 0.8em;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    white-space: nowrap;
}

.status-bar-actions button {
    margin: 0;
    white-space: nowrap;
}

.btn-danger { background: #ffcccc; border-color: #ff9999; color: #000; }
.btn-danger:hover { background: #ffb3b3; }
.btn-small { padding: 0.2rem 0.5rem; font-size: 0.8em; }

.unread-badge { background-color: #ff3b30; color: white; border-radius: 12px; padding: 2px 7px; font-size: 0.75em; font-weight: bold; margin-left: 8px; display: inline-block; }

/* ---------- Модалки ---------- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 9998; display: flex; justify-content: center; align-items: center; padding: 1rem; }
.modal-content { background: var(--section-bg); color: var(--text-color); padding: 1.5rem; border-radius: 12px; max-width: 400px; width: 100%; box-shadow: 0 10px 30px rgba(0,0,0,0.3); }
.modal-content h3 { margin-top: 0; margin-bottom: 1rem; }
.modal-content input[type="password"], .modal-content input[type="file"], .modal-content input[type="email"] { width: 100%; box-sizing: border-box; }
.modal-content label { display: block; margin: 0.75rem 0; }
.modal-buttons { display: flex; gap: 0.5rem; margin-top: 1rem; }
.modal-buttons button { flex: 1; }
.modal-error { color: #ff3b30; font-size: 0.9em; min-height: 1.2em; margin-top: 0.5rem; }

/* ---------- Emoji picker ---------- */
#emoji-picker {
    position: absolute;
    bottom: 50px;
    left: 0;
    background: var(--section-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 5px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
    max-height: 250px;
    max-width: 320px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 100;
}
#emoji-picker span {
    cursor: pointer;
    font-size: 1.4em;
    padding: 3px;
    text-align: center;
    border-radius: 4px;
    user-select: none;
}
#emoji-picker span:hover {
    background: var(--btn-hover);
}

/* ---------- Фото в чате ---------- */
.message img {
    max-width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    display: block;
    margin-top: 5px;
}

/* ---------- Полноэкранный просмотр фото ---------- */
#image-viewer-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.95);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}
#image-viewer-img {
    max-width: 90%;
    max-height: 80%;
    object-fit: contain;
    user-select: none;
}
.image-viewer-controls {
    position: absolute;
    bottom: 20px;
    display: flex;
    gap: 20px;
}
.image-viewer-controls button {
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 1em;
    cursor: pointer;
}
.image-viewer-controls button:hover {
    background: rgba(255,255,255,0.4);
}
.image-viewer-close {
    position: absolute;
    top: 20px; right: 20px;
    background: none;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
}
.image-viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    font-size: 3em;
    padding: 10px 20px;
    cursor: pointer;
    border-radius: 8px;
}
.image-viewer-nav:hover { background: rgba(255,255,255,0.4); }
.image-viewer-nav.prev { left: 20px; }
.image-viewer-nav.next { right: 20px; }

/* ---------- Аудио ---------- */
.message audio {
    max-width: 100%;
    margin-top: 5px;
    outline: none;
}
.recording {
    background-color: #ff3b30 !important;
    color: white !important;
    animation: pulse 1s infinite;
}

/* Чуть меньше внутренних отступов у медиа-сообщений */
.message.my:has(img), .message.their:has(img),
.message.my:has(audio), .message.their:has(audio) {
    padding: 4px;
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 60, 48, 0.7); }
    75% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(255, 60, 48, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 60, 48, 0); }
}

/* ---------- Меню настроек ---------- */
.settings-container { position: relative; display: inline-block; }
.settings-dropdown {
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--section-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    min-width: 280px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    padding: 5px 0;
    margin-top: 5px;
}
.settings-dropdown.hidden { display: none; }
.settings-item {
    padding: 10px 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-color);
    text-decoration: none;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    font-size: 0.95em;
}
.settings-item:hover { background: var(--btn-hover); }
.settings-item.danger { color: #ff3b30; }
.settings-divider { margin: 5px 0; border: 0; border-top: 1px solid var(--border-color); }

.settings-category {
    padding: 8px 15px 4px 15px;
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #999;
    font-weight: bold;
    cursor: default;
}

/* ---------- Файлы ---------- */
.progress-container {
    width: 100%;
    background-color: var(--btn-bg);
    border-radius: 10px;
    margin-top: 5px;
    overflow: hidden;
    height: 6px;
    display: none;
}
.progress-bar {
    width: 0%;
    height: 100%;
    background-color: #007bff;
    transition: width 0.2s;
}
.file-message {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,0.05);
    padding: 8px;
    border-radius: 6px;
    margin-top: 5px;
}
.file-icon { font-size: 1.5em; }
.file-info { flex: 1; overflow: hidden; }
.file-name { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.file-size { font-size: 0.8em; color: var(--time-color); }
.file-download-btn {
    background: #007bff;
    color: white;
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.8em;
    cursor: pointer;
    border: none;
}

.message { position: relative; }

/* ---------- Статусы (в списке друзей) ---------- */
.friend-login { font-weight: 500; }
.friend-status,
.friend-status-placeholder {
    font-size: 0.8em;
    color: #888;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.friend-status-placeholder { opacity: 0.7; }

/* Сетка эмодзи в модалке статуса */
#status-emoji-grid button {
    font-size: 1.2em;
    padding: 4px 8px;
    background: var(--btn-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    line-height: 1;
}
#status-emoji-grid button:hover { background: var(--btn-hover); }
#status-emoji-grid button.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

/* Свой статус в шапке */
.my-status-inline {
    font-size: 0.8em;
    color: #888;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: none;
}
.my-status-inline.visible { display: inline-block; }

/* Статус друга в списке — inline с обрезкой */
.friend-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.friend-login {
    font-weight: 500;
    flex-shrink: 0;
}
.friend-status-inline {
    font-size: 0.85em;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* ---------- Поиск по сообщениям ---------- */
.search-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.search-bar input {
    flex: 1;
    margin: 0;
}
.search-bar button {
    margin: 0;
    padding: 0.4rem 0.7rem;
}
.message.search-hidden { display: none !important; }
mark.search-highlight {
    background: #ffe066;
    color: #000;
    padding: 0 2px;
    border-radius: 2px;
}
[data-theme="dark"] mark.search-highlight {
    background: #b8860b;
    color: #fff;
}

/* ---------- Реакции ---------- */
.message-reactions {
    clear: both;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
    max-width: 100%;
}
.message-reactions:empty { display: none; }

.reaction-chip {
    font-size: 0.8em;
    padding: 1px 6px;
    border-radius: 10px;
    background: rgba(0,0,0,0.06);
    border: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    color: var(--text-color);
    white-space: nowrap;
}
.reaction-chip:hover { background: rgba(0,0,0,0.12); }
.reaction-chip.active {
    background: #cfe8ff;
    border-color: #007bff;
}
[data-theme="dark"] .reaction-chip { background: rgba(255,255,255,0.08); }
[data-theme="dark"] .reaction-chip:hover { background: rgba(255,255,255,0.16); }
[data-theme="dark"] .reaction-chip.active {
    background: #1a4d80;
    border-color: #4a9eff;
}

/* Панель выбора реакции */
#reaction-picker {
    position: fixed;
    z-index: 11000;
    background: var(--section-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 4px 8px;
    display: flex;
    gap: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
#reaction-picker.hidden { display: none; }
#reaction-picker button {
    background: none;
    border: none;
    font-size: 1.4em;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    line-height: 1;
    margin: 0;
    transition: transform 0.1s;
}
#reaction-picker button:hover { transform: scale(1.2); }

/* ---------- Плашка «Редактирование» ---------- */
.edit-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff3cd;
    color: #856604;
    border: 1px solid #ffc107;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.85em;
}
.edit-banner .edit-banner-text { flex: 1; }
.edit-banner button {
    margin: 0;
    padding: 2px 8px;
    background: transparent;
    border: 1px solid #856604;
    color: #856604;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95em;
}
.edit-banner button:hover { background: rgba(133, 100, 4, 0.1); }
[data-theme="dark"] .edit-banner {
    background: #4a3f1e;
    color: #e0c97a;
    border-color: #8a6d1e;
}
[data-theme="dark"] .edit-banner button {
    border-color: #e0c97a;
    color: #e0c97a;
}

/* ---------- Плашка «Ответ» ---------- */
.reply-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--reply-bg);
    color: var(--text-color);
    border-left: 3px solid #007bff;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.85em;
}
.reply-banner-label { font-weight: bold; color: #007bff; flex-shrink: 0; }
.reply-banner-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-banner button {
    margin: 0;
    padding: 2px 8px;
    background: transparent;
    border: 1px solid #007bff;
    color: #007bff;
    border-radius: 4px;
    cursor: pointer;
}

/* Цитата внутри сообщения */
.reply-quote {
    border-left: 3px solid #007bff;
    padding: 4px 8px;
    margin-bottom: 6px;
    background: rgba(0,123,255,0.08);
    border-radius: 4px;
    font-size: 0.85em;
    color: var(--text-color);
    opacity: 0.9;
    max-width: 100%;
    overflow: hidden;
}
.reply-quote b { color: #007bff; }

/* ===== Hover-кнопки сообщений — единый бар ===== */
.msg-actions {
    position: absolute;
    top: -26px;
    z-index: 5;
    display: none;
    gap: 1px;
    padding: 2px;
    background: var(--section-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    align-items: center;
    white-space: nowrap;
}
.message.my .msg-actions { right: 0; flex-direction: row-reverse; }
.message.their .msg-actions { left: 0; }

.message.my:hover .msg-actions,
.message.their:hover .msg-actions {
    display: flex;
}

.msg-actions button {
    position: static;
    display: flex;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-color);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    margin: 0;
    transition: background 0.15s, transform 0.1s;
}
.msg-actions button:hover {
    background: var(--btn-hover);
    transform: scale(1.12);
}
.msg-actions .msg-delete-btn { color: #ff3b30; }
.msg-actions .msg-delete-btn:hover { background: rgba(255, 59, 48, 0.15); }

/* Кнопка повтора отправки для pending-медиа */
.msg-retry-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #ff3b30;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 10;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: transform 0.15s;
}
.msg-retry-btn:hover {
    background: #e02818;
    transform: scale(1.15);
}
/* Визуально отмечаем pending медиа, чтобы было видно, что оно не ушло */
.message.my.pending img,
.message.my.pending audio {
    opacity: 0.7;
    outline: 2px solid #ff3b30;
    outline-offset: 2px;
    border-radius: 4px;
}
.message.my.pending .file-message {
    outline: 2px solid #ff3b30;
    outline-offset: 2px;
}

/* ---------- Групповой чат ---------- */
.group-sender-name {
    font-size: 0.75em;
    color: #007bff;
    font-weight: 600;
    margin-bottom: 3px;
    display: block;
}
[data-theme="dark"] .group-sender-name {
    color: #4a9eff;
}

/* Бейдж прочитанности в группе */
.msg-read-badge {
    font-size: 0.85em;
    margin-left: 3px;
}
.msg-read-badge.sent {
    color: var(--time-color);
}
.msg-read-badge.delivered {
    color: var(--time-color);
}
.msg-read-badge.read {
    color: #007bff;
}