:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #ffffff;
  --panel-soft: #edf7f5;
  --text: #182322;
  --muted: #687572;
  --line: #d9dfdc;
  --brand: #1f6f68;
  --brand-dark: #15514c;
  --accent: #d4523f;
  --warn: #a24135;
  --shadow: 0 18px 50px rgba(25, 37, 35, 0.11);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
}

body {
  min-width: 320px;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(31, 111, 104, 0.08), rgba(212, 82, 63, 0.08)),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background: var(--bg);
}

.app-nav {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.nav-title {
  min-width: 0;
}

.nav-title h1 {
  margin: 0;
  font-size: 1.36rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.nav-title span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.84rem;
}

.nav-actions {
  display: flex;
  gap: 8px;
}

.nav-actions.spacer {
  width: 42px;
}

.back-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 50%;
  color: var(--brand-dark);
  background: var(--panel-soft);
  font-size: 2rem;
  line-height: 1;
}

.icon-button,
.send-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 50%;
  color: var(--brand-dark);
  background: var(--panel-soft);
  font-size: 1.2rem;
  font-weight: 900;
}

.send-button {
  color: #fff;
  background: var(--brand);
}

.compact {
  min-height: 36px;
  padding: 8px 10px;
}

.app-content {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  overflow: hidden;
}

.settings-mode .app-content {
  grid-template-columns: minmax(0, 860px);
  justify-content: center;
  overflow: auto;
}

.chat-list-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding: 14px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.82);
  border-right: 1px solid var(--line);
}

.create-panel {
  display: grid;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1rem;
}

.bottom-tabs {
  display: none;
}

.auth-shell {
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(320px, 1.1fr);
  overflow: auto;
}

.brand-panel {
  padding: 48px;
  color: #fff;
  background:
    linear-gradient(rgba(24, 35, 34, 0.08), rgba(24, 35, 34, 0.18)),
    linear-gradient(135deg, var(--brand), #2b8b79);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
}

.logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
}

.brand-copy h1 {
  max-width: 560px;
  margin: 0 0 16px;
  font-size: clamp(2.2rem, 5vw, 4.7rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.brand-copy p {
  max-width: 520px;
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.86);
}

.auth-panel {
  display: grid;
  align-content: center;
  padding: 32px;
}

.auth-card {
  width: min(100%, 460px);
  margin: 0 auto;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  margin-bottom: 22px;
  border-radius: 8px;
  background: #eef1ef;
}

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

.tab.active {
  color: var(--text);
  background: #fff;
  box-shadow: 0 2px 8px rgba(30, 40, 38, 0.08);
}

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

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

.field span,
.section-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.input,
.textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  outline: none;
}

.textarea {
  min-height: 92px;
  resize: vertical;
}

.input:focus,
.textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 111, 104, 0.15);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.error {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--warn);
  background: #fff2ef;
  border: 1px solid #f1c0b8;
}

.success {
  padding: 10px 12px;
  border-radius: 8px;
  color: #0d5f47;
  background: #e7f7f1;
  border: 1px solid #b8e0d1;
}

.primary,
.secondary,
.ghost,
.danger {
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 800;
}

.primary {
  color: #fff;
  background: var(--brand);
}

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

.secondary {
  color: var(--brand-dark);
  background: var(--panel-soft);
}

.ghost {
  color: var(--text);
  background: transparent;
}

.ghost:hover {
  background: #eef1ef;
}

.danger {
  color: #fff;
  background: var(--accent);
}

.sidebar {
  min-width: 0;
  padding: 18px;
  background: rgba(255, 255, 255, 0.82);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.profile-strip,
.chat-header,
.compose {
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
}

.profile-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  margin-bottom: 16px;
}

.identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--brand);
  font-weight: 900;
}

.identity-text {
  min-width: 0;
}

