:root {
  --bg-deep: #0b1320;
  --bg-mid: #132235;
  --bg-glow: rgba(76, 138, 231, 0.18);
  --surface-dark: rgba(13, 22, 36, 0.76);
  --surface-dark-soft: rgba(255, 255, 255, 0.04);
  --surface-light: rgba(255, 255, 255, 0.92);
  --surface-light-strong: #ffffff;
  --surface-soft: #f4f7fb;
  --line: rgba(255, 255, 255, 0.1);
  --line-soft: #d9e3ee;
  --text: #182434;
  --text-soft: #6d8094;
  --text-dim: #90a1b3;
  --white: #f9fbff;
  --accent: #4c8ae7;
  --accent-strong: #2d70d6;
  --accent-soft: #eaf3ff;
  --success: #58c472;
  --danger: #d85d5d;
  --shadow-xl: 0 34px 90px rgba(3, 9, 20, 0.34);
  --shadow-lg: 0 18px 46px rgba(18, 37, 61, 0.14);
  --radius-xl: 30px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 18%, rgba(95, 158, 255, 0.24), transparent 24%),
    radial-gradient(circle at 82% 12%, rgba(27, 197, 189, 0.12), transparent 18%),
    radial-gradient(circle at 52% 82%, rgba(101, 120, 255, 0.08), transparent 20%),
    linear-gradient(135deg, var(--bg-deep) 0%, var(--bg-mid) 100%);
  overflow: hidden;
}

body.app-booting::before {
  content: "Палата 6";
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  color: rgba(249, 251, 255, 0.9);
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  background:
    radial-gradient(circle at 12% 18%, rgba(95, 158, 255, 0.24), transparent 24%),
    radial-gradient(circle at 82% 12%, rgba(27, 197, 189, 0.12), transparent 18%),
    radial-gradient(circle at 52% 82%, rgba(101, 120, 255, 0.08), transparent 20%),
    linear-gradient(135deg, var(--bg-deep) 0%, var(--bg-mid) 100%);
}

body.app-booting .page-shell {
  visibility: hidden;
}

body.view-login {
  overflow-y: auto;
}

body.view-app {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

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

.page-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 22px;
}

.login-screen,
.app-screen {
  min-height: calc(100vh - 44px);
  min-height: calc(100dvh - 44px);
}

body.view-app .page-shell {
  height: 100vh;
  height: 100dvh;
}

body.view-app .app-screen {
  height: calc(100vh - 44px);
  height: calc(100dvh - 44px);
}

.login-screen {
  display: grid;
  place-items: center;
}

.login-layout {
  width: min(1180px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 430px);
  gap: 22px;
  align-items: stretch;
}

.login-hero,
.login-card,
.sidebar,
.chat-panel {
  backdrop-filter: blur(18px);
}

.login-hero {
  position: relative;
  overflow: hidden;
  display: grid;
  align-content: space-between;
  gap: 28px;
  padding: 34px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at top right, rgba(91, 146, 255, 0.18), transparent 28%),
    linear-gradient(180deg, rgba(18, 31, 49, 0.92), rgba(10, 18, 31, 0.92));
  box-shadow: var(--shadow-xl);
}

.login-hero::after {
  content: "";
  position: absolute;
  inset: auto -12% -18% auto;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(76, 138, 231, 0.34), transparent 70%);
  filter: blur(10px);
  pointer-events: none;
}

.login-card {
  display: grid;
  align-content: start;
  gap: 22px;
  padding: 34px 32px;
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow-xl);
}

.login-card-top {
  display: grid;
  gap: 10px;
}

.login-card-top h2 {
  font-size: clamp(2rem, 4vw, 2.7rem);
  line-height: 0.98;
  letter-spacing: -0.05em;
}

