:root,
html[data-theme="forest"] {
  color-scheme: dark;
  /* палитра как у ГЗИ (forest / иконка #252525) */
  --bg: #252525;
  --card: #1a2128;
  --line: #33404c;
  --text: #eef3f7;
  --muted: #a3b0bb;
  --accent: #7dcea0;
  --accent-ink: #102117;
  --danger: #f2b2ab;
  --warn: #ebc888;
  --input: #0b1014;
  --chip: #141b21;
  --link: #9dc4de;
  --mine: #1e3a2e;
  --mine-border: color-mix(in srgb, var(--accent) 18%, var(--line));
  --theirs: #24352c;
  --fill-shade: color-mix(in srgb, var(--bg) 52%, black);
  --well-inset: color-mix(in srgb, black 16%, transparent);
  --radius: 16px;
  --radius-sm: 10px;
  /* --composer-pad-bottom: только shared/chat-ui.css (:root !important) */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --side-w: min(380px, 100%);
  --font: system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --fs: 18px;
  --fs-sm: max(15px, calc(var(--fs) - 2px));
  --fs-xs: max(14px, calc(var(--fs) - 3px));
  --fs-2xs: max(13px, calc(var(--fs) - 4px));
}

html[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #070b14; --card: #101827; --line: #243147; --text: #e8eef8; --muted: #8494ab;
  --accent: #5eead4; --accent-ink: #04201c; --danger: #f0a8a0; --warn: #e6c07b;
  --input: #050912; --chip: #0c1320; --link: #7dd3fc;
  --mine: #0d2f2a; --mine-border: color-mix(in srgb, var(--accent) 28%, var(--line)); --theirs: #0c1320;
}

html[data-theme="ember"] {
  color-scheme: dark;
  --bg: #10080a; --card: #1f1014; --line: #4a2430; --text: #f7e8e4; --muted: #b38990;
  --accent: #ff4d3a; --accent-ink: #2a0806; --danger: #ff8f9a; --warn: #f0c070;
  --input: #0c0507; --chip: #180c10; --link: #ff9a7a;
  --mine: #3a1412; --mine-border: color-mix(in srgb, var(--accent) 30%, var(--line)); --theirs: #180c10;
}

html[data-theme="moss"] {
  color-scheme: dark;
  --bg: #090b12; --card: #131722; --line: #2c3448; --text: #e9edf6; --muted: #8b93a8;
  --accent: #e2b44a; --accent-ink: #1f1606; --danger: #f0a0a8; --warn: #e6c07b;
  --input: #06080e; --chip: #0e121c; --link: #7eb6d9;
  --mine: #2a2410; --mine-border: color-mix(in srgb, var(--accent) 28%, var(--line)); --theirs: #0e121c;
}

