:root {
  color-scheme: light;
  --background: #ffffff;
  --surface: #ffffff;
  --surface-subtle: #f3f5f5;
  --chat-background: #fafbfb;
  --text: #121819;
  --muted: #667174;
  --divider: #e4e8e8;
  --accent: #236b63;
  --accent-soft: #e3ecea;
  --outgoing: #dce9e6;
  --incoming: #ffffff;
  --system: #e9ecec;
  --danger: #b34242;
  --shell-outside: #eef1f1;
  --overlay: rgb(12 19 20 / 44%);
  --app-bar: 54px;
  --bottom-nav: 60px;
  --chat-row: 72px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="light"] { color-scheme: light; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #141718;
  --surface: #181c1e;
  --surface-subtle: #222729;
  --chat-background: #15191a;
  --text: #f2f4f4;
  --muted: #9da7aa;
  --divider: #2d3436;
  --accent: #6aa79f;
  --accent-soft: #263b38;
  --outgoing: #28423e;
  --incoming: #202527;
  --system: #262c2e;
  --danger: #e17b7b;
  --shell-outside: #0e1112;
  --overlay: rgb(0 0 0 / 62%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --background: #141718;
    --surface: #181c1e;
    --surface-subtle: #222729;
    --chat-background: #15191a;
    --text: #f2f4f4;
    --muted: #9da7aa;
    --divider: #2d3436;
    --accent: #6aa79f;
    --accent-soft: #263b38;
    --outgoing: #28423e;
    --incoming: #202527;
    --system: #262c2e;
    --danger: #e17b7b;
    --shell-outside: #0e1112;
    --overlay: rgb(0 0 0 / 62%);
  }
}

* { box-sizing: border-box; }

html,
body { min-height: 100%; }

body {
  margin: 0;
  background: var(--shell-outside);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea { font: inherit; }

button { color: inherit; }

button,
[role="button"] { -webkit-tap-highlight-color: transparent; }

button:active:not(:disabled) { background-color: var(--accent-soft); }

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon,
.large-icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.large-icon { width: 32px; height: 32px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.auth-view,
.app-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
}

.auth-shell {
  width: min(100%, 420px);
  min-height: min(100dvh, 680px);
  background: var(--surface);
  border-inline: 1px solid var(--divider);
}

.auth-app-bar {
  height: var(--app-bar);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--divider);
}

.auth-app-bar h1,
.section-bar h1 {
  margin: 0;
  font-size: 23px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: -0.25px;
}

.auth-content { padding: 24px 20px; }

.auth-content h2 {
  margin: 0 0 6px;
  font-size: 21px;
  line-height: 1.2;
  font-weight: 650;
}

.auth-lead,
.code-caption {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.auth-form { display: grid; gap: 14px; }

.auth-form h2 { margin-top: 2px; }

.field,
.field-row { display: grid; gap: 6px; }

.field-row { grid-template-columns: 1fr 1fr; gap: 10px; }

.field label {
  font-size: 13px;
  font-weight: 600;
}

.field input,
.dialog-search input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 11px;
  font-size: 16px;
}

.field input:focus,
.dialog-search input:focus { border-color: var(--accent); }

.field-hint,
.field small { color: var(--muted); font-size: 12px; }

.code-input { max-width: 180px; letter-spacing: 5px; }

.primary-button,
.text-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 650;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
  padding: 0 16px;
}

.primary-button:disabled { opacity: 0.48; cursor: default; }

.text-button {
  background: transparent;
  color: var(--accent);
  padding: 0;
}

.back-to-phone {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
}

.back-to-phone .icon { width: 19px; height: 19px; }

.form-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.privacy-note {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--divider);
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.privacy-note .icon { width: 16px; height: 16px; }

.app-view { padding: 0 18px; }

.app-shell {
  width: min(100%, 1180px);
  height: min(100dvh, 900px);
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  background: var(--surface);
  border-inline: 1px solid var(--divider);
  overflow: hidden;
}

.sidebar {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: var(--app-bar) auto minmax(0, 1fr) var(--bottom-nav);
  background: var(--surface);
  border-right: 1px solid var(--divider);
}

.sidebar-header {
  position: relative;
  z-index: 2;
  height: var(--app-bar);
  border-bottom: 1px solid var(--divider);
  background: var(--surface);
}

.sidebar-header { grid-row: 1; }
.sidebar-offline { grid-row: 2; }
.sidebar-panel { grid-row: 3; }
.bottom-navigation { grid-row: 4; }

.section-bar,
.search-mode {
  height: 100%;
  display: flex;
  align-items: center;
}