.login-card-top p:last-child {
  color: var(--text-soft);
  line-height: 1.5;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.login-mark,
.sidebar-mark,
.preview-header-mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(180deg, #63a1ff, #3f7fe0);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.login-brand-copy,
.sidebar-topbar-copy {
  display: grid;
  gap: 4px;
}

.login-brand-copy span,
.sidebar-topbar-copy span {
  color: rgba(255, 255, 255, 0.64);
  font-size: 0.94rem;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-hero-copy {
  display: grid;
  gap: 16px;
  max-width: 620px;
}

.login-hero-copy h1 {
  color: var(--white);
  font-size: clamp(2.6rem, 4.8vw, 4.7rem);
  line-height: 0.92;
  letter-spacing: -0.06em;
}

.login-copy {
  max-width: 560px;
  color: rgba(255, 255, 255, 0.74);
  font-size: 1.05rem;
  line-height: 1.6;
}

.login-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.login-tag,
.meta-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.86);
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.87rem;
}

.login-preview {
  position: relative;
  z-index: 1;
}

.preview-phone {
  width: min(470px, 100%);
  margin-left: auto;
  padding: 18px;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.05));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.2);
}

.preview-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.preview-header-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
}

.preview-header-copy strong {
  display: block;
  color: var(--white);
  font-size: 1rem;
}

.preview-header-copy span {
  color: rgba(255, 255, 255, 0.58);
  font-size: 0.88rem;
}

.preview-messages {
  display: grid;
  gap: 10px;
}

.preview-bubble {
  width: fit-content;
  max-width: 82%;
  padding: 14px 16px 10px;
  border-radius: 18px;
  color: rgba(255, 255, 255, 0.92);
  line-height: 1.45;
  background: rgba(255, 255, 255, 0.1);
}

.preview-bubble span {
  display: block;
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.48);
  font-size: 0.78rem;
  text-align: right;
}

.preview-bubble.own {
  margin-left: auto;
  background: linear-gradient(180deg, rgba(76, 138, 231, 0.36), rgba(76, 138, 231, 0.24));
}

.preview-bubble.accent {
  background: linear-gradient(180deg, rgba(80, 198, 164, 0.26), rgba(80, 198, 164, 0.16));
}

.login-form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--text-soft);
  font-size: 0.92rem;
}

.field input,
.search-field input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: #fff;
  color: var(--text);
  padding: 14px 16px;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.field input:focus,
.search-field input:focus,
.composer textarea:focus {
  outline: none;
  border-color: rgba(76, 138, 231, 0.62);
  box-shadow: 0 0 0 4px rgba(76, 138, 231, 0.12);
}

.primary-button,
.ghost-button,
.reaction-chip,
.action-button {
  border: 0;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease, opacity 160ms ease;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(180deg, #5c9af0, #3f7fe0);
  font-weight: 700;
  box-shadow: 0 12px 24px rgba(63, 127, 224, 0.26);
}

.primary-button:hover,
.ghost-button:hover,
.reaction-chip:hover,
.action-button:hover {
  transform: translateY(-1px);
}

.ghost-button {
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--text);
  background: rgba(16, 28, 43, 0.06);
}

.ghost-button.recording,
#voice-button.recording {
  color: #fff;
  background: var(--danger);
}

.form-error {
  min-height: 24px;
  margin-top: 2px;
  color: #c94949;
  line-height: 1.45;
}

.app-screen {
  max-width: 1480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
  min-height: 0;
  overflow: hidden;
}

.app-screen.sidebar-closed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(10, 18, 30, 0.88), rgba(8, 14, 24, 0.92));
  box-shadow: var(--shadow-xl);
  color: var(--white);
  overflow: hidden;
  transition: opacity 180ms ease, transform 180ms ease;
}

.app-screen.sidebar-closed .sidebar {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-18px);
}

.room-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background:
    radial-gradient(circle at top right, rgba(76, 138, 231, 0.22), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.03));
}

.sidebar-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  color: var(--white);
  background: rgba(255, 255, 255, 0.08);
  font-size: 1.6rem;
  line-height: 1;
}

.room-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.profile-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: var(--surface-dark-soft);
}

.profile-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.profile-name {
  font-size: 1.06rem;
  font-weight: 700;
}

.profile-status {
  color: rgba(255, 255, 255, 0.56);
  font-size: 0.9rem;
}

