:root {
  color-scheme: light dark;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-strong: #f0f4ef;
  --ink: #17201b;
  --muted: #69736f;
  --line: #dde4de;
  --accent: #166f61;
  --accent-strong: #0e574c;
  --accent-soft: #dcefe9;
  --warm: #b66b2d;
  --shadow: 0 20px 60px rgba(23, 32, 27, 0.12);
  --request-shell-bg: var(--panel);
  --request-sidebar-bg: #fbfcfa;
  --request-panel-bg: transparent;
  --request-ink: var(--ink);
  --request-strong: var(--ink);
  --request-muted: var(--muted);
  --request-line: var(--line);
  --request-control-bg: var(--panel-strong);
  --request-control-hover: var(--accent-soft);
  --request-empty-bg: #ffffff;
  --request-card-bg: #f7faf7;
  --request-card-ink: var(--ink);
  --request-card-muted: var(--muted);
  --request-action: #315c87;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171c19;
    --panel: #202622;
    --panel-strong: #2b332e;
    --ink: #edf4ef;
    --muted: #a7b2ad;
    --line: rgba(255, 255, 255, 0.1);
    --accent: #35c985;
    --accent-strong: #46d896;
    --accent-soft: rgba(53, 201, 133, 0.16);
    --shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
    --request-shell-bg: #1f2321;
    --request-sidebar-bg: #2a302c;
    --request-panel-bg: transparent;
    --request-ink: #e9efeb;
    --request-strong: #f4f7f5;
    --request-muted: #aeb8b2;
    --request-line: rgba(255, 255, 255, 0.08);
    --request-control-bg: rgba(255, 255, 255, 0.06);
    --request-control-hover: rgba(255, 255, 255, 0.1);
    --request-empty-bg: rgba(255, 255, 255, 0.04);
    --request-card-bg: #1f2321;
    --request-card-ink: #eef4f0;
    --request-card-muted: #aeb8b2;
    --request-action: #8da2bd;
  }
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0)),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible {
  outline: 2px solid rgba(47, 197, 127, 0.72);
  outline-offset: 2px;
}

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

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

.auth-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  border: 1px solid rgba(23, 32, 27, 0.08);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.auth-panel label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.auth-panel input {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  padding: 0 12px;
  color: var(--ink);
}

.auth-panel input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 111, 97, 0.14);
}

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

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

.auth-tab.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 6px 18px rgba(23, 32, 27, 0.08);
}

.auth-panel:not(.register-mode) .register-only {
  display: none;
}

.auth-submit {
  height: 44px;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  height: min(820px, calc(100vh - 32px));
  min-height: 560px;
  margin: 16px auto;
  display: grid;
  grid-template-columns: 72px 332px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(23, 32, 27, 0.08);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.app-shell[data-view="requests"] {
  grid-template-columns: 72px 360px minmax(0, 1fr);
  background: var(--request-shell-bg);
}

.app-shell[data-view="requests"] .chat-panel {
  display: none;
}

.app-shell[data-view="requests"] .sidebar {
  color: var(--request-ink);
  background: var(--request-sidebar-bg);
  border-right-color: var(--request-line);
}

.app-shell[data-view="requests"] .brand-bar {
  display: none;
  background: var(--request-sidebar-bg);
  border-bottom-color: var(--request-line);
}

.app-shell[data-view="requests"] .brand-bar h1 {
  color: var(--request-strong);
}

.app-shell[data-view="moments"] {
  grid-template-columns: 72px minmax(0, 1fr);
  background: #eef2ed;
}

.app-shell[data-view="moments"] .sidebar,
.app-shell[data-view="moments"] .chat-panel,
.app-shell[data-view="moments"] .contacts-panel {
  display: none;
}

.app-shell[data-view="moments"] .moments-panel {
  grid-column: 2;
}

.app-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 22px 10px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  background: #2f3431;
}

.nav-spacer {
  flex: 1;
}

.nav-label,
.mobile-action-button,
.mobile-add-label,
.mobile-back-button,
.mobile-panel-back {
  display: none;
}