html[data-theme="frost"] {
  color-scheme: light;
  --bg: #efe9e0; --card: #fffcf7; --line: #d5cbbd; --text: #2a2420; --muted: #7a6f64;
  --accent: #2f8f82; --accent-ink: #f3fffc; --danger: #c04545; --warn: #9a6d1f;
  --input: #f7f2ea; --chip: #f3ece3; --link: #2f6f8f;
  --mine: #d7ebe7; --mine-border: color-mix(in srgb, var(--accent) 35%, var(--line)); --theirs: #f3ece3;
  --fill-shade: color-mix(in srgb, var(--bg) 58%, #3a322c);
  --well-inset: color-mix(in srgb, #2a2420 10%, transparent);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: var(--fs);
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  cursor: default;
  /* НЕ ставим user-select:none на html/body/* — WebKit глушит caret во всех input */
}
body { overflow: hidden; overscroll-behavior: none; }
/* UI без выделения текста — точечно, не через * */
.brand, .brand-sub, .topbar, .chat-head, .conv, .bubble, .day, .empty,
.me-menu, .toolbar, .btn, .icon-btn, .theme-chip, .auth-label, .pill-main {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
input, textarea, select, [contenteditable="true"] {
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
  pointer-events: auto !important;
  touch-action: auto !important;
  cursor: text;
  color: var(--text);
  caret-color: var(--accent);
  position: relative;
  z-index: 5;
}
input[type="checkbox"],
input[type="radio"],
input[type="file"],
input[type="button"],
input[type="submit"],
input[type="reset"] {
  cursor: pointer;
  z-index: auto;
}
button, a, summary, .chat-media, .conv, .swipe-row, .icon-btn, .btn,
.me-btn, .theme-chip, .chat-head-info, [role="button"], [data-act], [data-conv],
[data-dm], [data-open], [data-theme], [data-back], [data-close], [data-close-dialog],
[data-logout] {
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
/* label НЕ в списке touch-action:manipulation — иначе iOS не фокусит input внутри */
label.auth-save {
  display: flex;
  pointer-events: auto;
  touch-action: auto;
  cursor: pointer;
  align-items: center;
  gap: 0.5rem;
}
button, input, textarea, select { font: inherit; }
button { border: 0; background: none; color: inherit; }
a { color: var(--link); text-decoration: none; }
img, svg { -webkit-user-drag: none; user-drag: none; }
:focus:not(:focus-visible) { outline: none; }
input:focus, textarea:focus, select:focus {
  outline: none;
}
:focus-visible:not(input):not(textarea):not(select) {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
[hidden] { display: none !important; }
.hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  border: 0 !important;
  pointer-events: none !important;
}
#app {
  /* fixed+inset: на iOS 100%/100dvh часто короче экрана → «дыра» под композером */
  position: fixed;
  inset: 0;
  width: auto;
  height: auto;
  overflow: hidden;
  pointer-events: auto;
}
#app, #app * { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 40%, transparent) transparent; }

/* —— auth —— */
.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b));
  background:
    radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 58%),
    var(--bg);
}
.auth-card {
  width: min(400px, 100%);
  padding: 1.25rem 1.2rem 1.3rem;
  border-radius: var(--radius);
  background:
    radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 58%),
    linear-gradient(165deg, color-mix(in srgb, var(--card) 78%, var(--chip)), var(--card));
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line));
}
.brand {
  margin: 0;
  font-size: clamp(1.7rem, 5vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.auth-save { display: flex; align-items: center; gap: 0.5rem; margin: 0 0 0.85rem; font-weight: 600; color: var(--muted); font-size: var(--fs-xs); }
.auth-switch {
  margin-top: 8px;
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
}
.brand-sub {
  margin: 0.35rem 0 1.2rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}
/* поля как в ГЗИ: .field — сам input/textarea */
.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  margin-bottom: 0.85rem;
  pointer-events: auto;
  touch-action: auto;
}
.auth-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--muted);
}
.field,
.search input,
.composer textarea,
.chat-search input,
.modal input,
.modal select {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--line) 75%, var(--muted) 25%);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--input);
  color: var(--text);
  caret-color: var(--accent);
  font-size: 16px; /* без iOS-zoom при фокусе */
  outline: none;
  box-shadow: none;
  transition: border-color 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}
