/* ============================================================================
   text_chat — modern refined dark theme
   Design tokens → base → components → layout → responsive
   Inter is loaded via a <link> in each page's <head>, with a system fallback.
   ========================================================================== */

:root {
    /* Surfaces — a real depth hierarchy instead of one flat glass. */
    --bg: #0a0918;
    --surface-1: rgba(255, 255, 255, 0.035);   /* panels */
    --surface-2: rgba(255, 255, 255, 0.055);   /* cards, incoming bubbles */
    --surface-3: rgba(255, 255, 255, 0.09);     /* elevated / hover */
    --surface-solid: #15132e;                    /* opaque menus/modals */
    --surface-solid-2: #1b1838;

    /* Text */
    --text: #ecebf7;
    --text-2: #a9a4c9;
    --text-3: #726d94;

    /* Hairlines */
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);

    /* Accent (purple, refined) */
    --accent: #7c6cf0;
    --accent-2: #a29bfe;
    --accent-strong: #6c5ce7;
    --accent-soft: rgba(124, 108, 240, 0.16);
    --accent-softer: rgba(124, 108, 240, 0.10);
    --accent-ring: rgba(124, 108, 240, 0.5);
    --accent-grad: linear-gradient(135deg, #7b5cff 0%, #a78bff 100%);
    /* Own message bubbles (private + group) — a calm slate-blue, not the loud accent. */
    --own-bubble-grad: linear-gradient(135deg, #3b4a63 0%, #46587a 100%);

    /* Semantic */
    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.16);
    --danger: #fb7185;
    --danger-soft: rgba(251, 113, 133, 0.15);
    --warning: #fbbf24;

    /* Radii */
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 22px;
    --r-pill: 999px;

    /* Spacing (4px base) */
    --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
    --s-5: 20px; --s-6: 24px; --s-7: 32px; --s-8: 48px;

    /* Elevation */
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-2: 0 10px 30px -10px rgba(0, 0, 0, 0.55);
    --shadow-3: 0 28px 70px -18px rgba(0, 0, 0, 0.65);
    --glow: 0 8px 30px -6px rgba(124, 108, 240, 0.5);

    /* Motion */
    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
    --dur-1: 0.14s;
    --dur-2: 0.24s;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --header-h: 56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

/* Static ambient background — soft accent glows over a deep base. */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(1100px 760px at 12% -12%, rgba(124, 108, 240, 0.22), transparent 60%),
        radial-gradient(950px 680px at 105% 4%, rgba(0, 176, 220, 0.10), transparent 55%),
        radial-gradient(800px 900px at 50% 120%, rgba(124, 108, 240, 0.10), transparent 60%),
        linear-gradient(180deg, #0a0918 0%, #0b0a1c 100%);
}

body { font-size: 15px; line-height: 1.5; }

h1, h2, h3 { letter-spacing: -0.02em; line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 800; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: rgba(124, 108, 240, 0.4); color: #fff; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.16) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.14);
    border-radius: var(--r-pill);
    border: 2px solid transparent;
    background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.24); background-clip: padding-box; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Buttons ────────────────────────────────────────────────────────────── */

/* Base layout also covers button-like labels/anchors (photo-upload label,
   Google/Guest links) so they don't render as bare text. Variant rules below
   override the fill. */
button, .btn, .btn-secondary, .btn-danger, .btn-ghost {
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent-grad);
    border: none;
    border-radius: var(--r-md);
    padding: 11px 20px;
    min-height: 42px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
    text-decoration: none;
    box-sizing: border-box;
    transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-2) var(--ease),
                filter var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
    box-shadow: var(--shadow-1);
}
button:hover, .btn:hover { transform: translateY(-1px); box-shadow: var(--glow); filter: saturate(1.05); }
button:active, .btn:active { transform: translateY(0); box-shadow: var(--shadow-1); }
button:focus-visible, .btn:focus-visible,
input:focus-visible, textarea:focus-visible, a:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-ring);
}
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; filter: none; }

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
}
.btn-secondary:hover { background: var(--surface-3); border-color: var(--border-strong); box-shadow: none; filter: none; }

.btn-ghost {
    background: transparent;
    color: var(--text-2);
    box-shadow: none;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); box-shadow: none; filter: none; }

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid rgba(251, 113, 133, 0.35);
    box-shadow: none;
}
.btn-danger:hover { background: rgba(251, 113, 133, 0.25); box-shadow: none; filter: none; }

.btn-small { padding: 7px 14px; min-height: 34px; font-size: 0.82rem; border-radius: var(--r-sm); }
.btn-block { display: flex; width: 100%; }

/* Inline SVG icons */
.svg-ic { width: 1.05em; height: 1.05em; display: inline-block; vertical-align: -0.15em; flex-shrink: 0; }
i[data-icon] { display: inline-flex; }

/* Icon-only / small-context buttons get a fixed, legible icon size. */
.msg-react-btn .svg-ic, .msg-reply-btn .svg-ic,
.msg-pin-btn .svg-ic, .msg-edit-btn .svg-ic, .msg-delete-btn .svg-ic,
.mute-btn .svg-ic, .kick-btn .svg-ic, .pm-btn .svg-ic,
.reply-bar-cancel .svg-ic, .pending-remove .svg-ic { width: 16px; height: 16px; }
.close-pc-btn .svg-ic { width: 15px; height: 15px; }
.media-modal-close .svg-ic { width: 18px; height: 18px; }
.reply-bar-icon .svg-ic { width: 16px; height: 16px; }
.room-icon .svg-ic { width: 17px; height: 17px; color: var(--accent-2); }
.lock-icon .svg-ic { width: 13px; height: 13px; }
.pm-notif-ic .svg-ic { width: 16px; height: 16px; }
.pending-title .svg-ic { width: 14px; height: 14px; }
.room-group-header .svg-ic { width: 16px; height: 16px; color: var(--accent-2); }

/* ── Inputs ─────────────────────────────────────────────────────────────── */

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
    width: 100%;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text);
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 12px 14px;
    outline: none;
    transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    background: rgba(0, 0, 0, 0.32);
    box-shadow: 0 0 0 3px var(--accent-ring);
}
input:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── Avatars (shared) ───────────────────────────────────────────────────── */

.avatar {
    --sz: 36px;
    width: var(--sz);
    height: var(--sz);
    border-radius: 50%;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    font-weight: 700;
    font-size: calc(var(--sz) * 0.4);
    color: #fff;
    letter-spacing: 0;
    user-select: none;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { --sz: 30px; }
.avatar-lg { --sz: 76px; font-size: 1.9rem; }

.avatar-wrap { position: relative; flex-shrink: 0; display: inline-flex; }
.avatar-wrap .presence-dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 2px solid var(--surface-solid);
}
.presence-dot.online { background: var(--success); }
.presence-dot.offline { background: #4a4666; }
.conv-unread-dot {
    position: absolute; top: -2px; right: -2px;
    width: 11px; height: 11px; border-radius: 50%;
    background: var(--danger); border: 2px solid var(--surface-1);
}

/* ── Screens ────────────────────────────────────────────────────────────── */

.screen { display: none; width: 100%; height: 100%; position: relative; }
.screen.active { display: flex; flex-direction: column; }

/* ── Login / Signup ─────────────────────────────────────────────────────── */

body.centered-body { display: flex; align-items: center; justify-content: center; overflow-y: auto; padding: 24px; }

.login-container {
    width: 400px;
    max-width: 100%;
    background: var(--surface-1);
    backdrop-filter: blur(18px);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: 36px 34px;
    box-shadow: var(--shadow-3);
    text-align: center;
    animation: pop-in var(--dur-2) var(--ease);
}
.login-container h1 { margin-bottom: 6px; }

@keyframes pop-in {
    from { opacity: 0; transform: translateY(14px) scale(0.985); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-sub { margin: 0 0 22px; font-size: 0.9rem; color: var(--text-2); }

.login-container form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.login-container form input { margin: 0; }
.login-container button[type="submit"] { margin-top: 4px; width: 100%; }

.error-message, .success-message {
    font-size: 0.85rem;
    padding: 10px 12px;
    border-radius: var(--r-sm);
    margin-bottom: 12px;
    text-align: left;
    line-height: 1.4;
}
.error-message { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(251, 113, 133, 0.3); }
.success-message { background: var(--success-soft); color: var(--success); border: 1px solid rgba(52, 211, 153, 0.3); }

.login-alt-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.btn-block { display: flex; width: 100%; box-sizing: border-box; text-decoration: none; }

.login-footer-line { margin-top: 20px; font-size: 0.88rem; color: var(--text-2); }

.invite-banner {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    padding: 13px 15px;
    border-radius: var(--r-md);
    background: var(--accent-soft);
    border: 1px solid rgba(124, 108, 240, 0.35);
    color: var(--text);
    font-size: 0.86rem;
    line-height: 1.45;
    text-align: left;
}

.or-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
    color: var(--text-3);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.or-divider::before, .or-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--border);
}

.primary-google { background: var(--accent-grad) !important; color: #fff !important; border: none !important; font-weight: 700; box-shadow: var(--shadow-1); }
.primary-google .svg-ic { background: #fff; border-radius: 50%; padding: 3px; box-sizing: content-box; }
.primary-google:hover { box-shadow: var(--glow); }

.lang-picker-corner { position: fixed; top: 16px; right: 16px; }

/* ── Language picker ────────────────────────────────────────────────────── */

#lang-picker { position: fixed; bottom: 20px; right: 20px; z-index: 900; }
#room-screen.active ~ #lang-picker { display: none; }

#lang-toggle-btn {
    background: var(--surface-1);
    color: var(--text-2);
    border: 1px solid var(--border);
    border-radius: var(--r-pill);
    padding: 9px 16px;
    font-size: 0.82rem;
    font-weight: 600;
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-1);
    min-height: 0;
}
#lang-toggle-btn:hover { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-2); transform: none; filter: none; }

#lang-dropdown {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    min-width: 160px;
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    overflow: hidden;
    box-shadow: var(--shadow-3);
    animation: pop-in var(--dur-1) var(--ease);
}
#lang-dropdown.open { display: block; }
.lang-option {
    padding: 11px 16px;
    cursor: pointer;
    font-size: 0.88rem;
    color: var(--text-2);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background var(--dur-1);
}
.lang-code {
    display: inline-grid;
    place-items: center;
    min-width: 26px;
    padding: 2px 5px;
    border-radius: var(--r-sm);
    background: var(--surface-3);
    border: 1px solid var(--border);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--text-2);
}
.lang-option.active .lang-code { background: var(--accent-soft); border-color: rgba(124,108,240,0.4); color: var(--accent-2); }
.lang-option:hover { background: var(--surface-2); color: var(--text); }
.lang-option.active { color: var(--text); background: var(--accent-soft); font-weight: 600; }
.lang-option.active::after {
    content: '';
    margin-left: auto;
    width: 15px; height: 15px;
    background: var(--accent-2);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center/contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* ── Dashboard ──────────────────────────────────────────────────────────── */

/* overflow-x hidden so the page never scrolls sideways: a scroll container with
   one axis auto turns the other from visible into auto, which let a too-wide
   grid child cause horizontal scroll on mobile. */
#dashboard-screen.active { overflow-y: auto; overflow-x: hidden; align-items: center; }

.dashboard-wrap { width: 100%; max-width: 1120px; padding: 20px 20px 48px; box-sizing: border-box; }

.dashboard-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px 18px;
    margin-bottom: 22px;
    background: rgba(12, 11, 30, 0.7);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-2);
}
.dashboard-brand { display: inline-flex; align-items: center; gap: 9px; }
.dashboard-brand .svg-ic { width: 22px; height: 22px; color: var(--accent-2); }
.dashboard-logo-text {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: var(--accent-grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.dashboard-topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#admin-panel { display: flex; align-items: center; gap: 8px; }

.dashboard-body { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
/* Grid items default to min-width:auto and won't shrink below their content —
   force them to so long names/rows can't push the layout past the viewport. */
.dashboard-body > * { min-width: 0; }
.dashboard-left-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }


.dashboard-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: var(--shadow-2);
    backdrop-filter: blur(10px);
}
.dashboard-card h3 {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-3);
}

