:root {
  --brand: #0b5cff;
  --brand-2: #00b2ff;
  --brand-grad: linear-gradient(135deg, #0b5cff 0%, #2f7bff 55%, #00b2ff 100%);
  --bg: #ffffff;
  --bg-2: #f3f5f9;
  --bg-hover: #eef1f6;
  --bg-active: #e5eeff;
  --text: #0f1729;
  --muted: #66708a;
  --line: #e3e7ef;
  --bubble-them: #eceff4;
  --danger: #d92d3a;
  --online: #2fbf5a;
  --radius: 18px;
  --shadow: 0 10px 40px rgba(15, 23, 41, 0.14);
  --msg-fs: 15px;
  --seen: #0b5cff;
  color-scheme: light;
}
/* Dark theme: chosen in Settings, or following the system when Settings says "System" */
:root[data-theme="dark"] {
  --bg: #12151c;
  --bg-2: #1b1f29;
  --bg-hover: #222735;
  --bg-active: #1d2b4d;
  --text: #e9edf5;
  --muted: #97a0b5;
  --line: #2a3040;
  --bubble-them: #262b38;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  --seen: #4dabf7;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c;
    --bg-2: #1b1f29;
    --bg-hover: #222735;
    --bg-active: #1d2b4d;
    --text: #e9edf5;
    --muted: #97a0b5;
    --line: #2a3040;
    --bubble-them: #262b38;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    --seen: #4dabf7;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0 0; font-size: 13.5px; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Buttons ---------- */
.btn { border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; background: var(--bg-2); }
.btn.primary { background: var(--brand-grad); color: #fff; }
.btn.primary:disabled { opacity: 0.5; cursor: default; }
.btn.wide { width: 100%; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--bg-2);
  display: inline-grid; place-items: center; color: var(--text); flex: none;
}
.icon-btn:hover { background: var(--bg-hover); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- Auth ---------- */
.auth {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, rgba(11, 92, 255, 0.18), transparent 60%),
              radial-gradient(900px 500px at 110% 110%, rgba(0, 178, 255, 0.18), transparent 60%), var(--bg);
  overflow: auto; height: 100%;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 22px; padding: 32px 28px; box-shadow: var(--shadow); text-align: center;
}
.auth-logo { display: block; margin: 0 auto 12px; }
.auth-card h1 { font-size: 26px; letter-spacing: -0.02em; }
.auth-card > p { margin: 6px 0 20px; }
.tabs { display: flex; background: var(--bg-2); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.tab { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
#auth-form { display: grid; gap: 12px; text-align: left; }
#auth-form label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
#auth-form input, .dialog input {
  width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-2); outline: none; font-size: 15px;
}
#auth-form input:focus, .dialog input:focus { border-color: var(--brand); background: var(--bg); }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 360px 1fr; height: 100%; height: 100dvh; }
.sidebar { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.me { display: flex; align-items: center; gap: 10px; }
.me h2 { font-size: 24px; letter-spacing: -0.02em; }
.head-actions { display: flex; gap: 8px; }
.search { margin: 6px 16px 10px; position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); }
.search input {
  width: 100%; border: 0; border-radius: 20px; padding: 9px 14px 9px 36px; background: var(--bg-2); outline: none;
}
.conn-banner { margin: 0 16px 8px; padding: 6px 10px; border-radius: 8px; background: #fff3cd; color: #7a5b00; font-size: 13px; text-align: center; }

.conv-list { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; }
/* Secret chats */
.secret-entry { display: flex; align-items: center; gap: 12px; margin: 0 8px 4px; padding: 9px 10px; border: 0; border-radius: 12px; background: var(--bg-2); color: var(--text); text-align: left; cursor: pointer; font: inherit; }
.secret-entry[hidden], .secret-bar[hidden] { display: none; }
.secret-entry:hover { background: var(--bg-hover); }
.secret-ico { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); flex: none; }
.secret-ico svg, .pin-lock svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.secret-label { display: grid; flex: 1; }
.secret-label small { color: var(--muted); font-size: 12.5px; }
.secret-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); flex: none; }
.secret-bar { display: flex; align-items: center; gap: 8px; margin: 0 8px 6px; padding: 6px 8px; border-radius: 12px; background: color-mix(in srgb, var(--brand) 12%, var(--bg-2)); }
.secret-bar strong { flex: 1; font-size: 15px; }
.pin-dialog .dialog-inner { text-align: center; }
.pin-lock { width: 52px; height: 52px; margin: 0 auto 4px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
.pin-input { font: inherit; font-size: 26px; letter-spacing: 0.5em; text-align: center; width: 100%; box-sizing: border-box; padding: 10px 12px 10px calc(12px + 0.5em); margin-top: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); }
.pin-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0 0 !important; }
.pin-forgot { margin: 8px auto 0; display: block; }
.secret-set-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.secret-set-actions [hidden] { display: none; }
.conv {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 12px; cursor: pointer;
}
.conv:hover { background: var(--bg-hover); }
.conv.active { background: var(--bg-active); }
.conv-body { min-width: 0; flex: 1; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--muted); flex: none; }
.conv-preview { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 8px; justify-content: space-between; }
.conv-preview span:first-child { overflow: hidden; text-overflow: ellipsis; }
.conv.unread .conv-name, .conv.unread .conv-preview { color: var(--text); font-weight: 700; }
.badge { background: var(--brand); color: #fff; border-radius: 10px; font-size: 11.5px; font-weight: 700; padding: 1px 7px; flex: none; }
.conv-list:empty { flex: 0; }
.conv-empty { padding: 32px 24px; text-align: center; color: var(--muted); }

/* ---------- Avatars ---------- */
.avatar {
  --size: 40px; width: var(--size); height: var(--size); border-radius: 50%; flex: none; position: relative;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: calc(var(--size) * 0.4);
  background: var(--av, var(--brand)); user-select: none;
}
.avatar.lg { --size: 52px; }
.avatar.sm { --size: 28px; }
.avatar.xs { --size: 16px; font-size: 8px; }
.avatar.online::after {
  content: ""; position: absolute; right: -1px; bottom: -1px; width: 30%; height: 30%; min-width: 10px; min-height: 10px;
  border-radius: 50%; background: var(--online); border: 2.5px solid var(--bg);
}
#me-avatar { --size: 36px; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-empty { margin: auto; text-align: center; padding: 24px; }
.chat-empty h2 { margin: 14px 0 6px; font-size: 20px; }
.chat-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line);
  padding-top: max(10px, env(safe-area-inset-top));
}
.chat-title { min-width: 0; flex: 1; display: grid; }
.chat-title h3 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-status { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back-btn { display: none; background: transparent; color: var(--brand); }

.messages { flex: 1; overflow-y: auto; padding: 16px 16px 6px; display: flex; flex-direction: column; gap: 2px; overscroll-behavior: contain; }
.load-more { align-self: center; margin: 4px 0 10px; font-size: 13px; padding: 6px 12px; }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); margin: 14px 0 8px; font-weight: 600; }
.row { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.row.mine { justify-content: flex-end; }
.row .avatar-slot { width: 28px; flex: none; }
.row.group-start { margin-top: 8px; }
.sender-name { font-size: 12px; color: var(--muted); margin: 8px 0 2px 48px; }
.bubble {
  max-width: min(72%, 560px); padding: 8px 12px; border-radius: var(--radius); background: var(--bubble-them);
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  font-size: var(--msg-fs);
}
.row.mine .bubble { background: var(--brand-grad); background-attachment: fixed; color: #fff; }
.row:not(.mine):not(.group-end) .bubble { border-bottom-left-radius: 5px; }
.row:not(.mine):not(.group-start) .bubble { border-top-left-radius: 5px; }
.row.mine:not(.group-end) .bubble { border-bottom-right-radius: 5px; }
.row.mine:not(.group-start) .bubble { border-top-right-radius: 5px; }
/* Waiting messages look normal; the clock icon next to the time says they haven't gone yet */
.row.failed .bubble { background: var(--danger); }
.bubble.emoji-only { background: none !important; font-size: 38px; padding: 0 4px; line-height: 1.15; }
.bubble a { color: inherit; text-decoration: underline; }
/* Message time, WhatsApp style: tucked into the bottom-right of the bubble */
.msg-time { font-size: 11px; line-height: 1; white-space: nowrap; font-weight: 500; user-select: none; }
.bubble .msg-time { float: right; position: relative; top: 7px; margin: 0 -4px 0 10px; color: color-mix(in srgb, currentColor 62%, transparent); display: inline-flex; align-items: center; gap: 3px; }
.msg-time .tick { width: 16px; height: 14px; margin: 0 -2px 0 0; align-self: center; color: inherit; }
.msg-time .tick svg { width: 17px; height: 17px; stroke-width: 2.4; }
.row.mine .bubble .msg-time { color: rgba(255, 255, 255, 0.78); }
.row.mine .bubble .msg-time .tick-seen { color: #a6f4ff; } /* read: bright, stands out on the blue bubble */
.msg-time.on-media, .msg-time.below { display: inline-flex; align-items: center; gap: 3px; }
.msg-time.on-media .tick-seen { color: #8fe9ff; }
.msg-time .tick-sending svg { width: 12px; height: 12px; }
.msg-time-edited { font-style: italic; }
.msg-time.on-media { position: absolute; right: 8px; bottom: 8px; color: #fff; background: rgba(0, 0, 0, 0.45); padding: 3px 7px; border-radius: 10px; }
.msg-time.below { color: var(--muted); margin: 3px 6px 0; }
.row.mine .msg-time.below { align-self: flex-end; text-align: right; }
.messages.has-wallpaper .msg-time.below { background: color-mix(in srgb, var(--bg) 82%, transparent); color: var(--text); padding: 3px 8px; border-radius: 10px; width: fit-content; }
.receipt { align-self: flex-end; font-size: 11.5px; color: var(--muted); margin: 2px 2px 0; display: flex; gap: 2px; align-items: center; }
.receipt .avatar { border: 1px solid var(--bg); }

.typing { display: flex; align-items: center; gap: 8px; padding: 0 20px 6px; color: var(--muted); font-size: 13px; }
.dots { display: inline-flex; gap: 3px; background: var(--bubble-them); padding: 8px 10px; border-radius: 14px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.input-wrap { flex: 1; position: relative; display: flex; align-items: flex-end; min-width: 0; }
.composer { align-items: flex-end; }
.composer textarea {
  flex: 1; width: 100%; resize: none; border: 1px solid var(--line); outline: none; background: var(--bg-2); border-radius: 20px;
  padding: 9px 44px 9px 16px; min-height: 40px; max-height: 140px; line-height: 20px; font-size: var(--msg-fs);
  overflow-y: hidden; display: block; box-sizing: border-box; scrollbar-width: thin;
}
.composer textarea:focus { border-color: var(--brand); background: var(--bg); }
.composer textarea::placeholder { color: var(--muted); }
.attach-btn, .send-btn, .cam-btn { height: 40px; align-self: flex-end; }
.emoji-btn {
  position: absolute; right: 4px; bottom: 4px; width: 32px; height: 32px; border: 0; border-radius: 50%;
  background: transparent; color: var(--brand); display: grid; place-items: center; padding: 0;
}
.emoji-btn:hover { background: var(--bg-hover); }
.send-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--brand); display: grid; place-items: center; flex: none; }
.send-btn:disabled { color: var(--muted); opacity: 0.5; cursor: default; }
.send-btn svg { fill: currentColor; stroke-width: 1.5; }
.send-btn svg path:last-child { stroke: var(--bg); }

/* ---------- Images ---------- */
.attach-btn { width: 36px; height: 40px; border: 0; background: transparent; color: var(--brand); display: grid; place-items: center; flex: none; }
.attach-btn:disabled { opacity: 0.4; cursor: default; }
.attach-preview { padding: 8px 16px 0; }
.attach-thumb { position: relative; display: inline-block; }
.attach-thumb img { display: block; max-height: 120px; max-width: 200px; border-radius: 12px; border: 1px solid var(--line); object-fit: cover; }
.attach-remove {
  position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--bg);
  background: var(--text); color: var(--bg); display: grid; place-items: center; padding: 0;
}
.attach-remove svg { width: 14px; height: 14px; stroke-width: 3; }

.msg-stack { display: flex; flex-direction: column; gap: 2px; max-width: min(72%, 560px); }
.row.mine .msg-stack { align-items: flex-end; }
.msg-stack .bubble { max-width: 100%; }
.msg-image {
  display: block; border-radius: var(--radius); cursor: zoom-in; background: var(--bg-2);
  max-width: min(320px, 100%); max-height: 360px; width: auto; height: auto; object-fit: cover;
}
.row.pending .msg-image { opacity: 0.55; }
.img-wrap { position: relative; }
.img-wrap .spinner {
  position: absolute; inset: 0; margin: auto; width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.5); border-top-color: #fff; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.drop-overlay {
  position: absolute; inset: 8px; border: 3px dashed var(--brand); border-radius: 16px; z-index: 5;
  background: color-mix(in srgb, var(--bg) 85%, transparent); display: grid; place-items: center;
  font-size: 18px; font-weight: 700; color: var(--brand); pointer-events: none;
}
.chat-view { position: relative; }

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(5, 8, 15, 0.92); display: grid; place-items: center; padding: 56px 16px 16px; }
.lightbox img { max-width: calc(100vw - 32px); max-height: calc(100vh - 72px); max-height: calc(100dvh - 72px); object-fit: contain; border-radius: 6px; }
.lightbox-actions { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; padding-top: env(safe-area-inset-top); }
.lightbox .icon-btn { background: rgba(255,255,255,0.14); color: #fff; }

/* ---------- Message actions ---------- */
.row { position: relative; }
.msg-actions { display: flex; gap: 2px; align-self: center; opacity: 0; transition: opacity 0.12s; flex: none; }
.row:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
@media (hover: none) { .msg-actions { display: none; } }
.act-btn {
  width: 30px; height: 30px; border-radius: 50%; border: 0; background: transparent; color: var(--muted);
  display: grid; place-items: center; font-size: 18px; line-height: 1; padding: 0;
}
.act-btn:hover { background: var(--bg-hover); color: var(--text); }
.act-btn svg { width: 17px; height: 17px; }
@media (pointer: coarse) { .msg-stack { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } }

/* ---------- Reactions ---------- */
.msg-stack { position: relative; }
.row.has-reactions { margin-bottom: 16px; }
.reactions {
  position: absolute; bottom: -16px; left: 6px; display: inline-flex; align-items: center; gap: 1px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 1px 6px;
  font-size: 14px; line-height: 20px; box-shadow: 0 1px 4px rgba(0,0,0,0.12); z-index: 1;
}
.row.mine .reactions { left: auto; right: 6px; }
.reactions.includes-me { border-color: var(--brand); }
.reactions .count { font-size: 12px; color: var(--muted); margin-left: 3px; font-weight: 600; }

.popover {
  position: fixed; z-index: 40; background: var(--bg); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.popover.picker { display: flex; gap: 2px; padding: 5px 6px; border-radius: 26px; animation: pop 0.14s ease-out; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.pick {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; font-size: 26px; line-height: 1;
  display: grid; place-items: center; padding: 0; transition: transform 0.1s;
}
.pick:hover { transform: scale(1.22); }
.pick.chosen { background: var(--bg-active); }
.reply-pick { color: var(--muted); border-left: 1px solid var(--line); border-radius: 0 50% 50% 0; }
.reply-pick:hover { transform: none; color: var(--text); }
.reply-pick svg { width: 20px; height: 20px; }
.popover.details { border-radius: 14px; padding: 8px; min-width: 220px; max-height: 300px; overflow-y: auto; }
.details-title { font-weight: 700; padding: 4px 8px 8px; }
.detail-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; width: 100%; border: 0; background: none; text-align: left; }
button.detail-row:hover { background: var(--bg-hover); }
.detail-info { flex: 1; min-width: 0; }
.detail-emoji { font-size: 20px; }

/* ---------- Replies ---------- */
.reply-quote { display: flex; flex-direction: column; max-width: 100%; margin-top: 6px; }
.row.mine .reply-quote { align-items: flex-end; }
.reply-label { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); margin: 0 6px 3px; }
.reply-label svg { width: 13px; height: 13px; }
.quote {
  border: 0; background: var(--bg-2); color: var(--muted); border-radius: 14px; padding: 7px 12px 14px; margin-bottom: -10px;
  font-size: 13.5px; max-width: 100%; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0.85;
}
.quote:hover { opacity: 1; }
.msg-stack > .bubble, .msg-stack > .img-wrap { position: relative; } /* sit on top of the quote */
.row.flash .bubble, .row.flash .msg-image { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--brand-2); } 100% { box-shadow: 0 0 0 3px transparent; } }

