/* =========================================================================================
   Naundorf Secure Chat – visual system
   Concept: a quiet "vault". Deep graphite surfaces, one warm brass accent, generous rhythm.
   ========================================================================================= */

:root {
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "SF Pro Text", "Helvetica Neue", Roboto, Ubuntu, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "SF Pro Display", "Helvetica Neue", Roboto, sans-serif;
  --mono: "Cascadia Code", "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --r-xs: 6px;
  --r-sm: 9px;
  --r: 12px;
  --r-lg: 18px;
  --r-xl: 24px;

  --sidebar-w: 348px;
  --info-w: 348px;
  --col-w: 860px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t: 160ms var(--ease);
}

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0f13;
  --bg-2: #111419;
  --surface: #161a20;
  --surface-2: #1c2129;
  --surface-3: #242a34;
  --surface-4: #2d3440;
  --line: rgba(255, 255, 255, .065);
  --line-2: rgba(255, 255, 255, .12);
  --text: #eceef2;
  --text-2: #a4aab6;
  --text-3: #6d7483;
  --brand: #f7c325;
  --brand-ink: #1a1502;
  --logo: #f7c325;
  --accent: #f7c325;
  --accent-2: #e0a800;
  --accent-ink: #1a1502;
  --accent-soft: rgba(247, 195, 37, .13);
  --accent-line: rgba(247, 195, 37, .38);
  --mine: #2a2712;
  --mine-line: rgba(247, 195, 37, .17);
  --theirs: #1c2129;
  --ok: #5bd69b;
  --ok-soft: rgba(91, 214, 155, .12);
  --danger: #f06a6a;
  --danger-soft: rgba(240, 106, 106, .12);
  --warn: #f2b84b;
  --warn-soft: rgba(242, 184, 75, .12);
  --info: #86a8ff;
  --dots: rgba(255, 255, 255, .028);
  --shadow: 0 18px 50px rgba(0, 0, 0, .45), 0 2px 8px rgba(0, 0, 0, .3);
  --shadow-sm: 0 6px 18px rgba(0, 0, 0, .3);
  --backdrop: rgba(4, 5, 7, .62);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f1ec;
  --bg-2: #ebe8e1;
  --surface: #faf9f6;
  --surface-2: #ffffff;
  --surface-3: #efece5;
  --surface-4: #e4e0d7;
  --line: rgba(28, 24, 14, .08);
  --line-2: rgba(28, 24, 14, .14);
  --text: #17181c;
  --text-2: #5b5f68;
  --text-3: #8d9099;
  --brand: #f7c325;
  --brand-ink: #1a1502;
  --logo: #17181c;
  --accent: #8a6500;
  --accent-2: #6f5100;
  --accent-ink: #1a1502;
  --accent-soft: rgba(214, 160, 0, .12);
  --accent-line: rgba(180, 132, 0, .38);
  --mine: #fbf0c6;
  --mine-line: rgba(180, 132, 0, .22);
  --theirs: #ffffff;
  --ok: #1f9d63;
  --ok-soft: rgba(31, 157, 99, .1);
  --danger: #d23f3f;
  --danger-soft: rgba(210, 63, 63, .09);
  --warn: #b57a0b;
  --warn-soft: rgba(181, 122, 11, .1);
  --info: #3b62d6;
  --dots: rgba(28, 24, 14, .045);
  --shadow: 0 18px 50px rgba(40, 30, 10, .16), 0 2px 8px rgba(40, 30, 10, .08);
  --shadow-sm: 0 6px 18px rgba(40, 30, 10, .1);
  --backdrop: rgba(30, 26, 18, .38);
}

/* ----- base ------------------------------------------------------------------------------ */

*,
*::before,
*::after { box-sizing: border-box; }

html, body, #app { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