.profile-photo-row { display: flex; align-items: center; gap: 16px; }
.profile-photo-img {
    width: 76px; height: 76px;
    border-radius: 50%;
    object-fit: cover;
    padding: 3px;
    background: var(--accent-grad);
    box-shadow: var(--glow);
}
.photo-upload-label { cursor: pointer; }

.profile-field { display: flex; flex-direction: column; gap: 6px; }
.profile-field label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }

.profile-status { font-size: 0.85rem; padding: 8px 12px; border-radius: var(--r-sm); }
.profile-status.status-ok { background: var(--success-soft); color: var(--success); }
.profile-status.status-err { background: var(--danger-soft); color: var(--danger); }

.rooms-dashboard-card { min-height: 320px; }
.rooms-card-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rooms-card-header h3 { margin: 0; }

.dashboard-rooms-list { display: flex; flex-direction: column; gap: 8px; }

.dashboard-room-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--r-md);
    background: var(--surface-2);
    border: 1px solid var(--border);
    transition: background var(--dur-1), border-color var(--dur-1), transform var(--dur-1);
}
.dashboard-room-item:hover { background: var(--surface-3); border-color: var(--border-strong); transform: translateX(3px); }
.dashboard-room-item .room-icon {
    display: grid; place-items: center;
    width: 38px; height: 38px;
    border-radius: var(--r-sm);
    background: var(--accent-soft);
    font-size: 1rem;
    flex-shrink: 0;
}
.dashboard-room-item .room-name-text { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-capacity { font-size: 0.78rem; color: var(--text-3); flex-shrink: 0; }
.join-room-btn { flex-shrink: 0; }
.room-leave-btn {
    flex-shrink: 0;
    width: 34px; height: 34px; min-height: 0; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--r-sm);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-3);
    box-shadow: none;
}
.room-leave-btn:hover { background: var(--danger-soft); color: var(--danger); border-color: rgba(251, 113, 133, 0.3); box-shadow: none; transform: none; filter: none; }
.room-leave-btn .svg-ic { width: 16px; height: 16px; }

/* Empty states (rooms / conversations placeholders keep opacity:0.5 inline) */
.dashboard-room-item[style*="opacity"] {
    justify-content: center;
    color: var(--text-3);
    background: transparent;
    border-style: dashed;
}
.rooms-empty {
    padding: 14px 6px;
    text-align: center;
    color: var(--text-3);
    font-size: 0.85rem;
    font-style: italic;
}

/* Group headings within a room list. */
.room-group-label {
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
    padding: 10px 4px 4px;
}
.room-group-label:first-child { padding-top: 2px; }

/* Public / Private segmented toggle. */
.room-tabs {
    display: flex;
    gap: 2px;
    padding: 3px;
    border-radius: var(--r-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.room-tab {
    flex: 1;
    min-height: 0;
    padding: 5px 12px;
    border-radius: var(--r-pill);
    background: transparent;
    color: var(--text-2);
    border: none;
    box-shadow: none;
    font-size: 0.8rem;
    font-weight: 600;
}
.room-tab:hover { background: var(--surface-3); color: var(--text); transform: none; box-shadow: none; filter: none; }
.room-tab.active { background: var(--accent-grad); color: #fff; box-shadow: var(--shadow-1); }
.room-tab.active:hover { background: var(--accent-grad); }
#rooms-panel-tabs { margin: 0 10px 8px; }

/* Search box above a room list. */
.room-search { position: relative; display: flex; align-items: center; }
.room-search-icon {
    position: absolute;
    left: 11px;
    color: var(--text-3);
    pointer-events: none;
    display: inline-flex;
}
.room-search-icon .svg-ic { width: 15px; height: 15px; }
.room-search-input {
    width: 100%;
    padding-left: 34px !important;
    border-radius: var(--r-pill);
    font-size: 0.88rem;
}
#rooms-panel .room-search { padding: 0 10px 8px; }
#rooms-panel .room-search-icon { left: 21px; }
#rooms-panel .room-search-input { padding-top: 8px; padding-bottom: 8px; }

/* ── Modal ──────────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(5, 4, 14, 0.62);
    backdrop-filter: blur(6px);
}
.modal-box {
    width: 380px;
    max-width: 100%;
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-xl);
    padding: 26px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: var(--shadow-3);
    animation: pop-in var(--dur-2) var(--ease);
}
.modal-box h3 { font-size: 1.15rem; font-weight: 700; }
.modal-checkbox-label { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; cursor: pointer; color: var(--text-2); }
.modal-checkbox-label input { width: auto; }
.modal-buttons { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.modal-error { color: var(--danger); font-size: 0.85rem; padding: 9px 12px; background: var(--danger-soft); border-radius: var(--r-sm); }

/* Invite modal with user typeahead. */
.invite-box { width: 420px; }
.invite-hint { margin: 0; font-size: 0.82rem; color: var(--text-3); line-height: 1.45; }
.invite-search-wrap { position: relative; }
.invite-suggestions {
    display: none;
    margin-top: 6px;
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface-solid-2);
}
.invite-suggestions.open { display: block; }
.invite-suggestion {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background var(--dur-1);
}
.invite-suggestion:last-child { border-bottom: none; }
.invite-suggestion:hover { background: var(--surface-3); }
.invite-suggestion-text { display: flex; flex-direction: column; min-width: 0; }
.invite-suggestion-name { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invite-suggestion-email { font-size: 0.78rem; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-dialog-message { font-size: 0.95rem; color: var(--text-2); line-height: 1.45; word-break: break-word; }
.custom-dialog-input { width: 100%; box-sizing: border-box; }


/* ── Room screen ────────────────────────────────────────────────────────── */

#room-screen.active { flex-direction: column; }
#room-body { flex: 1; display: flex; flex-direction: row; overflow: hidden; min-height: 0; }

/* Rooms sidebar */
#rooms-panel {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface-1);
    border-right: 1px solid var(--border);
    overflow: hidden;
}
#rooms-panel-header,
#room-users-panel-header {
    padding: 16px 18px 12px;
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-3);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
#rooms-list { flex: 1; overflow-y: auto; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 3px; }

.room-item {
    padding: 10px 12px;
    border-radius: var(--r-md);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--text-2);
    transition: background var(--dur-1), color var(--dur-1);
}
.room-item:hover { background: var(--surface-2); color: var(--text); }
.room-item.active { background: var(--accent-soft); color: var(--text); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.room-item .lock-icon { opacity: 0.7; font-size: 0.85rem; }
.room-item .room-capacity { margin-left: auto; }

/* Members sidebar — shown whenever the room screen is active (which only
   happens inside a room), so no inline JS display toggling is needed. */
#room-users-panel {
    width: 248px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface-1);
    border-left: 1px solid var(--border);
    overflow: hidden;
}
#room-users-count { color: var(--text-3); letter-spacing: 0; font-weight: 600; }
#room-users-list { flex: 1; overflow-y: auto; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 2px; }

