:root {
    /* darker than a typical "messenger blue" on purpose: #3390ec only hits ~3.3:1
       contrast against white, failing WCAG AA (4.5:1) for both button text and
       link text. This shade clears ~4.7:1 either way. */
    --accent: #2776c2;
    --accent-dark: #1c4f85;
    --danger: #c82828;
    --bg-app: #eef2f5;
    --bg-sidebar: #ffffff;
    --bg-chat: #e6ebee;
    --bubble-me: #effdde;
    --bubble-other: #ffffff;
    --text-primary: #1c1f24;
    --text-secondary: #707579;
    --border: #e4e7eb;
    --radius: 14px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --focus-ring: 0 0 0 3px rgba(39, 118, 194, 0.5);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg-app);
    font-family: "Vazirmatn", Tahoma, sans-serif;
    color: var(--text-primary);
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: 6px;
}

[hidden] {
    display: none !important;
}

::-webkit-scrollbar {
    width: 7px;
}

::-webkit-scrollbar-thumb {
    background: #c6cdd3;
    border-radius: 10px;
}

/* ============ SHARED CONTROLS ============ */

.form-input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    font-family: inherit;
    background: #fff;
    color: var(--text-primary);
    transition: border-color .15s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
}

textarea.form-input {
    resize: vertical;
}

.btn {
    display: inline-block;
    border: none;
    cursor: pointer;
    border-radius: 10px;
    padding: 12px 18px;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    transition: background .15s ease, opacity .15s ease;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-dark);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-block {
    display: block;
    width: 100%;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 19px;
    color: var(--text-secondary);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.status-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #b8bec4;
}

.status-dot.online {
    background: #4cd964;
}

.field-error {
    color: var(--danger);
    font-size: 13px;
    margin: 4px 0 0;
}

.field-hint {
    color: var(--text-secondary);
    font-size: 12.5px;
    margin: 4px 0 0;
}

.availability-ok {
    color: #1c7a35;
}

.availability-taken {
    color: var(--danger);
}

.form-error-box {
    background: #fdeaea;
    border: 1px solid #f3b9b9;
    color: var(--danger);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 14px;
}

/* ============ AUTH PAGES ============ */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
    padding: 32px;
    position: relative;
}

.auth-logo {
    text-align: center;
    margin-bottom: 24px;
}

.auth-logo-circle {
    width: 64px;
    height: 64px;
    margin: 0 auto 12px;
    background: linear-gradient(135deg, var(--accent), #6ec1ff);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
}

.profile-avatar-preview {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    margin: 0 auto 12px;
    display: block;
}

.auth-logo h1 {
    font-size: 20px;
    margin: 0 0 4px;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 13.5px;
    margin: 0;
}

.auth-form .form-field {
    margin-bottom: 16px;
}

.auth-form label {
    display: block;
    font-size: 13.5px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.username-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.username-input-wrap .at-sign {
    position: absolute;
    right: 14px;
    color: var(--text-secondary);
    pointer-events: none;
}

.username-input-wrap .form-input {
    padding-right: 28px;
}

.auth-switch {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 18px;
}

.auth-switch a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: underline;
}

.back-link {
    display: inline-block;
    margin-bottom: 14px;
    color: var(--accent);
    font-size: 14px;
    text-decoration: underline;
}

.logout-btn {
    margin-top: 14px;
}

/* ============ APP LAYOUT ============ */

.app-body {
    overflow: hidden;
}

.layout {
    display: flex;
    height: 100vh;
}

/* SIDEBAR */
.sidebar {
    width: 360px;
    min-width: 280px;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    flex: 1;
    font-size: 18px;
    margin: 0;
}

.sidebar-profile-link {
    display: flex;
}

.sidebar-search {
    padding: 10px 14px;
}

.sidebar-list {
    flex: 1;
    overflow-y: auto;
}

.sidebar-section-title {
    padding: 10px 16px 6px;
    font-size: 12.5px;
    color: var(--text-secondary);
    font-weight: 600;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    position: relative;
}

.chat-item:hover {
    background: #f3f6f8;
}

.chat-item.active {
    background: #e8f3fd;
}

.chat-item-body {
    flex: 1;
    min-width: 0;
}

.chat-item-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.chat-item-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-item-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2px;
}

