/*
 * app.css — mobile-first. Base = phone; 768px adds tablet; 1100px adds desktop.
 * Logical properties only (margin-inline-start, inset-inline-end, text-align:start)
 * so Hebrew RTL needs no mirrored rules. Every colour is a token.
 * No inline styles anywhere (CSP style-src 'self'); dynamic values are custom
 * properties set via CSSOM (--h for avatar hue, width for progress).
 */
[hidden] { display: none !important; }

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e7eaee;
  --line: #e2e5ea;
  --line-strong: #cfd4db;
  --text: #15181d;
  --text-2: #4a515c;
  --muted: #6b7380;
  --brand: #b4232f;
  --brand-600: #9c1b26;
  --brand-50: #fbecee;
  --on-brand: #ffffff;
  --wa: #128c4b;
  --ok: #16834a; --ok-bg: #e6f5ec;
  --warn: #a35b00; --warn-bg: #fff3e0;
  --bad: #c0262d; --bad-bg: #fdecec;
  --busy: #2563c9; --busy-bg: #e8f0fd;
  --bubble-in: #ffffff;
  --bubble-out: #dcf7e3;
  --chat-bg: #efeae2;
  --chat-dot: #e3dccf;
  --mark: #ffe58a;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-2: 0 10px 30px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .08);
  --r-sm: 8px; --r: 12px; --r-lg: 18px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --topbar: 56px;
  --nav-w: 248px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Hebrew", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1014; --surface: #151a20; --surface-2: #1b2128; --surface-3: #232a33;
    --line: #262d36; --line-strong: #343d48;
    --text: #e8ebef; --text-2: #b8bfc9; --muted: #8b94a1;
    --brand: #e0505b; --brand-600: #f06872; --brand-50: #2a1416; --on-brand: #ffffff;
    --wa: #2fbf71;
    --ok: #4cc283; --ok-bg: #12291d; --warn: #f0a443; --warn-bg: #2d2010; --bad: #ff6b6b; --bad-bg: #2f1517;
    --busy: #6ea2ff; --busy-bg: #142238;
    --bubble-in: #1f262e; --bubble-out: #133b29; --chat-bg: #0f1418; --chat-dot: #161d23; --mark: #7a5d00;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4); --shadow-2: 0 12px 34px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 var(--s2); letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: 1rem; margin: 0 0 var(--s2); }
p { margin: 0 0 var(--s3); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); padding: 10px 12px; min-height: 44px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; padding: 0; accent-color: var(--brand); flex: 0 0 auto; }
@media (max-width: 640px) { input, select, textarea { font-size: 16px; } }   /* iOS zooms in on <16px focus */

.ltr { direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }
.row { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: var(--s2); }

