:root {
  --bg: #f5f9ff;
  --bg-elevated: #eef5ff;
  --panel: #e6f1ff;
  --panel-strong: #ffffff;
  --panel-soft: rgba(255, 255, 255, 0.72);
  --accent: #6ca8ff;
  --accent-strong: #4a89dc;
  --accent-soft: #cfe0ff;
  --text: #1e2a3a;
  --muted: #6b7c93;
  --line: #d6e4f2;
  --line-strong: #bfd4ee;
  --self-message: #dbeeff;
  --peer-message: #ffffff;
  --success: #70c797;
  --danger: #ff6b6b;
  --danger-soft: #f8d7da;
  --shadow: 0 18px 50px rgba(74, 137, 220, 0.12);
  --shadow-soft: 0 8px 18px rgba(91, 131, 178, 0.12);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --sidebar-width: 88px;
  --conversation-width: 360px;
  --toolbar-height: 72px;
  --securemsg-viewport-height: 100vh;
}

/* Compact Telegram-like message density and inline encrypted controls. */
.message-list {
  gap: 4px;
}

.message-day {
  min-height: 24px;
  padding: 0 10px;
  font-size: 11px;
}

.message-item:not(.message-item--clustered) {
  margin-top: 4px;
}

.message-bubble {
  max-width: min(68%, 560px);
  padding: 7px 9px 5px;
  gap: 4px;
  border-radius: 14px;
  box-shadow: 0 6px 14px rgba(74, 137, 220, 0.07);
}

.message-text {
  font-size: 13px;
  line-height: 1.34;
}

.message-text--deleted {
  color: var(--muted);
  font-style: italic;
}

.message-signature {
  display: none;
}

.message-footer {
  gap: 5px;
  font-size: 10.5px;
  line-height: 1;
}

.message-edited {
  color: var(--muted);
}

.message-state {
  color: var(--muted);
  letter-spacing: -0.12em;
}

.message-state--read {
  color: #2f80ed;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  max-width: 100%;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 120ms ease, max-height 120ms ease;
}

.message-bubble:hover .message-actions,
.message-bubble:focus-within .message-actions {
  opacity: 1;
  max-height: 96px;
}

.message-actions button {
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  font-size: 11px;
}

.message-item--highlighted .message-bubble {
  box-shadow: 0 0 0 2px rgba(108, 168, 255, 0.3), 0 12px 20px rgba(74, 137, 220, 0.12);
}

.message-forwarded {
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 700;
}

.message-reply-card {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 12px;
  border-left: 3px solid var(--accent);
  background: rgba(108, 168, 255, 0.1);
  text-align: left;
}

.message-reply-card strong {
  font-size: 11px;
  color: var(--accent-strong);
}

.message-reply-card span {
  color: var(--text);
  font-size: 11px;
}

.message-text a {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-preview-card {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
  border-radius: 14px;
  border: 1px solid rgba(108, 168, 255, 0.2);
  background: rgba(255, 255, 255, 0.78);
}

.link-preview-card strong {
  color: var(--text);
  font-size: 12px;
}

.link-preview-card span,
.link-preview-card small {
  color: var(--muted);
}

.composer-context {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(108, 168, 255, 0.18);
  border-radius: 16px;
  background: rgba(108, 168, 255, 0.08);
}

.composer-context__body {
  display: grid;
  gap: 2px;
}

.composer-context__label {
  margin: 0;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.composer-context__preview {
  margin: 0;
  color: var(--text);
  font-size: 12px;
}

.forward-target-list {
  display: grid;
  gap: 8px;
}

.forward-target {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 14px;
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.forward-target span {
  color: var(--muted);
  font-size: 12px;
}

.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(108, 168, 255, 0.16);
  color: var(--accent-strong);
  font-size: 12px;
}

.reaction-chip small {
  font-size: 10px;
  font-weight: 700;
}

.sticker-message {
  display: grid;
  place-items: center;
  min-width: 86px;
  min-height: 76px;
}

.sticker-message span {
  font-size: clamp(46px, 8vw, 72px);
  line-height: 1;
  filter: drop-shadow(0 8px 12px rgba(30, 42, 58, 0.12));
}

.sticker-panel {
  display: grid;
  grid-template-columns: repeat(6, minmax(44px, 1fr));
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-soft);
}

.sticker-button {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 58px;
  border-radius: 14px;
  color: var(--text);
  background: rgba(108, 168, 255, 0.08);
  border: 1px solid rgba(108, 168, 255, 0.16);
}

.sticker-button span {
  font-size: 28px;
  line-height: 1;
}

.sticker-button small {
  max-width: 100%;
  color: var(--muted);
  font-size: 9px;
  overflow: hidden;
  text-overflow: ellipsis;
}

#pick-gif {
  width: 52px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

#pick-sticker {
  font-size: 18px;
}