.profile-actions,
.panel-heading,
.composer-actions,
.composer-tools,
.composer-submit {
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-actions {
  flex-wrap: wrap;
}

.sidebar .ghost-button {
  color: var(--white);
  background: rgba(255, 255, 255, 0.06);
}

.panel-block {
  display: grid;
  gap: 10px;
  min-height: 0;
  padding: 14px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.03);
}

.panel-heading {
  justify-content: space-between;
}

.panel-heading h2 {
  font-size: 0.93rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--white);
  background: rgba(76, 138, 231, 0.92);
  font-size: 0.76rem;
  font-weight: 700;
}

.stack-list {
  display: grid;
  gap: 6px;
  align-content: start;
  overflow-y: auto;
}

.users-panel {
  grid-template-rows: auto minmax(0, 1fr);
}

.users-list {
  min-height: 0;
  padding-right: 4px;
  overscroll-behavior: contain;
}

.pin-item,
.user-item {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  transition: background 160ms ease, border-color 160ms ease;
}

.user-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.08);
}

.pin-preview,
.user-meta {
  color: rgba(255, 255, 255, 0.62);
  font-size: 0.86rem;
  line-height: 1.4;
}

.user-item {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
}

.user-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: rgba(255, 255, 255, 0.56);
  font-size: 0.74rem;
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
}

.status-pill.online {
  color: #81d795;
}

.status-pill.online::before {
  background: #81d795;
}

.chat-panel {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
  overflow: hidden;
  border-radius: 28px;
  background: rgba(249, 251, 255, 0.94);
  box-shadow: var(--shadow-xl);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.78);
}

.chat-header-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-info-button {
  all: unset;
  display: grid;
  gap: 1px;
  cursor: pointer;
  text-align: left;
}

.chat-header-copy {
  display: grid;
  gap: 2px;
}

.chat-presence {
  color: var(--text-soft);
  font-size: 0.84rem;
  line-height: 1.2;
}

.sidebar-toggle {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 14px;
  color: var(--text);
  background: #eef4fa;
  font-size: 1rem;
  transition: transform 160ms ease, background 160ms ease;
}

.sidebar-toggle:hover {
  transform: translateY(-1px);
  background: #e3edf8;
}

.search-field {
  width: min(280px, 100%);
}

.search-field input {
  background: var(--surface-soft);
  padding: 11px 14px;
}

.search-results {
  display: grid;
  gap: 8px;
  margin: 14px 18px 0;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-lg);
}

.search-results-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 6px;
  color: var(--text-soft);
}

.search-close-button {
  border: 0;
  border-radius: 999px;
  background: #eef4fa;
  color: var(--text-soft);
  min-height: 30px;
  padding: 0 12px;
  font-weight: 600;
}

.search-hit {
  all: unset;
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border-radius: 12px;
  cursor: pointer;
}

.search-hit:hover {
  background: #eff5fb;
}

.pins-bar {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.74);
}