/* icons */
.icon { display: inline-flex; width: 1.15em; height: 1.15em; flex: 0 0 auto; vertical-align: -.2em; }
.icon svg { width: 100%; height: 100%; }
.icon.big { width: 44px; height: 44px; color: var(--muted); }
[dir=rtl] .flip-rtl { transform: scaleX(-1); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s4); border-radius: var(--r-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-600); }
.btn.primary.wa { background: var(--wa); border-color: var(--wa); }
.btn.secondary { background: var(--surface-2); border-color: var(--line); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger, .btn.ghost.danger { color: var(--bad); }
.btn.danger:not(.ghost) { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { min-height: 34px; padding: 0 var(--s3); font-size: .875rem; }
.btn.wide { width: 100%; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after { content: ""; position: absolute; width: 18px; height: 18px; border: 2px solid var(--on-brand); border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn.secondary.busy::after { border-color: var(--text); border-top-color: transparent; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; cursor: pointer; color: var(--text-2); flex: 0 0 auto;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .icon { width: 22px; height: 22px; }
.link-btn {
  background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font-weight: 600;
  display: inline-flex; align-items: center; gap: var(--s1);
}
.link-btn[disabled] { color: var(--muted); cursor: default; font-weight: 500; }
.link-btn.back { margin-block-end: var(--s4); color: var(--text-2); }

.spinner { width: 22px; height: 22px; border: 2.5px solid var(--line-strong); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.xs { width: 13px; height: 13px; border-width: 2px; display: inline-block; }
.spinner.lg { width: 44px; height: 44px; border-width: 3.5px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* brand */
.brand { display: inline-flex; align-items: center; gap: var(--s2); color: var(--text); font-weight: 750; font-size: 1.05rem; letter-spacing: -.01em; text-decoration: none !important; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: var(--brand); color: var(--on-brand); font-weight: 800; font-size: 1rem;
}
.boot { height: 100vh; display: grid; place-items: center; }
.boot .brand-mark { width: 48px; height: 48px; font-size: 1.4rem; border-radius: 14px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-block-end: var(--s4); }
.label { font-weight: 600; font-size: .9rem; color: var(--text-2); }
.help { font-size: .8rem; color: var(--muted); }
.form-error { color: var(--bad); font-size: .9rem; min-height: 0; margin: 0 0 var(--s3); }
.form-error:empty { display: none; }
.check { display: flex; align-items: center; gap: var(--s2); cursor: pointer; padding: 6px 0; }
.check.center { justify-content: center; color: var(--muted); font-size: .9rem; }
.checks { display: flex; flex-direction: column; }
.note {
  display: flex; gap: var(--s2); align-items: flex-start; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r); padding: var(--s3) var(--s4); color: var(--text-2); font-size: .9rem; margin-block: var(--s4);
}
.note .icon { margin-block-start: 2px; color: var(--muted); }
.note.warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.static { padding: 10px 0; font-weight: 600; }
.divider { display: flex; align-items: center; gap: var(--s3); color: var(--muted); font-size: .85rem; margin: var(--s4) 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.segmented.wide { display: flex; }
.segmented button { flex: 1; border: 0; background: transparent; padding: 7px 14px; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--text-2); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.segmented button[disabled] { opacity: .4; cursor: not-allowed; }

/* auth */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; padding: var(--s4); padding-block-end: var(--s6);
  background: radial-gradient(1200px 500px at 50% -10%, var(--brand-50), transparent 70%), var(--bg); }
.auth-top { width: 100%; max-width: 440px; display: flex; justify-content: space-between; align-items: center; margin-block-end: 8vh; }
.auth-card { width: 100%; max-width: 440px; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-2); padding: var(--s6) var(--s5); }
.auth-card h1 { font-size: 1.6rem; }
.auth-card .muted { margin-block-end: var(--s5); }
.auth-foot { max-width: 440px; text-align: center; color: var(--muted); font-size: .85rem; margin-block-start: var(--s5); }
.code-input {
  font-size: 1.9rem; letter-spacing: .5em; text-align: center; font-weight: 700; padding-inline-start: .5em;
  font-variant-numeric: tabular-nums; margin-block-end: var(--s3); min-height: 60px;
}
.hero-icon { display: grid; place-items: center; margin: 0 auto var(--s4); width: 76px; height: 76px; border-radius: 50%; background: var(--brand-50); color: var(--brand); }
.hero-icon .icon { width: 40px; height: 40px; }
.lang-pill {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: .85rem; color: var(--text-2);
}
.lang-pill:hover { background: var(--surface-2); }

/* app shell */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar); display: flex; align-items: center; gap: var(--s2);
  padding: 0 var(--s3); background: var(--surface); border-block-end: 1px solid var(--line);
}
.top-account { font-weight: 600; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34vw; padding-inline-start: var(--s2); border-inline-start: 1px solid var(--line); }
.avatar-btn { border: 0; background: none; padding: 2px; border-radius: 50%; cursor: pointer; }
.avatar {
  --h: 350; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; flex: 0 0 auto;
  background: hsl(var(--h) 55% 88%); color: hsl(var(--h) 45% 28%); font-weight: 700; font-size: .9rem;
}
@media (prefers-color-scheme: dark) { .avatar { background: hsl(var(--h) 30% 26%); color: hsl(var(--h) 60% 82%); } }
.avatar-btn .avatar { width: 34px; height: 34px; font-size: .8rem; background: var(--brand-50); color: var(--brand); }
.avatar.lg { width: 48px; height: 48px; font-size: 1rem; }
.avatar.group .icon { width: 22px; height: 22px; }
.app-body { flex: 1; display: flex; min-height: 0; }
.main { flex: 1; min-width: 0; outline: none; }
.only-mobile { display: inline-grid; }

.sidenav {
  position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 50; width: min(84vw, 300px);
  background: var(--surface); border-inline-end: 1px solid var(--line); padding: var(--s3);
  display: flex; flex-direction: column; gap: var(--s3); overflow-y: auto;
  transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow-2);
}
[dir=rtl] .sidenav { transform: translateX(105%); }
body.drawer-open .sidenav { transform: none; }
.scrim { position: fixed; inset: 0; background: rgba(10, 12, 16, .45); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s; }
body.drawer-open .scrim { opacity: 1; pointer-events: auto; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group.bottom { margin-block-start: auto; padding-block-start: var(--s3); border-block-start: 1px solid var(--line); }
.nav-item {
  display: flex; align-items: center; gap: var(--s3); padding: 10px var(--s3); border-radius: var(--r-sm);
  color: var(--text-2); font-weight: 600; text-decoration: none !important;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--brand-50); color: var(--brand); }
.nav-item .icon { width: 20px; height: 20px; }

.acct { position: relative; }
.acct-btn {
  width: 100%; display: flex; align-items: center; gap: var(--s3); padding: var(--s2); border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: start;
}
.acct-btn:hover { background: var(--surface-2); }
.acct-mark { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--text); color: var(--surface); font-weight: 750; font-size: .85rem; flex: 0 0 auto; }
.acct-mark.sm { width: 26px; height: 26px; border-radius: 7px; font-size: .7rem; }
.acct-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.acct-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-role { font-size: .78rem; color: var(--muted); }
.acct-menu, .user-menu {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-2);
  padding: var(--s2); z-index: 60;
}
.acct-menu { position: absolute; inset-inline: 0; top: calc(100% + 6px); }
.user-menu { position: fixed; top: calc(var(--topbar) - 4px); inset-inline-end: var(--s3); width: min(300px, calc(100vw - 24px)); }
.menu-label { font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 6px var(--s2); }
.menu-item {
  display: flex; align-items: center; gap: var(--s3); width: 100%; padding: 10px var(--s2); border: 0; border-radius: var(--r-sm);
  background: none; cursor: pointer; color: var(--text); text-decoration: none !important; font-weight: 500; text-align: start;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item.active { font-weight: 700; }
.menu-item.danger { color: var(--bad); }
.menu-meta { margin-inline-start: auto; color: var(--muted); font-size: .8rem; }
.um-head { display: flex; gap: var(--s3); align-items: center; padding: var(--s2) var(--s2) var(--s3); border-block-end: 1px solid var(--line); margin-block-end: var(--s2); }
.um-name { font-weight: 700; }
.um-phone { color: var(--muted); font-size: .85rem; }
.um-section { padding: 0 0 var(--s2); border-block-end: 1px solid var(--line); margin-block-end: var(--s2); }
.um-section .segmented { display: flex; margin: 0 var(--s2); }

@media (min-width: 1100px) {
  .only-mobile { display: none !important; }
  .sidenav {
    position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); height: calc(100dvh - var(--topbar));
    transform: none !important; box-shadow: none; width: var(--nav-w); flex: 0 0 var(--nav-w); z-index: 1;
  }
  .scrim { display: none; }
}