#cancel-edit {
  min-height: 44px;
  white-space: nowrap;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.68)),
    linear-gradient(135deg, #f5f9ff 0%, #edf5ff 55%, #e8f1fe 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
textarea,
select {
  outline: none;
}

button {
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea {
  resize: vertical;
  min-height: 48px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(108, 168, 255, 0.18);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

summary {
  cursor: pointer;
}

.hidden,
.hidden-input {
  display: none !important;
}

.mobile-only {
  display: none !important;
}

.section-label {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.muted-text,
.status-line,
.hero-copy,
.auth-panel__hint,
.panel-title p,
.content-panel__header p,
.message-empty p,
.empty-panel p {
  color: var(--muted);
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button,
.primary-link,
.segment,
.context-menu__item {
  min-height: 44px;
  border-radius: 14px;
  padding: 0 16px;
  font-weight: 600;
  transition: background 160ms ease, transform 160ms ease, box-shadow 160ms ease, color 160ms ease, border-color 160ms ease;
}

.primary-button,
.primary-link {
  color: #fff;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  box-shadow: 0 12px 24px rgba(74, 137, 220, 0.2);
}

.secondary-button {
  color: var(--accent-strong);
  background: rgba(108, 168, 255, 0.14);
  border: 1px solid rgba(108, 168, 255, 0.26);
}

.ghost-button,
.segment,
.icon-button,
.context-menu__item {
  color: var(--text);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
}

.danger-button {
  color: #fff;
  background: linear-gradient(180deg, #ff8a8a, var(--danger));
  box-shadow: 0 12px 24px rgba(255, 107, 107, 0.18);
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:hover,
.ghost-button:hover,
.primary-link:hover,
.segment:hover,
.icon-button:hover,
.context-menu__item:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled,
.danger-button:disabled,
.ghost-button:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

.primary-button--icon {
  width: 48px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.icon-button svg,
.primary-button--icon svg,
.rail-icon svg,
.search-field__icon svg {
  width: 20px;
  height: 20px;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.theme-blue .app-shell,
.theme-blue .auth-layout {
  width: min(1600px, calc(100vw - 24px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px 0;
}

.auth-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(420px, 520px);
  gap: 22px;
  align-items: stretch;
}

.auth-hero,
.auth-panel,
.content-panel,
.conversation-pane,
.chat-pane,
.app-sidebar,
.workspace-header,
.composer,
.call-panel,
.empty-panel,
.detail-card,
.hero-stat,
.conversation-row,
.results-card,
.message-bubble,
.attachment-chip,
.context-menu,
.toast,
.debug-output {
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}

.auth-hero,
.auth-panel,
.content-panel,
.conversation-pane,
.chat-pane,
.app-sidebar,
.workspace-header,
.composer,
.call-panel,
.empty-panel,
.detail-card,
.context-menu,
.toast,
.debug-output {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
}

.auth-hero,
.auth-panel,
.content-panel,
.conversation-pane,
.chat-pane,
.app-sidebar,
.workspace-header,
.empty-panel {
  border-radius: var(--radius-xl);
}

.auth-hero,
.auth-panel,
.content-panel,
.conversation-pane,
.chat-pane,
.workspace-header {
  padding: 24px;
}

.auth-hero {
  display: grid;
  gap: 24px;
  align-content: space-between;
  background:
    linear-gradient(140deg, rgba(108, 168, 255, 0.16), rgba(255, 255, 255, 0.88)),
    var(--panel);
}

.auth-hero__badge {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--accent-strong);
  font-weight: 700;
}

.auth-hero h1 {
  margin: 0;
  font-size: clamp(34px, 4vw, 56px);
  line-height: 1.02;
}

.auth-hero__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.hero-stat {
  min-height: 132px;
  border-radius: 18px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.82);
  display: grid;
  align-content: start;
  gap: 10px;
}

.hero-stat strong {
  font-size: 16px;
}

.auth-panel {
  display: grid;
  gap: 18px;
  align-content: start;
  background: rgba(255, 255, 255, 0.86);
}

.auth-panel__header,
.workspace-header,
.content-panel__header,
.pane-header,
.chat-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.workspace-header {
  min-height: var(--toolbar-height);
  position: sticky;
  top: 12px;
  z-index: 20;
}

.workspace-title,
.auth-panel h2,
.content-panel h2,
.pane-header h2,
.chat-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.workspace-header__left,
.chat-header__identity,
.chat-header__actions,
.workspace-profile,
.auth-grid,
.composer-row,
.profile-card,
.call-panel,
.call-panel__actions,
.conversation-row__top,
.conversation-row__bottom {
  display: flex;
  gap: 12px;
  align-items: center;
}

.workspace-header__left {
  min-width: 0;
}

.workspace-profile {
  margin-left: auto;
  justify-content: flex-end;
}

.chat-zone-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mode-pill {
  border: 1px solid rgba(21, 61, 96, 0.14);
  background: rgba(255, 255, 255, 0.82);
  color: #163447;
  border-radius: 999px;
  padding: 0.52rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.mode-pill.is-active {
  border-color: rgba(21, 61, 96, 0.48);
  box-shadow: 0 14px 30px rgba(21, 61, 96, 0.16);
  transform: translateY(-1px);
}

.mode-pill--warning {
  color: #8c4b14;
  border-color: rgba(196, 118, 37, 0.2);
  background: linear-gradient(180deg, rgba(255, 245, 228, 0.94), rgba(255, 236, 206, 0.88));
}

.workspace-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  background: rgba(21, 61, 96, 0.09);
  color: #14364d;
  font-weight: 700;
  font-size: 0.85rem;
}

.workspace-badge[data-tone="warning"] {
  background: rgba(196, 118, 37, 0.14);
  color: #7b4616;
}

.profile-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(108, 168, 255, 0.16);
  color: var(--accent-strong);
  font-weight: 700;
}

.auth-stack,
.panel-stack,
.modal-stack {
  display: grid;
  gap: 14px;
}

.auth-stack {
  padding: 20px;
  border-radius: 18px;
  background: rgba(230, 241, 255, 0.58);
  border: 1px solid rgba(214, 228, 242, 0.9);
}

.auth-stack--primary {
  background: linear-gradient(180deg, rgba(230, 241, 255, 0.72), rgba(255, 255, 255, 0.94));
}

.auth-stack--compact {
  padding: 0;
  background: transparent;
  border: 0;
}

.auth-grid {
  align-items: start;
}

.auth-grid--two > * {
  flex: 1 1 220px;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.check-row input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.secondary-details {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 18px;
  background: rgba(245, 249, 255, 0.74);
}

.secondary-details[open] summary {
  margin-bottom: 16px;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: 14px;
}

.app-sidebar {
  position: sticky;
  top: 12px;
  z-index: 20;
  height: calc(100vh - 24px);
  padding: 18px 12px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 22px;
  background: linear-gradient(180deg, rgba(230, 241, 255, 0.86), rgba(255, 255, 255, 0.84));
}

.app-sidebar__brand {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 14px 24px rgba(74, 137, 220, 0.22);
}

.brand-copy {
  display: grid;
  gap: 4px;
  text-align: center;
}

.brand-copy strong {
  font-size: 13px;
}

.brand-copy span {
  color: var(--muted);
  font-size: 12px;
}

.rail-nav,
.app-sidebar__footer {
  display: grid;
  gap: 10px;
  align-content: start;
}

.rail-nav__button {
  position: relative;
  width: 100%;
  min-height: 48px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}

.rail-nav__button:hover,
.rail-nav__button.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: rgba(108, 168, 255, 0.22);
}

.rail-nav__button[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: 60;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(30, 42, 58, 0.92);
  color: #fff;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.rail-nav__button:hover::after {
  opacity: 1;
}

.workspace {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 14px;
  min-width: 0;
  align-content: start;
}

.messenger-layout {
  display: grid;
  grid-template-columns: minmax(300px, var(--conversation-width)) minmax(0, 1fr);
  gap: 14px;
  min-height: calc(100vh - 110px);
}

.conversation-pane,
.chat-pane {
  min-height: 0;
}

.conversation-pane {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 16px;
  background: rgba(230, 241, 255, 0.7);
}

.pane-header h2,
.content-panel__header h2 {
  margin-bottom: 4px;
}

.pane-header p,
.content-panel__header p {
  margin: 0;
}

.search-field {
  position: relative;
  display: block;
}

.search-field input {
  padding-left: 44px;
}

.search-field__icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.segmented-control {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.segment {
  padding: 0 14px;
}

.segment.is-active,
.segment.chip-active {
  color: #fff;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border-color: transparent;
}

.conversation-list,
.results-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 8px;
  align-content: start;
  align-items: start;
}

.conversation-search-section {
  display: grid;
  gap: 8px;
}

.conversation-search-section__header {
  padding: 0 4px;
}

.conversation-row,
.results-card {
  width: 100%;
  border-radius: 18px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.95);
  text-align: left;
}

.conversation-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background 160ms ease;
}

.conversation-row:hover,
.results-card:hover {
  transform: translateY(-1px);
  border-color: rgba(108, 168, 255, 0.3);
  box-shadow: 0 14px 30px rgba(74, 137, 220, 0.12);
}

.results-card--muted {
  cursor: default;
  opacity: 0.72;
}

.results-card--muted:hover {
  transform: none;
}

.conversation-row.active {
  background: #fff;
  border-color: rgba(108, 168, 255, 0.42);
  box-shadow: 0 14px 28px rgba(74, 137, 220, 0.12);
}

.conversation-row__body {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.conversation-row__top,
.conversation-row__bottom {
  justify-content: space-between;
  min-width: 0;
}

.conversation-row__title,
.conversation-row__preview {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-row__title {
  font-size: 15px;
  font-weight: 700;
}

.conversation-row__title--unread,
.conversation-row__preview--unread {
  color: var(--text);
  font-weight: 700;
}

.conversation-row__preview {
  color: var(--muted);
  font-size: 13px;
}

.conversation-row__time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.conversation-row__meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.conversation-tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(108, 168, 255, 0.12);
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-strong);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.64), rgba(255, 255, 255, 0.82)),
    linear-gradient(135deg, rgba(230, 241, 255, 0.88), rgba(245, 249, 255, 0.94));
}

.chat-header__identity {
  min-width: 0;
  flex: 1 1 auto;
}

.chat-header__meta {
  min-width: 0;
}

.chat-header__meta h2,
.chat-header__meta p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: 0 0 auto;
  background: linear-gradient(180deg, rgba(108, 168, 255, 0.26), rgba(108, 168, 255, 0.16));
  color: var(--accent-strong);
  font-weight: 800;
  text-transform: uppercase;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.avatar.has-image img {
  display: block;
}

.avatar.has-image span {
  display: none;
}

.avatar--chat {
  width: 56px;
  height: 56px;
  border-radius: 18px;
}

.avatar--list {
  width: 52px;
  height: 52px;
}

.avatar--message {
  width: 32px;
  height: 32px;
  border-radius: 11px;
  font-size: 11px;
}

.avatar--profile {
  width: 72px;
  height: 72px;
  border-radius: 24px;
}

.avatar-button {
  padding: 0;
  border: 0;
  box-shadow: none;
}

.call-panel {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding: 18px 20px;
  border-radius: 20px;
  background:
    linear-gradient(135deg, rgba(108, 168, 255, 0.18), rgba(255, 255, 255, 0.92)),
    rgba(255, 255, 255, 0.96);
}

.call-alert-banner {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 16px 20px;
  border: 1px solid rgba(108, 168, 255, 0.24);
  border-radius: 20px;
  background:
    linear-gradient(135deg, rgba(108, 168, 255, 0.12), rgba(255, 255, 255, 0.94)),
    rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 28px rgba(74, 137, 220, 0.08);
}

.call-alert-banner__meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.call-alert-banner__meta h3 {
  margin: 0;
  font-size: 16px;
}

.call-alert-banner[data-state="ready"] {
  border-color: rgba(83, 173, 123, 0.28);
  background:
    linear-gradient(135deg, rgba(102, 196, 140, 0.12), rgba(255, 255, 255, 0.94)),
    rgba(255, 255, 255, 0.98);
}

.call-alert-banner[data-state="blocked"] {
  border-color: rgba(232, 126, 84, 0.28);
  background:
    linear-gradient(135deg, rgba(255, 178, 145, 0.16), rgba(255, 255, 255, 0.94)),
    rgba(255, 255, 255, 0.98);
}

.call-alert-banner .secondary-button {
  flex: 0 0 auto;
  min-width: 220px;
}

.chat-header__actions .icon-button[data-state="ready"] {
  color: #3b9964;
  border-color: rgba(83, 173, 123, 0.28);
  background: linear-gradient(180deg, rgba(102, 196, 140, 0.18), rgba(255, 255, 255, 0.96));
}

.chat-header__actions .icon-button[data-state="blocked"] {
  color: #c96d4f;
  border-color: rgba(232, 126, 84, 0.28);
  background: linear-gradient(180deg, rgba(255, 178, 145, 0.22), rgba(255, 255, 255, 0.96));
}

.call-panel__meta h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.call-panel audio {
  display: none;
}

.call-panel__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-left: auto;
}

.call-select {
  display: grid;
  gap: 6px;
  min-width: 142px;
  color: var(--muted);
  font-size: 12px;
}

.call-select select {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
}

.call-video-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px;
  gap: 12px;
  width: min(100%, 560px);
  margin-left: auto;
  padding: 10px;
  border-radius: 18px;
  background: rgba(12, 16, 26, 0.9);
  transition: width 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.call-video-stage[data-stage-size="compact"] {
  width: min(100%, 420px);
  grid-template-columns: minmax(0, 1fr) 104px;
}

.call-video-stage[data-stage-size="standard"] {
  width: min(100%, 560px);
  grid-template-columns: minmax(0, 1fr) 128px;
}

.call-video-stage[data-stage-size="theater"] {
  width: min(100%, 840px);
  grid-template-columns: minmax(0, 1fr) 164px;
  box-shadow: 0 22px 46px rgba(10, 15, 28, 0.24);
}

.call-video-stage video {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  background: rgba(16, 24, 40, 0.92);
  object-fit: cover;
}

#local-call-video {
  align-self: end;
  justify-self: end;
  max-width: 128px;
}

.call-video-stage[data-stage-size="compact"] #local-call-video {
  max-width: 104px;
}