.chat-item-preview {
    font-size: 13.5px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-badge {
    background: var(--accent);
    color: #fff;
    font-size: 11.5px;
    font-weight: 600;
    border-radius: 10px;
    padding: 1px 7px;
    flex-shrink: 0;
}

/* AVATARS */
.avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.avatar-sm {
    width: 34px;
    height: 34px;
}

.avatar-fallback {
    background: linear-gradient(135deg, var(--accent), #6ec1ff);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
}

.avatar-dot {
    position: absolute;
    margin-right: -14px;
    margin-top: 32px;
    border: 2px solid #fff;
}

/* CHAT BOX */
.chat-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
    min-width: 0;
}

.chat-box-empty {
    align-items: center;
    justify-content: center;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
}

.back-link-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    background: rgba(51, 144, 236, 0.08);
}

.back-link-btn:hover {
    background: rgba(51, 144, 236, 0.16);
}

.back-link-btn span {
    font-size: 17px;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    font-weight: 600;
    font-size: 16px;
    margin: 0;
}

.chat-header-status {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
}

.chat-header-profile-link {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    border-radius: 8px;
    padding: 4px 6px;
}

.chat-header-profile-link:hover {
    background: rgba(0, 0, 0, 0.04);
}

.chat-header-menu-wrap {
    position: relative;
    flex-shrink: 0;
}

.chat-header-menu {
    position: absolute;
    top: 44px;
    left: 0;
}

/* SEARCH BAR */
.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
}

.search-bar .form-input {
    flex: 1;
}

.search-result-count {
    font-size: 12.5px;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 60px;
    text-align: center;
}

.message.search-current .bubble {
    outline: 2px solid var(--accent);
}

mark.search-highlight {
    background: #ffe28a;
    color: inherit;
    border-radius: 2px;
}

/* MESSAGES WINDOW */
.messages {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.empty-state {
    margin: auto;
    text-align: center;
    color: var(--text-secondary);
    max-width: 320px;
}

.empty-state-circle {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #6ec1ff);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    font-weight: 700;
}

.empty-state h2 {
    color: var(--text-primary);
    margin: 0 0 8px;
}

/* MESSAGE BUBBLES */

.message {
    display: flex;
    margin-bottom: 10px;
    max-width: 100%;
}

.message.me {
    justify-content: flex-end;
}

.message.other {
    justify-content: flex-start;
}

.bubble {
    max-width: 60%;
    padding: 9px 12px 7px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    position: relative;
}

.message.me .bubble {
    background: var(--bubble-me);
    border-bottom-right-radius: 4px;
}

.message.other .bubble {
    background: var(--bubble-other);
    border-bottom-left-radius: 4px;
}

.message-text {
    margin: 2px 0 4px;
    font-size: 15px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-secondary);
}

.edited-label {
    font-style: italic;
}

.seen-tick {
    color: var(--accent);
    font-size: 12px;
}

.message-actions {
    position: absolute;
    top: -14px;
    left: 6px;
    display: flex;
    gap: 4px;
    background: #fff;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    padding: 2px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .1s ease;
}

.message:hover .message-actions,
.message:focus-within .message-actions {
    opacity: 1;
    pointer-events: auto;
}

.msg-action-btn {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    padding: 4px 6px;
    border-radius: 6px;
}

.inline-edit-box,
.inline-confirm {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 220px;
}

.inline-edit-textarea {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.inline-edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-sm {
    border: none;
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
}

.btn-sm:hover {
    background: rgba(0, 0, 0, 0.12);
}

.btn-sm-primary {
    background: var(--accent);
    color: #fff;
}

.btn-sm-primary:hover {
    background: var(--accent-dark);
}

.btn-sm-danger {
    background: var(--danger);
    color: #fff;
}

.btn-sm-danger:hover {
    opacity: 0.85;
}

/* TOAST */
#toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.toast {
    background: #2b2f33;
    color: #fff;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    animation: toast-in .15s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-action-btn:hover {
    background: #f0f0f0;
}

