@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/vazirmatn-arabic.woff2') format('woff2-variations');
  font-weight: 100 900; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-089F, U+08A0-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/vazirmatn-latin.woff2') format('woff2-variations');
  font-weight: 100 900; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/vazirmatn-latin-ext.woff2') format('woff2-variations');
  font-weight: 100 900; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --brand: #0e7c66;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3ee;
  --bg: #ffffff;
  --bg-2: #f4f6f5;
  --chat-bg: #e8eeeb;
  --line: #e2e7e5;
  --ink: #12201c;
  --ink-2: #5d6b67;
  --ink-3: #8a9793;
  --out: #d9f2e8;
  --in: #ffffff;
  --danger: #d14343;
  --ok: #1f9d55;
  --read: #1a9fe0;
  --shadow: 0 1px 2px rgba(16, 32, 28, .08);
  --shadow-lg: 0 18px 50px rgba(16, 32, 28, .18);
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #2bb394;
    --brand-ink: #06231c;
    --brand-soft: #173a31;
    --bg: #131a18;
    --bg-2: #1a2320;
    --chat-bg: #0d1311;
    --line: #26322e;
    --ink: #e8efec;
    --ink-2: #a3b1ad;
    --ink-3: #75847f;
    --out: #1d4a3e;
    --in: #1d2724;
    --read: #5cc3f5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow-x: hidden; }
body {
  font-family: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--brand); }
[hidden] { display: none !important; }
#app { height: 100dvh; }