.call-video-stage[data-stage-size="theater"] #local-call-video {
  max-width: 164px;
}

.call-video-stage:fullscreen {
  display: block;
  width: 100vw;
  height: 100vh;
  padding: 24px;
  border-radius: 0;
  background: rgba(6, 9, 16, 0.98);
}

.call-video-stage:fullscreen #remote-call-video {
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 48px);
  aspect-ratio: auto;
  border-radius: 20px;
}

.call-video-stage:fullscreen #local-call-video {
  position: absolute;
  right: 28px;
  bottom: 28px;
  width: min(24vw, 280px);
  max-width: none;
  border: 2px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.32);
}

body.call-video-stage--fallback-fullscreen {
  overflow: hidden;
}

body.call-video-stage--fallback-fullscreen .call-panel {
  position: fixed;
  inset: 0;
  z-index: 80;
  margin: 0;
  padding: 24px;
  border-radius: 0;
  background: rgba(6, 9, 16, 0.98);
}

body.call-video-stage--fallback-fullscreen .call-panel__meta,
body.call-video-stage--fallback-fullscreen .call-panel__actions {
  display: none;
}

body.call-video-stage--fallback-fullscreen .call-panel__toolbar {
  position: absolute;
  top: 20px;
  right: 20px;
  left: 20px;
  z-index: 2;
  justify-content: flex-end;
}

body.call-video-stage--fallback-fullscreen .call-video-stage {
  position: absolute;
  inset: 0;
  display: grid;
  width: 100vw;
  height: 100vh;
  max-width: none;
  margin: 0;
  padding: 24px;
  border-radius: 0;
  background: rgba(6, 9, 16, 0.98);
  grid-template-columns: minmax(0, 1fr) 164px;
}

body.call-video-stage--fallback-fullscreen .call-video-stage video {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

body.call-video-stage--fallback-fullscreen #local-call-video {
  align-self: end;
  justify-self: end;
  width: min(24vw, 280px);
  max-width: none;
}

.empty-panel {
  min-height: 240px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 28px;
  background:
    linear-gradient(180deg, rgba(245, 249, 255, 0.94), rgba(255, 255, 255, 0.96));
}

.empty-panel h2,
.empty-panel h3 {
  margin: 0 0 8px;
}

.chat-workspace {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  min-height: 0;
}

.message-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 10px;
  padding: 4px 4px 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.25)),
    linear-gradient(135deg, rgba(230, 241, 255, 0.55), rgba(245, 249, 255, 0.96));
  border-radius: 22px;
}

.message-day {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  font-size: 12px;
  border: 1px solid var(--line);
}

.message-item {
  display: grid;
  gap: 4px;
  animation: messageIn 180ms ease;
}

.message-item--with-avatar {
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: end;
  column-gap: 8px;
}

.message-item.outgoing {
  justify-items: end;
}