.room-user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: var(--r-md);
    font-size: 0.88rem;
    transition: background var(--dur-1);
}
.room-user-item.clickable { cursor: pointer; }
.room-user-item:hover { background: var(--surface-2); }
.room-user-name { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-offline { opacity: 0.5; }
.user-action-btns { display: flex; gap: 2px; align-items: center; margin-left: auto; }
.pm-btn, .mute-btn, .kick-btn {
    background: none; border: none; box-shadow: none;
    cursor: pointer; font-size: 0.8rem; padding: 4px; min-height: 0;
    opacity: 0.45; border-radius: var(--r-sm); line-height: 1;
    transition: opacity var(--dur-1), background var(--dur-1);
}
.pm-btn:hover, .mute-btn:hover, .kick-btn:hover { opacity: 1; background: var(--surface-3); transform: none; box-shadow: none; filter: none; }
.mute-btn.muted { opacity: 1; filter: sepia(1) saturate(3) hue-rotate(170deg); }

/* Role name colors */
.name-guest { color: var(--text); }
.name-user { color: #74b9ff; }
.name-admin { color: #ff7675; }
.name-superadmin { color: #ccff00; }
.msg-author.clickable { cursor: pointer; }
.msg-author.clickable:hover { text-decoration: underline; }


/* ── Chat panel ─────────────────────────────────────────────────────────── */

#chat-panel { flex: 1; min-width: 0; display: none; flex-direction: column; overflow: hidden; background: transparent; }
#chat-panel.drag-over { outline: 2px dashed var(--accent); outline-offset: -6px; border-radius: var(--r-md); }

/* App-bar header */
#current-room-display {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--header-h);
    padding: 0 16px;
    flex-shrink: 0;
    background: rgba(12, 11, 30, 0.55);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}
#current-room-name { font-weight: 700; font-size: 1rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#current-room-display .header-spacer { flex: 1; }

.ws-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; transition: background 0.3s; }
.ws-dot.ws-connecting { background: var(--warning); }
.ws-dot.ws-connected { background: var(--success); }
.ws-dot.ws-reconnecting { background: var(--warning); animation: ws-blink 1s infinite; }
.ws-dot.ws-disconnected { background: var(--danger); }
@keyframes ws-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
#ws-status-label { font-size: 0.72rem; color: var(--text-3); }

#room-invite-btn, #leave-room-btn, #mobile-users-btn { min-height: 34px; }
#leave-room-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; font-size: 0.82rem; border-radius: var(--r-sm); background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(251, 113, 133, 0.3); box-shadow: none; }
#leave-room-btn .svg-ic { width: 16px; height: 16px; }
#leave-room-btn:hover { background: rgba(251, 113, 133, 0.22); box-shadow: none; filter: none; }
#mobile-users-btn { display: none; }

/* PM notification bell */
#pm-notif-btn { position: relative; cursor: pointer; }
#pm-notif-icon {
    display: grid; place-items: center;
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 1rem;
    transition: background var(--dur-1);
}
#pm-notif-btn:hover #pm-notif-icon { background: var(--surface-3); }
#pm-notif-count {
    position: absolute; top: -3px; right: -3px;
    min-width: 18px; height: 18px; padding: 0 5px;
    background: var(--danger); color: #fff;
    border-radius: var(--r-pill);
    font-size: 0.68rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--bg);
}
#pm-notif-dropdown {
    position: absolute; top: 46px; right: 0;
    min-width: 220px;
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    overflow: hidden;
    box-shadow: var(--shadow-3);
    z-index: 700;
    animation: pop-in var(--dur-1) var(--ease);
}
.pm-notif-item {
    padding: 11px 15px; cursor: pointer;
    font-size: 0.88rem; color: var(--text-2);
    display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid var(--border);
    transition: background var(--dur-1);
}
.pm-notif-item:last-child { border-bottom: none; }
.pm-notif-item:hover { background: var(--surface-2); color: var(--text); }
.pm-notif-item.unread { color: var(--text); font-weight: 600; }
.pm-notif-empty { padding: 16px; text-align: center; font-size: 0.85rem; color: var(--text-3); }

/* Chat history */
#chat-history {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px clamp(10px, 4vw, 40px) 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    /* No scroll-behavior here. With it, every `scrollTop = scrollHeight`
       animates — including the one that runs when a room is opened, which is
       why entering a conversation glided down through the whole history before
       settling. The two places that genuinely want a smooth scroll (jumping to
       a quoted message) ask for it themselves on the call, so nothing is lost
       by leaving the default alone. */
}

/* ── Messages: bubbles ──────────────────────────────────────────────────── */

.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 1px 0;
    max-width: 100%;
    animation: msg-in var(--dur-2) var(--ease);
}
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* Stored history is laid out in place. The slide-in is for a message arriving
   into a conversation already on screen; a hundred rows doing it at once as a
   room opens looks like the view scrolling down through them. */
.msg-row.from-history { animation: none; }
.msg-row.own { flex-direction: row-reverse; }

.msg-avatar { width: 34px; flex-shrink: 0; align-self: flex-end; }
.msg-row.grouped .msg-avatar { visibility: hidden; height: 0; }
.msg-row.own .msg-avatar { display: none; }

.msg-main { display: flex; flex-direction: column; min-width: 0; max-width: min(600px, 76%); }
.msg-row.own .msg-main { align-items: flex-end; }

.msg-head { display: flex; align-items: baseline; gap: 8px; margin: 6px 6px 3px; }
.msg-row.grouped .msg-head { display: none; }
.msg-author { font-size: 0.8rem; font-weight: 700; }
.msg-time { font-size: 0.68rem; color: var(--text-3); }

.msg-bubble {
    padding: 9px 13px;
    border-radius: 4px 16px 16px 16px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.94rem;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    box-shadow: var(--shadow-1);
}
.msg-row.grouped .msg-bubble { border-top-left-radius: 16px; }
.msg-row.own .msg-bubble {
    background: var(--own-bubble-grad);
    color: #fff;
    border-radius: 16px 4px 16px 16px;
}
.msg-row.own.grouped .msg-bubble { border-top-right-radius: 16px; }
.msg-bubble:empty { display: none; }

/* Actions (react / reply) */
.msg-actions {
    align-self: center;
    display: flex;
    gap: 3px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-1);
}
.msg-row:hover .msg-actions,
.msg-row:focus-within .msg-actions { opacity: 1; pointer-events: auto; }
/* Touch devices can't hover. Showing every message's actions all the time made
   the thread a wall of buttons, so there they stay hidden until the message is
   tapped (see initTapActions in app.js). `pointer-events` is what keeps a
   hidden row from swallowing the tap that is meant to open it. */
@media (hover: none) {
    .msg-actions { opacity: 0; pointer-events: none; }
    .msg-row.actions-open .msg-actions { opacity: 1; pointer-events: auto; }
    .pc-actions { opacity: 0; pointer-events: none; }
    .pc-msg-wrap.actions-open .pc-actions { opacity: 1; pointer-events: auto; }
}
.msg-react-btn, .msg-reply-btn, .msg-pin-btn, .msg-edit-btn, .msg-delete-btn {
    width: 30px; height: 30px; min-height: 0; padding: 0;
    border-radius: 50%;
    background: var(--surface-solid-2);
    border: 1px solid var(--border);
    color: var(--text-2);
    font-size: 0.85rem;
    box-shadow: var(--shadow-1);
}
.msg-react-btn:hover, .msg-reply-btn:hover, .msg-pin-btn:hover, .msg-edit-btn:hover { background: var(--surface-3); color: var(--text); transform: translateY(-1px); box-shadow: var(--shadow-2); filter: none; }
.msg-delete-btn:hover { background: var(--danger-soft); color: var(--danger); transform: translateY(-1px); box-shadow: var(--shadow-2); filter: none; }
.msg-row.is-pinned .msg-pin-btn { background: var(--accent-soft); color: var(--accent-2); }

/* System message chip */
.msg-system {
    align-self: center;
    margin: 8px auto;
    padding: 5px 14px;
    border-radius: var(--r-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-3);
    font-size: 0.78rem;
    max-width: 90%;
    text-align: center;
}

/* Day separator */
.msg-day-sep {
    align-self: center;
    margin: 14px auto 8px;
    padding: 3px 14px;
    border-radius: var(--r-pill);
    background: var(--surface-1);
    border: 1px solid var(--border);
    color: var(--text-3);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.msg-row.highlight .msg-bubble {
    animation: bubble-flash 1.4s var(--ease);
}
@keyframes bubble-flash {
    0%, 100% { box-shadow: var(--shadow-1); }
    30% { box-shadow: 0 0 0 3px var(--accent-ring); }
}

/* ── Reply ──────────────────────────────────────────────────────────────── */

.reply-quote {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin: 0 2px 4px;
    padding: 5px 10px;
    border-left: 3px solid var(--accent-2);
    background: var(--accent-softer);
    border-radius: 0 var(--r-sm) var(--r-sm) 0;
    cursor: pointer;
    font-size: 0.78rem;
    max-width: 100%;
    transition: background var(--dur-1);
}
.reply-quote:hover { background: var(--accent-soft); }
.msg-row.own .reply-quote { align-self: flex-end; border-left: none; border-right: 3px solid var(--accent-2); border-radius: var(--r-sm) 0 0 var(--r-sm); text-align: right; }
.reply-quote-name { color: var(--accent-2); font-weight: 700; }
.reply-quote-text { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#chat-reply-bar {
    display: none;
    align-items: center;
    gap: 10px;
    margin: 0 12px;
    padding: 10px 12px;
    border-left: 3px solid var(--accent-2);
    background: var(--surface-1);
    border-radius: var(--r-sm);
    flex-shrink: 0;
}
.reply-bar-icon { color: var(--accent-2); flex-shrink: 0; }
.reply-bar-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.reply-bar-name { font-size: 0.72rem; font-weight: 700; color: var(--accent-2); }
.reply-bar-text { font-size: 0.8rem; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar-cancel { background: none; border: none; box-shadow: none; color: var(--text-3); cursor: pointer; font-size: 0.9rem; padding: 2px 4px; min-height: 0; flex-shrink: 0; }
.reply-bar-cancel:hover { color: var(--danger); background: none; transform: none; box-shadow: none; filter: none; }

/* ── Reactions ──────────────────────────────────────────────────────────── */

.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 2px 2px; }
.msg-row.own .msg-reactions { justify-content: flex-end; }
.msg-reactions:empty { display: none; margin: 0; }

.reaction-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    min-height: 0;
    border-radius: var(--r-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-2);
    font-size: 0.78rem;
    box-shadow: none;
}
.reaction-pill:hover { background: var(--surface-3); transform: none; box-shadow: none; filter: none; }
.reaction-pill.mine { background: var(--accent-soft); border-color: rgba(124, 108, 240, 0.5); color: var(--text); }
.reaction-emoji { font-size: 0.9rem; }
.reaction-count { font-size: 0.72rem; opacity: 0.85; }