.field::placeholder,
.search input::placeholder,
.composer textarea::placeholder,
.chat-search input::placeholder {
  color: var(--muted);
  opacity: 1;
}
.field:focus,
.search input:focus,
.composer textarea:focus,
.chat-search input:focus,
.modal input:focus,
.modal select:focus {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
  outline: none;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { width: 100%; background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost {
  background: var(--chip);
  color: var(--text);
  border-color: var(--line);
}
.btn-ghost:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.btn-danger { background: color-mix(in srgb, var(--danger) 18%, var(--chip)); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.error { color: var(--danger); margin: 0 0 0.75rem; font-size: 0.9rem; }

/* —— shell —— */
.shell {
  height: 100%;
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  background: var(--bg);
}
.sidebar, .chat {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.sidebar {
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 55%, var(--bg));
}
.chat {
  background: var(--bg);
  overflow: hidden;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.7rem + var(--safe-t)) 0.9rem 0.7rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 88%, var(--bg));
}
.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.topbar .me {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}
.topbar .me .meta { text-align: right; min-width: 0; }
.topbar .me .name {
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.topbar .me .sub {
  font-size: 0.72rem;
  color: var(--muted);
}
.me-wrap { position: relative; flex: none; }
.me-btn {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  border-radius: 14px;
}
.me-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}
.me-btn .avatar { pointer-events: none; }
.me-menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 30;
  width: min(260px, calc(100vw - 1.5rem));
  padding: 0.7rem;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line));
  background:
    radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 58%),
    var(--card);
  box-shadow: 0 12px 32px color-mix(in srgb, #000 35%, transparent);
}
.me-menu-head {
  padding: 0.15rem 0.2rem 0.55rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.55rem;
}
.me-menu-head .name {
  font-size: 0.92rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.me-menu-head .sub {
  margin-top: 0.1rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.me-menu-label {
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0.15rem 0.35rem;
}
.me-menu .theme-row { margin: 0; }
.me-menu-logout {
  width: 100%;
  margin-top: 0.7rem;
}

.toolbar {
  display: flex;
  gap: 0.4rem;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.toolbar .btn { flex: 1; min-height: 36px; font-size: 0.82rem; padding: 0.35rem 0.5rem; }

.search {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 3;
  pointer-events: auto;
}
.search input {
  padding: 8px 12px;
  border-radius: 12px;
  min-height: 36px;
  background: var(--chip);
  border-color: transparent;
}

.conv-list {
  flex: 1;
  overflow: auto;
  padding: 0.4rem 0.45rem 0.75rem;
  overscroll-behavior: contain;
}
.conv {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: center;
  text-align: left;
  padding: 0.65rem 0.7rem;
  margin-bottom: 2px;
  border-radius: 12px;
  border: 1px solid transparent;
  color: var(--text);
  background: transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.conv:hover { background: color-mix(in srgb, var(--card) 70%, transparent); }
.conv.active {
  background: var(--card);
  border-color: color-mix(in srgb, var(--accent) 28%, var(--line));
}
.conv .body { min-width: 0; }
.conv .title {
  font-weight: 650;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  overflow: hidden;
}
.conv .title-text { overflow: hidden; text-overflow: ellipsis; }
.conv .preview {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv .meta-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  align-self: start;
  padding-top: 0.1rem;
}
.conv .time { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.7rem;
  font-weight: 700;
}
.pill-main {
  flex: none;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--line));
}

.avatar {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.92rem;
  color: #102117;
  flex: none;
  user-select: none;
}
.avatar.sm { width: 28px; height: 28px; font-size: 0.7rem; border-radius: 9px; }
.avatar .dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #3d4a55;
  border: 2px solid var(--card);
}
.avatar.online .dot { background: var(--accent); }

/* —— chat —— */
.chat-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: calc(0.55rem + var(--safe-t)) 0.85rem 0.55rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 88%, var(--bg));
  min-height: 56px;
}
.chat-head .back,
.chat-head .chat-back {
  display: none;
  flex: none;
}
.chat-head .title {
  font-weight: 700;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head .sub {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head .sub.live { color: var(--accent); }

.chat-search {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: relative;
  z-index: 3;
  pointer-events: auto;
}
.chat-search input {
  flex: 1;
  border-radius: 12px;
  padding: 8px 12px;
  min-height: 36px;
  min-width: 0;
  background: var(--chip);
  border-color: transparent;
}

.messages {
  overflow-anchor: none;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  padding: 0.85rem 0.9rem 0.5rem;
  background: var(--bg);
  position: relative;
  z-index: 0;
  /* mask на iOS иногда ломает hit-test соседних полей — без mask */
}
.chat-flow {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  width: 100%;
  flex: 0 0 auto;
}
.day {
  align-self: center;
  margin: 8px 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: 600;
  border: 1px solid var(--line);
}

/* gzi-like swipe rows */
.swipe-row {
  position: relative;
  display: block;
  width: 100%;
  flex: none;
  touch-action: pan-y;
}
.swipe-row.mine { text-align: right; }
.swipe-row.theirs { text-align: left; }
.swipe-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  color: var(--accent);
  pointer-events: none;
  display: grid;
  place-items: center;
  transition: opacity 0.12s ease;
}
.swipe-row.mine .swipe-arrow { left: 2px; }
.swipe-row.theirs .swipe-arrow { right: 2px; transform: translateY(-50%) scaleX(-1); }

.bubble {
  display: inline-block;
  vertical-align: top;
  text-align: left;
  position: relative;
  padding: 7px 11px 5px;
  border-radius: 16px;
  background: var(--theirs);
  border: 1px solid color-mix(in srgb, var(--accent) 14%, var(--line));
  max-width: min(75%, 640px);
  color: var(--text);
  line-height: 1.25;
  box-shadow: none;
}
.swipe-row.mine .bubble {
  background: var(--mine);
  border-color: var(--mine-border);
  border-bottom-right-radius: 4px;
}
.swipe-row.theirs .bubble {
  border-bottom-left-radius: 4px;
}
.bubble.pending { opacity: 0.72; }
.bubble.failed { outline: 1px solid color-mix(in srgb, var(--danger) 55%, transparent); }
.bubble .author {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}
.online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #00e676;
  flex: none;
}
.bubble .text {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  line-height: 1.25;
  font-size: var(--fs-sm);
}
.bubble .text a { color: inherit; font-weight: 700; text-decoration: underline; }
.bubble .time {
  margin-top: 2px;
  color: color-mix(in srgb, var(--text) 82%, var(--muted));
  font-size: var(--fs-2xs);
  text-align: right;
  opacity: 0.78;
  align-self: flex-end;
}
.quote {
  margin: 0 0 0.4rem;
  padding: 0.3rem 0.5rem;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: 0 8px 8px 0;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--muted);
}
.quote b {
  color: var(--accent);
  display: block;
  font-size: 0.72rem;
  font-style: normal;
}
.quote-body {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}
.bubble .preview,
.bubble .chat-image {
  display: block;
  max-width: min(280px, 70vw);
  max-height: min(360px, 50vh);
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center top;
  border-radius: 10px;
  background: var(--well-inset);
}
.chat-media {
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  line-height: 0;
  max-width: 100%;
  overflow: hidden;
  border-radius: 12px;
}
.bubble.has-media { padding: 0; overflow: hidden; width: fit-content; max-width: min(340px, 86%); }
.bubble.has-media:has(.album) { width: min(340px, 86%); max-width: min(340px, 86%); }
.bubble.has-media .author { margin: 0; padding: 0.45rem 0.65rem 0.25rem; }
.bubble.has-media .quote { margin: 0.35rem 0.5rem; }
.bubble.has-media .media-wrap {
  position: relative;
  display: block;
  width: fit-content;
  max-width: 100%;
  max-height: min(420px, 55vh);
  line-height: 0;
  overflow: hidden;
  background: transparent;
}
.bubble.has-media:has(.album) .media-wrap { width: 100%; max-height: none; }
.bubble.has-media .chat-media { margin: 0; border-radius: 0; max-width: 100%; }
/* было max-height:none — длинные скрины (Ozon и т.п.) заливали весь экран и ломали скролл/фокус */
.bubble.has-media .preview,
.bubble.has-media .chat-image {
  margin: 0;
  border-radius: 0;
  width: auto;
  max-width: min(340px, 86vw);
  max-height: min(420px, 55vh);
  height: auto;
  object-fit: contain;
  object-position: center top;
  background: transparent;
}
.bubble.has-media .media-wrap > .time {
  position: absolute;
  right: 8px;
  bottom: 6px;
  z-index: 2;
  margin: 0;
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  pointer-events: none;
}
.bubble.has-caption .msg-caption {
  padding: 0.4rem 0.65rem 0;
  white-space: pre-wrap;
  line-height: 1.3;
}
.bubble.has-caption > .time { display: block; width: fit-content; margin: 0.15rem 0.5rem 0.35rem auto; }
.bubble.media-only:not(:has(.author)):not(:has(.quote)) .media-wrap { border-radius: 16px; }
.bubble.media-only.mine:not(:has(.author)):not(:has(.quote)) .media-wrap { border-bottom-right-radius: 4px; }
.bubble.media-only.theirs:not(:has(.author)):not(:has(.quote)) .media-wrap { border-bottom-left-radius: 4px; }
.bubble.has-media .album { width: 100%; margin: 0; border-radius: 0; }
.bubble.has-media .album .chat-media,
.bubble.has-media .album .chat-image { border-radius: 0 !important; }

