/*
 * Schriftarten der Hauptseite (NICHT Django Admin, NICHT Special Elite).
 * Einzige Quelle: Open Sans (Text), Fraunces (Überschriften).
 * Admin verwendet eigene Schriftarten in /static/admin/css/ — sie werden nur auf /admin/-Seiten geladen.
 *
 * Шрифты подключаются <link> в <head> шаблонов — @import здесь был бы ВТОРЫМ
 * подключением того же URL (двойная загрузка + блокировка парсинга CSS).
 */

/* Einheitliche Schriftart für alle Sprachen (DE, RU usw.) und Geräte — ohne Wechsel bei Sprachänderung */
html,
html[lang],
html[lang="de"],
html[lang="ru"] {
    font-family: 'Open Sans', sans-serif !important;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Globale Schriftarten für alle Sprachen: Text — Open Sans, Überschriften — Fraunces */
*,
*::before,
*::after,
html[lang] *,
html[lang] *::before,
html[lang] *::after {
    font-family: 'Open Sans', sans-serif !important;
}

body {
    background: url("/static/img/paper-fibers.5f93b84dd8f8.png") repeat, var(--paper);
    font-family: 'Open Sans', sans-serif !important;
    color: var(--ink);
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.container, .auth-container {
    background: var(--card-bg);
    padding: 20px;
    border: 3px solid var(--sepia);
    border-radius: 10px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 30px;
}

.auth-container {
    max-width: 350px;
    width: 100%;
    /* main-content теперь width:100% (body — flex): карточка центрируется внутри main,
       иначе прижата влево */
    margin: 0 auto;
    text-align: center;
}

h1, h2, h3, h4, h5, h6,
html[lang] h1, html[lang] h2, html[lang] h3, html[lang] h4, html[lang] h5, html[lang] h6 {
    font-family: 'Fraunces', serif !important;
}

h1 {
    font-size: 28px;
    color: var(--sepia);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    margin-bottom: 15px;
}

.rules-container h1 {
    font-size: 20px;
    margin: 15px 0 10px;
}

h2 {
    font-size: 24px;
    color: var(--ink);
    border-bottom: 2px dashed var(--sepia);
    padding-bottom: 5px;
    margin-top: 20px;
}

.error {
    color: var(--sepia);
    font-size: 14px;
    margin: 10px 0;
}

.auth-form, .chat-create-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-form input[type="text"],
.auth-form input[type="password"],
.chat-create-form input[type="text"],
.chat-create-form select {
    background: var(--input-bg);
    border: 2px solid var(--sepia);
    padding: 8px;
    font-family: 'Open Sans', sans-serif !important;
    font-size: 14px;
    color: var(--ink);
    border-radius: 5px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chat-create-form input[readonly] {
    background: var(--surface-msg-other);
    cursor: not-allowed;
}

/* Auf mobilen Geräten wird oft die System-Schriftart eingesetzt — erzwinge eine einheitliche Schriftart */
input, select, textarea, button, a {
    font-family: 'Open Sans', sans-serif !important;
}

button, .auth-form button, .chat-create-form button {
    background: var(--sepia);
    color: var(--input-bg);
    border: none;
    padding: 10px;
    font-family: 'Open Sans', sans-serif !important;
    font-size: 16px;
    cursor: pointer;
    border-radius: 5px;
    transition: background 0.3s;
}

button:hover, .auth-form button:hover, .chat-create-form button:hover {
    background: var(--sepia-deep);
}

.exit-btn {
    position: fixed;
    top: 10px;
    right: 10px;
    background: var(--sepia);
    color: var(--input-bg);
    border: none;
    padding: 8px 16px;
    font-family: 'Open Sans', sans-serif !important;
    font-size: 14px;
    cursor: pointer;
    border-radius: 5px;
    transition: background 0.3s;
}

.exit-btn:hover {
    background: var(--sepia-deep);
}

#map {
    height: 400px;
    margin: 20px 0;
    border: 2px solid var(--sepia);
    border-radius: 5px;
}

.chat-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.chat-list li {
    padding: 10px;
    border-bottom: 1px dashed var(--sepia);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-list li a {
    color: var(--ink);
    text-decoration: none;
    font-size: 16px;
}

.chat-list li a:hover {
    color: var(--sepia);
}

.user-count {
    background: var(--sepia);
    color: var(--input-bg);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
}

.search-container {
    margin: 10px 0;
}

#chat-search {
    width: 100%;
    background: var(--input-bg);
    border: 2px solid var(--sepia);
    padding: 8px;
    font-family: 'Open Sans', sans-serif !important;
    font-size: 14px;
    color: var(--ink);
    border-radius: 5px;
}

#messages {
    max-height: 400px;
    overflow-y: auto;
    margin: 20px 0;
    padding: 10px;
    background: var(--surface-soft);
    border: 2px solid var(--sepia);
    border-radius: 5px;
}

/* Предупреждение о скором автоудалении чата */
.chat-deletion-warning {
    margin: 12px 0;
    padding: 8px 12px;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 5px;
    color: #856404;
    font-size: 14px;
}

.chat-deletion-warning .btn-sm {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 10px;
    font-size: 13px;
    line-height: 1.6;
}

.message {
    margin-bottom: 10px;
    padding: 8px;
    border-radius: 5px;
    color: var(--ink);
}

.message.mine {
    background: var(--surface-msg-mine);
    margin-left: 20%;
    text-align: right;
}

.message.other {
    background: var(--surface-msg-other);
    margin-right: 20%;
}

.message .timestamp {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* Имя отправителя + кнопки звонка/видео. При длинном имени оно переносится,
   кнопки не наезжают на текст (flex-wrap + flex-shrink:0 у кнопок) */
.message-author-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    max-width: 100%;
    vertical-align: middle;
}
.message-author-name {
    overflow-wrap: anywhere;
    word-break: break-word;
}
.author-call-btn,
.author-video-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--sepia);
    border-radius: 50%;
    background: var(--input-bg);
    color: var(--sepia);
    cursor: pointer;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}