/* pages */
.page { padding: var(--s5) var(--s4) var(--s6); max-width: 1100px; margin: 0 auto; }
.page.narrow { max-width: 680px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; margin-block-end: var(--s4); }
.page-head h1 { margin: 0; }
.page-loading { display: flex; gap: var(--s3); align-items: center; justify-content: center; padding: var(--s6); color: var(--muted); }
.page-loading.small { padding: var(--s4); }
.section-title { font-size: 1rem; margin: var(--s5) 0 var(--s3); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); flex-wrap: wrap; margin: var(--s5) 0 var(--s3); }
.section-head .section-title { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s4); box-shadow: var(--shadow-1); }
.card.form { padding: var(--s5) var(--s4); }
.cards { display: grid; gap: var(--s4); grid-template-columns: 1fr; }
@media (min-width: 768px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } .page { padding-inline: var(--s5); } }
@media (min-width: 1400px) { .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-block-start: var(--s3); padding-block-start: var(--s3); border-block-start: 1px solid var(--line); }
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s3); padding: var(--s6) var(--s4); color: var(--text-2); }
.empty.tall { min-height: 50vh; justify-content: center; }
.empty.card { grid-column: 1 / -1; }
.empty-small { padding: var(--s4); color: var(--muted); text-align: center; }
.boot-error { padding: var(--s6); text-align: center; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--text-2); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.busy { background: var(--busy-bg); color: var(--busy); }
.pill.busy .dot, .pill.wait .dot { animation: pulse 1.2s infinite; }
.pill.wait { background: var(--warn-bg); color: var(--warn); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); font-size: .75rem; font-weight: 600; margin-inline-end: 4px; }
.tag.ok { background: var(--ok-bg); color: var(--ok); margin-inline-start: var(--s2); }