.message-stack {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.message-avatar {
  align-self: end;
  padding-bottom: 2px;
}

.message-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.message-bubble {
  max-width: min(72%, 640px);
  border-radius: 18px;
  padding: 12px 14px 10px;
  display: grid;
  gap: 10px;
  background: var(--peer-message);
}

.message-item.outgoing .message-bubble {
  background: var(--self-message);
}

.message-item.outgoing .message-meta {
  justify-content: flex-end;
}

.message-author {
  font-weight: 700;
}

.message-text {
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-signature {
  color: var(--muted);
  font-size: 12px;
}

.message-footer {
  display: inline-flex;
  justify-content: flex-end;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.message-state {
  color: var(--accent-strong);
  font-weight: 700;
}

.media-card,
.call-card,
.detail-card {
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.media-preview {
  display: block;
  max-width: min(100%, 340px);
  border-radius: 14px;
}

.media-preview--telegram {
  width: min(100%, 340px);
  max-height: 300px;
  object-fit: contain;
  background: #f7f9fc;
}

.media-card--telegram {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.media-card--telegram-photo,
.media-card--telegram-video {
  margin: 0;
}

.media-card--telegram-photo .media-preview,
.media-card--telegram-video .media-preview {
  width: min(100%, 420px);
  max-height: 420px;
  border-radius: 12px;
  border: 1px solid rgba(214, 228, 242, 0.86);
  background: #fff;
}

.media-card--telegram-audio,
.media-card--telegram-placeholder {
  padding: 10px 12px;
  border: 1px solid rgba(214, 228, 242, 0.86);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
}

.media-card--telegram-audio audio {
  width: min(100%, 360px);
}

.composer {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.94);
}

.composer-row {
  align-items: flex-end;
}

.composer-field {
  flex: 1 1 auto;
}

.composer-field textarea {
  min-height: 48px;
  max-height: 180px;
  border-radius: 18px;
  resize: none;
}

.attachment-chip {
  padding: 12px 14px;
  border-radius: 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: rgba(230, 241, 255, 0.72);
}

.attachment-chip__meta {
  display: grid;
  gap: 4px;
}

.content-panel,
.contacts-layout,
.settings-layout {
  min-width: 0;
}

.contacts-layout,
.settings-layout {
  display: grid;
  gap: 14px;
}

.contacts-layout {
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, 0.9fr) minmax(300px, 0.9fr);
}

.settings-layout {
  grid-template-columns: minmax(340px, 0.9fr) minmax(280px, 0.72fr) minmax(340px, 1fr);
}

.profile-card {
  margin-bottom: 18px;
  padding: 18px;
  border-radius: 20px;
  background: rgba(230, 241, 255, 0.72);
  border: 1px solid var(--line);
}

.panel-divider {
  height: 1px;
  background: var(--line);
}

.results-card {
  display: grid;
  gap: 6px;
}

.results-card__header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.results-card strong {
  font-size: 15px;
}

.identity-card,
.group-member-card {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  column-gap: 12px;
}

.identity-card__body,
.group-member-card__meta {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.group-member-card {
  gap: 12px;
}

.group-member-card__identity {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.search-result__snippet {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.debug-output {
  margin: 0;
  min-height: 104px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  overflow: auto;
  font: 12px/1.45 "SFMono-Regular", Consolas, monospace;
}

.modal-shell {
  width: min(92vw, 720px);
  max-height: min(86vh, 980px);
  overflow: auto;
  border: 0;
  border-radius: 24px;
  padding: 24px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 22px 60px rgba(27, 59, 101, 0.22);
}

.modal-shell::backdrop {
  background: rgba(20, 39, 61, 0.28);
}

.modal-shell--compact {
  width: min(92vw, 540px);
}

body.securemsg-call-ringing .call-panel,
body.securemsg-call-ringing #incoming-call-dialog[open] {
  animation: callRingPulse 1.4s ease-in-out infinite;
}

body.securemsg-call-ringing .call-panel {
  border-color: rgba(239, 68, 68, 0.35);
}

body.securemsg-call-ringing #incoming-call-dialog[open] {
  border: 1px solid rgba(239, 68, 68, 0.18);
  box-shadow: 0 26px 70px rgba(239, 68, 68, 0.24);
}

.modal-close {
  margin-left: auto;
  margin-bottom: 16px;
  display: block;
}

.modal-body img,
.modal-body video {
  width: 100%;
  border-radius: 18px;
}

.context-menu {
  position: fixed;
  z-index: 50;
  min-width: 220px;
  padding: 8px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
}

.context-menu__item {
  width: 100%;
  text-align: left;
  border: 0;
  box-shadow: none;
}

.context-menu__item + .context-menu__item {
  margin-top: 4px;
}

.context-menu__item--danger {
  color: var(--danger);
}

.toast-region {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 70;
  display: grid;
  gap: 10px;
  pointer-events: none;
}

.toast {
  min-width: 260px;
  max-width: min(360px, calc(100vw - 28px));
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  pointer-events: auto;
  animation: toastIn 180ms ease;
}

.toast--error {
  border-color: rgba(255, 107, 107, 0.3);
  background: rgba(248, 215, 218, 0.96);
}

.toast--success {
  border-color: rgba(112, 199, 151, 0.34);
  background: rgba(235, 250, 240, 0.96);
}

.mobile-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(27, 52, 83, 0.24);
}

body.drawer-open {
  overflow: hidden;
}

body.drawer-open .mobile-overlay {
  display: block !important;
}

body.drawer-open .app-sidebar {
  transform: translateX(0);
}

body.mobile-chat-open .conversation-pane {
  display: none;
}

body.mobile-chat-open .chat-pane {
  display: grid;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes callRingPulse {
  0%,
  100% {
    transform: translateY(0);
    box-shadow: 0 14px 30px rgba(74, 137, 220, 0.12);
  }
  50% {
    transform: translateY(-1px);
    box-shadow: 0 22px 42px rgba(239, 68, 68, 0.2);
  }
}

@media (max-width: 1260px) {
  .contacts-layout,
  .settings-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1100px) {
  .auth-layout,
  .messenger-layout {
    grid-template-columns: 1fr;
  }

  .auth-hero__grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .theme-blue .app-shell,
  .theme-blue .auth-layout {
    width: 100vw;
    padding: 0;
  }

  .mobile-only {
    display: inline-flex !important;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 40;
    width: min(86vw, 320px);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    grid-template-columns: 1fr;
  }

  .app-sidebar__brand,
  .rail-nav,
  .app-sidebar__footer {
    justify-items: start;
  }

  .rail-nav__button,
  .rail-nav__link {
    width: 100%;
    justify-content: flex-start;
    padding: 0 14px;
  }

  .rail-nav__button[data-tooltip]::after {
    display: none;
  }

  .workspace-header,
  .conversation-pane,
  .chat-pane,
  .content-panel,
  .auth-panel,
  .auth-hero {
    padding: 14px;
  }

  .workspace {
    gap: 8px;
  }

  .workspace-header {
    position: static;
    min-height: 0;
  }

  .workspace-profile {
    display: none;
  }

  .segmented-control {
    overflow: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .segment {
    flex: 0 0 auto;
  }

  .chat-header,
  .call-panel,
  .button-row,
  .composer-row,
  .auth-grid,
  .auth-panel__header {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-header {
    flex-flow: row wrap;
    gap: 10px;
  }

  .chat-header__identity {
    flex: 1 1 min(100%, 260px);
  }

  .chat-header__meta h2,
  .chat-header__meta p {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .chat-header__actions {
    width: 100%;
    margin-left: 0;
    display: grid;
    grid-template-columns: repeat(3, 44px);
    justify-content: end;
    gap: 8px;
  }

  .call-panel {
    gap: 10px;
    padding: 14px;
  }

  .composer {
    padding: 12px;
  }

  .composer-row {
    flex-flow: row wrap;
  }

  .composer-field {
    flex: 1 1 100%;
    order: 2;
  }

  .message-list {
    padding: 8px;
  }

  .message-bubble {
    max-width: 100%;
  }

  .toast-region {
    top: 8px;
    left: 8px;
    right: 8px;
  }

  .toast {
    width: 100%;
    min-width: 0;
    max-width: none;
    padding: 12px 14px;
  }
}

@media (max-width: 640px) {
  .workspace-header,
  .conversation-pane,
  .chat-pane,
  .content-panel,
  .auth-panel,
  .auth-hero,
  .empty-panel {
    border-radius: 18px;
  }

  .theme-blue .app-shell,
  .theme-blue .auth-layout {
    width: 100vw;
  }

  .workspace-title,
  .auth-panel h2,
  .content-panel h2,
  .pane-header h2,
  .chat-header h2 {
    font-size: 18px;
  }

  .auth-hero h1 {
    font-size: 28px;
  }

  .message-list {
    border-radius: 18px;
  }

  .chat-pane {
    gap: 10px;
  }

  .avatar--chat {
    width: 48px;
    height: 48px;
  }

  .icon-button,
  .primary-button--icon {
    width: 44px;
    height: 44px;
  }

  .modal-shell {
    width: min(96vw, 540px);
    padding: 16px;
  }
}

/* Compact production layout: keep desktop usable without giant cards/gaps. */
:root {
  --conversation-width: 320px;
  --toolbar-height: 60px;
}

.theme-blue .app-shell,
.theme-blue .auth-layout {
  width: min(1440px, calc(100vw - 16px));
  padding: 8px 0;
}

.app-shell,
.workspace,
.messenger-layout,
.chat-workspace {
  gap: 10px;
}

.auth-hero,
.auth-panel,
.content-panel,
.conversation-pane,
.chat-pane,
.workspace-header {
  padding: 18px;
}

.conversation-pane {
  gap: 12px;
}

.message-list {
  padding: 10px;
}

/* Android WebView can report a desktop-sized CSS viewport. Force phone UI. */
body.securemsg-android {
  --android-toolbar-height: calc(76px + env(safe-area-inset-top, 0px));
  width: 100vw;
  min-height: var(--securemsg-viewport-height);
  overflow: hidden;
  background: #f5f9ff;
}

body.securemsg-android .theme-blue,
body.securemsg-android .app-shell {
  width: 100vw;
}

body.securemsg-android .theme-blue .app-shell,
body.securemsg-android .theme-blue .auth-layout {
  width: 100vw;
  min-height: var(--securemsg-viewport-height);
  padding: 0;
}

body.securemsg-android .mobile-only {
  display: inline-flex !important;
}

body.securemsg-android .app-shell {
  grid-template-columns: 1fr;
  gap: 0;
}

body.securemsg-android .app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: min(82vw, 300px);
  height: var(--securemsg-viewport-height);
  transform: translateX(-105%);
  transition: transform 180ms ease;
  border-radius: 0 22px 22px 0;
}

body.securemsg-android.drawer-open .app-sidebar {
  transform: translateX(0);
}

body.securemsg-android .workspace {
  height: var(--securemsg-viewport-height);
  gap: 0;
}

body.securemsg-android .workspace-header {
  position: static;
  min-height: var(--android-toolbar-height);
  padding: calc(14px + env(safe-area-inset-top, 0px)) 14px 12px;
  border-radius: 0;
  box-shadow: none;
}

body.securemsg-android .workspace-profile {
  display: none;
}

body.securemsg-android .messenger-layout {
  grid-template-columns: 1fr;
  gap: 0;
  min-height: 0;
  height: calc(var(--securemsg-viewport-height) - var(--android-toolbar-height));
}

body.securemsg-android .conversation-pane,
body.securemsg-android .chat-pane,
body.securemsg-android .content-panel,
body.securemsg-android .auth-panel,
body.securemsg-android .auth-hero,
body.securemsg-android .empty-panel {
  border-radius: 0;
  padding: 12px;
  box-shadow: none;
}

body.securemsg-android .conversation-pane {
  grid-template-rows: auto auto auto minmax(0, 1fr);
  height: 100%;
  gap: 10px;
}

body.securemsg-android.mobile-chat-open .conversation-pane {
  display: none;
}

body.securemsg-android:not(.mobile-chat-open) .chat-pane {
  display: none;
}

body.securemsg-android.mobile-chat-open .chat-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100%;
  gap: 8px;
}

body.securemsg-android .pane-header p,
body.securemsg-android .workspace-title,
body.securemsg-android .brand-copy {
  display: none;
}

body.securemsg-android .segmented-control {
  overflow-x: auto;
  flex-wrap: nowrap;
  padding-bottom: 2px;
}

body.securemsg-android .segment {
  flex: 0 0 auto;
}

body.securemsg-android .conversation-row {
  padding: 12px;
  border-radius: 16px;
}

body.securemsg-android .chat-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

body.securemsg-android .chat-header__identity {
  min-width: 0;
}

body.securemsg-android .chat-header__meta h2,
body.securemsg-android .chat-header__meta p {
  white-space: normal;
  overflow-wrap: anywhere;
}

body.securemsg-android .chat-header__actions {
  display: grid;
  grid-template-columns: repeat(3, 42px);
  gap: 6px;
}

body.securemsg-android .avatar--chat {
  width: 46px;
  height: 46px;
}

body.securemsg-android .icon-button,
body.securemsg-android .primary-button--icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
}

body.securemsg-android .call-panel {
  padding: 10px 12px;
  border-radius: 16px;
  gap: 8px;
}

body.securemsg-android .call-panel__toolbar {
  width: 100%;
  margin-left: 0;
}

body.securemsg-android .chat-workspace {
  min-height: 0;
  gap: 8px;
}

body.securemsg-android .message-list {
  border-radius: 16px;
  padding: 8px;
  gap: 8px;
}

body.securemsg-android .message-bubble {
  max-width: 92%;
  padding: 10px 12px;
}

body.securemsg-android .composer {
  padding: 10px;
  border-radius: 16px;
}

body.securemsg-android .composer-row {
  display: grid;
  grid-template-columns: 42px 52px 42px minmax(0, 1fr) 42px;
  gap: 8px;
  align-items: end;
}

body.securemsg-android .composer-field textarea {
  min-height: 42px;
  max-height: 112px;
  padding: 10px 12px;
}

body.securemsg-android .toast-region {
  top: 8px;
  left: 8px;
  right: 8px;
}

body.securemsg-android .toast {
  width: 100%;
  min-width: 0;
  max-width: none;
  padding: 11px 12px;
}

/* Stable production layout: keep panels in normal flow and prevent overlay collisions. */
:root {
  --sidebar-width: 76px;
  --conversation-width: 304px;
  --toolbar-height: 56px;
}

.theme-blue .app-shell,
.theme-blue .auth-layout {
  width: min(1280px, calc(100vw - 16px));
  min-height: var(--securemsg-viewport-height);
  padding: 8px 0;
}

.app-shell {
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: 10px;
}

.app-sidebar {
  top: 8px;
  height: calc(var(--securemsg-viewport-height) - 16px);
  padding: 12px 8px;
  gap: 12px;
  z-index: 10;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
}

.rail-nav__button {
  min-height: 44px;
  border-radius: 14px;
}

.workspace {
  grid-template-rows: auto minmax(0, 1fr);
  min-height: calc(var(--securemsg-viewport-height) - 16px);
  gap: 10px;
}

.workspace-header {
  position: static;
  min-height: var(--toolbar-height);
  padding: 12px 16px;
  z-index: 1;
}

.messenger-layout {
  grid-template-columns: minmax(280px, var(--conversation-width)) minmax(0, 1fr);
  min-height: 0;
  height: calc(var(--securemsg-viewport-height) - var(--toolbar-height) - 26px);
  overflow: hidden;
}

.conversation-pane,
.chat-pane,
.content-panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
}

.conversation-pane {
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 10px;
}

.conversation-list,
.results-list,
.message-list {
  min-height: 0;
  overflow: auto;
  align-content: start;
  align-items: start;
}

.conversation-row {
  grid-template-columns: 46px minmax(0, 1fr);
  padding: 12px;
}

.avatar--list {
  width: 46px;
  height: 46px;
}

.chat-pane {
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
}

.chat-header {
  min-width: 0;
  align-items: flex-start;
}

.chat-header__identity {
  min-width: 0;
}

.chat-header__actions {
  flex: 0 0 auto;
}

.call-alert-banner {
  padding: 12px 14px;
  gap: 10px;
}

.call-alert-banner .secondary-button {
  min-width: 0;
}

.call-panel {
  padding: 12px 14px;
  gap: 10px;
}

.empty-panel {
  min-height: 160px;
}

.chat-workspace {
  min-height: 0;
  overflow: hidden;
}

.message-list {
  padding: 10px;
}

.composer {
  padding: 12px;
}

.composer-row {
  min-width: 0;
}

.composer-field {
  min-width: 0;
}

.message-bubble {
  max-width: min(78%, 560px);
}

@media (max-width: 860px) {
  body[data-page="chat"] {
    overflow: hidden;
  }

  .theme-blue .app-shell,
  .theme-blue .auth-layout {
    width: 100vw;
    min-height: var(--securemsg-viewport-height);
    padding: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .workspace {
    min-height: var(--securemsg-viewport-height);
    height: var(--securemsg-viewport-height);
    gap: 0;
  }

  .workspace-header {
    min-height: 54px;
    padding: 8px 10px;
    border-radius: 0;
    border-width: 0 0 1px;
    box-shadow: none;
  }

  .workspace-title,
  .brand-copy {
    display: none;
  }

  .messenger-layout {
    display: block;
    height: calc(var(--securemsg-viewport-height) - 54px);
    min-height: 0;
    overflow: hidden;
  }

  .conversation-pane,
  .chat-pane,
  .content-panel,
  .auth-panel,
  .auth-hero,
  .empty-panel {
    border-radius: 0;
    padding: 10px;
    box-shadow: none;
  }

  body:not(.mobile-chat-open) .conversation-pane {
    display: grid;
    height: 100%;
  }

  body:not(.mobile-chat-open) .chat-pane {
    display: none !important;
  }

  body.mobile-chat-open .conversation-pane {
    display: none !important;
  }

  body.mobile-chat-open .chat-pane {
    display: grid;
    height: 100%;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .chat-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }

  .chat-header__identity {
    display: grid;
    grid-template-columns: 42px 42px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
  }

  .chat-header__actions {
    display: grid;
    grid-template-columns: repeat(3, 42px);
    gap: 6px;
    justify-content: end;
    width: 100%;
  }

  .chat-header__meta h2,
  .chat-header__meta p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-header__meta p:not(.section-label),
  .pane-header p {
    display: none;
  }

  .avatar--chat,
  .avatar--list {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }

  .conversation-row {
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .segmented-control {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .segment {
    flex: 0 0 auto;
  }

  .message-list {
    border-radius: 14px;
    padding: 8px;
  }

  .message-bubble {
    max-width: 94%;
  }

  .composer {
    border-radius: 14px;
    padding: 8px;
  }

  .composer-row {
    display: grid;
    grid-template-columns: 42px 52px 42px minmax(0, 1fr) 42px;
    gap: 8px;
    align-items: end;
  }

  .composer-field textarea {
    min-height: 42px;
    max-height: 112px;
    padding: 10px 12px;
  }

  .icon-button,
  .primary-button--icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }
}

body.securemsg-android[data-page="chat"] {
  overflow: hidden;
}

body.securemsg-android:not([data-page="chat"]) {
  overflow: auto;
}

body.securemsg-android:not([data-page="chat"]) .workspace {
  height: auto;
  min-height: var(--securemsg-viewport-height);
}

body.securemsg-android:not([data-page="chat"]) .content-panel,
body.securemsg-android:not([data-page="chat"]) .auth-panel,
body.securemsg-android:not([data-page="chat"]) .auth-hero {
  overflow: visible;
}

body.securemsg-android .theme-blue .app-shell,
body.securemsg-android .theme-blue .auth-layout,
body.securemsg-android .app-shell {
  width: 100vw;
  min-height: var(--securemsg-viewport-height);
  padding: 0;
  margin: 0;
}

body.securemsg-android .app-shell {
  grid-template-columns: 1fr;
  gap: 0;
}

body.securemsg-android .auth-layout {
  display: grid;
  grid-template-columns: 1fr !important;
  align-items: start;
  gap: 10px;
  width: 100vw !important;
  min-height: var(--securemsg-viewport-height);
  padding: 0 !important;
}

body.securemsg-android .auth-hero,
body.securemsg-android .auth-panel {
  width: 100%;
  min-width: 0;
  border-radius: 0;
  box-shadow: none;
}

body.securemsg-android .auth-hero {
  min-height: auto;
  padding: 18px 14px 14px;
  gap: 14px;
  align-content: start;
}

body.securemsg-android .auth-hero__badge {
  padding: 7px 10px;
  font-size: 11px;
}

body.securemsg-android .auth-hero h1 {
  font-size: 28px;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

body.securemsg-android .hero-copy {
  margin: 0;
  font-size: 13px;
}

body.securemsg-android .auth-hero__grid {
  grid-template-columns: 1fr;
  gap: 8px;
}

body.securemsg-android .hero-stat {
  min-height: 0;
  padding: 12px;
  border-radius: 14px;
}

body.securemsg-android .auth-panel {
  padding: 12px;
  gap: 10px;
  background: transparent;
  border: 0;
}

body.securemsg-android .auth-panel__header {
  display: block;
}

body.securemsg-android .auth-panel__hint {
  display: none;
}

body.securemsg-android .auth-stack {
  padding: 12px;
  gap: 10px;
  border-radius: 16px;
}

body.securemsg-android .auth-grid,
body.securemsg-android .auth-grid--two,
body.securemsg-android .button-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

body.securemsg-android label {
  gap: 6px;
}

body.securemsg-android input,
body.securemsg-android select,
body.securemsg-android textarea {
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 16px;
}

body.securemsg-android .primary-button,
body.securemsg-android .secondary-button,
body.securemsg-android .danger-button,
body.securemsg-android .ghost-button {
  min-height: 44px;
}

body.securemsg-android .contacts-layout,
body.securemsg-android .settings-layout {
  grid-template-columns: 1fr !important;
  gap: 10px;
}

body.securemsg-android .content-panel {
  padding: 12px;
  border-radius: 0;
  box-shadow: none;
}

body.securemsg-android .workspace {
  min-height: var(--securemsg-viewport-height);
  height: var(--securemsg-viewport-height);
  gap: 0;
}

body.securemsg-android:not([data-page="chat"]) .workspace {
  height: auto;
  min-height: var(--securemsg-viewport-height);
}

body.securemsg-android .workspace-header {
  min-height: var(--android-toolbar-height);
  padding: calc(14px + env(safe-area-inset-top, 0px)) 14px 12px;
  border-radius: 0;
  border-width: 0 0 1px;
  box-shadow: none;
}

body.securemsg-android .messenger-layout {
  display: block;
  height: calc(var(--securemsg-viewport-height) - var(--android-toolbar-height));
  min-height: 0;
  overflow: hidden;
}

body.securemsg-android:not(.mobile-chat-open) .conversation-pane {
  display: grid !important;
  height: 100%;
}

body.securemsg-android:not(.mobile-chat-open) .chat-pane {
  display: none !important;
}

body.securemsg-android.mobile-chat-open .conversation-pane {
  display: none !important;
}

body.securemsg-android.mobile-chat-open .chat-pane {
  display: grid !important;
  height: 100%;
  grid-template-rows: auto auto minmax(0, 1fr);
}

body.securemsg-android .chat-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
}

body.securemsg-android .chat-header__identity {
  display: grid;
  grid-template-columns: 42px 42px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

body.securemsg-android .chat-header__actions {
  display: grid;
  grid-template-columns: repeat(3, 42px);
  gap: 6px;
  justify-content: end;
  width: 100%;
}

body.securemsg-android .chat-header__meta h2,
body.securemsg-android .chat-header__meta p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.securemsg-android {
  font-size: 16px;
}

body.securemsg-android .workspace-header {
  min-height: var(--android-toolbar-height);
  padding: calc(14px + env(safe-area-inset-top, 0px)) 14px 12px;
}

body.securemsg-android .messenger-layout {
  height: calc(var(--securemsg-viewport-height) - var(--android-toolbar-height));
}

body.securemsg-android .conversation-pane,
body.securemsg-android .chat-pane,
body.securemsg-android .content-panel,
body.securemsg-android .empty-panel {
  padding: 14px;
}

body.securemsg-android .section-label {
  font-size: 13px;
  margin-bottom: 4px;
}

body.securemsg-android .pane-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

body.securemsg-android .search-field input,
body.securemsg-android input,
body.securemsg-android select,
body.securemsg-android textarea {
  min-height: 48px;
  font-size: 16px;
}

body.securemsg-android .segmented-control {
  gap: 8px;
}

body.securemsg-android .segment {
  min-height: 42px;
  padding: 0 14px;
  font-size: 14px;
}

body.securemsg-android .conversation-list,
body.securemsg-android .results-list {
  gap: 10px;
}

body.securemsg-android .conversation-row,
body.securemsg-android .results-card,
body.securemsg-android .empty-panel {
  border-radius: 18px;
}

body.securemsg-android .conversation-row,
body.securemsg-android .results-card {
  min-height: 72px;
  padding: 14px;
}

body.securemsg-android .conversation-row__title {
  font-size: 16px;
}

body.securemsg-android .conversation-row__preview,
body.securemsg-android .muted-text,
body.securemsg-android .status-line {
  font-size: 14px;
}

body.securemsg-android .empty-panel {
  min-height: 120px;
}

body.securemsg-android .icon-button,
body.securemsg-android .primary-button--icon {
  width: 52px;
  height: 52px;
  min-width: 52px;
  min-height: 52px;
}

body.securemsg-android .composer-row {
  grid-template-columns: 48px 58px 48px minmax(0, 1fr) 48px;
}

.fatal-screen {
  min-height: var(--securemsg-viewport-height);
  padding: 16px;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.fatal-card {
  width: min(100%, 420px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.fatal-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  line-height: 1.15;
}

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at top left, rgba(108, 168, 255, 0.18), transparent 32%),
    linear-gradient(135deg, #f5f9ff, #eaf4ff);
}

.app-ready .boot-screen {
  display: none;
}

.boot-card {
  width: min(100%, 420px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.boot-card h1 {
  margin: 0 0 8px;
  font-size: 24px;
  line-height: 1.12;
}

.boot-card p:last-child {
  margin-bottom: 0;
  color: var(--muted);
}

.boot-card--error {
  border-color: rgba(255, 107, 107, 0.4);
}

/* Messenger product pass: stable grids, message clusters, and non-overlapping composer/history. */
.messenger-layout {
  align-items: stretch;
}

.conversation-pane,
.chat-pane {
  background-clip: padding-box;
}

.conversation-list {
  padding: 2px;
  grid-auto-rows: min-content;
}

.conversation-row {
  min-height: 70px;
  overflow: hidden;
  border: 1px solid rgba(214, 228, 242, 0.86);
}

.conversation-row__top,
.conversation-row__bottom {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.conversation-row__meta {
  min-width: 0;
}

.conversation-row.active {
  background: linear-gradient(180deg, #ffffff, #f7fbff);
}

.chat-header {
  min-height: 76px;
  padding-bottom: 2px;
}

.chat-header__identity {
  min-width: 0;
  overflow: hidden;
}

.chat-header__actions {
  margin-left: auto;
}

.call-alert-banner {
  align-items: flex-start;
}

.call-alert-banner .secondary-button {
  width: 100%;
}

.chat-header__meta h2 {
  font-size: 19px;
}

.chat-header__meta p {
  color: var(--muted);
}

.chat-workspace {
  overflow: hidden;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding: 14px;
  scroll-behavior: smooth;
}

.message-day {
  position: sticky;
  top: 6px;
  z-index: 1;
  align-self: center;
  margin: 8px 0;
  box-shadow: 0 8px 18px rgba(91, 131, 178, 0.08);
}

.message-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
}

.message-item.outgoing {
  align-items: flex-end;
}

.message-item--clustered {
  margin-top: -2px;
}

.message-item:not(.message-item--clustered) {
  margin-top: 8px;
}

.message-meta {
  max-width: min(76%, 680px);
  padding: 0 4px;
}

.message-handle {
  color: var(--muted);
}

.message-bubble {
  width: fit-content;
  max-width: min(76%, 680px);
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(214, 228, 242, 0.76);
  box-shadow: 0 10px 24px rgba(74, 137, 220, 0.08);
}

.message-item.incoming .message-bubble {
  border-top-left-radius: 8px;
}

.message-item.outgoing .message-bubble {
  border-top-right-radius: 8px;
}

.message-item--clustered.incoming .message-bubble {
  border-top-left-radius: 16px;
}

.message-item--clustered.outgoing .message-bubble {
  border-top-right-radius: 16px;
}

.message-bubble__content {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.message-text {
  font-size: 14px;
  line-height: 1.46;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-footer {
  margin-top: 2px;
  min-width: 0;
  align-self: end;
  opacity: 0.82;
}

.media-card,
.call-card {
  max-width: 100%;
  overflow: hidden;
}

.media-card .secondary-button,
.media-card .secondary {
  justify-self: start;
}

.message-empty-state {
  min-height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

.message-empty-state__icon {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  box-shadow: 0 16px 28px rgba(74, 137, 220, 0.22);
}

.message-empty-state h3,
.message-empty-state p {
  margin: 0;
}

.composer {
  position: relative;
  z-index: 2;
  border: 1px solid rgba(214, 228, 242, 0.9);
  box-shadow: 0 12px 28px rgba(74, 137, 220, 0.1);
}

.composer-row {
  display: grid;
  grid-template-columns: 48px 58px 48px minmax(0, 1fr) 48px;
  gap: 10px;
  align-items: end;
}

.composer-field textarea {
  display: block;
  overflow: auto;
  line-height: 1.35;
}

.call-panel {
  flex-wrap: wrap;
  border: 1px solid rgba(108, 168, 255, 0.24);
}

.call-panel__meta {
  min-width: min(100%, 260px);
}

.call-panel__actions {
  margin-left: auto;
}

.call-panel__toolbar {
  min-width: min(100%, 320px);
}

@media (max-width: 860px) {
  .message-list {
    padding: 10px;
  }

  .message-meta,
  .message-bubble {
    max-width: 94%;
  }

  .chat-header {
    min-height: 0;
  }

  .call-panel__actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .call-panel__toolbar {
    width: 100%;
    margin-left: 0;
  }

  .call-select {
    flex: 1 1 150px;
  }

  .call-video-stage {
    grid-template-columns: 1fr;
    width: 100%;
    margin-left: 0;
  }

  #local-call-video {
    max-width: 140px;
  }
}

.message-list {
  gap: 4px;
}

.message-bubble {
  max-width: min(68%, 560px);
  padding: 7px 9px 5px;
  gap: 4px;
  border-radius: 14px;
}

.message-text {
  font-size: 13px;
  line-height: 1.34;
}

.message-footer {
  gap: 5px;
  font-size: 10.5px;
}

/* Keep the composer controls on one row and give the message field the full remaining width. */
.composer-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
}

.composer-field,
.composer-field textarea {
  width: 100%;
  min-width: 0;
}

.composer-field {
  order: 0;
  flex: 1 1 auto;
}

.composer-row > .icon-button,
.composer-row > .primary-button--icon {
  flex: 0 0 48px;
}

.composer-row > #pick-gif {
  flex-basis: 58px;
}

body.securemsg-android .composer-row {
  display: flex;
}

@media (max-width: 640px) {
  .composer-row,
  body.securemsg-android .composer-row {
    gap: 8px;
  }

  .composer-row > .icon-button,
  .composer-row > .primary-button--icon {
    flex-basis: 44px;
  }

  .composer-row > #pick-gif {
    flex-basis: 52px;
  }
}

/* Product pass: stabilize video-call layout, mobile sizing, and fullscreen controls. */
.call-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid rgba(108, 168, 255, 0.24);
}

.call-panel__header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.call-panel__meta {
  min-width: 0;
  flex: 1 1 320px;
}

.call-panel__meta h3 {
  margin: 0 0 6px;
  font-size: 20px;
  line-height: 1.2;
}

.call-panel__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.call-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(108, 168, 255, 0.24);
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.call-chip--subtle {
  color: var(--muted);
}

.call-chip[data-tone="ringing"] {
  border-color: rgba(108, 168, 255, 0.34);
  color: var(--accent-strong);
  background: rgba(108, 168, 255, 0.18);
}

.call-chip[data-tone="connecting"] {
  border-color: rgba(255, 196, 107, 0.32);
  color: #8a5b00;
  background: rgba(255, 216, 153, 0.24);
}

.call-chip[data-tone="success"] {
  border-color: rgba(83, 173, 123, 0.32);
  color: #2e7a4f;
  background: rgba(102, 196, 140, 0.18);
}

.call-chip[data-tone="warning"] {
  border-color: rgba(232, 126, 84, 0.32);
  color: #b05a3f;
  background: rgba(255, 178, 145, 0.18);
}

.call-chip[data-tone="error"] {
  border-color: rgba(255, 107, 107, 0.34);
  color: #a54343;
  background: rgba(255, 160, 160, 0.2);
}

.call-notice {
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 196, 107, 0.28);
  background: rgba(255, 244, 214, 0.82);
  color: #7f5600;
  font-size: 13px;
  line-height: 1.45;
}

.call-video-stage {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  height: clamp(240px, 42vw, 560px);
  min-height: clamp(240px, 42vw, 560px);
  max-width: 780px;
  margin: 0 auto;
  padding: 0;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid rgba(108, 168, 255, 0.18);
  background: linear-gradient(180deg, rgba(10, 14, 24, 0.98), rgba(16, 22, 36, 0.98));
  box-shadow: 0 22px 46px rgba(10, 15, 28, 0.24);
}

.call-video-stage[data-stage-size="compact"] {
  max-width: 560px;
  height: clamp(220px, 32vw, 420px);
}

.call-video-stage[data-stage-size="standard"] {
  max-width: 780px;
  height: clamp(240px, 42vw, 560px);
}

.call-video-stage[data-stage-size="theater"] {
  max-width: 100%;
  height: clamp(280px, 52vw, 680px);
}

.call-video-stage__remote-frame,
.call-video-stage__local-frame {
  position: relative;
  overflow: hidden;
}

.call-video-stage__remote-frame {
  min-height: inherit;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, rgba(18, 24, 38, 0.98), rgba(10, 14, 24, 0.98));
}

.call-video-stage__remote-frame video {
  width: 100%;
  height: 100%;
  min-height: inherit;
  display: block;
  aspect-ratio: auto;
  object-fit: cover;
  background: transparent;
  border-radius: 0;
}

.call-video-stage__local-frame {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: clamp(112px, 22%, 188px);
  aspect-ratio: 3 / 4;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(10, 14, 24, 0.96);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.3);
  z-index: 2;
}

.call-video-stage__local-frame video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  aspect-ratio: auto;
  border-radius: 18px;
  background: transparent;
}

.call-video-stage__placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  text-align: center;
  color: rgba(233, 240, 255, 0.82);
  font-size: 14px;
  line-height: 1.45;
  background:
    radial-gradient(circle at top, rgba(63, 112, 196, 0.3), transparent 48%),
    linear-gradient(180deg, rgba(18, 24, 38, 0.96), rgba(10, 14, 24, 0.98));
}

.call-video-stage[data-remote-video="ready"] #remote-call-placeholder,
.call-video-stage[data-local-video="ready"] #local-call-placeholder {
  display: none;
}

.call-panel__footer {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 14px;
  align-items: start;
}

.call-panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-left: 0;
}

.call-panel__actions > button {
  flex: 1 1 150px;
}

.call-panel__toolbar {
  display: grid;
  gap: 12px;
  min-width: 0;
  width: 100%;
  margin-left: 0;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(108, 168, 255, 0.2);
  background: rgba(255, 255, 255, 0.72);
}

.call-panel__toolbar-meta {
  display: grid;
  gap: 4px;
}

.call-panel__toolbar-title {
  margin: 0;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.call-panel__settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  align-items: end;
}

.call-select {
  min-width: 0;
}

.call-select span {
  font-weight: 700;
}

.call-select select {
  width: 100%;
}

.call-panel[data-mode="audio"] .call-video-stage {
  height: auto;
  min-height: 0;
  aspect-ratio: auto;
}

.call-video-stage:fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  min-height: 100vh;
  border: 0;
  border-radius: 0;
  background: rgba(6, 9, 16, 0.99);
}