.album {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  overflow: hidden;
  background: color-mix(in srgb, var(--bg) 100%, #000);
}
.album .chat-media {
  position: relative;
  margin: 0;
  aspect-ratio: 1;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.album .chat-image {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: cover !important;
  object-position: center;
  border-radius: 0 !important;
}
.album.count-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
  aspect-ratio: 2 / 1;
}
.album.count-2 .chat-media { aspect-ratio: auto; height: 100%; }
.album.count-3,
.album.count-4,
.album.count-5,
.album.count-6,
.album.count-7,
.album.count-8,
.album.count-9,
.album.count-10 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.album.count-3 .chat-media,
.album.count-4 .chat-media,
.album.count-5 .chat-media,
.album.count-6 .chat-media,
.album.count-7 .chat-media,
.album.count-8 .chat-media,
.album.count-9 .chat-media,
.album.count-10 .chat-media { aspect-ratio: auto; height: 100%; min-height: 0; }
.album.count-3 { grid-template-rows: repeat(2, minmax(0, 1fr)); aspect-ratio: 3 / 2; }
.album.count-4,
.album.count-5,
.album.count-6 { grid-template-rows: repeat(3, minmax(0, 1fr)); aspect-ratio: 1 / 1; }
.album.count-7,
.album.count-8,
.album.count-9 { grid-template-rows: repeat(4, minmax(0, 1fr)); aspect-ratio: 3 / 4; }
.album.count-10 { grid-template-rows: repeat(5, minmax(0, 1fr)); aspect-ratio: 3 / 5; }
.album.count-3 .chat-media:nth-child(1),
.album.count-4 .chat-media:nth-child(1),
.album.count-5 .chat-media:nth-child(1),
.album.count-6 .chat-media:nth-child(1),
.album.count-7 .chat-media:nth-child(1),
.album.count-8 .chat-media:nth-child(1),
.album.count-9 .chat-media:nth-child(1),
.album.count-10 .chat-media:nth-child(1) { grid-area: 1 / 1 / 3 / 3; }
.album.count-3 .chat-media:nth-child(2),
.album.count-4 .chat-media:nth-child(2),
.album.count-5 .chat-media:nth-child(2),
.album.count-6 .chat-media:nth-child(2),
.album.count-7 .chat-media:nth-child(2),
.album.count-8 .chat-media:nth-child(2),
.album.count-9 .chat-media:nth-child(2),
.album.count-10 .chat-media:nth-child(2) { grid-area: 1 / 3 / 2 / 4; }
.album.count-3 .chat-media:nth-child(3),
.album.count-4 .chat-media:nth-child(3),
.album.count-5 .chat-media:nth-child(3),
.album.count-6 .chat-media:nth-child(3),
.album.count-7 .chat-media:nth-child(3),
.album.count-8 .chat-media:nth-child(3),
.album.count-9 .chat-media:nth-child(3),
.album.count-10 .chat-media:nth-child(3) { grid-area: 2 / 3 / 3 / 4; }
.album.count-4 .chat-media:nth-child(4),
.album.count-5 .chat-media:nth-child(4),
.album.count-6 .chat-media:nth-child(4),
.album.count-7 .chat-media:nth-child(4),
.album.count-8 .chat-media:nth-child(4),
.album.count-9 .chat-media:nth-child(4),
.album.count-10 .chat-media:nth-child(4) { grid-area: 3 / 1 / 4 / 2; }
.album.count-5 .chat-media:nth-child(5),
.album.count-6 .chat-media:nth-child(5),
.album.count-7 .chat-media:nth-child(5),
.album.count-8 .chat-media:nth-child(5),
.album.count-9 .chat-media:nth-child(5),
.album.count-10 .chat-media:nth-child(5) { grid-area: 3 / 2 / 4 / 3; }
.album.count-6 .chat-media:nth-child(6),
.album.count-7 .chat-media:nth-child(6),
.album.count-8 .chat-media:nth-child(6),
.album.count-9 .chat-media:nth-child(6),
.album.count-10 .chat-media:nth-child(6) { grid-area: 3 / 3 / 4 / 4; }
.album.count-7 .chat-media:nth-child(7),
.album.count-8 .chat-media:nth-child(7),
.album.count-9 .chat-media:nth-child(7),
.album.count-10 .chat-media:nth-child(7) { grid-area: 4 / 1 / 5 / 2; }
.album.count-8 .chat-media:nth-child(8),
.album.count-9 .chat-media:nth-child(8),
.album.count-10 .chat-media:nth-child(8) { grid-area: 4 / 2 / 5 / 3; }
.album.count-9 .chat-media:nth-child(9),
.album.count-10 .chat-media:nth-child(9) { grid-area: 4 / 3 / 5 / 4; }
.album.count-10 .chat-media:nth-child(10) { grid-area: 5 / 1 / 6 / 2; }
.bubble .file {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.3rem;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  background: color-mix(in srgb, var(--chip) 80%, transparent);
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--text);
  font-weight: 650;
  font-size: 0.85rem;
}

