/* ===== THEME TOKENS ===== */
:root,
html[data-theme="light"] {
    color-scheme: light;

    --bg-page: #f4f4f9;
    --bg-surface: #ffffff;
    --bg-elevated: #ffffff;
    --bg-muted: #f9f9f9;
    --bg-hover: #f0f0f0;
    --bg-subtle: #f8f9fa;
    --bg-code: #f5f5f5;

    --text-primary: #212529;
    --text-secondary: #555555;
    --text-muted: #666666;
    --text-subtle: #888888;
    --text-hint: #6c757d;
    --text-faint: #999999;

    --border: #cccccc;
    --border-subtle: #eeeeee;
    --border-light: #dddddd;
    --border-row: #f0f0f0;

    --accent: #2c3e50;
    --accent-dark: #1a252f;
    --accent-focus-ring: rgba(44, 62, 80, 0.1);

    --navbar-bg: #2c3e50;
    --navbar-text: #ffffff;
    --navbar-hover: rgba(255, 255, 255, 0.1);

    --message-other: #e1e1e1;
    --message-own: #dcf8c6;

    --room-unread-bg: #fef9e6;
    --room-unread-border: #f39c12;

    --shadow-sm: rgba(0, 0, 0, 0.05);
    --shadow-md: rgba(0, 0, 0, 0.1);
    --shadow-lg: rgba(0, 0, 0, 0.15);

    --danger: #e74c3c;
    --danger-dark: #c0392b;
    --danger-bg: #fdecea;
    --danger-border: #f5c6cb;
    --danger-text: #c0392b;

    --success-bg: #eafaf1;
    --success-border: #abebc6;
    --success-text: #1e8449;

    --btn-secondary: #95a5a6;
    --btn-secondary-hover: #7f8c8d;
    --btn-copy-bg: #ecf0f1;
    --btn-copy-hover: #dfe6e9;

    --new-msg-indicator-bg: rgba(255, 255, 255, 0.92);
    --new-msg-indicator-border: #dddddd;

    --online: #2ecc71;
    --add-link: #2ecc71;
}

html[data-theme="dark"] {
    color-scheme: dark;

    --bg-page: #0f1419;
    --bg-surface: #1a2332;
    --bg-elevated: #243044;
    --bg-muted: #121a24;
    --bg-hover: #2a3548;
    --bg-subtle: #1e2836;
    --bg-code: #1e2836;

    --text-primary: #e8eaed;
    --text-secondary: #bdc1c6;
    --text-muted: #9aa0a6;
    --text-subtle: #80868b;
    --text-hint: #9aa0a6;
    --text-faint: #70757a;

    --border: #3c4858;
    --border-subtle: #2a3548;
    --border-light: #3c4858;
    --border-row: #2a3548;

    --accent: #5d8ab4;
    --accent-dark: #4a7196;
    --accent-focus-ring: rgba(93, 138, 180, 0.25);

    --navbar-bg: #151d28;
    --navbar-text: #e8eaed;
    --navbar-hover: rgba(255, 255, 255, 0.08);

    --message-other: #2a3340;
    --message-own: #1e3d2f;

    --room-unread-bg: #2a2418;
    --room-unread-border: #d68910;

    --shadow-sm: rgba(0, 0, 0, 0.25);
    --shadow-md: rgba(0, 0, 0, 0.35);
    --shadow-lg: rgba(0, 0, 0, 0.45);

    --danger-bg: #3d2020;
    --danger-border: #6b3030;
    --danger-text: #f5b7b1;

    --success-bg: #1a3328;
    --success-border: #2d5a45;
    --success-text: #abebc6;

    --btn-secondary: #4a5568;
    --btn-secondary-hover: #5a6578;
    --btn-copy-bg: #243044;
    --btn-copy-hover: #2a3548;

    --new-msg-indicator-bg: rgba(26, 35, 50, 0.95);
    --new-msg-indicator-border: #3c4858;
}