.call-video-stage:fullscreen .call-video-stage__remote-frame,
.call-video-stage:fullscreen .call-video-stage__remote-frame video {
  min-height: 100vh;
  height: 100vh;
}

.call-video-stage:fullscreen .call-video-stage__local-frame {
  right: 28px;
  bottom: 28px;
  width: min(24vw, 280px);
}

body.call-video-stage--fallback-fullscreen {
  overflow: hidden;
}

body.call-video-stage--fallback-fullscreen .call-panel {
  position: fixed;
  inset: 0;
  z-index: 80;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: rgba(6, 9, 16, 0.99);
}

body.call-video-stage--fallback-fullscreen .call-panel__header,
body.call-video-stage--fallback-fullscreen .call-panel__footer {
  position: absolute;
  left: 16px;
  right: 16px;
  z-index: 3;
  padding: 12px;
  border-radius: 18px;
  background: rgba(8, 12, 22, 0.78);
  backdrop-filter: blur(14px);
}

body.call-video-stage--fallback-fullscreen .call-panel__header {
  top: 16px;
}

body.call-video-stage--fallback-fullscreen .call-panel__footer {
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  grid-template-columns: minmax(0, 1fr);
}

body.call-video-stage--fallback-fullscreen .call-notice {
  position: absolute;
  top: 112px;
  left: 16px;
  right: 16px;
  z-index: 3;
}

