:root {
    --bg: #1a1d21;
    --sidebar-bg: #19171d;
    --chat-bg: #222529;
    --surface: #2c2f33;
    --surface-hover: #35393e;
    --surface-active: #404449;
    --accent: #5865f2;
    --accent-hover: #4752c4;
    --accent-dim: rgba(88,101,242,0.15);
    --text: #dde1e7;
    --text-muted: #96989d;
    --text-bright: #ffffff;
    --border: rgba(255,255,255,0.07);
    --border-strong: rgba(255,255,255,0.13);
    --green: #23a559;
    --red: #f23f42;
    --yellow: #f0b132;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --font: 'DM Sans', system-ui, sans-serif;
    --font-mono: 'DM Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    overflow: hidden;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

/* ─── Auth ──────────────────────────────────────────── */
.auth-page {
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.auth-card {
    width: 380px;
    padding: 44px 40px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
}

.logo-mark {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    flex-shrink: 0;
}

.auth-logo span {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-bright);
    letter-spacing: -0.5px;
}

.auth-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 28px;
}

.input-group { margin-bottom: 16px; }

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.input-group input,
.uid-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-bright);
    font-family: var(--font);
    font-size: 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.input-group input:focus,
.uid-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.input-group input::placeholder,
.uid-input::placeholder { color: var(--text-muted); }

.auth-divider {
    text-align: center;
    position: relative;
    margin: 20px 0;
    color: var(--text-muted);
    font-size: 13px;
}

.auth-divider::before, .auth-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 42%;
    height: 1px;
    background: var(--border-strong);
}

.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }

/* ─── Buttons ───────────────────────────────────────── */
.btn-primary {
    width: 100%;
    padding: 11px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
    width: 100%;
    padding: 11px 20px;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

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

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.icon-btn:hover { color: var(--text-bright); background: var(--surface-hover); }
#logout-btn:hover { color: var(--red) !important; }

/* ─── Layout ────────────────────────────────────────── */
.messenger-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100dvh;
}

/* ─── Sidebar ───────────────────────────────────────── */
.sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.workspace-name {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-bright);
    letter-spacing: -0.3px;
}

.header-actions { display: flex; gap: 2px; }

.user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

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

.user-name {
    display: block;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.uid-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.uid-text {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}

.copy-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    border-radius: 3px;
    transition: color 0.15s;
    flex-shrink: 0;
}

.copy-btn:hover { color: var(--text-bright); }

.add-contact {
    padding: 10px 16px;
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.uid-input { flex: 1; padding: 8px 12px; font-size: 13px; }

.btn-add {
    background: var(--accent-dim);
    color: #818cf8;
    border: 1px solid rgba(88,101,242,0.3);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    transition: background 0.15s;
    flex-shrink: 0;
}

.btn-add:hover { background: rgba(88,101,242,0.25); }

/* Sidebar contact search */
.sidebar-search {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-search-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
}

.sidebar-search-inner svg { color: var(--text-muted); flex-shrink: 0; }

.sidebar-search-inner input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-bright);
    font-family: var(--font);
    font-size: 13px;
    width: 100%;
}

.sidebar-search-inner input::placeholder { color: var(--text-muted); }

.scroller {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.list-section-header {
    padding: 10px 16px 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.section-label {
    padding: 8px 16px 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

/* Chat items */
.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 7px 16px;
    background: none;
    border: none;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: background 0.1s;
    font-family: var(--font);
}

.chat-item:hover { background: var(--surface-hover); }
.chat-item.active { background: var(--accent-dim); }
.chat-item.active .chat-item-name { color: var(--text-bright); }

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

.chat-item-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 4px;
}

.chat-item-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.chat-item-preview {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    margin-top: 2px;
}

.chat-item-preview.unread { color: var(--text); font-weight: 500; }

.unread-badge {
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 999px;
    flex-shrink: 0;
    min-width: 18px;
    text-align: center;
}

/* ─── Avatar ────────────────────────────────────────── */
.avatar-wrap { position: relative; flex-shrink: 0; }

.avatar-wrap img { width: 36px; height: 36px; border-radius: var(--radius-sm); object-fit: cover; display: block; }

.avatar-initials {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: 0.5px;
}

.avatar-initials.sm { width: 32px; height: 32px; font-size: 12px; }

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--sidebar-bg);
    position: absolute;
    bottom: -1px;
    right: -1px;
}