html[data-theme="neutral"] {
    color-scheme: light;

    --bg-page: #d9d5cd;
    --bg-surface: #e4e0d9;
    --bg-elevated: #ebe8e1;
    --bg-muted: #dfdbd5;
    --bg-hover: #d2cec6;
    --bg-subtle: #dcd8d0;
    --bg-code: #d6d2ca;

    --text-primary: #3d3a36;
    --text-secondary: #5c5852;
    --text-muted: #6b665f;
    --text-subtle: #7a756d;
    --text-hint: #6b665f;
    --text-faint: #8a857d;

    --border: #bab5ac;
    --border-subtle: #c9c4bc;
    --border-light: #bfbab1;
    --border-row: #cdc8bf;

    --accent: #566573;
    --accent-dark: #46515e;
    --accent-focus-ring: rgba(86, 101, 115, 0.15);

    --navbar-bg: #566573;
    --navbar-text: #f7f4ee;
    --navbar-hover: rgba(255, 255, 255, 0.12);

    --message-other: #cdc9c1;
    --message-own: #c3cfc0;

    --room-unread-bg: #e4dcc9;
    --room-unread-border: #b8860b;

    --shadow-sm: rgba(61, 58, 54, 0.07);
    --shadow-md: rgba(61, 58, 54, 0.11);
    --shadow-lg: rgba(61, 58, 54, 0.15);

    --danger-bg: #f5e8e6;
    --danger-border: #e0b4b0;
    --danger-text: #9b3d32;

    --success-bg: #e4efe6;
    --success-border: #a8c9ae;
    --success-text: #3d6b47;

    --btn-secondary: #8a939c;
    --btn-secondary-hover: #7a828a;
    --btn-copy-bg: #d2cdc4;
    --btn-copy-hover: #c5c0b8;

    --new-msg-indicator-bg: rgba(228, 224, 216, 0.95);
    --new-msg-indicator-border: #bab5ac;
}

/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    min-height: 100dvh;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ===== HEADER / NAVBAR ===== */
.site-header {
    flex-shrink: 0;
}

.navbar {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    background: var(--navbar-bg);
    color: var(--navbar-text);
    padding: 0.5rem 1rem;
    flex-wrap: nowrap;
    flex-shrink: 0;
    gap: 10px;
}

.nav-burger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--navbar-text);
    border-radius: 8px;
    background: transparent;
    color: var(--navbar-text);
    cursor: pointer;
    flex-shrink: 0;
}

.nav-burger-bar {
    display: block;
    width: 18px;
    height: 2px;
    margin: 0 auto;
    background: currentColor;
    border-radius: 1px;
}

.navbar-brand {
    flex: 1;
    min-width: 0;
}

.site-title {
    font-weight: 600;
    color: var(--navbar-text);
}

.nav-mobile-panel {
    display: flex;
    flex-direction: column;
    background: var(--navbar-bg);
    border-top: 1px solid var(--navbar-hover);
    padding: 0.5rem 1rem 0.75rem;
    gap: 0.25rem;
}

.nav-mobile-panel[hidden] {
    display: none;
}

.nav-mobile-panel a {
    color: var(--navbar-text);
    text-decoration: none;
    padding: 0.75rem 0.5rem;
    border-radius: 8px;
}

.nav-mobile-panel a:hover {
    background: var(--navbar-hover);
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    margin-left: auto;
}

.logout-form {
    margin: 0;
}

.back-button {
    font-size: 1.5rem;
    text-decoration: none;
    color: var(--accent);
    margin-right: 10px;
    display: inline-block;
}

.back-button:hover {
    color: var(--accent-dark);
}

.room-title-section {
    display: flex;
    align-items: center;
}

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

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

.nav-links--desktop {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.nav-links--desktop a {
    color: var(--navbar-text);
    text-decoration: none;
}

.navbar-actions .logout-btn--link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    line-height: 1.2;
}

.theme-dropdown {
    position: relative;
}

.theme-dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid var(--navbar-text);
    color: var(--navbar-text);
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1.2;
    transition: background 0.2s;
}

.theme-dropdown-toggle:hover,
.theme-dropdown.is-open .theme-dropdown-toggle {
    background: var(--navbar-hover);
}

.theme-dropdown-caret {
    font-size: 0.7rem;
    opacity: 0.85;
}

.theme-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 150px;
    padding: 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px var(--shadow-md);
    z-index: 200;
}

.theme-dropdown-menu[hidden] {
    display: none;
}