.typing-line {
  font-style: italic;
  color: var(--accent);
  padding: 0 12px;
  font-size: var(--fs-xs);
  font-weight: 600;
  min-height: 0;
}
.typing-line:empty { display: none; }

.reply-bar {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 4px 12px;
  background: var(--chip);
  border-top: 0;
  color: var(--muted);
  font-size: var(--fs-xs);
}
.reply-bar .grow { flex: 1; min-width: 0; }
.reply-bar .label {
  display: block;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.72rem;
}
.reply-bar b { color: var(--text); font-size: 0.82rem; }
.reply-bar .quote-body {
  color: var(--muted);
  font-size: 0.8rem;
}

.composer {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  flex-shrink: 0;
  position: relative;
  z-index: 6;
  padding: 4px 8px var(--composer-pad-bottom);
  border-top: 0;
  background: var(--bg);
  pointer-events: auto;
  isolation: isolate;
}
.composer.placeholder {
  justify-content: center;
  color: var(--muted);
  font-size: var(--fs-xs);
  padding: 8px 8px var(--composer-pad-bottom);
}
.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 120px;
  height: 44px;
  resize: none;
  border-radius: 12px;
  padding: 9px 14px;
  line-height: 24px;
  border: 1px solid color-mix(in srgb, var(--line) 75%, var(--muted) 25%);
  background: var(--input);
  color: var(--text);
  font-size: 16px;
  caret-color: var(--accent);
  outline: none;
  box-shadow: none;
}
.composer textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: none;
  outline: none;
}
.icon-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  flex: 0 0 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--chip);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 1.1rem;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.icon-btn.ghost {
  background: transparent;
  border-color: transparent;
  width: 36px;
  height: 36px;
  min-width: 36px;
}
.icon-btn:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.icon-btn.send {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: color-mix(in srgb, var(--accent) 65%, #000 35%);
}
.icon-btn.send:hover { filter: brightness(1.06); }

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 45;
  backdrop-filter: blur(2px);
}
.dialog {
  width: min(360px, 100%);
  background:
    radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 58%),
    var(--card);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--line));
  border-radius: var(--radius);
  padding: 1rem;
}
.dialog h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }
.dialog-stack { display: grid; gap: 0.5rem; }
.dialog-stack .btn { width: 100%; }
.field-area {
  resize: vertical;
  min-height: 96px;
  line-height: 1.35;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 1.5rem;
  line-height: 1.45;
  max-width: 280px;
}
.empty strong {
  display: block;
  color: var(--text);
  margin-bottom: 0.35rem;
  font-size: 1.05rem;
}
.empty-chat {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 2rem;
  text-align: center;
}
.empty-chat strong { display: block; color: var(--text); font-size: 1.1rem; margin-bottom: 0.4rem; }