.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[dir="rtl"] .flip-rtl, [dir="rtl"] .back .ic { transform: scaleX(-1); }
.ic.down { transform: rotate(-90deg); }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: 12px; font-weight: 600; white-space: nowrap;
  transition: filter .15s, background .15s;
}
.btn .ic { width: 20px; height: 20px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: var(--bg-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; display: inline-grid; place-items: center; color: var(--ink-2);
  transition: background .15s, color .15s; flex: none;
}
.icon-btn:hover { background: var(--bg-2); color: var(--ink); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.danger { color: var(--danger); }
.icon-btn.light { color: #fff; }
.icon-btn.light:hover { background: rgba(255, 255, 255, .15); }
.input {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 12px 14px; resize: vertical; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: 12px; }
.form-error { color: var(--danger); min-height: 1.5em; margin: 8px 0 0; font-size: 14px; }
.hint { color: var(--ink-3); font-size: 13px; margin: 0; }
.center { text-align: center; }
.muted { color: var(--ink-2); }
.row { display: flex; gap: 10px; align-items: center; }
.row .input { flex: 1; }
.row-end { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }
.label { margin: 4px 0 0; font-size: 12px; font-weight: 700; letter-spacing: .02em; color: var(--ink-3); text-transform: uppercase; }
.chip { height: 34px; padding: 0 14px; border-radius: 99px; background: var(--bg-2); font-size: 14px; border: 1px solid transparent; }
.chip.on { background: var(--brand-soft); color: var(--brand); border-color: color-mix(in srgb, var(--brand) 40%, transparent); font-weight: 600; }
.lang-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.lang-bar.left { justify-content: flex-start; }
.badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 99px; background: var(--brand); color: var(--brand-ink);
  font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; line-height: 1;
}
.tag { flex: none; line-height: 1.4; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.tag.soft { background: var(--bg-2); color: var(--ink-2); }
.empty { color: var(--ink-3); text-align: center; padding: 28px 20px; margin: 0; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; display: inline-block; }
.spinner.light { border-color: rgba(255, 255, 255, .35); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 18px; }

/* ---------- auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--chat-bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--bg); border-radius: 22px; padding: 32px 24px; box-shadow: var(--shadow-lg); display: grid; gap: 14px; }
.auth-logo { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto; }
.auth-card h1 { margin: 0; text-align: center; font-size: 26px; letter-spacing: .01em; }
.auth-card .tagline { margin: -10px 0 4px; text-align: center; }
.auth-form { display: grid; gap: 14px; margin-top: 6px; }
.auth-form h2 { margin: 0; font-size: 19px; }
.auth-form p { margin: -6px 0 0; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 380px 1fr; height: 100dvh; }
.sidebar { display: flex; flex-direction: column; min-height: 0; border-inline-end: 1px solid var(--line); background: var(--bg); }
.side-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
.side-head h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; }
.me-btn { border-radius: 50%; }
.search-wrap { position: relative; margin: 0 12px 8px; }
.search-wrap .ic { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--ink-3); pointer-events: none; }
.search { width: 100%; height: 40px; border-radius: 12px; border: 0; background: var(--bg-2); padding-inline: 38px 12px; outline: none; }
.search::-webkit-search-cancel-button { display: none; }
.tabs { display: flex; gap: 6px; margin: 0 12px 8px; padding: 4px; background: var(--bg-2); border-radius: 12px; }
.tab { flex: 1; height: 34px; border-radius: 9px; font-weight: 600; color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.tab.on { background: var(--bg); color: var(--ink); box-shadow: var(--shadow); }
.tab .badge { min-width: 20px; height: 20px; font-size: 11px; }
.banner { display: flex; align-items: center; gap: 10px; margin: 0 12px 8px; padding: 10px 12px; border-radius: 12px; background: var(--brand-soft); font-size: 13px; }
.banner > .ic { color: var(--brand); }
.banner span { flex: 1; }
.offline { position: fixed; top: 0; inset-inline: 0; z-index: 50; text-align: center; padding: 6px 12px; padding-top: max(6px, env(safe-area-inset-top)); background: #b45309; color: #fff; font-size: 13px; }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.conv { display: flex; gap: 12px; align-items: center; padding: 9px 10px; border-radius: 14px; color: inherit; text-decoration: none; }
.conv:hover { background: var(--bg-2); }
.conv.active { background: var(--brand-soft); }
.conv-av { position: relative; flex: none; }
.dot { position: absolute; bottom: 1px; inset-inline-end: 1px; width: 13px; height: 13px; border-radius: 50%; background: var(--ok); border: 2.5px solid var(--bg); }
.conv-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.conv-row { display: flex; align-items: center; gap: 8px; }
.conv-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--ink-3); flex: none; }
.conv-prev { flex: 1; min-width: 0; color: var(--ink-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: start; }
.conv-prev.typing, .chat-sub.typing { color: var(--brand); }
.conv.unread .conv-time { color: var(--brand); font-weight: 600; }

.avatar { border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 600; overflow: hidden; flex: none; user-select: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar .ic { width: 55%; height: 55%; }

.pane { min-width: 0; min-height: 0; background: var(--chat-bg); position: relative; }
.pane.drop::after { content: ''; position: absolute; inset: 10px; border: 2px dashed var(--brand); border-radius: 18px; pointer-events: none; }
.pane-empty { height: 100%; display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--ink-3); }
.pane-empty img { width: 84px; height: 84px; border-radius: 24px; opacity: .9; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: 100dvh; }
.chat-head {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--bg); border-bottom: 1px solid var(--line); min-height: 60px;
}
.chat-head .back { display: none; }
.chat-id { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: start; padding: 2px 4px; border-radius: 12px; }
.chat-id-text { min-width: 0; }
.chat-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub.on { color: var(--brand); }
.head-actions { display: flex; gap: 2px; }
.head-actions .icon-btn { color: var(--brand); }
.scroll-area { position: relative; flex: 1; min-height: 0; }
.scroller { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; }
.msgs { max-width: 860px; margin: 0 auto; padding: 12px 14px 8px; display: flex; flex-direction: column; gap: 3px; }
.jump { position: absolute; bottom: 14px; inset-inline-end: 16px; width: 42px; height: 42px; border-radius: 50%; background: var(--bg); box-shadow: var(--shadow-lg); display: grid; place-items: center; color: var(--ink-2); }
.day { align-self: center; margin: 10px 0 6px; }
.day span { display: inline-block; padding: 3px 12px; border-radius: 99px; background: color-mix(in srgb, var(--bg) 80%, transparent); font-size: 12px; color: var(--ink-2); box-shadow: var(--shadow); }

.msg { display: flex; margin-top: 6px; }
.msg.compact { margin-top: 0; }
.msg.out { justify-content: flex-end; }
.msg.flash .bubble { animation: flash 1.2s ease; }
@keyframes flash { 30% { box-shadow: 0 0 0 3px var(--brand); } }
.bubble {
  position: relative; max-width: min(78%, 560px); padding: 7px 11px 6px; border-radius: 16px;
  background: var(--in); box-shadow: var(--shadow); overflow-wrap: anywhere; user-select: text; -webkit-user-select: text;
}
.msg.out .bubble { background: var(--out); }
.msg.in:not(.compact) .bubble { border-start-start-radius: 6px; }
.msg.out:not(.compact) .bubble { border-start-end-radius: 6px; }
.bubble .text { white-space: pre-wrap; display: inline; }
.bubble.deleted .text { font-style: italic; color: var(--ink-3); }
.sender { font-size: 13px; font-weight: 700; margin-bottom: 1px; }
.meta { float: inline-end; display: inline-flex; align-items: center; gap: 4px; margin-inline-start: 10px; margin-top: 6px; margin-bottom: -2px; font-size: 11px; color: var(--ink-3); line-height: 1; position: relative; top: 3px; }
.meta .edited { font-style: italic; }
.tick { display: inline-flex; }
.tick .ic { width: 16px; height: 16px; stroke-width: 2.2; }
.tick.read { color: var(--read); }
.tick.failed { color: var(--danger); }
.bubble.media { padding: 4px; }
.bubble.media .text { display: block; padding: 4px 7px 0; }
.bubble.media > .meta { margin: 4px 6px 2px; }
.bubble.media:not(:has(.text)) > .meta { position: absolute; bottom: 10px; inset-inline-end: 10px; margin: 0; top: auto; padding: 3px 7px; border-radius: 99px; background: rgba(0, 0, 0, .45); color: #fff; }
.bubble.media:not(:has(.text)) > .meta .tick.read { color: #9be0ff; }
.media-box { position: relative; max-width: 100%; border-radius: 12px; overflow: hidden; background: var(--bg-2); cursor: zoom-in; }
.media-box img, .media-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-box.video { cursor: default; background: #000; }
.media-wait { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .3); }
.quote {
  display: grid; text-align: start; gap: 0; width: 100%; padding: 5px 10px; margin: 2px 0 5px; border-radius: 8px;
  background: color-mix(in srgb, var(--ink) 6%, transparent); border-inline-start: 3px solid var(--brand); font-size: 13px;
}
.quote strong { font-size: 12.5px; }
.quote span { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.audio { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 2px 0; }
.play { width: 40px; height: 40px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; flex: none; }
.play .ic { width: 18px; height: 18px; stroke: none; }
.seek { flex: 1; accent-color: var(--brand); height: 4px; min-width: 100px; }
.atime { font-size: 12px; color: var(--ink-2); min-width: 34px; font-variant-numeric: tabular-nums; }
.file-row { display: flex; align-items: center; gap: 10px; text-align: start; min-width: 200px; padding: 2px 0; }
.file-ic { width: 42px; height: 42px; border-radius: 12px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; flex: none; }
.file-info { display: grid; min-width: 0; }
.file-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.file-info small { color: var(--ink-3); }
.msg.sys { justify-content: center; margin: 8px 0; }
.call-pill { display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 99px; background: var(--bg); box-shadow: var(--shadow); font-size: 13.5px; }
.call-pill .ic { width: 18px; height: 18px; color: var(--ok); }
.call-pill.missed .ic { color: var(--danger); }
.call-pill .meta { float: none; margin: 0; top: 0; }
.chat-empty { margin: auto; }

/* composer */
.composer-wrap { background: var(--bg); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px 0; max-width: 860px; margin: 0 auto; color: var(--brand); }
.reply-body { flex: 1; min-width: 0; display: grid; padding-inline-start: 10px; border-inline-start: 3px solid var(--brand); font-size: 13px; }
.reply-body span { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; max-width: 860px; margin: 0 auto; }
.composer-input {
  flex: 1; min-height: 44px; max-height: 160px; resize: none; border: 0; outline: none; border-radius: 22px;
  background: var(--bg-2); padding: 10px 16px; line-height: 1.5; overflow-y: auto;
}
.composer .icon-btn { height: 44px; width: 44px; }
.send-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; flex: none; transition: transform .1s; }
.send-btn:active { transform: scale(.94); }
.composer.recording { align-items: center; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s ease-in-out infinite; margin-inline-start: 4px; }
@keyframes pulse { 50% { opacity: .3; } }
.rec-label { flex: 1; color: var(--ink-2); }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; margin-inline-end: 6px; }

/* ---------- sheets ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(8, 16, 14, .45); display: flex; align-items: center; justify-content: center; padding: 16px; opacity: 0; transition: opacity .2s; }
.sheet.show { opacity: 1; }
.sheet-panel {
  width: 100%; max-width: 440px; max-height: min(86dvh, 760px); display: flex; flex-direction: column;
  background: var(--bg); border-radius: 20px; box-shadow: var(--shadow-lg); transform: translateY(12px); transition: transform .2s;
}
.sheet-panel.wide { max-width: 560px; }
.sheet.show .sheet-panel { transform: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 4px 20px; }
[dir="rtl"] .sheet-head { padding: 12px 20px 4px 12px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; }
.sheet-body { padding: 10px 20px 20px; overflow-y: auto; }
.dialog { display: grid; gap: 16px; }
.dialog p { margin: 0; font-size: 16px; }
.actions { display: grid; gap: 2px; margin: -4px -8px; }
.action { display: flex; align-items: center; gap: 14px; padding: 13px 12px; border-radius: 12px; text-align: start; font-size: 16px; }
.action:hover { background: var(--bg-2); }
.action .ic { color: var(--ink-2); }
.action.danger, .action.danger .ic { color: var(--danger); }
.people { display: grid; gap: 2px; margin: 0 -8px; }
.person { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px; text-align: start; width: 100%; }
.person:hover { background: var(--bg-2); }
.person-text { flex: 1; min-width: 0; display: grid; }
.person-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-text small { color: var(--ink-3); text-align: start; }
.person.accent { color: var(--brand); }
.round-ic { width: 42px; height: 42px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; flex: none; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); pointer-events: none; }
.profile-head { display: grid; justify-items: center; gap: 6px; }
.profile-name { font-size: 19px; font-weight: 700; }
.avatar-edit { position: relative; border-radius: 50%; }
.avatar-edit .cam { position: absolute; bottom: 0; inset-inline-end: 0; width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; border: 3px solid var(--bg); }
.avatar-edit .cam .ic { width: 16px; height: 16px; }
.card { display: grid; gap: 10px; padding: 14px; border-radius: 16px; background: var(--bg-2); }
.card .input, .card .chip:not(.on) { background: var(--bg); }
.list-actions { gap: 0; padding: 6px; }
.list-btn { display: flex; align-items: center; gap: 14px; padding: 11px 10px; border-radius: 10px; text-align: start; }
.list-btn:hover { background: var(--bg); }
.list-btn .ic { color: var(--ink-2); }
.list-btn.danger, .list-btn.danger .ic { color: var(--danger); }
.ok-line { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--ok); font-weight: 600; }
.invites { display: grid; gap: 6px; }
.invite { display: flex; align-items: center; gap: 10px; padding: 6px 4px 6px 8px; border-radius: 12px; background: var(--bg); }
[dir="rtl"] .invite { padding: 6px 8px 6px 4px; }

.toast { position: fixed; z-index: 80; bottom: calc(90px + env(safe-area-inset-bottom)); left: 50%; transform: translate(-50%, 10px); opacity: 0; transition: .25s; background: #1f2a27; color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-lg); max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .92); display: grid; place-items: center; }
.viewer img { max-width: 100%; max-height: 100dvh; object-fit: contain; }
.viewer-bar { position: absolute; top: max(8px, env(safe-area-inset-top)); inset-inline-end: 8px; display: flex; gap: 4px; z-index: 1; }

/* ---------- call ---------- */
.call { position: fixed; inset: 0; z-index: 70; background: radial-gradient(120% 90% at 50% 0%, #1d5a4c, #0b1714 70%); color: #fff; display: flex; flex-direction: column; }
.call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; opacity: 0; transition: opacity .3s; }
.call.is-voice .call-remote { width: 1px; height: 1px; }
.call.is-video.live .call-remote { opacity: 1; }
.call-local { position: absolute; z-index: 2; width: 110px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 14px; top: max(16px, env(safe-area-inset-top)); inset-inline-end: 16px; background: #000; box-shadow: var(--shadow-lg); transform: scaleX(-1); }
.call.is-voice .call-local { display: none; }
.call-top { position: relative; z-index: 1; flex: 1; display: grid; align-content: center; justify-items: center; gap: 8px; padding: 24px; text-align: center; }
.call.is-video.live .call-top { flex: none; align-content: start; justify-items: start; padding-top: max(18px, env(safe-area-inset-top)); text-shadow: 0 1px 6px rgba(0, 0, 0, .6); }
.call.is-video.live .call-avatar { display: none; }
.call-avatar { margin-bottom: 8px; border-radius: 50%; box-shadow: 0 0 0 8px rgba(255, 255, 255, .06), 0 0 0 18px rgba(255, 255, 255, .03); }
.call-name { font-size: 26px; font-weight: 700; }
.call-status, .call-timer { font-size: 15px; opacity: .85; font-variant-numeric: tabular-nums; }
.call.is-video.live { justify-content: space-between; }
.call-controls { position: relative; z-index: 1; display: flex; justify-content: center; gap: 22px; padding: 24px 16px; padding-bottom: max(28px, calc(env(safe-area-inset-bottom) + 16px)); }
.cbtn { display: grid; justify-items: center; gap: 6px; color: #fff; font-size: 12px; }
.cbtn .ic { width: 62px; height: 62px; padding: 18px; border-radius: 50%; background: rgba(255, 255, 255, .16); stroke-width: 1.8; box-sizing: border-box; }
.cbtn.off .ic { background: #fff; color: #10201b; }
.cbtn.red .ic { background: #e5484d; }
.cbtn.green .ic { background: #22a95e; }
.cbtn span { opacity: .9; }

/* ---------- responsive ---------- */
@media (max-width: 899px) {
  /* iOS zooms into inputs smaller than 16px on focus */
  input, textarea, .search, .composer-input, .input { font-size: 16px; }
  .shell { grid-template-columns: 1fr; }
  .pane { display: none; }
  body.in-chat .sidebar { display: none; }
  body.in-chat .pane { display: block; }
  .chat-head .back { display: inline-grid; }
  .sheet { align-items: flex-end; padding: 0; }
  .sheet-panel, .sheet-panel.wide { max-width: none; border-radius: 22px 22px 0 0; max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom); transform: translateY(30px); }
  .bubble { max-width: 86%; }
  .msgs { padding: 10px 8px 6px; }
}
@media (min-width: 900px) and (max-width: 1100px) { .shell { grid-template-columns: 320px 1fr; } }

/* ================= phase 1 additions ================= */
/* manual theme switch */
:root[data-theme="dark"] {
  --brand: #2bb394; --brand-ink: #06231c; --brand-soft: #173a31; --bg: #131a18; --bg-2: #1a2320; --chat-bg: #0d1311;
  --line: #26322e; --ink: #e8efec; --ink-2: #a3b1ad; --ink-3: #75847f; --out: #1d4a3e; --in: #1d2724; --read: #5cc3f5;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35); --shadow-lg: 0 18px 50px rgba(0, 0, 0, .5); color-scheme: dark;
}
:root[data-theme="light"] {
  --brand: #0e7c66; --brand-ink: #ffffff; --brand-soft: #e3f3ee; --bg: #ffffff; --bg-2: #f4f6f5; --chat-bg: #e8eeeb;
  --line: #e2e7e5; --ink: #12201c; --ink-2: #5d6b67; --ink-3: #8a9793; --out: #d9f2e8; --in: #ffffff; --read: #1a9fe0;
  --shadow: 0 1px 2px rgba(16, 32, 28, .08); --shadow-lg: 0 18px 50px rgba(16, 32, 28, .18); color-scheme: light;
}
/* wallpapers (tinted so they work in light and dark) */
:root[data-wall="sand"] { --chat-bg: color-mix(in srgb, #e9dcc3 55%, var(--bg)); }
:root[data-wall="sky"]  { --chat-bg: color-mix(in srgb, #c9def2 55%, var(--bg)); }
:root[data-wall="rose"] { --chat-bg: color-mix(in srgb, #f0d3da 55%, var(--bg)); }
:root[data-wall="mint"] { --chat-bg: color-mix(in srgb, #cdebdc 60%, var(--bg)); }
:root[data-wall="dots"] .scroller { background-image: radial-gradient(color-mix(in srgb, var(--ink) 9%, transparent) 1.2px, transparent 1.4px); background-size: 18px 18px; }
.walls { display: flex; gap: 10px; flex-wrap: wrap; }
.wall { width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--line); background: #e8eeeb; }
.wall[data-w="sand"] { background: #e9dcc3; } .wall[data-w="sky"] { background: #c9def2; } .wall[data-w="rose"] { background: #f0d3da; }
.wall[data-w="mint"] { background: #cdebdc; }
.wall[data-w="dots"] { background: #e8eeeb radial-gradient(#9aa7a3 1.2px, transparent 1.4px) 0 0 / 9px 9px; }
.wall.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.switch-row { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--brand); flex: none; margin-top: 2px; }
.switch-row span { display: grid; gap: 2px; }
.switch-row small { color: var(--ink-3); font-size: 13px; }
.list-btn .list-state { margin-inline-start: auto; color: var(--ink-3); }
.list-btn { width: 100%; }
.stack.tight { gap: 8px; }
.ic.tiny { width: 13px; height: 13px; stroke-width: 2.2; }

/* chat list flags & search */
.conv-flag { color: var(--ink-3); display: inline-flex; flex: none; }
.conv-flag .ic { width: 16px; height: 16px; }
.badge.muted { background: var(--ink-3); }
.search-results .conv { width: 100%; text-align: start; }
.label.pad { padding: 10px 10px 4px; }
.empty.small { padding: 10px; font-size: 14px; }

/* header extras */
.ttl-chip { display: inline-flex; align-items: center; gap: 3px; margin-inline-start: 6px; padding: 1px 7px; border-radius: 99px; background: var(--bg-2); color: var(--ink-2); font-size: 11.5px; font-weight: 600; vertical-align: middle; }
.ttl-chip .ic { width: 12px; height: 12px; }
.pin-bar { display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--bg); border-bottom: 1px solid var(--line); color: var(--brand); }
.pin-bar > .ic { width: 18px; height: 18px; }
.pin-body { flex: 1; min-width: 0; display: grid; text-align: start; padding-inline-start: 10px; border-inline-start: 3px solid var(--brand); }
.pin-body strong { font-size: 12.5px; }
.pin-body span { color: var(--ink-2); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* bubbles: forwarded, scheduled, reactions */
.stackm { display: flex; flex-direction: column; max-width: min(78%, 560px); }
.msg.out .stackm { align-items: flex-end; }
.msg.in .stackm { align-items: flex-start; }
.stackm .bubble { max-width: 100%; }
.fwd { display: flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--ink-3); font-style: italic; margin-bottom: 2px; }
.fwd .ic { width: 14px; height: 14px; }
.msg.scheduled .bubble { opacity: .75; border: 1.5px dashed color-mix(in srgb, var(--brand) 60%, transparent); }
.sched { display: inline-flex; align-items: center; gap: 3px; color: var(--brand); font-weight: 600; }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: -4px; padding: 0 6px; position: relative; z-index: 1; }
.react { display: inline-flex; align-items: center; gap: 3px; height: 26px; padding: 0 8px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); font-size: 14px; box-shadow: var(--shadow); }
.react.mine { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 45%, transparent); }
.react .n { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.react-bar { display: flex; justify-content: space-between; gap: 4px; padding: 4px 4px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.react-pick { width: 46px; height: 46px; border-radius: 50%; font-size: 26px; line-height: 1; transition: transform .1s, background .15s; }
.react-pick:hover, .react-pick.on { background: var(--brand-soft); }
.react-pick:active { transform: scale(1.2); }
.tick .progress, .media-wait .progress { font-size: 11px; font-weight: 700; margin-inline-start: 2px; color: #fff; }
.tick .progress { color: var(--ink-3); }
.media-wait { flex-direction: column; gap: 4px; }
.media-load { position: absolute; inset: 0; margin: auto; width: max-content; height: 44px; padding: 0 14px; border-radius: 99px; background: rgba(0, 0, 0, .55); color: #fff; display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }

/* polls */
.bubble.card { min-width: 250px; }
.poll { display: grid; gap: 6px; min-width: 240px; padding: 2px 0 4px; }
.poll-q { font-weight: 700; font-size: 15.5px; }
.poll-sub { color: var(--ink-3); font-size: 12px; }
.poll-opt { position: relative; display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 10px; border-radius: 10px; background: color-mix(in srgb, var(--ink) 5%, transparent); overflow: hidden; text-align: start; }
.poll-fill { position: absolute; inset-block: 0; inset-inline-start: 0; background: color-mix(in srgb, var(--brand) 22%, transparent); transition: width .3s; }
.poll-check { position: relative; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--ink-3); display: grid; place-items: center; flex: none; }
.poll-opt.on .poll-check { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.poll-check .ic { width: 13px; height: 13px; stroke-width: 3; }
.poll-label { position: relative; flex: 1; }
.poll-pct { position: relative; font-size: 12.5px; font-weight: 700; color: var(--ink-2); }

/* location */
.loc-card { display: grid; width: 260px; max-width: 100%; color: inherit; text-decoration: none; margin: 0 0 2px; }
.loc-map { position: relative; height: 130px; border-radius: 10px; background: color-mix(in srgb, var(--brand) 14%, var(--bg-2)); overflow: hidden; }
.loc-map img { position: absolute; left: 50%; top: 50%; width: 256px; height: 256px; transform: translate(-50%, -50%); }
.loc-pin { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -85%); color: #e5484d; }
.loc-pin .ic { width: 34px; height: 34px; fill: #e5484d; stroke: #fff; stroke-width: 1.5; }
.loc-text { display: grid; padding: 8px 10px 0; }
.loc-text small { color: var(--brand); font-weight: 600; }

/* round video note */
.bubble.note { background: none; box-shadow: none; padding: 0; }
.note-box { position: relative; width: 220px; height: 220px; border-radius: 50%; overflow: hidden; background: #000; cursor: pointer; box-shadow: var(--shadow-lg); }
.note-box video { width: 100%; height: 100%; object-fit: cover; }
.note-box .media-wait, .note-box .media-load { border-radius: 50%; }
.note-time { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); padding: 2px 8px; border-radius: 99px; background: rgba(0, 0, 0, .5); color: #fff; font-size: 12px; font-variant-numeric: tabular-nums; }
.note-box.playing { box-shadow: 0 0 0 3px var(--brand), var(--shadow-lg); }
.bubble.note > .meta { float: none; display: flex; justify-content: flex-end; margin: 4px 6px 0; top: 0; }
.vn { position: fixed; inset: 0; z-index: 75; background: rgba(5, 12, 10, .92); display: grid; grid-template-rows: 1fr auto; color: #fff; }
.vn-stage { display: grid; place-items: center; align-content: center; gap: 14px; }
.vn-ring { --p: 0; width: min(78vw, 320px); aspect-ratio: 1; border-radius: 50%; padding: 6px; background: conic-gradient(#e5484d calc(var(--p) * 360deg), rgba(255, 255, 255, .15) 0); }
.vn-preview { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; transform: scaleX(-1); background: #000; }
.vn-time { font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 600; }
.vn-bar { display: flex; align-items: center; justify-content: space-around; padding: 20px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.vn-rec { width: 74px; height: 74px; border-radius: 50%; border: 4px solid #fff; display: grid; place-items: center; }
.vn-rec span { width: 54px; height: 54px; border-radius: 50%; background: #e5484d; transition: .2s; }
.vn.recording .vn-rec span { width: 26px; height: 26px; border-radius: 6px; }
.send-btn:disabled { opacity: .35; }

/* PIN lock */
.pin-screen { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: grid; justify-items: center; align-content: center; gap: 14px; padding: 24px; }
.pin-logo { width: 64px; height: 64px; border-radius: 18px; }
.pin-screen h2 { margin: 0; font-size: 19px; }
.pin-dots { display: flex; gap: 16px; margin: 6px 0; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink-3); }
.pin-dots span.on { background: var(--brand); border-color: var(--brand); }
.pin-msg { min-height: 1.4em; margin: 0; color: var(--danger); font-size: 14px; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; }
.pin-key { width: 76px; height: 76px; border-radius: 50%; background: var(--bg-2); font-size: 28px; font-weight: 500; display: grid; place-items: center; }
.pin-key:active { background: var(--brand-soft); }
.pin-links { display: flex; gap: 20px; min-height: 40px; }
.link-btn { color: var(--brand); font-weight: 600; padding: 8px; }
.pin-screen.shake .pin-dots { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@media (max-width: 899px) { .stackm { max-width: 86%; } }