.reaction-picker {
    display: flex;
    gap: 2px;
    padding: 6px;
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-pill);
    box-shadow: var(--shadow-3);
    z-index: 3500;
    animation: pop-in var(--dur-1) var(--ease);
}
.reaction-picker-emoji {
    background: none; border: none; box-shadow: none;
    font-size: 1.25rem; padding: 5px 7px; min-height: 0;
    border-radius: 50%; cursor: pointer; line-height: 1;
    transition: transform var(--dur-1), background var(--dur-1);
}
.reaction-picker-emoji:hover { background: var(--surface-3); transform: scale(1.25); box-shadow: none; filter: none; }

/* ── Attachments ────────────────────────────────────────────────────────── */

.chat-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chat-attachments.multi .chat-file-image,
.chat-attachments.multi .chat-file-video { max-width: 150px; max-height: 120px; }
.chat-file-caption { margin-top: 4px; word-wrap: break-word; }

.chat-media {
    position: relative;
    display: inline-block;
    cursor: pointer;
    line-height: 0;
    border-radius: var(--r-md);
    overflow: hidden;
    box-shadow: var(--shadow-1);
}
.chat-media:hover { filter: brightness(1.06); }
.chat-media:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-file-image, .chat-file-video { display: block; max-width: min(300px, 100%); max-height: 240px; border-radius: var(--r-md); }
/* With width/height attributes present, keep the aspect while both bounds apply. */
.chat-file-image[width] { width: auto; height: auto; }
.chat-media-video video { pointer-events: none; }
.chat-play-badge {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    background: rgba(0, 0, 0, 0.25);
}
.chat-play-badge .svg-ic {
    width: 34px; height: 34px;
    padding: 8px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    box-sizing: content-box;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.6));
}
#pm-notif-icon .svg-ic, #chat-attach-btn .svg-ic { width: 1.15em; height: 1.15em; }
.pending-icon .svg-ic { width: 18px; height: 18px; }
.chat-file-link {
    display: inline-flex; align-items: center; gap: 10px;
    margin-top: 6px; padding: 10px 12px;
    border-radius: var(--r-md);
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    color: var(--text); text-decoration: none;
    font-size: 0.85rem;
    max-width: 260px;
}
.chat-file-link:hover { background: rgba(0, 0, 0, 0.32); text-decoration: none; }
.chat-file-icon { font-size: 1.3rem; flex-shrink: 0; }
.chat-file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-file-size { color: var(--text-3); font-size: 0.76rem; flex-shrink: 0; }
.msg-row.own .chat-file-link { background: rgba(0, 0, 0, 0.2); }

/* Pending attachment tray */
#chat-attachments-tray {
    display: none;
    margin: 0 12px;
    padding: 12px;
    border: 1px dashed rgba(124, 108, 240, 0.5);
    border-radius: var(--r-md);
    background: var(--accent-softer);
    flex-shrink: 0;
    max-height: 170px;
    overflow-y: auto;
}
#chat-attachments-tray.uploading { opacity: 0.6; pointer-events: none; }
.pending-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.pending-title { font-size: 0.76rem; font-weight: 700; letter-spacing: 0.03em; color: var(--accent-2); }
.pending-clear { background: none; border: none; box-shadow: none; padding: 0; min-height: 0; font-size: 0.74rem; font-weight: 600; color: var(--text-3); cursor: pointer; text-decoration: underline; }
.pending-clear:hover { color: var(--danger); background: none; transform: none; box-shadow: none; filter: none; }
.pending-list { display: flex; flex-wrap: wrap; gap: 8px; }
.pending-file {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px 6px 6px;
    border-radius: var(--r-sm);
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid var(--border);
    font-size: 0.78rem; max-width: 230px;
}
.pending-thumb { width: 30px; height: 30px; object-fit: cover; border-radius: var(--r-sm); flex-shrink: 0; }
.pending-icon { font-size: 1.2rem; width: 30px; text-align: center; flex-shrink: 0; }
.pending-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-size { color: var(--text-3); flex-shrink: 0; }
.pending-remove { background: none; border: none; box-shadow: none; color: var(--text-3); cursor: pointer; padding: 2px 4px; min-height: 0; line-height: 1; flex-shrink: 0; }
.pending-remove:hover { color: var(--danger); background: none; transform: none; box-shadow: none; filter: none; }
.pending-hint { margin-top: 8px; font-size: 0.72rem; color: var(--text-3); font-style: italic; }

/* Composer */
#chat-panel-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: rgba(12, 11, 30, 0.5);
    backdrop-filter: blur(12px);
    flex-shrink: 0;
}
#chat-reply-bar + #chat-panel-footer, #chat-attachments-tray + #chat-panel-footer { border-top: 1px solid var(--border); }
#chat-attach-btn {
    flex-shrink: 0;
    width: 42px; height: 42px; padding: 0;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-2);
    border: 1px solid var(--border);
    font-size: 1.15rem;
    box-shadow: none;
}
#chat-attach-btn:hover { background: var(--surface-3); color: var(--text); transform: none; box-shadow: none; filter: none; }
#chat-input { flex: 1; min-width: 0; border-radius: var(--r-pill); background: rgba(0, 0, 0, 0.25); }
#send-btn { flex-shrink: 0; border-radius: var(--r-pill); padding: 11px 22px; }
#chat-input:disabled, #send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* WS retry bar */
#ws-retry-bar {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--danger-soft);
    border-top: 1px solid rgba(251, 113, 133, 0.35);
    font-size: 0.8rem;
    color: var(--danger);
    flex-shrink: 0;
}
#ws-retry-btn { padding: 5px 14px; min-height: 0; background: transparent; border: 1px solid var(--danger); color: var(--danger); font-size: 0.78rem; border-radius: var(--r-sm); box-shadow: none; }
#ws-retry-btn:hover { background: rgba(251, 113, 133, 0.18); box-shadow: none; transform: none; filter: none; }

/* ── Media lightbox ─────────────────────────────────────────────────────── */

#media-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(3, 2, 10, 0.9);
    backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}
