:root {
  --bg-0: #d2dde7;
  --bg-1: #e5edf5;
  --bg-2: #eff4f9;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-2: rgba(248, 252, 255, 0.7);
  --line: rgba(217, 228, 238, 0.7);
  --text: #1e2c3b;
  --muted: #6c8094;
  --primary: #3390ec;
  --primary-strong: #2f83d6;
  --incoming: #ffffff;
  --outgoing: #d9fdd3;
  --sidebar-surface: rgba(255, 255, 255, 0.88);
  --sidebar-active: #dcedff;
  --sidebar-hover: rgba(51, 144, 236, 0.1);
  --message-tail-incoming: #ffffff;
  --message-tail-outgoing: #d9fdd3;
  --ok: #1c9a52;
  --warn: #b17109;
  --danger: #cc4a46;
  --shadow: 0 24px 60px rgba(18, 33, 52, 0.16);
  --glass-highlight: rgba(255, 255, 255, 0.46);
  --safe-top: env(safe-area-inset-top);
  --safe-right: env(safe-area-inset-right);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --app-height: 100vh;
}

:root[data-theme="dark"] {
  --bg-0: #0d1620;
  --bg-1: #101b27;
  --bg-2: #122131;
  --surface: rgba(20, 32, 45, 0.9);
  --surface-2: rgba(18, 29, 41, 0.88);
  --line: rgba(93, 121, 146, 0.28);
  --text: #edf4fb;
  --muted: #9bb1c4;
  --primary: #59a8ff;
  --primary-strong: #3d91f1;
  --incoming: #182533;
  --outgoing: #244c3b;
  --sidebar-surface: rgba(19, 31, 43, 0.94);
  --sidebar-active: rgba(73, 149, 232, 0.22);
  --sidebar-hover: rgba(89, 168, 255, 0.12);
  --message-tail-incoming: #182533;
  --message-tail-outgoing: #244c3b;
  --shadow: 0 22px 52px rgba(0, 0, 0, 0.4);
  --glass-highlight: rgba(255, 255, 255, 0.04);
}

@supports (height: 100dvh) {
  :root {
    --app-height: 100dvh;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

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

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  min-height: var(--app-height);
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(1200px 420px at 18% -30%, rgba(51, 144, 236, 0.24) 0%, transparent 58%),
    radial-gradient(1020px 360px at 98% -20%, rgba(74, 172, 238, 0.16) 0%, transparent 54%),
    radial-gradient(480px 480px at 72% 18%, rgba(255, 255, 255, 0.38) 0%, transparent 72%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 52%, var(--bg-0) 100%);
}

body::before,
body::after {
  content: "";
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(18px);
  opacity: 0.9;
}

body::before {
  width: 320px;
  height: 320px;
  top: 72px;
  left: -90px;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.72), rgba(86, 194, 255, 0.18) 55%, transparent 75%);
}

body::after {
  width: 460px;
  height: 460px;
  right: -120px;
  bottom: -120px;
  background: radial-gradient(circle at 35% 35%, rgba(255, 213, 163, 0.34), rgba(92, 163, 255, 0.18) 58%, transparent 76%);
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(1100px 420px at 8% -20%, rgba(79, 157, 255, 0.18) 0%, transparent 56%),
    radial-gradient(920px 420px at 100% -10%, rgba(28, 118, 201, 0.18) 0%, transparent 54%),
    radial-gradient(520px 520px at 76% 18%, rgba(121, 180, 255, 0.08) 0%, transparent 70%),
    linear-gradient(180deg, #0a1219 0%, #0d1721 38%, #101d29 100%);
}

:root[data-theme="dark"] body::before {
  background: radial-gradient(circle at 30% 30%, rgba(95, 168, 255, 0.22), rgba(32, 79, 125, 0.12) 55%, transparent 74%);
}

:root[data-theme="dark"] body::after {
  background: radial-gradient(circle at 35% 35%, rgba(23, 93, 160, 0.22), rgba(11, 36, 65, 0.16) 58%, transparent 76%);
}

.hidden {
  display: none !important;
}

.app-root {
  width: min(100%, 960px);
  margin: 0 auto;
  padding: 28px 16px 32px;
  min-height: var(--app-height);
  position: relative;
  isolation: isolate;
}

.app-root::before {
  content: "";
  position: fixed;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  top: 36%;
  left: 32%;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.34), rgba(120, 226, 215, 0.14) 58%, transparent 74%);
  filter: blur(20px);
  pointer-events: none;
  z-index: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(22px) saturate(1.15);
  -webkit-backdrop-filter: blur(22px) saturate(1.15);
  position: relative;
}

.card::before,
.settings-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--glass-highlight), transparent 34%);
  pointer-events: none;
}

.auth-screen {
  max-width: 430px;
  margin: 8vh auto;
  padding: 24px;
  display: grid;
  gap: 10px;
  border-radius: 20px;
  position: relative;
}

.auth-top h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sub {
  margin: 4px 0;
  color: var(--muted);
  font-size: 13px;
}

label {
  font-size: 13px;
  color: #4f6072;
}

input,
textarea,
select,
button,
summary {
  font: inherit;
  touch-action: manipulation;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  background: var(--surface);
  color: var(--text);
}

select {
  appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #96c6f2;
  box-shadow: 0 0 0 3px rgba(42, 139, 231, 0.15);
}

button {
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: var(--primary);
  transition: transform 0.1s ease, background-color 0.15s ease;
}

