:root {
  --brand: #008069;
  --brand-dark: #006e5a;
  --accent: #25d366;
  --bg: #f0f2f5;
  --panel: #ffffff;
  --chat-bg: #efeae2;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --text: #111b21;
  --muted: #667781;
  --line: #e9edef;
  --hover: #f5f6f6;
  --active: #f0f2f5;
  --tick-read: #53bdeb;
  --danger: #d93025;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141a;
    --panel: #111b21;
    --chat-bg: #0b141a;
    --bubble-in: #202c33;
    --bubble-out: #005c4b;
    --text: #e9edef;
    --muted: #8696a0;
    --line: #222d34;
    --hover: #202c33;
    --active: #2a3942;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); }

/* ---------- buttons & forms ---------- */
.btn {
  display: block; width: 100%;
  background: var(--brand); color: #fff;
  border: 0; border-radius: 24px;
  padding: 12px 18px; font-weight: 600;
}
.btn:hover { background: var(--brand-dark); }
.btn.small { display: inline-block; width: auto; padding: 8px 16px; font-size: 14px; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.btn.ghost:hover { background: rgba(0,128,105,.08); }
.link-btn { background: none; border: 0; color: var(--brand); padding: 0; }
.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: none; border: 0; color: var(--muted);
  text-decoration: none; flex-shrink: 0;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.alert { padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; font-size: 14px; }
.alert-err { background: #fde8e7; color: var(--danger); }
.alert-ok { background: #e2f7ed; color: var(--brand-dark); }

/* ---------- auth pages ---------- */
.auth-body {
  min-height: 100%;
  background: linear-gradient(var(--brand) 0 220px, var(--bg) 220px);
  padding: 32px 16px;
}
.auth-card {
  max-width: 420px; margin: 0 auto;
  background: var(--panel); border-radius: 12px;
  padding: 28px 24px; box-shadow: 0 6px 24px rgba(0,0,0,.12);
}
.auth-logo { display: flex; align-items: center; gap: 10px; color: var(--brand); margin-bottom: 16px; }
.auth-logo h1 { font-size: 22px; margin: 0; }
.auth-card h2 { margin: 0 0 6px; font-size: 20px; }
.auth-card p.muted { margin: 0 0 18px; font-size: 14px; }
.auth-card label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
.auth-card label small { font-size: 12px; }
.auth-card input:not([type=hidden]) {
  display: block; width: 100%; margin-top: 6px;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); outline: none;
}
.auth-card input:focus { border-color: var(--brand); }
.otp-input {
  text-align: center; font-size: 28px !important;
  letter-spacing: 12px; margin-bottom: 16px !important;
}
.switch { text-align: center; font-size: 14px; margin: 18px 0 0; }
form.inline { text-align: center; margin-top: 14px; font-size: 14px; color: var(--muted); }

/* ---------- app layout ---------- */
.app-body { overflow: hidden; }
.app {
  display: grid; grid-template-columns: minmax(300px, 30%) 1fr;
  height: 100vh; height: 100dvh;
  max-width: 1600px; margin: 0 auto;
  background: var(--panel);
}
.bar {
  display: flex; align-items: center; gap: 10px;
  height: 60px; padding: 0 12px;
  background: var(--active); flex-shrink: 0;
}
.bar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.bar-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title small { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.avatar {
  position: relative; flex-shrink: 0;
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 17px;
}
.avatar .dot {
  position: absolute; right: 0; bottom: 0;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--panel);
}

/* sidebar */
.sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; }
.filter { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.filter input {
  width: 100%; padding: 8px 14px; border: 0; border-radius: 8px;
  background: var(--active); outline: none;
}
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; }
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }
.chat-mid { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: -10px; }
.chat-item:last-child .chat-mid { border-bottom: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview { color: var(--muted); font-size: 14px; }
.time { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.time.unread { color: var(--accent); }
.badge {
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  display: grid; place-items: center; flex-shrink: 0;
}
.empty-list { padding: 32px 20px; text-align: center; color: var(--muted); }

/* conversation */
.convo { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.convo-empty {
  margin: auto; text-align: center; color: var(--muted); padding: 24px; max-width: 420px;
}
.convo-empty svg { color: var(--brand); opacity: .5; }
.convo-empty h2 { color: var(--text); font-weight: 400; }
.convo-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.convo-inner[hidden], .convo-empty[hidden] { display: none; }
.back { display: none; }

.messages {
  flex: 1; overflow-y: auto; padding: 16px 6%;
  display: flex; flex-direction: column; gap: 3px;
}
.day-divider {
  align-self: center; margin: 10px 0;
  background: var(--panel); color: var(--muted);
  font-size: 12.5px; padding: 5px 12px; border-radius: 8px;
  box-shadow: 0 1px .5px rgba(0,0,0,.13);
}
.bubble {
  max-width: min(65%, 560px); padding: 6px 8px 8px 9px;
  border-radius: 8px; box-shadow: 0 1px .5px rgba(0,0,0,.13);
  font-size: 14.5px; line-height: 1.4;
  word-wrap: break-word; white-space: pre-wrap;
}
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 0; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 0; }
.bubble .meta {
  float: right; margin: 6px 0 -4px 10px;
  font-size: 11px; color: var(--muted);
  display: inline-flex; gap: 3px; align-items: center;
}
.bubble .tick { letter-spacing: -3px; padding-right: 3px; }
.bubble.read .tick { color: var(--tick-read); }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px; background: var(--active);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1; resize: none; border: 0; outline: none;
  border-radius: 8px; padding: 10px 14px; max-height: 120px;
  background: var(--panel); line-height: 1.35;
}
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--brand); color: #fff; display: grid; place-items: center; flex-shrink: 0;
}
.send-btn svg { width: 22px; height: 22px; fill: currentColor; }