.section-bar { justify-content: space-between; padding: 0 8px 0 16px; }

.header-actions { display: flex; align-items: center; }

.icon-button,
.send-button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 7px;
  display: inline-grid;
  place-items: center;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover,
.send-button:hover:not(:disabled) { background: var(--surface-subtle); }

.danger-icon-button { color: var(--danger); }
.danger-icon-button:disabled { color: var(--muted); cursor: default; opacity: 0.55; }

.search-mode { padding: 0 8px 0 4px; }

.search-mode input {
  min-width: 0;
  flex: 1;
  height: 40px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  outline: 0;
}

.search-mode input::-webkit-search-cancel-button { display: none; }

.sidebar-offline,
.offline-banner {
  min-height: 25px;
  padding: 4px 12px;
  background: var(--system);
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.offline-banner.reconnecting,
.sidebar-offline:not([hidden]) { color: var(--text); }

.sidebar-panel {
  min-height: 0;
  overflow-y: auto;
  background: var(--surface);
}

.chats-panel { position: relative; }

.chat-list { min-height: 100%; }

.chat-row {
  width: 100%;
  height: var(--chat-row);
  padding: 0 12px;
  border: 0;
  border-bottom: 1px solid var(--divider);
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.chat-row:hover,
.chat-row[aria-current="true"] { background: var(--surface-subtle); }

.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  background: var(--avatar-bg-light, var(--accent-soft));
  color: var(--avatar-fg-light, var(--accent));
  font-size: 15px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.avatar.group { background: var(--surface-subtle); color: var(--muted); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-small { width: 42px; height: 42px; font-size: 14px; }
.avatar-compact { width: 36px; height: 36px; font-size: 12px; }

.group-collage {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--divider);
}

.group-collage.count-2 .avatar-cell:first-child,
.group-collage.count-3 .avatar-cell:first-child { grid-row: 1 / 3; }
.group-collage.count-4 { grid-template-rows: 1fr 1fr; }

.avatar-cell {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--avatar-bg-light);
  color: var(--avatar-fg-light);
  font-size: 9px;
  font-weight: 700;
}

:root[data-theme="dark"] .avatar,
:root[data-theme="dark"] .avatar-cell {
  background: var(--avatar-bg-dark, var(--accent-soft));
  color: var(--avatar-fg-dark, var(--accent));
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .avatar,
  :root:not([data-theme]) .avatar-cell {
    background: var(--avatar-bg-dark, var(--accent-soft));
    color: var(--avatar-fg-dark, var(--accent));
  }
}

.chat-copy { min-width: 0; display: grid; gap: 4px; }
.chat-topline,
.chat-preview-line { min-width: 0; display: flex; align-items: center; gap: 7px; }

.chat-title {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16.5px;
  line-height: 1.15;
  font-weight: 650;
}

.chat-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.chat-preview {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.2;
}

.chat-preview.system { color: var(--muted); font-style: italic; }

.unread-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  display: inline-grid;
  place-items: center;
  background: var(--accent);
  color: #ffffff;
  font-size: 11px;
  line-height: 1;
  font-weight: 700;
}

.sidebar-empty,
.conversation-empty,
.messages-empty,
.messages-loading {
  color: var(--muted);
  text-align: center;
}

.sidebar-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 40px 20px;
}
.sidebar-empty p { margin: 0 0 6px; }

.bottom-navigation {
  position: relative;
  z-index: 3;
  height: var(--bottom-nav);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--divider);
  background: var(--surface);
}