.nav-button,
.nav-profile {
  position: relative;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: #d7ded9;
  background: transparent;
  font-size: 22px;
}

.nav-button:hover,
.nav-button.active,
.nav-profile:hover,
.nav-profile.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.nav-button.active::before,
.nav-profile.active::before {
  content: "";
  position: absolute;
  left: -10px;
  width: 4px;
  height: 26px;
  border-radius: 999px;
  background: #2fc57f;
}

.nav-button.subtle {
  color: #aeb8b2;
  font-size: 20px;
}

.nav-icon-people,
.row-icon.people {
  position: relative;
  width: 24px;
  height: 24px;
  display: block;
  color: currentColor;
}

.nav-icon-people::before,
.row-icon.people::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 3px;
  width: 8px;
  height: 8px;
  border: 2px solid currentColor;
  border-radius: 999px;
}

.nav-icon-people::after,
.row-icon.people::after {
  content: "";
  position: absolute;
  left: 4px;
  bottom: 3px;
  width: 16px;
  height: 10px;
  border: 2px solid currentColor;
  border-bottom: 0;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}

.nav-icon-moments {
  position: relative;
  width: 22px;
  height: 22px;
  display: block;
  border: 2px solid currentColor;
  border-radius: 5px;
}

.nav-icon-moments::before,
.nav-icon-moments::after {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
}

.nav-icon-moments::before {
  left: 5px;
  top: 5px;
}

.nav-icon-moments::after {
  right: 5px;
  bottom: 5px;
}

.nav-profile .avatar {
  width: 42px;
  height: 42px;
}

.nav-badge {
  position: absolute;
  right: -2px;
  top: -3px;
  min-width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: #f04444;
  font-size: 12px;
  font-weight: 800;
}

.sidebar {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
}

.side-view {
  display: none;
  min-height: 0;
}