.compact body { font-size: 14px; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; opacity: .55; }
a { color: var(--accent); text-underline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
code { font-family: var(--mono); }
[hidden] { display: none !important; }
.muted { color: var(--text-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { flex: none; display: block; }
.rot-270 { transform: rotate(-90deg); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

::selection { background: var(--accent-soft); }

* { scrollbar-width: thin; scrollbar-color: var(--surface-4) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ----- logo / brand ------------------------------------------------------------------------ */

.logo { display: block; flex: none; }
.logo .logo-mark { fill: var(--logo); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo + .brand-text { padding-left: 12px; border-left: 1px solid var(--line-2); }
.brand-text { display: grid; line-height: 1.05; }
.brand-name { font-family: Bahnschrift, "DIN Alternate", var(--font-display); font-weight: 600; font-size: 18px; letter-spacing: -.02em; }
.brand-sub { font-family: Bahnschrift, "DIN Alternate", var(--font); font-size: 10.5px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); margin-top: 2px; }

.boot { display: grid; place-items: center; height: 100%; color: var(--logo); }
.boot-mark { animation: breathe 1.6s var(--ease) infinite; }
@keyframes breathe { 50% { transform: scale(.92); opacity: .6; } }

/* ----- buttons & inputs -------------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--r);
  background: var(--surface-3); color: var(--text); font-weight: 560; white-space: nowrap;
  border: 1px solid var(--line); transition: background var(--t), transform var(--t), border-color var(--t), filter var(--t);
}
.btn:hover:not(:disabled) { background: var(--surface-4); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover:not(:disabled) { background: var(--brand); filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--danger); filter: brightness(1.08); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger-soft:hover:not(:disabled) { background: var(--danger-soft); filter: brightness(1.2); }
.btn-success { background: var(--ok); color: #06140d; border-color: transparent; }
.btn-success:hover:not(:disabled) { background: var(--ok); filter: brightness(1.08); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13.5px; border-radius: var(--r-sm); gap: 6px; }
.btn-lg { height: 48px; font-size: 16px; border-radius: 14px; }
.btn-block { width: 100%; }
.btn.loading { color: transparent !important; position: relative; }
.btn.loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--brand-ink); border-right-color: transparent; animation: spin .7s linear infinite;
}

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 11px;
  color: var(--text-2); transition: background var(--t), color var(--t);
}
.icon-btn:hover:not(:disabled), .icon-btn.active { background: var(--surface-3); color: var(--text); }

.link-btn { color: var(--accent); font-weight: 600; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }

.input {
  width: 100%; height: 44px; padding: 0 14px; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text);
  transition: border-color var(--t), box-shadow var(--t), background var(--t); outline: none;
}
textarea.input { height: auto; padding: 11px 14px; resize: vertical; min-height: 44px; }
.input::placeholder { color: var(--text-3); }
.input:focus { border-color: var(--accent-line); box-shadow: 0 0 0 4px var(--accent-soft); }

.field { display: grid; gap: 7px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12.5px; color: var(--text-3); }
.form-error {
  color: var(--danger); background: var(--danger-soft); padding: 10px 12px;
  border-radius: var(--r-sm); font-size: 14px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.spinner {
  width: 26px; height: 26px; border-radius: 50%; margin: 12px auto;
  border: 2.5px solid var(--surface-4); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
.spinner.sm { width: 18px; height: 18px; border-width: 2px; margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px;
  background: var(--surface-3); border-radius: 13px;
}
.segmented button {
  height: 36px; border-radius: 10px; font-weight: 600; color: var(--text-2); transition: background var(--t), color var(--t);
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  height: 30px; padding: 0 12px; border-radius: 99px; font-size: 13px; font-weight: 560;
  color: var(--text-2); background: transparent; border: 1px solid var(--line-2); transition: all var(--t);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { color: var(--text); border-color: var(--text-3); }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

.badge {
  min-width: 21px; height: 21px; padding: 0 6px; border-radius: 99px; flex: none;
  display: inline-grid; place-items: center; font-size: 11.5px; font-weight: 700;
  background: var(--brand); color: var(--brand-ink);
}
.pill {
  display: inline-flex; align-items: center; gap: 4px; height: 21px; padding: 0 7px; border-radius: 99px;
  font-size: 11.5px; font-weight: 700; flex: none;
}
.pill-call { background: var(--ok-soft); color: var(--ok); }
.pill-call.joined { background: var(--ok); color: #06140d; }
.tag {
  display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 6px; font-size: 11px;
  font-weight: 650; background: var(--accent-soft); color: var(--accent); vertical-align: 1px;
}
.tag-ok { background: var(--ok-soft); color: var(--ok); }

/* ----- avatars ----------------------------------------------------------------------------- */

.avatar {
  --size: 40px;
  width: var(--size); height: var(--size); border-radius: 50%; flex: none;
  display: inline-grid; place-items: center; font-weight: 650; letter-spacing: .01em;
  font-size: calc(var(--size) * .37); user-select: none;
  background: var(--av-bg); color: var(--av-fg);
}
.avatar.group { border-radius: 32%; }
.avatar-wrap { position: relative; display: inline-block; flex: none; width: var(--size); height: var(--size); }
.presence-dot {
  position: absolute; right: -1px; bottom: -1px; width: 32%; height: 32%; min-width: 10px; min-height: 10px;
  border-radius: 50%; background: var(--text-3); border: 2.5px solid var(--bg-2); display: none;
}
.presence-dot.on { display: block; background: var(--ok); }

.tone-0 { --av-bg: #3d301a; --av-fg: #f2c57c; }
.tone-1 { --av-bg: #163530; --av-fg: #74d8c4; }
.tone-2 { --av-bg: #2b2442; --av-fg: #bba7f7; }
.tone-3 { --av-bg: #3b2029; --av-fg: #f3a0b7; }
.tone-4 { --av-bg: #172c3e; --av-fg: #8ac4f3; }
.tone-5 { --av-bg: #27321b; --av-fg: #b8de7f; }
.tone-6 { --av-bg: #3c261a; --av-fg: #f5aa88; }
.tone-7 { --av-bg: #262b35; --av-fg: #b8c2d3; }
[data-theme="light"] .tone-0 { --av-bg: #f5e3c2; --av-fg: #7c5412; }
[data-theme="light"] .tone-1 { --av-bg: #d3efe8; --av-fg: #155e52; }
[data-theme="light"] .tone-2 { --av-bg: #e5defa; --av-fg: #4b3796; }
[data-theme="light"] .tone-3 { --av-bg: #f8dbe3; --av-fg: #8b2847; }
[data-theme="light"] .tone-4 { --av-bg: #d8e9f8; --av-fg: #1f5687; }
[data-theme="light"] .tone-5 { --av-bg: #e2efcf; --av-fg: #44621a; }
[data-theme="light"] .tone-6 { --av-bg: #fae0d2; --av-fg: #8a3b18; }
[data-theme="light"] .tone-7 { --av-bg: #e2e6ec; --av-fg: #3e4859; }

.tone-text-0 { color: #eab45f; } .tone-text-1 { color: #5fcdb7; } .tone-text-2 { color: #ab95f2; } .tone-text-3 { color: #ef8fab; }
.tone-text-4 { color: #78b5ef; } .tone-text-5 { color: #a5d268; } .tone-text-6 { color: #f19a74; } .tone-text-7 { color: #a8b3c6; }
[data-theme="light"] .tone-text-0 { color: #94620e; } [data-theme="light"] .tone-text-1 { color: #16786a; }
[data-theme="light"] .tone-text-2 { color: #5b43b3; } [data-theme="light"] .tone-text-3 { color: #a83257; }
[data-theme="light"] .tone-text-4 { color: #26689f; } [data-theme="light"] .tone-text-5 { color: #52781e; }
[data-theme="light"] .tone-text-6 { color: #a2481f; } [data-theme="light"] .tone-text-7 { color: #4c586c; }

/* ----- auth -------------------------------------------------------------------------------- */

.auth { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(420px, .9fr); height: 100%; }
.auth-hero {
  position: relative; overflow: hidden; padding: 44px 56px; display: flex; flex-direction: column; gap: 48px;
  background:
    radial-gradient(900px 520px at 85% 110%, rgba(247, 195, 37, .16), transparent 60%),
    radial-gradient(600px 400px at -10% -10%, rgba(134, 168, 255, .07), transparent 60%),
    #0b0d10;
  color: #eceef2; border-right: 1px solid rgba(255, 255, 255, .06);
}
.auth-hero .logo .logo-mark { fill: #f7c325; }
.auth-hero .brand-text { border-color: rgba(255, 255, 255, .16); }
.auth-hero-copy { margin-top: auto; max-width: 560px; position: relative; z-index: 1; }
.auth-hero h1 { font-size: clamp(38px, 4.6vw, 62px); line-height: 1.02; font-weight: 700; letter-spacing: -.035em; }
.auth-hero h1 em { font-style: normal; color: #f7c325; }
.auth-hero .lead { margin-top: 18px; font-size: 17px; color: #a4aab6; max-width: 470px; }
.auth-features { list-style: none; margin: 0; padding: 0; display: grid; gap: 18px; max-width: 520px; position: relative; z-index: 1; }
.auth-features li { display: flex; gap: 14px; align-items: flex-start; }
.auth-features strong { display: block; font-weight: 620; margin-bottom: 2px; }
.auth-features span { color: #a4aab6; font-size: 14px; }
.feature-icon {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: none;
  background: rgba(247, 195, 37, .1); color: #f7c325; border: 1px solid rgba(247, 195, 37, .22);
}
.auth-hero-art { position: absolute; right: -160px; top: -120px; width: 620px; height: 620px; pointer-events: none; }
.auth-hero-art span {
  position: absolute; inset: 0; border-radius: 50%; border: 1px solid rgba(247, 195, 37, .14);
  animation: ring 9s var(--ease) infinite;
}
.auth-hero-art span:nth-child(2) { inset: 90px; border-color: rgba(247, 195, 37, .2); animation-delay: -3s; }
.auth-hero-art span:nth-child(3) { inset: 180px; border-color: rgba(247, 195, 37, .3); border-style: dashed; animation: spin 60s linear infinite; }
@keyframes ring { 50% { transform: scale(1.04); opacity: .6; } }

.auth-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px; background: var(--bg); overflow-y: auto; }
.auth-card { width: min(400px, 100%); display: grid; gap: 14px; }
.auth-card h2 { font-size: 28px; font-weight: 680; margin-top: 8px; }
.auth-card .brand-compact { display: none; }
.auth-form { display: grid; gap: 16px; margin-top: 8px; }
.auth-note { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--text-2); }
.auth-note .icon { color: var(--accent); margin-top: 2px; }
.auth-foot { margin-top: 28px; font-size: 12px; }

.auth-invite-note {
  display: flex; gap: 10px; align-items: flex-start; margin-top: 10px; padding: 12px 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); font-size: 13px; color: var(--text-2);
}
.auth-invite-note > .icon { color: var(--accent); margin-top: 1px; }
.auth-invite-note strong { color: var(--text); }
.invite-banner {
  display: flex; gap: 12px; align-items: center; padding: 12px 14px; margin-top: 6px; border-radius: 14px;
  background: var(--accent-soft); border: 1px solid var(--accent-line); color: var(--accent);
}
.invite-banner div { display: grid; gap: 1px; }
.invite-banner strong { color: var(--text); font-size: 15px; }
.invite-banner span { font-size: 12.5px; color: var(--text-2); }
.auth-switch { justify-self: center; margin-top: 4px; }
.invite-invalid { display: grid; justify-items: center; text-align: center; gap: 10px; padding: 18px 0 8px; }
.invite-invalid-icon { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; background: var(--danger-soft); color: var(--danger); }

.fatal { height: 100%; display: grid; place-content: center; justify-items: center; gap: 14px; text-align: center; padding: 24px; max-width: 520px; margin: 0 auto; }
.fatal h1 { font-size: 26px; }

/* ----- app layout -------------------------------------------------------------------------- */

.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100%; height: 100dvh; }

.sidebar {
  display: flex; flex-direction: column; min-height: 0; background: var(--bg-2); border-right: 1px solid var(--line);
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 10px 20px; }
.head-actions { display: flex; gap: 4px; }
.sidebar-tools { padding: 6px 16px 12px; display: grid; gap: 12px; }

.search { position: relative; }
.search > .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 40px; height: 42px; background: var(--surface); border-color: var(--line); }
.search .input:focus { background: var(--surface-2); }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }

.conv-list { flex: 1; overflow-y: auto; padding: 2px 10px 10px; }
.conv-item {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px;
  text-align: left; position: relative; transition: background var(--t);
}
.conv-item:hover { background: var(--surface); }
.conv-item.active { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
.conv-item.active::before {
  content: ""; position: absolute; left: -10px; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand);
}
.conv-main { flex: 1; min-width: 0; display: grid; gap: 3px; }
.conv-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.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(--text-3); flex: none; }
.conv-item.unread .conv-time { color: var(--accent); font-weight: 600; }
.conv-preview { flex: 1; min-width: 0; color: var(--text-2); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item.unread .conv-preview { color: var(--text); }
.conv-preview.typing { color: var(--accent); font-style: italic; }

.list-empty { display: grid; justify-items: center; text-align: center; gap: 10px; padding: 48px 18px; }
.list-empty-icon { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-bottom: 4px; }
.list-empty p { font-size: 14px; max-width: 250px; }
.list-empty .btn { margin-top: 8px; }

.me-card { display: flex; align-items: center; gap: 11px; padding: 12px 12px 12px 16px; border-top: 1px solid var(--line); }
.me-text { flex: 1; min-width: 0; display: grid; }
.me-text strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.conn i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.conn-online i { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.conn-connecting i, .conn-offline i { background: var(--warn); animation: breathe 1.2s infinite; }
.conn-offline { color: var(--warn); }

.main { position: relative; min-width: 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); background: var(--bg); }
.main.with-info { grid-template-columns: minmax(0, 1fr) var(--info-w); }
.chat-host { min-width: 0; min-height: 0; display: flex; }

/* ----- empty state ------------------------------------------------------------------------- */

.empty-main {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 32px; gap: 12px;
  background: radial-gradient(600px 400px at 50% 38%, var(--accent-soft), transparent 70%);
}
.empty-art { position: relative; width: 200px; height: 200px; display: grid; place-items: center; margin-bottom: 18px; }
.empty-art span { position: absolute; inset: 0; border-radius: 50%; border: 1px solid var(--accent-line); opacity: .45; animation: ring 7s var(--ease) infinite; }
.empty-art span:nth-child(2) { inset: 30px; opacity: .7; animation-delay: -2.3s; }
.empty-art span:nth-child(3) { inset: 60px; border-style: dashed; opacity: .9; animation: spin 50s linear infinite; }
.empty-main h2 { font-size: 26px; font-weight: 680; }
.empty-main > p { max-width: 460px; }
.empty-facts { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 14px; }
.empty-facts span {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); font-size: 13px; color: var(--text-2);
}
.empty-facts .icon { color: var(--accent); }

/* ----- chat -------------------------------------------------------------------------------- */

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.chat-head {
  display: flex; align-items: center; gap: 8px; height: 68px; padding: 0 14px 0 18px; flex: none;
  border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); position: relative; z-index: 2;
}
.back-btn { display: none; }
.chat-id { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; padding: 6px 8px 6px 4px; border-radius: 12px; }
.chat-id:hover { background: var(--surface); }
.chat-id-text { min-width: 0; display: grid; }
.chat-id-text strong { font-size: 16px; font-weight: 640; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-id-text small { font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-id-text .online { color: var(--ok); }
.chat-id-text .typing { color: var(--accent); font-style: italic; }
.chat-actions { display: flex; align-items: center; gap: 2px; }

.e2ee-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; margin-right: 6px; border-radius: 99px;
  font-size: 12.5px; font-weight: 600; color: var(--text-2); background: var(--surface); border: 1px solid var(--line);
  transition: all var(--t);
}
button.e2ee-chip:hover { border-color: var(--line-2); color: var(--text); }
.e2ee-chip.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.e2ee-chip.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; animation: nudge 2.4s ease-in-out infinite; }
@keyframes nudge { 0%, 88%, 100% { transform: none; } 92% { transform: translateX(-2px); } 96% { transform: translateX(2px); } }

.banners { display: grid; gap: 1px; flex: none; }
.banner { display: flex; align-items: center; gap: 12px; padding: 10px 18px; font-size: 13.5px; border-bottom: 1px solid var(--line); }
.banner-text { flex: 1; min-width: 0; }
.banner-call { background: var(--ok-soft); }
.banner-warn { background: var(--warn-soft); color: var(--text); }
.banner-warn > .icon { color: var(--warn); }
.banner-info { background: var(--surface); }
.banner-info > .icon { color: var(--info); }
.pulse-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(91, 214, 155, .6); } 100% { box-shadow: 0 0 0 10px rgba(91, 214, 155, 0); } }

.timeline-wrap { flex: 1; min-height: 0; position: relative; }
.timeline {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; outline: none;
  background-image: radial-gradient(circle at 1px 1px, var(--dots) 1px, transparent 0);
  background-size: 22px 22px;
}
.timeline-inner { max-width: var(--col-w); margin: 0 auto; padding: 18px 22px 14px; min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.timeline-top { display: grid; gap: 10px; justify-items: center; }
.loading-older { padding: 10px; }
.timeline-loading { padding: 40px; }
.timeline-error { display: grid; justify-items: center; gap: 8px; padding: 40px; color: var(--danger); }
.e2ee-note {
  display: flex; gap: 10px; align-items: flex-start; max-width: 460px; margin: 18px auto 14px; padding: 12px 16px;
  border-radius: 14px; background: color-mix(in srgb, var(--accent-soft) 70%, var(--bg)); color: var(--text-2);
  font-size: 13px; border: 1px solid var(--mine-line);
}
.e2ee-note .icon { color: var(--accent); margin-top: 1px; }
.history-note { font-size: 12.5px; color: var(--text-3); text-align: center; max-width: 420px; margin-bottom: 8px; }

.day { display: flex; justify-content: center; margin: 18px 0 10px; position: sticky; top: 8px; z-index: 1; pointer-events: none; }
.day span {
  font-size: 12px; font-weight: 600; color: var(--text-2); padding: 4px 12px; border-radius: 99px;
  background: color-mix(in srgb, var(--surface-2) 88%, transparent); backdrop-filter: blur(8px); border: 1px solid var(--line);
}

.jump-btn {
  position: absolute; right: 22px; bottom: 16px; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface-2); color: var(--text); border: 1px solid var(--line-2);
  box-shadow: var(--shadow-sm); z-index: 3; transition: transform var(--t);
}
.jump-btn:hover { transform: translateY(-2px); }

/* messages */
.msg { display: flex; align-items: flex-end; gap: 8px; position: relative; margin-top: 2px; }
.msg.grp-start { margin-top: 12px; }
.msg.mine { flex-direction: row-reverse; }
.msg-avatar { width: 30px; flex: none; align-self: flex-end; }
.msg:not(.grp-end) .msg-avatar { visibility: hidden; }

.bubble {
  position: relative; max-width: min(620px, 78%); padding: 8px 12px 6px; min-width: 64px;
  background: var(--theirs); border: 1px solid var(--line); border-radius: 18px;
  overflow-wrap: anywhere; box-shadow: 0 1px 1px rgba(0, 0, 0, .06);
}
.msg:not(.mine):not(.grp-start) .bubble { border-top-left-radius: 6px; }
.msg:not(.mine):not(.grp-end) .bubble { border-bottom-left-radius: 6px; }
.msg.mine .bubble { background: var(--mine); border-color: var(--mine-line); }
.msg.mine:not(.grp-start) .bubble { border-top-right-radius: 6px; }
.msg.mine:not(.grp-end) .bubble { border-bottom-right-radius: 6px; }
.msg.pending .bubble { opacity: .82; }
.msg.failed .bubble { border-color: var(--danger); }
.msg.flash .bubble { animation: flash 1.3s var(--ease); }
@keyframes flash { 30% { box-shadow: 0 0 0 4px var(--accent-line); } }

.sender { font-size: 12.5px; font-weight: 650; margin-bottom: 2px; }
.msg:not(.grp-start) .sender { display: none; }
.text { white-space: pre-wrap; line-height: 1.45; }
.text a { overflow-wrap: anywhere; }
.muted-italic { color: var(--text-2); font-style: italic; display: flex; align-items: center; gap: 6px; }
.bubble-error { background: var(--danger-soft) !important; border-color: transparent !important; }
.bubble-error .muted-italic { color: var(--danger); }

.meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: 11px; color: var(--text-3); margin-top: 2px; line-height: 1; user-select: none; }
.tick { display: inline-flex; color: var(--text-3); }
.tick.read { color: var(--accent); }
.tick.failed { color: var(--danger); }

.failed-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 6px; font-size: 12.5px; color: var(--danger); }
.failed-row span { display: inline-flex; gap: 5px; align-items: center; }

.quote {
  display: grid; text-align: left; width: 100%; margin: 2px 0 6px; padding: 6px 10px; border-radius: 10px;
  background: color-mix(in srgb, var(--text) 5%, transparent); border-left: 3px solid var(--accent); font-size: 13px;
}
.quote strong { font-size: 12.5px; color: var(--accent); }
.quote span { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tools {
  display: flex; gap: 2px; align-self: center; opacity: 0; pointer-events: none; transition: opacity var(--t);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 2px; box-shadow: var(--shadow-sm);
}
.msg:hover .tools, .msg:focus-within .tools, .msg.show-tools .tools { opacity: 1; pointer-events: auto; }
.tool { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--text-2); }
.tool:hover { background: var(--surface-3); color: var(--text); }
.tool.danger:hover { color: var(--danger); background: var(--danger-soft); }

.system { display: flex; justify-content: center; margin: 12px 0; }
.system span {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: 99px; max-width: 90%;
  font-size: 12.5px; color: var(--text-2); background: var(--surface); border: 1px solid var(--line);
}
.system time { color: var(--text-3); font-size: 11px; margin-left: 2px; }
.system-missed span { color: var(--danger); }

/* media & files */
.bubble-media { padding: 4px; }
.bubble-media .meta { position: absolute; right: 12px; bottom: 10px; color: #fff; background: rgba(0, 0, 0, .45); padding: 3px 7px; border-radius: 99px; }
.bubble-media .meta .tick { color: #fff; }
.bubble-media .sender { padding: 4px 8px 2px; }
.image { margin: 0; position: relative; max-width: 100%; border-radius: 14px; overflow: hidden; cursor: zoom-in; background: var(--surface-3); }
.image img { width: 100%; height: 100%; object-fit: cover; display: block; transition: filter .3s var(--ease); }
.image img.blurry { filter: blur(8px); transform: scale(1.04); }
.bubble:not(.bubble-media) .image { margin-bottom: 6px; }
.media-overlay {
  position: absolute; inset: auto 8px 8px; display: grid; gap: 6px; padding: 8px 10px; border-radius: 10px;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 12px; backdrop-filter: blur(6px);
}
.progress { height: 4px; border-radius: 4px; background: color-mix(in srgb, var(--text) 12%, transparent); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--brand); border-radius: 4px; transition: width .2s linear; }
.media-overlay .progress { background: rgba(255, 255, 255, .25); }

.file-card { display: flex; align-items: center; gap: 12px; min-width: 240px; max-width: 360px; padding: 4px 2px 6px; flex-wrap: wrap; }
.file-card .progress { flex-basis: 100%; }
.file-icon { position: relative; width: 44px; height: 50px; display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); flex: none; }
.file-icon em { position: absolute; bottom: 6px; font-size: 8.5px; font-style: normal; font-weight: 800; letter-spacing: .04em; }
.file-icon .icon { margin-top: -8px; }
.file-text { flex: 1; min-width: 0; display: grid; }
.file-text strong { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-text small { color: var(--text-2); font-size: 12px; }
.file-dl { background: var(--surface-3); color: var(--text); }
.video-card { display: flex; align-items: center; gap: 12px; min-width: 240px; padding: 4px 2px 6px; text-align: left; }
.play-disc { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: var(--brand-ink); flex: none; }

.voice { display: flex; align-items: center; gap: 10px; min-width: 250px; padding: 2px 0 4px; flex-wrap: wrap; }
.voice .progress { flex-basis: 100%; }
.voice-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: var(--brand-ink); flex: none; }
.voice-track { flex: 1; position: relative; height: 30px; cursor: pointer; }
.voice-bars { display: flex; align-items: center; gap: 2px; height: 100%; }
.voice-bars b { flex: 1; border-radius: 2px; background: color-mix(in srgb, var(--text) 26%, transparent); min-height: 3px; }
.voice-track > i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent); mix-blend-mode: normal; opacity: .35; border-radius: 4px; pointer-events: none; }
.voice-time { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; min-width: 34px; }

/* composer */
.composer { flex: none; padding: 10px 22px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.composer > * { max-width: calc(var(--col-w) - 44px); margin-left: auto; margin-right: auto; }
.reply-bar {
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 14px; margin-bottom: 8px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--line); color: var(--accent);
}
.reply-text { flex: 1; min-width: 0; display: grid; font-size: 13px; }
.reply-text strong { color: var(--accent); }
.reply-text span { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.attach-btn { width: 46px; height: 46px; border-radius: 50%; flex: none; }
.composer-field {
  flex: 1; min-width: 0; display: flex; align-items: flex-end; border-radius: 23px; padding: 0 6px 0 16px;
  background: var(--surface-2); border: 1px solid var(--line-2); transition: border-color var(--t), box-shadow var(--t);
}
.composer-field:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 4px var(--accent-soft); }
.composer-input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; resize: none;
  padding: 12px 0; max-height: 180px; line-height: 1.4; display: block;
}
.composer-input::placeholder { color: var(--text-3); }
.send-btn {
  width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); transition: transform var(--t), background var(--t), color var(--t);
}
.send-btn:hover { transform: scale(1.05); }
.send-btn.is-voice { background: var(--surface-3); color: var(--text); }
.send-btn.is-voice:hover { background: var(--accent-soft); color: var(--accent); }
.danger-btn { color: var(--danger); width: 46px; height: 46px; border-radius: 50%; }
.danger-btn:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.recording {
  flex: 1; height: 46px; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-radius: 23px;
  background: var(--danger-soft); color: var(--text); font-size: 14px; font-weight: 560;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: breathe 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; color: var(--text-2); }
.rec-wave { margin-left: auto; display: flex; gap: 3px; align-items: center; height: 20px; }
.rec-wave i { width: 3px; height: 30%; border-radius: 2px; background: var(--danger); animation: wave 1s ease-in-out infinite; }
.rec-wave i:nth-child(2) { animation-delay: -.8s; } .rec-wave i:nth-child(3) { animation-delay: -.6s; }
.rec-wave i:nth-child(4) { animation-delay: -.4s; } .rec-wave i:nth-child(5) { animation-delay: -.2s; }
@keyframes wave { 50% { height: 100%; } }

.drop-hint {
  position: absolute; inset: 10px; border-radius: 20px; border: 2px dashed var(--accent);
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(4px);
  display: none; place-items: center; z-index: 10; pointer-events: none;
}
.drop-hint > div { display: grid; justify-items: center; gap: 6px; color: var(--accent); }
.drop-hint strong { font-size: 18px; color: var(--text); }
.drop-hint span { color: var(--text-2); font-size: 13px; }
.chat.dragging .drop-hint { display: grid; }

/* ----- info panel -------------------------------------------------------------------------- */

.info { border-left: 1px solid var(--line); background: var(--bg-2); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.info-head { display: flex; align-items: center; justify-content: space-between; height: 68px; padding: 0 12px 0 20px; border-bottom: 1px solid var(--line); flex: none; }
.info-head h2 { font-size: 16px; font-weight: 640; }
.info-scroll { overflow-y: auto; flex: 1; padding-bottom: 24px; }
.info-hero { display: grid; justify-items: center; text-align: center; gap: 4px; padding: 28px 20px 20px; }
.info-hero .avatar-wrap, .info-hero > .avatar { margin-bottom: 10px; }
.info-hero h3 { font-size: 20px; font-weight: 680; display: flex; align-items: center; gap: 4px; }
.info-hero .bio { margin-top: 8px; color: var(--text); font-size: 14px; }
.inline-edit { width: 30px; height: 30px; }
.info-section { padding: 16px 20px; border-top: 1px solid var(--line); display: grid; gap: 12px; }
.info-section h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); }
.section-head { display: flex; align-items: center; justify-content: space-between; }

.trust-status { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.trust-status > .icon { color: var(--text-2); margin-top: 1px; }
.trust-status div { display: grid; gap: 2px; }
.trust-status strong { font-size: 14px; }
.trust-status span { font-size: 12.5px; color: var(--text-2); }
.trust-status.ok { background: var(--ok-soft); border-color: transparent; }
.trust-status.ok > .icon, .trust-status.ok strong { color: var(--ok); }
.trust-status.warn { background: var(--warn-soft); border-color: transparent; }
.trust-status.warn > .icon, .trust-status.warn strong { color: var(--warn); }

.device-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.device-list li { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.device-list li > div { flex: 1; min-width: 0; display: grid; gap: 2px; }
.device-list strong { font-size: 14px; font-weight: 600; }
.device-list code { font-size: 11.5px; color: var(--text-2); letter-spacing: .02em; }
.device-list small { font-size: 12px; }
.device-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); flex: none; }

.member-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.member-list li { display: flex; align-items: center; gap: 11px; padding: 7px 6px; border-radius: 12px; }
.member-list li:hover { background: var(--surface); }
.member-text { flex: 1; min-width: 0; display: grid; }
.member-text strong { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-text small { font-size: 12px; }
.verified-mark { color: var(--ok); display: inline-flex; }
.warn-mark { color: var(--warn); display: inline-flex; }
.role { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--surface-3); color: var(--text-2); }
.role-owner { background: var(--accent-soft); color: var(--accent); }

.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.facts li { display: flex; gap: 10px; font-size: 13px; color: var(--text-2); }
.facts .icon { color: var(--accent); margin-top: 2px; }

/* ----- overlays ---------------------------------------------------------------------------- */

.backdrop {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background: var(--backdrop); backdrop-filter: blur(3px); opacity: 0; transition: opacity 180ms var(--ease);
}
.backdrop.in { opacity: 1; }
.modal {
  width: 100%; max-height: min(88vh, 860px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 22px; box-shadow: var(--shadow);
  transform: translateY(10px) scale(.985); transition: transform 220ms var(--ease);
}
.backdrop.in .modal { transform: none; }
.modal-sm { max-width: 420px; }
.modal-md { max-width: 540px; }
.modal-lg { max-width: 860px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 16px 8px 24px; }
.modal-head h2 { font-size: 20px; font-weight: 680; }
.modal-head p { font-size: 13.5px; margin-top: 4px; }
.modal-body { padding: 12px 24px 20px; overflow-y: auto; display: grid; gap: 16px; align-content: start; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; border-top: 1px solid var(--line); }
.confirm-text { color: var(--text-2); }

.menu {
  position: fixed; z-index: 120; min-width: 210px; padding: 6px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line-2); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-4px); transition: opacity 120ms, transform 160ms var(--ease);
}
.menu.in { opacity: 1; transform: none; }
.menu-item { width: 100%; display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 10px; border-radius: 9px; font-size: 14px; text-align: left; color: var(--text); }
.menu-item .icon { color: var(--text-2); }
.menu-item:hover { background: var(--surface-3); }
.menu-item.danger, .menu-item.danger .icon { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }

body:has(.main.in-call) #toasts { bottom: 112px; }
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; justify-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 24px); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 14px; max-width: 520px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line-2); box-shadow: var(--shadow);
  font-size: 14px; opacity: 0; transform: translateY(10px); transition: opacity 200ms, transform 240ms var(--ease);
}
.toast.in { opacity: 1; transform: none; }
.toast-error .icon { color: var(--danger); }
.toast-warn .icon { color: var(--warn); }
.toast-ok .icon { color: var(--ok); }
.toast-info .icon { color: var(--accent); }

.lightbox {
  position: fixed; inset: 0; z-index: 150; background: rgba(5, 6, 8, .92); display: flex; flex-direction: column;
  opacity: 0; transition: opacity 180ms var(--ease); color: #eceef2;
}
.lightbox.in { opacity: 1; }
.lightbox-bar { display: flex; align-items: center; gap: 6px; padding: 12px 16px; }
.lightbox-bar .icon-btn { color: #cfd3db; }
.lightbox-bar .icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.lightbox-name { flex: 1; min-width: 0; display: grid; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lightbox-name small { font-weight: 400; color: #9aa0ab; }
.lightbox-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 20px 20px; }
.lightbox-stage img, .lightbox-stage video { max-width: 100%; max-height: 100%; border-radius: 10px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }

.replaced { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; background: var(--backdrop); backdrop-filter: blur(6px); padding: 20px; }
.replaced-card { display: grid; justify-items: center; gap: 12px; text-align: center; max-width: 380px; padding: 30px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow); }
.replaced-card > .icon { color: var(--accent); }

/* dialogs */
.user-search { display: grid; gap: 10px; }
.pick-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 320px; overflow-y: auto; }
.pick-hint { padding: 14px 6px; font-size: 13.5px; }
.pick-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px; text-align: left; }
.pick-item:hover { background: var(--surface-3); }
.pick-text { flex: 1; min-width: 0; display: grid; }
.pick-text strong { font-weight: 600; }
.pick-text small { font-size: 12.5px; }
.pick-plus { color: var(--text-3); }
.pick-item:hover .pick-plus { color: var(--accent); }
.new-group-link { margin-top: 2px; }
.selected-chips:empty { display: none; }
.chip-user { background: var(--surface-3); color: var(--text); border-color: transparent; padding: 0 6px 0 4px; height: 30px; }
.chip-user button { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; color: var(--text-2); }
.chip-user button:hover { background: var(--surface-4); color: var(--text); }

.verify { display: grid; gap: 16px; }
.safety-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 14px; padding: 20px; border-radius: 16px;
  background: var(--bg); border: 1px solid var(--line); font-family: var(--mono); font-size: 21px; letter-spacing: .06em;
  text-align: center; font-variant-numeric: tabular-nums; user-select: all;
}
.copy-number { justify-self: center; }
.device-details summary { cursor: pointer; font-size: 13.5px; color: var(--text-2); padding: 4px 0; }
.device-details .device-list { margin-top: 10px; }
.verify-actions { display: grid; gap: 10px; }

.small { font-size: 12.5px; }
.invite-pane { gap: 14px; }
.invite-create { display: flex; gap: 8px; }
.invite-create .input { flex: 1; }
.invite-result { display: grid; gap: 10px; padding: 14px; border-radius: 16px; background: var(--ok-soft); border: 1px solid transparent; }
.invite-result-head { display: flex; align-items: center; gap: 8px; color: var(--ok); }
.invite-url-row { display: flex; gap: 8px; }
.invite-url { font-family: var(--mono); font-size: 12.5px; background: var(--surface); }
.invite-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.invite-list li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.invite-list li.invite-empty { background: none; border: 0; padding: 4px 0; font-size: 13.5px; }
.invite-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.invite-text strong { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.invite-status { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--text-2); }
.invite-status.used { color: var(--ok); }
.invite-status.expired { color: var(--text-3); }
.pick-hint .btn { margin-top: 8px; }
@media (max-width: 560px) { .invite-create, .invite-url-row { flex-direction: column; } }

.badge-host { position: relative; }
.dot-badge {
  position: absolute; top: 2px; right: 1px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 99px;
  display: grid; place-items: center; font-size: 10.5px; font-weight: 800; background: var(--danger); color: #fff;
  box-shadow: 0 0 0 2px var(--bg-2);
}
.pick-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.contacts-pane { display: grid; gap: 6px; }
.contacts-section { display: grid; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.contacts-section:last-child { border-bottom: 0; }
.contacts-section h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); }
.contacts-section .link-btn { justify-self: start; }
.contact-add { display: grid; gap: 8px; }
.contact-add-row { display: flex; gap: 8px; }
.contact-add-row .input { flex: 1; }
.contact-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.contact-list li { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 12px; }
.contact-list li:hover { background: var(--surface-2); }
.contact-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; }
.contact-text { flex: 1; min-width: 0; display: grid; }
.contact-text strong { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-text small { font-size: 12.5px; }
.admin-pane { gap: 12px; }
.admin-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.admin-stats div { padding: 10px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); display: grid; }
.admin-stats strong { font-size: 20px; font-family: var(--font-display); }
.admin-stats span { font-size: 12px; color: var(--text-2); }
.admin-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.admin-list li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.admin-list li.is-disabled { opacity: .62; }
.admin-user { flex: 1; min-width: 0; display: grid; gap: 2px; }
.admin-user strong { font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.admin-user small { font-size: 12px; color: var(--text-2); }
.tag-danger { background: var(--danger-soft); color: var(--danger); }
.admin-hint { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--text-2); padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); }
.admin-hint .icon { color: var(--accent); margin-top: 1px; }
@media (max-width: 560px) { .admin-stats { grid-template-columns: 1fr 1fr; } .contact-add-row { flex-direction: column; } }

.settings .modal-body { padding: 0; }
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 460px; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px 20px 16px; border-right: 1px solid var(--line); }
.settings-nav button { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 12px; border-radius: 10px; color: var(--text-2); font-weight: 560; text-align: left; }
.settings-nav button:hover { background: var(--surface-3); color: var(--text); }
.settings-nav button.active { background: var(--accent-soft); color: var(--accent); }
.settings-nav .settings-logout { margin-top: auto; color: var(--danger); }
.settings-nav .settings-logout:hover { background: var(--danger-soft); color: var(--danger); }
.settings-pane { padding: 8px 26px 26px; overflow-y: auto; }
.pane { display: grid; gap: 14px; align-content: start; }
.pane h3 { font-size: 15px; font-weight: 650; margin-top: 8px; }
.pane-actions { display: flex; justify-content: flex-end; }
.profile-preview { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 16px; background: var(--bg); border: 1px solid var(--line); }
.profile-preview div { display: grid; }
.profile-preview strong { font-size: 17px; }
.fp-big { display: block; padding: 14px 16px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); font-size: 16px; letter-spacing: .08em; color: var(--accent); text-align: center; }

.theme-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.theme-option { display: grid; gap: 10px; padding: 10px; border-radius: 16px; border: 1px solid var(--line-2); text-align: left; transition: border-color var(--t); }
.theme-option > span:last-child { display: flex; align-items: center; gap: 7px; font-weight: 560; font-size: 14px; }
.theme-option.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.theme-swatch { height: 70px; border-radius: 10px; display: grid; grid-template-columns: 1fr 2fr; grid-template-rows: 1fr 1fr; gap: 5px; padding: 8px; }
.theme-swatch i { border-radius: 5px; }
.theme-swatch i:first-child { grid-row: span 2; }
.theme-dark .theme-swatch { background: #0d0f13; } .theme-dark .theme-swatch i { background: #1c2129; } .theme-dark .theme-swatch i:last-child { background: #f7c325; }
.theme-light .theme-swatch { background: #f3f1ec; } .theme-light .theme-swatch i { background: #fff; } .theme-light .theme-swatch i:last-child { background: #f7c325; }
.theme-system .theme-swatch { background: linear-gradient(135deg, #0d0f13 50%, #f3f1ec 50%); } .theme-system .theme-swatch i { background: rgba(128, 128, 128, .35); } .theme-system .theme-swatch i:last-child { background: #f7c325; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row > span:first-child { display: grid; gap: 3px; }
.switch-row small { font-size: 12.5px; }
.switch { position: relative; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch i { display: block; width: 44px; height: 26px; border-radius: 99px; background: var(--surface-4); transition: background var(--t); position: relative; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform var(--t); box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + i { opacity: .4; }
.check-row { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--text-2); cursor: pointer; }
.check-row input { margin-top: 3px; accent-color: var(--accent); }

/* ----- calls ------------------------------------------------------------------------------- */

.stage {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column;
  background: radial-gradient(1000px 600px at 50% 120%, rgba(247, 195, 37, .08), transparent 60%), #08090b;
  color: #eceef2;
  --line: rgba(255, 255, 255, .08);
}
.stage-head { display: flex; align-items: center; gap: 14px; padding: 16px 18px 8px 24px; }
.stage-title { flex: 1; min-width: 0; display: grid; }
.stage-title strong { font-size: 17px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-status { font-size: 13px; color: #9aa0ab; font-variant-numeric: tabular-nums; }
.stage-chip { background: rgba(91, 214, 155, .12); color: #5bd69b; margin: 0; }
.stage-head-actions { display: flex; gap: 4px; }
.stage .icon-btn { color: #bfc4cd; }
.stage .icon-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.audio-unlock { align-self: center; display: inline-flex; gap: 8px; align-items: center; padding: 8px 16px; border-radius: 99px; background: #f7c325; color: #1a1502; font-weight: 600; }

.stage-body { flex: 1; min-height: 0; padding: 10px 18px; display: flex; }
.stage-grid {
  flex: 1; min-height: 0; display: flex; flex-wrap: wrap; gap: 12px; align-content: center; justify-content: center;
}
.stage-grid .tile { aspect-ratio: 16 / 10; flex: 0 0 calc((100% - (var(--cols, 1) - 1) * 12px) / var(--cols, 1)); max-height: 100%; }
.stage-grid[data-count="1"] { place-items: center; }
.stage-grid[data-count="1"] .tile { width: min(100%, 880px); }
.stage-grid[data-count="2"] { display: block; position: relative; }
.stage-grid[data-count="2"] .tile:not(.self) { position: absolute; inset: 0; aspect-ratio: auto; }
.stage-grid[data-count="2"] .tile.self .avatar { --size: 52px !important; }
.stage-grid[data-count="2"] .tile.self {
  position: absolute; right: 16px; bottom: 16px; width: clamp(150px, 22%, 280px); aspect-ratio: 16 / 10; z-index: 2;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5); border: 1px solid rgba(255, 255, 255, .12);
}
.stage-spotlight { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 12px; }
.stage-strip { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.stage-strip .tile { aspect-ratio: 16 / 10; flex: none; }

.tile {
  position: relative; overflow: hidden; border-radius: 18px; background: #15181e; min-height: 0;
  display: grid; place-items: center; cursor: pointer; transition: box-shadow 160ms var(--ease);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
}
.tile.speaking { box-shadow: inset 0 0 0 3px #f7c325, 0 0 0 1px rgba(247, 195, 37, .3); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile video.mirror { transform: scaleX(-1); }
.tile video.contain { object-fit: contain; }
.tile.spotlight { cursor: zoom-out; }
.tile-avatar { display: grid; place-items: center; }
.tile.speaking .tile-avatar .avatar { box-shadow: 0 0 0 5px rgba(247, 195, 37, .35); }
.tile-avatar .avatar { transition: box-shadow 160ms; }
.tile-label {
  position: absolute; left: 10px; bottom: 10px; display: flex; align-items: center; gap: 6px; max-width: calc(100% - 20px);
  padding: 5px 10px; border-radius: 99px; background: rgba(0, 0, 0, .55); backdrop-filter: blur(6px); font-size: 12.5px; font-weight: 600;
}
.tile-label span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-muted { color: #f06a6a; display: inline-flex; }
.tile-state { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; background: rgba(8, 9, 11, .55); font-size: 13px; color: #cfd3db; }

.dock {
  align-self: center; display: flex; gap: 12px; padding: 12px 14px; margin: 8px 0 18px; border-radius: 99px;
  background: rgba(28, 31, 38, .85); border: 1px solid rgba(255, 255, 255, .08); backdrop-filter: blur(12px);
  margin-bottom: max(18px, env(safe-area-inset-bottom));
}
.dock-btn {
  width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255, 255, 255, .1); color: #fff; transition: background var(--t), transform var(--t);
}
.dock-btn:hover { background: rgba(255, 255, 255, .18); }
.dock-btn:active { transform: scale(.95); }
.dock-btn.off { background: #eceef2; color: #16181d; }
.dock-btn.on { background: #f7c325; color: #1a1502; }
.dock-btn.hangup { width: 72px; border-radius: 99px; background: #e5484d; }
.dock-btn.hangup:hover { background: #f05b60; }
.hangup .icon, .decline .icon { transform: rotate(135deg); }

.mini-call {
  position: fixed; right: 20px; top: 80px; z-index: 60; display: flex; align-items: center; gap: 6px;
  padding: 8px; border-radius: 20px; background: #15181e; color: #eceef2; border: 1px solid rgba(255, 255, 255, .1);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .45); max-width: calc(100vw - 24px); animation: rise 260ms var(--ease);
}
@keyframes rise { from { transform: translateY(-12px); opacity: 0; } }
.mini-main { display: flex; align-items: center; gap: 10px; padding: 4px 10px 4px 4px; min-width: 0; text-align: left; border-radius: 14px; }
.mini-main:hover { background: rgba(255, 255, 255, .06); }
.mini-pulse { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: #5bd69b; color: #06140d; flex: none; animation: pulse 2s infinite; }
.mini-text { display: grid; min-width: 0; }
.mini-text strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.mini-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .08); color: #fff; flex: none; }
.mini-btn:hover { background: rgba(255, 255, 255, .16); }
.mini-btn.off { background: #eceef2; color: #16181d; }
.mini-btn.hangup { background: #e5484d; }

.incoming {
  position: fixed; top: 20px; right: 20px; z-index: 180; width: 380px; max-width: calc(100vw - 24px);
  display: grid; grid-template-columns: auto 1fr; gap: 14px 16px; align-items: center; padding: 18px;
  border-radius: 24px; background: #15181e; color: #eceef2; border: 1px solid rgba(255, 255, 255, .1);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5); opacity: 0; transform: translateY(-12px); transition: opacity 200ms, transform 260ms var(--ease);
}
.incoming.in { opacity: 1; transform: none; }
.incoming-ring { border-radius: 50%; animation: pulse-accent 1.4s infinite; }
@keyframes pulse-accent { 0% { box-shadow: 0 0 0 0 rgba(247, 195, 37, .55); } 100% { box-shadow: 0 0 0 18px rgba(247, 195, 37, 0); } }
.incoming-text { display: grid; gap: 2px; min-width: 0; }
.incoming-text strong { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.incoming-text span { font-size: 13.5px; color: #a4aab6; }
.incoming-text small { display: inline-flex; align-items: center; gap: 5px; color: #5bd69b; font-size: 12px; margin-top: 2px; }
.incoming-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 12px; }
.round-btn { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; color: #fff; transition: transform var(--t), filter var(--t); }
.round-btn:hover { transform: scale(1.06); filter: brightness(1.08); }
.round-btn.decline { background: #e5484d; }
.round-btn.accept { background: #2fbf71; }

/* ----- responsive -------------------------------------------------------------------------- */

@media (max-width: 1180px) {
  .main.with-info { grid-template-columns: minmax(0, 1fr); }
  .main.with-info .info { position: absolute; top: 0; right: 0; bottom: 0; width: min(var(--info-w), 100%); z-index: 15; box-shadow: var(--shadow); }
  .chat-actions .e2ee-chip span { display: none; }
  .chat-actions .e2ee-chip { padding: 0 9px; }
}

@media (max-width: 880px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app[data-view="list"] .main { display: none; }
  .app[data-view="chat"] .sidebar { display: none; }
  .back-btn { display: inline-grid; }
  .chat-head { padding: 0 8px; gap: 2px; height: 60px; }
  .chat-id { padding-left: 2px; }
  .timeline-inner { padding: 12px 12px 10px; }
  .composer { padding: 8px 10px 10px; }
  .bubble { max-width: 86%; }
  .stage { position: fixed; z-index: 90; }
  .stage-spotlight { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .stage-strip { flex-direction: row; overflow-x: auto; }
  .stage-strip .tile { width: 140px; }
  .stage-grid { --cols: 1 !important; overflow-y: auto; }
  .stage-grid[data-count="3"], .stage-grid[data-count="4"] { --cols: 2 !important; }
  .stage-grid .tile { aspect-ratio: 3 / 4; }
  .stage-grid[data-count="1"] .tile { aspect-ratio: 3 / 4; width: min(100%, 420px); }
  .dock { gap: 10px; }
  .dock-btn { width: 50px; height: 50px; }
  .main.with-info .info { position: fixed; inset: 0; width: 100%; z-index: 40; }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 4px 12px 10px; }
  .settings-nav button { flex: none; }
  .settings-nav .settings-logout { margin-top: 0; }
  .settings-pane { padding: 8px 18px 22px; }
  .theme-options { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .form-grid { grid-template-columns: 1fr; }
  .tools { display: none; }
  .msg.show-tools .tools { display: flex; }
  .mini-call { left: 12px; right: 12px; top: auto; bottom: calc(76px + env(safe-area-inset-bottom)); }
  .mini-main { flex: 1; }
  .incoming { top: 12px; right: 12px; left: 12px; width: auto; max-width: none; }
  #toasts { bottom: 90px; }
}

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .auth-card .brand-compact { display: flex; margin-bottom: 18px; }
}

@media (max-width: 560px) {
  .backdrop { place-items: end center; padding: 0; }
  .modal { border-radius: 22px 22px 0 0; max-height: 92vh; }
  .safety-grid { font-size: 17px; padding: 14px; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

.compact .msg.grp-start { margin-top: 8px; }
.compact .bubble { padding: 6px 10px 5px; }
.compact .conv-item { padding: 7px 10px; }