.bottom-navigation button {
  min-width: 0;
  border: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.bottom-navigation button:hover { background: var(--surface-subtle); }
.bottom-navigation button.selected { color: var(--accent); }
.bottom-navigation .icon { width: 21px; height: 21px; }
.bottom-navigation span { font-size: 11px; line-height: 1.1; font-weight: 600; }

.menu-row,
.profile-row,
.settings-row {
  width: 100%;
  min-height: 60px;
  padding: 0 14px;
  border: 0;
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

button.menu-row { cursor: pointer; }
button.menu-row:hover { background: var(--surface-subtle); }
.menu-row strong,
.profile-row strong { display: block; font-size: 15px; font-weight: 650; }
.menu-row small,
.profile-row small { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; }

.menu-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.menu-icon .icon { width: 21px; height: 21px; }
.panel-note { margin: 14px; color: var(--muted); font-size: 12.5px; }
.profile-row { min-height: 68px; }
.settings-row { min-height: 52px; }

.settings-profile-form {
  padding: 12px 14px 14px;
  border-bottom: 1px solid var(--divider);
  display: grid;
  gap: 10px;
}

.settings-profile-error {
  min-height: 0;
  margin: 0;
}

.settings-save-button {
  min-height: 42px;
}

.theme-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 10px 14px 14px 58px;
  border-bottom: 1px solid var(--divider);
}

.theme-options button {
  min-height: 34px;
  padding: 0 6px;
  border: 1px solid var(--divider);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.theme-options button.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.notification-row.enabled .menu-icon { color: var(--accent); }
.notification-row.enabled small { color: var(--accent); }
.notification-row[disabled] { cursor: default; opacity: .62; }

.logout-row { margin-top: 8px; color: var(--danger); }
.logout-row .menu-icon { color: var(--danger); }

.conversation {
  min-width: 0;
  min-height: 0;
  position: relative;
  background: var(--surface);
}

.conversation-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 24px;
}

.conversation-empty h2 { margin: 10px 0 2px; color: var(--text); font-size: 18px; }
.conversation-empty p { margin: 0; font-size: 13px; }

.chat-view {
  height: 100%;
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-rows: var(--app-bar) auto minmax(0, 1fr) auto;
}

.chat-header {
  min-width: 0;
  height: var(--app-bar);
  padding: 0 8px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--divider);
  background: var(--surface);
}

.chat-header { grid-row: 1; }
.offline-banner { grid-row: 2; }
.message-list { grid-row: 3; }
.composer { grid-row: 4; }

.back-button { display: none; }
.chat-heading { min-width: 0; flex: 1; }
.call-header-actions { display: flex; align-items: center; }

.chat-heading h2 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16.5px;
  line-height: 1.2;
  font-weight: 650;
}

.chat-heading span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.message-list {
  min-height: 0;
  overflow-y: auto;
  padding: 0;
  background: var(--surface);
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.message-flow {
  width: min(100%, 760px);
  min-height: 100%;
  margin: 0 auto;
  padding: 14px clamp(14px, 3vw, 34px) 18px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: var(--chat-background);
  border-inline: 1px solid var(--divider);
}

.day-separator {
  width: max-content;
  margin: 8px auto 11px;
  padding: 3px 8px;
  border-radius: 7px;
  background: var(--system);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.2;
}

.message-row { width: 100%; display: flex; margin: 2px 0; }
.message-row.mine { justify-content: flex-end; }

.message-bubble {
  max-width: min(72%, 520px);
  padding: 7px 9px 5px;
  border: 1px solid var(--divider);
  border-radius: 11px 11px 11px 3px;
  background: var(--incoming);
  overflow-wrap: anywhere;
}

.message-row.mine .message-bubble {
  border-color: transparent;
  border-radius: 12px 12px 4px 12px;
  background: var(--outgoing);
}

.message-bubble.failed { border-color: var(--danger); }
.message-bubble:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.message-text { white-space: pre-wrap; font-size: 15px; line-height: 1.3; }
.message-text.deleted { color: var(--muted); font-style: italic; }

.file-attachment {
  min-width: min(260px, 64vw);
  max-width: 360px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 8px;
}

.file-mark {
  width: 38px;
  height: 38px;
  border: 1px solid var(--divider);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--surface);
}

.file-mark .icon { width: 20px; height: 20px; }
.file-copy { min-width: 0; }
.file-copy strong,
.file-copy small { display: block; }
.file-copy strong {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-copy small { margin-top: 2px; color: var(--muted); font-size: 11.5px; }

.attachment-download,
.voice-play {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.attachment-download:hover,
.voice-play:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.attachment-download:focus-visible,
.voice-play:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.attachment-download:disabled,
.voice-play:disabled { opacity: 0.5; }
.attachment-download .icon,
.voice-play .icon { width: 20px; height: 20px; }

.voice-attachment {
  min-width: min(220px, 62vw);
  display: flex;
  align-items: center;
  gap: 7px;
}

.voice-copy { min-width: 0; flex: 1; }
.voice-copy strong { display: block; font-size: 14px; font-weight: 650; }
.voice-copy span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.message-meta {
  margin-top: 3px;
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 5px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1;
}

.delivery-indicator {
  min-width: 11px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: -2px;
}

.delivery-indicator.read { color: var(--accent); }
.delivery-indicator.failed { color: var(--danger); letter-spacing: 0; }
.delivery-indicator.pending { letter-spacing: 0; }

.retry-message {
  min-width: 44px;
  min-height: 44px;
  margin: 1px -5px -5px auto;
  padding: 0 5px;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.messages-state {
  width: min(100%, 360px);
  margin: auto;
  padding: 40px 20px;
  color: var(--muted);
  text-align: center;
}

.messages-state strong { display: block; color: var(--text); font-size: 15px; }
.messages-state p { margin: 5px 0 8px; font-size: 13px; }
.messages-state .text-button { min-height: 44px; padding-inline: 10px; }

.unread-separator {
  width: 100%;
  margin: 10px 0 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 650;
}

.unread-separator::before,
.unread-separator::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--accent);
  opacity: 0.45;
}

.typing-indicator {
  min-width: 48px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--divider);
  border-radius: 11px 11px 11px 3px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--incoming);
}