#media-modal.open { display: flex; animation: pop-in var(--dur-2) var(--ease); }
.media-modal-body { display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: 100%; max-height: 100%; }
.media-modal-image, .media-modal-video { max-width: min(1100px, 92vw); max-height: 82vh; border-radius: var(--r-md); box-shadow: var(--shadow-3); background: #000; }
.media-modal-close {
    position: absolute; top: 16px; right: 20px;
    width: 42px; height: 42px; padding: 0;
    background: var(--surface-2); border: 1px solid var(--border);
    color: #fff; font-size: 1.1rem; border-radius: 50%; box-shadow: none;
}
.media-modal-close:hover { background: var(--surface-3); box-shadow: none; transform: none; filter: none; }
.media-modal-bar { display: flex; align-items: center; gap: 16px; font-size: 0.85rem; color: var(--text-2); }
.media-modal-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.media-modal-download { color: var(--accent-2); font-weight: 600; }

/* ── Private chat windows ───────────────────────────────────────────────── */

#private-chats-container { position: fixed; inset: 0; pointer-events: none; z-index: 1500; }
.private-chat-window {
    position: absolute;
    pointer-events: auto;
    width: 320px;
    height: 420px;
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    resize: both;
    min-width: 260px;
    min-height: 300px;
    animation: pop-in var(--dur-2) var(--ease);
}
.private-chat-header {
    background: rgba(124, 108, 240, 0.12);
    padding: 12px 14px;
    cursor: move;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
    font-weight: 600;
    user-select: none;
    border-bottom: 1px solid var(--border);
}
.pc-peer { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pc-peer span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.close-pc-btn { background: var(--surface-2); border: none; box-shadow: none; color: var(--text-2); padding: 4px 9px; min-height: 0; border-radius: var(--r-sm); cursor: pointer; }
.close-pc-btn:hover { background: var(--surface-3); color: var(--text); transform: none; box-shadow: none; filter: none; }
.private-chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.pc-msg { padding: 8px 12px; border-radius: var(--r-md); background: var(--surface-2); font-size: 0.9rem; line-height: 1.4; word-wrap: break-word; overflow-wrap: anywhere; }
.pc-msg.me { background: var(--own-bubble-grad); color: #fff; }
.pc-msg.system { align-self: center; background: var(--danger-soft); color: var(--danger); font-size: 0.78rem; text-align: center; max-width: 95%; }

/* A PM message row: bubble/attachments/reactions column + a hover react button. */
.pc-msg-wrap { display: flex; align-items: flex-end; gap: 6px; max-width: 92%; }
.pc-msg-wrap.me { align-self: flex-end; flex-direction: row-reverse; }
.pc-msg-wrap.them { align-self: flex-start; }
.pc-main { display: flex; flex-direction: column; min-width: 0; }
.pc-msg-wrap.me .pc-main { align-items: flex-end; }
.pc-main .chat-attachments { margin-top: 4px; }
.pc-main .chat-file-image, .pc-main .chat-file-video { max-width: min(220px, 100%); max-height: 180px; }
.pc-main .chat-file-link { max-width: 220px; }
.pc-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.pc-msg-wrap.me .pc-reactions { justify-content: flex-end; }
.pc-reactions:empty { display: none; margin: 0; }
.pc-actions {
    align-self: center;
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--dur-1);
}
.pc-msg-wrap:hover .pc-actions { opacity: 1; }
.pc-react-btn, .pc-reply-btn {
    width: 26px; height: 26px; min-height: 0; padding: 0; flex-shrink: 0;
    border-radius: 50%;
    background: var(--surface-solid-2);
    border: 1px solid var(--border);
    color: var(--text-2);
    box-shadow: none;
}
.pc-react-btn .svg-ic, .pc-reply-btn .svg-ic { width: 15px; height: 15px; }
.pc-react-btn:hover, .pc-reply-btn:hover { background: var(--surface-3); color: var(--text); transform: none; box-shadow: none; filter: none; }

.pc-reply-bar {
    display: none;
    align-items: center;
    gap: 8px;
    margin: 0 10px 8px;
    padding: 8px 10px;
    border-left: 3px solid var(--accent-2);
    background: var(--surface-1);
    border-radius: var(--r-sm);
    flex-shrink: 0;
}
.private-chat-footer { padding: 10px; display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--border); }
.private-chat-footer[hidden], .pc-locked[hidden], .pc-locked-add[hidden], .pc-call-btn[hidden] { display: none; }
.pc-locked {
    padding: 12px 14px; border-top: 1px solid var(--border);
    display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
    color: var(--text-2); font-size: 13px; line-height: 1.45;
}
.pc-locked-add {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 14px; border-radius: var(--r-pill);
}
.pc-locked-add svg { width: 16px; height: 16px; }
.private-chat-footer input[type="text"] { flex: 1; min-width: 0; border-radius: var(--r-pill); }
.pc-send-btn { flex-shrink: 0; padding: 10px 14px; }
.pc-attach-btn {
    flex-shrink: 0;
    width: 38px; height: 38px; padding: 0;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-2);
    border: 1px solid var(--border);
    box-shadow: none;
}
.pc-attach-btn .svg-ic { width: 1.1em; height: 1.1em; }
.pc-attach-btn:hover { background: var(--surface-3); color: var(--text); transform: none; box-shadow: none; filter: none; }

/* Staged PM attachments tray, above the composer. */
.pc-attach-tray {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
    margin: 0 10px;
    border: 1px dashed rgba(124, 108, 240, 0.5);
    border-radius: var(--r-md);
    background: var(--accent-softer);
    max-height: 120px;
    overflow-y: auto;
    flex-shrink: 0;
}

/* ── Toasts ─────────────────────────────────────────────────────────────── */

#ws-toast-container { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 4000; pointer-events: none; align-items: center; }
.ws-toast {
    padding: 11px 18px;
    border-radius: var(--r-md);
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    font-size: 0.85rem;
    color: var(--text);
    box-shadow: var(--shadow-3);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity var(--dur-2), transform var(--dur-2);
    max-width: min(90vw, 360px);
    border-left: 3px solid var(--accent);
}
.ws-toast.show { opacity: 1; transform: translateY(0); }
.ws-toast.ok { border-left-color: var(--success); }
.ws-toast.err { border-left-color: var(--danger); }
.ws-toast.info { border-left-color: var(--warning); }

/* ── Mobile drawer backdrop ─────────────────────────────────────────────── */

#mobile-users-backdrop { display: none; position: fixed; inset: 0; background: rgba(3, 2, 10, 0.55); backdrop-filter: blur(2px); z-index: 1400; }
#mobile-users-backdrop.visible { display: block; }

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
    .dashboard-body { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    /* Room becomes a single full-screen chat with an app-bar. */
    #rooms-panel { display: none; }
    #room-users-panel { display: none; }
    #mobile-users-btn { display: inline-flex; }
    #chat-history { padding: 14px 12px 8px; }
    .msg-main { max-width: 82%; }

    /* Members list slides in from the right as a drawer. */
    #room-users-panel.mobile-open {
        display: flex;
        position: fixed;
        top: 0; right: 0;
        width: min(300px, 84vw);
        height: 100dvh;
        z-index: 1450;
        border-left: 1px solid var(--border-strong);
        box-shadow: var(--shadow-3);
        animation: drawer-in var(--dur-2) var(--ease);
    }
    @keyframes drawer-in { from { transform: translateX(100%); } to { transform: translateX(0); } }

    /* PM windows dock as full-width bottom sheets. */
    .private-chat-window {
        left: 0 !important; right: 0 !important;
        bottom: 0 !important; top: auto !important;
        width: 100% !important; height: 72dvh !important;
        border-radius: var(--r-lg) var(--r-lg) 0 0;
        resize: none;
        min-width: 0;
    }
    .private-chat-header { cursor: default; }

    /* iOS zooms the page when focusing an input smaller than 16px — pin the
       chat/search/composer inputs to 16px on mobile to prevent that jump. */
    input[type="text"], input[type="email"], input[type="password"], textarea, select {
        font-size: 16px;
    }

    /* Header dropdowns (pins / history search) would clip off the left edge when
       anchored to a mid-header button on a narrow screen — dock them as a
       full-width sheet just under the app bar instead. */
    .header-panel {
        position: fixed;
        top: calc(var(--header-h) + 6px);
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
        max-height: 62dvh;
    }
}

@media (max-width: 480px) {
    .dashboard-wrap { padding: 12px 12px 40px; }
    .dashboard-topbar { padding: 12px 14px; }
    .dashboard-card { padding: 18px; }
    .login-container { padding: 28px 22px; }
    #current-room-display { padding: 0 10px; gap: 6px; }
    #current-room-name { font-size: 0.95rem; }
    #ws-status-label { display: none; }
    .msg-main { max-width: 86%; }
    #send-btn { padding: 11px 16px; }

    /* Space is tight — the Invite/Leave buttons go icon-only so the room name
       keeps room. The icons still convey the action. */
    #room-invite-btn .btn-text, #leave-room-btn .btn-text { display: none; }
    #room-invite-btn, #leave-room-btn { gap: 0; padding: 7px 10px; }
    #room-invite-btn .svg-ic, #leave-room-btn .svg-ic { margin: 0; }
}

/* ── Team-chat features: links, mentions, unread, edit/delete, pins, search ── */

/* Links in messages */
.msg-link { color: var(--accent-2); text-decoration: underline; text-underline-offset: 2px; word-break: break-word; }
.msg-link:hover { color: var(--accent); }

/* @mentions */
.mention {
    color: var(--accent-2);
    background: var(--accent-softer);
    border-radius: var(--r-sm);
    padding: 0 3px;
    font-weight: 600;
}
.mention-me {
    color: #fff;
    background: var(--accent-strong);
}

/* Unread dot on room list items */
.room-unread-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent-2);
    box-shadow: 0 0 0 2px var(--accent-soft);
    flex-shrink: 0;
    margin-left: 4px;
}
.dashboard-room-item .room-unread-dot { margin-left: auto; }

/* A room you have been let into and not yet opened. Reads as a label rather
   than an alarm: it is an invitation waiting, not something going wrong. */
.room-new-chip {
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-2);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    flex-shrink: 0;
}
.room-tab-badge {
    margin-left: 6px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--accent-strong);
    color: #fff;
    font-size: 0.66rem;
    font-weight: 700;
}

/* Shared-files panel */
.file-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--r-sm); }
.file-row:hover { background: var(--surface-2); }
.file-row + .file-row { border-top: 1px solid var(--border); }
.file-row .chat-media, .file-row .chat-file-link { flex-shrink: 0; max-width: 64px; margin: 0; }
.file-row .chat-file-image, .file-row .chat-file-video { width: 64px; height: 48px; object-fit: cover; border-radius: var(--r-sm); }
.file-row .chat-file-name, .file-row .chat-file-size { display: none; }
.file-row-meta { min-width: 0; display: flex; flex-direction: column; }
.file-row-name { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row-sub { color: var(--text-3); font-size: 0.74rem; }

/* Edited marker + deleted tombstone */
.msg-edited { color: var(--text-2); font-size: 0.74em; font-style: italic; opacity: 0.85; }
.msg-row.own .msg-edited { color: rgba(255, 255, 255, 0.8); opacity: 1; }
.msg-row.msg-tombstone .msg-bubble {
    background: transparent;
    border: 1px dashed var(--border-strong);
    color: var(--text-3);
    font-style: italic;
}

/* Inline edit box */
.msg-edit-input {
    width: 100%;
    min-width: 240px;
    min-height: 60px;
    resize: vertical;
    font: inherit;
    padding: 8px 10px;
    box-sizing: border-box;
}
.msg-edit-actions { display: flex; gap: 6px; margin-top: 6px; justify-content: flex-end; }
.msg-edit-actions button { padding: 5px 14px; min-height: 0; font-size: 0.82rem; }

/* Pinned marker in a message head */
.msg-pinned-marker { display: inline-flex; align-items: center; color: var(--accent-2); }
.msg-pinned-marker .svg-ic { width: 13px; height: 13px; }
.msg-row.is-pinned .msg-bubble { box-shadow: inset 3px 0 0 var(--accent-2); }

/* Room-header panel buttons (pins / search) */
.header-panel-wrap { position: relative; display: inline-flex; }
.header-panel-btn { position: relative; }
.header-panel-btn.active { background: var(--surface-3); color: var(--text); border-color: var(--border-strong); }
.header-btn-badge {
    position: absolute; top: -5px; right: -5px;
    min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 8px;
    background: var(--accent-strong); color: #fff;
    font-size: 0.68rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    box-sizing: border-box;
}

.header-panel {
    display: none;
    position: absolute; top: calc(100% + 8px); right: 0;
    width: 320px; max-width: 80vw;
    max-height: 60vh; overflow-y: auto;
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-2);
    padding: 8px;
    z-index: 60;
}
.header-panel.open { display: block; }
.header-panel-empty { color: var(--text-3); font-size: 0.85rem; padding: 14px 10px; text-align: center; }
.header-panel-input { width: 100%; box-sizing: border-box; margin-bottom: 6px; }