button:hover {
  background: var(--primary-strong);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(208, 223, 235, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

button.ghost:hover {
  background: rgba(255, 255, 255, 0.88);
}

.status {
  min-height: 18px;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.status.ok {
  color: var(--ok);
}

.status.warn {
  color: var(--warn);
}

.status.error {
  color: var(--danger);
}

.app-screen {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 0;
  width: 100%;
  min-height: min(1120px, calc(var(--app-height) - 56px));
  height: min(1120px, calc(var(--app-height) - 56px));
  max-height: min(1120px, calc(var(--app-height) - 56px));
  padding: 0;
  border-radius: 28px;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--sidebar-surface);
  border-right: 1px solid var(--line);
  position: relative;
  min-height: 0;
}

.sidebar-head {
  display: contents;
  position: relative;
  z-index: 30;
}

.profile-bar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
}

.profile-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(165deg, #68bdf6 0%, #3390ec 100%);
  background-size: cover;
  background-position: center;
}

.profile-avatar.has-image {
  color: transparent;
}

.profile-meta h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.profile-meta .sub {
  margin-top: 2px;
}

.search-wrap {
  position: relative;
  display: contents;
}

.search-row {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  display: flex;
  min-width: 0;
  padding: 10px 12px 8px 8px;
}

.sidebar-tabs {
  grid-column: 1;
  grid-row: 2 / 4;
  display: grid;
  align-content: start;
  gap: 8px;
  min-width: 0;
  padding: 10px 8px 10px 12px;
  border-right: 1px solid var(--line);
}

.chat-folders {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.chat-folder {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(199, 217, 233, 0.9);
  background: rgba(245, 250, 255, 0.9);
  color: #3d5870;
  font-weight: 700;
  font-size: 11px;
  line-height: 1.1;
  min-width: 0;
  padding: 7px 6px;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
}

.chat-folder:hover {
  background: rgba(228, 240, 252, 0.96);
  color: #284763;
}

.chat-folder.is-active {
  background: rgba(51, 144, 236, 0.18);
  border-color: rgba(51, 144, 236, 0.52);
  color: #14518c;
}

.search-wrap input {
  flex: 1 1 auto;
  min-width: 0;
  border-radius: 999px;
  padding: 7px 9px;
  background: rgba(241, 246, 251, 0.96);
  border-color: rgba(219, 229, 237, 0.92);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  font-size: 13px;
}

.search-row #chatSearchInput {
  width: 100%;
  min-width: 0;
  padding-right: 42px;
}

.menu-btn {
  width: 100%;
  height: 34px;
  min-width: 0;
  border-radius: 12px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  border-color: rgba(51, 144, 236, 0.5);
  background: #3390ec;
  color: #fff;
  box-shadow: 0 4px 10px rgba(51, 144, 236, 0.28);
  z-index: 3;
  font-size: 0;
}

#sidebarMenuBtn::before {
  content: "";
  width: 14px;
  height: 10px;
  display: block;
  background:
    linear-gradient(#fff 0 0) top/100% 2px no-repeat,
    linear-gradient(#fff 0 0) center/100% 2px no-repeat,
    linear-gradient(#fff 0 0) bottom/100% 2px no-repeat;
}

.search-row #sidebarMenuBtn {
  margin-left: 0;
}

#sidebarMenuBtn:hover {
  background: #2f83d6;
}

@media (min-width: 1280px) {
  .app-root {
    width: min(100%, 1220px);
  }

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

  .messages {
    padding: 18px 24px 16px;
  }
}

.sidebar-menu {
  position: absolute;
  top: 108px;
  left: 12px;
  right: auto;
  width: min(230px, calc(100% - 24px));
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 34px rgba(28, 45, 66, 0.18);
  backdrop-filter: blur(22px) saturate(1.28);
  -webkit-backdrop-filter: blur(22px) saturate(1.28);
  padding: 6px;
  display: grid;
  gap: 4px;
  z-index: 80;
}

.sidebar-menu-item {
  width: 100%;
  text-align: left;
  background: rgba(244, 248, 252, 0.88);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 600;
  padding: 9px 10px;
}

.sidebar-menu-item:hover {
  background: rgba(226, 237, 246, 0.96);
  color: var(--text);
}

.sidebar-section {
  padding: 10px 12px;
}

.sidebar-section h3 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #7c8ea0;
}

.chat-list-wrap {
  grid-column: 2;
  grid-row: 3;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.chat-list {
  min-height: 0;
  overflow-y: auto;
  align-content: start;
  gap: 1px;
  -webkit-overflow-scrolling: touch;
}

.search-section {
  display: grid;
  gap: 8px;
  padding: 8px 0 12px;
}

.search-section-title {
  padding: 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6f8498;
}

.search-user-list {
  display: grid;
  gap: 6px;
}

.search-user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 0 6px;
}

.search-user-main {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  background: transparent;
  border: 0;
  padding: 8px 6px;
  border-radius: 14px;
  color: inherit;
  text-align: left;
}

.search-user-main:hover {
  background: #eef5fb;
}