.name,
.nickname {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name {
  font-weight: 900;
}

.nickname {
  color: var(--muted);
  font-size: 0.88rem;
}

.sidebar-section {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.section-title {
  margin: 0;
  font-size: 1rem;
}

.search-results,
.chat-list {
  display: grid;
  gap: 8px;
}

.chat-list {
  align-content: start;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}

.user-row,
.chat-row {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  overflow: hidden;
}

.chat-row.active {
  border-color: var(--brand);
  background: var(--panel-soft);
}

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

.preview {
  display: -webkit-box;
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.member-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.member-chip {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--brand-dark);
  background: var(--panel-soft);
  font-size: 0.84rem;
  font-weight: 800;
}

.member-chip .ghost {
  min-height: 24px;
  padding: 0 6px;
  border-radius: 6px;
}

.notification-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.notification-box p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.notification-box.enabled {
  border-color: #b8e0d1;
  background: #f0fbf6;
}

.settings-panel {
  display: grid;
  gap: 14px;
  width: min(100%, 720px);
  padding: 18px;
}

.settings-block {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.identity-settings {
  padding: 16px;
}

.empty {
  padding: 18px;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  border: 1px dashed var(--line);
  line-height: 1.5;
}

.chat-header {
  min-width: 0;
  padding: 18px 22px;
}

.chat-header h2 {
  margin: 0;
  font-size: 1.24rem;
}

.chat-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.participants-line {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  min-width: 0;
  max-width: min(72%, 680px);
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  line-height: 1.45;
  overflow-wrap: anywhere;
  touch-action: pan-y;
  word-break: break-word;
  transition:
    box-shadow 180ms ease,
    transform 180ms ease;
}

.message.own {
  align-self: flex-end;
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

.message-author {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.message.own .message-author {
  color: rgba(255, 255, 255, 0.78);
}

.message p {
  margin: 8px 0 0;
}

.message-highlight {
  box-shadow: 0 0 0 3px rgba(22, 136, 128, 0.24);
  transform: translateY(-1px);
}

.message-reply,
.reply-composer {
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  text-align: left;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-reply {
  width: 100%;
  margin: 0 0 8px;
  padding: 7px 9px;
  border-left: 4px solid var(--accent);
  border-radius: 7px;
  color: var(--text);
  background: rgba(18, 136, 128, 0.1);
}

.message-reply span,
.reply-composer span {
  min-width: 0;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
}

.message-reply strong,
.reply-composer strong {
  min-width: 0;
  display: -webkit-box;
  grid-column: 1 / -1;
  overflow: hidden;
  color: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.message.own .message-reply {
  color: #fff;
  border-left-color: #ffd7ce;
  background: rgba(255, 255, 255, 0.14);
}

.message.own .message-reply span {
  color: #ffd7ce;
}

.message-mention,
.message-link {
  display: inline;
  max-width: 100%;
  min-height: 0;
  padding: 0;
  color: var(--accent);
  background: transparent;
  border-radius: 0;
  font: inherit;
  font-weight: 900;
  line-height: inherit;
  overflow-wrap: anywhere;
  text-align: left;
  text-decoration: none;
  vertical-align: baseline;
  white-space: normal;
  word-break: break-word;
}

.message-link {
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

.message.own .message-mention,
.message.own .message-link {
  color: #ffd7ce;
}

.message-photo {
  display: block;
  width: min(100%, 420px);
  max-height: 420px;
  object-fit: contain;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
}

.compose {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  position: relative;
}

.mention-picker {
  grid-column: 1 / -1;
  max-height: 260px;
  overflow: auto;
  display: grid;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.mention-option {
  min-height: 58px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  text-align: left;
  background: transparent;
  border-bottom: 1px solid var(--line);
}

.mention-option:last-child {
  border-bottom: 0;
}

.mention-option strong,
.mention-option small {
  display: block;
}

.mention-option small {
  color: var(--muted);
  font-size: 0.86rem;
}

.photo-picker {
  display: grid;
  place-items: center;
  cursor: pointer;
}

.photo-picker input {
  display: none;
}

.photo-preview {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.reply-composer {
  grid-column: 1 / -1;
  align-items: center;
  padding: 9px 10px;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--panel-soft);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.reply-composer div {
  min-width: 0;
}

.reply-composer .ghost {
  width: 30px;
  min-height: 30px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.1rem;
}

.photo-preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
}

.photo-preview strong {
  display: block;
  font-size: 0.9rem;
}

.photo-preview p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.profile-editor {
  display: grid;
  gap: 14px;
  padding: 0;
  margin: 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 35, 34, 0.26);
}

.public-profile {
  width: min(100%, 420px);
  display: grid;
  gap: 16px;
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.public-profile p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.modal-close {
  justify-self: end;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hidden {
  display: none !important;
}

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

  .brand-panel {
    min-height: 280px;
    padding: 28px;
  }

  .auth-panel {
    padding: 18px;
  }

  .app-shell {
    height: 100dvh;
    overflow: hidden;
  }

  .app-content {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    overflow: hidden;
  }

  .settings-mode .app-content {
    display: block;
    overflow: auto;
  }

  .chat-list-panel {
    max-height: none;
    height: 100%;
    border-right: 0;
    border-bottom: 0;
    overflow: hidden;
  }

  .chat-screen-list .main {
    display: none;
  }

  .chat-screen-conversation .chat-list-panel {
    display: none;
  }

  .chat-screen-conversation .bottom-tabs {
    display: none;
  }

  .main {
    min-height: 0;
  }

  .chat-screen-conversation .main {
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .chat-screen-conversation .main > .chat-header {
    display: none;
  }

  .message {
    max-width: 88%;
  }

  .bottom-tabs {
    min-height: 58px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.94);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(18px);
  }

  .bottom-tabs button {
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    font-weight: 900;
  }

  .bottom-tabs button.active {
    color: var(--brand-dark);
    background: var(--panel-soft);
  }
}

@media (max-width: 520px) {
  .user-row,
  .chat-row {
    align-items: stretch;
  }

  .user-row,
  .chat-row {
    flex-direction: column;
  }

  .app-nav {
    min-height: 58px;
    padding: 8px 12px;
  }

  .nav-title h1 {
    font-size: 1.18rem;
  }

  .chat-header {
    padding: 12px 14px;
  }

  .messages {
    padding: 14px;
  }

  .compose {
    grid-template-columns: 42px 1fr 42px;
    gap: 8px;
    padding: 10px 12px;
  }

  .photo-preview {
    grid-template-columns: 64px 1fr;
  }

  .photo-preview .ghost {
    grid-column: 1 / -1;
  }

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