.side-view.active {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.brand-bar,
.chat-header {
  flex: 0 0 auto;
  min-height: 84px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.brand-bar {
  justify-content: space-between;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: 0;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-size: 26px;
  line-height: 1;
}

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

.icon-button.quiet {
  color: var(--muted);
  background: transparent;
}

.icon-button.quiet:hover {
  color: var(--ink);
  background: var(--panel-strong);
}

.text-button {
  border: 0;
  color: var(--accent);
  background: transparent;
  font-size: 13px;
  font-weight: 760;
}

.search-box {
  margin: 16px;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.search-box input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.sidebar-search {
  flex: 0 0 auto;
}

.app-shell[data-view="requests"] .sidebar-search {
  border-color: var(--request-line);
  background: var(--request-control-bg);
  color: var(--request-muted);
}

.app-shell[data-view="requests"] .sidebar-search input {
  color: var(--request-ink);
}

.app-shell[data-view="requests"] .sidebar-search input::placeholder {
  color: var(--request-muted);
}

.request-panel {
  padding: 0 12px 14px;
  overflow: auto;
  background: transparent;
}

.contact-manager,
.contact-row,
.contact-person {
  width: 100%;
  min-height: 48px;
  display: grid;
  align-items: center;
  border: 0;
  border-radius: 8px;
  color: var(--request-ink);
  background: transparent;
  text-align: left;
}

.contact-manager {
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 8px;
  padding: 0 12px;
  background: var(--request-control-bg);
}

.contact-manager:hover,
.contact-manager.active,
.contact-row:hover,
.contact-row.active,
.contact-person:hover,
.contact-person.active {
  background: var(--request-control-hover);
}

.contact-row {
  grid-template-columns: 20px minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 8px;
  padding: 0 12px;
  font-weight: 760;
}

.contact-row em {
  min-width: 22px;
  font-style: normal;
  text-align: right;
}

.section-count {
  color: var(--request-muted);
}

.section-badge {
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  padding: 0 7px;
  color: #fff;
  background: #f04444;
  font-size: 12px;
  font-weight: 800;
}

.contact-caret {
  color: var(--request-muted);
  font-size: 24px;
  line-height: 1;
  transform-origin: center;
  transition: transform 160ms ease;
}

.contact-row.expanded .contact-caret {
  transform: rotate(90deg);
}

.request-panel .text-button {
  color: var(--accent);
}

.request-list,
.contact-list {
  display: grid;
  gap: 8px;
  margin: 8px 0 10px;
  padding-left: 28px;
}

.request-list.is-collapsed,
.contact-list.is-collapsed {
  display: none;
}

.request-empty,
.contact-empty {
  padding: 16px;
  border: 1px solid var(--request-line);
  border-radius: 8px;
  background: var(--request-empty-bg);
  color: var(--request-muted);
  font-size: 13px;
  text-align: center;
}

.request-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: var(--request-control-bg);
}

.refresh-inline {
  margin: 14px 4px 0;
  padding: 0;
}

.request-copy,
.lookup-card div {
  min-width: 0;
}

.request-copy strong,
.contact-person strong {
  display: block;
  overflow: hidden;
  color: var(--request-strong);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.request-copy span,
.contact-person em {
  display: block;
  overflow: hidden;
  color: var(--request-muted);
  font-size: 12px;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.request-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  padding-left: 44px;
}

.contact-person {
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 10px;
}

.mini-button {
  min-height: 28px;
  border: 0;
  border-radius: 8px;
  padding: 0 10px;
  color: #fff;
  background: var(--accent);
  font-size: 12px;
  font-weight: 760;
}

.mini-button.quiet {
  color: var(--muted);
  background: var(--panel-strong);
}

.request-panel .mini-button.quiet {
  color: var(--request-ink);
  background: var(--request-control-bg);
}

.friend-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 10px 14px;
}

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

.friend-item:hover {
  background: var(--panel-strong);
}

.friend-item.active {
  background: var(--accent-soft);
}

.avatar {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  background-position: center;
  background-size: cover;
  font-weight: 800;
}

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

.avatar.small {
  width: 32px;
  height: 32px;
  font-size: 12px;
}

.avatar.large {
  width: 54px;
  height: 54px;
  font-size: 20px;
}

.friend-meta,
.chat-title {
  min-width: 0;
}

.friend-meta strong,
.chat-title h2 {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friend-meta span,
.chat-title p,
.friend-time,
.field-hint {
  color: var(--muted);
  font-size: 13px;
}

.friend-time {
  align-self: start;
  padding-top: 4px;
}

.chat-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #ffffff 0%, #f8faf7 100%);
}

.chat-header {
  background: rgba(255, 255, 255, 0.82);
}

.message-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 24px;
}

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

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

.message-row.highlight .bubble {
  box-shadow: 0 0 0 3px rgba(49, 201, 133, 0.28), 0 6px 18px rgba(23, 32, 27, 0.05);
}

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

.bubble {
  max-width: min(520px, 72%);
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  line-height: 1.48;
  word-break: break-word;
  box-shadow: 0 6px 18px rgba(23, 32, 27, 0.05);
}

.bubble.attachment-bubble {
  max-width: min(340px, 70%);
  padding: 8px;
}

.bubble.voice-bubble {
  width: 230px;
  max-width: min(230px, 72%);
  padding: 10px 12px;
}

.voice-message {
  width: 100%;
  display: grid;
  grid-template-columns: 24px minmax(86px, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.voice-message-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: 999px;
}

.voice-message-icon::before,
.voice-message-icon::after {
  content: "";
  grid-area: 1 / 1;
  border: 2px solid currentColor;
  border-left: 0;
  border-top-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
}

.voice-message-icon::before {
  width: 7px;
  height: 10px;
}

.voice-message-icon::after {
  width: 13px;
  height: 16px;
}

.voice-message-wave {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.voice-message-wave i {
  width: 4px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.72;
}

.voice-message-wave i:nth-child(2) {
  height: 13px;
}

.voice-message-wave i:nth-child(3) {
  height: 17px;
}

.voice-message-wave i:nth-child(4) {
  height: 11px;
}

.voice-message.playing .voice-message-wave i {
  animation: voicePulse 700ms ease-in-out infinite;
}

.voice-message.loading .voice-message-wave i {
  animation: none;
  opacity: 0.42;
}

.voice-message.loading .voice-message-icon {
  animation: voiceLoading 900ms ease-in-out infinite;
  opacity: 0.64;
}

@keyframes voiceLoading {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(0.9);
  }
}

.voice-message strong {
  justify-self: end;
  white-space: nowrap;
  font-size: 13px;
}

.message-row.mine .bubble {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.bubble.pending {
  opacity: 0.78;
}

.bubble.failed {
  outline: 2px solid rgba(240, 68, 68, 0.34);
}

.message-error {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: #f04444;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 6px 16px rgba(240, 68, 68, 0.28);
}

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

.message-time {
  display: block;
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 11px;
}

.message-row:not(.mine) .message-time {
  color: var(--muted);
}

.message-state {
  display: block;
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 11px;
}

.attachment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 16px 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.message-attachment {
  display: block;
  width: auto;
  max-width: min(300px, 100%);
  max-height: 280px;
  margin-bottom: 8px;
  border-radius: 8px;
  object-fit: contain;
}

.attachment-open {
  display: block;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
}

.composer {
  flex: 0 0 auto;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.composer-surface {
  position: relative;
  display: grid;
  gap: 10px;
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.composer textarea {
  width: 100%;
  min-height: 104px;
  max-height: 190px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 14px 16px 4px;
  color: var(--ink);
  line-height: 1.55;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 0 10px 10px;
}

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

.tool-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-size: 18px;
  font-weight: 800;
}

.tool-button:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tool-button.recording {
  color: #fff;
  border-color: #f04444;
  background: #f04444;
}

.tool-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.mic-icon {
  width: 10px;
  height: 14px;
  display: block;
  position: relative;
  border: 1.8px solid currentColor;
  border-radius: 999px;
}

.mic-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 13px;
  height: 8px;
  border: 1.8px solid currentColor;
  border-top: 0;
  border-radius: 0 0 10px 10px;
  transform: translateX(-50%);
}

.mic-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -10px;
  width: 1.8px;
  height: 5px;
  background: currentColor;
  transform: translateX(-50%);
}

.voice-recorder {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 3;
  min-width: 260px;
  height: 44px;
  display: grid;
  grid-template-columns: 36px minmax(88px, 1fr) auto 36px;
  align-items: center;
  gap: 10px;
  padding: 4px;
  border-radius: 999px;
  background: var(--panel-strong);
  box-shadow: 0 12px 30px rgba(23, 32, 27, 0.12);
}

.voice-cancel-button,
.voice-send-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  font-size: 20px;
  font-weight: 800;
}

.voice-cancel-button {
  color: var(--muted);
  background: var(--panel);
}

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

.voice-wave {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.voice-wave span {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--accent);
  animation: voicePulse 900ms ease-in-out infinite;
}

.voice-wave span:nth-child(2) { animation-delay: 90ms; }
.voice-wave span:nth-child(3) { animation-delay: 180ms; }
.voice-wave span:nth-child(4) { animation-delay: 270ms; }
.voice-wave span:nth-child(5) { animation-delay: 360ms; }
.voice-wave span:nth-child(6) { animation-delay: 450ms; }

.voice-recorder strong {
  color: var(--muted);
  font-size: 12px;
}

@keyframes voicePulse {
  0%,
  100% {
    transform: scaleY(1);
    opacity: 0.45;
  }
  50% {
    transform: scaleY(2.4);
    opacity: 1;
  }
}

.composer textarea:focus,
.composer-surface:focus-within,
.dialog-surface input:focus,
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 111, 97, 0.14);
}

