/* Capy UI: the brand Capy theme (espresso and caramel from the app icon), light and dark. */

:root {
    --safe-top: env(safe-area-inset-top, 0px); /* native apps set the status bar height */
    --status-top: var(--safe-top); /* the same, kept for the call bar while the app below it drops its own */
    --primary: #5b8fd9;
    --primary-dark: #4a7bc8;
    --background: #e8e8e8;
    --surface: #d8d8d8;
    --surface-raised: #f4f4f4;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --divider: #c8c8c8;
    --border: #b0b0b0;
    --success: #10b981;
    --error: #ef4444;
    --surface-variant: #d0d0d0;
    --hover: rgba(0, 0, 0, .07);
    --message-sent: #c5ddf0;
    --message-received: #f0f0f0;
    --left-panel-bg: #d8d8d8;
    --left-header-bg: #5b8fd9;
    --right-header-bg: #d8d8d8;
    --shadow: rgba(0, 0, 0, 0.12);
    --reaction: #5ba642;
    color-scheme: light;
}

[data-theme="dark"] {
    --primary: #60a5fa;
    --primary-dark: #3b82f6;
    --background: #111827;
    --surface: #0f172a;
    --surface-raised: #1e293b;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --divider: #1f2937;
    --border: #374151;
    --success: #34d399;
    --error: #f87171;
    --surface-variant: #1e293b;
    --hover: rgba(255, 255, 255, .09);
    --message-sent: #1e3a5f;
    --message-received: #1f2937;
    --left-panel-bg: #0f172a;
    --left-header-bg: #1e3a5f;
    --right-header-bg: #0f172a;
    --shadow: rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

/* Brand theme: dark espresso surfaces, cream text and caramel accents, as in the app icon. */
[data-theme="capy"] {
    --primary: #b8723a;
    --primary-dark: #8f5528;
    --background: #2a1810;
    --surface: #24150e;
    --surface-raised: #3a2419;
    --text-primary: #f4e6d0;
    --text-secondary: #c9a888;
    --text-muted: #9a7b62;
    --divider: #3f2a1e;
    --border: #5a3d2b;
    --success: #6fbf73;
    --error: #e57368;
    --surface-variant: #3a2419;
    --hover: rgba(244, 222, 189, .08);
    --message-sent: #6b4126;
    --message-received: #3a2419;
    --left-panel-bg: #24150e;
    --left-header-bg: #381f15;
    --right-header-bg: #2e1b12;
    --shadow: rgba(0, 0, 0, .45);
    --reaction: #8fbf5a;
    color-scheme: dark;
}

/* Capy: the chat itself sits on pastel beige; lists, headers, composer and menus stay espresso. */
[data-theme="capy"] .right-panel { background: #efe4d2; }
[data-theme="capy"] .messages-container,
[data-theme="capy"] .typing-bar,
[data-theme="capy"] .right-panel .placeholder {
    --primary: #9a5a2c;
    --text-primary: #3c2217;
    --text-secondary: #7a5a45;
    --text-muted: #a88c76;
    --divider: #e0d0b8;
    --border: #cdb393;
    --hover: rgba(60, 34, 23, .07);
    --surface-variant: #f1e3cc;
    --surface-raised: #fffaf2;
    --message-sent: #e8c9a0;
    --message-received: #fffaf2;
    --shadow: rgba(60, 34, 23, .15);
    --reaction: #9a5a2c;
    color: var(--text-primary);
    color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body, #app {
    height: 100%;
    font-family: "Noto Color Emoji", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--surface);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 600; }
h2 { font-size: 16px; font-weight: 600; margin-bottom: 10px; }
h3 { font-size: 16px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .3px; }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.break { word-break: break-all; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.hint { font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.error { color: var(--error); margin-top: 8px; }

.boot { height: 100%; display: flex; align-items: center; justify-content: center; font-size: 22px; color: var(--text-secondary); }

/* ─── Controls ─── */

input, textarea, select {
    font: inherit;
    color: var(--text-primary);
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 10px;
}
button { font-family: inherit; }
input:focus, textarea:focus { outline: none; border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text-primary); }
label.check input { width: auto; }

.btn {
    font: inherit;
    border: 1px solid var(--border);
    background: var(--surface-raised);
    color: var(--text-primary);
    border-radius: 4px;
    padding: 7px 14px;
    cursor: pointer;
}
.btn:hover:not(:disabled) { filter: brightness(0.96); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { color: var(--error); }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn.wide { width: 100%; }

.icon-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.icon-btn:hover { background: rgba(127, 127, 127, 0.18); text-decoration: none; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--divider); }
.tab { font: inherit; background: none; border: none; padding: 8px 14px; cursor: pointer; color: var(--text-secondary); border-bottom: 2px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.card { background: var(--surface-raised); border-radius: 6px; padding: 18px; box-shadow: 0 1px 3px var(--shadow); }

/* ─── Auth and plain pages ─── */

.center-page { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: calc(16px + var(--safe-top)) 16px 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card form, .grid-form { display: flex; flex-direction: column; gap: 12px; }
.auth-logo { font-size: 28px; font-weight: 700; color: var(--primary); text-align: center; margin-bottom: 14px; }

.page { max-width: 900px; margin: 0 auto; padding: calc(16px + var(--safe-top)) 16px 16px; display: flex; flex-direction: column; gap: 14px; }
.page-header { display: flex; align-items: center; gap: 8px; }
.inline-form { display: flex; gap: 8px; margin-top: 8px; }
.inline-form input { flex: 1; min-width: 0; }
label.retention { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; text-align: left; }
.retention select { width: auto; min-width: 0; max-width: 62%; flex: 0 1 auto; text-overflow: ellipsis; }
.totp-qr { display: block; width: 200px; height: 200px; margin: 12px 0; border-radius: 8px; background: #fff; }
.recovery-codes { display: grid; grid-template-columns: repeat(2, max-content); gap: 6px 24px; margin: 12px 0; font-size: 15px; }
.invite-result { margin-top: 14px; padding: 12px; border: 1px dashed var(--primary); border-radius: 4px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--text-secondary); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--divider); }
.table td { padding: 6px; border-bottom: 1px solid var(--divider); }
.table tr.muted td { opacity: .55; }
.page .card { overflow-x: auto; }

/* ─── Main layout ─── */

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.left-panel {
    width: 320px;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    background: var(--left-panel-bg);
    border-right: 1px solid var(--divider);
}

.left-header {
    background: var(--left-header-bg);
    color: #fff;
    padding: var(--safe-top) 6px 0 16px;
    height: calc(56px + var(--safe-top));
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.left-header a.icon-btn { color: #fff; }
.account-link { display: flex; flex-shrink: 0; padding: 3px; margin-left: -3px; border-radius: 8px; }
.account-link:hover { background: rgba(255, 255, 255, .12); }
button.account-link { border: none; background: none; cursor: pointer; color: inherit; }

/* Account menu: slides in from the left like a phone drawer; on phones a strip of the list stays visible to tap away. */
.side-drawer {
    position: fixed; z-index: 1001; left: 0; top: 0; bottom: 0; width: 300px; max-width: 100vw;
    display: flex; flex-direction: column; overflow-y: auto;
    background: var(--surface-raised); box-shadow: 4px 0 24px rgba(0, 0, 0, .3);
    animation: drawer-in .18s ease-out;
}
@keyframes drawer-in { from { transform: translateX(-100%); } to { transform: none; } }
.drawer-head {
    display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
    padding: calc(20px + var(--safe-top, 0px)) 20px 16px; background: var(--left-header-bg); color: #fff;
}
.drawer-head .avatar { margin-bottom: 8px; }
.drawer-name { font-size: 16px; font-weight: 600; }
.drawer-username { font-size: 13px; opacity: .8; }
.drawer-item {
    display: flex; align-items: center; gap: 22px; padding: 12px 20px; font-size: 15px;
    color: var(--text-primary); text-decoration: none;
}
.drawer-item:first-of-type { margin-top: 6px; }
.drawer-item:hover { background: var(--hover); text-decoration: none; }
.drawer-item .icon { color: var(--text-secondary); }
@media (max-width: 600px) { .side-drawer { width: 85vw; } }
.conn-state { font-size: 11px; opacity: .85; margin-left: 8px; }

.search-input { width: 100%; border: none; box-shadow: 0 1px 3px var(--shadow); }
.search-bar { padding: 8px 10px; border-bottom: 1px solid var(--divider); }
.search-bar-in { animation: search-bar-in .18s ease-out; }
@keyframes search-bar-in { from { opacity: 0; transform: translateY(-100%); } }
.left-header .icon-btn.on { background: rgba(255, 255, 255, .16); }
.token-box { padding: 8px 10px; margin: 8px 0; background: var(--surface-variant); border-radius: 4px; user-select: all; }
.code-block { margin: 6px 0 0; padding: 8px 10px; background: var(--surface-variant); border-radius: 4px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.bot-head { display: flex; align-items: center; gap: 10px; }
.bot-name { font-weight: 600; }
.card h3 { margin: 14px 0 0; font-size: 14px; }
.card > a.btn { display: inline-block; margin-top: 8px; }
.no-margin { margin: 0 0 10px; }
.list-section { padding: 8px 14px 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); }
.list-note { padding: 8px 14px; text-align: center; }
.search-hit .chat-preview { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
mark { background: rgba(255, 196, 0, 0.45); color: inherit; border-radius: 2px; padding: 0 1px; }
.message-row.flash .message-bubble { animation: msg-flash 1.6s ease-out; }
@keyframes msg-flash { 0%, 30% { box-shadow: 0 0 0 3px rgba(255, 196, 0, 0.8); } 100% { box-shadow: 0 0 0 3px transparent; } }

.chat-list { flex: 1; overflow-y: auto; background: var(--background); }
.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--divider);
    color: inherit;
}
.chat-item:hover { background: var(--surface-variant); text-decoration: none; }
.chat-item.selected { background: color-mix(in srgb, var(--primary) 24%, transparent); }
.chat-content { flex: 1; min-width: 0; }
.chat-item-top, .chat-item-bottom { display: flex; align-items: center; gap: 6px; }
.chat-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-mark { color: var(--text-secondary); vertical-align: -2px; margin-right: 4px; }
.chat-mark.after { margin: 0 0 0 4px; }
.chat-time { font-size: 11px; color: var(--text-secondary); flex-shrink: 0; }
.chat-preview { flex: 1; font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.unread .chat-preview { color: var(--text-primary); }
.chat-badge { background: var(--primary); color: #fff; border-radius: 10px; min-width: 20px; padding: 0 6px; font-size: 11px; font-weight: 600; text-align: center; line-height: 20px; }
.chat-badge.muted { background: var(--text-secondary); }
.notify-banner { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface-raised); border-bottom: 1px solid var(--border); font-size: 13px; }
.notify-banner .grow { flex: 1; }
.notify-banner.warn { background: color-mix(in srgb, #f59e0b 18%, var(--surface-raised)); }
.device-settings { display: flex; flex-direction: column; gap: 12px; }
.device-setting { display: flex; align-items: center; gap: 12px; }
.device-setting .grow { flex: 1; min-width: 0; }
.device-setting-title { font-weight: 500; }
.permission-ok { color: #22c55e; display: flex; padding: 0 6px; }

.empty-state, .placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 32px; color: var(--text-secondary); text-align: center; }
.placeholder { flex: 1; }
.placeholder-icon { font-size: 44px; opacity: .6; }

/* Rounded squares, like phone app icons; the crop preview in capy-avatar.js uses the same ratio. */
.avatar {
    width: 44px;
    height: 44px;
    border-radius: 21%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
    user-select: none;
    position: relative;
    overflow: hidden;
}
.avatar.small { width: 36px; height: 36px; font-size: 13px; }
.avatar.tiny { width: 32px; height: 32px; font-size: 12px; }
.avatar.large { width: 80px; height: 80px; font-size: 28px; }
.avatar-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* A loaded picture shows on its own: a transparent one (the Capy head) has no colored square and initials behind it. */
.avatar.has-img { background: none; color: transparent; }
.avatar-wrap { position: relative; display: inline-flex; flex-shrink: 0; }
.avatar-bot {
    position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
    background: #2f80d6; color: #fff; font-size: 10px; font-weight: 700; line-height: 13px; letter-spacing: .3px;
    padding: 0 4px; border-radius: 5px; border: 1.5px solid var(--surface); pointer-events: none; white-space: nowrap;
}
.avatar-wrap.bot-s .avatar-bot { font-size: 8px; line-height: 10px; padding: 0 3px; bottom: -5px; border-width: 1px; }
.avatar-wrap.bot-l .avatar-bot { font-size: 12px; line-height: 16px; padding: 0 6px; bottom: -8px; border-width: 2px; }
.message-avatar { width: 26px; margin-right: 6px; flex-shrink: 0; align-self: flex-end; }
/* Smaller than a one-line bubble, so avatars of neighbouring runs never touch. */
.message-avatar .avatar.tiny { width: 26px; height: 26px; font-size: 10px; }

.avatar-editor { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 8px 0; }
.avatar-edit { position: relative; padding: 0; border: 0; background: none; border-radius: 21%; cursor: pointer; }
.avatar-edit:disabled { opacity: .6; cursor: default; }
.avatar-edit-badge {
    position: absolute; right: 0; bottom: 0; width: 26px; height: 26px; border-radius: 21%;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary); color: #fff; border: 2px solid var(--surface-raised);
}
.avatar-edit-side { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.chat-info-avatar { display: flex; justify-content: center; margin: 8px 0; }
.chat-info-person { text-align: center; margin-bottom: 8px; overflow-wrap: anywhere; }
.avatar.zoomable { cursor: pointer; }
.avatar.avatar-link { cursor: pointer; }
.avatar-view {
    position: fixed; inset: 0; z-index: 1100; background: rgba(0, 0, 0, .88); cursor: zoom-out;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 16px;
}
.avatar-view-img { width: min(88vw, 70vh, 512px); aspect-ratio: 1; object-fit: cover; border-radius: 21%; }
.avatar-view-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; cursor: default; }

.avatar-crop {
    position: fixed; inset: 0; z-index: 2000; padding: 16px;
    display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .7);
}
.avatar-crop-box {
    width: min(100%, 360px); padding: 16px; border-radius: 8px;
    display: flex; flex-direction: column; gap: 12px; background: var(--surface-raised);
}
.avatar-crop-box canvas { display: block; width: 100%; aspect-ratio: 1; background: #000; cursor: grab; touch-action: none; }
.avatar-crop-box input[type=range] { width: 100%; }
.avatar-crop-actions { display: flex; justify-content: flex-end; gap: 8px; }

.right-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--surface); position: relative; }

/* Chat wallpaper: a soft gradient for the theme with a faint doodle tile over it, as in Telegram.
   The tile colour is baked into each data URL (CSS variables do not reach inside an image).
   Settings can turn it off: <html data-wall="plain">. */
html:not([data-wall="plain"]) .right-panel {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220' fill='none' stroke='%231e3a5f' stroke-opacity='.13' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 40c10-14 28-14 34 0-10 10-26 10-34 0z M37 40v-12'/%3E%3Ccircle cx='120' cy='30' r='11'/%3E%3Cpath d='M120 19c2-5 6-6 9-5'/%3E%3Cpath d='M170 60c8-6 16-6 24 0s16 6 24 0 M170 72c8-6 16-6 24 0'/%3E%3Cpath d='M30 110h34a8 8 0 0 1 8 8v14a8 8 0 0 1-8 8H46l-9 8v-8h-7a8 8 0 0 1-8-8v-14a8 8 0 0 1 8-8z'/%3E%3Cpath d='M120 125c-7-8-18-2-12 8l12 11 12-11c6-10-5-16-12-8z'/%3E%3Cpath d='M186 120l4 9 10 1-8 6 3 10-9-6-9 6 3-10-8-6 10-1z'/%3E%3Ccircle cx='40' cy='186' r='6'/%3E%3Ccircle cx='28' cy='172' r='3.5'/%3E%3Ccircle cx='40' cy='166' r='3.5'/%3E%3Ccircle cx='52' cy='172' r='3.5'/%3E%3Cpath d='M112 200v-26l16-4v26 M112 200a5 4 0 1 1-1-1 M128 196a5 4 0 1 1-1-1'/%3E%3Cpath d='M168 190c0-14 10-22 22-22s22 8 22 18c0 8-6 12-14 12h-16c-8 0-14-2-14-8z M180 170l-3-6 M200 170l3-6'/%3E%3Ccircle cx='186' cy='182' r='1'/%3E%3Ccircle cx='200' cy='182' r='1'/%3E%3Cpath d='M80 70l6 6m0-6l-6 6 M150 100h8 M154 96v8 M88 160h6 M10 140h6 M13 137v6'/%3E%3C/svg%3E") 0 0 / 220px 220px,
                linear-gradient(160deg, #cfdcea 0%, #d8e3d4 50%, #e6dfcb 100%);
}
html[data-theme="dark"]:not([data-wall="plain"]) .right-panel {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220' fill='none' stroke='%23cbd5e1' stroke-opacity='.07' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 40c10-14 28-14 34 0-10 10-26 10-34 0z M37 40v-12'/%3E%3Ccircle cx='120' cy='30' r='11'/%3E%3Cpath d='M120 19c2-5 6-6 9-5'/%3E%3Cpath d='M170 60c8-6 16-6 24 0s16 6 24 0 M170 72c8-6 16-6 24 0'/%3E%3Cpath d='M30 110h34a8 8 0 0 1 8 8v14a8 8 0 0 1-8 8H46l-9 8v-8h-7a8 8 0 0 1-8-8v-14a8 8 0 0 1 8-8z'/%3E%3Cpath d='M120 125c-7-8-18-2-12 8l12 11 12-11c6-10-5-16-12-8z'/%3E%3Cpath d='M186 120l4 9 10 1-8 6 3 10-9-6-9 6 3-10-8-6 10-1z'/%3E%3Ccircle cx='40' cy='186' r='6'/%3E%3Ccircle cx='28' cy='172' r='3.5'/%3E%3Ccircle cx='40' cy='166' r='3.5'/%3E%3Ccircle cx='52' cy='172' r='3.5'/%3E%3Cpath d='M112 200v-26l16-4v26 M112 200a5 4 0 1 1-1-1 M128 196a5 4 0 1 1-1-1'/%3E%3Cpath d='M168 190c0-14 10-22 22-22s22 8 22 18c0 8-6 12-14 12h-16c-8 0-14-2-14-8z M180 170l-3-6 M200 170l3-6'/%3E%3Ccircle cx='186' cy='182' r='1'/%3E%3Ccircle cx='200' cy='182' r='1'/%3E%3Cpath d='M80 70l6 6m0-6l-6 6 M150 100h8 M154 96v8 M88 160h6 M10 140h6 M13 137v6'/%3E%3C/svg%3E") 0 0 / 220px 220px,
                radial-gradient(120% 80% at 20% 0%, #1b2a45 0%, #0f172a 60%);
}
html[data-theme="capy"]:not([data-wall="plain"]) .right-panel {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220' fill='none' stroke='%236b4126' stroke-opacity='.12' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 40c10-14 28-14 34 0-10 10-26 10-34 0z M37 40v-12'/%3E%3Ccircle cx='120' cy='30' r='11'/%3E%3Cpath d='M120 19c2-5 6-6 9-5'/%3E%3Cpath d='M170 60c8-6 16-6 24 0s16 6 24 0 M170 72c8-6 16-6 24 0'/%3E%3Cpath d='M30 110h34a8 8 0 0 1 8 8v14a8 8 0 0 1-8 8H46l-9 8v-8h-7a8 8 0 0 1-8-8v-14a8 8 0 0 1 8-8z'/%3E%3Cpath d='M120 125c-7-8-18-2-12 8l12 11 12-11c6-10-5-16-12-8z'/%3E%3Cpath d='M186 120l4 9 10 1-8 6 3 10-9-6-9 6 3-10-8-6 10-1z'/%3E%3Ccircle cx='40' cy='186' r='6'/%3E%3Ccircle cx='28' cy='172' r='3.5'/%3E%3Ccircle cx='40' cy='166' r='3.5'/%3E%3Ccircle cx='52' cy='172' r='3.5'/%3E%3Cpath d='M112 200v-26l16-4v26 M112 200a5 4 0 1 1-1-1 M128 196a5 4 0 1 1-1-1'/%3E%3Cpath d='M168 190c0-14 10-22 22-22s22 8 22 18c0 8-6 12-14 12h-16c-8 0-14-2-14-8z M180 170l-3-6 M200 170l3-6'/%3E%3Ccircle cx='186' cy='182' r='1'/%3E%3Ccircle cx='200' cy='182' r='1'/%3E%3Cpath d='M80 70l6 6m0-6l-6 6 M150 100h8 M154 96v8 M88 160h6 M10 140h6 M13 137v6'/%3E%3C/svg%3E") 0 0 / 220px 220px,
                linear-gradient(160deg, #f3e9d8 0%, #efe4d2 45%, #e6d3b8 100%);
}

.chat-view-header {
    height: calc(56px + var(--safe-top));
    display: flex;
    align-items: center;
    gap: 6px;
    padding: var(--safe-top) 12px 0;
    background: var(--right-header-bg);
    border-bottom: 1px solid var(--divider);
    flex-shrink: 0;
}
.chat-view-header-info { display: flex; align-items: center; gap: 10px; cursor: pointer; min-width: 0; }
.chat-view-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-view-header-info > .avatar { flex-shrink: 0; }
.chat-view-header-info > div:last-child { min-width: 0; }
.chat-view-sub { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back-btn { display: none; }
/* Back: a plain rounded square, as every button here, set apart from the avatar next to it. */
.nav-back {
    flex-shrink: 0; border-radius: 21%; margin-right: 6px;
    background: var(--surface-variant); color: var(--text-primary);
}
.nav-back:hover { background: var(--hover); }

.messages-container { flex: 1; overflow-y: auto; padding: 12px 20px; display: flex; flex-direction: column; gap: 2px; }
/* A line's chat has no message box: its last calls stay off the very bottom. */
.messages-container.placing { visibility: hidden; }
.messages-container.line-chat { padding-bottom: 72px; }
.messages-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); }
.load-older { text-align: center; padding: 6px; }
.day-separator { text-align: center; margin: 10px 0 6px; }
.day-separator span { background: rgba(127, 127, 127, .18); color: var(--text-secondary); font-size: 12px; padding: 2px 10px; border-radius: 10px; }

/* ─── Messages ─── */

.message-row { display: flex; }
.message-row.own { justify-content: flex-end; }
/* A new speaker: a bit more air above, so the turns of a conversation read apart; one person's run stays tight. */
.message-row.run-start { margin-top: 6px; }
.message-row.other { justify-content: flex-start; }

.message-bubble {
    position: relative;
    max-width: min(640px, 75%);
    padding: 6px 12px 4px;
    border-radius: 4px;
    word-wrap: break-word;
    box-shadow: 0 1px 1px var(--shadow);
}
.message-bubble.own { background: var(--message-sent); border-bottom-right-radius: 2px; }
.message-bubble.other { background: var(--message-received); border-bottom-left-radius: 2px; }
.message-bubble.pending { opacity: .7; }
.message-sender { font-size: 12px; font-weight: 600; margin-bottom: 2px; }
.message-forward { font-size: 12px; color: var(--text-secondary); margin-bottom: 2px; }
.message-bubble.mentioned { box-shadow: 0 0 0 1px var(--primary), 0 1px 1px var(--shadow); }
.mention { color: var(--primary-dark); font-weight: 600; }
.chat-draft { color: var(--error); }

.pinned-bar { display: flex; align-items: center; gap: 6px; padding: 4px 8px 4px 12px; background: var(--surface-raised); border-bottom: 1px solid var(--divider); }
.pinned-open { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 2px 0 2px 8px; border: 0; border-left: 2px solid var(--primary); background: none; color: inherit; text-align: left; cursor: pointer; }
.pinned-label { font-size: 12px; font-weight: 600; color: var(--primary-dark); }
.pinned-text { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-list { display: flex; flex-direction: column; gap: 2px; max-height: 60vh; overflow-y: auto; }
.pin-row { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--divider); }
.pin-row:last-child { border-bottom: 0; }
.pin-open { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 8px 4px; border: 0; background: none; color: inherit; text-align: left; cursor: pointer; border-radius: 8px; }
.pin-open:hover { background: var(--hover); }
.pin-meta { font-size: 12px; font-weight: 600; color: var(--primary-dark); }
.pin-text { font-size: 14px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.mention-list { display: flex; flex-direction: column; max-height: 240px; overflow-y: auto; border-bottom: 1px solid var(--divider); }
.mention-item { display: flex; align-items: center; gap: 8px; padding: 5px 12px; border: 0; background: none; color: inherit; text-align: left; cursor: pointer; }
.mention-item:hover, .mention-item.active { background: var(--surface-variant); }

.link-preview { display: flex; gap: 8px; margin-top: 6px; padding: 6px 8px; border-left: 2px solid var(--primary); border-radius: 2px; background: rgba(127, 127, 127, .1); color: inherit; text-decoration: none; }
.link-preview img { width: 56px; height: 56px; flex-shrink: 0; border-radius: 4px; object-fit: cover; }
.link-preview-body { display: flex; flex-direction: column; min-width: 0; font-size: 13px; }
.link-preview-site { font-size: 12px; color: var(--primary-dark); }
.link-preview-title { font-weight: 600; overflow-wrap: anywhere; }
.link-preview-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--text-secondary); }

.forward-list { max-height: 50vh; overflow-y: auto; margin-top: 8px; }
.forward-target { width: 100%; border: 0; background: none; color: inherit; text-align: left; font-size: inherit; }
.member-actions { display: flex; flex-shrink: 0; gap: 2px; color: var(--text-secondary); }
.member-actions .icon-btn { width: 36px; height: 36px; }
.member-actions .icon-btn.active { color: var(--primary); }
.member-text { min-width: 0; }
.member-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phone-line { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.error-text { color: var(--error); }
.invite-link { padding: 6px 8px; border-radius: 4px; background: var(--surface-variant); font-size: 12px; overflow-wrap: anywhere; user-select: all; }
.invite-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.join-card { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.message-content { display: flow-root; white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.message-content.muted { font-style: italic; }
.message-content code { font-family: ui-monospace, Consolas, monospace; background: rgba(127, 127, 127, .18); padding: 0 4px; border-radius: 3px; }
.message-content .code-block { background: rgba(127, 127, 127, .15); padding: 8px; border-radius: 4px; overflow-x: auto; white-space: pre; margin: 4px 0; }
.message-content .code-block code { background: none; padding: 0; }
.spoiler { background: var(--text-primary); color: transparent; border-radius: 3px; cursor: pointer; }
.spoiler.shown { background: rgba(127, 127, 127, .2); color: inherit; }
/* Text under a cut: a folded block with a quote bar, opened by its title. */
.cut { margin: 4px 0; border-left: 3px solid var(--primary); border-radius: 4px; background: rgba(127, 127, 127, .1); padding: 4px 8px; }
.cut > summary { cursor: pointer; font-weight: 500; color: var(--primary); list-style: none; user-select: none; }
.cut > summary::-webkit-details-marker { display: none; }
.cut > summary::after { content: " ▾"; }
.cut[open] > summary::after { content: " ▴"; }
.cut-body { margin-top: 4px; white-space: normal; overflow-wrap: anywhere; }
.call-note { margin: 6px 2px 0; max-width: 100%; overflow-wrap: anywhere; }

.message-footer { display: flex; align-items: center; justify-content: flex-end; gap: 6px; font-size: 11px; color: var(--text-secondary); margin-top: 2px; flex-wrap: wrap; }
.message-meta { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-style: normal; line-height: 14px; color: var(--text-secondary); white-space: nowrap; user-select: none; }
.message-content > .message-meta { float: right; margin: 7px -4px -2px 10px; }
.message-ticks { display: inline-flex; }
.message-ticks svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.message-ticks.read { color: var(--primary); }
.message-edited { font-style: italic; }

.message-quote { display: block; border-left: 3px solid var(--reaction); background: color-mix(in srgb, var(--reaction) 12%, transparent); border-radius: 2px; padding: 3px 8px; margin-bottom: 4px; color: inherit; }
.message-quote:hover { text-decoration: none; filter: brightness(.97); }
.quote-name { font-size: 12px; font-weight: 700; color: var(--reaction); }
.quote-text { font-size: 12px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.message-more {
    position: absolute;
    top: 2px;
    right: -30px;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0;
    font-size: 16px;
}
.message-row.own .message-more { right: auto; left: -30px; }
/* Chat layout setting: every message on the left. */
[data-layout="left"] .message-row.own { justify-content: flex-start; }
[data-layout="left"] .message-bubble.own { border-bottom-right-radius: 4px; border-bottom-left-radius: 2px; }
[data-layout="left"] .message-row.own .message-more { left: auto; right: -30px; }
.message-row:hover .message-more { opacity: 1; }
.message-more:hover { background: var(--surface-variant); }

.message-reactions-inline { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 8px;
    border: 1px solid var(--divider);
    border-radius: 12px;
    background: var(--surface-variant);
    color: var(--text-primary);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
}
.reaction-badge.active { border-color: var(--reaction); background: rgba(91, 166, 66, .2); }
.reaction-count { font-size: 11px; opacity: .75; }

.typing-bar { font-size: 12px; color: var(--text-secondary); padding: 2px 20px 4px; font-style: italic; }

/* Context menu (echat) */
.toast {
    position: fixed; z-index: 1002; left: 50%; bottom: 90px; transform: translateX(-50%); max-width: calc(100vw - 32px);
    padding: 10px 16px; border-radius: 6px; background: var(--surface-raised); color: var(--text-primary);
    box-shadow: 0 4px 16px rgba(0, 0, 0, .3); font-size: 14px;
}

/* Message menu: reactions on their own strip above the actions. */
.ctx-wrap { position: fixed; z-index: 1001; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; width: max-content; }
.ctx-reactions, .ctx-menu {
    background: var(--surface-raised); border: 1px solid var(--border); border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.ctx-reactions { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 4px 6px; max-width: 347px; }
.ctx-more-reactions {
    width: 30px; height: 30px; margin-left: 2px; border: none; border-radius: 6px; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; background: var(--hover); color: var(--text-secondary);
}
.ctx-menu { padding: 4px 0; min-width: 220px; }
.ctx-reaction-btn { width: 35px; height: 35px; border: none; background: transparent; cursor: pointer; font-size: 22px; border-radius: 6px; line-height: 1; }
.ctx-reaction-btn:hover { background: var(--hover); transform: scale(1.15); }
.ctx-reaction-btn.active { background: rgba(91, 166, 66, .18); }
.ctx-divider { border-top: 1px solid var(--divider); margin: 4px 0; }
.ctx-item { padding: 8px 18px 8px 16px; cursor: pointer; display: flex; align-items: center; gap: 16px; font-size: 14px; user-select: none; }
.ctx-item .icon { color: var(--text-secondary); }
.ctx-danger .icon { color: var(--error); }
.ctx-item:hover { background: var(--hover); }
.ctx-icon { width: 18px; text-align: center; }
.ctx-danger { color: var(--error); }

/* ─── Composer ─── */

.composer { flex-shrink: 0; background: var(--right-header-bg); border-top: 1px solid var(--divider); padding-bottom: env(safe-area-inset-bottom, 0px); }
.compose-strip { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-bottom: 1px solid var(--divider); }
.strip-icon { color: var(--primary); font-size: 18px; }
.strip-body { flex: 1; min-width: 0; font-size: 12px; }
.strip-body b { color: var(--primary); }
.strip-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-secondary); }
.message-input-bar { display: flex; align-items: flex-end; gap: 2px; padding: 4px 8px; }
.message-textarea, .message-textarea:focus { flex: 1; resize: none; height: 40px; padding: 9px 6px 10px; line-height: 21px; overflow-y: hidden; border: none; border-radius: 0; background: transparent; }
.icon .line { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon .solid { fill: currentColor; stroke: currentColor; stroke-width: 1.2; stroke-linejoin: round; }
.composer-btn { width: 40px; height: 40px; border-radius: 6px; color: var(--text-secondary); }
.composer-btn:hover { color: var(--primary); background: none; }
.send-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: none; border-radius: 6px; background: none; color: var(--primary); cursor: pointer; flex-shrink: 0; }
.send-btn:hover { color: var(--primary-dark); }

/* ─── Modals, toasts ─── */

.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 1000; }
.backdrop.transparent { background: transparent; }
.modal {
    position: fixed;
    z-index: 1001;
    /* centred without transform: a transform would trap fixed overlays inside (the avatar view) */
    inset: var(--safe-top) 0 0 0;
    margin: auto;
    height: fit-content;
    width: min(480px, calc(100vw - 24px));
    max-height: calc(100dvh - 24px - var(--safe-top));
    display: flex;
    flex-direction: column;
    background: var(--surface-raised);
    border-radius: 8px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 18px; }
.modal-body { padding: 4px 18px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.user-search { display: flex; flex-direction: column; gap: 6px; }
.user-results { display: flex; flex-direction: column; max-height: 280px; overflow-y: auto; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 4px; cursor: pointer; }
.user-row:hover { background: var(--surface-variant); }
.member-list .user-row { cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: color-mix(in srgb, var(--primary) 20%, transparent); border-radius: 12px; padding: 2px 4px 2px 10px; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.chip button { border: none; background: none; cursor: pointer; color: inherit; }

/* Settings: the sections as a menu beside the open one (as the chat list and a chat), screens of their own on a phone. */
.settings-title { flex: 1; font-size: 18px; font-weight: 600; margin-left: 4px; }
.settings-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.settings-me, .settings-row {
    display: flex; align-items: center; gap: 18px; width: 100%; padding: 12px 16px; font-size: 15px;
    color: var(--text-primary); text-decoration: none; border: 0; background: none; text-align: left; cursor: pointer;
}
.settings-me { gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--divider); margin-bottom: 6px; }
.settings-me .grow { display: flex; flex-direction: column; min-width: 0; }
.settings-me-name { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-me:hover, .settings-row:hover { background: var(--hover); text-decoration: none; }
.settings-me.on, .settings-row.on { background: color-mix(in srgb, var(--primary) 24%, transparent); }
.settings-row > .icon { color: var(--text-secondary); flex-shrink: 0; }
.settings-me > .icon:last-child, .settings-row > .icon:last-child { color: var(--text-secondary); opacity: .6; }
.settings-row.danger, .settings-row.danger > .icon { color: var(--error); }
.settings-row.danger { margin-top: 6px; border-top: 1px solid var(--divider); }
.settings-pane { flex: 1; width: 100%; overflow-y: auto; }
.settings-pane > * { flex-shrink: 0; } /* the pane scrolls, its cards keep their height */
.settings-pane.single > .card > h2:first-child { display: none; }
/* The page background of the other settings-like pages, not the chat wallpaper (pale under light text in the Capy theme). */
html body .app.settings-app > .right-panel { background: var(--background); }
@media (min-width: 769px) {
    .settings-back { display: none; }
    /* The profile shown beside the menu before a section is picked. */
    .settings-me.default { background: color-mix(in srgb, var(--primary) 24%, transparent); }
}
.toast { position: fixed; z-index: 1100; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text-primary); color: var(--surface-raised); padding: 10px 16px; border-radius: 6px; cursor: pointer; max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }
.toast.error { background: var(--error); color: #fff; }

/* ─── Attachments ─── */

.hidden-file-input { display: none; }
.icon-btn.small { width: 26px; height: 26px; font-size: 12px; }
.send-btn:disabled { opacity: .5; cursor: default; }

.upload-strip { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; max-height: 140px; overflow-y: auto; }
.upload-chip {
    display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 6px; width: 220px;
    border-radius: 6px; background: var(--surface-raised); border: 1px solid var(--divider);
}
.upload-chip.failed { border-color: var(--error); }
.upload-thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.upload-icon { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.upload-body { flex: 1; min-width: 0; }
.upload-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-size { font-size: 11px; color: var(--text-secondary); }
.upload-error { font-size: 11px; color: var(--error); }
.upload-progress { height: 4px; border-radius: 2px; background: var(--divider); margin-top: 4px; overflow: hidden; }
.upload-progress > div { height: 100%; background: var(--primary); transition: width .2s; }
/* A video on its way, as a message of its own in the chat. */
.video-send { width: 260px; max-width: 100%; }
.video-send-row { display: flex; align-items: center; gap: 8px; }
.video-send-row > .icon { color: var(--text-secondary); flex-shrink: 0; }
.video-send-body { flex: 1; min-width: 0; }
.video-send-body .upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.message-input-bar.recording { align-items: center; }
.record-indicator { flex: 1; display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 8px; }
.record-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--error); transition: transform .15s; }
.record-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.record-hint { color: var(--text-secondary); font-size: 13px; }

.right-panel.drop-target::after {
    content: var(--drop-hint, "Release to attach files");
    position: absolute; inset: 8px; z-index: 50; pointer-events: none;
    display: flex; align-items: center; justify-content: center; font-size: 18px; color: var(--primary);
    border: 2px dashed var(--primary); border-radius: 10px; background: color-mix(in srgb, var(--surface) 85%, transparent);
}

.message-bubble.media-only { padding: 3px; }
/* Reactions and time sit in a row under the picture, never over it. */
.message-bubble.media-only .message-footer { margin-top: 3px; padding: 0 5px 1px; }

/* A caption wider than the picture makes the bubble wider: the picture stays in the middle of it. */
.media-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; margin: 2px auto 4px; max-width: 320px; }
.media-thumb {
    padding: 0; border: none; border-radius: 4px; overflow: hidden; cursor: pointer;
    background: rgba(127, 127, 127, .2); display: block;
}
.media-grid.multi { width: 320px; max-width: 100%; }
.media-grid.multi .media-thumb { width: calc(50% - 1.5px) !important; height: 150px !important; }
.media-grid.multi.odd .media-thumb:first-child { width: 100% !important; height: 200px !important; }
.media-grid.multi.three .media-thumb { width: calc((100% - 6px) / 3) !important; height: 105px !important; }
.media-grid.single .media-thumb { position: relative; max-width: 100%; }
.media-grid.single .media-thumb img { position: absolute; inset: 0; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.message-bubble.media-only .media-grid { margin: 0 auto; }
.media-video { display: block; max-width: min(360px, 100%); max-height: 360px; border-radius: 4px; margin: 2px auto 4px; background: #000; cursor: pointer; }

.voice { --progress: 0; display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 10px; min-width: 220px; padding: 0; }
.voice-play {
    grid-row: 1 / span 2; width: 40px; height: 40px; border-radius: 21%; border: none; flex-shrink: 0; cursor: pointer;
    background: var(--primary); color: #fff; font-size: 14px;
}
.voice .voice-icon-pause, .voice.playing .voice-icon-play { display: none; }
.voice.playing .voice-icon-pause { display: inline; }
.voice-wave { display: flex; align-items: center; gap: 2px; height: 24px; cursor: pointer; position: relative; }
.voice-wave span { flex: 1; min-height: 3px; border-radius: 1px; background: var(--text-muted); }
.voice-wave span.played { background: var(--primary); }
.voice-time { font-size: 12px; line-height: 14px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

.message-bubble.meta-over .message-footer { position: relative; pointer-events: none; }
.message-bubble.meta-over .voice + .message-footer { margin-top: -14px; }
.message-bubble.meta-over .file-card { min-width: 240px; margin: 0; }
.message-bubble.meta-over .file-card + .message-footer { margin-top: -14px; }
.message-bubble.meta-over .call-record { min-width: 230px; }
.message-bubble.meta-over .call-record + .message-footer { margin-top: -14px; }
/* Voice and call rows: the circle sits the same distance from the top, bottom and left edge. */
.message-bubble:has(.voice), .message-bubble:has(> .call-record), .message-bubble.meta-over:has(.file-card:not(.audio)) { padding: 8px 12px 8px 8px; }

/* A file is a row inside the bubble, like voice and call rows: no box of its own, the time stays on the bubble. */
.file-card {
    display: flex; align-items: center; gap: 10px; margin: 2px 0; min-width: 220px;
    background: none; color: inherit; text-decoration: none;
}
button.file-card { border: none; padding: 0; font: inherit; text-align: left; cursor: pointer; width: 100%; }
.file-card:hover { text-decoration: none; }
.file-card:hover .file-icon { filter: brightness(1.12); }
.file-card.audio { flex-direction: column; align-items: stretch; }
.file-card audio { width: 100%; height: 36px; }
.file-icon {
    width: 40px; height: 40px; border-radius: 21%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center; background: var(--primary); color: #fff;
}
.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.file-size { font-size: 12px; color: var(--text-secondary); }

.lightbox {
    position: fixed; inset: 0; z-index: 1000; background: rgba(0, 0, 0, .9); padding-top: var(--safe-top);
    display: flex; align-items: center; justify-content: center; outline: none;
}
.lightbox-img { max-width: 96vw; max-height: calc(100vh - 80px); object-fit: contain; cursor: default; user-select: none; -webkit-user-drag: none; will-change: transform; }
.lightbox-bar {
    position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px;
    padding: calc(8px + var(--safe-top)) 12px 8px; color: #fff; background: linear-gradient(rgba(0, 0, 0, .6), transparent); z-index: 1;
}
.lightbox-bar .icon-btn { color: #fff; min-width: 44px; min-height: 44px; font-size: 22px; }
.lightbox-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lightbox-count { color: #ccc; font-size: 13px; }
.lightbox-nav {
    position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 64px; border: none;
    background: rgba(255, 255, 255, .1); color: #fff; font-size: 36px; cursor: pointer; border-radius: 6px;
}
.lightbox-nav:hover { background: rgba(255, 255, 255, .2); }
.lightbox-nav.prev { left: 12px; }
.lightbox-nav.next { right: 12px; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: 10px 16px; background: #fee2e2; color: #7f1d1d; z-index: 2000; }
#blazor-error-ui .reload { margin-left: 8px; }

/* ─── Calls ─── */

.chat-view-actions { margin-left: auto; display: flex; gap: 2px; color: var(--text-secondary); }
.chat-view-actions .icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.icon { flex-shrink: 0; }

.call-overlay {
    position: fixed; inset: 0; z-index: 1500;
    display: flex; flex-direction: column; align-items: center; justify-content: space-between;
    padding: max(48px, var(--safe-top)) 16px max(32px, env(safe-area-inset-bottom));
    background: radial-gradient(circle at 50% 30%, #2b3f5c, #0b1220 75%);
    color: #fff; overflow: hidden;
}
[data-theme="capy"] .call-overlay { background: radial-gradient(circle at 50% 30%, #5a3824, #1a0f0a 75%); }
.call-overlay.ended .call-status { color: #fca5a5; }
/* The whole frame stays visible: a phone's portrait picture must not be cropped to a wide window. */
.call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
/* Audio-only: the element still plays the peer's sound, it is just not seen. */
.call-remote.audio-only { width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.call-local {
    position: absolute; z-index: 2; right: 16px; top: max(16px, var(--safe-top));
    width: 28vw; max-width: 220px; min-width: 96px; aspect-ratio: 3 / 4; object-fit: cover;
    border-radius: 10px; background: #111; box-shadow: 0 6px 24px rgba(0, 0, 0, .5); transform: scaleX(-1);
}
.call-info { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 6vh; text-align: center; }
.call-overlay.with-video .call-info { margin-top: 0; align-self: flex-start; align-items: flex-start; text-shadow: 0 1px 4px rgba(0, 0, 0, .8); }
.avatar.huge { width: 112px; height: 112px; font-size: 40px; }
.call-number { margin-top: 6px; font-size: 17px; color: var(--text-secondary); }
.avatar.pulse { animation: call-pulse 1.6s ease-out infinite; }
@keyframes call-pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .35); }
    100% { box-shadow: 0 0 0 28px rgba(255, 255, 255, 0); }
}
.call-name { font-size: 24px; font-weight: 600; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-status { font-size: 15px; color: rgba(255, 255, 255, .75); font-variant-numeric: tabular-nums; }
.call-controls { position: relative; z-index: 1; display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; }
.call-btn {
    width: 64px; height: 64px; border-radius: 21%; border: none; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .18); color: #fff; backdrop-filter: blur(6px);
    transition: transform .1s, background .15s;
}
.call-btn:hover { background: rgba(255, 255, 255, .28); }
.call-devices {
    position: absolute; z-index: 2; left: 50%; bottom: 120px; transform: translateX(-50%);
    width: min(440px, calc(100vw - 32px)); padding: 14px 16px; border-radius: 8px;
    background: var(--surface-raised); color: var(--text-primary); box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}
.media-devices { display: flex; flex-direction: column; gap: 8px; }
.call-keypad { width: min(300px, calc(100vw - 32px)); }
.keypad-typed { min-height: 28px; text-align: center; font-size: 20px; letter-spacing: 2px; overflow: hidden; white-space: nowrap; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad-key {
    height: 52px; border: none; border-radius: 8px; font-size: 22px; cursor: pointer;
    background: var(--surface); color: var(--text-primary);
}
.keypad-key:hover { background: var(--hover); }
.keypad-key:active { transform: scale(.96); }
/* The phone page: keypad with contact hits above it, contacts and recent numbers. */
.phone-page { max-width: 520px; }
.phone-page .tabs { margin-bottom: 0; }
.phone-page .tab { flex: 1; }
.phone-line-pick { max-width: 45%; min-width: 0; text-overflow: ellipsis; }
.dialer { width: min(340px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 6px; }
.dial-display { display: flex; }
.dial-number {
    flex: 1; min-width: 0; text-align: center; font-size: 28px; letter-spacing: 1px; padding: 6px 0;
    border: none; background: none; color: var(--text-primary); outline: none;
}
.dial-who { min-height: 22px; text-align: center; color: var(--text-secondary); align-self: center; }
.dial-suggest { height: 144px; overflow: hidden; display: flex; flex-direction: column; gap: 2px; }
.dial-hit {
    display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 2px; min-width: 0; height: 46px; flex-shrink: 0; padding: 3px 10px;
    border: none; border-radius: 8px; background: none; color: var(--text-primary); font: inherit; text-align: left; cursor: pointer;
}
.dial-hit:hover { background: var(--hover); }
.dial-hit .member-line { max-width: 100%; }
/* Two lines in a fixed row: their own line heights, so the name is never cut by the number under it. */
.dial-hit .member-line { line-height: 20px; }
.dial-hit .small { line-height: 16px; }
.dial-keypad .keypad-key { height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; user-select: none; touch-action: manipulation; }
.key-digit { font-size: 24px; line-height: 1.1; }
.key-letters { font-size: 10px; letter-spacing: 1px; color: var(--text-secondary); min-height: 12px; }
.dial-actions { display: grid; grid-template-columns: repeat(3, 1fr); align-items: center; justify-items: center; margin-top: 6px; }
.dial-call {
    width: 64px; height: 64px; border-radius: 21%; border: none; cursor: pointer;
    background: #22c55e; color: #fff; display: flex; align-items: center; justify-content: center;
}
.dial-call:hover:not(:disabled) { background: #16a34a; }
.dial-call:disabled { opacity: .45; cursor: default; }
.phone-tools { display: flex; align-items: center; gap: 4px; }
.phone-tools input { min-width: 0; }
.contact-phone-row { display: flex; align-items: center; gap: 6px; }
.contact-phone-row input { min-width: 0; }
.contact-label { width: 30%; }
.media-devices select { width: 62%; min-width: 0; text-overflow: ellipsis; }
.media-check { display: flex; align-items: center; gap: 10px; }
.media-level { flex: 1; height: 6px; border-radius: 3px; overflow: hidden; background: var(--surface-variant); }
.media-level[hidden] { display: none; }
.media-level span { display: block; width: 0; height: 100%; background: var(--primary); transition: width .06s linear; }
.media-preview { width: 100%; max-width: 320px; border-radius: 6px; background: #000; transform: scaleX(-1); }
.media-preview[hidden] { display: none; }
.call-btn:active { transform: scale(.94); }
.call-local.back { transform: none; }
/* Clear of the status bar (a tap at its edge pulls the system shade instead) and big enough for a thumb. */
.call-minimize {
    position: absolute; z-index: 3; left: 8px; top: calc(var(--safe-top) + 10px);
    width: 48px; height: 48px; display: flex; align-items: center; justify-content: center;
    color: #fff; touch-action: manipulation;
}
.call-overlay.with-video .call-info { padding-left: 44px; }

/* Minimized call: a bar on top, the app goes on below it. */
.call-overlay.minimized {
    inset: 0 0 auto 0; height: calc(44px + var(--status-top)); padding: var(--status-top) 8px 0 12px;
    flex-direction: row; align-items: center; justify-content: flex-start; gap: 8px;
    background: var(--primary); box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.call-overlay.minimized .call-remote, .call-overlay.minimized .call-local {
    position: absolute; width: 1px; height: 1px; min-width: 0; opacity: 0; pointer-events: none;
}
.call-bar { flex: 1; min-width: 0; height: 100%; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.call-bar-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 1; }
.call-bar-status { font-size: 13px; opacity: .85; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 2; }
.call-bar-btn {
    width: 36px; height: 36px; flex-shrink: 0; border: none; border-radius: 6px; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, .2); color: #fff;
}
.call-bar-btn.off { background: #fff; color: #1e293b; }
.call-bar-btn.decline { background: #ef4444; }
body:has(.call-overlay.minimized) { padding-top: calc(44px + var(--status-top)); --safe-top: 0px; }
body:has(.call-overlay.minimized) .app { height: calc(100dvh - 44px - var(--status-top)); }
@media (max-width: 420px) {
    .call-controls { gap: 12px; }
    .call-btn { width: 56px; height: 56px; }
}
.call-outputs { display: flex; flex-direction: column; gap: 4px; width: min(300px, calc(100vw - 32px)); padding: 8px; }
.call-output {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: none; border-radius: 6px;
    background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.call-output:hover { background: var(--hover); }
.call-output.current { color: var(--primary); font-weight: 600; }
.call-btn.off { background: #fff; color: #1e293b; }
.call-btn.on { background: var(--primary); }
.call-btn.on:hover { background: var(--primary-dark); }
.call-btn.accept { background: #22c55e; }
.call-btn.accept:hover { background: #16a34a; }
.call-btn.decline { background: #ef4444; }
.call-btn.decline:hover { background: #dc2626; }

/* Group calls: tiles laid out by participant count, filled by capy-groupcall.js. */
.call-overlay.group-call { justify-content: flex-start; gap: 14px; padding-top: max(20px, var(--safe-top)); }
.gc-head { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.unread-seen .unread-separator { display: none; }
.call-overlay.group-call.minimized { padding-top: var(--status-top); gap: 8px; }
.gc-hidden { display: none !important; }
.gc-grid {
    flex: 1; width: 100%; max-width: 1200px; min-height: 0;
    display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); grid-auto-rows: minmax(140px, 1fr);
    align-content: center; overflow-y: auto;
}
.gc-grid[data-count="1"] { grid-template-columns: minmax(0, 720px); justify-content: center; }
.gc-grid[data-count="2"] { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.gc-tile {
    position: relative; border-radius: 14px; overflow: hidden; background: rgba(255, 255, 255, .08);
    display: flex; align-items: center; justify-content: center; min-height: 140px;
    outline: 3px solid transparent; outline-offset: -3px; transition: outline-color .15s;
}
.gc-tile.speaking { outline-color: #22c55e; }
.gc-tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: none; background: #000; }
.gc-tile.with-video video { display: block; }
.gc-tile.local video { transform: scaleX(-1); }
.gc-tile.screen { grid-column: 1 / -1; }
.gc-avatar {
    width: 84px; height: 84px; border-radius: 21%; background: var(--primary-dark); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 600;
}
.gc-tile.with-video .gc-avatar { display: none; }
.gc-avatar { overflow: hidden; }
.gc-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gc-unmute {
    align-self: center; margin: 0 auto 8px; padding: 8px 16px; border: 0; border-radius: 18px;
    background: #fff; color: #111; font-weight: 600; cursor: pointer;
}
.gc-name {
    position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px); padding: 3px 8px; border-radius: 8px;
    background: rgba(0, 0, 0, .55); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: flex; gap: 4px; align-items: center;
}
.group-call-banner {
    display: flex; align-items: center; gap: 10px; padding: 8px 14px;
    background: color-mix(in srgb, #22c55e 18%, var(--surface-raised)); border-bottom: 1px solid var(--border); color: var(--text-primary);
}
.group-call-banner.error { background: color-mix(in srgb, #ef4444 15%, var(--surface-raised)); }
.group-call-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }

.call-record {
    display: flex; align-items: center; gap: 10px; padding: 0 4px 0 0; min-width: 190px;
    background: none; border: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.call-record:disabled { cursor: default; }
.call-record-icon {
    width: 40px; height: 40px; border-radius: 21%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--success); color: #fff;
}
.call-record.missed .call-record-icon { background: var(--error); }
.call-record-title { display: block; font-weight: 600; }
.call-record.missed .call-record-title { color: var(--error); }
.call-record-sub { display: block; font-size: 12px; color: var(--text-secondary); }

/* A phone line's call record: the other side's picture, name and number, then direction, duration and time. */
.message-bubble:has(> .phone-record) { padding: 8px 10px 6px 8px; }
.phone-record {
    display: flex; align-items: flex-start; gap: 10px; min-width: 220px; max-width: 100%; padding: 0;
    background: none; border: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.phone-record:disabled { cursor: default; }
/* The call's recording: one compact row under the call, the time at its end. */
.phone-record + .voice { margin-top: 8px; grid-template-columns: auto 1fr auto; min-width: 0; }
.phone-record + .voice .voice-play { grid-row: 1; width: 32px; height: 32px; font-size: 12px; }
.phone-record + .voice .voice-wave { grid-row: 1; grid-column: 2; }
.phone-record + .voice .voice-time { grid-row: 1; grid-column: 3; }
.phone-record .avatar.phone-record-avatar { width: 36px; height: 36px; font-size: 14px; flex-shrink: 0; }
.avatar.phone-unknown { background: var(--text-muted); color: #fff; }
.phone-record-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.phone-record-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phone-record-number { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
.phone-record-row { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 13px; color: var(--text-secondary); }
.phone-record-outcome { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phone-record-row .message-meta { margin-left: 8px; flex-shrink: 0; }
.phone-dir { flex-shrink: 0; }
.phone-dir.call-in { color: #34d399; }
.phone-dir.call-out { color: #60a5fa; }
.phone-dir.call-missed { color: #f87171; }

/* ─── Mobile: one panel at a time ─── */

/* Admin users: a table with icon toggles on wide screens, a list with a card per user on phones. */
@media (min-width: 769px) { .users-narrow { display: none; } }
@media (max-width: 768px) { .users-wide { display: none; } }

@media (max-width: 768px) {
    .left-panel { width: 100%; min-width: 0; border-right: none; }
    .app.has-chat .left-panel { display: none; }
    .app.no-chat .right-panel { display: none; }
    .back-btn { display: inline-flex; }
    .messages-container { padding: 10px; }
    .message-bubble { max-width: 85%; }
    .message-more { display: none; }
}

/* Avatar colours (echat palette); "-text" variants colour sender names. */
.avatar-color-0 { background: #5b8fd9; } .avatar-color-0-text { color: #5b8fd9; }
.avatar-color-1 { background: #e07a5f; } .avatar-color-1-text { color: #e07a5f; }
.avatar-color-2 { background: #81b29a; } .avatar-color-2-text { color: #4f8a6d; }
.avatar-color-3 { background: #f2cc8f; color: #333; } .avatar-color-3-text { color: #c08a2e; }
.avatar-color-4 { background: #9b5de5; } .avatar-color-4-text { color: #9b5de5; }
.avatar-color-5 { background: #00bbf9; } .avatar-color-5-text { color: #0096c7; }
.avatar-color-6 { background: #f15bb5; } .avatar-color-6-text { color: #d6409f; }
.avatar-color-7 { background: #fee440; color: #333; } .avatar-color-7-text { color: #b59f00; }
.avatar-color-8 { background: #00f5d4; color: #333; } .avatar-color-8-text { color: #00a88f; }
.avatar-color-9 { background: #99c2b2; } .avatar-color-9-text { color: #5f8f7c; }
.avatar-color-10 { background: #d4a373; } .avatar-color-10-text { color: #b07a44; }
.avatar-color-11 { background: #a8dadc; color: #333; } .avatar-color-11-text { color: #4c9a9e; }
.avatar-color-12 { background: #e9c46a; color: #333; } .avatar-color-12-text { color: #b08f2a; }
.avatar-color-13 { background: #2a9d8f; } .avatar-color-13-text { color: #2a9d8f; }
.avatar-color-14 { background: #e76f51; } .avatar-color-14-text { color: #e76f51; }
.avatar-color-15 { background: #606c38; } .avatar-color-15-text { color: #7a8a45; }

/* Secret chats */
.safety-code {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 17px; letter-spacing: .5px; line-height: 1.6;
    display: grid; grid-template-columns: repeat(4, max-content); gap: 2px 14px; margin: 6px 0;
}

/* Composer: emoji picker and formatting bar */
.composer { position: relative; }
.emoji-picker {
    position: absolute; right: 8px; bottom: calc(100% + 6px); z-index: 1001; display: flex; flex-direction: column;
    width: min(372px, calc(100% - 16px)); height: min(440px, 62vh); background: var(--surface-raised);
    border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); overflow: hidden;
}
.emoji-search { display: flex; align-items: center; gap: 4px; padding: 8px 8px 4px; }
.emoji-search-input, .emoji-search-input:focus { flex: 1; min-width: 0; height: 34px; padding: 0 12px; border: none; border-radius: 17px; background: var(--surface-variant); }
.emoji-close { width: 30px; height: 30px; border: none; border-radius: 6px; background: none; color: var(--text-secondary); cursor: pointer; flex-shrink: 0; }
.emoji-close:hover { background: var(--surface-variant); }
.emoji-scroll { flex: 1; min-height: 0; position: relative; overflow-y: auto; padding: 0 6px 6px; }
.emoji-section { content-visibility: auto; }
.emoji-section[hidden] { display: none; }
.emoji-title { margin: 0; padding: 10px 6px 4px; font-size: 13px; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--text-secondary); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); }
.emoji-item { height: 38px; padding: 0; border: none; border-radius: 8px; background: none; font-size: 26px; line-height: 1; cursor: pointer; -webkit-touch-callout: none; user-select: none; }
.emoji-item:hover { background: var(--surface-variant); }
.emoji-empty { padding: 28px 8px; text-align: center; color: var(--text-secondary); }
.emoji-empty[hidden] { display: none; }
.emoji-tabs { display: flex; justify-content: space-between; padding: 3px 6px; border-top: 1px solid var(--border); }
.emoji-tab { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 32px; border: none; border-radius: 8px; background: none; color: var(--text-secondary); cursor: pointer; }
.emoji-tab:hover { background: var(--surface-variant); }
.emoji-tab.active { color: var(--primary); background: var(--surface-variant); }
.emoji-tones { position: absolute; z-index: 2; display: flex; padding: 3px; background: var(--surface-raised); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 4px 16px rgba(0, 0, 0, .25); }
.emoji-tones .emoji-item { width: 38px; }
.format-bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px 12px 0; }
.format-btn { min-width: 34px; height: 30px; padding: 0 6px; border: none; border-radius: 4px; background: none; color: inherit; font-size: 14px; cursor: pointer; }
.format-btn:hover { background: var(--surface-variant); }
.format-btn.bold { font-weight: 700; }
.format-btn.italic { font-style: italic; }
.format-btn.strike { text-decoration: line-through; }
.format-btn.underline { text-decoration: underline; }
.format-btn.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.format-btn.spoiler-mark::first-letter { background: var(--text-primary); color: var(--surface-raised); }

/* Code blocks: highlight.js tokens, github-dark palette */
.message-content pre.code-block { background: #0d1117; color: #c9d1d9; border: 1px solid #30363d; line-height: 1.4; }
.message-content pre.code-block code { color: inherit; }
.code-block .hljs-doctag, .code-block .hljs-keyword, .code-block .hljs-meta .hljs-keyword, .code-block .hljs-template-tag,
.code-block .hljs-template-variable, .code-block .hljs-type, .code-block .hljs-variable.language_ { color: #ff7b72; }
.code-block .hljs-title, .code-block .hljs-title.class_, .code-block .hljs-title.class_.inherited__, .code-block .hljs-title.function_ { color: #d2a8ff; }
.code-block .hljs-attr, .code-block .hljs-attribute, .code-block .hljs-literal, .code-block .hljs-meta, .code-block .hljs-number,
.code-block .hljs-operator, .code-block .hljs-selector-attr, .code-block .hljs-selector-class, .code-block .hljs-selector-id, .code-block .hljs-variable { color: #79c0ff; }
.code-block .hljs-meta .hljs-string, .code-block .hljs-regexp, .code-block .hljs-string { color: #a5d6ff; }
.code-block .hljs-built_in, .code-block .hljs-symbol { color: #ffa657; }
.code-block .hljs-code, .code-block .hljs-comment, .code-block .hljs-formula { color: #8b949e; font-style: italic; }
.code-block .hljs-name, .code-block .hljs-quote, .code-block .hljs-selector-pseudo, .code-block .hljs-selector-tag { color: #7ee787; }
.code-block .hljs-section { color: #1f6feb; font-weight: 700; }
.code-block .hljs-bullet { color: #f2cc60; }
.code-block .hljs-emphasis { font-style: italic; }
.code-block .hljs-strong { font-weight: 700; }
.code-block .hljs-addition { color: #aff5b4; background: #033a16; }
.code-block .hljs-deletion { color: #ffdcd7; background: #67060c; }

/* ─── Scheduled messages ─── */

.send-menu { position: absolute; right: 8px; bottom: calc(100% + 6px); z-index: 1001; }
.scheduled-bar {
    display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 14px; border: none; border-top: 1px solid var(--divider);
    background: var(--right-header-bg); color: var(--primary); font: inherit; font-size: 13px; cursor: pointer; text-align: left;
}
.scheduled-bar:hover { background: var(--hover); }
.scheduled-failed { color: var(--error); margin-left: auto; }
.schedule-quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.schedule-when { width: 100%; }
.schedule-text { width: 100%; margin-bottom: 12px; resize: vertical; }
.scheduled-list { display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow-y: auto; }
.scheduled-item { display: flex; align-items: center; gap: 2px; padding: 6px 0; border-bottom: 1px solid var(--divider); }
.scheduled-item:last-child { border-bottom: none; }
.scheduled-body { flex: 1; min-width: 0; }
.scheduled-when { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--primary); }
.scheduled-item.failed .scheduled-when { color: var(--error); }
.scheduled-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn.danger { color: var(--error); }

/* ─── Message selection, unread mark ─── */

.message-row.selecting { position: relative; padding-left: 34px; }
.message-row.selected { background: color-mix(in srgb, var(--primary) 14%, transparent); }
.select-hit { position: absolute; inset: 0; z-index: 2; cursor: pointer; }
.select-mark {
    position: absolute; left: 8px; top: 50%; width: 20px; height: 20px; margin-top: -10px;
    border: 2px solid var(--text-secondary); border-radius: 50%; box-sizing: border-box;
}
.message-row.selected .select-mark { background: var(--primary); border-color: var(--primary); box-shadow: inset 0 0 0 3px var(--surface); }
.select-header { gap: 8px; }
.select-count { flex: 1; font-weight: 600; }
.chat-badge.marked { min-width: 12px; width: 12px; height: 12px; padding: 0; }

/* ─── Jump buttons over the message list ─── */

.scroll-fabs { position: sticky; bottom: 4px; height: 0; order: 99; z-index: 3; align-self: flex-end; }
.scroll-fab {
    position: absolute; right: -8px; width: 42px; height: 42px; border-radius: 21%; border: 1px solid var(--border);
    background: var(--surface-raised); color: var(--text-secondary); box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
    display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 18px; font-weight: 600;
}
.scroll-fab.down { bottom: 0; display: none; }
.messages-container.scrolled-up .scroll-fab.down { display: flex; }
.scroll-fab.mention { bottom: 0; color: var(--primary); }
.messages-container.scrolled-up .scroll-fab.mention { bottom: 50px; }
.unread-separator span { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }

.chat-search-input { flex: 1; min-width: 0; }
.search-count { flex-shrink: 0; min-width: 28px; text-align: center; }

/* ─── Shared media, person card ─── */

.shared-open { display: flex; align-items: center; gap: 8px; width: 100%; justify-content: center; margin-bottom: 12px; }
.shared-tabs { display: flex; gap: 4px; margin-bottom: 10px; border-bottom: 1px solid var(--divider); }
.shared-tab { flex: 1; padding: 8px 4px; border: none; background: none; color: var(--text-secondary); font: inherit; cursor: pointer; border-bottom: 2px solid transparent; }
.shared-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.shared-body { max-height: 60vh; overflow-y: auto; }
.shared-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.shared-cell { position: relative; aspect-ratio: 1; border: none; padding: 0; background: var(--hover); cursor: pointer; overflow: hidden; }
.shared-cell img, .shared-cell video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.shared-cell .shared-video { position: absolute; left: 4px; bottom: 4px; font-size: 11px; color: #fff; background: rgba(0, 0, 0, .55); border-radius: 4px; padding: 1px 5px; }
.shared-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 4px; border: none; border-bottom: 1px solid var(--divider); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.shared-row:hover { background: var(--hover); }
.shared-row .grow { min-width: 0; }
.shared-row .shared-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clickable { cursor: pointer; }
.person-card { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 12px; text-align: center; }
.person-name { font-size: 18px; font-weight: 600; }

/* ─── Polls ─── */

.attach-menu { position: absolute; left: 8px; bottom: calc(100% + 6px); z-index: 1001; }
.link-btn { border: none; background: none; padding: 4px 0; color: var(--primary); font: inherit; cursor: pointer; }
.link-btn.small { font-size: 12px; }
.link-btn:disabled { opacity: .5; cursor: default; }
.poll-check { margin-top: 8px; }
.poll-input { width: 100%; box-sizing: border-box; }
.poll-label { margin: 12px 0 4px; }
.poll-edit-row { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.poll-edit-row .poll-input { flex: 1; min-width: 0; }
.poll { min-width: min(260px, 62vw); padding: 2px 0; }
.poll-question { font-weight: 600; word-break: break-word; }
.poll-kind { margin-bottom: 8px; }
.poll-option { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 4px; border: none; border-top: 1px solid var(--divider); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.poll-option:disabled { opacity: .6; }
.poll-mark { flex-shrink: 0; width: 18px; height: 18px; border: 2px solid var(--primary); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; color: var(--primary); }
.poll-mark.square { border-radius: 4px; }
.poll-result { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0; }
.poll-share { flex-shrink: 0; width: 38px; text-align: right; font-size: 13px; font-weight: 600; }
.poll-bar-wrap { flex: 1; min-width: 0; }
.poll-option-text { word-break: break-word; }
.poll-bar { height: 4px; margin-top: 3px; border-radius: 2px; background: var(--primary); opacity: .55; }
.poll-result.mine .poll-bar { opacity: 1; }
.poll-footer { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; }

/* ─── Location and contact cards ─── */

.location-card, .contact-card { display: flex; align-items: center; gap: 10px; min-width: min(220px, 60vw); padding: 8px 10px; margin: 2px 0 4px; border: 1px solid var(--divider); border-radius: 8px; background: var(--hover); color: inherit; font: inherit; text-align: left; text-decoration: none; cursor: pointer; }
.contact-card:disabled { cursor: default; opacity: 1; }
.location-pin { font-size: 26px; line-height: 1; }
.location-card > span:last-child, .contact-text { display: flex; flex-direction: column; min-width: 0; }
.location-title, .contact-name { font-weight: 600; }
.contact-text { flex: 1; }
.contact-text > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-action { flex-shrink: 0; font-size: 12px; color: var(--primary); }
.location-preview { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-bottom: 10px; }
.location-coords { font-variant-numeric: tabular-nums; }

/* Yes/no question (capy.confirm): above every other window. */
.confirm-backdrop { z-index: 3000; }
.modal.confirm-dialog { z-index: 3001; max-width: min(380px, calc(100vw - 32px)); padding: 18px; }
.confirm-text { margin-bottom: 14px; white-space: pre-line; line-height: 1.4; }

/* ─── Video messages ─── */

.video-note-recorder { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.video-note-frame { position: relative; width: min(260px, 70vw); aspect-ratio: 1; }
.video-note-frame video { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; background: #000; transform: scaleX(-1); }
.video-note-ring { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); transform: rotate(-90deg); pointer-events: none; }
.video-note-ring circle { fill: none; stroke: var(--primary); stroke-width: 2; stroke-dasharray: 301.6; transition: stroke-dashoffset .2s linear; }
.video-note { position: relative; width: min(220px, 60vw); aspect-ratio: 1; margin: 2px 0 4px; cursor: pointer; }
.video-note video { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; background: #000; display: block; }
.video-note-time { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); font-size: 11px; color: #fff; background: rgba(0, 0, 0, .55); border-radius: 8px; padding: 1px 6px; }

/* ─── Stickers ─── */

.picker-pop { position: absolute; right: 8px; bottom: calc(100% + 6px); z-index: 1001; width: min(372px, calc(100% - 16px)); display: flex; flex-direction: column;
    background: var(--surface-raised); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); overflow: hidden; }
.picker-pop .emoji-picker { position: static; width: 100%; border: none; border-radius: 0; box-shadow: none; }
.picker-tabs { display: flex; border-bottom: 1px solid var(--divider); }
.sticker-panel { height: min(440px, 62vh); overflow-y: auto; padding: 0 6px 6px; }
.sticker-empty { padding: 16px 8px; }
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.sticker-cell { aspect-ratio: 1; padding: 4px; border: none; border-radius: 8px; background: none; cursor: pointer; }
.sticker-cell:hover { background: var(--surface-variant); }
.sticker-cell img { width: 100%; height: 100%; object-fit: contain; }
.sticker-image { display: block; width: min(160px, 45vw); height: min(160px, 45vw); object-fit: contain; }
.admin-stickers { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; margin-top: 8px; }
.admin-sticker { position: relative; aspect-ratio: 1; border-radius: 8px; background: var(--surface-variant); }
.admin-sticker img { width: 100%; height: 100%; object-fit: contain; }
.admin-sticker .icon-btn { position: absolute; top: 0; right: 0; width: 24px; height: 24px; font-size: 12px; }

/* ─── Archive ─── */

/* Hidden chats: pulled out of the list's top. The hint shows above the list while it is pulled. */
.chat-list { position: relative; z-index: 1; }
.hidden-head { display: flex; align-items: center; gap: 6px; }
.pull-hint { position: relative; height: 0; z-index: 0; }
.pull-hint > span { position: absolute; left: 0; right: 0; top: 0; height: 56px; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.pull-hint:has(+ .chat-list.pull-armed) > span { color: var(--primary); }

/* Chat folder tabs over the chat list; they scroll sideways when there are many. */
.folder-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding: 0 8px; border-bottom: 1px solid var(--divider); flex-shrink: 0; }
.folder-tabs::-webkit-scrollbar { display: none; }
.folder-tab { font: inherit; font-size: 14px; background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 10px; cursor: pointer; color: var(--text-secondary); white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }
.folder-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.folder-count { font-size: 11px; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--text-secondary); color: var(--bg, #000); text-align: center; line-height: 18px; }
.folder-tab.active .folder-count { background: var(--primary); }
.folder-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.folder-form { display: flex; flex-direction: column; gap: 10px; }
.folder-chats { max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.folder-chat { padding: 4px 0; min-width: 0; }
.folder-chat .member-line { min-width: 0; }

/* Profile: "about me" line and the username field. */
.bio { white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0; }
.field-label { display: block; margin-top: 12px; font-size: 13px; color: var(--text-secondary); }
.username-at { align-self: center; color: var(--text-secondary); }

/* Blocked person: a bar in place of the message box. */
.blocked-bar { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--divider); background: var(--bg-secondary, transparent); flex-wrap: wrap; }
.block-btn { margin-top: 10px; }

.delete-account { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

/* Signing in from another device. */
.link-panel { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.link-qr { width: 200px; height: 200px; border-radius: 8px; background: #fff; }
.link-code { font-size: 28px; font-weight: 600; letter-spacing: 3px; font-family: ui-monospace, monospace; }
.link-start { margin-top: 8px; }
.link-form { display: flex; flex-direction: column; gap: 10px; }
.link-form input { font-family: ui-monospace, monospace; letter-spacing: 2px; text-transform: uppercase; }

.message-views { margin-right: 4px; white-space: nowrap; }

/* Threads: replies to one message. */
.thread-link { display: block; margin-top: 4px; background: none; border: none; padding: 2px 0; font: inherit; font-size: 13px; color: var(--primary); cursor: pointer; }
.thread { display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; margin-bottom: 10px; }
.thread-item { padding: 6px 10px; border-radius: 8px; background: color-mix(in srgb, var(--text-secondary) 10%, transparent); }
.thread-root { border-left: 3px solid var(--primary); }
.thread-head { font-size: 13px; font-weight: 600; }
.thread-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Bots: buttons under messages and the command menu. */
.inline-buttons { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.inline-row { display: flex; gap: 4px; }
.inline-btn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; text-decoration: none; }
.bot-commands { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 6px 12px; border-top: 1px solid var(--divider); flex-shrink: 0; }
.bot-command { border: none; cursor: pointer; padding: 4px 10px; font: inherit; font-size: 13px; color: inherit; white-space: nowrap; }

/* Accounts saved on this device, offered on the sign-in page. */
.saved-accounts { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.saved-account { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 1px solid var(--divider); border-radius: 10px; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.saved-account .member-text { display: flex; flex-direction: column; min-width: 0; }

/* Sharing from another app: what is being sent, above the chat list. */
.share-page .share-list { display: flex; flex-direction: column; }
.share-what { margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Swipes. A chat row slides left over a mark: read (a check) or unread (a dot). */
.chat-item[data-chat] { position: relative; overflow: hidden; }
.chat-item.swiping > * { transform: translateX(calc(var(--swipe, 0px) * -1)); }
.chat-item.swiping::after, .chat-item.swiping::before {
    content: ''; position: absolute; top: 0; bottom: 0; right: 0; width: var(--swipe, 0px);
}
.chat-item.swiping::after { background: var(--text-secondary); transition: background .12s; }
.chat-item.swiping.swipe-armed::after { background: var(--primary); }
.chat-item.swiping::before {
    z-index: 1; background: #fff;
    -webkit-mask: var(--swipe-icon) center / 22px no-repeat; mask: var(--swipe-icon) center / 22px no-repeat;
    --swipe-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}
.chat-item.swiping:not(.unread)::before {
    --swipe-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='6' fill='%23000'/%3E%3C/svg%3E");
}
/* A message slides left to be answered: the reply mark comes in from the edge. */
.messages-container { overflow-x: hidden; }
.message-row.swiping { position: relative; }
.message-row.swiping::after {
    content: ''; position: absolute; right: -48px; top: 50%; width: 32px; height: 32px; margin-top: -16px;
    border-radius: 21%; background: var(--surface-variant); opacity: .55; transition: opacity .12s;
}
.message-row.swiping::before {
    content: ''; position: absolute; right: -41px; top: 50%; width: 18px; height: 18px; margin-top: -9px; z-index: 1;
    background: var(--text-primary); opacity: .55; transition: opacity .12s;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 17l-5-5 5-5'/%3E%3Cpath d='M4 12h10a6 6 0 0 1 6 6v1'/%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='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 17l-5-5 5-5'/%3E%3Cpath d='M4 12h10a6 6 0 0 1 6 6v1'/%3E%3C/svg%3E") center / contain no-repeat;
}
.message-row.swipe-armed::after, .message-row.swipe-armed::before { opacity: 1; }
/* The chat slides right off the list. */
.right-panel.swiping { box-shadow: -10px 0 24px rgba(0, 0, 0, .25); z-index: 5; }

/* SMS of the lines: conversations by number, as on a phone. */
.sms-page { max-width: 520px; }
/* One conversation is drawn as a chat: the chat's header, bubbles and composer. */
.sms-app .right-panel { max-width: 900px; margin: 0 auto; width: 100%; }
.sms-error { font-size: 12px; color: var(--error); padding: 2px 0 0; }
.sms-thread-error { padding: 4px 12px; }
.sms-list { display: flex; flex-direction: column; margin: 0 -16px; }
.sms-from { display: flex; align-items: center; gap: 8px; }
.sms-from select { flex: 1; min-width: 0; }
.sms-new {
    position: fixed; right: 20px; bottom: 20px; width: 56px; height: 56px; border: none; border-radius: 21%;
    display: flex; align-items: center; justify-content: center; background: var(--primary); color: #fff; cursor: pointer;
}