.typing-indicator span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-pulse 1.1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 120ms; }
.typing-indicator span:nth-child(3) { animation-delay: 240ms; }

@keyframes typing-pulse {
  0%, 70%, 100% { opacity: 0.35; translate: 0 0; }
  35% { opacity: 1; translate: 0 -2px; }
}

.scroll-bottom-button {
  position: absolute;
  z-index: 3;
  right: 16px;
  bottom: 66px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--divider);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.composer {
  min-height: 54px;
  padding: 5px 8px 5px 12px;
  display: flex;
  align-items: flex-end;
  gap: 5px;
  border-top: 1px solid var(--divider);
  background: var(--surface);
}

.composer textarea {
  min-width: 0;
  flex: 1;
  height: 44px;
  min-height: 44px;
  max-height: 124px;
  padding: 10px;
  resize: none;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 16px;
  line-height: 1.3;
}

.composer textarea:focus { border-color: var(--accent); }
.composer-action { flex: 0 0 44px; color: var(--muted); }
.composer-action:hover { color: var(--accent); }
.composer-action:disabled { opacity: 0.4; cursor: default; }
.voice-button { color: var(--accent); }
.send-button { color: var(--accent); }
.send-button:disabled { color: var(--muted); opacity: 0.55; cursor: default; }

.recording-panel {
  min-width: 0;
  min-height: 44px;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.recording-panel[hidden] { display: none; }
.recording-panel time {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}
.recording-panel button {
  min-width: 58px;
  min-height: 44px;
  margin-left: auto;
  padding: 0 5px;
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}
.recording-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: recording-pulse 1.2s infinite;
}

.composer.recording #attach-button,
.composer.recording #message-input,
.composer.recording #send-button { display: none; }
.composer.recording .voice-button { color: var(--danger); }

@keyframes recording-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.message-menu {
  position: fixed;
  z-index: 40;
  width: 190px;
  padding: 4px;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: var(--surface);
}