.pins-bar-label {
  color: var(--text-soft);
  font-size: 0.84rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.pins-bar-list {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  min-width: 0;
  padding-bottom: 2px;
}

.pin-strip-button {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid #d9e5f2;
  border-radius: 999px;
  background: #f5f9fd;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.pin-strip-author {
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

.pin-strip-text {
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 14px 18px 0;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid #cae0fb;
  background: #edf6ff;
}

.composer .reply-bar {
  margin: 0;
  border-radius: 18px;
}

.reply-bar p {
  margin-top: 4px;
  color: var(--text-soft);
}

.messages-list {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  padding: 20px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 22px 22px, rgba(103, 139, 173, 0.12) 2px, transparent 2px),
    radial-gradient(circle at 74px 74px, rgba(103, 139, 173, 0.08) 2px, transparent 2px),
    linear-gradient(180deg, #ebf2f8 0%, #e2ebf3 100%);
  background-size: 96px 96px, 96px 96px, cover;
}

.empty-state {
  width: min(460px, 100%);
  margin: auto;
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 28px 26px;
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.empty-state-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.empty-state h3 {
  font-size: 1.3rem;
}

.empty-state p {
  max-width: 320px;
  color: var(--text-soft);
  line-height: 1.55;
}

.message-card {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.message-card.is-own {
  justify-content: flex-end;
}

.message-card.is-own .avatar {
  display: none;
}

.message-card.is-highlighted .message-body {
  animation: pulse-highlight 1.4s ease;
}

.message-body {
  width: fit-content;
  max-width: min(72%, 760px);
  display: grid;
  gap: 10px;
  padding: 12px 14px 10px;
  border-radius: 20px 20px 20px 8px;
  border: 1px solid rgba(201, 217, 232, 0.9);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 10px 24px rgba(41, 62, 82, 0.08);
}

.message-body.has-image {
  max-width: min(460px, 72vw);
}

.message-body.media-only {
  gap: 8px;
  padding: 8px;
}

.message-card.is-own .message-body {
  margin-left: auto;
  border-radius: 20px 20px 8px 20px;
  border-color: rgba(190, 219, 255, 0.9);
  background: linear-gradient(180deg, #f2f9ff 0%, #e6f3ff 100%);
}

.message-top {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.message-author {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.message-author strong {
  font-size: 0.9rem;
  color: var(--accent-strong);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 0.74rem;
}

.message-meta-bottom {
  justify-content: flex-end;
  margin-top: 2px;
}

.message-reply {
  padding: 8px 10px;
  border-radius: 12px;
  border-left: 3px solid var(--accent);
  background: rgba(234, 243, 255, 0.9);
  color: var(--text-soft);
  font-size: 0.88rem;
}

.message-text {
  color: var(--text);
  line-height: 1.52;
  word-break: break-word;
}

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

.attachments {
  display: grid;
  gap: 10px;
}

.attachment-card {
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid rgba(203, 217, 230, 0.92);
  background: rgba(255, 255, 255, 0.92);
}

.attachment-card.attachment-card-audio {
  width: min(320px, 72vw);
  max-width: 100%;
  min-width: 220px;
  padding: 8px 10px;
  border: 1px solid rgba(203, 217, 230, 0.92);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
}

.attachment-card.attachment-card-image {
  position: relative;
  border: 0;
  border-radius: 18px;
  background: #dfe8f3;
  box-shadow: 0 8px 22px rgba(33, 52, 76, 0.12);
}

.attachment-image-link {
  display: block;
  line-height: 0;
}

.attachment-card img {
  display: block;
  width: 100%;
  max-height: min(360px, 52vh);
  object-fit: cover;
}

.attachment-image-meta {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: #f7fbff;
  background: rgba(15, 22, 34, 0.58);
  backdrop-filter: blur(10px);
  font-size: 0.76rem;
  font-weight: 600;
}

.attachment-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
}

.attachment-link {
  color: var(--accent-strong);
  text-decoration: none;
}

.attachment-link:hover {
  text-decoration: underline;
}

.reaction-row,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.reaction-chip,
.action-button {
  padding: 7px 10px;
  border-radius: 999px;
  color: var(--text-soft);
  background: #eef4fa;
  font-size: 0.8rem;
}

.reaction-chip.active {
  color: #fff;
  background: var(--accent);
}

.composer {
  display: grid;
  gap: 10px;
  padding: 12px 18px 14px;
  border-top: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.88);
}

.composer-shell {
  position: relative;
}

.composer textarea {
  min-height: 60px;
  max-height: 160px;
  padding: 14px 64px 14px 132px;
  resize: none;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.98);
}

.composer-inline-tools {
  position: absolute;
  left: 12px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.composer-icon-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  background: #eef4fa;
  font-size: 1.08rem;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.composer-icon-button:hover {
  transform: translateY(-1px);
  background: #e3edf8;
}

.composer-send-button {
  position: absolute;
  right: 12px;
  bottom: 10px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(180deg, #5c9af0, #3f7fe0);
  box-shadow: 0 10px 18px rgba(63, 127, 224, 0.22);
  font-size: 1.1rem;
}

.emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 2px 0;
}

.emoji-picker-button {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 14px;
  background: #eef4fa;
  font-size: 1.18rem;
  transition: transform 160ms ease, background 160ms ease;
}

.emoji-picker-button:hover {
  transform: translateY(-1px);
  background: #e3edf8;
}

#emoji-button.active {
  color: #fff;
  background: linear-gradient(180deg, #5c9af0, #3f7fe0);
}

#app-error.form-error {
  margin: 0;
  padding: 0 18px 14px;
}

.message-context-menu {
  position: fixed;
  z-index: 1000;
  width: min(300px, calc(100vw - 24px));
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 20px;
  border: 1px solid rgba(206, 218, 232, 0.9);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 50px rgba(17, 33, 52, 0.2);
  backdrop-filter: blur(18px);
}

.message-context-reactions {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.context-reaction-button,
.context-action-button {
  border: 0;
  border-radius: 14px;
  background: #eef4fa;
}

.context-reaction-button {
  min-height: 42px;
  font-size: 1.2rem;
}

.context-action-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 44px;
  padding: 0 14px;
  color: var(--text);
  font-weight: 600;
}

.context-action-button.danger {
  color: #c04b4b;
  background: #fff0f0;
}

.message-context-actions {
  display: grid;
  gap: 8px;
}

.reaction-popover {
  position: fixed;
  z-index: 1050;
  min-width: 180px;
  max-width: min(280px, calc(100vw - 24px));
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid rgba(206, 218, 232, 0.9);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 50px rgba(17, 33, 52, 0.18);
  backdrop-filter: blur(18px);
}

.reaction-popover-title {
  color: var(--text);
  font-weight: 700;
}

.reaction-popover-users {
  display: grid;
  gap: 6px;
}

.reaction-popover-user {
  padding: 8px 10px;
  border-radius: 12px;
  background: #eef4fa;
  color: var(--text-soft);
}

.media-library {
  position: fixed;
  inset: 0;
  z-index: 1080;
  display: grid;
  place-items: center;
  padding: 24px;
}

.media-library-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 12, 20, 0.55);
  backdrop-filter: blur(8px);
}

.media-library-card {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  max-height: min(82vh, 100%);
  display: grid;
  gap: 16px;
  padding: 20px;
  border-radius: 28px;
  background: rgba(249, 251, 255, 0.98);
  box-shadow: 0 30px 70px rgba(16, 28, 43, 0.28);
}

.media-library-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.media-library-header h3 {
  font-size: 1.4rem;
}

.media-library-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.media-filter {
  border: 1px solid #d7e4f3;
  border-radius: 999px;
  background: #f3f8fd;
  color: var(--text-soft);
  min-height: 36px;
  padding: 0 14px;
  font-weight: 600;
}

.media-filter.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(180deg, #5c9af0, #3f7fe0);
}

.media-library-list {
  min-height: 240px;
  max-height: min(56vh, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  overflow-y: auto;
  padding-right: 4px;
  overscroll-behavior: contain;
}

.media-library-item {
  text-decoration: none;
  text-align: left;
  cursor: pointer;
}

.media-library-image {
  position: relative;
  overflow: hidden;
  min-height: 180px;
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: #dfe8f3;
  box-shadow: 0 14px 34px rgba(21, 36, 55, 0.12);
}

.media-library-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-library-meta {
  position: absolute;
  right: 10px;
  bottom: 10px;
  left: 10px;
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 16px;
  color: #fff;
  background: rgba(15, 22, 34, 0.56);
  backdrop-filter: blur(10px);
  text-align: left;
}

.media-library-meta span {
  color: rgba(255, 255, 255, 0.74);
  font-size: 0.8rem;
}

.media-library-file {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 20px;
  border: 1px solid #d7e4f3;
  background: #f7fbff;
  color: var(--text);
}

.media-library-file strong {
  display: block;
  margin-bottom: 4px;
}

.media-library-file span {
  color: var(--text-soft);
  font-size: 0.84rem;
}

.media-library-file-meta {
  display: grid;
  gap: 4px;
}

.media-library-empty {
  min-height: 220px;
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 24px;
  border-radius: 24px;
  border: 1px dashed #cbd9e8;
  color: var(--text-soft);
  text-align: center;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(7, 12, 20, 0.82);
  backdrop-filter: blur(12px);
}

.image-lightbox-figure {
  max-width: min(1100px, 100%);
  max-height: min(88vh, 100%);
  display: grid;
  gap: 14px;
  margin: 0;
}

.image-lightbox img {
  display: block;
  max-width: 100%;
  max-height: calc(88vh - 56px);
  margin: 0 auto;
  border-radius: 24px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.35);
}

.image-lightbox figcaption {
  color: rgba(255, 255, 255, 0.82);
  text-align: center;
}

.image-lightbox-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  font-size: 2rem;
  line-height: 1;
}

.avatar {
  position: relative;
  overflow: hidden;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.36);
}

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