.theme-option {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.theme-option:hover {
    background: var(--bg-hover);
}

.theme-option.is-active {
    font-weight: 600;
}

.logout-btn {
    background: none;
    border: 1px solid var(--navbar-text);
    color: var(--navbar-text);
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: var(--navbar-hover);
}

/* ===== MAIN CONTENT ===== */
.content {
    max-width: 800px;
    width: 100%;
    margin: 2rem auto;
    padding: 1rem;
    background: var(--bg-surface);
    border-radius: 8px;
    flex-shrink: 0;
    flex: 1;
}

.content h2 {
    text-align: center;
}

/* ===== FORMS & INPUTS ===== */
.form-card {
    max-width: 500px;
    margin: 2rem auto;
    padding: 1.5rem;
    background: var(--bg-surface);
    border-radius: 16px;
    box-shadow: 0 4px 12px var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

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

.mention-star {
    color: gold;
    margin-left: 5px;
    flex-shrink: 0;
}

.mention-suggestions {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 150px;
    overflow-y: auto;
    z-index: 1000;
    margin-bottom: 5px;
}

.mention-item {
    padding: 5px 10px;
    cursor: pointer;
}

.mention-item:hover {
    background-color: var(--bg-hover);
}

.form-control,
input[type="text"],
input[type="password"],
input[type="email"] {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 30px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    background: var(--bg-surface);
    color: var(--text-primary);
}

.form-control:focus,
input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-focus-ring);
}

.form-card form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

#id_participants {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    padding: 10px 0;
}

#id_participants label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
    cursor: pointer;
}

.room-name-input,
.message-input {
    width: 100%;
}

/* ===== BUTTONS ===== */
.btn-primary,
.btn-create,
.send-btn,
.action-btn,
.message-form button[type="submit"],
.btn-file {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border: none;
    color: white;
    padding: 10px 20px;
    border-radius: 40px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px var(--shadow-md);
    text-align: center;
    display: inline-block;
}

.btn-primary:hover,
.btn-create:hover,
.send-btn:hover,
.action-btn:hover,
.message-form button[type="submit"]:hover,
.btn-file:hover {
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    transform: translateY(-1px);
    box-shadow: 0 4px 10px var(--shadow-lg);
}

.action-btn.delete {
    background: linear-gradient(135deg, var(--danger), var(--danger-dark));
}

.action-btn.delete:hover {
    background: linear-gradient(135deg, var(--danger-dark), var(--danger));
}

.logout-btn {
    background: none;
    border: 1px solid var(--navbar-text);
    box-shadow: none;
    padding: 5px 12px;
    transform: none;
}

.logout-btn:hover {
    background: var(--navbar-hover);
    transform: none;
}

.btn-file {
    width: auto;
    min-width: 160px;
    margin-top: 0;
}

/* ===== CHAT PAGE ===== */
.chat-content {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    margin: 0;
    padding: 0;
    background: var(--bg-surface);
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-room-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.room-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.chat-header {
    flex-shrink: 0;
    padding: 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

.chat-messages-wrap {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-muted);
}

.chat-messages.js-chat-scroll:not(.at-bottom-ready) {
    visibility: hidden;
}

.no-results {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
}

.search-messages-form {
    display: flex;
    gap: 6px;
    align-items: center;
}

.search-messages-field {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-width 0.25s ease, opacity 0.2s ease;
}

.search-messages-form.is-open .search-messages-field {
    max-width: 260px;
    opacity: 1;
}

.search-messages-field .form-control {
    width: 200px;
    min-width: 140px;
    padding: 6px 12px;
    font-size: 0.9rem;
}

.clear-search {
    flex-shrink: 0;
    text-decoration: none;
    color: var(--danger);
    font-size: 1rem;
    line-height: 1;
    padding: 4px;
}

.header-icon-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    border-radius: 8px;
    transition: background 0.15s ease, transform 0.1s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    text-decoration: none;
    color: inherit;
    box-shadow: none;
}

.header-icon-btn:hover {
    background: var(--bg-hover);
    transform: scale(1.05);
}

.header-icon-btn--danger:hover {
    background: var(--danger-bg);
}

.header-icon-form {
    display: inline-flex;
    margin: 0;
}

.input-icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 8px;
    transition: transform 0.1s;
    box-shadow: none;
    color: inherit;
}

.input-icon-btn:hover {
    transform: scale(1.1);
    background: none;
}

.chat-input {
    flex-shrink: 0;
    padding: 10px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 70%;
}

.my-message {
    align-self: flex-end;
    text-align: left;
}

.other-message {
    align-self: flex-start;
    text-align: right;
}

.message-bubble {
    background: var(--message-other);
    padding: 8px 12px;
    border-radius: 18px;
    display: inline-block;
    word-wrap: break-word;
    max-width: 100%;
    color: var(--text-primary);
}