/* —— modal —— */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: end center;
  padding: 0.75rem;
  z-index: 40;
  backdrop-filter: blur(2px);
}
.modal {
  width: min(480px, 100%);
  background:
    radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 58%),
    var(--card);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--line));
  border-radius: 16px 16px 12px 12px;
  padding: 1.05rem 1.05rem 1.1rem;
  max-height: min(82vh, 640px);
  overflow: auto;
}
.modal h2 { margin: 0 0 0.85rem; font-size: 1.1rem; letter-spacing: -0.01em; }
.modal .actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.9rem;
}
.modal .actions .btn-primary { width: auto; }
.user-pick { display: grid; gap: 0.25rem; max-height: 42vh; overflow: auto; }
.user-pick .conv { margin: 0; }
.user-pick label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.55rem;
  border-radius: 10px;
  color: var(--text);
}
.user-pick label:hover { background: var(--chip); }
.theme-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.35rem;
}
.theme-chip {
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
}
.theme-chip.on {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--chip));
}

/* media viewer styles → css/chat-media.css (shared) */

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .shell.show-chat .sidebar { display: none; }
  .shell:not(.show-chat) .chat { display: none; }
  .chat-head .back,
  .chat-head .chat-back { display: grid; place-items: center; }
  .topbar .me .meta { display: none; }
  .bubble { max-width: 92%; }
  .modal-backdrop { place-items: end stretch; padding: 0; }
  .modal {
    width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: min(88vh, 720px);
    padding-bottom: calc(1rem + var(--safe-b));
  }
}