/* dialog */
dialog {
  width: min(420px, calc(100% - 32px)); border: 0; border-radius: 12px;
  padding: 16px; background: var(--panel); color: var(--text);
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.dlg-search { display: flex; gap: 8px; }
.dlg-search input {
  flex: 1; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; outline: none; background: var(--panel); min-width: 0;
}
.dlg-search input:focus { border-color: var(--brand); }
.result-card {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding: 12px; border: 1px solid var(--line); border-radius: 10px; margin-top: 8px;
}
.result-card .chat-mid { border: 0; margin: 0; padding: 0; }
.result-actions { display: flex; gap: 8px; width: 100%; justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #323232; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 14px; z-index: 50;
}

/* ---------- mobile: one pane at a time ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .sidebar > .bar { background: var(--brand); color: #fff; }
  .sidebar > .bar .icon-btn, .sidebar > .bar small { color: rgba(255,255,255,.85); }
  .convo { display: none; }
  .app.show-convo .sidebar { display: none; }
  .app.show-convo .convo { display: flex; }
  .convo .bar { background: var(--brand); color: #fff; padding-left: 4px; }
  .convo .bar small, .convo .bar .icon-btn { color: rgba(255,255,255,.85); }
  .convo .bar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.7); }
  .back { display: grid; }
  .messages { padding: 12px 10px; }
  .bubble { max-width: 82%; }
}

/* ---------- call history in chat ---------- */
.bubble.call-log { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bubble.call-log .call-icon { font-size: 16px; }
.bubble.call-log.missed .text { color: var(--danger); font-weight: 600; }
.bubble.call-log .meta { margin-left: auto; float: none; margin-top: 0; margin-bottom: 0; }

/* ---------- call screen ---------- */
.call {
  position: fixed; inset: 0; z-index: 100;
  background: radial-gradient(circle at 50% 30%, #1f6f5c 0%, #0b3b32 55%, #06231e 100%);
  color: #fff; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: max(40px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
.call[hidden] { display: none !important; }
body.in-call { overflow: hidden; }

.call-info { text-align: center; position: relative; z-index: 2; margin-top: 6vh; }
.call-info h2 { margin: 18px 0 6px; font-size: 26px; font-weight: 500; }
.call-info p { margin: 0; font-size: 16px; opacity: .85; font-variant-numeric: tabular-nums; }
.avatar.big { width: 112px; height: 112px; font-size: 44px; margin: 0 auto; box-shadow: 0 0 0 10px rgba(255,255,255,.06), 0 0 0 22px rgba(255,255,255,.03); }

/* remote video fills the screen; voice calls keep it invisible (it still plays the audio) */
#remoteVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; opacity: 0; pointer-events: none; }
.call.video.connected #remoteVideo { opacity: 1; }
.call.video.connected .call-info { margin-top: 0; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.call.video.connected .call-info .avatar, .call.video.connected .call-info h2 { display: none; }
.call.video.connected .call-info p {
  background: rgba(0,0,0,.35); padding: 4px 12px; border-radius: 14px; display: inline-block;
}

/* my own camera: full screen while ringing, small corner window during the call */
#localVideo { display: none; position: absolute; object-fit: cover; background: #111; z-index: 1; }
.call.video #localVideo { display: block; inset: 0; width: 100%; height: 100%; opacity: .55; }
.call.video.connected #localVideo {
  inset: auto; top: max(16px, env(safe-area-inset-top)); right: 16px;
  width: 110px; height: 160px; border-radius: 12px; opacity: 1;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
#localVideo.mirror { transform: scaleX(-1); }
#localVideo.hidden-cam { visibility: hidden; }

.call-controls { display: flex; gap: 22px; position: relative; z-index: 2; padding: 14px 22px; border-radius: 40px; }
.call.connected .call-controls { background: rgba(0,0,0,.3); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.cbtn {
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.18); color: #fff;
  display: grid; place-items: center; transition: transform .1s, background .15s;
}
.cbtn:active { transform: scale(.92); }
.cbtn svg { width: 28px; height: 28px; fill: currentColor; }
.cbtn.off { background: #fff; color: #111; }
.cbtn.red { background: #ea0038; }
.cbtn.green { background: #25d366; animation: pulse 1.4s infinite; }
.cbtn[hidden] { display: none !important; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(37,211,102,.6); }
  100% { box-shadow: 0 0 0 18px rgba(37,211,102,0); }
}

@media (min-width: 761px) {
  .call.video.connected #localVideo { width: 200px; height: 130px; }
}

.add-peer { display: inline-flex !important; align-items: center; gap: 6px; flex-shrink: 0; }
.add-peer svg { width: 18px; height: 18px; fill: currentColor; }
.add-peer[hidden] { display: none !important; }
.app, .convo-inner { overflow: hidden; }
@media (max-width: 760px) {
  .add-peer { padding: 8px !important; border-radius: 50%; }
  .add-peer span { display: none; }
  .convo .bar { gap: 4px; }
}

/* =====================================================================
   Phase 3: profiles, groups, photos, voice notes, notifications, install
   ===================================================================== */
.avatar { background-size: cover; background-position: center; overflow: hidden; }
.avatar.has-img { color: transparent; }
.avatar svg { width: 60%; height: 60%; fill: #fff; color: #fff; }
.avatar.huge { width: 140px; height: 140px; font-size: 56px; margin: 0 auto; }
.avatar.clickable { cursor: pointer; }
.avatar-btn { background: none; border: 0; padding: 0; border-radius: 50%; }
.empty-logo { border-radius: 20px; opacity: .9; }

/* menu */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 44px; z-index: 30; min-width: 190px;
  background: var(--panel); border-radius: 8px; padding: 6px 0;
  box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.menu button {
  display: block; width: 100%; text-align: left; padding: 11px 18px;
  background: none; border: 0; color: var(--text); font-size: 14.5px;
}
.menu button:hover { background: var(--hover); }

/* banners */
.banner {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: #e7f6f2; border-bottom: 1px solid var(--line);
}
.banner-icon { width: 38px; height: 38px; border-radius: 50%; background: var(--brand); display: grid; place-items: center; flex-shrink: 0; }
.banner-icon svg { width: 20px; height: 20px; fill: #fff; }
.banner-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.banner-text strong { font-size: 14px; }
.banner-text small { color: var(--muted); font-size: 12.5px; }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.small svg { width: 18px; height: 18px; }
@media (prefers-color-scheme: dark) { .banner { background: #182229; } }

/* conversation header is a button (opens info) */
.peer-head {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  background: none; border: 0; padding: 0; color: inherit; text-align: left;
}

/* composer */
.composer { align-items: flex-end; }
.composer .icon-btn { margin-bottom: 2px; }
.send-btn[hidden] { display: none !important; }
.recorder {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  background: var(--active); padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.recorder[hidden] { display: none !important; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #ea0038; animation: blink 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-size: 16px; min-width: 44px; }
.rec-hint { flex: 1; color: var(--muted); font-size: 14px; }
@keyframes blink { 50% { opacity: .25; } }

/* messages */
.bubble.cont { margin-top: -1px; }
.bubble.cont.in { border-top-left-radius: 8px; }
.bubble.cont.out { border-top-right-radius: 8px; }
.messages > .bubble:not(.cont) { margin-top: 6px; }
.sender-name { font-size: 12.5px; font-weight: 600; margin-bottom: 2px; }
.system-line {
  align-self: center; text-align: center; max-width: 85%;
  background: var(--panel); color: var(--muted); font-size: 12.5px;
  padding: 5px 12px; border-radius: 8px; margin: 6px 0;
  box-shadow: 0 1px .5px rgba(0,0,0,.08);
}
.bubble.media { padding: 4px 4px 6px; }
.bubble.media .sender-name { padding: 2px 5px 0; }
.photo { display: block; max-width: 100%; height: auto; border-radius: 6px; cursor: pointer; background: rgba(0,0,0,.06); object-fit: cover; }
.bubble.media .caption { display: block; padding: 5px 5px 0; }
.bubble.media .meta { margin-right: 4px; }
.bubble.media:not(:has(.caption)) .meta {
  position: relative; float: right; margin: -26px 8px 0 0;
  background: rgba(0,0,0,.4); color: #fff; padding: 1px 6px; border-radius: 10px;
}
.bubble.pending { opacity: .85; min-width: 200px; }
.bubble.pending.failed { background: #fde8e7; color: var(--danger); }
.progress { height: 4px; background: rgba(0,0,0,.1); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }

.bubble.voice { min-width: 240px; }
.vplayer { display: flex; align-items: center; gap: 10px; padding: 2px 0; }
.vplay {
  width: 38px; height: 38px; border-radius: 50%; border: 0; flex-shrink: 0;
  background: var(--brand); color: #fff; display: grid; place-items: center;
}
.vplay svg { width: 20px; height: 20px; fill: currentColor; }
.vbar { flex: 1; min-width: 80px; accent-color: var(--brand); height: 4px; }
.vtime { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; }
.bubble.voice .meta { margin-top: 0; }

/* dialogs */
dialog.tall { max-height: 86vh; max-height: 86dvh; overflow-y: auto; }
dialog.small { width: min(360px, calc(100% - 32px)); }
.dlg-label { font-size: 13px; color: var(--muted); margin: 14px 0 8px; }
.dlg-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.dlg-foot.right { justify-content: flex-end; }
.field {
  display: block; width: 100%; padding: 10px 12px; margin: 0 0 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); outline: none;
}
.field:focus { border-color: var(--brand); }
.field[readonly] { background: var(--active); color: var(--muted); }
.field[hidden] { display: none; }
.list-action {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 4px;
  background: none; border: 0; color: var(--text); font-size: 15px; text-align: left; border-radius: 8px;
}
.list-action:hover { background: var(--hover); }
.la-icon { width: 42px; height: 42px; border-radius: 50%; background: var(--brand); display: grid; place-items: center; }
.la-icon svg { width: 22px; height: 22px; fill: #fff; }
.pick-list { max-height: 45vh; overflow-y: auto; margin: 0 -4px; }
.pick-row { display: flex; align-items: center; gap: 12px; padding: 8px 4px; border-radius: 8px; cursor: pointer; }
.pick-row:hover { background: var(--hover); }
.pick-row input { width: 20px; height: 20px; accent-color: var(--brand); flex-shrink: 0; }
.pick-row .chat-mid, .member-row .chat-mid { border: 0; margin: 0; padding: 0; }
.photo-preview { display: block; max-width: 100%; max-height: 55vh; margin: 0 auto 12px; border-radius: 8px; }
.btn.danger { background: var(--danger); }
.danger-text { color: var(--danger) !important; border-color: var(--danger) !important; }
.ios-steps { padding-left: 22px; line-height: 1.6; font-size: 15px; }

/* info panels */
.big-avatar-wrap { text-align: center; margin: 6px 0 14px; }
.avatar-actions { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.info-name { text-align: center; margin: 4px 0 2px; font-size: 22px; font-weight: 500; }
.info-sub { text-align: center; margin: 2px 0; font-size: 14px; }
.info-field { display: block; }
.info-label { display: block; font-size: 12.5px; color: var(--brand); margin-bottom: 4px; font-weight: 600; }
.info-section { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.info-section p { margin: 0; }
.info-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: 14.5px; }
.info-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.inline-edit { display: flex; gap: 8px; align-items: flex-end; }
.inline-edit .info-field { flex: 1; }
.inline-edit .btn { margin-bottom: 10px; }
.member-row { display: flex; align-items: center; gap: 12px; padding: 8px 4px; border-radius: 8px; }
.member-row.clickable { cursor: pointer; }
.member-row.clickable:hover { background: var(--hover); }
.admin-badge { font-size: 11.5px; color: var(--brand); border: 1px solid var(--brand); border-radius: 6px; padding: 1px 6px; flex-shrink: 0; }
.member-menu { display: flex; flex-direction: column; margin: 0 0 6px 58px; border-left: 2px solid var(--brand); }
.member-menu button { background: none; border: 0; text-align: left; padding: 8px 12px; color: var(--text); font-size: 14px; }
.member-menu button:hover { background: var(--hover); }
#infoBody > .btn { margin-top: 16px; }

/* photo viewer */
.viewer {
  position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px;
}
.viewer[hidden] { display: none !important; }
.viewer img { max-width: 100%; max-height: calc(100% - 80px); object-fit: contain; border-radius: 4px; }
.viewer p { color: #fff; margin: 12px 0 0; text-align: center; max-width: 600px; }
#viewerClose { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; color: #fff; background: rgba(255,255,255,.12); }

@media (max-width: 760px) {
  .sidebar > .bar .avatar-btn .avatar:not(.has-img) { background-color: rgba(255,255,255,.2) !important; }
  .convo .bar .peer-head { color: #fff; }
  dialog { max-height: 90dvh; }
}
.peer-head:focus, .avatar-btn:focus { outline: none; }
.peer-head:focus-visible, .avatar-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 8px; }

/* =====================================================================
   Phase 4: status, typing, ticks, block & report
   ===================================================================== */
.side-tabs { display: flex; background: var(--panel); border-bottom: 1px solid var(--line); }
.side-tabs button {
  flex: 1; padding: 11px 0; background: none; border: 0; border-bottom: 3px solid transparent;
  color: var(--muted); font-weight: 600; font-size: 14.5px; position: relative;
}
.side-tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.tab-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); vertical-align: middle; margin-left: 4px; }
.tab-dot[hidden] { display: none; }
.side-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-pane[hidden] { display: none !important; }
.status-pane { overflow-y: auto; }
.status-pane .chat-list { flex: none; overflow: visible; }
.status-me { display: flex; align-items: center; gap: 4px; padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--line); }
.status-me-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 0; text-align: left; color: var(--text); }
.status-me-main .chat-mid { border: 0; margin: 0; padding: 0; }
.status-label { margin: 14px 16px 4px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.status-label[hidden] { display: none; }
.status-note { padding: 16px; text-align: center; }
.ring { padding: 2px; border-radius: 50%; border: 2.5px solid #c5ccd0; flex-shrink: 0; }
.ring.unseen { border-color: var(--accent); }
.ring.mine:not(.unseen) { border-color: transparent; }
.ring .avatar { width: 40px; height: 40px; }
#myRing:not(.unseen) { border-color: transparent; }

.typing-text { color: var(--accent) !important; font-weight: 500; }
.convo .bar .typing-text { color: #b8f5d0 !important; }
@media (min-width: 761px) { .convo .bar .typing-text { color: var(--brand) !important; } }

.bubble .tick.single { letter-spacing: 0; }
.blocked-bar {
  display: flex; align-items: center; justify-content: center; gap: 12px; padding: 12px;
  background: var(--active); color: var(--muted); font-size: 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.blocked-bar[hidden] { display: none !important; }
.safety .list-action { font-size: 14.5px; }
.report-reasons { display: flex; flex-direction: column; gap: 2px; margin: 10px 0; }
.report-reasons label, .check-row { display: flex; align-items: center; gap: 10px; padding: 7px 4px; font-size: 14.5px; cursor: pointer; border-radius: 6px; }
.report-reasons label:hover { background: var(--hover); }
.report-reasons input, .check-row input { width: 18px; height: 18px; accent-color: var(--brand); }

/* write a text status */
.status-compose {
  position: fixed; inset: 0; z-index: 95; display: flex; flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
  transition: background .25s;
}
.status-compose[hidden] { display: none !important; }
.sc-top { display: flex; justify-content: space-between; }
.sc-top .icon-btn { color: #fff; background: rgba(0,0,0,.18); }
#scText {
  flex: 1; width: 100%; background: transparent; border: 0; outline: none; resize: none;
  color: #fff; font-size: 30px; text-align: center; padding: 18vh 8px 0; line-height: 1.3;
}
#scText::placeholder { color: rgba(255,255,255,.65); }
.sc-send { position: absolute; right: 18px; bottom: max(20px, env(safe-area-inset-bottom)); width: 56px; height: 56px; background: var(--accent); }

/* status viewer */
.story { position: fixed; inset: 0; z-index: 96; background: #000; color: #fff; display: flex; flex-direction: column; }
.story[hidden] { display: none !important; }
body.in-story { overflow: hidden; }
.story-bars { display: flex; gap: 4px; padding: max(10px, env(safe-area-inset-top)) 10px 0; position: relative; z-index: 3; }
.sbar { flex: 1; height: 3px; background: rgba(255,255,255,.35); border-radius: 2px; overflow: hidden; }
.sbar i { display: block; height: 100%; width: 0; background: #fff; }
.story-head { display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 12px; position: relative; z-index: 3; }
.story-head .bar-title small { color: rgba(255,255,255,.75); }
.story-head .icon-btn { color: #fff; }
.story-head .icon-btn:hover { background: rgba(255,255,255,.12); }
.story-body { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; }
.story-text { max-width: 640px; padding: 24px; text-align: center; line-height: 1.35; white-space: pre-wrap; word-wrap: break-word; }
.story-img { max-width: 100%; max-height: 100%; object-fit: contain; }
.story-caption {
  position: absolute; bottom: 90px; left: 0; right: 0; text-align: center; padding: 10px 16px;
  background: rgba(0,0,0,.45); font-size: 16px;
}
.story-tap { position: absolute; top: 90px; bottom: 80px; z-index: 2; }
.story-tap.left { left: 0; width: 33%; }
.story-tap.right { right: 0; width: 67%; }
.story-foot {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; justify-content: center;
  padding: 12px 12px max(14px, env(safe-area-inset-bottom));
}
.story-views { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 20px; padding: 8px 16px; font-size: 15px; }
.story-views svg { width: 20px; height: 20px; fill: currentColor; }
.story-views[hidden], .story-reply[hidden] { display: none !important; }
.story-reply { display: flex; gap: 8px; width: 100%; max-width: 600px; }
.story-reply input { flex: 1; border: 0; border-radius: 24px; padding: 12px 16px; background: rgba(255,255,255,.18); color: #fff; outline: none; font-size: 15px; }
.story-reply input::placeholder { color: rgba(255,255,255,.7); }
.story-viewers {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; max-height: 60%; overflow-y: auto;
  background: var(--panel); color: var(--text); border-radius: 14px 14px 0 0; padding: 14px 16px max(16px, env(safe-area-inset-bottom));
}
.story-viewers[hidden] { display: none !important; }
.story-viewers .chat-mid { border: 0; margin: 0; padding: 0; }

/* messages shown before the server confirms them */
.bubble.sending .tick { letter-spacing: 0; font-size: 10px; }
.bubble.out.failed { background: #fde8e7; cursor: pointer; }
.bubble.out.failed .tick { color: var(--danger); letter-spacing: 0; }
@media (prefers-color-scheme: dark) { .bubble.out.failed { background: #4a1f1f; } }

/* =====================================================================
   Phase 6: reply / edit / delete, message menu, mute & archive, settings
   ===================================================================== */
.bubble { position: relative; }
.bubble .quote {
  display: flex; flex-direction: column; gap: 1px; cursor: pointer;
  background: rgba(0,0,0,.05); border-left: 4px solid var(--brand); border-radius: 6px;
  padding: 5px 8px; margin: 0 0 4px; font-size: 13px; max-width: 100%; overflow: hidden;
}
.bubble .quote strong { font-size: 12.5px; }
.bubble .quote span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bubble.out .quote { background: rgba(0,0,0,.06); }
@media (prefers-color-scheme: dark) { .bubble .quote { background: rgba(255,255,255,.07); } }
.bubble.deleted .text { font-style: italic; color: var(--muted); }
.bubble.flash { animation: flash 1.4s; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 1px .5px rgba(0,0,0,.13); } }
.bubble.selected { filter: brightness(.94); }
.more-btn {
  position: absolute; top: 2px; right: 2px; width: 24px; height: 22px; border: 0; border-radius: 6px;
  background: inherit; color: var(--muted); display: none; place-items: center; padding: 0; cursor: pointer;
}
.more-btn svg { width: 20px; height: 20px; fill: currentColor; }
@media (hover: hover) { .bubble:hover .more-btn { display: grid; } }
@media (pointer: coarse) { .bubble { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; } }

.msg-menu {
  position: fixed; z-index: 120; min-width: 170px; padding: 6px 0;
  background: var(--panel); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.25);
}
.msg-menu[hidden] { display: none; }
.msg-menu button { display: block; width: 100%; text-align: left; padding: 10px 16px; background: none; border: 0; color: var(--text); font-size: 14.5px; }
.msg-menu button:hover { background: var(--hover); }

.compose-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px 0; background: var(--active);
}
.compose-bar[hidden] { display: none !important; }
.cb-text {
  flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel);
  border-left: 4px solid var(--brand); border-radius: 8px; padding: 6px 10px; font-size: 13.5px;
}
.cb-text strong { color: var(--brand); font-size: 13px; }
.cb-text span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compose-bar.editing .cb-text { border-left-color: #f0a500; }
.compose-bar.editing .cb-text strong { color: #b07800; }

.stack-buttons { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.stack-buttons .btn { width: 100%; }
.stack-buttons [hidden] { display: none !important; }

/* chat menu sits in the green bar on phones */
.convo .menu { top: 46px; }

/* chat list: muted / archived */
.muted-ico { font-size: 12px; opacity: .7; flex-shrink: 0; }
.badge.muted { background: #a7b2b8; }
.archived-row { gap: 16px !important; padding: 12px 18px !important; }
.archived-row strong { flex: 1; font-weight: 600; }
.arch-ico { width: 42px; text-align: center; font-size: 18px; color: var(--brand); }
.arch-count { color: var(--brand); font-size: 13px; font-weight: 600; }

/* settings */
.settings-me, .settings-row {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: none; border: 0; padding: 12px 6px; border-radius: 10px; color: var(--text);
}
.settings-me { border-bottom: 1px solid var(--line); margin-bottom: 6px; padding-bottom: 14px; border-radius: 0; }
.settings-me .avatar { width: 56px; height: 56px; font-size: 22px; }
.settings-me:hover, .settings-row:hover { background: var(--hover); }
.sr-ico { width: 34px; text-align: center; font-size: 20px; flex-shrink: 0; }
.sr-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sr-text strong { font-weight: 600; font-size: 15px; }
.sr-text small { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.back-row { color: var(--brand); font-weight: 600; padding: 4px 2px 10px; }
.priv-row { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.priv-row select.field { width: auto; min-width: 130px; margin: 0; padding: 8px 10px; }
input.switch {
  appearance: none; -webkit-appearance: none; width: 44px; height: 26px; border-radius: 13px; flex-shrink: 0;
  background: #c5ccd0; position: relative; cursor: pointer; transition: background .15s; margin: 0;
}
input.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
input.switch:checked { background: var(--brand); }
input.switch:checked::after { left: 21px; }
.mini-form { border-top: 1px solid var(--line); padding: 4px 0; }
.mini-form summary { cursor: pointer; padding: 12px 2px; font-weight: 600; font-size: 15px; list-style: none; }
.mini-form summary::-webkit-details-marker { display: none; }
.mini-form summary::after { content: '›'; float: right; color: var(--muted); font-size: 20px; line-height: 1; transition: transform .15s; }
.mini-form[open] summary::after { transform: rotate(90deg); }
.mini-form form { padding: 0 2px 14px; }
.otp-small { letter-spacing: 6px; font-size: 20px; text-align: center; }
#infoBody > .btn.ghost { width: 100%; margin-top: 14px; }
@media (max-width: 760px) {
  .convo .bar .icon-btn:hover, .sidebar > .bar .icon-btn:hover { background: rgba(255,255,255,.15); }
}