.send-button,
.primary-button,
.secondary-button {
  border: 0;
  border-radius: 8px;
  font-weight: 760;
}

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

.send-button {
  min-width: 88px;
  height: 36px;
}

.composer.is-recording .send-button {
  display: none;
}

.send-button:disabled,
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.secondary-button {
  color: var(--ink);
  background: var(--panel-strong);
}

.secondary-button:hover {
  background: #e3e9e2;
}

.contacts-panel {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 42px;
  background:
    radial-gradient(circle at 72% 18%, rgba(47, 197, 127, 0.1), transparent 28%),
    var(--request-card-bg);
}

.contact-card {
  width: min(520px, 100%);
  display: grid;
  gap: 26px;
  padding: 34px;
  color: var(--request-card-ink);
}

.contact-card-header {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--request-line);
}

.contact-card-header .avatar.large {
  width: 64px;
  height: 64px;
}

.contact-card h2 {
  overflow: hidden;
  margin-bottom: 6px;
  color: var(--request-card-ink);
  font-size: 22px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-card p {
  overflow: hidden;
  color: var(--request-card-muted);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-info-block {
  display: grid;
  gap: 18px;
  margin: 0;
  padding: 0 0 22px;
  border-bottom: 1px solid var(--request-line);
}

.contact-info-block div {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 18px;
}

.contact-info-block dt {
  color: var(--request-card-muted);
  font-size: 14px;
}

.contact-info-block dd {
  margin: 0;
  color: var(--request-card-ink);
  font-size: 15px;
  line-height: 1.5;
}

.contact-actions-row {
  display: flex;
  justify-content: center;
  gap: 34px;
}

.contact-action {
  min-width: 92px;
  display: grid;
  justify-items: center;
  gap: 8px;
  border: 0;
  color: var(--request-action);
  background: transparent;
}

.contact-action span {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--request-action) 46%, transparent);
  border-radius: 8px;
  color: var(--request-action);
  font-size: 21px;
}