.reply-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px 0 16px; border-top: 1px solid var(--line); }
.reply-bar-text { flex: 1; min-width: 0; }
.reply-to-name { font-size: 13px; font-weight: 700; }
.reply-to-text { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar .icon-btn { width: 30px; height: 30px; background: transparent; }

/* ---------- Edit & unsend ---------- */
.bubble.unsent, .row.mine .bubble.unsent {
  background: transparent; color: var(--muted); border: 1px solid var(--line); font-style: italic; font-size: 14px;
}
.edited-tag { font-size: 11.5px; color: var(--muted); margin: 1px 8px 0; }
.row.being-edited .bubble { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.quote.unsent { font-style: italic; cursor: default; }
.edit-bar .edit-icon { width: 18px; height: 18px; color: var(--brand); flex: none; }
.more-pick { font-size: 20px; border-left: 0; border-radius: 50%; }

.popover.menu { border-radius: 14px; padding: 6px; min-width: 200px; max-width: 260px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left;
  padding: 9px 10px; border-radius: 9px; font-weight: 600;
}
.menu-item:hover { background: var(--bg-hover); }
.menu-item svg { width: 18px; height: 18px; }
.menu-item.danger { color: var(--danger); }
.menu-note { font-size: 12.5px; color: var(--muted); padding: 6px 10px 8px; }

/* ---------- Seen status ---------- */
.tick { width: 16px; height: 16px; flex: none; align-self: flex-end; margin-bottom: 3px; color: var(--muted); display: grid; place-items: center; }
.tick svg { width: 16px; height: 16px; stroke-width: 2.2; }
.tick-seen { color: var(--seen); }
.tick-failed { color: var(--danger); }
.tick-sending svg { width: 13px; height: 13px; }
.row.is-unsent .tick { visibility: hidden; }
.receipt { gap: 4px; }
.receipt .avatar { margin-right: 2px; }
.popover.info { min-width: 260px; }
.info-sent { font-size: 12.5px; color: var(--muted); padding: 0 8px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.popover.info .tick { align-self: center; margin: 0; }

/* ---------- Documents ---------- */
.file-card {
  position: relative; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 16px;
  background: var(--bubble-them); color: var(--text); text-decoration: none; min-width: 220px; max-width: 320px;
  border: 1px solid var(--line);
}
a.file-card:hover { border-color: var(--brand); }
.row.mine .file-card { background: var(--bg); }
.file-icon {
  width: 40px; height: 48px; border-radius: 6px; background: var(--fc, #5c677d); color: #fff; flex: none;
  display: grid; place-items: end center; padding-bottom: 6px; font-size: 10px; font-weight: 800; letter-spacing: 0.03em;
  clip-path: polygon(0 0, 72% 0, 100% 22%, 100% 100%, 0 100%);
}
.file-info { min-width: 0; flex: 1; }
.file-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.file-dl { color: var(--brand); display: grid; place-items: center; flex: none; }
.file-dl svg { width: 20px; height: 20px; }
.spinner.dark { position: static; margin: 0; width: 20px; height: 20px; border-color: var(--line); border-top-color: var(--brand); flex: none; }
.attach-doc .file-card { min-width: 240px; }
.msg-stack > .file-card { position: relative; }

/* ---------- Comfort: mute, emoji, toast ---------- */
.mute-btn { margin-left: auto; background: transparent; color: var(--muted); }
.mute-btn.on { color: var(--danger); }
.muted-icon { font-size: 11px; margin-left: 5px; opacity: 0.8; }
.popover.emoji-grid { display: grid; grid-template-columns: repeat(8, 36px); gap: 2px; padding: 8px; border-radius: 16px; max-width: calc(100vw - 16px); }
.emo { width: 36px; height: 36px; border: 0; background: none; border-radius: 8px; font-size: 22px; line-height: 1; padding: 0; }
.emo:hover { background: var(--bg-hover); transform: scale(1.1); }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 90; /* above the status viewer */ max-width: min(420px, calc(100vw - 32px));
  background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out; text-align: center;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- People: nearby, requests, friends ---------- */
.people-btn { position: relative; }
.people-badge { position: absolute; top: -3px; right: -3px; font-size: 10.5px; padding: 0 5px; line-height: 16px; min-width: 16px; text-align: center; background: var(--danger); }
.people { width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow-y: auto; }
.people .dialog-inner { gap: 10px; min-height: 420px; align-content: start; }
.people-tabs { margin-bottom: 4px; }
.people-tabs .badge { font-size: 11px; padding: 0 6px; margin-left: 4px; background: var(--danger); }
.ptab { display: grid; gap: 10px; }

.nearby-intro { text-align: center; padding: 6px 8px 0; }
.nearby-intro p { margin: 10px 0 6px; }
.privacy-list { text-align: left; margin: 0 auto; padding: 10px 14px 10px 30px; background: var(--bg-2); border-radius: 12px; color: var(--muted); font-size: 13px; display: grid; gap: 4px; max-width: 400px; }
.radar { position: relative; width: 76px; height: 76px; margin: 4px auto 0; display: grid; place-items: center; }
.radar span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--brand); opacity: 0; animation: ping 2.4s ease-out infinite; }
.radar span:nth-child(2) { animation-delay: 1.2s; }
.radar svg { width: 34px; height: 34px; color: var(--brand); position: relative; }
@keyframes ping { 0% { transform: scale(0.35); opacity: 0.9; } 100% { transform: scale(1.15); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .radar span { animation: none; opacity: 0.4; } }
.nearby-controls { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.radius { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--muted); font-size: 14px; }
.radius select { font: inherit; color: var(--text); background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 7px 8px; }
.nearby-status { text-align: center; margin: 0; }
/* Contacts */
.contacts-icon { background: color-mix(in srgb, var(--brand) 12%, transparent); border-radius: 50%; width: 68px; height: 68px; }
.contacts-icon svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.contacts-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }
.contacts-howto { font-size: 13px; color: var(--muted); background: var(--bg-2); border-radius: 12px; padding: 8px 12px; }
.contacts-howto summary { cursor: pointer; font-weight: 600; color: var(--text); }
.contacts-howto ul { margin: 8px 0 2px; padding-left: 18px; display: grid; gap: 4px; }
#contacts-results { display: grid; gap: 8px; }
#contacts-results[hidden] { display: none; }
.contacts-search { font: inherit; color: var(--text); background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; box-sizing: border-box; }
.plist-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.plist-head .plist-title { margin: 0; }
.plist-title .muted { text-transform: none; letter-spacing: 0; }
.contacts-foot { text-align: center; font-size: 13px; color: var(--muted); margin: 6px 0 0; }
#contacts-share, #contacts-refresh, #contacts-add-all, .contacts-cta { color: var(--brand); cursor: pointer; }
#contacts-forget { cursor: pointer; }
.contacts-cta { display: block; margin: 8px auto 0; }
.contacts-cta[hidden] { display: none; }
.link-btn { border: 0; background: none; color: var(--danger); font-weight: 600; justify-self: center; padding: 6px; }
.link-btn:hover { text-decoration: underline; }

.plist-title { margin: 6px 0 0; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.people-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; }
.person:hover { background: var(--bg-hover); }
.person-info { flex: 1; min-width: 0; }
.person-info .u-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-info .u-handle { overflow-wrap: anywhere; } /* let "@name · About 2–5 km away" wrap on phones */
.person-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.small-btn { padding: 6px 12px; font-size: 13px; border-radius: 9px; }
.small-btn.ghost { background: var(--bg-2); }
.small-btn.ghost:hover { background: var(--bg-active); }
.small-btn:disabled { opacity: 0.6; }
.danger-text { color: var(--danger); }
.rel-tag { font-size: 12.5px; color: var(--online); font-weight: 700; }
@media (max-width: 760px) {
  /* Phones: buttons go on their own line under the name so names aren't cut off */
  .person { flex-wrap: wrap; }
  .person-info { flex-basis: calc(100% - 60px); }
  .person-actions { width: 100%; justify-content: flex-start; padding-left: 50px; }
}
.people-empty { color: var(--muted); font-size: 13.5px; padding: 10px 8px; }
#friend-search { width: 100%; padding: 10px 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); outline: none; font-size: 15px; }
#friend-search:focus { border-color: var(--brand); background: var(--bg); }
#search-list { border-bottom: 1px solid var(--line); padding-bottom: 8px; }

/* ---------- Profile photos ---------- */
.avatar.has-photo { background: var(--bg-2); }
.avatar > img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar.xl { --size: 84px; }
.avatar.hero { --size: 168px; font-size: 60px; }
.clickable { cursor: pointer; }
/* Status ring around an avatar: bright = new, grey = seen */
.avatar.ring { box-shadow: 0 0 0 2.5px var(--bg), 0 0 0 5px var(--ring, var(--line)); }
.avatar.ring-new { --ring: var(--brand); }
.avatar.ring-new::before { content: ""; position: absolute; inset: -5px; border-radius: 50%; padding: 2.5px; background: var(--brand-grad); -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; }
.avatar.ring-new { box-shadow: 0 0 0 2.5px var(--bg); }
.avatar.ring-seen { --ring: var(--muted); }

.photo-edit { display: grid; justify-items: center; gap: 4px; }
.photo-btn { position: relative; border: 0; background: none; padding: 0; border-radius: 50%; }
.photo-cam { position: absolute; right: -2px; bottom: -2px; width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; border: 3px solid var(--bg); }
.photo-cam svg { width: 15px; height: 15px; }
.photo-btn:hover .avatar { filter: brightness(0.9); }
.link-btn.small { font-size: 12.5px; padding: 2px; }

/* ---------- Status strip ---------- */
.status-strip { display: flex; gap: 12px; overflow-x: auto; padding: 4px 16px 12px; scrollbar-width: none; }
.status-strip::-webkit-scrollbar { display: none; }
.status-item { position: relative; display: grid; justify-items: center; gap: 6px; border: 0; background: none; padding: 6px 2px 0; width: 66px; flex: none; color: var(--text); }
.status-item .avatar { --size: 54px; }
.status-label { font-size: 12px; max-width: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-add { position: absolute; top: 40px; right: 4px; width: 22px; height: 22px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 800; font-size: 16px; line-height: 19px; text-align: center; border: 2.5px solid var(--bg); }

/* Status preview inside the circle: media is pinned to the circle so tall photos/videos can't spill out */
.status-thumb { overflow: visible; background: #222; color: #fff; flex: none; }
.status-thumb > img, .status-thumb > video {
  position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; border-radius: 50%; object-fit: cover; display: block; pointer-events: none;
}
.status-item { overflow: visible; }
.status-item .status-thumb { --size: 54px; width: 54px; height: 54px; }
.thumb-play { position: absolute; right: -2px; bottom: -2px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,0.75); color: #fff; font-size: 9px; display: grid; place-items: center; border: 2px solid var(--bg); }
.thumb-text { font-size: 8.5px; font-weight: 700; line-height: 1.15; text-align: center; padding: 6px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; word-break: break-word; }

/* ---------- Status composer ---------- */
.status-compose { width: min(440px, calc(100vw - 24px)); }
.sc-text-preview { border-radius: 16px; min-height: 240px; display: grid; place-items: center; padding: 20px; transition: background 0.2s; }
.sc-text-preview textarea { width: 100%; min-height: 160px; border: 0; background: transparent; color: #fff; font-size: 24px; font-weight: 600; text-align: center; resize: none; outline: none; font-family: inherit; }
.sc-text-preview textarea::placeholder { color: rgba(255,255,255,0.7); }
.sc-bgs { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.sc-photo-pick { width: 100%; min-height: 220px; border: 2px dashed var(--line); border-radius: 16px; background: var(--bg-2); display: grid; place-items: center; color: var(--muted); font-weight: 600; overflow: hidden; padding: 0; }
.sc-photo-pick span { display: grid; justify-items: center; gap: 8px; }
.sc-photo-pick svg { width: 34px; height: 34px; }
.sc-photo-pick img { width: 100%; max-height: 360px; object-fit: contain; display: block; background: #000; }
#sc-caption { width: 100%; margin-top: 8px; padding: 10px 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); outline: none; font-size: 15px; color: var(--text); }
.sc-note { margin: 2px 0 0; text-align: center; }

/* ---------- Status viewer ---------- */
.no-scroll { overflow: hidden; }
.status-viewer { position: fixed; inset: 0; z-index: 70; background: #0b0d12; display: grid; place-items: center; }
.sv-frame { position: relative; width: min(460px, 100vw); height: min(820px, 100dvh); display: flex; flex-direction: column; color: #fff; }
.sv-bars { display: flex; gap: 4px; padding: 10px 12px 0; padding-top: max(10px, env(safe-area-inset-top)); position: relative; z-index: 3; }
.sv-bar { flex: 1; height: 3px; border-radius: 2px; background: rgba(255,255,255,0.3); overflow: hidden; }
.sv-bar i { display: block; height: 100%; width: 0; background: #fff; }
.sv-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; position: relative; z-index: 3; }
.sv-head .avatar { --size: 38px; }
.sv-who { flex: 1; min-width: 0; display: grid; }
.sv-who span { font-size: 12.5px; opacity: 0.75; }
.sv-icon { width: 38px; height: 38px; border: 0; border-radius: 50%; background: rgba(255,255,255,0.12); color: #fff; display: grid; place-items: center; }
.sv-icon:hover { background: rgba(255,255,255,0.22); }
.sv-content { position: absolute; inset: 0; display: grid; place-items: center; border-radius: 0; overflow: hidden; }
@media (min-width: 761px) { .sv-content { border-radius: 14px; } }
.sv-text { font-size: 30px; font-weight: 700; text-align: center; padding: 70px 28px; white-space: pre-wrap; overflow-wrap: anywhere; text-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.sv-text.long { font-size: 21px; }
.sv-img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sv-caption { position: absolute; left: 0; right: 0; bottom: 84px; text-align: center; padding: 10px 18px; background: linear-gradient(transparent, rgba(0,0,0,0.6)); font-size: 16px; white-space: pre-wrap; }
.sv-nav { position: absolute; top: 90px; bottom: 90px; width: 35%; border: 0; background: transparent; z-index: 2; cursor: pointer; }
.sv-prev { left: 0; }
.sv-next { right: 0; width: 65%; }
.sv-foot { margin-top: auto; position: relative; z-index: 3; padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); display: grid; justify-items: center; }
.sv-views { display: inline-flex; align-items: center; gap: 6px; border: 0; background: rgba(255,255,255,0.14); color: #fff; padding: 8px 14px; border-radius: 20px; font-weight: 600; }
.sv-views svg { width: 18px; height: 18px; }
.sv-reply { width: 100%; display: flex; gap: 8px; }
.sv-reply input { flex: 1; border: 1px solid rgba(255,255,255,0.35); background: rgba(0,0,0,0.35); color: #fff; border-radius: 22px; padding: 11px 16px; outline: none; font-size: 15px; }
.sv-reply input::placeholder { color: rgba(255,255,255,0.7); }
.sv-send { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; }
.sv-send svg { fill: currentColor; width: 20px; height: 20px; }
.popover.viewers-pop { z-index: 80; }
.sv-mine-actions { display: flex; gap: 10px; justify-content: center; }
.sv-del { color: #ffb3b3; }

/* ---------- Link preview cards ---------- */
.link-card {
  display: block; width: min(340px, 100%); border-radius: 16px; overflow: hidden; background: var(--bg); color: var(--text);
  text-decoration: none; border: 1px solid var(--line); box-shadow: 0 2px 10px rgba(0,0,0,0.08); margin-top: 2px;
}
.link-card:hover { border-color: var(--brand); }
.lc-img { display: block; width: 100%; aspect-ratio: 1.91 / 1; object-fit: cover; background: var(--bg-2); }
.link-card.image-only .lc-img { aspect-ratio: auto; max-height: 340px; object-fit: contain; background: #000; cursor: zoom-in; }
.lc-body { padding: 10px 12px 12px; display: grid; gap: 3px; }
.lc-site { display: flex; align-items: center; gap: 6px; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; }
.lc-fav { width: 14px; height: 14px; border-radius: 3px; }
.lc-title { font-weight: 700; font-size: 14.5px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lc-desc { font-size: 13px; color: var(--muted); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lc-price { justify-self: start; margin-top: 4px; background: var(--brand); color: #fff; font-weight: 800; font-size: 13px; padding: 3px 10px; border-radius: 10px; }
.row.mine .link-card { align-self: flex-end; }

/* ---------- Groups & channels ---------- */
.ch-badge { position: absolute; right: -4px; bottom: -4px; font-size: calc(var(--size) * 0.32); line-height: 1; background: var(--bg); border-radius: 50%; padding: 2px; }
.role-badge { margin-left: 6px; font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; padding: 1px 6px; border-radius: 6px; background: var(--bg-active); color: var(--brand); vertical-align: middle; }
.role-badge.owner { background: var(--brand); color: #fff; }
.pp-desc { margin: 6px 12px 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; color: var(--text); text-align: center; }
.pp-edit { display: grid; gap: 8px; }
.pp-edit input, .pp-edit textarea, #nc-name, #nc-desc, #sl-url {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); outline: none; font: inherit; color: var(--text); resize: vertical;
}
.pp-edit input:focus, .pp-edit textarea:focus, #nc-name:focus, #nc-desc:focus { border-color: var(--brand); background: var(--bg); }
.pp-edit .btn { justify-self: start; }
.pp-section .set-row { flex-wrap: wrap; }
.pp-section .segmented span { min-width: 0; padding: 0 10px; font-size: 13px; }
.small-dialog { width: min(420px, calc(100vw - 24px)); }
.nc-note { margin: 0; }
.join-inner { justify-items: center; text-align: center; position: relative; padding-top: 24px; }
.join-close { position: absolute; top: 12px; right: 12px; }
.join-inner h2 { font-size: 22px; }
.jd-desc { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.sl-row { display: flex; gap: 8px; }
.sl-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.join-card { padding: 12px; display: grid; gap: 10px; }
.jc-body { display: flex; gap: 12px; align-items: center; }
.jc-text { display: grid; gap: 2px; min-width: 0; }
.join-card .btn { justify-self: stretch; }

/* ---------- Camera & photo editor ---------- */
.cam-btn { width: 34px; }
.cam { position: fixed; inset: 0; z-index: 78; background: #000; color: #fff; }
.cam-capture, .cam-edit { position: absolute; inset: 0; display: flex; flex-direction: column; }
.cam-capture video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-capture video.mirror { transform: scaleX(-1); }
.cam-nocam { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; text-align: center; padding: 24px; }
.cam-nocam p { max-width: 320px; margin: 0; opacity: 0.85; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cam-flash.go { animation: shutter-flash 0.35s ease-out; }
@keyframes shutter-flash { 0% { opacity: 0.85; } 100% { opacity: 0; } }
.cam-grid { position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, transparent calc(33.33% - 0.5px), rgba(255,255,255,.35) calc(33.33% - 0.5px), rgba(255,255,255,.35) calc(33.33% + 0.5px), transparent calc(33.33% + 0.5px), transparent calc(66.66% - 0.5px), rgba(255,255,255,.35) calc(66.66% - 0.5px), rgba(255,255,255,.35) calc(66.66% + 0.5px), transparent calc(66.66% + 0.5px)),
              linear-gradient(180deg, transparent calc(33.33% - 0.5px), rgba(255,255,255,.35) calc(33.33% - 0.5px), rgba(255,255,255,.35) calc(33.33% + 0.5px), transparent calc(33.33% + 0.5px), transparent calc(66.66% - 0.5px), rgba(255,255,255,.35) calc(66.66% - 0.5px), rgba(255,255,255,.35) calc(66.66% + 0.5px), transparent calc(66.66% + 0.5px)); }
.cam-top { position: relative; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 14px; padding-top: max(14px, env(safe-area-inset-top)); }
/* Three equal columns so the shutter stays centred even when "switch camera" is hidden */
#cam-flip[hidden] { display: grid !important; visibility: hidden; }
.cam-bottom > :first-child { justify-self: start; margin-left: 12%; }
.cam-bottom > :last-child { justify-self: end; margin-right: 12%; }
.cam-bottom { position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 24px 20px; padding-bottom: max(28px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,0.5)); }
.cam-icon { width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(0,0,0,0.4); color: #fff; display: grid; place-items: center; font-size: 20px; backdrop-filter: blur(6px); }
.cam-icon:hover { background: rgba(255,255,255,0.2); }
.cam-icon.big { width: 52px; height: 52px; }
.cam-icon svg { width: 22px; height: 22px; }
.cam-icon .aa { font-weight: 800; font-size: 17px; }
.cam-shutter { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: rgba(255,255,255,0.25); padding: 0; transition: transform 0.1s; }
.cam-shutter:hover { background: rgba(255,255,255,0.4); }
.cam-shutter:active { transform: scale(0.92); }
.cam-shutter:disabled { opacity: 0.35; }
.ed-tools { display: flex; gap: 10px; }
.ed-stage-wrap { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 12px; }
.ed-stage { position: relative; overflow: hidden; border-radius: 10px; touch-action: none; }
.ed-stage canvas { width: 100%; height: 100%; display: block; }
.ed-layer { position: absolute; inset: 0; }
.ed-ov { position: absolute; transform: translate(-50%, -50%); white-space: pre; cursor: grab; user-select: none; line-height: 1.2; padding: 2px 6px; border-radius: 6px; outline: none; touch-action: none; }
.ed-ov.text { font-weight: 800; text-shadow: 0 1px 6px rgba(0,0,0,0.45); user-select: text; cursor: text; }
.ed-ov.selected { box-shadow: 0 0 0 2px rgba(255,255,255,0.85); }
.ed-selected { display: flex; align-items: center; gap: 12px; justify-content: center; flex-wrap: wrap; padding: 8px 12px 0; }
.ed-selected input[type=range] { width: 140px; accent-color: #fff; }
.ed-colors { display: flex; gap: 6px; }
.ed-colors .swatch { width: 24px; height: 24px; border: 2px solid rgba(255,255,255,0.6); }
.ed-colors .swatch.chosen { outline: 2px solid #fff; outline-offset: 2px; }
.cam .btn.ghost { background: rgba(255,255,255,0.14); color: #fff; }
.ed-panel { padding: 10px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); display: grid; gap: 10px; background: #0d0f14; }
.ed-tabs { background: rgba(255,255,255,0.08); margin: 0; }
.ed-tabs .tab { color: rgba(255,255,255,0.6); }
.ed-tabs .tab.active { background: rgba(255,255,255,0.16); color: #fff; box-shadow: none; }
.ed-filters { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.ed-filters::-webkit-scrollbar { display: none; }
.ed-filter { flex: none; border: 0; background: none; color: rgba(255,255,255,0.75); display: grid; gap: 4px; justify-items: center; font-size: 12px; font-weight: 600; padding: 0; }
.ed-filter canvas { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 2px solid transparent; }
.ed-filter.chosen { color: #fff; }
.ed-filter.chosen canvas { border-color: var(--brand-2); }
.ed-adjust { display: grid; gap: 6px; max-height: 190px; overflow-y: auto; }
.ed-adj-row { display: grid; grid-template-columns: 90px 1fr 36px; gap: 10px; align-items: center; font-size: 13px; }
.ed-adj-row input { accent-color: var(--brand-2); width: 100%; }
.ed-adj-val { text-align: right; opacity: 0.7; font-variant-numeric: tabular-nums; }
.ed-send { display: flex; gap: 8px; align-items: center; }
.ed-send input { flex: 1; min-width: 0; border: 1px solid rgba(255,255,255,0.2); background: rgba(255,255,255,0.08); color: #fff; border-radius: 22px; padding: 10px 16px; outline: none; font-size: 15px; }
.ed-send input::placeholder { color: rgba(255,255,255,0.55); }
.ed-send-btn { width: 46px; height: 46px; background: var(--brand-grad); color: #fff; border-radius: 50%; }
.ed-send-btn svg { fill: #fff; }
.ed-send-btn svg path:last-child { stroke: var(--brand); }
.popover.ed-emoji { z-index: 85; }
@media (min-width: 761px) { .cam-edit .ed-panel, .cam-edit .ed-selected { width: min(560px, 100%); margin: 0 auto; border-radius: 16px 16px 0 0; } }

/* ---------- Sign in with mobile number ---------- */
.otp-step { display: grid; gap: 12px; text-align: left; }
.otp-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.phone-row { display: flex; gap: 8px; }
.phone-row select, .phone-row input, #otp-name {
  padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font: inherit; font-size: 16px; outline: none;
}
.phone-row select { flex: none; width: 108px; }
.phone-row input { flex: 1; min-width: 0; letter-spacing: 0.03em; }
.phone-row select:focus, .phone-row input:focus, #otp-name:focus { border-color: var(--brand); background: var(--bg); }
.otp-fine { margin: 0; text-align: center; }
.otp-sentto { margin: 0; text-align: center; font-size: 14px; }
.otp-boxes { display: flex; gap: 8px; justify-content: center; }
.otp-box {
  width: 46px; height: 54px; text-align: center; font-size: 24px; font-weight: 700; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text); outline: none; caret-color: var(--brand);
}
.otp-box:focus { border-color: var(--brand); background: var(--bg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.otp-resend { justify-self: center; color: var(--brand); }
.otp-resend:disabled { color: var(--muted); text-decoration: none; cursor: default; }
.test-note { margin: 10px 0 0; font-size: 12.5px; background: #fff3cd; color: #7a5b00; border-radius: 8px; padding: 6px 10px; }
.verified-tag { color: var(--online); font-weight: 700; margin-left: 6px; }
#set-phone[readonly] { opacity: 0.8; cursor: default; }
@media (max-width: 400px) { .otp-box { width: 40px; height: 50px; } }

/* In-app confirmation dialog */
.confirm-dialog { width: min(380px, calc(100vw - 32px)); z-index: 100; }
.confirm-dialog h3 { font-size: 17px; }
.confirm-dialog p { margin: 0; font-size: 14px; }
.cd-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.btn.danger-fill { background: var(--danger); color: #fff; }

/* Status reply quote in chat */
.status-chip { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.status-chip img, .status-swatch { width: 30px; height: 40px; border-radius: 6px; object-fit: cover; flex: none; }
.status-chip span:last-child { overflow: hidden; text-overflow: ellipsis; }
.status-quote .quote { cursor: default; }

/* ---------- Contact info panel ---------- */
.chat-id { display: flex; align-items: center; gap: 12px; border: 0; background: none; padding: 4px 6px; margin: -4px 0 -4px -6px; border-radius: 12px; min-width: 0; text-align: left; color: inherit; }
.chat-id:hover { background: var(--bg-hover); }
.profile-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 100vw); z-index: 30; background: var(--bg);
  border-left: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column; animation: slide-in 0.18s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.pp-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.pp-head h3 { font-size: 17px; }
.pp-body { overflow-y: auto; flex: 1; padding-bottom: 24px; }
.pp-hero { display: grid; justify-items: center; gap: 4px; padding: 24px 16px 16px; text-align: center; }
.pp-hero .avatar { margin-bottom: 10px; }
.pp-hero h2 { font-size: 22px; }
.pp-quick { display: flex; gap: 10px; margin-top: 14px; }
.pp-action { display: inline-flex; flex-direction: column; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 14px; min-width: 76px; font-size: 13px; font-weight: 600; color: var(--brand); }
.pp-action:hover { background: var(--bg-hover); }
.pp-action svg { width: 20px; height: 20px; }
.pp-section { border-top: 8px solid var(--bg-2); padding: 14px 16px; display: grid; gap: 10px; }
.pp-section h4 { margin: 0; font-size: 13px; color: var(--muted); font-weight: 700; }
.pp-about { font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.pp-rel { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pp-tabs { margin: 0; }
.pp-media.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.pp-media.grid .people-empty { grid-column: 1 / -1; }
.pp-media.list { display: grid; gap: 6px; }
.pp-media .file-card { max-width: none; }
.pp-thumb { border: 0; padding: 0; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--bg-2); cursor: zoom-in; }
.pp-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pp-link { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 10px; background: var(--bg-2); color: var(--text); text-decoration: none; min-width: 0; }
.pp-link:hover { background: var(--bg-hover); }
.pp-link-url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--brand); font-size: 14px; }
.pp-safety { display: grid; gap: 6px; }
.pp-safety .pp-action { flex-direction: row; justify-content: flex-start; border: 0; padding: 10px 6px; font-size: 15px; gap: 12px; }
.pp-action.danger { color: var(--danger); }
@media (max-width: 760px) { .profile-panel { width: 100vw; border-left: 0; } }

/* ---------- Video status ---------- */
.sc-photo-pick video { width: 100%; max-height: 360px; object-fit: contain; display: block; background: #000; }
.sc-photo-pick small { display: block; font-weight: 400; font-size: 12px; max-width: 260px; text-align: center; margin-top: 2px; }
.sc-video-info { text-align: center; margin: 6px 0 0; }
#sc-video-caption { width: 100%; margin-top: 8px; padding: 10px 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); outline: none; font-size: 15px; color: var(--text); }
.sc-progress { position: relative; height: 26px; border-radius: 13px; background: var(--bg-2); overflow: hidden; margin-top: 8px; display: grid; place-items: center; }
.sc-progress i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--brand-grad); transition: width 0.2s; }
.sc-progress span { position: relative; font-size: 12.5px; font-weight: 700; color: var(--text); }
.sv-spinner { display: none; position: absolute; inset: 0; margin: auto; z-index: 1; }
.sv-content.buffering .sv-spinner { display: block; }
.video-swatch { display: grid; place-items: center; background: #111; color: #fff; font-size: 13px; }

/* ---------- System notes & call logs in chat ---------- */
.system-note { align-self: center; font-size: 12.5px; color: var(--muted); margin: 10px 0; padding: 4px 12px; border-radius: 12px; text-align: center; }
.call-row { margin-top: 8px; }
.call-log { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 16px; background: var(--bubble-them); max-width: min(80%, 360px); }
.row.mine .call-log { background: var(--bg-active); }
.call-log-icon { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: #fff; flex: none; }
.call-log.missed .call-log-icon { background: var(--danger); }
.call-log-icon svg { width: 18px; height: 18px; }
.call-log-text { display: grid; min-width: 0; }
.call-log-text strong { font-size: 14px; }
.call-log-text span { font-size: 12.5px; color: var(--muted); }
.call-again { border: 0; background: none; color: var(--brand); font-weight: 700; font-size: 13px; padding: 6px 4px 6px 10px; margin-left: auto; border-left: 1px solid var(--line); }

/* ---------- Chat backgrounds ---------- */
.messages.has-wallpaper .day-sep, .messages.has-wallpaper .system-note, .messages.has-wallpaper .sender-name, .messages.has-wallpaper .reply-label, .messages.has-wallpaper .edited-tag, .messages.has-wallpaper .receipt {
  background: color-mix(in srgb, var(--bg) 82%, transparent); color: var(--text); padding: 3px 10px; border-radius: 10px; backdrop-filter: blur(4px);
}
.messages.has-wallpaper .sender-name, .messages.has-wallpaper .reply-label, .messages.has-wallpaper .edited-tag { justify-self: start; width: fit-content; }
.messages.has-wallpaper .tick { background: color-mix(in srgb, var(--bg) 75%, transparent); border-radius: 50%; }
.wallpaper-dialog { width: min(520px, calc(100vw - 24px)); }
.wp-note { margin: 0; }
.wp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; max-height: 50dvh; overflow-y: auto; padding: 2px; }
.wp-tile { position: relative; height: 120px; border-radius: 12px; border: 1px solid var(--line); padding: 0; display: flex; align-items: flex-end; justify-content: center; overflow: hidden; }
.wp-tile span { margin: 6px; padding: 2px 8px; border-radius: 8px; background: rgba(0,0,0,0.45); color: #fff; font-size: 11.5px; font-weight: 600; }
.wp-tile.chosen { outline: 3px solid var(--brand); outline-offset: 2px; }
.wp-actions { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; }

/* ---------- Calls ---------- */
.call-btn { background: transparent; color: var(--brand); }
.chat-head .mute-btn { margin-left: 0; }
.chat-head .chat-id { margin-right: auto; flex: 1; } /* name takes the free space; buttons sit on the right */
.call { position: fixed; inset: 0; z-index: 75; background: radial-gradient(circle at 50% 30%, #23324f, #0b0f18 70%); color: #fff; display: grid; place-items: center; overflow: hidden; }
.call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; display: none; }
.call.has-remote-video .call-remote { display: block; }
.call.has-remote-video.remote-cam-off .call-remote { display: none; }
.call-info { position: relative; z-index: 1; display: grid; justify-items: center; gap: 8px; text-align: center; padding-bottom: 120px; }
.call-info h2 { font-size: 26px; }
.call-state { font-size: 16px; opacity: 0.8; font-variant-numeric: tabular-nums; }
.call.has-remote-video:not(.remote-cam-off) .call-info { position: absolute; top: max(20px, env(safe-area-inset-top)); left: 20px; padding: 0; justify-items: start; text-align: left; }
.call.has-remote-video:not(.remote-cam-off) .call-info .avatar { display: none; }
.call.has-remote-video:not(.remote-cam-off) .call-info h2 { font-size: 18px; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.call:not(.connected) .call-info .avatar { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.25); } 50% { box-shadow: 0 0 0 18px rgba(255,255,255,0); } }
@media (prefers-reduced-motion: reduce) { .call:not(.connected) .call-info .avatar { animation: none; } }
.call-local { position: absolute; right: 16px; bottom: 120px; width: min(30vw, 180px); aspect-ratio: 3 / 4; object-fit: cover; border-radius: 14px; background: #000; box-shadow: 0 6px 24px rgba(0,0,0,0.5); z-index: 2; transform: scaleX(-1); }
.call-controls { position: absolute; left: 0; right: 0; bottom: max(28px, env(safe-area-inset-bottom)); display: flex; justify-content: center; gap: 18px; z-index: 3; }
.call-ctl { width: 60px; height: 60px; border-radius: 50%; border: 0; background: rgba(255,255,255,0.16); color: #fff; display: grid; place-items: center; backdrop-filter: blur(6px); }
.call-ctl:hover { background: rgba(255,255,255,0.26); }
.call-ctl svg { width: 26px; height: 26px; }
.call-ctl.off { background: #fff; color: #111; }
.call-ctl.off::after { content: ""; position: absolute; width: 34px; height: 2.5px; background: currentColor; transform: rotate(-45deg); }
.call-ctl { position: relative; }
.call-ctl.end { background: #e03131; }
.call-ctl.end:hover { background: #c92a2a; }
.call-ctl.end svg { fill: currentColor; stroke: none; }
.call-ctl.accept { background: #2fb344; }
.call-ctl.accept:hover { background: #2b9a3e; }
.incoming {
  position: fixed; z-index: 76; left: 50%; top: max(16px, env(safe-area-inset-top)); transform: translateX(-50%);
  width: min(420px, calc(100vw - 24px)); background: #151b29; color: #fff; border-radius: 20px; padding: 16px; box-shadow: 0 16px 50px rgba(0,0,0,0.5);
  display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; animation: drop-in 0.2s ease-out;
}
@keyframes drop-in { from { transform: translate(-50%, -12px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.incoming .avatar { --size: 60px; }
.in-text { display: grid; gap: 2px; min-width: 0; }
.in-text strong { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.in-text span { opacity: 0.75; font-size: 14px; }
.in-actions { grid-column: 1 / -1; display: flex; justify-content: center; gap: 22px; }
.in-actions .call-ctl { width: 54px; height: 54px; }

/* ---------- New group & friend picker ---------- */
.new-group-btn { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: var(--bg-2); border-radius: 14px; padding: 10px 12px; text-align: left; color: var(--text); }
.new-group-btn:hover { background: var(--bg-active); }
.new-group-btn span:last-child { display: grid; }
.new-group-btn small { color: var(--muted); font-size: 12.5px; }
.ng-icon { width: 42px; height: 42px; border-radius: 50%; background: var(--brand-grad); color: #fff; display: grid; place-items: center; flex: none; }
.pick-friends { width: min(440px, calc(100vw - 24px)); }
#pf-name, #pf-filter { width: 100%; padding: 10px 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); outline: none; font-size: 15px; color: var(--text); }
#pf-name:focus, #pf-filter:focus { border-color: var(--brand); background: var(--bg); }

/* ---------- Call history ---------- */
.calls-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 16px; padding: 5px 12px; font-size: 13px; font-weight: 600; }
.chip-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.call-dir { font-weight: 800; color: var(--online); }
.call-item.is-missed .call-dir, .call-item.is-missed .u-handle { color: var(--danger); }
.call-act { color: var(--brand); width: 34px; height: 34px; }
.call-act svg { width: 19px; height: 19px; }

/* ---------- Screen sharing in calls ---------- */
.call-ctl.on { background: var(--brand); }
.call.remote-presenting .call-remote { object-fit: contain; background: #000; }
.call-local.screen { transform: none; aspect-ratio: 16 / 10; width: min(36vw, 240px); object-fit: contain; }

/* ---------- Meet ---------- */
.meet-lobby { width: min(760px, calc(100vw - 24px)); }
.ml-start { display: grid; gap: 12px; padding: 8px 0; }
.ml-join { display: flex; gap: 8px; }
.ml-join input { flex: 1; min-width: 0; padding: 10px 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); outline: none; font-size: 15px; color: var(--text); }
.ml-ready { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: center; }
.ml-preview { position: relative; aspect-ratio: 16 / 10; border-radius: 14px; overflow: hidden; background: #111; }
.ml-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.ml-preview-off { position: absolute; inset: 0; display: grid; place-items: center; color: #ddd; font-weight: 600; }
.ml-toggles { position: absolute; left: 0; right: 0; bottom: 12px; display: flex; justify-content: center; gap: 14px; }
.ml-toggles .call-ctl { width: 48px; height: 48px; }
.ml-side { display: grid; gap: 10px; }
.ml-side h2 { font-size: 20px; }
.ml-code-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ml-code-row code { background: var(--bg-2); padding: 5px 10px; border-radius: 8px; font-size: 14px; letter-spacing: 0.04em; }
@media (max-width: 760px) { .ml-ready { grid-template-columns: 1fr; } }

.meet { position: fixed; inset: 0; z-index: 74; background: #0e1118; color: #fff; display: flex; flex-direction: column; }
.meet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
.meet-title { display: grid; min-width: 0; }
.meet-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meet-title span { font-size: 12.5px; opacity: 0.7; font-variant-numeric: tabular-nums; }
.meet .btn.ghost { background: rgba(255,255,255,0.12); color: #fff; }
.meet-body { flex: 1; min-height: 0; display: flex; gap: 10px; padding: 0 12px; }
.meet-stage { flex: 3; min-width: 0; display: grid; }
.meet-stage .tile { height: 100%; }
.meet-grid { flex: 1; min-width: 0; display: grid; gap: 10px; grid-template-columns: repeat(var(--cols, 1), 1fr); grid-auto-rows: 1fr; align-content: center; }
.meet.has-stage .meet-grid { flex: 0 0 220px; grid-template-columns: 1fr; grid-auto-rows: 130px; overflow-y: auto; align-content: start; }
.tile { position: relative; background: #1b2130; border-radius: 14px; overflow: hidden; display: grid; place-items: center; min-height: 120px; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile video.mirror { transform: scaleX(-1); }
.tile.presenting video { object-fit: contain; background: #000; }
.tile-avatar { display: grid; place-items: center; }
.tile-name { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 6px; align-items: center; background: rgba(0,0,0,0.55); padding: 3px 10px; border-radius: 10px; font-size: 13px; max-width: calc(100% - 20px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-tag { background: var(--brand); border-radius: 6px; padding: 0 6px; font-size: 11px; font-weight: 700; }
.tile-muted { font-size: 12px; }
.meet-people { width: 300px; flex: none; background: var(--bg); color: var(--text); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.meet-people header { display: flex; justify-content: space-between; align-items: center; }
.meet-people .people-list { flex: 1; }
.meet-controls { display: flex; justify-content: center; gap: 14px; padding: 14px; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
.meet-controls .call-ctl { width: 54px; height: 54px; }
.meet-count { position: absolute; top: -4px; right: -4px; background: var(--brand); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700; padding: 0 6px; line-height: 18px; }
@media (max-width: 760px) {
  .meet-body { flex-direction: column; }
  .meet.has-stage .meet-grid { flex: 0 0 120px; grid-auto-flow: column; grid-auto-columns: 140px; grid-template-columns: none; grid-auto-rows: auto; overflow-x: auto; }
  .meet-people { position: fixed; inset: auto 0 0 0; width: 100%; max-height: 70dvh; border-radius: 18px 18px 0 0; z-index: 2; }
  .meet-controls { gap: 10px; }
  .meet-controls .call-ctl { width: 48px; height: 48px; }
}
.meet-invite-banner { z-index: 77; }
.meet-invite-banner .in-actions .btn { min-width: 110px; }
.meet-card .call-log-icon { background: var(--brand-grad); }

/* ---------- Add by phone or email ---------- */
.lookup-form { display: grid; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.lookup-row { display: flex; gap: 8px; }
.lookup-row input, .contact-form input {
  flex: 1; min-width: 0; padding: 10px 13px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-2); outline: none; font-size: 15px; color: var(--text);
}
.lookup-row input:focus, .contact-form input:focus { border-color: var(--brand); background: var(--bg); }
.lookup-hint { margin: 0; }
.contact-form { display: grid; gap: 4px; margin-top: 14px; }
.contact-form input { width: 100%; margin-bottom: 6px; }
.contact-form p { margin: 0 0 8px; }
.contact-form .btn { justify-self: start; }

/* ---------- Block & report ---------- */
.chat-more { background: transparent; color: var(--muted); }
.mute-btn + .chat-more { margin-left: 0; }
.blocked-bar {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; text-align: center;
  padding: 14px 16px; padding-bottom: max(14px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
  color: var(--muted); font-size: 14px; background: var(--bg-2);
}
.person-more { width: 30px; height: 30px; font-size: 18px; }
.report { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow-y: auto; }
.report-preview { background: var(--bg-2); border-left: 3px solid var(--danger); border-radius: 8px; padding: 8px 12px; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reasons { border: 0; margin: 0; padding: 0; display: grid; gap: 2px; }
.reasons legend { font-weight: 700; margin-bottom: 6px; padding: 0; }
.reasons label { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.reasons label:hover { background: var(--bg-hover); }
.reasons input { accent-color: var(--brand); width: 17px; height: 17px; margin: 0; }
.report textarea { width: 100%; resize: vertical; border: 1px solid var(--line); background: var(--bg-2); border-radius: 10px; padding: 10px 12px; font: inherit; color: inherit; outline: none; }
.report textarea:focus { border-color: var(--brand); background: var(--bg); }
.report .muted.small { margin: 0; }

/* ---------- Settings ---------- */
.settings { width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow-y: auto; }
.toggle { position: relative; }
.settings .dialog-inner { gap: 4px; }
.set-section { border-top: 1px solid var(--line); padding: 12px 2px 8px; }
.set-section h4 { margin: 0 0 8px; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.set-row > span { display: flex; flex-direction: column; font-weight: 500; }
.set-row small { color: var(--muted); font-size: 12.5px; font-weight: 400; margin-top: 2px; }
.set-note { margin: 4px 0 0; }
.set-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.profile-row { display: flex; gap: 14px; align-items: center; }
.name-form { flex: 1; display: grid; gap: 4px; }
.name-row { display: flex; gap: 8px; }
.name-row input { flex: 1; min-width: 0; }
.danger-btn { background: transparent; color: var(--danger); border: 1px solid var(--line); margin-top: 8px; }
.danger-btn:hover { background: var(--bg-hover); }

.segmented { display: inline-flex; background: var(--bg-2); border-radius: 10px; padding: 3px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: grid; place-items: center; min-width: 54px; height: 30px; padding: 0 10px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.segmented input:checked + span { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 0; padding: 0; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.25); }
.swatch.chosen { outline: 3px solid var(--text); outline-offset: 2px; }

.toggle { cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; flex: none; transition: background 0.15s; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: transform 0.15s; }
.toggle input:checked + i { background: var(--brand); }
.toggle input:checked + i::after { transform: translateX(18px); }
.toggle input:focus-visible + i { outline: 2px solid var(--brand); outline-offset: 2px; }
.toggle input:disabled + i { opacity: 0.5; }

/* ---------- Dialog ---------- */
.dialog { border: 0; padding: 0; border-radius: 18px; width: min(440px, calc(100vw - 24px)); background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(10, 15, 30, 0.45); }
.dialog-inner { display: grid; gap: 10px; padding: 16px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h3 { font-size: 18px; }
.picked { display: flex; flex-wrap: wrap; gap: 6px; }
.picked:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-active); color: var(--brand); border: 0; border-radius: 16px; padding: 4px 10px; font-weight: 600; font-size: 13px; }
.user-results { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; min-height: 60px; }
.user-results li { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; }
.user-results li:hover { background: var(--bg-hover); }
.user-results li.selected { background: var(--bg-active); }
.user-results .hint { color: var(--muted); cursor: default; justify-content: center; }
.user-results .hint:hover { background: none; }
.u-name { font-weight: 600; }
.u-handle { font-size: 12.5px; color: var(--muted); }
.check { margin-left: auto; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); }
li.selected .check { background: var(--brand); border-color: var(--brand); box-shadow: inset 0 0 0 3px var(--bg); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  /* A fixed, app-like screen: the page never scrolls, bounces, zooms or slides sideways */
  html, body { position: fixed; inset: 0; width: 100%; overflow: hidden; overscroll-behavior: none; }
  body { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
  .app { grid-template-columns: 1fr; height: var(--app-h, 100dvh); overflow: hidden; }
  .sidebar, .chat, .chat-view, .messages, .conv-list { overflow-x: hidden; }
  .conv-list, .messages { overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; }
  /* 16px stops iPhone from zooming the page when you tap a text box */
  input, textarea, select, .composer textarea, .search input { font-size: max(16px, var(--msg-fs)); }
  .sidebar-head, .chat-head, .composer, .status-strip { -webkit-user-select: none; user-select: none; }

  .sidebar { border-right: 0; padding-top: env(safe-area-inset-top); }
  .chat { display: none; }
  .app.chat-open .sidebar { display: none; }
  .app.chat-open .chat { display: flex; }
  .back-btn { display: inline-grid; }

  /* Chat list: bigger rows and photos, thin dividers */
  .sidebar-head { padding: 10px 14px 6px; }
  .sidebar-head .icon-btn { width: 38px; height: 38px; background: transparent; }
  .search { margin: 4px 14px 8px; }
  .search input { padding: 10px 14px 10px 38px; }
  .conv-list { padding: 0 0 calc(12px + env(safe-area-inset-bottom)); }
  .conv { border-radius: 0; padding: 10px 16px; gap: 14px; min-height: 72px; position: relative; }
  .conv .avatar { --size: 52px; }
  .conv-body { align-self: stretch; display: grid; align-content: center; gap: 3px; }
  .conv-body::after { content: ""; position: absolute; left: 82px; right: 0; bottom: 0; border-bottom: 1px solid var(--line); opacity: 0.6; }
  .conv:last-child .conv-body::after { display: none; }
  .conv-name { font-size: 16.5px; }
  .conv-preview { font-size: 14.5px; }
  .conv.unread .conv-time { color: var(--brand); font-weight: 700; }
  .badge { min-width: 21px; height: 21px; padding: 0 6px; border-radius: 11px; display: inline-grid; place-items: center; font-size: 12px; }
  .conv:active { background: var(--bg-hover); }
  .secret-entry, .secret-bar { margin-left: 10px; margin-right: 10px; }

  /* Chat header: back · photo · name/status (gets all the free room) · call buttons */
  .chat-head { gap: 2px; padding: 6px 4px 6px 2px; padding-top: max(6px, env(safe-area-inset-top)); min-height: 60px; background: var(--bg); position: relative; z-index: 2; }
  .chat-head .icon-btn { width: 40px; height: 40px; background: transparent; }
  .chat-head .chat-id { gap: 10px; padding: 4px; margin: 0; }
  .chat-head .chat-title h3 { font-size: 16.5px; }
  .chat-head #chat-status { font-size: 12.5px; }
  .chat-head #chat-avatar { --size: 40px; }
  .chat-head .mute-btn { display: none; } /* Mute is in the contact / group info */

  /* Messages */
  .messages { padding: 10px 10px 6px; }
  .bubble { max-width: 84%; padding: 6px 10px 8px; }
  .msg-stack { max-width: 84%; }
  .row:not(.mine) .msg-stack .bubble, .row.mine .msg-stack .bubble { max-width: 100%; }
  .msg-image { max-width: min(260px, 100%); }
  .msg-actions { display: none; }
  .day-sep { background: var(--bg-2); padding: 4px 12px; border-radius: 8px; font-size: 12px; margin: 10px 0 6px; position: sticky; top: 4px; z-index: 1; box-shadow: 0 1px 2px rgba(0,0,0,0.12); }
  .receipt { margin-right: 4px; }

  /* Typing box: rounded field with buttons inside the bar, sits right above the keyboard */
  .composer { gap: 4px; padding: 6px 6px; padding-bottom: max(6px, env(safe-area-inset-bottom)); background: var(--bg); }
  html.kb-open .composer { padding-bottom: 6px; } /* keyboard covers the home-bar area */
  .composer textarea { min-height: 44px; padding: 11px 44px 11px 16px; border-radius: 22px; line-height: 22px; }
  .composer .emoji-btn { bottom: 6px; }
  .attach-btn, .cam-btn { width: 38px; height: 44px; }
  .send-btn { width: 44px; height: 44px; background: var(--brand-grad); color: #fff; }
  .send-btn:disabled { color: #fff; opacity: 0.45; }
  .send-btn svg path:last-child { stroke: var(--brand); }

  .dialog { margin-top: auto; margin-bottom: 0; border-radius: 18px 18px 0 0; width: 100vw; max-width: 100vw; }
  .dialog-inner { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .profile-panel { height: var(--app-h, 100dvh); bottom: auto; }
}

/* ---------- End-to-end encryption ---------- */
.e2e-notice { align-self: center; max-width: 440px; margin: 6px auto 10px; padding: 8px 12px; border-radius: 10px; background: #fff5c4; color: #54471a; font-size: 12.5px; line-height: 1.4; text-align: center; cursor: pointer; }
:root[data-theme="dark"] .e2e-notice { background: #3a3415; color: #f3e6a6; }
.pp-e2e { display: grid; gap: 8px; font-size: 14px; }
.e2e-code { display: grid; gap: 6px; }
.e2e-digits { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; letter-spacing: 1px; line-height: 1.7; color: var(--text); word-spacing: 6px; }
.e2e-input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); color: var(--text); font-size: 16px; margin-top: 8px; }
.e2e-input[hidden] { display: none; }
.call-e2e { margin-top: 6px; font-size: 13px; opacity: 0.75; }
.call-e2e[hidden] { display: none; }
/* ---------- Encryption info in every chat, flash messages, deleted messages ---------- */
.e2e-notice { display: block; border: 0; font: inherit; font-size: 12.5px; }
#cd-text { white-space: pre-line; }
.e2e-lock { border: 0; background: none; padding: 0 0 0 6px; font-size: 13px; cursor: pointer; vertical-align: 1px; opacity: 0.8; }
.flash-btn.on { color: #f59f00; }
.flash-btn.on svg { fill: #f59f00; }
.composer.flash-on .input-wrap { box-shadow: 0 0 0 2px #f59f00 inset; }
.flash-btn[hidden] { display: none; }
.flash-bubble { display: flex; align-items: center; gap: 10px; min-width: 200px; border: 0; font: inherit; text-align: left; cursor: default; }
button.flash-bubble { cursor: pointer; }
.flash-bubble .flash-icon { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: #fff3bf; font-size: 17px; flex: none; }
.flash-bubble .flash-text { display: grid; gap: 1px; flex: 1; }
.flash-bubble .flash-text small { opacity: 0.75; font-size: 12px; }
.flash-bubble.opened .flash-icon { background: rgba(127, 127, 127, 0.18); filter: grayscale(1); }
.flash-bubble.opened .flash-text b { font-weight: 500; opacity: 0.75; }
.flash-view { position: fixed; inset: 0; z-index: 1000; background: #000; color: #fff; display: flex; flex-direction: column; user-select: none; -webkit-user-select: none; }
.flash-view[hidden] { display: none; }
.flash-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top)); }
.flash-head #flash-from { font-weight: 600; }
.flash-note { flex: 1; font-size: 12px; opacity: 0.7; }
.flash-close, .flash-close:hover { color: #fff; background: rgba(255,255,255,.16); }
.flash-content { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 16px; overflow: auto; }
.flash-img { max-width: 100%; max-height: 70vh; object-fit: contain; pointer-events: none; }
.flash-txt { font-size: 20px; line-height: 1.45; text-align: center; max-width: 640px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.bubble.unsent .msg-time { margin-left: 8px; }
/* Contacts on Bluewez, in the chat list */
.conv-section { list-style: none; padding: 14px 16px 6px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.contact-row .conv-preview span { color: var(--muted); }
.find-contacts-icon { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: var(--bg-2); flex: none; }
.find-contacts .conv-name { color: var(--brand); font-weight: 600; }.composer .flash-btn { right: 36px; }
.input-wrap:has(.flash-btn:not([hidden])) textarea { padding-right: 76px; }
/* Text formatting in messages: *bold* _italic_ ~strike~ `code` ```block``` lists and quotes */
.bubble strong, .flash-txt strong, .format-preview strong { font-weight: 700; }
.fmt-code { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: .9em; background: rgba(127,127,127,.2); padding: 1px 5px; border-radius: 5px; }
.fmt-pre { display: block; margin: 4px 0; padding: 8px 10px; background: rgba(127,127,127,.16); border-radius: 8px; font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: .88em; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; text-align: left; }
.fmt-list { margin: 2px 0; padding-left: 22px; white-space: normal; text-align: left; }
.fmt-list li { white-space: pre-wrap; margin: 1px 0; }
.fmt-quote { margin: 4px 0; padding: 2px 0 2px 10px; border-left: 3px solid currentColor; opacity: .85; white-space: pre-wrap; text-align: left; }
.flash-txt .fmt-list, .flash-txt .fmt-quote, .flash-txt .fmt-pre { display: inline-block; }

/* Formatting bar and live preview above the message box */
.format-tools { padding: 6px 12px 0; display: grid; gap: 6px; background: var(--bg); }
.format-tools[hidden], .format-bar[hidden], .format-preview[hidden] { display: none; }
.format-bar { display: flex; gap: 4px; align-items: center; overflow-x: auto; scrollbar-width: none; }
.format-bar::-webkit-scrollbar { display: none; }
.format-bar button { flex: none; }
.format-bar button { min-width: 34px; height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); color: var(--text); font-size: 14px; cursor: pointer; }
.format-bar button:hover { background: var(--bg-hover); border-color: var(--brand); }
.format-bar .fb-mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.fb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.format-preview { max-height: 120px; overflow-y: auto; align-self: end; justify-self: end; max-width: min(85%, 560px); opacity: .95; position: relative; }
.format-preview::before { content: 'Preview'; display: block; font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; opacity: .7; margin-bottom: 2px; white-space: normal; }
.format-btn { width: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--brand); display: grid; place-items: center; font-size: 15px; cursor: pointer; flex: none; letter-spacing: -1px; }
.format-btn:hover { background: var(--bg-hover); }
.format-btn.on { background: var(--brand); color: #fff; }
/* Settings: link rows (More from Bluewez, Help & about) and Delete account */
.set-link { display: flex; align-items: center; gap: 12px; padding: 10px 4px; color: var(--text); text-decoration: none; border-radius: 10px; }
.set-link:hover { background: var(--bg-hover); }
.set-link > span:nth-child(2) { flex: 1; display: grid; }
.set-link small { color: var(--muted); font-size: 12.5px; }
.sl-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--bg-2); display: grid; place-items: center; font-size: 18px; flex: none; }
.sl-out { color: var(--muted); font-size: 18px; }
.delete-account-btn { display: block; margin: 14px auto 4px; font-size: 14px; cursor: pointer; }
.da-list { margin: 0 0 8px; padding-left: 20px; font-size: 14px; }
#da-input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2); color: var(--text); font-size: 16px; letter-spacing: .08em; margin-top: 4px; }
#da-error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }
#da-ok:disabled { opacity: .5; }