/* Pins panel items */
.pin-item { padding: 8px; border-radius: var(--r-sm); cursor: pointer; }
.pin-item:hover { background: var(--surface-2); }
.pin-item + .pin-item { border-top: 1px solid var(--border); }
.pin-item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.pin-item-name { font-weight: 700; font-size: 0.82rem; }
.pin-item-text { color: var(--text-2); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-item-unpin {
    width: 24px; height: 24px; min-height: 0; padding: 0;
    border-radius: 50%; background: transparent; border: none; color: var(--text-3);
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.pin-item-unpin:hover { background: var(--danger-soft); color: var(--danger); filter: none; box-shadow: none; }
.pin-item-unpin .svg-ic { width: 14px; height: 14px; }

/* Search results panel */
.search-result { padding: 8px; border-radius: var(--r-sm); cursor: pointer; }
.search-result:hover { background: var(--surface-2); }
.search-result + .search-result { border-top: 1px solid var(--border); }
.search-result-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.search-result-name { font-weight: 700; font-size: 0.82rem; }
.search-result-time { color: var(--text-3); font-size: 0.72rem; flex-shrink: 0; }
.search-result-text { color: var(--text-2); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* "Who reacted" popover */
.reaction-tip {
    position: fixed;
    z-index: 5000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    max-width: 220px;
    padding: 8px 12px;
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-2);
    font-size: 0.82rem;
    color: var(--text);
    pointer-events: none;
    visibility: hidden;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.reaction-tip.below { transform: translateY(-4px); }
.reaction-tip.show { visibility: visible; opacity: 1; transform: translateY(0); }
.reaction-tip-emoji { font-size: 1.15rem; line-height: 1; }
.reaction-tip-names { text-align: center; color: var(--text-2); line-height: 1.45; }

/* Notifications card */
.notif-desc { color: var(--text-3); font-size: 0.85rem; margin: 4px 0 12px; line-height: 1.45; }
.notif-toggle-row { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 0.9rem; color: var(--text-2); user-select: none; }
.notif-toggle-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
#notif-status { margin-top: 10px; }

/* Mention autocomplete dropdown */
.mention-box {
    position: fixed;
    z-index: 200;
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-2);
    padding: 4px;
    max-height: 220px; overflow-y: auto;
}
.mention-option {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px; border-radius: var(--r-sm);
    cursor: pointer; font-size: 0.88rem;
}
.mention-option:hover, .mention-option:first-child { background: var(--accent-soft); }

/* Desktop app card: the note under the download button is a caveat, not a
   feature, so it reads quieter than the description above it. */
.desktop-note {
    margin: 8px 0 0;
    font-size: 0.74rem;
    color: var(--text-3);
    line-height: 1.4;
}
#desktop-download { justify-content: center; gap: 8px; }

/* ── Usernames & contacts ───────────────────────────────────────────────── */

/* The handle beside a name: quiet, never wraps, never the thing you read first. */
.user-handle { font-size: 0.74rem; color: var(--text-3); margin-left: 6px; font-weight: 500; white-space: nowrap; }
.invite-suggestion-name .user-handle { margin-left: 5px; }
.room-user-item .user-handle { flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* The line under a username field: the rule at rest, the verdict once typed. */
.field-hint { font-size: 0.78rem; color: var(--text-3); min-height: 1.1em; margin-top: 4px; text-align: left; }
.field-hint.ok { color: var(--success); }
.field-hint.err { color: var(--danger); }
.login-container form .field-hint { margin-top: -4px; }

/* Pick-a-username: the login card, centred on the empty app. */
#pick-username-screen.active { align-items: center; justify-content: center; padding: 24px; }
.pick-username-box { display: flex; flex-direction: column; gap: 10px; }
.pick-username-box h1 { margin-bottom: 0; }
.pick-username-desc { margin: 0 0 8px; font-size: 0.9rem; color: var(--text-2); }
.pick-username-box input { margin: 0; text-align: left; }
.pick-username-box #pick-username-btn { width: 100%; margin-top: 2px; }
.pick-username-box #pick-username-logout { margin-top: 4px; }

.inline-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px;
    border-radius: 9px; background: var(--accent-strong); color: #fff;
    font-size: 0.68rem; font-weight: 700; letter-spacing: 0; vertical-align: middle;
}

/* Contacts card.
   Narrow by nature — a third of a desktop, all of a phone — so a row carries
   one thing to read and at most two to press: the name has its whole line,
   the handle sits under it, and the rarer actions wait behind ⋯. */
.contacts-card { gap: 14px; }

/* The two views, as one control: a sunk track with the fill moving between
   halves, so it reads as a switch rather than two buttons side by side. */
.contact-tabs {
    display: grid; grid-template-columns: 1fr 1fr; gap: 3px;
    padding: 3px; border-radius: 999px;
    background: rgba(0, 0, 0, 0.25); border: 1px solid var(--border);
}
.contact-tab {
    min-height: 0; padding: 7px 10px; border-radius: 999px;
    background: transparent; box-shadow: none; color: var(--text-2);
    font-size: 0.82rem; font-weight: 600; gap: 6px;
}
.contact-tab:hover { background: var(--surface-3); color: var(--text); transform: none; box-shadow: none; filter: none; }
.contact-tab.is-active { background: var(--accent-grad); color: #fff; box-shadow: var(--shadow-1); }
.contact-tab.is-active:hover { background: var(--accent-grad); }
.contact-tab-badge {
    min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.66rem; font-weight: 700; background: var(--accent-2); color: #14122b;
}
.contact-tab.is-active .contact-tab-badge { background: #fff; color: var(--accent-strong); }
.contact-tab-badge[hidden] { display: none; }

.contact-empty-cta { margin-top: 8px; gap: 7px; }
.contact-empty-cta .svg-ic { width: 15px; height: 15px; }
.contact-link {
    display: inline; min-height: 0; padding: 0; margin-left: 4px;
    background: none; box-shadow: none; color: var(--accent-2);
    font-size: inherit; font-weight: 600;
}
.contact-link:hover { background: none; box-shadow: none; transform: none; text-decoration: underline; filter: none; }

.contact-search { position: relative; display: flex; align-items: center; }
.contact-search .contact-search-icon {
    position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
    color: var(--text-3); pointer-events: none; display: inline-flex;
}
.contact-search .contact-search-icon .svg-ic { width: 16px; height: 16px; }
.contact-search input { padding: 10px 38px 10px 38px; font-size: 0.9rem; }
.contact-search-clear {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    width: 28px; height: 28px; min-height: 0; padding: 0;
    background: transparent; box-shadow: none; color: var(--text-3); border-radius: 50%;
}
.contact-search-clear[hidden] { display: none; }
.contact-search-clear:hover { background: var(--surface-3); color: var(--text); transform: translateY(-50%); box-shadow: none; filter: none; }
.contact-search-clear .svg-ic { width: 14px; height: 14px; }

.contacts-body { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.contacts-body:empty { display: none; }

.contact-group { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.contact-group-label {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--text-3); padding: 0 8px 4px;
}
.contact-group-count {
    font-size: 0.66rem; font-weight: 700; letter-spacing: 0;
    color: var(--text-2); background: var(--surface-3); border-radius: 999px; padding: 1px 7px;
}

.contact-item {
    display: flex; align-items: center; gap: 11px;
    padding: 8px 8px; margin: 0 -8px;
    border-radius: var(--r-md);
    min-width: 0;
    transition: background var(--dur-1) var(--ease);
}
.contact-item.is-openable { cursor: pointer; }
.contact-item.is-openable:hover, .contact-item:focus-visible { background: var(--surface-3); outline: none; }
.contact-item.is-openable:active { background: var(--surface-2); }

.contact-avatar { --sz: 38px; font-size: 0.85rem; }
.contact-item .presence-dot {
    position: absolute; right: -1px; bottom: -1px;
    width: 11px; height: 11px; border-radius: 50%;
    border: 2px solid var(--surface-solid);
}

.contact-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.contact-title {
    font-size: 0.92rem; font-weight: 600; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.contact-sub {
    font-size: 0.76rem; color: var(--text-3);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.contact-online { color: var(--success); font-weight: 600; }
.contact-sub-muted { font-style: italic; }
.contact-person .contact-title, .contact-outgoing .contact-title { color: var(--text-2); }

.contact-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.contact-btn {
    width: 32px; height: 32px; min-height: 0; padding: 0;
    border-radius: 50%;
    background: transparent; color: var(--text-3);
    box-shadow: none; border: 1px solid transparent;
}
.contact-btn .svg-ic { width: 16px; height: 16px; }
.contact-btn:hover, .contact-btn.is-open {
    background: var(--surface-3); color: var(--text); border-color: var(--border);
    transform: none; box-shadow: none; filter: none;
}
.contact-btn-primary { background: var(--accent-grad); color: #fff; box-shadow: var(--shadow-1); }
.contact-btn-primary:hover { background: var(--accent-grad); color: #fff; filter: brightness(1.08); border-color: transparent; }
.contact-btn-accent { color: var(--accent-2); border-color: var(--border); }
.contact-btn-accent:hover { color: #fff; background: var(--accent-grad); border-color: transparent; }

/* Show the ⋯ only where it is relevant on a pointer device; always on touch. */
@media (hover: hover) {
    .contact-contact .contact-btn[data-act="menu"] { opacity: 0; transition: opacity var(--dur-1); }
    .contact-contact:hover .contact-btn[data-act="menu"],
    .contact-contact:focus-within .contact-btn[data-act="menu"],
    .contact-btn[data-act="menu"].is-open { opacity: 1; }
}

/* Specific enough to beat the base input[type="text"] rule, which would
   otherwise make the field twice the height of the name it replaces. */
input.contact-nick-input { margin: 0 0 1px; padding: 3px 8px; font-size: 0.9rem; font-weight: 600; border-radius: var(--r-sm); }

.contact-menu {
    position: fixed; z-index: 3000; min-width: 196px;
    background: var(--surface-solid); border: 1px solid var(--border-strong);
    border-radius: var(--r-md); box-shadow: var(--shadow-3);
    padding: 5px; display: flex; flex-direction: column;
    animation: pop-in var(--dur-1) var(--ease);
}
.contact-menu-item {
    justify-content: flex-start; gap: 10px;
    width: 100%; min-height: 0; padding: 9px 11px;
    background: transparent; box-shadow: none; color: var(--text);
    font-size: 0.88rem; font-weight: 500; border-radius: var(--r-sm);
}
.contact-menu-item .svg-ic { width: 16px; height: 16px; color: var(--text-3); }
.contact-menu-item:hover, .contact-menu-item:focus-visible {
    background: var(--surface-3); transform: none; box-shadow: none; filter: none; outline: none;
}
.contact-menu-item.is-danger, .contact-menu-item.is-danger .svg-ic { color: var(--danger); }
.contact-menu-item.is-danger:hover { background: var(--danger-soft); }

.contact-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 14px 8px 6px; }
.contact-empty-icon {
    width: 44px; height: 44px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent-soft); color: var(--accent-2); margin-bottom: 4px;
}
.contact-empty-icon .svg-ic { width: 20px; height: 20px; }
.contact-empty-title { font-weight: 600; font-size: 0.92rem; }
.contact-empty-text { font-size: 0.8rem; color: var(--text-3); line-height: 1.45; max-width: 240px; }
.contact-empty-inline { font-size: 0.84rem; color: var(--text-3); padding: 2px 0; }


/* Pending contact requests: a pill in the dashboard bar, an icon in a room's
   header, and the same popover from either. Only present while something waits. */
.contact-req-btn[hidden] { display: none; }
.contact-req-btn {
    position: relative; gap: 8px; min-height: 36px; padding: 6px 12px 6px 11px;
    background: var(--accent-soft); color: var(--accent-2);
    border: 1px solid rgba(162, 155, 254, 0.35); border-radius: 999px;
    box-shadow: none; font-size: 0.84rem; font-weight: 600;
}
.contact-req-btn .svg-ic { width: 16px; height: 16px; }
.contact-req-btn:hover, .contact-req-btn.is-open {
    background: var(--accent-grad); color: #fff; border-color: transparent;
    transform: none; box-shadow: var(--glow);
}
.contact-req-count {
    min-width: 19px; height: 19px; padding: 0 6px; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent-strong); color: #fff; font-size: 0.7rem; font-weight: 700;
}
.contact-req-btn:hover .contact-req-count, .contact-req-btn.is-open .contact-req-count { background: #fff; color: var(--accent-strong); }
.contact-req-btn.is-compact { width: 36px; height: 36px; min-height: 0; padding: 0; justify-content: center; }
.contact-req-btn.is-compact .contact-req-count {
    position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px;
    border: 2px solid var(--bg);
}
/* Soft pulse on arrival, so the eye finds it once; then it stays still. */
.contact-req-btn:not([hidden]) { animation: req-in 0.9s var(--ease) 1; }
@keyframes req-in { 0% { box-shadow: 0 0 0 0 var(--accent-ring); } 70% { box-shadow: 0 0 0 10px transparent; } 100% { box-shadow: none; } }

.contact-req-pop {
    position: fixed; z-index: 3000; width: 320px; max-width: calc(100vw - 16px);
    background: var(--surface-solid); border: 1px solid var(--border-strong);
    border-radius: var(--r-lg); box-shadow: var(--shadow-3);
    padding: 12px 14px 8px; animation: pop-in var(--dur-1) var(--ease);
}
.contact-req-head {
    font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--text-3); padding: 0 0 6px;
}
.contact-req-list { display: flex; flex-direction: column; max-height: 360px; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }

@media (max-width: 480px) {
    .contact-req-btn .contact-req-label { display: none; }
    .contact-req-btn:not(.is-compact) { padding: 6px 10px; }
}

/* ── Dashboard layout ───────────────────────────────────────────────────────
   The main page is for talking. Three panes side by side on a desktop —
   conversations, rooms, contacts — each scrolling inside itself so the page
   holds still; two columns on a tablet; one pane at a time on a phone, picked
   from the bar above them. Who you are and how the app behaves live in the
   settings sheet behind the account button. */

.dashboard-wrap { max-width: 1360px; }
.dashboard-topbar { margin-bottom: 18px; flex-wrap: nowrap; }
.dashboard-topbar-actions { flex-wrap: nowrap; gap: 10px; }

.dash-grid {
    display: grid;
    grid-template-columns: minmax(270px, 1fr) minmax(340px, 1.25fr) minmax(290px, 1fr);
    grid-template-areas: "chats rooms contacts";
    gap: 18px;
    align-items: stretch;
}
.dash-grid > [data-pane="chats"] { grid-area: chats; }
.dash-grid > [data-pane="rooms"] { grid-area: rooms; }
.dash-grid > [data-pane="contacts"] { grid-area: contacts; }

/* Each pane is as tall as the window allows and scrolls its own list. */
.dash-grid .dash-pane {
    height: calc(100vh - 150px);
    min-height: 460px;
    overflow: hidden;
    padding: 20px;
    gap: 14px;
}
.dash-grid .dash-pane > * { flex-shrink: 0; }
#dashboard-conversations-list, #dashboard-rooms-list, .dash-grid #contacts-body {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
    margin: 0 -10px; padding: 0 10px 4px;
    scrollbar-width: thin;
}
.dash-grid .dash-pane .rooms-card-header { min-height: 32px; }
.dash-grid .dash-pane h3 { display: inline-flex; align-items: center; gap: 8px; }
.dash-grid .dash-pane h3 .svg-ic { width: 15px; height: 15px; color: var(--accent-2); }
.rooms-dashboard-card { min-height: 0; }
.rooms-dashboard-card .room-tabs { align-self: flex-start; }
.rooms-dashboard-card .room-tab { padding: 6px 16px; }

.card-header-btn {
    min-height: 0; padding: 6px 12px 6px 10px; gap: 6px;
    font-size: 0.8rem; border-radius: 999px;
}
.card-header-btn .svg-ic { width: 15px; height: 15px; }

/* Account button and menu. */
.account-wrap { position: relative; }
.account-btn {
    min-height: 0; padding: 4px 10px 4px 4px; gap: 9px;
    background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
    border-radius: 999px; box-shadow: none; font-weight: 600; font-size: 0.88rem;
}
.account-btn:hover, .account-btn[aria-expanded="true"] {
    background: var(--surface-3); border-color: var(--border-strong);
    transform: none; box-shadow: none; filter: none;
}
.account-avatar { display: inline-flex; }
.account-face { --sz: 30px; font-size: 0.78rem; }
.account-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-chevron { color: var(--text-3); display: inline-flex; transition: transform var(--dur-1) var(--ease); }
.account-chevron .svg-ic { width: 15px; height: 15px; }
.account-btn[aria-expanded="true"] .account-chevron { transform: rotate(180deg); }

.account-menu {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 900;
    min-width: 230px; padding: 6px;
    background: var(--surface-solid); border: 1px solid var(--border-strong);
    border-radius: var(--r-md); box-shadow: var(--shadow-3);
    display: flex; flex-direction: column;
    animation: pop-in var(--dur-1) var(--ease);
}
.account-menu[hidden] { display: none; }
.account-menu-head { display: flex; flex-direction: column; gap: 1px; padding: 8px 11px 10px; border-bottom: 1px solid var(--border); margin-bottom: 5px; }
.account-menu-name { font-weight: 700; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu-handle { font-size: 0.78rem; color: var(--text-3); }
.account-menu-item {
    justify-content: flex-start; gap: 10px; width: 100%;
    min-height: 0; padding: 9px 11px; border-radius: var(--r-sm);
    background: transparent; box-shadow: none; color: var(--text);
    font-size: 0.88rem; font-weight: 500;
}
.account-menu-item .svg-ic { width: 16px; height: 16px; color: var(--text-3); }
.account-menu-item:hover, .account-menu-item:focus-visible { background: var(--surface-3); transform: none; box-shadow: none; filter: none; outline: none; }
.account-menu-item.is-danger, .account-menu-item.is-danger .svg-ic { color: var(--danger); }
.account-menu-item.is-danger:hover { background: var(--danger-soft); }
.account-menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }
#admin-panel { display: block; }

/* Settings page. A screen like the others: in the flow, scrolling itself,
   nothing fixed or blurred on top of the page. */
#settings-screen.active { overflow-y: auto; overflow-x: hidden; align-items: center; }
.settings-page { width: 100%; max-width: 620px; padding: 20px 20px 56px; box-sizing: border-box; }
.settings-head {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 16px; margin-bottom: 16px;
    background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--r-lg);
}
.settings-head h3 { margin: 0; font-size: 1.05rem; }
.settings-back {
    min-height: 0; padding: 7px 14px 7px 10px; gap: 6px;
    background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
    border-radius: 999px; box-shadow: none; font-size: 0.85rem; font-weight: 600;
}
.settings-back:hover { background: var(--surface-3); border-color: var(--border-strong); transform: none; box-shadow: none; filter: none; }
.settings-back .svg-ic { width: 16px; height: 16px; }
.settings-body {
    display: flex; flex-direction: column;
    background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg);
    padding: 2px 22px 18px;
}
.settings-section { display: flex; flex-direction: column; gap: 14px; padding: 18px 0; border-bottom: 1px solid var(--border); }
.settings-section:last-child { border-bottom: none; padding-bottom: 4px; }
.settings-section h3 {
    margin: 0; display: inline-flex; align-items: center; gap: 8px;
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3);
}
.settings-section h3 .svg-ic { width: 15px; height: 15px; }

/* Phone navigation — hidden until the panes stop fitting side by side. */
.dash-nav { display: none; }

@media (max-width: 1180px) {
    .dash-grid {
        grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.2fr);
        grid-template-areas: "chats rooms" "contacts rooms";
    }
    .dash-grid .dash-pane { height: auto; min-height: 0; }
    .dash-grid > [data-pane="rooms"] { height: calc(100vh - 150px); min-height: 520px; }
    .dash-grid > [data-pane="chats"], .dash-grid > [data-pane="contacts"] { max-height: 60vh; }
}

@media (max-width: 760px) {
    .dashboard-topbar { margin-bottom: 12px; }
    .account-name { display: none; }
    .account-btn { padding: 3px 7px 3px 3px; gap: 5px; }
    .dash-nav {
        display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px;
        padding: 3px; margin-bottom: 12px;
        background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
    }
    .dash-nav-btn {
        position: relative; min-height: 0; padding: 8px 6px; gap: 6px;
        background: transparent; box-shadow: none; color: var(--text-2);
        border-radius: 999px; font-size: 0.8rem; font-weight: 600;
    }
    .dash-nav-btn .svg-ic { width: 15px; height: 15px; }
    .dash-nav-btn:hover { background: var(--surface-3); transform: none; box-shadow: none; filter: none; }
    .dash-nav-btn.is-active { background: var(--accent-grad); color: #fff; box-shadow: var(--shadow-1); }
    .dash-nav-badge {
        min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
        display: inline-flex; align-items: center; justify-content: center;
        background: var(--danger); color: #fff; font-size: 0.64rem; font-weight: 700;
    }
    .dash-nav-badge[hidden] { display: none; }

    .dash-grid { grid-template-columns: 1fr; grid-template-areas: none; gap: 0; }
    .dash-grid > [data-pane] { grid-area: auto; display: none; }
    .dash-grid[data-active-pane="chats"] > [data-pane="chats"],
    .dash-grid[data-active-pane="rooms"] > [data-pane="rooms"],
    .dash-grid[data-active-pane="contacts"] > [data-pane="contacts"] { display: flex; }
    .dash-grid .dash-pane, .dash-grid > [data-pane="rooms"],
    .dash-grid > [data-pane="chats"], .dash-grid > [data-pane="contacts"] {
        height: auto; min-height: 0; max-height: none; overflow: visible; padding: 18px;
    }
    #dashboard-conversations-list, #dashboard-rooms-list, .dash-grid #contacts-body { overflow: visible; margin: 0; padding: 0; }
    .settings-page { padding: 12px 12px 40px; }
    .settings-body { padding: 2px 16px 14px; }
}
@media (max-width: 380px) {
    .dash-nav-btn span:not(.dash-nav-badge) { display: none; }
}

/* Conversation rows share the contact row; these are the parts only they have. */
.conv-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; align-self: stretch; justify-content: center; }
.conv-time { font-size: 0.72rem; color: var(--text-3); white-space: nowrap; }
.conv-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft); }
.conv-item.is-unread .contact-title { color: var(--text); font-weight: 700; }
.conv-item.is-unread .contact-sub { color: var(--text-2); }
.conv-item.is-unread .conv-time { color: var(--accent-2); font-weight: 600; }