.contact-action strong {
  font-size: 13px;
}

.contact-action:hover {
  color: var(--accent);
}

.contact-action:hover span {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.self-card-dialog {
  width: min(440px, calc(100vw - 40px));
  border: 0;
  border-radius: 12px;
  padding: 0;
  background: transparent;
}

.self-card-dialog::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

.self-card-surface {
  position: relative;
  display: grid;
  gap: 26px;
  padding: 34px 36px 32px;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
}

.self-card-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 22px;
}

.self-card-close:hover {
  background: var(--panel-strong);
}

.self-card-head {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 22px;
  align-items: center;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.self-card-head .avatar.large {
  width: 88px;
  height: 88px;
}

.self-card-head h2 {
  overflow: hidden;
  margin-bottom: 8px;
  font-size: 24px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.self-card-head p {
  color: var(--muted);
  line-height: 1.6;
}

.self-card-head strong {
  font-weight: 680;
}

.self-card-line {
  min-height: 54px;
  display: grid;
  gap: 8px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.self-card-line strong {
  color: var(--muted);
  font-size: 18px;
}

.self-card-line span {
  color: #9aa3a0;
  font-size: 13px;
}

.self-card-action {
  justify-self: center;
  display: grid;
  justify-items: center;
  gap: 8px;
  border: 0;
  color: #2f4f86;
  background: transparent;
}

.self-card-action span {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 2px solid #2f4f86;
  border-radius: 999px;
  font-size: 20px;
}

.self-card-tools {
  display: flex;
  gap: 10px;
}

.self-card-tools button {
  flex: 1;
  height: 38px;
  border: 0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 760;
}

.image-preview-dialog {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  border: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.9);
}

.image-preview-dialog::backdrop {
  background: rgba(0, 0, 0, 0.78);
}

.image-preview-dialog[open] {
  display: grid;
  place-items: center;
}

.image-preview-dialog img {
  max-width: min(92vw, 1280px);
  max-height: 88vh;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
}

.image-preview-close {
  position: fixed;
  top: 22px;
  right: 28px;
  z-index: 2;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  font-size: 26px;
}

.image-preview-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

.moments-panel {
  min-width: 0;
  overflow: auto;
  background: #f4f6f3;
}

.moments-topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid rgba(23, 32, 27, 0.08);
  background: rgba(244, 246, 243, 0.88);
  backdrop-filter: blur(16px);
}

.moments-topbar h1 {
  font-size: 22px;
}

.moments-cover {
  position: relative;
  min-height: 290px;
  margin-bottom: 58px;
  background:
    linear-gradient(135deg, rgba(22, 111, 97, 0.86), rgba(33, 47, 39, 0.54)),
    linear-gradient(45deg, #ced9d0, #eef2ed);
}

.moments-cover::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 96px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.18));
}