.avatar-sm {
  width: 40px;
  height: 40px;
  font-size: 0.9rem;
}

.avatar-xl {
  width: 68px;
  height: 68px;
  font-size: 1.18rem;
}

audio {
  width: 100%;
  min-width: 0;
  display: block;
}

@keyframes pulse-highlight {
  0% {
    box-shadow: 0 0 0 0 rgba(76, 138, 231, 0.24);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(76, 138, 231, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(76, 138, 231, 0);
  }
}

@media (max-width: 1080px) {
  .login-layout {
    grid-template-columns: 1fr;
  }

  .preview-phone {
    margin-left: 0;
  }

  .app-screen,
  .app-screen.sidebar-open {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .message-body {
    max-width: 82%;
  }

  .message-body.has-image {
    max-width: min(420px, 82vw);
  }
}

@media (max-width: 920px) {
  .page-shell {
    padding: 0;
  }

  body.view-app {
    overflow: hidden;
  }

  body.view-login {
    overflow-y: auto;
  }

  body.view-login .page-shell {
    height: auto;
    padding: 12px;
  }

  body.view-login .login-screen {
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    place-items: start;
  }

  body.view-login .login-layout {
    gap: 14px;
  }

  body.view-login .login-card {
    order: 1;
  }

  body.view-login .login-hero {
    order: 2;
  }

  .app-screen {
    position: relative;
    grid-template-columns: 1fr;
    height: 100%;
    min-height: 100%;
    gap: 0;
  }

  .app-screen.sidebar-closed {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    height: 100%;
    border-radius: 0;
  }

  .sidebar-backdrop {
    position: absolute;
    inset: 0;
    z-index: 15;
    display: block;
    border: 0;
    padding: 0;
    background: rgba(4, 10, 18, 0.48);
    opacity: 1;
    transition: opacity 180ms ease;
  }

  .app-screen.sidebar-closed .sidebar-backdrop {
    opacity: 0;
    pointer-events: none;
  }

  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, calc(100vw - 44px));
    height: 100%;
    z-index: 20;
    border-radius: 0 26px 26px 0;
    transform: translateX(0);
    transition: transform 180ms ease, opacity 180ms ease;
  }

  .app-screen.sidebar-closed .sidebar {
    display: grid;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-105%);
  }

  .sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