.message-bubble img,
.message-bubble video {
    max-width: min(280px, 100%);
    height: auto;
    border-radius: 12px;
    cursor: pointer;
}

.message-bubble video {
    cursor: default;
}

.my-message .message-bubble {
    background: var(--message-own);
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-subtle);
    margin-top: 4px;
    margin-left: 8px;
    margin-right: 8px;
}

.message-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 0;
}

.message-compose {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.message-compose__row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    width: 100%;
}

.message-compose__input,
.message-form textarea.message-compose__input {
    flex: 1;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    box-sizing: border-box;
    resize: none;
    overflow-y: hidden;
    line-height: 1.4;
    max-height: 150px;
    border: 1px solid var(--border);
    border-radius: 30px;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    background: var(--bg-surface);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
    margin: 0;
    vertical-align: bottom;
}

.message-compose__input:focus,
.message-form textarea.message-compose__input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-focus-ring);
}

.message-compose__row .send-btn {
    flex-shrink: 0;
    align-self: flex-end;
    min-height: 44px;
}

.send-btn-icon {
    display: none;
}

.send-btn {
    flex-shrink: 0;
}

.attach-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 8px;
    transition: transform 0.1s;
}

.attach-btn:hover {
    transform: scale(1.1);
}

.file-link {
    display: inline-block;
    margin-top: 5px;
    padding: 4px 8px;
    background: var(--message-other);
    border-radius: 12px;
    font-size: 0.8rem;
    text-decoration: none;
    color: var(--accent);
}

/* ===== ROOMS LIST ===== */
.rooms-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

body.page-rooms .content {
    overflow-x: hidden;
}

body.page-rooms #rooms-list-app {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.room-card {
    background: var(--bg-surface);
    border-radius: 16px;
    box-shadow: 0 2px 8px var(--shadow-sm);
    transition: all 0.2s;
    border: 1px solid var(--border-subtle);
    overflow: hidden;
}

.room-card:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px var(--shadow-md);
}

.room-card.unread {
    background: var(--room-unread-bg);
    border-left: 4px solid var(--room-unread-border);
}

.room-card.has-draft .room-last-message-text {
    color: var(--text-subtle);
    font-style: italic;
}

.room-link {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 16px;
    text-decoration: none;
    color: inherit;
    min-width: 0;
}

.room-avatar {
    position: relative;
    flex-shrink: 0;
    width: 50px;
    height: 50px;
}

.room-avatar-img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg-hover);
    display: block;
}

.room-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.room-name {
    font-weight: 600;
    font-size: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    min-width: 0;
    gap: 6px;
}

.room-last-message {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
}