.message img {
    max-width: 280px;
    max-height: 320px;
    border-radius: 10px;
    display: block;
    object-fit: cover;
}

.message video {
    max-width: 300px;
    border-radius: 10px;
    display: block;
}

.message audio {
    width: 260px;
    display: block;
    margin: 4px 0;
}

.message.pending .bubble {
    opacity: 0.85;
}

.upload-progress-track {
    width: 100%;
    height: 4px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    margin-top: 6px;
    overflow: hidden;
}

.upload-progress-bar {
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width .15s ease;
}

.upload-status {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.message.upload-failed .upload-status {
    color: var(--danger);
}

.message.upload-failed .upload-progress-track {
    display: none;
}

.upload-retry-btn {
    margin-top: 6px;
}

.file-link {
    display: inline-block;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    font-size: 14px;
}

.mention-link,
.message-link {
    color: var(--accent);
    text-decoration: underline;
    word-break: break-all;
}

.location-link {
    display: inline-block;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    font-size: 14px;
}

/* CONNECTION BANNER */
.connection-banner {
    padding: 7px 18px;
    background: #fff7e0;
    color: #8a6d1f;
    font-size: 13px;
    text-align: center;
    border-bottom: 1px solid #f0dfa0;
}

/* TYPING INDICATOR */
.typing-indicator {
    padding: 4px 24px;
    font-size: 12.5px;
    color: var(--text-secondary);
    font-style: italic;
}

/* RECORDING BAR */
.recording-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    background: #fff5f5;
    border-top: 1px solid var(--border);
    font-size: 14px;
}

.recording-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.recording-hint {
    flex: 1;
    color: var(--text-secondary);
}

.recording-cancel {
    color: var(--danger);
}

.recording-stop {
    color: var(--accent);
}

/* COMPOSER */
.composer {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 14px;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
}

.composer-text-form {
    flex: 1;
}

.composer-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 10px 16px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 140px;
    background: #f3f5f7;
}

.composer-input:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
}

.composer-btn {
    font-size: 21px;
}

.send-btn {
    color: var(--accent);
}

.attach-wrap {
    position: relative;
}

.attach-menu {
    position: absolute;
    bottom: 48px;
    left: 0;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 20;
    min-width: 170px;
}

.attach-menu button {
    border: none;
    background: none;
    text-align: right;
    padding: 11px 16px;
    cursor: pointer;
    font-size: 14.5px;
}

.attach-menu button:hover {
    background: #f3f5f7;
}

/* FORWARDED / REPLY PREVIEW (inside a message bubble) */
.forwarded-label {
    font-size: 12.5px;
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 4px;
}

.reply-preview {
    display: block;
    border-right: 3px solid var(--accent);
    background: rgba(39, 118, 194, 0.07);
    border-radius: 6px;
    padding: 5px 10px;
    margin-bottom: 6px;
    font-size: 13px;
}

.reply-preview-sender {
    display: block;
    color: var(--accent);
    font-weight: 600;
}

.reply-preview-snippet {
    display: block;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* REPLY BAR (above composer, while composing a reply) */
.reply-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px;
    background: #f3f5f7;
    border-top: 1px solid var(--border);
}

.reply-bar-info {
    flex: 1;
    min-width: 0;
    font-size: 13px;
}

.reply-bar-label {
    display: block;
    color: var(--accent);
    font-weight: 600;
}

.reply-bar-snippet {
    display: block;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* SHARED MESSAGE OPTIONS MENU (reply / forward / copy / edit / delete) */
.message-options-menu {
    position: fixed;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 50;
    min-width: 170px;
}

.message-options-menu button {
    border: none;
    background: none;
    text-align: right;
    padding: 11px 16px;
    cursor: pointer;
    font-size: 14.5px;
}

.message-options-menu button:hover {
    background: #f3f5f7;
}

/* FORWARD MODAL */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
    padding: 16px;
}