.moments-user {
  position: absolute;
  right: 44px;
  bottom: -34px;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  gap: 14px;
  color: #fff;
}

.moments-user strong {
  padding-bottom: 12px;
  font-size: 22px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.24);
}

.moments-user .avatar {
  width: 72px;
  height: 72px;
  border: 3px solid #fff;
  box-shadow: 0 10px 28px rgba(23, 32, 27, 0.18);
}

.moments-feed {
  width: min(720px, calc(100% - 56px));
  display: grid;
  gap: 0;
  margin: 0 auto 52px;
  background: #fff;
  border: 1px solid rgba(23, 32, 27, 0.08);
  border-radius: 8px;
}

.moment-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 14px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.moment-card:last-child {
  border-bottom: 0;
}

.moment-card strong {
  color: #315c87;
  font-size: 15px;
}

.moment-card p {
  margin: 8px 0 10px;
  color: var(--ink);
  line-height: 1.55;
}

.moment-card time {
  color: var(--muted);
  font-size: 12px;
}

.moment-photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 78px);
  gap: 6px;
  margin-bottom: 10px;
}

.moment-photo-grid span {
  aspect-ratio: 1;
  border-radius: 4px;
  background:
    linear-gradient(135deg, rgba(22, 111, 97, 0.72), rgba(182, 107, 45, 0.52)),
    #dfe8e1;
}

.friend-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.friend-dialog::backdrop {
  background: rgba(23, 32, 27, 0.32);
}

.dialog-surface {
  display: grid;
  gap: 16px;
  padding: 20px;
  background: #fff;
}

.dialog-surface header,
.dialog-surface footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-surface h2 {
  font-size: 20px;
}

.dialog-surface label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.dialog-surface input {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  padding: 0 12px;
  color: var(--ink);
}

.avatar-upload-field {
  position: relative;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  row-gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  cursor: pointer;
}

.avatar-upload-field > span {
  grid-column: 1 / -1;
}

.avatar-upload-field input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.avatar-upload-field strong {
  position: relative;
  z-index: 1;
  justify-self: start;
  min-width: 96px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
}