.room-last-message-text {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.unread-badge {
    background: var(--danger);
    color: white;
    border-radius: 30px;
    padding: 2px 8px;
    font-size: 0.7rem;
    font-weight: bold;
    margin-left: 8px;
    flex-shrink: 0;
}

/* ===== PROFILE PAGE ===== */
.avatar-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.avatar-preview {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    margin: 0 auto;
    border: 3px solid var(--accent);
}

.form-text {
    font-size: 0.75rem;
    color: var(--text-hint);
    margin-top: 5px;
}

.password-note {
    text-align: center;
    background: var(--bg-subtle);
    padding: 10px;
    border-radius: 30px;
    color: var(--accent);
    font-size: 0.9rem;
}

.error-message {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 0.35rem;
}

.form-errors {
    list-style: none;
    padding: 10px 14px;
    margin: 0 0 1rem;
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    border-radius: 8px;
    color: var(--danger-text);
    font-size: 0.9rem;
}

.form-errors li + li {
    margin-top: 4px;
}

.form-control.is-invalid {
    border-color: var(--danger);
}

.password-help {
    margin: 0.35rem 0 0;
    padding-left: 1.2rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.password-help li {
    margin-bottom: 0.2rem;
}

.password-reset-note {
    text-align: center;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-subtle);
    font-size: 0.9rem;
    color: var(--text-muted);
}

.password-reset-note p {
    margin: 0.35rem 0;
}

.support-email-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.support-email {
    font-weight: 500;
    color: var(--accent);
    word-break: break-all;
}

.btn-copy-email {
    background: var(--btn-copy-bg);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.btn-copy-email:hover {
    background: var(--btn-copy-hover);
}

.password-help-block {
    margin-top: 1rem;
    padding: 12px 14px;
    background: var(--bg-subtle);
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
}

.password-help-block p {
    margin: 0.25rem 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.admin-contact-link {
    font-weight: 600;
    font-size: 1rem;
}

.admin-contact-hint {
    color: var(--text-subtle);
    font-size: 0.85rem;
    margin-left: 4px;
}

/* ===== INVITE PAGE ===== */
.invite-result {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid var(--border-subtle);
}

.invite-result p {
    margin: 10px 0 5px;
    font-weight: 500;
}

.invite-code {
    background: var(--bg-code);
    border: 1px solid var(--border-light);
    border-radius: 30px;
    padding: 10px 15px;
    font-family: monospace;
    font-size: 0.9rem;
    width: 100%;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.btn-secondary {
    background: var(--btn-secondary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 30px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: var(--btn-secondary-hover);
}

/* ===== MODAL (image preview) ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.modal-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
    position: relative;
    top: 50%;
    transform: translateY(-50%);
}

.close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #bbb;
}

/* Desktop chat: messages scroll inside viewport, input always visible */
@media (min-width: 769px) {
    .navbar {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        align-items: center;
    }

    .navbar-brand {
        flex: unset;
        justify-self: start;
    }

    .nav-links--desktop {
        justify-self: center;
    }

    .navbar-actions {
        margin-left: 0;
        justify-self: end;
    }

    body.page-chat {
        height: 100dvh;
        overflow: hidden;
    }

    body.page-chat main {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    body.page-chat .content {
        flex: 1;
        min-height: 0;
        margin: 1rem auto;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    body.page-chat .chat-content {
        flex: 1;
        min-height: 0;
    }

    body.page-chat .chat-container {
        flex: 1;
        min-height: 0;
    }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .nav-burger {
        display: flex;
    }

    .nav-links--desktop {
        display: none;
    }

    .navbar {
        padding: 0.5rem 0.75rem;
        padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
    }

    .username {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .theme-dropdown-toggle {
        padding: 5px 8px;
        font-size: 0.8rem;
    }

    #theme-dropdown-label {
        display: none;
    }

    .content {
        margin: 0.75rem;
        padding: 0.75rem;
        border-radius: 12px;
    }

    .form-card {
        margin: 0.5rem auto;
        padding: 1.25rem;
        border-radius: 12px;
    }

    .form-control,
    input[type="text"],
    input[type="password"],
    input[type="email"] {
        font-size: 16px;
        min-height: 44px;
    }

    .btn-primary,
    .btn-create,
    .send-btn,
    .action-btn,
    .message-form button[type="submit"],
    .btn-file {
        min-height: 44px;
    }

    .rooms-list {
        margin-top: 12px;
        gap: 8px;
    }

    .room-card {
        border-radius: 12px;
    }

    .room-link {
        padding: 14px 12px;
    }

    .room-card:hover {
        transform: none;
    }

    #rooms-list-app .btn-create {
        display: block;
        width: 100%;
        text-align: center;
    }

    .message {
        max-width: 88%;
    }

    .message-bubble img,
    .message-bubble video {
        max-width: 100%;
    }

    .header-icon-btn {
        width: 40px;
        height: 40px;
    }

    .chat-header {
        padding: 0.65rem 0.75rem;
        padding-top: calc(0.65rem + env(safe-area-inset-top, 0px));
    }

    .room-header {
        margin-bottom: 0;
    }

    .room-actions {
        gap: 8px;
    }

    .room-title-section {
        flex: 1;
        min-width: 0;
    }

    .search-messages-form.is-open .search-messages-field {
        max-width: min(52vw, 220px);
    }

    .search-messages-field .form-control {
        width: 100%;
        min-width: 0;
    }

    .chat-input {
        padding: 8px 10px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .message-compose__input {
        font-size: 16px;
        min-height: 44px;
        border-radius: 22px;
        padding: 0.65rem 1rem;
    }

    .send-btn-text {
        display: none;
    }

    .send-btn-icon {
        display: inline;
        font-size: 1.1rem;
    }

    .send-btn {
        width: 44px;
        height: 44px;
        min-height: 44px;
        padding: 0;
        border-radius: 50%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .input-icon-btn,
    .attach-btn {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .upload-limit-hint {
        font-size: 0.7rem;
        margin-top: 4px;
    }

    #emoji-picker {
        width: min(300px, calc(100vw - 24px));
        right: 12px;
        bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    }

    /* Fullscreen chat */
    body.page-chat .site-header {
        display: none;
    }

    body.page-chat main {
        flex: 1;
        min-height: 0;
    }

    body.page-chat .content {
        margin: 0;
        padding: 0;
        border-radius: 0;
        max-width: none;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    body.page-chat .chat-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    body.page-chat .chat-container {
        height: 100dvh;
        height: 100vh;
    }

    body.page-chat.keyboard-open .chat-container {
        height: var(--app-height, 100dvh);
    }

    /* Rooms list page */
    body.page-rooms .content {
        margin: 0;
        padding: 0.75rem;
        border-radius: 0;
        max-width: none;
        overflow-x: hidden;
    }

    body.page-rooms #rooms-list-app,
    body.page-rooms .rooms-list {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    body.page-rooms .room-card,
    body.page-rooms .room-link {
        max-width: 100%;
    }

    body.page-rooms .content > h2 {
        font-size: 1.25rem;
        text-align: left;
        margin-bottom: 0.75rem;
    }
}

@media (max-width: 480px) {
    .navbar-actions {
        gap: 6px;
    }

    .logout-btn {
        padding: 5px 10px;
        font-size: 0.85rem;
    }

    .chat-room-title {
        font-size: 0.95rem;
    }

    .message {
        max-width: 92%;
    }

    .search-messages-form.is-open .search-messages-field {
        max-width: min(46vw, 180px);
    }
}

/* Список пользователей на странице создания комнаты */
.users-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    margin-top: 10px;
}

.user-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-row);
    transition: background 0.1s;
}

.user-item:hover {
    background: var(--bg-muted);
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 15px;
}

.user-name {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 500;
}

.user-checkbox {
    margin-left: auto;
}

.user-checkbox input {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.room-avatar-preview {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    margin: 0 auto 15px auto;
}

.online-indicator {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 14px;
    height: 14px;
    background-color: var(--online);
    border-radius: 50%;
    border: 2px solid var(--bg-surface);
}

.message-group {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

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

.message-content {
    flex: 1;
}

.message-author {
    text-align: left;
    font-size: 0.8rem;
    font-weight: bold;
    margin-bottom: 2px;
}

.online-count {
    position: absolute;
    bottom: -5px;
    right: -5px;
    background-color: var(--online);
    color: white;
    font-size: 0.7rem;
    border-radius: 20px;
    padding: 1px 5px;
    border: 1px solid var(--bg-surface);
    font-weight: bold;
}

.participants-list,
.users-to-add {
    list-style: none;
    padding: 0;
}

.participants-list li,
.users-to-add li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-bottom: 1px solid var(--border-subtle);
}

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

.remove-link,
.add-link {
    margin-left: auto;
    text-decoration: none;
    font-weight: bold;
}

.remove-link {
    color: var(--danger);
}

.add-link {
    color: var(--add-link);
}

.search-form {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.settings-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.room-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.room-header h2 {
    margin: 0;
}

.room-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
}

.search-form-container {
    margin-left: auto;
}

.room-header .search-form-container {
    margin-left: 0;
}

.edit-msg-btn,
.delete-me-btn,
.delete-all-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    margin-left: 5px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.edit-msg-btn:hover,
.delete-me-btn:hover,
.delete-all-btn:hover {
    opacity: 1;
}

.edited-mark {
    font-size: 0.7rem;
    color: var(--text-subtle);
    margin-left: 5px;
}

.draft-indicator {
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--text-subtle);
    padding-left: 2px;
}

.new-messages-indicator {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: var(--new-msg-indicator-bg);
    border: 1px solid var(--new-msg-indicator-border);
    border-radius: 14px;
    padding: 6px 10px;
    backdrop-filter: blur(4px);
    gap: 8px;
    align-items: center;
    box-shadow: 0 2px 10px var(--shadow-sm);
    display: none;
}

.new-messages-jump {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 3px 9px;
    cursor: pointer;
}

.file-name-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.upload-limit-hint {
    margin: 6px 0 0;
    font-size: 0.75rem;
    color: var(--text-faint);
}

.flash-messages {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
}

.flash-message {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
}

.flash-error {
    background: var(--danger-bg);
    color: var(--danger-text);
    border: 1px solid var(--danger-border);
}

.flash-success {
    background: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success-border);
}

#emoji-picker {
    width: 300px;
    height: 350px;
    display: none;
    position: absolute;
    bottom: 70px;
    right: 20px;
    z-index: 1000;
}