.num-top { display: flex; gap: var(--s3); align-items: flex-start; }
.num-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--ok-bg); color: var(--ok); flex: 0 0 auto; }
.num-title { flex: 1; min-width: 0; }
.num-title h2 { overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); margin: var(--s3) 0; }
.stats div { background: var(--surface-2); border-radius: var(--r-sm); padding: var(--s2) var(--s3); }
.stats dt { font-size: .75rem; color: var(--muted); }
.stats dd { margin: 0; font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.progress { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; margin: var(--s3) 0; }
.progress span { display: block; height: 100%; width: 3%; background: var(--busy); border-radius: 99px; transition: width .4s; }
.progress.indeterminate span { width: 35%; animation: indet 1.3s ease-in-out infinite; }
@keyframes indet { 0% { margin-inline-start: -35%; } 100% { margin-inline-start: 100%; } }
.acct-card.disabled { opacity: .65; }

.method-choice { display: grid; gap: var(--s2); margin-block-end: var(--s4); }
@media (min-width: 560px) { .method-choice { grid-template-columns: 1fr 1fr; } }
.method {
  display: flex; gap: var(--s3); align-items: flex-start; text-align: start; padding: var(--s3); border-radius: var(--r);
  border: 1.5px solid var(--line); background: var(--surface); cursor: pointer;
}
.method .icon { width: 24px; height: 24px; color: var(--muted); margin-block-start: 2px; }
.method.on { border-color: var(--brand); background: var(--brand-50); }
.method.on .icon { color: var(--brand); }
.method-text { display: flex; flex-direction: column; gap: 2px; }

.link-card { padding: var(--s5) var(--s4); }
.qr-wrap { display: grid; gap: var(--s5); align-items: center; }
@media (min-width: 700px) { .qr-wrap { grid-template-columns: auto 1fr; } }
.qr-box { background: #fff; padding: 14px; border-radius: var(--r); border: 1px solid var(--line); justify-self: center; line-height: 0; }
.qr { width: min(280px, 70vw); height: auto; image-rendering: pixelated; }
.steps { margin: 0; padding-inline-start: 1.3em; display: flex; flex-direction: column; gap: var(--s3); font-size: 1rem; }
.steps li::marker { font-weight: 700; color: var(--brand); }
.pair { display: grid; gap: var(--s5); justify-items: center; }
.pair-code { font: 800 2.4rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; background: var(--surface-2); padding: var(--s4) var(--s5); border-radius: var(--r); }
.center-stage { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s3); padding: var(--s3) 0; }
.center-stage .stats { width: 100%; max-width: 440px; }
.center-stage .progress { width: 100%; max-width: 440px; }
.big-check { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); }
.big-check .icon { width: 32px; height: 32px; }
.big-check.busy { background: var(--busy-bg); color: var(--busy); }
.big-check.busy .icon { animation: bob 1.4s ease-in-out infinite; }
.big-check.bad { background: var(--bad-bg); color: var(--bad); }
@keyframes bob { 50% { transform: translateY(3px); } }