.author-call-btn:hover,
.author-video-btn:hover {
    background: var(--sepia);
    color: var(--input-bg);
}

#message-input {
    width: calc(100% - 110px);
    background: var(--input-bg);
    border: 2px solid var(--sepia);
    padding: 8px;
    font-family: 'Open Sans', sans-serif !important;
    font-size: 14px;
    color: var(--ink);
    border-radius: 5px;
    margin-right: 10px;
}

#file-input {
    margin: 10px 0;
}

#voice-chat-controls {
    margin: 10px 0;
}

#voice-participants {
    margin-top: 10px;
}

#voice-select-participants {
    margin-top: 5px;
}

#voice-select-participants label {
    display: block;
    margin: 5px 0;
}

#location-controls {
    margin: 10px 0;
}

#location-controls button {
    margin-right: 10px;
}

.rules-container {
    margin: 15px 0;
    padding: 10px;
    background: var(--surface-soft);
    border: 2px solid var(--sepia);
    border-radius: 5px;
}

.rules-container ul {
    list-style-type: disc;
    padding-left: 20px;
    margin: 10px 0;
}

.rules-container li {
    margin-bottom: 5px;
}

.rules-agreement {
    margin-top: 10px;
    font-size: 14px;
}


/* ========== Responsive: Mobil und Tablets ========== */
* {
    box-sizing: border-box;
}

/* Tablets und schmale Bildschirme */
@media screen and (max-width: 768px) {
    body {
        padding: 10px;
        min-height: 100vh;
    }
    .container {
        max-width: 100%;
        padding: 15px 12px;
        border-width: 2px;
    }
    .auth-container {
        max-width: 100%;
        padding: 15px 12px;
    }
    h1 {
        font-size: 22px;
    }
    h2 {
        font-size: 20px;
    }
    button, .auth-form button, .chat-create-form button {
        padding: 10px 14px;
        font-size: 14px;
    }
    .exit-btn {
        padding: 8px 12px;
        font-size: 13px;
        top: 8px;
        right: 8px;
    }
    #message-input {
        width: calc(100% - 90px);
    }
    #messages {
        max-height: 50vh;
    }
    .message.mine {
        margin-left: 10%;
    }
    .message.other {
        margin-right: 10%;
    }
}

/* Telefone (Porträt) */
@media screen and (max-width: 576px) {
    body {
        padding: 8px;
    }
    .container, .auth-container {
        padding: 12px 10px;
        border-radius: 8px;
    }
    h1 {
        font-size: 20px;
    }
    h2 {
        font-size: 18px;
    }
    button, .auth-form button, .chat-create-form button {
        padding: 10px 12px;
        font-size: 13px;
    }
    .auth-form input[type="text"],
    .auth-form input[type="password"],
    .chat-create-form input[type="text"],
    .chat-create-form select,
    #chat-search,
    #message-input {
        padding: 8px 10px;
        font-size: 16px; /* verhindert Zoom auf iOS */
    }
    .exit-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
    .chat-list li {
        flex-wrap: wrap;
        padding: 8px;
    }
}