@media (max-width: 720px) {
  .login-hero,
  .login-card,
  .sidebar {
    padding: 16px;
  }

  .chat-panel {
    padding: 0;
  }

  .chat-header,
  .profile-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .search-field {
    width: 100%;
  }

  .chat-header {
    padding: 10px 12px;
    gap: 10px;
  }

  .chat-header-main {
    width: 100%;
  }

  .message-body {
    max-width: 90%;
  }

  .message-body.has-image {
    max-width: 100%;
  }

  .attachment-card.attachment-card-audio {
    width: min(100%, 280px);
    min-width: 0;
  }

  .composer {
    padding: 10px 12px 12px;
  }

  .composer textarea {
    min-height: 54px;
    padding: 12px 56px 12px 126px;
  }

  .composer-inline-tools {
    left: 10px;
    bottom: 9px;
  }

  .composer-icon-button {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }

  .composer-send-button {
    right: 10px;
    bottom: 8px;
    width: 36px;
    height: 36px;
  }

  body.view-login .login-card-top h2 {
    font-size: clamp(1.9rem, 11vw, 2.6rem);
  }

  body.view-login .login-hero-copy h1 {
    font-size: clamp(2rem, 13vw, 3.2rem);
  }

  body.view-login .preview-phone {
    width: 100%;
  }
}