/* members */
.member-list { display: flex; flex-direction: column; gap: var(--s2); }
.member { display: grid; grid-template-columns: auto 1fr auto; gap: var(--s3); align-items: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s3) var(--s4); }
.mem-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.mem-name { font-weight: 700; }
.mem-perms { display: flex; flex-wrap: wrap; gap: 4px; }
.mem-actions { grid-column: 2 / -1; display: flex; gap: var(--s2); justify-content: flex-end; }
.role { font-size: .75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.role.owner { background: var(--brand-50); color: var(--brand); }
.role.admin { background: var(--busy-bg); color: var(--busy); }
.scope-list { padding-inline-start: var(--s5); }
@media (min-width: 768px) { .member { grid-template-columns: auto 1fr auto auto; align-items: center; } .mem-actions { grid-column: auto; } }

.list { display: flex; flex-direction: column; }
.list-row { display: flex; gap: var(--s3); align-items: center; padding: var(--s3) 0; border-block-end: 1px solid var(--line); }
.list-row:last-child { border-block-end: 0; }
.list-row > .icon { width: 22px; height: 22px; color: var(--muted); }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: grid; grid-template-columns: 28px 1fr; gap: 2px var(--s2); padding: var(--s2) 0; border-block-end: 1px solid var(--line); }
.activity li:last-child { border-block-end: 0; }
.activity time { grid-column: 2; }
.act-icon { color: var(--muted); text-align: center; }
.act-main b { text-transform: capitalize; }
.changelog section { padding-block-end: var(--s3); border-block-end: 1px solid var(--line); margin-block-end: var(--s3); }
.changelog ul { margin: 0; padding-inline-start: 1.2em; }

/* modal + toasts */
.modal-back { position: fixed; inset: 0; z-index: 80; background: rgba(10, 12, 16, .5); display: flex; align-items: flex-end; justify-content: center; padding: 0; animation: fade .15s; }
.modal-card { background: var(--surface); width: 100%; max-height: 92vh; overflow: auto; border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: var(--shadow-2); animation: up .2s ease; }
@media (min-width: 640px) {
  .modal-back { align-items: center; padding: var(--s4); }
  .modal-card { max-width: 520px; border-radius: var(--r-lg); }
  .modal-card.wide { max-width: 860px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) var(--s3) var(--s2) var(--s5); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-body { padding: var(--s2) var(--s5) var(--s4); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s3) var(--s5) var(--s5); border-block-start: 1px solid var(--line); flex-wrap: wrap; }