/* Kleine Telefone */
@media screen and (max-width: 480px) {
    body {
        padding: 6px;
    }
    .container, .auth-container {
        padding: 10px 8px;
        border-width: 2px;
    }
    h1 {
        font-size: 18px;
    }
    h2 {
        font-size: 16px;
    }
    button, .auth-form button, .chat-create-form button {
        padding: 8px 10px;
        font-size: 12px;
    }
    .exit-btn {
        padding: 6px 8px;
        font-size: 11px;
    }
}

/* Modale Fenster auf Mobilgeräten */
@media screen and (max-width: 768px) {
    .modal-content,
    .modal-overlay .modal-content {
        width: 95%;
        max-width: none;
        margin: 10px auto;
        padding: 20px 15px;
        max-height: 85vh;
    }
}
@media screen and (max-width: 480px) {
    .modal-content,
    .modal-overlay .modal-content {
        width: 98%;
        padding: 15px 10px;
    }
}

@media (prefers-contrast: high) {
    body {
        background: #fff;
        color: #000;
    }
    .container, .auth-container {
        background: #fff;
        border-color: #000;
    }
    .auth-form input[type="text"],
    .auth-form input[type="password"],
    .chat-create-form input[type="text"],
    .chat-create-form select,
    #chat-search,
    #message-input {
        background: #fff;
        color: #000;
        border-color: #000;
    }
    button, .auth-form button, .chat-create-form button, .exit-btn {
        background: #000;
        color: #fff;
    }
    .message.mine, .message.other {
        background: #ddd;
    }
    h1, h2, .chat-list li a {
        color: #000;
    }
    .user-count {
        background: #000;
        color: #fff;
    }
}

/* Einheitliche Schriftart auf Mobilgeräten: Deaktivierung der System-Schriftart-Substitution */
@media screen and (max-width: 1024px) {
    html, body, body *,
    input, select, textarea, button, a, span, p, label, div {
        font-family: 'Open Sans', sans-serif !important;
    }
    h1, h2, h3, h4, h5, h6 {
        font-family: 'Fraunces', serif !important;
    }
    input, textarea {
        -webkit-appearance: none;
        appearance: none;
    }
}

/* ── Поиск по сообщениям чата ───────────────────────────────────────── */

/* Кнопка «Suche» в шапке чата */
.header-search-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    margin-left: 12px;
    background: var(--sepia);
    /* var(--input-bg): контрастен кнопке в обеих темах (в тёмной sepia светлая, #fff сливался) */
    color: var(--input-bg);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
}
.header-search-btn:hover {
    background: var(--sepia-deep);
}

/* Оверлей и модалка поиска */
.message-search-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 8vh 16px 16px;
    box-sizing: border-box;
}
.message-search-overlay[hidden] {
    display: none;
}

.message-search-modal {
    background: var(--card-bg);
    border: 3px solid var(--sepia);
    border-radius: 10px;
    width: 100%;
    max-width: 560px;
    max-height: 75vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

/* Шапка модалки: поле ввода + крестик */
.message-search-head {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-bottom: 2px solid var(--sepia);
    background: var(--card-bg);
}
.message-search-head input,
.message-search-filters input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: 2px solid var(--sepia);
    border-radius: 6px;
    background: var(--surface-input);
    color: var(--ink);
    font-size: 15px;
    outline: none;
}
.message-search-head input:focus,
.message-search-filters input:focus {
    border-color: #6f4420;
}
/* Фильтры поиска: автор + дата */
.message-search-filters {
    display: flex;
    gap: 8px;
    padding: 8px 12px 0;
    background: var(--card-bg);
}
.message-search-filters #message-search-date {
    flex: 0 0 auto;
    width: 160px;
}
.message-search-close {
    background: none;
    border: none;
    color: var(--ink);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    padding: 0 8px;
}
.message-search-close:hover {
    color: var(--sepia);
}

/* Список результатов */
.message-search-results {
    overflow-y: auto;
    padding: 8px 12px 12px;
}
.message-search-result {
    background: var(--surface-input);
    border: 1px solid #d9c9a3;
    border-radius: 6px;
    padding: 10px 12px;
    margin-top: 8px;
}
.message-search-result-head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    color: var(--sepia);
}
.message-search-result-time {
    color: #a08c6a;
    white-space: nowrap;
}
.message-search-result-text {
    margin-top: 4px;
    font-size: 14px;
    color: var(--ink);
    white-space: pre-wrap;
    overflow-wrap: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.message-search-empty {
    text-align: center;
    color: #a08c6a;
    padding: 24px 0;
}

/* На узких экранах кнопка — только иконка лупы */
@media screen and (max-width: 480px) {
    .header-search-btn-text {
        display: none;
    }
    .header-search-btn {
        padding: 8px 10px;
        margin-left: 6px;
    }
}