.search-user-meta {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.search-user-name {
  font-size: 14px;
  font-weight: 700;
  color: #203243;
}

.search-user-sub {
  min-width: 0;
  font-size: 12px;
  color: #6f8498;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-user-action {
  min-width: 88px;
  border-radius: 999px;
}

.empty-item {
  color: #73889b;
  font-size: 13px;
  padding: 10px;
  border: 1px dashed #cfdbe8;
  border-radius: 11px;
  background: #f8fbfe;
}

.sidebar-menu-item[data-accent="primary"] {
  background: #edf4fb;
  color: #21507f;
}

.sidebar-menu-item[data-accent="primary"]:hover {
  background: #e3eef9;
  color: #173e67;
}

:root[data-theme="dark"] .sidebar-menu {
  border-color: rgba(103, 141, 172, 0.28);
  background: rgba(13, 24, 36, 0.86);
  box-shadow: 0 20px 42px rgba(0, 0, 0, 0.38);
}

:root[data-theme="dark"] .sidebar-menu-item {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

:root[data-theme="dark"] .sidebar-menu-item:hover {
  background: rgba(89, 168, 255, 0.12);
}

:root[data-theme="dark"] .sidebar-menu-item[data-accent="primary"] {
  background: rgba(89, 168, 255, 0.14);
  color: #cfe6ff;
}

:root[data-theme="dark"] .sidebar-menu-item[data-accent="primary"]:hover {
  background: rgba(89, 168, 255, 0.2);
  color: #eef7ff;
}

:root[data-theme="dark"] .chat-folder {
  border-color: rgba(96, 128, 154, 0.56);
  background: rgba(28, 44, 60, 0.88);
  color: #b6c8d8;
}

:root[data-theme="dark"] .chat-folder:hover {
  background: rgba(46, 67, 88, 0.92);
  color: #d7e7f7;
}

:root[data-theme="dark"] .chat-folder.is-active {
  background: rgba(84, 160, 236, 0.22);
  border-color: rgba(110, 181, 251, 0.52);
  color: #dff1ff;
}


:root[data-theme="dark"] .sidebar-section h3,
:root[data-theme="dark"] .search-section-title,
:root[data-theme="dark"] .search-user-sub,
:root[data-theme="dark"] .empty-item {
  color: var(--muted);
}

:root[data-theme="dark"] .search-user-main:hover {
  background: rgba(89, 168, 255, 0.08);
}

:root[data-theme="dark"] .search-user-name {
  color: #edf4fb;
}

:root[data-theme="dark"] .empty-item {
  border-color: rgba(95, 128, 154, 0.36);
  background: rgba(13, 24, 36, 0.56);
}

:root[data-theme="dark"] .sidebar-head,
:root[data-theme="dark"] .chat-header,
:root[data-theme="dark"] .composer,
:root[data-theme="dark"] .call-panel {
  background: rgba(17, 28, 40, 0.94);
}

:root[data-theme="dark"] .search-wrap input,
:root[data-theme="dark"] .composer input,
:root[data-theme="dark"] input,
:root[data-theme="dark"] select {
  background: rgba(24, 37, 51, 0.96);
  border-color: rgba(75, 103, 126, 0.5);
  color: #edf4fb;
}

:root[data-theme="dark"] #sidebarMenuBtn {
  background: #4f9df2;
  border-color: rgba(127, 194, 255, 0.6);
  color: #fff;
}

:root[data-theme="dark"] button.ghost {
  background: rgba(26, 40, 55, 0.92);
  border-color: rgba(73, 101, 125, 0.46);
  color: #edf4fb;
}

:root[data-theme="dark"] button.ghost:hover {
  background: rgba(31, 48, 66, 0.98);
}

:root[data-theme="dark"] .chat-item.active .chat-button {
  box-shadow: inset 0 0 0 1px rgba(93, 168, 255, 0.16);
}

:root[data-theme="dark"] .chat-time,
:root[data-theme="dark"] .chat-preview {
  color: #9ab0c3;
}

:root[data-theme="dark"] .chat-avatar.online::after {
  border-color: #14212d;
}

.chat-item {
  padding: 2px 8px;
  border-radius: 18px;
}

.chat-row {
  display: block;
}

.chat-button {
  width: 100%;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: inherit;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  text-align: left;
}

.chat-button:hover {
  background: var(--sidebar-hover);
  box-shadow: none;
  transform: none;
}

.chat-item.active .chat-button {
  background: var(--sidebar-active);
}

.chat-delete {
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

.chat-avatar {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(160deg, #67b9f5 0%, #3390ec 100%);
  background-size: cover;
  background-position: center;
}

.chat-avatar.has-image {
  color: transparent;
}

.chat-avatar.online::after {
  content: "";
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #39c06b;
  border: 2px solid #fff;
}

.chat-body {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.chat-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-name {
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-pin {
  font-size: 11px;
  flex-shrink: 0;
}

.chat-time {
  font-size: 11px;
  color: #7f92a4;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.chat-muted-mark {
  font-size: 11px;
}

.chat-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #5aa8f2;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.chat-preview {
  font-size: 12px;
  color: #6d8196;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-preview-draft {
  color: #c35a2a;
  font-weight: 700;
}

.main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-height: 0;
  height: 100%;
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
}

:root[data-theme="dark"] .sidebar,
:root[data-theme="dark"] .main {
  background: rgba(12, 20, 29, 0.92);
}

.chat-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

:root[data-theme="dark"] .chat-header,
:root[data-theme="dark"] .composer,
:root[data-theme="dark"] .call-panel,
:root[data-theme="dark"] .call-panel.call-active {
  background: rgba(10, 20, 30, 0.5);
}

.chat-profile-trigger,
.chat-header-info-btn {
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
}

.chat-profile-trigger:hover,
.chat-header-info-btn:hover {
  background: transparent;
}

.mobile-back-btn {
  display: none;
  padding: 8px 11px;
  border-radius: 10px;
}

.chat-peer-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(160deg, #65b8f5 0%, #3390ec 100%);
  background-size: cover;
  background-position: center;
}

.chat-peer-avatar.has-image {
  color: transparent;
}

.chat-header-meta h2 {
  margin: 0;
  font-size: 17px;
}

.chat-header-meta .sub {
  margin-top: 1px;
  font-size: 12px;
}

.chat-header-info-btn {
  min-width: 0;
  text-align: left;
}

.call-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.call-actions button {
  padding: 8px 12px;
  border-radius: 999px;
  min-height: 35px;
}

.messages {
  min-height: 0;
  height: 100%;
  overflow: auto;
  padding: 16px 20px 14px;
  display: grid;
  align-content: start;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 14% 14%, rgba(255, 255, 255, 0.32) 0, transparent 42%),
    radial-gradient(circle at 83% 72%, rgba(255, 255, 255, 0.18) 0, transparent 40%),
    linear-gradient(180deg, rgba(222, 233, 242, 0.62) 0%, rgba(216, 229, 240, 0.52) 100%);
  transition: opacity 180ms ease, transform 180ms ease;
}

.messages.chat-switching {
  opacity: 0.42;
  transform: translateY(6px);
}

:root[data-chat-wallpaper="telegram"] .messages {
  background:
    radial-gradient(circle at 14% 14%, rgba(255, 255, 255, 0.2) 0, transparent 40%),
    radial-gradient(circle at 83% 72%, rgba(255, 255, 255, 0.14) 0, transparent 36%),
    repeating-linear-gradient(135deg, rgba(71, 145, 215, 0.11) 0 18px, rgba(104, 171, 235, 0.06) 18px 36px),
    linear-gradient(180deg, rgba(214, 230, 244, 0.78) 0%, rgba(205, 224, 239, 0.7) 100%);
}

:root[data-chat-wallpaper="night"] .messages {
  background:
    radial-gradient(circle at 12% 8%, rgba(126, 170, 214, 0.14) 0, transparent 34%),
    radial-gradient(circle at 84% 70%, rgba(63, 107, 151, 0.16) 0, transparent 38%),
    linear-gradient(180deg, rgba(16, 27, 38, 0.98), rgba(13, 21, 31, 0.98));
}

:root[data-chat-wallpaper="sunset"] .messages {
  background:
    radial-gradient(circle at 16% 18%, rgba(255, 214, 174, 0.34) 0, transparent 36%),
    radial-gradient(circle at 85% 74%, rgba(255, 164, 171, 0.22) 0, transparent 38%),
    linear-gradient(180deg, rgba(245, 227, 213, 0.9) 0%, rgba(222, 204, 230, 0.66) 48%, rgba(208, 219, 238, 0.7) 100%);
}

:root[data-theme="dark"] .messages {
  background:
    radial-gradient(circle at top left, rgba(72, 124, 174, 0.08), transparent 32%),
    radial-gradient(circle at bottom right, rgba(24, 62, 101, 0.1), transparent 36%),
    linear-gradient(180deg, rgba(13, 22, 31, 0.96), rgba(17, 27, 38, 0.98));
}

:root[data-theme="dark"][data-chat-wallpaper="telegram"] .messages {
  background:
    radial-gradient(circle at top left, rgba(90, 151, 214, 0.12), transparent 34%),
    radial-gradient(circle at bottom right, rgba(46, 90, 132, 0.2), transparent 40%),
    repeating-linear-gradient(135deg, rgba(79, 136, 192, 0.13) 0 18px, rgba(27, 57, 88, 0.18) 18px 36px),
    linear-gradient(180deg, rgba(18, 30, 42, 0.98), rgba(15, 24, 35, 0.98));
}

:root[data-theme="dark"][data-chat-wallpaper="sunset"] .messages {
  background:
    radial-gradient(circle at 16% 18%, rgba(196, 119, 91, 0.24) 0, transparent 36%),
    radial-gradient(circle at 85% 74%, rgba(129, 78, 132, 0.24) 0, transparent 40%),
    linear-gradient(180deg, rgba(40, 26, 32, 0.96) 0%, rgba(29, 28, 45, 0.94) 56%, rgba(19, 30, 43, 0.96) 100%);
}

.message {
  position: relative;
  max-width: min(760px, 74%);
  min-width: 124px;
  border: 1px solid rgba(207, 220, 231, 0.84);
  border-radius: 18px;
  padding: 9px 12px;
  background: var(--incoming);
  box-shadow: 0 5px 14px rgba(29, 47, 66, 0.08);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 1;
}

.message-new {
  animation: message-pop-in 300ms ease-out;
}

@keyframes message-pop-in {
  0% {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

:root[data-theme="dark"] .message {
  border-color: rgba(72, 101, 126, 0.42);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}

.message-heart-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.82);
  color: #d6527b;
  box-shadow: 0 8px 16px rgba(46, 67, 88, 0.14);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  cursor: pointer;
  opacity: 0;
  transform: scale(0.92);
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease, background 120ms ease;
}

.message:hover .message-heart-btn,
.message:focus-within .message-heart-btn {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.message-heart-btn:hover {
  background: rgba(255, 255, 255, 0.96);
}

.message.mine .message-heart-btn {
  right: auto;
  left: 8px;
}

:root[data-theme="dark"] .message-heart-btn {
  background: rgba(24, 37, 51, 0.96);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.26);
}

.message.quick-picker-open {
  z-index: 12;
}

.message::after {
  content: "";
  position: absolute;
  left: -7px;
  top: 12px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 7px 7px 0;
  border-color: transparent var(--message-tail-incoming) transparent transparent;
}

.message.mine {
  margin-left: auto;
  min-width: 124px;
  background: var(--outgoing);
  border-color: rgba(182, 223, 170, 0.72);
}

.message.mine::after {
  left: auto;
  right: -7px;
  border-width: 7px 0 7px 7px;
  border-color: transparent transparent transparent var(--message-tail-outgoing);
}

.message .meta {
  order: 3;
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 6px;
  font-size: 11px;
  color: #647b90;
  min-height: 12px;
}

.message .meta-right {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

.message .time {
  color: #7a8f9f;
  white-space: nowrap;
}

.message .edited {
  font-size: 10px;
  color: #7f8f9f;
  letter-spacing: 0.01em;
}

.message .author {
  display: none;
}

.message .read-status {
  display: none;
}

.message.mine .read-status {
  display: inline;
  min-width: 0;
  text-align: left;
  color: #6c7f92;
  letter-spacing: -0.02em;
  font-weight: 800;
  white-space: nowrap;
}

.message.mine .read-status.is-read {
  color: #2a8be7;
}

:root[data-theme="dark"] .message .meta,
:root[data-theme="dark"] .message .time,
:root[data-theme="dark"] .message .edited,
:root[data-theme="dark"] .message.mine .read-status {
  color: #9ab0c3;
}

:root[data-theme="dark"] .message.mine .read-status.is-read {
  color: #73b6ff;
}

.message .text {
  order: 1;
  margin: 0;
  padding-right: 0;
  font-size: 14px;
  line-height: 1.38;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message .text a {
  color: #2b7fcc;
  text-decoration: none;
}

.message .text a:hover {
  text-decoration: underline;
}

.message .text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(38, 56, 74, 0.08);
}

:root[data-theme="dark"] .message .text a {
  color: #7fc2ff;
}

:root[data-theme="dark"] .message .text code {
  background: rgba(167, 202, 239, 0.16);
}

.message .quick-reactions {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 12px;
  z-index: 3;
  display: grid;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  min-width: min(360px, calc(100vw - 40px));
  max-width: min(420px, calc(100vw - 24px));
  animation: quick-panel-in 160ms ease-out;
}

.message.mine .quick-reactions {
  left: auto;
  right: 12px;
}

.message.quick-picker-below .quick-reactions {
  top: calc(100% + 10px);
  bottom: auto;
}

.quick-reaction-shell,
.quick-action-shell {
  border: 1px solid rgba(220, 230, 239, 0.92);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 28px rgba(41, 61, 81, 0.18);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

:root[data-theme="dark"] .quick-reaction-shell,
:root[data-theme="dark"] .quick-action-shell {
  border-color: rgba(72, 101, 126, 0.46);
  background: rgba(18, 29, 41, 0.98);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.34);
}

.quick-reaction-shell {
  padding: 10px 12px;
}

.quick-action-shell {
  padding: 8px;
}

.quick-reaction-row,
.quick-action-row,
.quick-reaction-grid {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-reaction-grid {
  padding-top: 2px;
  max-height: min(220px, 42vh);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

.quick-reaction-search {
  width: 100%;
  border: 1px solid rgba(64, 125, 193, 0.14);
  border-radius: 12px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: #35506b;
}

.quick-reaction-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.quick-reaction-tab {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(64, 125, 193, 0.08);
  cursor: pointer;
}

.quick-reaction-tab.active {
  background: rgba(64, 125, 193, 0.18);
}

.quick-action-row {
  flex-direction: column;
  align-items: stretch;
}

.quick-reaction-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border: 0;
  border-radius: 999px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  background: transparent;
  color: #35506b;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.quick-reaction-btn:hover {
  background: rgba(64, 125, 193, 0.1);
  transform: translateY(-1px);
}

.quick-reaction-btn.more {
  font-size: 22px;
  font-weight: 700;
}

.quick-action-btn {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 14px;
  padding: 7px 9px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  background: rgba(64, 125, 193, 0.08);
  color: #35506b;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.quick-action-btn:hover {
  background: rgba(64, 125, 193, 0.16);
  transform: translateY(-1px);
}

.quick-action-btn:disabled {
  opacity: 0.45;
}

.quick-action-icon {
  font-size: 14px;
  line-height: 1;
}

.quick-action-label {
  line-height: 1;
}

@keyframes quick-panel-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.message .reactions {
  order: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
}

.reaction-pill {
  min-width: 0;
  border: 1px solid #cbd9e8;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  color: #496174;
  background: #edf3fa;
  cursor: pointer;
}

.reaction-pill:hover {
  background: #e4edf8;
}

.reaction-pill.active {
  border-color: #7bb3ec;
  background: #dcedff;
  color: #2a78c8;
}

.message.mine .reaction-pill {
  border-color: #bed89c;
  background: #e7f4d5;
  color: #4b6930;
}

.message.mine .reaction-pill:hover {
  background: #deefc8;
}

.message.mine .reaction-pill.active {
  border-color: #8bb866;
  background: #d4ebb8;
  color: #426923;
}

.message .attachments {
  order: 2;
  margin-top: 0;
  display: grid;
  gap: 6px;
}

.message .attachments:empty {
  display: none;
}

.message .attachments img,
.message .attachments video {
  width: 100%;
  max-width: 390px;
  border-radius: 13px;
  border: 1px solid #cfdbe6;
  background: #dfe9f3;
}

.message .attachments .media-label {
  font-size: 12px;
  color: #62798e;
}

.message .forwarded {
  margin: 0;
  font-size: 11px;
  font-weight: 800;
  color: #2a8be7;
}

.message.mine .forwarded {
  color: #4c8f28;
}

.message .reply-snippet {
  margin: 0;
  padding: 5px 8px;
  border-radius: 9px;
  border-left: 3px solid #74aee4;
  background: #eef4fb;
  font-size: 12px;
  color: #4e6276;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

:root[data-theme="dark"] .message .reply-snippet,
:root[data-theme="dark"] .message .call-snippet,
:root[data-theme="dark"] .voice-note {
  border-color: rgba(88, 122, 150, 0.44);
  background: rgba(18, 34, 47, 0.72);
}

.message.mine .reply-snippet {
  border-left-color: #8db95f;
  background: #e5f2d2;
}

:root[data-theme="dark"] .message.mine .reply-snippet,
:root[data-theme="dark"] .message.mine .call-snippet,
:root[data-theme="dark"] .message.mine .voice-note {
  border-color: rgba(80, 126, 82, 0.55);
  background: rgba(24, 53, 33, 0.72);
}

.message .call-snippet {
  margin: 0;
  padding: 7px 8px;
  border-radius: 10px;
  border: 1px solid #cddceb;
  background: #f1f7fe;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.message.mine .call-snippet {
  border-color: #c3de9d;
  background: #e7f5d4;
}

.message .call-text {
  font-size: 12px;
  color: #4d6278;
  font-weight: 700;
}

.message .call-redial {
  min-width: 0;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
}

.message.flash {
  animation: msgFlash 0.65s ease;
}

@keyframes msgFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(42, 139, 231, 0.45);
  }
  100% {
    box-shadow: 0 0 0 14px rgba(42, 139, 231, 0);
  }
}

.voice-note {
  width: min(300px, 100%);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid #c8d8e7;
  border-radius: 18px;
  padding: 8px 12px 8px 8px;
  background: #eef5fc;
}

.message.mine .voice-note {
  background: #e3f2d0;
  border-color: #c2dc9e;
}

.voice-play {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 0;
  min-width: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2a8be7;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.voice-play:hover {
  background: #1c78ce;
}

.message.mine .voice-play {
  background: #6aa736;
}

.message.mine .voice-play:hover {
  background: #5b942f;
}

.voice-wave {
  height: 24px;
  min-width: 110px;
  display: flex;
  align-items: end;
  gap: 3px;
  cursor: pointer;
}

.voice-bar {
  width: 2px;
  border-radius: 999px;
  background: #9eb9d3;
  transition: background-color 0.12s ease;
}

.voice-bar.played {
  background: #2a8be7;
}

.message.mine .voice-bar {
  background: #9db48b;
}

.message.mine .voice-bar.played {
  background: #6aa736;
}

.voice-time {
  font-size: 12px;
  color: #5f7488;
  font-weight: 700;
  min-width: 40px;
  text-align: right;
  white-space: nowrap;
}

.voice-native {
  display: none;
}

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

.pending-media {
  border-top: 1px solid var(--line);
  background: #f6f9fc;
  padding: 8px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

:root[data-theme="dark"] .pending-media {
  background: rgba(10, 21, 31, 0.72);
}

.undo-bar {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f3f8ff;
  padding: 7px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
}

:root[data-theme="dark"] .undo-bar {
  background: rgba(10, 21, 31, 0.72);
}

.undo-text {
  font-size: 13px;
  font-weight: 700;
  color: #45607a;
}

.undo-countdown {
  font-size: 12px;
  font-weight: 700;
  color: #6a7f92;
}

:root[data-theme="dark"] .undo-text,
:root[data-theme="dark"] .undo-countdown {
  color: var(--muted);
}

.reply-bar {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #edf6ff;
  padding: 7px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

:root[data-theme="dark"] .reply-bar {
  background: rgba(10, 21, 31, 0.72);
}

.reply-text {
  font-size: 12px;
  color: #496780;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

:root[data-theme="dark"] .reply-text {
  color: var(--muted);
}

.reply-cancel {
  min-width: 34px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  padding: 0;
}

.markdown-preview {
  border-top: 1px solid var(--line);
  padding: 8px 14px 10px;
  background: rgba(255, 255, 255, 0.86);
}

.markdown-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.markdown-preview-content {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 40px;
  font-size: 13px;
  line-height: 1.4;
  background: rgba(248, 252, 255, 0.9);
}

.markdown-preview-content:empty::before {
  content: "Empty";
  color: var(--muted);
}

.markdown-preview-content a {
  color: #2b7fcc;
}

.markdown-preview-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  background: rgba(38, 56, 74, 0.08);
  border-radius: 6px;
  padding: 1px 4px;
}

:root[data-theme="dark"] .markdown-preview {
  background: rgba(20, 32, 45, 0.9);
}

:root[data-theme="dark"] .markdown-preview-content {
  background: rgba(15, 24, 35, 0.88);
}

:root[data-theme="dark"] .markdown-preview-content code {
  background: rgba(167, 202, 239, 0.16);
}

.pinned-bar {
  border-bottom: 1px solid var(--line);
  background: #f2f8ff;
  padding: 7px 10px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

:root[data-theme="dark"] .pinned-bar {
  background: rgba(10, 21, 31, 0.72);
}

.pinned-label {
  font-size: 10px;
  letter-spacing: 0.05em;
  font-weight: 800;
  color: #2a8be7;
}

.pinned-text {
  font-size: 12px;
  color: #4c6177;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

:root[data-theme="dark"] .pinned-text {
  color: var(--muted);
}

.pinned-unpin {
  min-width: 0;
  padding: 5px 8px;
  font-size: 12px;
}

.context-menu {
  position: fixed;
  z-index: 4000;
  min-width: 220px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid #d2deea;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 26px rgba(27, 48, 76, 0.2);
  display: grid;
  gap: 4px;
}

:root[data-theme="dark"] .context-menu {
  border-color: rgba(99, 136, 164, 0.32);
  background: rgba(17, 28, 40, 0.98);
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.34);
}

.context-menu .context-item {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 9px;
  padding: 8px 10px;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  color: #3f566c;
  background: #f1f6fb;
}

:root[data-theme="dark"] .context-menu .context-item {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.context-menu .context-item:hover {
  background: #e4eef8;
}

.context-menu .context-item.danger {
  color: #b23838;
  background: #fff2f2;
}

.context-menu .context-item.danger:hover {
  background: #ffe8e8;
}

.forward-panel {
  position: fixed;
  inset: 0;
  z-index: 3800;
  background: rgba(17, 28, 43, 0.35);
  display: grid;
  place-items: center;
  padding: 12px;
}

.forward-card {
  width: min(380px, 100%);
  max-height: min(78vh, 680px);
  border-radius: 14px;
  border: 1px solid #cfdbe7;
  background: #fff;
  box-shadow: 0 24px 40px rgba(16, 30, 48, 0.2);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.inline-add-chat-panel {
  margin-top: 10px;
  border: 1px solid rgba(198, 214, 228, 0.9);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 30px rgba(20, 39, 61, 0.12);
  padding: 12px;
  display: grid;
  gap: 10px;
}

#addContactPanel {
  grid-column: 2;
  grid-row: 3;
  align-self: start;
  z-index: 95;
  margin: 8px 12px 0 8px;
}

.create-chat-panel-main {
  position: absolute;
  top: 128px;
  left: 32px;
  z-index: 120;
  width: min(640px, calc(100% - 64px));
  margin-top: 0;
  border-radius: 22px;
  padding: 18px;
}

.create-chat-form-grid {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.create-chat-icon-block {
  display: grid;
  gap: 8px;
  justify-items: stretch;
}

.create-chat-avatar-preview {
  width: 76px;
  height: 76px;
  justify-self: center;
  font-size: 18px;
}

.create-chat-fields {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.inline-add-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.inline-add-chat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.inline-add-chat-row input {
  min-width: 0;
}

.inline-add-chat-close {
  min-width: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
}

.inline-panel-stack {
  display: grid;
  gap: 6px;
}

:root[data-theme="dark"] .inline-add-chat-panel {
  border-color: rgba(99, 136, 164, 0.3);
  background: rgba(18, 30, 43, 0.96);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
}

.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 3900;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(9, 18, 28, 0.42);
  backdrop-filter: blur(8px);
}

.settings-card {
  width: min(560px, calc(100vw - 24px));
  max-height: min(88vh, 820px);
  overflow-y: auto;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 24px 54px rgba(11, 25, 39, 0.22);
  padding: 20px;
  display: grid;
  gap: 18px;
  position: relative;
}

:root[data-theme="dark"] .settings-card,
:root[data-theme="dark"] .settings-section,
:root[data-theme="dark"] .settings-session-item {
  background: rgba(17, 28, 40, 0.9);
}

.settings-head,
.settings-support-row,
.settings-profile {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.settings-session-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.settings-close-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
}

.settings-section {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.settings-section h4,
.settings-head h3 {
  margin: 0;
}

.settings-avatar-preview {
  width: 72px;
  height: 72px;
  font-size: 20px;
}

.settings-profile-actions {
  flex: 1;
  display: grid;
  gap: 8px;
}

.settings-sessions-list {
  display: grid;
  gap: 10px;
}

.settings-session-item {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.18);
}

.settings-session-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--text);
}

.settings-session-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: #e6f3ff;
  color: #21507f;
  font-size: 11px;
  font-weight: 800;
}

.settings-session-meta {
  font-size: 12px;
  color: var(--muted);
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
}

.profile-card {
  width: min(460px, calc(100vw - 24px));
}

.action-card {
  width: min(480px, calc(100vw - 24px));
}

.shortcuts-card {
  width: min(430px, calc(100vw - 24px));
}

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

.shortcuts-list p {
  margin: 0;
}

.folder-settings {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

.folder-settings label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.folder-settings input[type="checkbox"] {
  accent-color: var(--primary);
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid rgba(175, 194, 211, 0.9);
  background: rgba(244, 249, 255, 0.92);
  color: #27435c;
  font-size: 12px;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  text-align: center;
}

:root[data-theme="dark"] kbd {
  border-color: rgba(85, 112, 134, 0.9);
  background: rgba(30, 48, 65, 0.9);
  color: #d7e8f8;
}

.action-card textarea {
  min-height: 132px;
  resize: vertical;
  line-height: 1.45;
}

.action-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.action-panel-actions {
  justify-content: space-between;
}

.profile-hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px;
  align-items: center;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.45);
  background:
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.55), transparent 34%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.12));
}

.profile-hero::before,
.profile-hero::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
}

.profile-hero::before {
  width: 128px;
  height: 128px;
  right: -36px;
  top: -54px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.44), rgba(255, 255, 255, 0));
}