@media (min-width: 861px) {
  .modal-backdrop { place-items: center; }
  .modal { border-radius: var(--radius); }
}

.chat-head-info {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  flex: 1;
  margin: 0;
  padding: 0.15rem 0.35rem 0.15rem 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 12px;
}
.chat-head-info:active { opacity: 0.92; }
.icon-btn:active { transform: none; }
.btn:active { filter: none; }
.chat-head-meta { min-width: 0; flex: 1; }
.chat-head-meta .title {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head-meta .sub {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head-meta .sub.live { color: var(--accent); }

.chat-info-dialog {
  width: min(420px, 100%);
  max-height: min(88vh, 720px);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-bottom: calc(1rem + var(--safe-b, 0px));
}
.chat-info-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.chat-info-head h2 { margin: 0; font-size: 1.1rem; }
.chat-info-sub { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }
.chat-info-desc {
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  background: color-mix(in srgb, var(--on-surface, var(--text)) 6%, transparent);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  line-height: 1.4;
  font-size: 0.92rem;
}
.chat-info-desc.muted { color: var(--muted); }
.chat-info-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chat-info-members {
  display: grid;
  gap: 0.35rem;
  overflow: auto;
  max-height: min(48vh, 420px);
  margin: 0 -0.15rem;
  padding: 0 0.15rem;
}
.chat-info-member {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.4rem 0.35rem;
  border-radius: 12px;
}
.chat-info-member .body { min-width: 0; }
.chat-info-member .name {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-info-member .status {
  font-size: 0.75rem;
  color: var(--muted);
}
.chat-info-member .status.on { color: var(--accent); }
