:root {
  color-scheme: light;
  --bg: #edf5f3;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --conversation-bg: #f7fbfa;
  --tab-bg: #e4efed;
  --input-disabled: #e8f0ef;
  --ink: #182026;
  --muted: #66727d;
  --line: #cfdeda;
  --accent: #007a73;
  --accent-dark: #005f59;
  --accent-soft: #d9f0ed;
  --icon: #006e68;
  --icon-hover: #004f4b;
  --icon-hover-bg: #d7ece9;
  --alert: #b83e35;
  --danger-soft: #fde4e1;
  --sent: #007a73;
  --received: #e2ebe9;
  --hover: #e1efed;
  --shadow: 0 18px 48px rgba(28, 38, 48, 0.14);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body[data-theme="indigo"] {
  --bg: #eef1ff;
  --panel: #fbfcff;
  --panel-strong: #ffffff;
  --conversation-bg: #f6f7ff;
  --tab-bg: #e4e8ff;
  --input-disabled: #edf0fb;
  --ink: #1d2437;
  --muted: #65708d;
  --line: #d8def8;
  --accent: #4f46e5;
  --accent-dark: #3730a3;
  --accent-soft: #e0e7ff;
  --icon: #4338ca;
  --icon-hover: #312e81;
  --icon-hover-bg: #e2e7ff;
  --sent: #4f46e5;
  --received: #e8ecfb;
  --hover: #e8ecff;
  --shadow: 0 18px 48px rgba(43, 49, 96, 0.16);
}

body[data-theme="rose"] {
  --bg: #fff0f3;
  --panel: #fffafb;
  --panel-strong: #ffffff;
  --conversation-bg: #fff7f9;
  --tab-bg: #fde7ed;
  --input-disabled: #f8edf0;
  --ink: #2b2025;
  --muted: #7a6570;
  --line: #eed3dc;
  --accent: #be3455;
  --accent-dark: #93223d;
  --accent-soft: #fde2eb;
  --icon: #a52748;
  --icon-hover: #7b1c35;
  --icon-hover-bg: #f9dce5;
  --sent: #be3455;
  --received: #f3e2e7;
  --hover: #fde7ed;
  --shadow: 0 18px 48px rgba(96, 39, 58, 0.15);
}

body[data-theme="forest"] {
  --bg: #eef6ec;
  --panel: #fbfff9;
  --panel-strong: #ffffff;
  --conversation-bg: #f6fbf3;
  --tab-bg: #dfeddc;
  --input-disabled: #e8f1e5;
  --ink: #1d281c;
  --muted: #65745f;
  --line: #cfdfca;
  --accent: #2f7d32;
  --accent-dark: #215b24;
  --accent-soft: #ddf2df;
  --icon: #286f2c;
  --icon-hover: #1d4d21;
  --icon-hover-bg: #daecd7;
  --sent: #2f7d32;
  --received: #e2ebde;
  --hover: #e0eddc;
  --shadow: 0 18px 48px rgba(42, 68, 39, 0.14);
}

body[data-theme="graphite"] {
  color-scheme: dark;
  --bg: #111820;
  --panel: #18222c;
  --panel-strong: #202c37;
  --conversation-bg: #0f151c;
  --tab-bg: #111a23;
  --input-disabled: #1d2833;
  --ink: #eff5f8;
  --muted: #a4b2bf;
  --line: #2d3b47;
  --accent: #83c5be;
  --accent-dark: #5baaa2;
  --accent-soft: #1f3a3b;
  --icon: #9bd7d0;
  --icon-hover: #d6fffa;
  --icon-hover-bg: #22343b;
  --alert: #ff776d;
  --danger-soft: #3d2325;
  --sent: #4f9e97;
  --received: #22303c;
  --hover: #202c37;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  outline: none;
}

input {
  min-height: 44px;
  padding: 0 12px;
}

input:disabled {
  background: var(--input-disabled);
  color: var(--muted);
}

textarea {
  min-height: 46px;
  max-height: 140px;
  padding: 12px 14px;
  resize: none;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  line-height: 1;
}

h2 {
  font-size: 1.05rem;
}

.hidden {
  display: none !important;
}

.status {
  position: fixed;
  z-index: 60;
  left: 50%;
  top: 18px;
  width: min(92vw, 460px);
  min-height: 0;
  transform: translateX(-50%);
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  box-shadow: var(--shadow);
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.status.show {
  min-height: 44px;
  padding: 12px 16px;
  opacity: 1;
  transform: translateX(-50%) translateY(4px);
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card,
.modal-card {
  width: min(100%, 480px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-card {
  display: grid;
  gap: 22px;
  padding: clamp(20px, 4vw, 34px);
}

.brand-block {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark,
.avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  font-weight: 850;
}

.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar.large {
  width: 76px;
  height: 76px;
  flex-basis: 76px;
  font-size: 1.35rem;
}

.avatar.xlarge {
  width: 112px;
  height: 112px;
  margin-inline: auto;
  flex-basis: 112px;
  font-size: 2rem;
}

.brand-block p {
  margin-top: 6px;
  color: var(--muted);
}

.auth-tabs,
.settings-tabs {
  display: grid;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tab-bg);
}

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

.settings-tabs {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.tab-button,
.settings-tab {
  min-height: 42px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab-button.active,
.settings-tab.active {
  background: var(--panel-strong);
  color: var(--ink);
  box-shadow: 0 1px 8px rgba(28, 38, 48, 0.1);
}

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

.primary-button,
.secondary-button,
.danger-button,
.send-button,
.fab,
.icon-button,
.file-button,
.theme-option {
  min-width: 44px;
  min-height: 44px;
  border-radius: 8px;
  font-weight: 850;
}

.primary-button,
.send-button,
.fab {
  background: var(--accent);
  color: #ffffff;
}

.primary-button {
  width: 100%;
  padding: 0 18px;
}

.secondary-button,
.file-button,
.theme-option {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--ink);
}

.compact-button {
  width: auto;
  padding: 0 12px;
}

.danger-button {
  width: 100%;
  padding: 0 18px;
  background: var(--alert);
  color: #ffffff;
}

.primary-button:hover,
.send-button:hover,
.fab:hover {
  background: var(--accent-dark);
}

.secondary-button:hover,
.file-button:hover,
.theme-option:hover,
.icon-button:hover {
  background: var(--icon-hover-bg);
}

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  overflow: hidden;
}

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

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.profile-block {
  display: flex;
  min-width: 0;
  gap: 12px;
  align-items: center;
}

.profile-copy,
.chat-title,
.chat-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.profile-copy strong,
.chat-title strong,
.chat-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-copy span,
.chat-title span,
.chat-copy span,
.chat-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.identifier-pill,
.blocked-pill,
.blocked-label {
  width: fit-content;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 850;
}

.identifier-pill {
  margin-top: 4px;
}

.blocked-pill,
.blocked-label {
  background: var(--danger-soft);
  color: var(--alert);
}

.conversation-header .blocked-pill {
  margin-left: auto;
  white-space: nowrap;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  background: transparent;
  color: var(--icon);
  font-size: 1.25rem;
}

.icon-button:hover {
  color: var(--icon-hover);
}

.list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 16px;
}

.chat-list {
  min-height: 0;
  overflow: auto;
  padding: 0 8px 92px;
}

.chat-list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 2px;
  align-items: center;
}

.chat-item {
  width: 100%;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 72px;
  padding: 10px 8px;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.chat-row-menu {
  opacity: 0;
}

.chat-list-row:hover .chat-row-menu,
.chat-row-menu:focus-visible {
  opacity: 1;
}

.chat-item:hover,
.chat-item.active {
  background: var(--hover);
}

.chat-item.unread .chat-copy strong,
.chat-item.unread .chat-copy span {
  color: var(--ink);
  font-weight: 900;
}

.chat-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-name-line {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-name-line strong {
  min-width: 0;
}

.pin-badge,
.owner-badge {
  flex: 0 0 auto;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.68rem;
  font-weight: 900;
}

.chat-meta {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.unread-badge {
  min-width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--alert);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 900;
}

.fab {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  box-shadow: var(--shadow);
  font-size: 2rem;
  line-height: 1;
}

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

.empty-state {
  padding: 24px;
}

.conversation {
  min-width: 0;
  display: grid;
  background: var(--conversation-bg);
}

.conversation-empty {
  display: grid;
  place-items: center;
}

.conversation-active {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

.conversation-header {
  min-width: 0;
  min-height: 74px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.chat-info-button {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.chat-info-button:hover {
  background: var(--hover);
}

.back-button {
  display: none;
}

.avatar.small {
  width: 42px;
  height: 42px;
  flex-basis: 42px;
}

.message-list {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 20px;
}

.message-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.message-row.mine {
  justify-content: flex-end;
}

.message-bubble {
  max-width: min(76%, 680px);
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--received);
  color: var(--ink);
  overflow-wrap: anywhere;
  touch-action: pan-y;
}

.message-row.mine .message-bubble {
  background: var(--sent);
  color: #ffffff;
}

.sender-label,
.forwarded-label {
  font-size: 0.76rem;
  font-weight: 900;
}

.message-row.mine .sender-label,
.message-row.mine .forwarded-label {
  color: rgba(255, 255, 255, 0.84) !important;
}

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

.reply-quote {
  min-height: 34px;
  padding: 6px 8px;
  border-left: 3px solid currentColor;
  border-radius: 6px;
  background: color-mix(in srgb, currentColor 10%, transparent);
  color: inherit;
  text-align: left;
  opacity: 0.88;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-body {
  white-space: pre-wrap;
}

.message-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.14s ease;
}

.message-row:hover .message-actions,
.message-actions:focus-within {
  opacity: 1;
}

.message-action-button {
  min-width: 34px;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--icon);
  font-size: 0.76rem;
  font-weight: 850;
}

.message-action-button:hover {
  background: var(--icon-hover-bg);
  color: var(--icon-hover);
}

.message-time {
  color: inherit;
  font-size: 0.72rem;
  opacity: 0.72;
  justify-self: end;
}

.message-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: 10px;
  align-items: end;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

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

.reply-preview div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

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

.reply-preview span {
  color: var(--muted);
  font-size: 0.88rem;
}

.send-button {
  width: 52px;
  height: 46px;
  font-size: 1.25rem;
}

.modal-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 32, 38, 0.48);
}

.modal-card {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.menu-card {
  width: min(100%, 420px);
}

.menu-profile {
  display: grid;
  justify-items: center;
  gap: 6px;
  text-align: center;
}

.menu-profile span {
  color: var(--muted);
}

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

.menu-stack {
  display: grid;
  gap: 8px;
}

.menu-button {
  min-height: 46px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  text-align: left;
  font-weight: 800;
}

.menu-button:hover {
  background: var(--hover);
}

.danger-text {
  color: var(--alert);
}

.settings-card {
  width: min(100%, 760px);
  max-height: min(92vh, 780px);
  overflow: auto;
}

.settings-panel {
  display: grid;
  gap: 18px;
}

.avatar-editor {
  display: flex;
  align-items: center;
  gap: 16px;
}

.avatar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.file-button {
  position: relative;
  padding: 0 16px;
  text-align: center;
}

.file-button.wide {
  width: 100%;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

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

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

.member-item,
.forward-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.forward-item {
  grid-template-columns: auto 42px minmax(0, 1fr);
  cursor: pointer;
}

.forward-item input {
  width: 18px;
  min-height: 18px;
}

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

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

.member-copy span {
  color: var(--muted);
  font-size: 0.86rem;
}

.delete-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.theme-option {
  gap: 8px;
  padding: 12px 10px;
}

.theme-option.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.theme-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.theme-swatch.teal {
  background: linear-gradient(135deg, #edf5f3 0 50%, #007a73 50% 100%);
}

.theme-swatch.indigo {
  background: linear-gradient(135deg, #eef1ff 0 50%, #4f46e5 50% 100%);
}

.theme-swatch.rose {
  background: linear-gradient(135deg, #fff0f3 0 50%, #be3455 50% 100%);
}

.theme-swatch.forest {
  background: linear-gradient(135deg, #eef6ec 0 50%, #2f7d32 50% 100%);
}

.theme-swatch.graphite {
  background: linear-gradient(135deg, #111820 0 50%, #83c5be 50% 100%);
}

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

.block-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

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

.block-copy span {
  color: var(--muted);
  font-size: 0.86rem;
}

.account-actions {
  display: flex;
  gap: 10px;
}

.danger-zone {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.avatar-prompt-card {
  text-align: center;
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
  }

  .conversation {
    display: none;
  }

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

  .app.chat-open .conversation {
    display: grid;
  }

  .back-button {
    display: grid;
  }

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

  .chat-row-menu,
  .message-actions {
    display: none;
  }

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

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

@media (max-width: 560px) {
  .auth-screen,
  .modal-backdrop {
    padding: 12px;
  }

  .auth-card,
  .modal-card {
    padding: 18px;
  }

  .brand-block {
    align-items: flex-start;
  }

  .auth-tabs,
  .settings-tabs,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .sidebar-header,
  .conversation-header {
    padding-inline: 12px;
  }

  .message-list {
    padding: 14px 12px;
  }

  .message-form {
    grid-template-columns: minmax(0, 1fr) 48px;
    padding: 10px 12px 12px;
  }

  .reply-preview {
    padding: 8px 12px;
  }

  .send-button {
    width: 48px;
  }

  .avatar-editor {
    align-items: flex-start;
  }

  .block-item,
  .member-item {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .block-item .secondary-button,
  .member-item .owner-badge {
    grid-column: 1 / -1;
  }

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