.message-menu button {
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  display: block;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.message-menu button:hover,
.message-menu button:focus-visible { background: var(--surface-subtle); }
.message-menu button.danger { color: var(--danger); }

.new-chat-dialog {
  width: min(calc(100% - 28px), 480px);
  max-height: min(720px, calc(100dvh - 28px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--divider);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.new-chat-dialog::backdrop { background: var(--overlay); }

.dialog-header {
  height: var(--app-bar);
  padding: 0 6px 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--divider);
}

.dialog-header h2 { margin: 0; font-size: 18px; font-weight: 650; }

.segmented {
  margin: 12px 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--divider);
  border-radius: 7px;
  overflow: hidden;
}

.segmented button {
  min-height: 36px;
  border: 0;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.segmented button + button { border-left: 1px solid var(--divider); }
.segmented button.selected { background: var(--accent-soft); color: var(--accent); font-weight: 650; }

.group-fields { padding: 0 14px; }

.selected-users {
  min-height: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.user-chip {
  min-height: 28px;
  padding: 0 7px 0 9px;
  border: 1px solid var(--divider);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-subtle);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}

.user-chip .icon { width: 14px; height: 14px; }

.dialog-search {
  height: 48px;
  margin: 8px 14px 0;
  display: flex;
  align-items: center;
  gap: 7px;
}

.dialog-search > .icon { width: 19px; height: 19px; color: var(--muted); }
.dialog-search input { height: 38px; }
.dialog-hint { min-height: 18px; margin: 2px 14px 6px; color: var(--muted); font-size: 12px; }

.user-results { max-height: 300px; overflow-y: auto; border-top: 1px solid var(--divider); }

.user-result {
  width: 100%;
  min-height: 60px;
  padding: 0 14px;
  border: 0;
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.user-result:hover,
.user-result.selected { background: var(--surface-subtle); }
.user-result-copy { min-width: 0; flex: 1; }
.user-result-copy strong { display: block; font-size: 15px; }
.user-result-copy span { display: block; color: var(--muted); font-size: 12.5px; }

.selection-mark {
  width: 22px;
  height: 22px;
  border: 1px solid var(--divider);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: transparent;
}

.user-result.selected .selection-mark { border-color: var(--accent); background: var(--accent); color: #ffffff; }
.selection-mark .icon { width: 14px; height: 14px; }
.create-group-button { width: calc(100% - 28px); margin: 12px 14px 14px; }

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 18px;
  translate: -50% 0;
  max-width: min(380px, calc(100% - 28px));
  padding: 9px 12px;
  border: 1px solid var(--divider);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.call-layer {
  position: fixed;
  z-index: 60;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: var(--overlay);
}

.call-shell {
  width: min(100%, 420px);
  min-height: min(680px, calc(100dvh - 36px));
  padding: 20px 18px 22px;
  display: grid;
  grid-template-rows: minmax(230px, 1fr) auto auto auto;
  gap: 18px;
  border: 1px solid var(--divider);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}

.call-media {
  min-height: 230px;
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  border: 1px solid var(--divider);
  border-radius: 10px;
  background: var(--chat-background);
}

.call-media > #remote-video {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  object-fit: cover;
  background: var(--chat-background);
}

.call-media:not(.has-remote-video) > #remote-video { visibility: hidden; }
.call-avatar { width: 82px; height: 82px; font-size: 24px; }

.local-video {
  width: 108px;
  aspect-ratio: 3 / 4;
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  border: 1px solid rgb(255 255 255 / 40%);
  border-radius: 8px;
  object-fit: cover;
  background: #111;
}

.call-shell.audio-call .call-media {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.call-shell.audio-call .call-media > #remote-video,
.call-shell.audio-call .local-video,
.call-shell.audio-call .video-control { display: none; }

.call-copy { text-align: center; }
.call-copy h2 { margin: 0; font-size: 22px; font-weight: 650; }
.call-copy p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.call-copy time { display: block; margin-top: 5px; color: var(--text); font-variant-numeric: tabular-nums; font-size: 13px; }

.call-controls {
  min-height: 72px;
  display: flex;
  justify-content: center;
  align-items: start;
  gap: clamp(8px, 3vw, 14px);
}

.call-control {
  width: 58px;
  min-height: 66px;
  padding: 0;
  border: 0;
  display: grid;
  place-items: center;
  align-content: start;
  gap: 5px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 11px;
}

.call-control .icon {
  width: 48px;
  height: 48px;
  padding: 12px;
  border: 1px solid var(--divider);
  border-radius: 50%;
  background: var(--surface-subtle);
}

.call-control[aria-pressed="true"] .icon { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.call-control.decline .icon { border-color: var(--danger); background: var(--danger); color: #fff; }
.call-control.accept .icon { border-color: var(--accent); background: var(--accent); color: #fff; }

.call-diagnostics {
  padding-top: 10px;
  border-top: 1px solid var(--divider);
  color: var(--muted);
  font-size: 12px;
}

.call-diagnostics summary { cursor: pointer; }
.call-diagnostics pre { max-height: 100px; overflow: auto; margin: 7px 0 0; white-space: pre-wrap; font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }

@media (max-width: 1100px) and (min-width: 841px) {
  .app-shell { grid-template-columns: 320px minmax(0, 1fr); }
  .app-view { padding-inline: 10px; }
  .message-flow { width: min(100%, 680px); }
}

@media (max-width: 840px) {
  .auth-view,
  .app-view { display: block; }
  .app-view { padding: 0; }
  .auth-shell { min-height: 100dvh; border: 0; }
  .app-shell {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    border: 0;
  }
  .sidebar { height: 100%; border-right: 0; }
  .conversation {
    position: fixed;
    z-index: 10;
    inset: 0;
    height: 100vh;
    height: 100dvh;
    display: none;
  }
  .app-shell.chat-open .conversation { display: block; }
  .conversation-empty { display: none; }
  .back-button { display: inline-grid; margin-left: -6px; }
  .chat-header { padding-left: 6px; }
  .message-flow { width: 100%; border-inline: 0; padding-inline: 10px; }
  .message-bubble { max-width: 82%; }
  .scroll-bottom-button { right: 10px; }
  .new-chat-dialog {
    width: 100%;
    max-width: none;
    max-height: 86dvh;
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: 10px 10px 0 0;
  }
  .call-layer { padding: 0; background: var(--surface); }
  .call-shell { width: 100%; min-height: 100dvh; border: 0; border-radius: 0; }
}

@media (max-width: 380px) {
  .field-row { grid-template-columns: 1fr; }
  .theme-options { padding-left: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