body.call-video-stage--fallback-fullscreen .call-video-stage {
  width: 100vw;
  height: 100vh;
  max-width: none;
  min-height: 100vh;
  border: 0;
  border-radius: 0;
}

body.call-video-stage--fallback-fullscreen .call-video-stage__remote-frame,
body.call-video-stage--fallback-fullscreen .call-video-stage__remote-frame video {
  min-height: 100vh;
  height: 100vh;
}

body.call-video-stage--fallback-fullscreen .call-video-stage__local-frame {
  right: 20px;
  bottom: calc(130px + env(safe-area-inset-bottom, 0px));
  width: min(24vw, 240px);
}

@media (max-width: 980px) {
  .chat-header {
    gap: 12px;
  }

  .chat-header__actions {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .chat-header__meta h2,
  .chat-header__meta p {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  .call-panel__footer {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  .call-panel {
    padding: 14px;
    gap: 12px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .call-panel__header {
    gap: 10px;
  }

  .call-panel__badges {
    justify-content: flex-start;
  }

  .call-video-stage {
    height: min(52vh, 360px);
    min-height: min(52vh, 360px);
    max-width: 100%;
  }

  .call-video-stage__local-frame {
    right: 12px;
    bottom: 12px;
    width: 120px;
  }

  .call-panel__actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .call-panel__actions > button {
    min-height: 52px;
  }

  .call-panel__settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .chat-pane {
    gap: 8px;
  }

  .chat-header {
    min-height: 0;
    padding-bottom: 0;
  }

  .chat-header__actions {
    justify-content: space-between;
  }

  .call-chip {
    min-height: 30px;
    font-size: 11px;
  }

  .call-panel__actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #hangup-call {
    grid-column: 1 / -1;
  }

  .call-panel__settings-grid {
    grid-template-columns: 1fr;
  }

  .call-video-stage {
    height: min(46vh, 300px);
    min-height: min(46vh, 300px);
  }

  .call-video-stage__local-frame {
    width: 104px;
  }

  .call-video-stage__placeholder {
    font-size: 13px;
    padding: 16px;
  }

  body.call-video-stage--fallback-fullscreen .call-panel__header,
  body.call-video-stage--fallback-fullscreen .call-panel__footer,
  body.call-video-stage--fallback-fullscreen .call-notice {
    left: 10px;
    right: 10px;
  }

  body.call-video-stage--fallback-fullscreen .call-video-stage__local-frame {
    right: 12px;
    width: 104px;
  }
}

.chat-security-banner {
  display: grid;
  gap: 8px;
  margin: 0 24px 14px;
}

.group-pinned-banner {
  margin: 0 24px 14px;
}

.group-pinned-banner__card {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(108, 168, 255, 0.22);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow-soft);
}

.group-pinned-banner__meta {
  display: grid;
  gap: 4px;
}

.call-alert-banner {
  pointer-events: none;
}

.call-alert-banner .secondary-button {
  pointer-events: auto;
}

.chat-security-banner__item {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(108, 168, 255, 0.22);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow-soft);
}

.chat-security-banner__item strong {
  font-size: 12px;
}

.chat-security-banner__item span {
  color: var(--muted);
  font-size: 12px;
}

.chat-security-banner__item[data-tone="warning"] {
  border-color: rgba(255, 107, 107, 0.28);
  background: rgba(255, 107, 107, 0.08);
}

.chat-security-banner__item[data-tone="neutral"] {
  border-color: rgba(30, 42, 58, 0.12);
  background: rgba(255, 255, 255, 0.92);
}

.voice-preview {
  display: grid;
  gap: 8px;
}

.voice-preview-card,
.voice-note-card {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid rgba(108, 168, 255, 0.2);
  background: rgba(255, 255, 255, 0.86);
}

.voice-preview-card--recording {
  border-color: rgba(255, 107, 107, 0.3);
  background: rgba(255, 107, 107, 0.08);
}

.voice-preview-card__meta,
.voice-note-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.voice-waveform {
  display: flex;
  align-items: end;
  gap: 3px;
  min-height: 42px;
}

.voice-waveform__bar {
  display: block;
  width: 6px;
  min-height: 8%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(108, 168, 255, 0.92), rgba(74, 137, 220, 0.42));
}