.modal-box {
    background: #fff;
    border-radius: 16px;
    padding: 22px;
    width: 100%;
    max-width: 380px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-box h2 {
    margin: 0 0 14px;
    font-size: 17px;
}

.caption-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    max-height: 220px;
    overflow: hidden;
    border-radius: 10px;
    background: #f3f5f7;
}

.caption-preview img,
.caption-preview video {
    max-width: 100%;
    max-height: 220px;
    border-radius: 10px;
}

.caption-preview audio {
    width: 100%;
}

.caption-preview .caption-file-name {
    padding: 16px;
    font-size: 14px;
    color: var(--text-secondary);
    word-break: break-all;
}

.caption-input {
    width: 100%;
    margin-bottom: 4px;
}

.forward-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

.forward-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 4px;
    cursor: pointer;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.modal-actions .btn {
    flex: 1;
}

/* USER PROFILE PAGE */
.profile-page {
    overflow-y: auto;
}

.profile-body {
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
    padding: 24px 16px 40px;
}

.profile-summary {
    text-align: center;
    margin-bottom: 24px;
}

.profile-summary h1 {
    font-size: 20px;
    margin: 4px 0;
}

.profile-username-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.profile-share-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
}

.profile-bio {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0;
}

.profile-bio-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
}

.profile-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.profile-tab {
    flex: 1;
    border: none;
    background: none;
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    cursor: pointer;
}

.profile-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

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

.profile-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 24px 0;
}

.profile-media-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.profile-media-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: #eee;
}

.profile-media-item img,
.profile-media-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.profile-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
    background: var(--bg-sidebar);
    border-radius: 10px;
    padding: 8px 12px;
}

.profile-list-item audio {
    flex: 1;
}

.profile-link-text {
    flex: 1;
    margin: 0;
    font-size: 14px;
    overflow-wrap: anywhere;
}

.profile-item-actions {
    display: flex;
    gap: 2px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 8px;
    padding: 2px;
}

.profile-media-item .profile-item-actions {
    position: absolute;
    bottom: 4px;
    left: 4px;
}

/* RESPONSIVE */
@media (max-width: 860px) {
    .sidebar {
        width: 100%;
        min-width: 0;
    }

    .chat-box {
        position: fixed;
        inset: 0;
        z-index: 30;
        display: none;
    }

    body.chat-active .chat-box {
        display: flex;
    }

    body.chat-active .sidebar {
        display: none;
    }

    .bubble {
        max-width: 80%;
    }
}

/* ============ CALLS ============ */

.call-log-row {
    align-self: center;
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-secondary);
    border-radius: 14px;
    padding: 6px 14px;
    font-size: 13px;
    margin: 6px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-call-buttons {
    display: flex;
    gap: 4px;
}

.incoming-call-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.incoming-call-box {
    background: var(--bg-sidebar);
    border-radius: 16px;
    padding: 28px 32px;
    text-align: center;
    min-width: 260px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.incoming-call-caller {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.incoming-call-kind {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.incoming-call-actions {
    display: flex;
    justify-content: center;
    gap: 24px;
}

.incoming-call-actions button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #fff;
}

.incoming-call-decline {
    background: var(--danger);
}

.incoming-call-accept {
    background: #2da44e;
}

.call-room {
    position: fixed;
    inset: 0;
    background: #14171c;
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 900;
}

.call-status-bar {
    text-align: center;
    padding: 14px;
    color: #cfd3da;
    font-size: 14px;
}

.call-video-grid {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    gap: 12px;
    padding: 12px;
    overflow: auto;
}

.call-video-tile {
    background: #1f242c;
    border-radius: 12px;
    overflow: hidden;
    width: min(420px, 90vw);
    aspect-ratio: 4 / 3;
}

.call-video-tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.call-video-tile-local {
    border: 2px solid var(--accent);
}

.call-controls {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 20px;
}

.call-control-btn {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: none;
    background: #2a2f38;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    transition: background .15s ease;
}

.call-control-btn:hover {
    background: #383f4a;
}

.call-control-btn.call-control-off {
    background: var(--danger);
}

.call-control-hangup {
    background: var(--danger);
    transform: rotate(135deg);
}

.call-control-hangup:hover {
    background: #a31f1f;
}