.profile-hero::after {
  width: 100px;
  height: 100px;
  left: -24px;
  bottom: -42px;
  background: radial-gradient(circle, rgba(110, 178, 255, 0.18), rgba(110, 178, 255, 0));
}

.profile-hero-avatar {
  width: 96px;
  height: 96px;
  font-size: 28px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 18px 32px rgba(65, 98, 132, 0.18);
}

.profile-hero-meta {
  min-width: 0;
  position: relative;
  z-index: 1;
}

.profile-hero-meta h4 {
  margin: 0;
  font-size: 24px;
}

.profile-hero-meta .sub {
  margin: 4px 0 0;
}

#profileStatus {
  color: #1f76d2;
  font-weight: 700;
}

.profile-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.forward-card h3 {
  margin: 0;
  font-size: 16px;
}

.forward-list {
  max-height: 46vh;
  overflow: auto;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
}

.forward-chat-btn {
  width: 100%;
  border: 1px solid #d6e2ee;
  border-radius: 10px;
  background: #f5f9fd;
  color: #3f566c;
  text-align: left;
  padding: 8px 10px;
  display: grid;
  gap: 3px;
}

.forward-chat-btn:hover {
  background: #eaf2fb;
}

.forward-chat-btn strong {
  font-size: 14px;
}

.forward-chat-btn span {
  font-size: 12px;
  color: #6c8094;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pending-item {
  border: 1px solid #cfdbe7;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  background: #eaf2fb;
  color: #3f5770;
}

.pending-item:hover {
  background: #deebf9;
}

.pending-item:active {
  transform: none;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.composer input {
  border-radius: 999px;
  padding: 12px 18px;
  border-color: rgba(216, 227, 236, 0.94);
  background: rgba(247, 250, 252, 0.98);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.composer button {
  border-radius: 999px;
  min-width: 84px;
}

.composer .composer-action {
  min-width: 0;
  padding: 9px 12px;
}

.format-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px;
  border: 1px solid rgba(205, 220, 234, 0.88);
  border-radius: 999px;
  background: rgba(245, 250, 255, 0.96);
}

.format-toolbar .format-btn {
  min-width: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  padding: 0;
  font-size: 12px;
  color: #28445d;
}

.format-toolbar .format-btn:hover {
  background: rgba(51, 144, 236, 0.16);
  color: #0f4e88;
}

:root[data-theme="dark"] .format-toolbar {
  border-color: rgba(93, 122, 148, 0.5);
  background: rgba(25, 40, 56, 0.9);
}

:root[data-theme="dark"] .format-toolbar .format-btn {
  color: #d5e4f4;
}

.icon-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon {
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.composer .composer-action.recording {
  background: #ce4a4a;
  border-color: #ce4a4a;
  color: #fff;
}

.call-panel {
  border-top: 1px solid var(--line);
  padding: 10px 12px 12px;
  background: rgba(255, 255, 255, 0.9);
}

.call-panel.call-active {
  background:
    radial-gradient(circle at top right, rgba(122, 194, 255, 0.18), transparent 38%),
    rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.call-controls {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.call-control-btn {
  min-width: 0;
  border-radius: 20px;
  border: 1px solid rgba(195, 213, 228, 0.9);
  background: rgba(255, 255, 255, 0.72);
  color: #24415a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 8px;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(30, 56, 84, 0.12);
}

:root[data-theme="dark"] .call-control-btn {
  border-color: rgba(99, 136, 164, 0.34);
  background: rgba(24, 37, 51, 0.92);
  color: #e9f2fb;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.24);
}

.call-control-btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.84);
}

:root[data-theme="dark"] .call-control-btn:hover {
  background: rgba(31, 47, 64, 0.96);
}

.call-control-btn.active {
  border-color: rgba(236, 148, 148, 0.95);
  background: rgba(255, 231, 231, 0.9);
  color: #a53b3b;
}

:root[data-theme="dark"] .call-control-btn.active {
  border-color: rgba(214, 116, 116, 0.56);
  background: rgba(92, 39, 39, 0.86);
  color: #ffd2d2;
}

.call-control-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.call-control-btn.danger {
  border-color: rgba(222, 123, 123, 0.96);
  background: linear-gradient(180deg, rgba(236, 108, 108, 0.94), rgba(206, 74, 74, 0.94));
  color: #fff;
}

.call-control-icon {
  font-size: 18px;
  line-height: 1;
}

.call-control-label {
  font-size: 11px;
  line-height: 1.1;
}

.media-wrap {
  margin-top: 8px;
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.call-panel.show-video .media-wrap {
  display: grid;
}

video {
  width: 100%;
  min-height: 120px;
  border-radius: 11px;
  border: 1px solid #ced9e5;
  background: #15283a;
}

#localVideo,
#remoteVideo {
  transform: scaleX(1) !important;
  -webkit-transform: scaleX(1) !important;
  filter: none !important;
}

@media (max-width: 1160px) {
  .app-root {
    width: min(100%, 940px);
    padding: 20px 12px 24px;
  }

  .app-screen {
    grid-template-columns: 300px minmax(0, 1fr);
    min-height: min(1040px, calc(var(--app-height) - 40px));
    height: min(1040px, calc(var(--app-height) - 40px));
    max-height: min(1040px, calc(var(--app-height) - 40px));
  }
}

@media (max-width: 980px) {
  .app-screen {
    grid-template-columns: 1fr;
    min-height: calc(var(--app-height) - 28px);
    height: calc(var(--app-height) - 28px);
    max-height: calc(var(--app-height) - 28px);
  }

  .sidebar,
  .main {
    min-height: 0;
    max-height: var(--app-height);
  }

  .mobile-back-btn {
    display: inline-block;
  }

  .app-screen:not(.chat-open) .main {
    display: none;
  }

  .app-screen.chat-open .sidebar {
    display: none;
  }

  .chat-header {
    grid-template-columns: auto auto 1fr;
  }

  .call-actions {
    grid-column: 1 / -1;
  }

  .settings-panel {
    padding: 12px;
    align-items: end;
  }

  .settings-card {
    width: 100%;
    max-height: min(92vh, 920px);
    border-radius: 24px 24px 0 0;
  }
}

@media (max-width: 680px) {
  .auth-screen {
    margin: 3vh auto;
    padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
    max-height: calc(var(--app-height) - 24px);
    overflow: auto;
  }

  .profile-bar {
    grid-template-columns: auto 1fr;
  }

  .app-root {
    width: 100%;
    padding: 0;
  }

  .app-screen {
    border-radius: 0;
    min-height: var(--app-height);
    height: var(--app-height);
    max-height: var(--app-height);
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  .composer {
    grid-template-columns: 1fr 1fr;
  }

  .composer #messageInput {
    grid-column: 1 / -1;
  }

  .format-toolbar {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .inline-add-chat-row {
    grid-template-columns: 1fr;
  }

  .create-chat-panel-main {
    top: 92px;
    left: 12px;
    width: calc(100% - 24px);
    padding: 14px;
  }

  .create-chat-form-grid {
    grid-template-columns: 1fr;
  }

  .profile-actions {
    grid-template-columns: 1fr;
  }

  .folder-settings {
    grid-template-columns: 1fr;
  }

  .composer button[type="submit"] {
    grid-column: 1 / -1;
  }

  .message {
    max-width: 90%;
  }

  .media-wrap {
    grid-template-columns: 1fr;
  }

  .call-controls {
    grid-template-columns: repeat(3, minmax(84px, 1fr));
  }
}

@media (max-width: 520px) {
  .chat-header {
    padding: 8px 10px;
  }

  .chat-header-meta h2 {
    font-size: 16px;
  }

  .chat-peer-avatar {
    width: 38px;
    height: 38px;
  }

  .call-actions {
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .call-actions button {
    min-height: 32px;
    padding: 6px 10px;
  }

  .messages {
    padding: 12px;
  }

  .composer {
    padding-bottom: 10px;
  }

  .chat-folders {
    gap: 5px;
  }
}

/* Sidebar controls */
.search-row {
  display: flex !important;
  align-items: center !important;
  min-width: 0 !important;
}

.search-row #chatSearchInput {
  flex: 1 1 auto !important;
  width: auto !important;
  min-width: 0 !important;
  padding-right: 10px !important;
}

.search-row #sidebarMenuBtn {
  position: static !important;
  transform: none !important;
}

#sidebarMenuBtn {
  background: #1f7fe0 !important;
  border-color: #1f7fe0 !important;
  font-size: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: 40 !important;
  pointer-events: auto !important;
  visibility: visible !important;
  opacity: 1 !important;
}

#sidebarMenuBtn::before {
  content: none !important;
  display: none !important;
}

#sidebarMenuBtn .hamburger-icon {
  width: 16px !important;
  display: grid !important;
  gap: 3px !important;
  visibility: visible !important;
  opacity: 1 !important;
}

#sidebarMenuBtn .hamburger-icon > span {
  display: block !important;
  height: 3px !important;
  border-radius: 99px !important;
  background: #fff !important;
  visibility: visible !important;
  opacity: 1 !important;
}

@media (min-width: 981px) {
  .search-row #chatSearchInput {
    max-width: none !important;
  }
}