.voice-note-card audio,
.voice-preview-card audio {
  width: 100%;
}

.icon-button.is-recording {
  color: #d64545;
  background: rgba(255, 107, 107, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 107, 107, 0.25);
}

.conversation-tag--warning {
  color: #a84343;
  background: rgba(255, 107, 107, 0.14);
}

.conversation-tag--trust {
  color: #2b5ca8;
  background: rgba(108, 168, 255, 0.16);
}

.results-card--security[data-tone="warning"] {
  border-color: rgba(255, 107, 107, 0.24);
}

.results-card--security[data-tone="error"] {
  border-color: rgba(255, 107, 107, 0.38);
  background: rgba(255, 107, 107, 0.08);
}

.app-lock-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(108, 168, 255, 0.24), transparent 45%),
    rgba(245, 249, 255, 0.96);
  backdrop-filter: blur(18px);
}

.app-lock-screen__card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border-radius: 24px;
  border: 1px solid rgba(108, 168, 255, 0.22);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.app-lock-screen__card input {
  font-size: 18px;
  letter-spacing: 0.18em;
  text-align: center;
}

body.app-locked {
  overflow: hidden;
}

body[data-page="chat"] {
  overflow: hidden;
}

body[data-page="chat"].theme-blue .app-shell {
  width: 100vw;
  min-height: 100vh;
  height: 100vh;
  padding: 0;
  gap: 0;
}