.status-dot.online { background: var(--green); }
.status-dot.offline { background: var(--text-muted); }

/* ─── Chat viewport ─────────────────────────────────── */
.chat-viewport {
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

/* Placeholder */
.placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
}

.placeholder-icon {
    width: 72px;
    height: 72px;
    border-radius: var(--radius-lg);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.placeholder-title { font-size: 18px; font-weight: 600; color: var(--text-bright); }
.placeholder-sub { font-size: 14px; color: var(--text-muted); text-align: center; max-width: 280px; }

/* Active chat */
#active-chat-ui {
    display: flex !important;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Chat header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--chat-bg);
    flex-shrink: 0;
}

.back-btn { display: none; }

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

.chat-header-avatar img {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    display: block;
}

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

.chat-header-name {
    display: block;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-status { display: block; font-size: 12px; color: var(--green); }
.chat-header-actions { display: flex; gap: 2px; }

/* ─── Messages ──────────────────────────────────────── */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px 8px;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Date separator */
.date-sep {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 0 10px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.date-sep::before, .date-sep::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Message group */
.msg-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 4px;
    flex-shrink: 0;
}

.msg-group.sent  { align-items: flex-end; }
.msg-group.received { align-items: flex-start; }
.msg-group.condensed { margin-bottom: 1px; }

/* ─── THE FIX for letter-wrapping bug ──────────────── */
/* .msg-wrap must NOT be inline-block — it collapses and wraps each letter */
.msg-wrap {
    position: relative;
    /* block-level, but size determined by child .msg */
    display: table;   /* shrink-wraps to content width, no collapse bug */
    max-width: min(520px, 75%);
}

.msg-group.sent .msg-wrap  { align-self: flex-end; }
.msg-group.received .msg-wrap { align-self: flex-start; }

.msg {
    display: block;
    padding: 9px 14px;
    border-radius: 14px;
    font-size: 14.5px;
    line-height: 1.55;
    /* Proper word wrapping — NOT word-break:break-all which breaks mid-word */
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;   /* preserves intentional newlines */
    min-width: 48px;         /* prevents single-char bubbles collapsing */
}

.msg.sent {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg.received {
    background: var(--surface);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.msg.sent a { color: #c7d2fe; text-decoration: underline; }
.msg.received a { color: #818cf8; text-decoration: underline; }

/* Message footer */
.msg-footer {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 3px;
    padding: 0 2px;
}

.msg-time { font-size: 11px; color: var(--text-muted); }

.msg-status {
    font-size: 11px;
    color: var(--text-muted);
}

.msg-status.seen { color: #818cf8; }

.edited-label {
    font-size: 10.5px;
    color: var(--text-muted);
    font-style: italic;
}

/* ─── Reactions ─────────────────────────────────────── */
.reaction-bar {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 5px;
    padding: 0 2px;
}

.reaction-pill {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.1s, border-color 0.1s;
    color: var(--text-muted);
    font-weight: 500;
}

.reaction-pill:hover { background: var(--surface-hover); border-color: var(--accent); }
.reaction-pill.mine { border-color: var(--accent); background: var(--accent-dim); color: #818cf8; }

/* Quick react bar (hover) */
.quick-react {
    position: absolute;
    bottom: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 6px 8px;
    display: none;
    gap: 2px;
    z-index: 50;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    white-space: nowrap;
}

.msg-group.sent .quick-react  { right: 0; }
.msg-group.received .quick-react { left: 0; }

.msg-wrap:hover .quick-react { display: flex; }

.quick-react span {
    cursor: pointer;
    font-size: 18px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: background 0.1s, transform 0.1s;
}

.quick-react span:hover { background: var(--surface-hover); transform: scale(1.2); }

/* ─── Typing indicator ──────────────────────────────── */
.typing-indicator {
    padding: 6px 20px 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
    min-height: 26px;
}

.typing-dots { display: flex; gap: 3px; align-items: center; }

.typing-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: bounce 1.3s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.30s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ─── Message bar ───────────────────────────────────── */
.message-bar {
    padding: 10px 16px;
    background: var(--chat-bg);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
    position: relative;
}

.msg-input {
    flex: 1;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 14.5px;
    background: var(--surface);
    border: 1px solid transparent;
    outline: none;
    resize: none;
    max-height: 140px;
    overflow-y: auto;
    line-height: 1.5;
    color: var(--text-bright);
    font-family: var(--font);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.msg-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.msg-input::placeholder { color: var(--text-muted); }

.send-btn {
    width: 38px;
    height: 38px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
    align-self: flex-end;
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.93); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Emoji picker */
.emoji-picker {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 16px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 12px;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    width: 300px;
}

.emoji-search {
    width: 100%;
    padding: 7px 10px;
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-bright);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    margin-bottom: 8px;
}

.emoji-search:focus { border-color: var(--accent); }
.emoji-search::placeholder { color: var(--text-muted); }

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 1px;
    max-height: 180px;
    overflow-y: auto;
}

.emoji-grid span {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.1s;
}

.emoji-grid span:hover { background: var(--surface-hover); }

/* ─── Modal ─────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
}

.modal-box {
    background: var(--surface);
    padding: 28px;
    border-radius: var(--radius-lg);
    width: 400px;
    border: 1px solid var(--border-strong);
    position: relative;
    z-index: 1;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.modal-header h3 { font-size: 18px; font-weight: 600; color: var(--text-bright); }

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

.modal-actions .btn-secondary,
.modal-actions .btn-primary { flex: 1; width: auto; padding: 10px 16px; font-size: 14px; }

/* ─── Requests ──────────────────────────────────────── */
.request-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
}

.request-item .uid-preview {
    flex: 1;
    font-size: 13px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.accept-btn {
    background: rgba(35,165,89,0.15);
    color: #23a559;
    border: 1px solid rgba(35,165,89,0.3);
    border-radius: var(--radius-sm);
    padding: 5px 12px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
    flex-shrink: 0;
}

.accept-btn:hover { background: rgba(35,165,89,0.25); }

/* ─── Context menu ──────────────────────────────────── */
.msg-context-menu {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 6px;
    z-index: 500;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    min-width: 160px;
    animation: menuPop 0.1s ease;
}

@keyframes menuPop {
    from { opacity: 0; transform: scale(0.93) translateY(4px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    transition: background 0.1s;
    border: none;
    background: none;
    width: 100%;
    font-family: var(--font);
    text-align: left;
}

.ctx-item:hover { background: var(--surface-hover); color: var(--text-bright); }
.ctx-item.danger { color: var(--red); }
.ctx-item.danger:hover { background: rgba(242,63,66,0.1); color: var(--red); }
.ctx-item svg { flex-shrink: 0; opacity: 0.75; }

.ctx-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ─── Inline edit ───────────────────────────────────── */
.msg-edit-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: min(520px, 75vw);
    align-self: flex-end;
    flex-shrink: 0;
}

.msg-edit-input {
    padding: 10px 14px;
    background: var(--surface);
    border: 1.5px solid var(--accent);
    border-radius: var(--radius-md);
    color: var(--text-bright);
    font-family: var(--font);
    font-size: 14.5px;
    line-height: 1.5;
    outline: none;
    resize: none;
    width: 100%;
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.msg-edit-hint { font-size: 11px; color: var(--text-muted); padding: 0 2px; }

.msg-edit-actions { display: flex; gap: 6px; justify-content: flex-end; }

.msg-edit-actions button {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.1s;
}

.edit-save { background: var(--accent); color: #fff; }
.edit-save:hover { background: var(--accent-hover); }
.edit-cancel { background: var(--surface-hover); color: var(--text-muted); }
.edit-cancel:hover { background: var(--surface-active); color: var(--text); }

/* ─── Scroll-to-bottom button ───────────────────────── */
.scroll-to-bottom {
    position: absolute;
    bottom: 12px;
    right: 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    transition: opacity 0.2s, transform 0.15s;
    z-index: 10;
}

.scroll-to-bottom:hover { transform: scale(1.08); }

/* ─── Mobile ────────────────────────────────────────── */
@media (max-width: 768px) {
    .messenger-layout { grid-template-columns: 1fr; }
    .messenger-layout.view-chat .sidebar { display: none; }
    .messenger-layout:not(.view-chat) .chat-viewport { display: none; }
    .back-btn { display: flex !important; }
    .msg-wrap { max-width: min(300px, 82%); }
}

/* ─── Toast ─────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--surface-active);
    color: var(--text-bright);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--border-strong);
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 9999;
    white-space: nowrap;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }