:root {
  color-scheme: light;
  --bg: #f2f5f9;
  --surface: #ffffff;
  --surface-strong: #f7f9fc;
  --surface-muted: #f4f7fb;
  --text: #111827;
  --muted: #6b7280;
  --line: #d7dee8;
  --line-soft: #e8edf4;
  --blue: #2563eb;
  --blue-dark: #1e40af;
  --green: #059669;
  --green-dark: #047857;
  --orange: #ea580c;
  --danger: #b42318;
  --danger-action-bg: #fee2e2;
  --danger-action-bg-hover: #fecaca;
  --danger-action-text: #991b1b;
  --shadow: 0 18px 42px rgba(17, 24, 39, 0.12);
  --panel-shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
  --primary-contrast: #ffffff;
  --auth-screen-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(238, 242, 246, 0.98)), var(--bg);
  --topbar-bg: rgba(255, 255, 255, 0.94);
  --panel-head-bg: #ffffff;
  --soft-bg: #e9f0ff;
  --soft-bg-hover: #deebff;
  --soft-border: #cfe0ff;
  --control-hover: #eef3f8;
  --dialog-hover-bg: #f4f8ff;
  --dialog-unread-bg: #fff8f1;
  --dialog-unread-text: #9a3412;
  --avatar-bg: #e6f6ef;
  --avatar-text: #047857;
  --message-image-bg: #e5e7eb;
  --outgoing-bg: #e8f1ff;
  --outgoing-border: #c9dcff;
  --unread-border: #fdba74;
  --unread-ring: rgba(249, 115, 22, 0.16);
  --reply-bg: rgba(255, 255, 255, 0.96);
  --reply-input-bg: #f7f9fc;
  --attachment-bg: #fbfcfe;
  --remove-bg: #fee2e2;
  --remove-text: #991b1b;
  --empty-icon-bg: #eaf1ff;
  --modal-backdrop: rgba(17, 24, 39, 0.42);
  --toast-bg: #111827;
  --toast-text: #ffffff;
  --focus-ring: rgba(37, 99, 235, 0.14);
  --primary-shadow: 0 6px 14px rgba(37, 99, 235, 0.18);
  --send-shadow: 0 6px 14px rgba(5, 150, 105, 0.16);
  --send-bg-hover: #066f52;
  --topbar-shadow: 0 1px 0 rgba(23, 32, 51, 0.02);
  --bubble-shadow: 0 3px 10px rgba(23, 32, 51, 0.06);
  --reply-shadow: 0 -8px 18px rgba(23, 32, 51, 0.05);
  --radius: 10px;
  --topbar-height: 50px;
  --settings-width: 244px;
  --app-height: 100dvh;
  --keyboard-inset: 0px;
  --visual-offset-top: 0px;
  --font-ui: 14px;
  --font-title: 16px;
  --font-message: 14px;
  --font-input: 16px;
  --font-control: 12px;
  --font-label: 12px;
  --font-caption: 11px;
  --font-meta: 9px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-font-size="compact"] {
  --font-ui: 13px;
  --font-title: 15px;
  --font-message: 13px;
  --font-input: 16px;
  --font-control: 11px;
  --font-label: 11px;
  --font-caption: 10px;
  --font-meta: 9px;
}

html[data-font-size="large"] {
  --font-ui: 16px;
  --font-title: 18px;
  --font-message: 16px;
  --font-input: 17px;
  --font-control: 13px;
  --font-label: 13px;
  --font-caption: 12px;
  --font-meta: 10px;
}

html[data-font-size="xlarge"] {
  --font-ui: 18px;
  --font-title: 20px;
  --font-message: 18px;
  --font-input: 19px;
  --font-control: 14px;
  --font-label: 14px;
  --font-caption: 13px;
  --font-meta: 11px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b111b;
  --surface: #111827;
  --surface-strong: #182233;
  --surface-muted: #0d1420;
  --text: #edf2f7;
  --muted: #9aa6b5;
  --line: #2c3748;
  --line-soft: #202b3a;
  --blue: #7aa7ff;
  --blue-dark: #5f8fe8;
  --green: #3dd59f;
  --green-dark: #18a879;
  --orange: #f59e0b;
  --danger: #fb7185;
  --danger-action-bg: #3b1d23;
  --danger-action-bg-hover: #4a222b;
  --danger-action-text: #fda4af;
  --shadow: 0 20px 55px rgba(0, 0, 0, 0.38);
  --panel-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
  --primary-contrast: #08111f;
  --auth-screen-bg: linear-gradient(180deg, rgba(15, 23, 32, 0.92), rgba(10, 16, 24, 0.98)), var(--bg);
  --topbar-bg: rgba(11, 17, 27, 0.92);
  --panel-head-bg: #111827;
  --soft-bg: #1c3153;
  --soft-bg-hover: #243c64;
  --soft-border: #35527f;
  --control-hover: #243244;
  --dialog-hover-bg: #1a2738;
  --dialog-unread-bg: #2a231c;
  --dialog-unread-text: #f7b267;
  --avatar-bg: #14382d;
  --avatar-text: #74e2b5;
  --message-image-bg: #0c141e;
  --outgoing-bg: #172b4d;
  --outgoing-border: #2d4975;
  --unread-border: #d97706;
  --unread-ring: rgba(245, 158, 11, 0.22);
  --reply-bg: rgba(21, 30, 42, 0.98);
  --reply-input-bg: #101923;
  --attachment-bg: #101923;
  --remove-bg: #3b1d23;
  --remove-text: #fda4af;
  --empty-icon-bg: #182c4d;
  --modal-backdrop: rgba(4, 8, 14, 0.68);
  --toast-bg: #e6edf5;
  --toast-text: #111827;
  --focus-ring: rgba(122, 167, 255, 0.2);
  --primary-shadow: 0 8px 18px rgba(95, 143, 232, 0.18);
  --send-shadow: 0 8px 18px rgba(24, 168, 121, 0.18);
  --send-bg-hover: #22c38d;
  --topbar-shadow: 0 1px 0 rgba(0, 0, 0, 0.22);
  --bubble-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
  --reply-shadow: 0 -12px 24px rgba(0, 0, 0, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  touch-action: pan-x pan-y;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  width: 100%;
  max-width: 100%;
  height: var(--app-height);
  min-height: var(--app-height);
  overflow: hidden;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: var(--font-ui);
  line-height: 1.32;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

html.keyboard-open,
html.keyboard-open body {
  width: 100%;
  height: var(--app-height);
  min-height: var(--app-height);
  max-height: var(--app-height);
  overflow: hidden;
}

html.keyboard-open body {
  position: fixed;
  inset: var(--visual-offset-top) auto auto 0;
}

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

button {
  cursor: pointer;
}

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

[hidden] {
  display: none !important;
}

.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;
}

.auth-screen {
  height: var(--app-height);
  min-height: var(--app-height);
  max-height: var(--app-height);
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--auth-screen-bg);
}

.auth-card {
  width: min(100%, 350px);
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-logo {
  width: min(190px, 76%);
  height: auto;
  display: block;
  margin: 0 0 12px;
  border-radius: 7px;
  background: #fff;
}

.auth-card h1,
.panel-head h2,
.chat-head h2,
.empty-chat h2,
.modal h2 {
  margin: 0;
  letter-spacing: 0;
}

.auth-card h1 {
  margin-bottom: 14px;
  font-size: 22px;
  line-height: 1.15;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 14px;
  padding: 3px;
  border-radius: 8px;
  background: var(--surface-strong);
  border: 1px solid var(--line-soft);
}

.auth-tab {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--bubble-shadow);
}

.auth-form {
  display: block;
}

label {
  display: grid;
  gap: 5px;
  margin-bottom: 11px;
  color: var(--muted);
  font-size: var(--font-label);
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
  font-size: var(--font-input);
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-error {
  min-height: 17px;
  margin: 0 0 9px;
  color: var(--danger);
  font-size: var(--font-label);
  font-weight: 700;
}

.primary-btn,
.soft-btn,
.ghost-btn,
.icon-text-btn,
.attachment-add-btn,
.send-btn,
.settings-row,
.font-size-option,
.icon-btn {
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  font-size: var(--font-control);
  font-weight: 800;
}

.primary-btn {
  width: 100%;
  background: var(--blue);
  color: var(--primary-contrast);
  padding: 0 14px;
  box-shadow: var(--primary-shadow);
}

.primary-btn:hover {
  background: var(--blue-dark);
}

.soft-btn {
  background: var(--soft-bg);
  color: var(--blue);
  border: 1px solid var(--soft-border);
  padding: 0 10px;
}

.ghost-btn {
  background: var(--surface-strong);
  color: var(--text);
  padding: 0 12px;
}

.icon-btn {
  width: 34px;
  padding: 0;
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--line-soft);
}

.icon-text-btn {
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--line-soft);
  padding: 0 10px;
}

.danger-action {
  background: var(--danger-action-bg);
  color: var(--danger-action-text);
}

.danger-action:hover {
  background: var(--danger-action-bg-hover);
}

.send-btn {
  width: 38px;
  min-width: 38px;
  background: var(--green-dark);
  color: #fff;
  box-shadow: var(--send-shadow);
}

.attach-btn {
  color: var(--muted);
  background: transparent;
  border-color: transparent;
}

.icon-btn:hover,
.ghost-btn:hover,
.attachment-add-btn:hover {
  background: var(--control-hover);
}

.soft-btn:hover {
  background: var(--soft-bg-hover);
}

.send-btn:hover {
  background: var(--send-bg-hover);
}

.icon-btn svg,
.icon-text-btn svg,
.attachment-add-btn svg,
.send-btn svg,
.settings-row svg,
.theme-icon,
.empty-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.font-size-btn span {
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
}

.theme-icon-sun {
  display: none;
}

html[data-theme="dark"] .theme-icon-moon {
  display: none;
}

html[data-theme="dark"] .theme-icon-sun {
  display: block;
}

.app-shell {
  height: var(--app-height);
  min-height: var(--app-height);
  max-height: var(--app-height);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.offline-banner {
  flex: 0 0 auto;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--dialog-unread-bg);
  color: var(--dialog-unread-text);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.25;
  text-align: center;
}

.topbar {
  flex: 0 0 auto;
  height: var(--topbar-height);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line-soft);
  position: relative;
  z-index: 30;
  backdrop-filter: blur(14px);
  box-shadow: var(--topbar-shadow);
}

.back-btn {
  display: none;
}

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

.topbar-logo {
  width: 64px;
  height: 26px;
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
}

.topbar-copy {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.topbar-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-control);
}

.topbar-copy span {
  color: var(--muted);
  font-size: var(--font-meta);
  font-weight: 700;
}

.topbar-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 5px;
}

.settings-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(var(--settings-width), calc(100vw - 16px));
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  z-index: 70;
}

.settings-title {
  padding: 2px 2px 4px;
  color: var(--muted);
  font-size: var(--font-caption);
  font-weight: 900;
}

.settings-row {
  width: 100%;
  justify-content: flex-start;
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid var(--line-soft);
  background: var(--surface-strong);
  color: var(--text);
  text-align: left;
}

.switch-row {
  justify-content: space-between;
  min-height: 44px;
}

.switch-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.switch-copy strong,
.switch-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switch-copy strong {
  font-size: var(--font-control);
}

.switch-copy small {
  color: var(--muted);
  font-size: var(--font-meta);
  font-weight: 800;
}

.switch-state {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  font-size: var(--font-meta);
  font-weight: 900;
}

.switch-row.active {
  border-color: var(--soft-border);
  background: var(--soft-bg);
  color: var(--blue);
}

.switch-row.active .switch-state {
  background: var(--blue);
  color: var(--primary-contrast);
}

.settings-row:hover,
.font-size-option:hover {
  background: var(--control-hover);
}

.settings-row.danger-row {
  color: var(--danger-action-text);
  background: var(--danger-action-bg);
}

.settings-icon {
  width: 22px;
  min-width: 22px;
  display: inline-grid;
  place-items: center;
  color: currentColor;
  font-weight: 900;
}

.settings-group {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-muted);
}

.settings-group > span {
  color: var(--muted);
  font-size: var(--font-caption);
  font-weight: 900;
}

.font-size-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.font-size-option {
  min-height: 32px;
  padding: 0;
  border: 1px solid var(--line-soft);
  background: var(--surface);
  color: var(--text);
}

.font-size-option.active {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--primary-contrast);
}

.workspace {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  padding: 0;
  overflow: hidden;
}

.dialogs-panel,
.chat-panel {
  height: 100%;
  min-height: 0;
  background: var(--surface);
  border: 0;
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
}

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

.chat-panel {
  display: none;
  grid-template-rows: minmax(0, 1fr);
  position: relative;
  touch-action: pan-y;
}

.app-shell.chat-open .dialogs-panel {
  display: none;
}

.app-shell.chat-open .chat-panel {
  display: grid;
}

.app-shell.chat-open .back-btn {
  display: inline-flex;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 54px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-head-bg);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel-head h2,
.chat-head h2,
.empty-chat h2,
.modal h2 {
  font-size: var(--font-title);
  line-height: 1.2;
}

.count-badge {
  display: inline-flex;
  margin-top: 3px;
  color: var(--muted);
  font-size: var(--font-caption);
  font-weight: 800;
}

.dialog-list {
  display: grid;
  align-content: start;
  min-height: 0;
  max-height: none;
  overflow: auto;
  overscroll-behavior: contain;
}

.dialog-row {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
  color: var(--text);
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 7px 10px;
  text-align: left;
  position: relative;
}

.dialog-row:hover,
.dialog-row.active {
  background: var(--dialog-hover-bg);
}

.dialog-row.active {
  box-shadow: inset 3px 0 0 var(--blue);
}

.dialog-row.unread {
  background: var(--dialog-unread-bg);
}

.dialog-row.unread .dialog-name {
  color: var(--dialog-unread-text);
}

.dialog-row .avatar,
.chat-head .avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--avatar-bg);
  color: var(--avatar-text);
  font-size: var(--font-control);
  font-weight: 900;
}

.dialog-main {
  min-width: 0;
}

.dialog-name-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
}

.dialog-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-ui);
  font-weight: 900;
}

.presence-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: var(--font-meta);
  font-weight: 900;
  line-height: 1;
}

.presence-pill::before,
.peer-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
}

.presence-pill.online,
.peer-status.online {
  color: var(--green);
}

.presence-pill.offline,
.peer-status.offline {
  color: var(--muted);
}

.dialog-preview {
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: var(--font-label);
  font-weight: 600;
}

.dialog-row.unread .dialog-preview {
  color: var(--text);
  font-weight: 800;
}

.dialog-time {
  align-self: start;
  color: var(--muted);
  font-size: var(--font-meta);
  font-weight: 800;
}

.unread-dot {
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--orange);
  color: #fff;
  font-size: var(--font-caption);
  font-weight: 900;
}

.active-chat {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.chat-head {
  min-height: 54px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
}

.chat-head span {
  color: var(--muted);
  font-size: var(--font-caption);
  font-weight: 800;
}

.chat-head .peer-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.message-list {
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 10px;
  background: var(--surface-muted);
  overscroll-behavior: contain;
  scroll-padding-bottom: 76px;
}

.message {
  max-width: min(78%, 560px);
  display: grid;
  gap: 2px;
}

.message.incoming {
  justify-self: start;
}

.message.outgoing {
  justify-self: end;
}

.bubble {
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 7px 9px;
  background: var(--surface);
  box-shadow: var(--bubble-shadow);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: var(--font-message);
}

.bubble.has-attachments {
  display: grid;
  gap: 6px;
  padding: 6px;
  white-space: normal;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 1px 2px;
}

.message-image-link {
  display: inline-block;
  max-width: min(280px, 70vw);
  overflow: hidden;
  border-radius: 7px;
  background: var(--message-image-bg);
  line-height: 0;
}

.message-image-link img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 300px;
  object-fit: contain;
}

.message.outgoing .bubble {
  background: var(--outgoing-bg);
  border-color: var(--outgoing-border);
  border-bottom-right-radius: 5px;
}

.message.incoming .bubble {
  border-bottom-left-radius: 5px;
}

.message.unread .bubble {
  border-color: var(--unread-border);
  box-shadow: 0 0 0 2px var(--unread-ring);
}

.message-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: flex-end;
  color: var(--muted);
  font-size: var(--font-meta);
  font-weight: 800;
}

.message.incoming .message-meta {
  justify-content: flex-start;
  padding-left: 4px;
}

.message.outgoing .message-meta {
  padding-right: 4px;
}

.read-status.read {
  color: var(--green);
}

.read-status.unread {
  color: var(--muted);
}

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

.message-edit-btn,
.text-action-btn {
  min-height: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 1px 3px;
  font-size: var(--font-meta);
  font-weight: 900;
}

.message-edit-btn:hover,
.text-action-btn:hover {
  background: var(--soft-bg);
}

.reply-form {
  align-self: end;
  display: grid;
  gap: 5px;
  min-height: 50px;
  padding: 6px max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  background: var(--reply-bg);
  border-top: 1px solid var(--line-soft);
  box-shadow: var(--reply-shadow);
  z-index: 2;
  transform: translateZ(0);
}

.edit-banner {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid var(--soft-border);
  border-radius: 8px;
  background: var(--soft-bg);
  color: var(--text);
  font-size: var(--font-label);
  font-weight: 900;
}

.reply-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 38px;
  align-items: end;
  gap: 4px;
  min-height: 38px;
  padding: 4px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: var(--reply-input-bg);
}

.reply-row:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.reply-form textarea {
  min-height: 34px;
  max-height: 104px;
  resize: none;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 7px 4px;
  box-shadow: none;
}

.reply-form textarea:focus {
  box-shadow: none;
}

.attachment-field {
  display: grid;
  gap: 7px;
  margin: -2px 0 10px;
}

.attachment-add-btn {
  width: fit-content;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--text);
  padding: 0 10px;
}

.attachment-preview {
  display: grid;
}

.attachment-chip {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--attachment-bg);
}

.attachment-chip.uploading {
  border-color: var(--blue);
}

.attachment-chip.error {
  border-color: var(--danger);
}

.attachment-chip img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--message-image-bg);
}

.attachment-info {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.attachment-info strong,
.attachment-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-info strong {
  color: var(--text);
  font-size: var(--font-label);
  font-weight: 900;
}

.attachment-info span {
  color: var(--muted);
  font-size: var(--font-caption);
  font-weight: 700;
}

.attachment-progress {
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line-soft);
}

.attachment-progress > span {
  display: block;
  width: var(--progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  transition: width 0.16s ease;
}

.attachment-remove {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: var(--remove-bg);
  color: var(--remove-text);
  font-size: var(--font-ui);
  font-weight: 900;
  line-height: 1;
}

.attachment-remove:disabled {
  opacity: 0.45;
}

.empty-chat {
  height: 100%;
  min-height: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.empty-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--empty-icon-bg);
  color: var(--blue);
}

.modal-backdrop {
  position: fixed;
  inset: 0 auto auto 0;
  width: 100%;
  height: var(--app-height);
  max-height: var(--app-height);
  display: grid;
  place-items: end center;
  padding: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  overflow: hidden;
  background: var(--modal-backdrop);
  z-index: 50;
}

.modal {
  width: min(100%, 480px);
  max-height: calc(var(--app-height) - 20px);
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  margin-bottom: 12px;
}

.modal-actions {
  justify-content: flex-end;
  margin: 6px 0 0;
}

.modal-actions .primary-btn {
  width: auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--toast-bg);
  color: var(--toast-text);
  z-index: 80;
  font-size: var(--font-ui);
  font-weight: 800;
  box-shadow: var(--shadow);
}

@media (max-width: 430px) {
  .topbar {
    gap: 5px;
  }

  .soft-btn {
    width: 62px;
    max-width: 62px;
    padding: 0 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: var(--font-control);
  }

  .topbar-logo {
    width: 54px;
    height: 22px;
  }

  .app-shell.chat-open .topbar-logo {
    width: 44px;
    height: 18px;
  }

  .app-shell.chat-open .topbar-copy {
    display: none;
  }

  .topbar-copy strong {
    font-size: var(--font-control);
  }

  .workspace {
    padding: 0;
  }

  .message-list {
    padding: 8px;
  }

  .dialog-row {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    padding: 7px 8px;
  }

  .dialog-row .avatar,
  .chat-head .avatar {
    width: 34px;
    height: 34px;
  }

  .message {
    max-width: 90%;
  }

  .reply-form {
    padding: 6px max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .panel-actions .icon-text-btn {
    min-height: 34px;
    padding: 0 8px;
    font-size: var(--font-control);
  }
}

@media (max-width: 360px) {
  .topbar-copy {
    display: none;
  }
}

@media (min-width: 760px) {
  .app-shell {
    --topbar-height: 56px;
  }

  .topbar {
    padding: 7px 14px;
  }

  .back-btn {
    display: none !important;
  }

  .workspace {
    grid-template-columns: minmax(270px, 320px) minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .dialogs-panel,
  .chat-panel,
  .app-shell.chat-open .dialogs-panel,
  .app-shell.chat-open .chat-panel {
    display: grid;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    box-shadow: var(--panel-shadow);
  }

  .dialogs-panel {
    grid-template-rows: auto 1fr;
  }

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

  .dialog-list {
    max-height: none;
  }

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

  .modal-backdrop {
    place-items: center;
  }

  .message-list {
    padding: 12px;
  }

  .reply-form {
    min-height: 56px;
    padding: 8px 10px;
  }

  .reply-row {
    grid-template-columns: 40px minmax(240px, 1fr) 42px;
    gap: 8px;
  }

  .attach-btn,
  .send-btn {
    width: 40px;
    min-width: 40px;
  }

  .reply-form textarea {
    max-height: 88px;
  }
}