.lightbox { width: 100%; height: auto; border-radius: var(--r-sm); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
#toasts { position: fixed; inset-inline: 0; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: var(--s2); pointer-events: none; padding: 0 var(--s3); }
.toast {
  display: flex; gap: var(--s2); align-items: center; max-width: 520px; padding: 10px 16px; border-radius: var(--r);
  background: var(--text); color: var(--surface); box-shadow: var(--shadow-2); font-weight: 500;
  opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s;
}
.toast.in { opacity: 1; transform: none; }
.toast.error { background: var(--bad); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }
.version-banner {
  position: fixed; bottom: var(--s4); inset-inline-start: 50%; transform: translateX(-50%); z-index: 90;
  display: flex; gap: var(--s3); align-items: center; padding: 8px 8px 8px 16px; border-radius: 999px;
  background: var(--text); color: var(--surface); box-shadow: var(--shadow-2); white-space: nowrap;
}
[dir=rtl] .version-banner { transform: translateX(50%); }

/* ── chats ─────────────────────────────────────────────────────────── */
.main.flush { display: flex; }
.chats { flex: 1; display: grid; grid-template-columns: 1fr; height: calc(100vh - var(--topbar)); height: calc(100dvh - var(--topbar)); min-width: 0; }
.list-pane { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-inline-end: 1px solid var(--line); }
.chat-pane { display: none; flex-direction: column; min-height: 0; min-width: 0; background: var(--chat-bg); }
.chats.has-chat .list-pane { display: none; }
.chats.has-chat .chat-pane { display: flex; }
.only-narrow { display: inline-grid; }
@media (min-width: 768px) {
  .chats { grid-template-columns: minmax(300px, 380px) 1fr; }
  .chats .list-pane, .chats.has-chat .list-pane { display: flex; }
  .chats .chat-pane { display: flex; }
  .only-narrow { display: none !important; }
}
.list-head { padding: var(--s3); display: flex; flex-direction: column; gap: var(--s2); border-block-end: 1px solid var(--line); }
.search-wrap { position: relative; }
.search-wrap .icon { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-input { padding-inline-start: 38px; border-radius: 999px; background: var(--surface-2); border-color: transparent; min-height: 40px; }
.list-filters { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px; font-size: .85rem; font-weight: 600; cursor: pointer; color: var(--text-2); }
.chip.on { background: var(--text); border-color: var(--text); color: var(--surface); }
.conn-select { width: auto; min-height: 32px; padding: 4px 10px; font-size: .85rem; border-radius: 999px; margin-inline-start: auto; max-width: 50%; }
.search-all { display: flex; align-items: center; gap: var(--s2); border: 1px dashed var(--line-strong); background: var(--surface); color: var(--brand); border-radius: var(--r-sm); padding: 8px 12px; cursor: pointer; font-weight: 600; text-align: start; }
.chat-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.sentinel { height: 1px; }
.chat-item {
  display: flex; gap: var(--s3); align-items: center; padding: 10px var(--s3); color: var(--text); text-decoration: none !important;
  border-block-end: 1px solid var(--line); position: relative;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--brand-50); }
.chat-item.active::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 3px; background: var(--brand); }
.ci-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ci-row { display: flex; gap: var(--s2); align-items: baseline; justify-content: space-between; min-width: 0; }
.ci-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-time { color: var(--muted); font-size: .75rem; flex: 0 0 auto; }
.ci-last { color: var(--text-2); font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-last b { font-weight: 600; color: var(--muted); }
.ci-count { flex: 0 0 auto; font-size: .7rem; color: var(--muted); background: var(--surface-2); border-radius: 99px; padding: 0 7px; font-variant-numeric: tabular-nums; }
.ci-conn { font-size: .72rem; color: var(--muted); }
.results-head { padding: var(--s3); display: flex; flex-direction: column; gap: var(--s2); border-block-end: 1px solid var(--line); }
.results-title { font-weight: 700; }
.result-item { display: flex; flex-direction: column; gap: 4px; padding: 10px var(--s3); border-block-end: 1px solid var(--line); color: var(--text); text-decoration: none !important; }
.result-item:hover { background: var(--surface-2); }
.result-text { font-size: .875rem; color: var(--text-2); overflow-wrap: anywhere; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

.chat-head {
  display: flex; gap: var(--s3); align-items: center; padding: var(--s2) var(--s3); min-height: 60px;
  background: var(--surface); border-block-end: 1px solid var(--line);
}
.ch-main { min-width: 0; flex: 1; }
.ch-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-meta { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-scroll {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: var(--s3) var(--s3) var(--s5);
  background-color: var(--chat-bg);
  background-image: radial-gradient(var(--chat-dot) 1px, transparent 1px); background-size: 18px 18px;
}
@media (min-width: 1100px) { .msg-scroll { padding-inline: 6%; } }
.msg-top { display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s2) 0 var(--s3); }
.beginning { font-size: .8rem; color: var(--muted); background: var(--surface); padding: 4px 12px; border-radius: 99px; box-shadow: var(--shadow-1); }
.msg-list { display: flex; flex-direction: column; gap: 3px; }
.day { display: flex; justify-content: center; margin: var(--s3) 0 var(--s2); position: sticky; top: 0; z-index: 2; }
.day span { background: var(--surface); color: var(--text-2); font-size: .78rem; font-weight: 600; padding: 4px 12px; border-radius: 8px; box-shadow: var(--shadow-1); }
.sys { display: flex; justify-content: center; margin: 6px 0; }
.sys span { font-size: .78rem; color: var(--muted); background: var(--surface-2); padding: 3px 10px; border-radius: 8px; text-align: center; max-width: 90%; }
.msg-row { display: flex; flex-direction: column; max-width: 100%; }
.msg-row.in { align-items: flex-start; }
.msg-row.out { align-items: flex-end; }
.msg {
  position: relative; max-width: min(85%, 560px); padding: 6px 10px 6px; border-radius: 10px; box-shadow: var(--shadow-1);
  background: var(--bubble-in); overflow-wrap: anywhere;
}
.msg.out { background: var(--bubble-out); }
.msg-row.in .msg { border-start-start-radius: 3px; }
.msg-row.out .msg { border-start-end-radius: 3px; }
.msg.hl { outline: 2.5px solid var(--warn); outline-offset: 2px; }
.msg .text { white-space: pre-wrap; }
.msg .text a { overflow-wrap: anywhere; }
.msg .meta { font-size: .7rem; color: var(--muted); text-align: end; margin-block-start: 2px; line-height: 1; }
.msg .sender { --h: 200; font-size: .8rem; font-weight: 700; color: hsl(var(--h) 55% 38%); margin-block-end: 2px; }
@media (prefers-color-scheme: dark) { .msg .sender { color: hsl(var(--h) 65% 70%); } }
.quote { font-size: .82rem; color: var(--text-2); background: rgba(0, 0, 0, .05); border-inline-start: 3px solid var(--brand); padding: 4px 8px; border-radius: 6px; margin-block-end: 4px; max-height: 4.5em; overflow: hidden; white-space: pre-wrap; }
@media (prefers-color-scheme: dark) { .quote { background: rgba(255, 255, 255, .06); } }
.msg.deleted .text { text-decoration: line-through; text-decoration-color: var(--bad); color: var(--text-2); }
.deleted-tag { display: inline-flex; gap: 4px; align-items: center; font-size: .75rem; color: var(--bad); font-weight: 600; margin-block-end: 2px; }
.edited-tag { border: 0; background: none; padding: 0; font-size: .7rem; color: var(--muted); text-decoration: underline dotted; cursor: pointer; }
.original { font-size: .82rem; color: var(--text-2); border-block-start: 1px dashed var(--line-strong); margin-block-start: 4px; padding-block-start: 4px; white-space: pre-wrap; }
.reactions { display: flex; gap: 2px; position: relative; margin-block-start: 2px; }
.reaction { background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 0 6px; font-size: .85rem; }
.reaction.mine { border-color: var(--ok); }
.reply-time { display: inline-flex; gap: 4px; align-items: center; font-size: .72rem; font-weight: 600; margin: 2px 4px 6px; padding: 1px 8px; border-radius: 99px; }
.reply-time .icon { width: 12px; height: 12px; }
.reply-time.fast { color: var(--ok); background: var(--ok-bg); }
.reply-time.mid { color: var(--warn); background: var(--warn-bg); }
.reply-time.slow { color: var(--bad); background: var(--bad-bg); }
.kind-line { display: flex; gap: 6px; align-items: center; font-size: .8rem; color: var(--muted); font-weight: 600; }
.media { margin: -2px -6px 4px; }
.media img { display: block; max-width: 100%; width: 320px; max-height: 360px; object-fit: cover; border-radius: 8px; cursor: zoom-in; background: var(--surface-2); }
.media.sticker img { width: 140px; height: 140px; object-fit: contain; background: transparent; }
.media video { display: block; width: 320px; max-width: 100%; border-radius: 8px; background: #000; }
.audio-line { display: flex; gap: 6px; align-items: center; padding: 4px 6px; }
.audio-line audio { width: 260px; max-width: 62vw; height: 40px; }
.doc { display: flex; gap: var(--s2); align-items: center; padding: 10px; border-radius: 8px; background: rgba(0, 0, 0, .05); color: var(--text); text-decoration: none !important; }
.doc-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-info { font-size: .75rem; color: var(--muted); }
.media-ph { display: flex; flex-wrap: wrap; gap: 6px var(--s2); align-items: center; padding: 10px; border-radius: 8px; background: rgba(0, 0, 0, .05); min-width: 220px; }
@media (prefers-color-scheme: dark) { .doc, .media-ph { background: rgba(255, 255, 255, .06); } }
.media-ph > .icon { width: 22px; height: 22px; color: var(--muted); }
.ph-label { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ph-info { font-size: .75rem; color: var(--muted); }
.ph-state { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.ph-note { width: 100%; font-size: .72rem; color: var(--muted); }
.empty.pick { color: var(--muted); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