/* ── Voice calls ────────────────────────────────────────────────────────────
   The call is a screen, and the incoming bar is small and solid: no fixed,
   blurred layer anywhere (Android Chrome once refused to draw one). */
.pc-call-btn {
    width: 30px; height: 30px; min-height: 0; padding: 0; border-radius: 50%;
    background: var(--success-soft); color: var(--success); box-shadow: none; margin-left: auto; margin-right: 4px;
}
.pc-call-btn:hover { background: var(--success); color: #07130e; transform: none; box-shadow: none; filter: none; }
.pc-call-btn .svg-ic { width: 15px; height: 15px; }

.pc-call-line {
    align-self: center; display: inline-flex; align-items: center; gap: 7px;
    margin: 6px auto; padding: 5px 12px; border-radius: 999px;
    background: var(--surface-2); color: var(--text-2); font-size: 0.78rem;
}
.pc-call-line .svg-ic { width: 13px; height: 13px; color: var(--success); }
.pc-call-line.is-missed .svg-ic { color: var(--danger); }

#call-screen.active { align-items: center; justify-content: center; overflow-y: auto; }
.call-page {
    width: 100%; max-width: 420px; min-height: 100%; box-sizing: border-box;
    padding: 48px 24px 40px; display: flex; flex-direction: column; justify-content: space-between; gap: 40px;
}
.call-peer { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 6vh; text-align: center; }
.call-avatar { position: relative; display: inline-flex; }
.call-face { --sz: 132px; font-size: 2.6rem; box-shadow: 0 0 0 6px var(--accent-soft); }
#call-screen:not(.is-active-call) .call-face { animation: call-pulse 1.8s var(--ease) infinite; }
@keyframes call-pulse {
    0% { box-shadow: 0 0 0 0 var(--accent-ring), 0 0 0 6px var(--accent-soft); }
    70% { box-shadow: 0 0 0 26px transparent, 0 0 0 6px var(--accent-soft); }
    100% { box-shadow: 0 0 0 0 transparent, 0 0 0 6px var(--accent-soft); }
}
.call-name { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.call-status { font-size: 0.95rem; color: var(--text-3); font-variant-numeric: tabular-nums; min-height: 1.4em; }
.call-status.is-live { color: var(--success); font-weight: 600; }

.call-controls { display: flex; justify-content: center; gap: 36px; }
.call-controls[hidden] { display: none; }
.call-btn {
    flex-direction: column; gap: 8px; min-height: 0; padding: 0;
    background: transparent; box-shadow: none; color: var(--text-2); font-size: 0.8rem; font-weight: 600;
}
.call-btn .svg-ic {
    width: 64px; height: 64px; padding: 20px; box-sizing: border-box; border-radius: 50%;
    background: var(--surface-3); color: var(--text); transition: background var(--dur-1), transform var(--dur-1);
}
.call-btn:hover { background: transparent; box-shadow: none; transform: none; filter: none; }
.call-btn:hover .svg-ic { transform: scale(1.05); }
.call-btn.is-on .svg-ic { background: var(--text); color: #14122b; }
.call-btn.is-end .svg-ic { background: var(--danger); color: #fff; }
.call-btn.is-accept .svg-ic { background: var(--success); color: #07130e; }
.call-btn:disabled { opacity: 0.45; }

.call-bar {
    /* Centred by margins, not a transform: the pop-in animation owns
       `transform`, and while it ran the bar sat half off the right edge. */
    position: fixed; z-index: 2500; top: 12px; left: 12px; right: 12px; margin: 0 auto;
    width: 440px; max-width: calc(100vw - 24px); box-sizing: border-box;
    display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 10px;
    background: var(--surface-solid); border: 1px solid var(--border-strong); border-radius: 999px;
    box-shadow: var(--shadow-3); animation: pop-in var(--dur-2) var(--ease);
}
.call-bar[hidden] { display: none; }
.call-bar-who {
    flex: 1; min-width: 0; justify-content: flex-start; gap: 10px; min-height: 0; padding: 0;
    background: transparent; box-shadow: none; color: var(--text); text-align: left;
}
.call-bar-who:hover { background: transparent; box-shadow: none; transform: none; filter: none; }
.call-bar-avatar { display: inline-flex; }
.call-bar-text { display: flex; flex-direction: column; min-width: 0; }
.call-bar-name { font-weight: 700; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-bar-sub { font-size: 0.75rem; color: var(--success); }
.call-bar-btn { width: 42px; height: 42px; min-height: 0; padding: 0; border-radius: 50%; box-shadow: none; flex-shrink: 0; }
.call-bar-btn .svg-ic { width: 18px; height: 18px; }
.call-bar-btn.is-end { background: var(--danger); color: #fff; }
.call-bar-btn.is-accept { background: var(--success); color: #07130e; animation: call-nudge 1.2s var(--ease) infinite; }
.call-bar-btn:hover { transform: none; filter: brightness(1.08); }
@keyframes call-nudge { 0%, 100% { transform: rotate(0); } 10% { transform: rotate(-14deg); } 20% { transform: rotate(14deg); } 30% { transform: rotate(0); } }
@media (prefers-reduced-motion: reduce) {
    #call-screen .call-face, .call-bar-btn.is-accept { animation: none; }
}