.avatar-upload-field em {
  position: relative;
  z-index: 1;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-upload-field:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.identity-preview {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.identity-preview .avatar.large {
  box-shadow: none;
}

.lookup-card {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.identity-preview strong {
  display: block;
  overflow: hidden;
  margin-bottom: 7px;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy-id-button {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--accent);
  background: #fff;
  font-size: 13px;
  font-weight: 760;
}

.copy-id-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.field-hint {
  margin-top: -8px;
}

.field-hint.error {
  color: #b42318;
}

.card-fields {
  display: grid;
  gap: 10px;
  margin: 0;
}

.card-fields div {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
}

.card-fields dt {
  color: var(--muted);
  font-size: 13px;
}

.card-fields dd {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
}

.dialog-surface footer {
  justify-content: flex-end;
}

.dialog-surface footer button {
  min-width: 82px;
  height: 40px;
}

@media (prefers-color-scheme: dark) {
  body {
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0)),
      var(--bg);
  }

  .auth-panel,
  .auth-tab.active,
  .search-box,
  .attachment-preview,
  .composer,
  .composer-surface,
  .tool-button,
  .bubble,
  .friend-dialog,
  .dialog-surface,
  .moments-feed,
  .self-card-surface {
    background: var(--panel);
  }

  .app-shell {
    border-color: var(--line);
    background: var(--panel);
  }

  .sidebar {
    background: #1d231f;
  }

  .chat-panel {
    background: linear-gradient(180deg, #202622 0%, #171c19 100%);
  }

  .chat-header {
    background: rgba(32, 38, 34, 0.86);
  }

  .auth-panel,
  .friend-dialog,
  .moments-feed {
    border-color: var(--line);
  }

  .app-shell[data-view="moments"] {
    background: var(--bg);
  }

  .moments-panel {
    background: var(--bg);
  }

  .moments-topbar {
    border-bottom-color: var(--line);
    background: rgba(23, 28, 25, 0.88);
  }

  .moment-card p {
    color: var(--ink);
  }

  .avatar-upload-field,
  .lookup-card {
    border-color: var(--line);
    background: var(--panel-strong);
  }

  .secondary-button:hover {
    background: #343d37;
  }
}

@media (max-width: 760px), (max-width: 1024px) and (pointer: coarse) {
  body {
    min-height: 100svh;
    background: var(--panel);
  }

  .app-shell {
    width: 100%;
    height: 100svh;
    min-height: 0;
    margin: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) calc(62px + env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .app-shell[data-view="requests"],
  .app-shell[data-view="moments"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) calc(62px + env(safe-area-inset-bottom));
  }

  .app-nav {
    grid-column: 1;
    grid-row: 2;
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    align-items: stretch;
    padding: 0 4px env(safe-area-inset-bottom);
    border-top: 1px solid var(--line);
    border-right: 0;
    background: var(--panel);
  }

  .nav-profile {
    order: 4;
  }

  .nav-button[data-view="messages"] {
    order: 1;
  }

  .nav-button[data-view="requests"] {
    order: 2;
  }

  .nav-button[data-view="moments"] {
    order: 3;
  }

  .nav-button,
  .nav-profile {
    width: 100%;
    height: 62px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-radius: 0;
    color: var(--muted);
    background: transparent;
    font-size: 20px;
  }

  .nav-button:hover,
  .nav-button.active,
  .nav-profile:hover,
  .nav-profile.active {
    color: var(--accent);
    background: transparent;
  }

  .nav-button.active::before,
  .nav-profile.active::before {
    top: 0;
    left: 50%;
    width: 28px;
    height: 3px;
    transform: translateX(-50%);
  }

  .nav-label {
    display: block;
    font-size: 12px;
    font-weight: 680;
    line-height: 1;
  }

  .nav-profile .avatar {
    width: 23px;
    height: 23px;
    border-radius: 5px;
    font-size: 11px;
  }

  .nav-icon-people {
    width: 23px;
    height: 23px;
  }

  .nav-icon-moments {
    width: 22px;
    height: 22px;
  }

  .nav-spacer,
  .nav-button.subtle {
    display: none;
  }

  .nav-badge {
    right: calc(50% - 28px);
    top: 6px;
  }

  .sidebar {
    grid-column: 1;
    grid-row: 1;
    border-right: 0;
  }

  .brand-bar {
    min-height: 62px;
    justify-content: flex-end;
    padding: max(12px, env(safe-area-inset-top)) 16px 8px;
    border-bottom: 0;
  }

  .brand-bar > div:first-child {
    display: none;
  }

  .header-actions {
    flex-direction: row;
    gap: 8px;
  }

  .mobile-action-button,
  #newFriendButton {
    width: auto;
    height: 38px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 16px;
    color: var(--ink);
    background: var(--panel);
    font-size: 14px;
    font-weight: 680;
  }

  #newFriendButton:hover,
  .mobile-action-button:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
  }

  .desktop-add-icon {
    display: none;
  }

  .mobile-add-label {
    display: inline;
  }

  .sidebar-search {
    display: none;
    margin: 0 16px 12px;
    padding: 0 12px;
  }

  .app-shell.mobile-search-open .sidebar-search {
    display: flex;
  }

  .search-box input {
    width: 100%;
  }

  .friend-list {
    padding: 8px 12px 12px;
  }

  .request-panel {
    padding: 8px 12px 12px;
  }

  .contact-manager,
  .contact-row,
  .contact-person {
    min-height: 44px;
  }

  .friend-item {
    min-height: 68px;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    justify-content: normal;
    gap: 12px;
    padding: 10px 8px;
  }

  .friend-meta,
  .friend-time {
    display: block;
  }

  .chat-panel {
    display: none;
    grid-column: 1;
    grid-row: 1 / -1;
  }

  .app-shell.mobile-conversation-open[data-view="messages"] .sidebar,
  .app-shell.mobile-conversation-open[data-view="messages"] .app-nav {
    display: none;
  }

  .app-shell.mobile-conversation-open[data-view="messages"] .chat-panel {
    display: flex;
  }

  .app-shell[data-view="requests"] .brand-bar {
    display: flex;
  }

  .app-shell[data-view="requests"] .contacts-panel {
    display: none;
  }

  .app-shell.mobile-contact-open[data-view="requests"] .sidebar,
  .app-shell.mobile-contact-open[data-view="requests"] .app-nav {
    display: none;
  }

  .app-shell.mobile-contact-open[data-view="requests"] .contacts-panel {
    grid-column: 1;
    grid-row: 1 / -1;
    display: flex;
  }

  .contacts-panel {
    position: relative;
    padding: 18px;
  }

  .mobile-panel-back {
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    left: 14px;
    z-index: 1;
    height: 38px;
    display: inline-flex;
    align-items: center;
    border: 0;
    padding: 0 8px;
    color: var(--accent);
    background: transparent;
    font-size: 16px;
    font-weight: 680;
  }

  .contact-card {
    gap: 18px;
    padding: 56px 12px 12px;
  }

  .contact-card-header {
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 12px;
  }

  .contact-card-header .avatar.large {
    width: 52px;
    height: 52px;
  }

  .contact-info-block div {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 12px;
  }

  .contact-actions-row {
    flex-wrap: wrap;
    gap: 18px;
  }

  .moments-topbar {
    min-height: 58px;
    padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  }

  .app-shell[data-view="moments"] .moments-panel {
    grid-column: 1;
    grid-row: 1;
    padding-bottom: 12px;
  }

  .moments-cover {
    min-height: 220px;
  }

  .moments-user {
    right: 20px;
  }

  .moments-feed {
    width: calc(100% - 24px);
    margin-bottom: 24px;
  }

  .moment-photo-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-width: 250px;
  }

  .chat-header {
    min-height: calc(62px + env(safe-area-inset-top));
    padding: max(12px, env(safe-area-inset-top)) 14px 10px;
    gap: 10px;
  }

  .mobile-back-button {
    width: 32px;
    height: 38px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border: 0;
    padding: 0;
    color: var(--accent);
    background: transparent;
    font-size: 34px;
    line-height: 1;
  }

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

  .bubble {
    max-width: 88%;
  }

  .composer {
    gap: 8px;
    padding: 10px;
  }

  .composer-surface {
    min-height: 132px;
  }

  .voice-recorder {
    left: 8px;
    right: 8px;
    min-width: 0;
  }

  .composer textarea {
    min-height: 88px;
  }

  .tool-button {
    width: 32px;
    height: 32px;
  }

  .self-card-dialog {
    width: calc(100vw - 28px);
  }

  .self-card-surface {
    gap: 20px;
    padding: 28px 20px 20px;
  }

  .self-card-head {
    grid-template-columns: 62px minmax(0, 1fr);
    gap: 14px;
    padding-bottom: 18px;
  }

  .self-card-head .avatar.large {
    width: 62px;
    height: 62px;
  }
}

.empty-state.compact {
  min-height: 120px;
  padding: 20px;
}

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

.search-group + .search-group {
  margin-top: 14px;
}

.search-group h3 {
  padding: 6px 8px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
}

.search-result {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  background: transparent;
  text-align: left;
}

.search-result:hover {
  background: var(--accent-soft);
}

.search-result span:not(.avatar) {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.search-result strong,
.search-result em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result strong {
  color: var(--ink);
  font-size: 14px;
}

.search-result em,
.search-result time {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}