body[data-page="chat"] .app-sidebar {
  top: 0;
  height: 100vh;
  border-radius: 0;
}

body[data-page="chat"] .workspace {
  height: 100vh;
  min-height: 0;
  gap: 0;
}

body[data-page="chat"] .workspace-header {
  position: static;
  min-height: 44px;
  padding: 6px 12px;
  border-radius: 0;
  border-width: 0 0 1px;
  box-shadow: none;
}

body[data-page="chat"] .workspace-header__left > div,
body[data-page="chat"] .workspace-profile,
body[data-page="chat"] #chat-zone-badge,
body[data-page="chat"] .pane-header > div:first-child,
body[data-page="chat"] #chat-subtitle {
  display: none;
}

body[data-page="chat"] .chat-zone-switch {
  margin-left: auto;
}

body[data-page="chat"] .messenger-layout {
  min-height: 0;
  height: calc(100vh - 44px);
  gap: 0;
}

body[data-page="chat"] .conversation-pane,
body[data-page="chat"] .chat-pane {
  border-radius: 0;
  padding: 12px;
  box-shadow: none;
}

body[data-page="chat"] .conversation-pane {
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 10px;
}

body[data-page="chat"] .pane-header {
  min-height: 0;
  gap: 8px;
}

body[data-page="chat"] .chat-pane {
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
}

body[data-page="chat"] .chat-header {
  min-height: 48px;
  padding-bottom: 0;
}

body[data-page="chat"] .chat-security-banner {
  display: none !important;
}

body[data-page="chat"] .chat-security-banner__item {
  min-width: max-content;
  padding: 6px 8px;
}

body[data-page="chat"] .chat-security-banner__item span {
  display: none;
}

body[data-page="chat"] .message-list {
  border-radius: 14px;
}

.message-list {
  scroll-padding-top: 140px;
  scroll-padding-bottom: 140px;
  padding-bottom: 120px;
}

@media (max-width: 860px) {
  body[data-page="chat"] .workspace-header {
    min-height: 44px;
  }

  body[data-page="chat"] .messenger-layout {
    height: calc(var(--securemsg-viewport-height) - 44px);
  }

  .chat-security-banner {
    margin: 0 16px 12px;
  }

  .voice-waveform__bar {
    width: 5px;
  }
}
