:root {
  color-scheme: light;
  --page: #dbe7e2;
  --shell: #f7faf8;
  --sidebar: #ffffff;
  --header: #eef4f1;
  --line: #d7e1dc;
  --text: #17231f;
  --muted: #66756f;
  --green: #128c7e;
  --green-2: #25d366;
  --bubble-me: #d9fdd3;
  --bubble-them: #ffffff;
  --shadow: 0 28px 80px rgba(22, 37, 31, 0.2);
}

body.dark {
  color-scheme: dark;
  --page: #0b141a;
  --shell: #111b21;
  --sidebar: #111b21;
  --header: #202c33;
  --line: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --green: #00a884;
  --green-2: #25d366;
  --bubble-me: #005c4b;
  --bubble-them: #202c33;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 15%, rgba(37, 211, 102, 0.18), transparent 30%),
    radial-gradient(circle at 85% 80%, rgba(18, 140, 126, 0.16), transparent 34%),
    var(--page);
  color: var(--text);
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.hidden {
  display: none !important;
}

.auth-screen {
  width: min(440px, calc(100% - 32px));
}

.auth-card {
  border: 1px solid rgba(23, 35, 31, 0.12);
  border-radius: 8px;
  padding: 28px;
  background: var(--sidebar);
  box-shadow: var(--shadow);
}

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

.brand-row h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

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

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 24px 0 16px;
}

.auth-tabs button,
.ghost-button,
.danger-button,
.primary-button,
.row-actions button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}

.auth-tabs button {
  background: var(--header);
  color: var(--muted);
}

.auth-tabs button.is-active,
.primary-button {
  background: var(--green);
  color: #fff;
}

.auth-form,
.stack-form {
  display: grid;
  gap: 12px;
}

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

.auth-form input,
.stack-form input,
.stack-form select,
.inline-form input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  padding: 0 13px;
  background: var(--shell);
  color: var(--text);
}

.form-message {
  min-height: 20px;
  margin: 12px 0 0;
  color: #d9480f;
  font-size: 13px;
  font-weight: 750;
}

.auth-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.phone-shell {
  width: min(1180px, calc(100% - 36px));
  height: min(760px, calc(100vh - 36px));
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(23, 35, 31, 0.12);
  border-radius: 8px;
  background: var(--shell);
  box-shadow: var(--shadow);
}

.sidebar,
.chat {
  min-height: 0;
}

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

.sidebar-panel {
  min-height: 0;
  overflow: hidden;
}

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

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

.settings-panel {
  overflow: auto;
  padding: 18px;
}

.section-title {
  padding: 18px 18px 10px;
}

.section-title h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.section-title p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.sidebar-header,
.chat-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--header);
}

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

.profile h1,
.profile h2 {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile h2 {
  font-size: 17px;
}

.profile p {
  margin: 5px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.avatar-me {
  background: linear-gradient(135deg, var(--green), var(--green-2));
}

.icon-button,
.send-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

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

.header-actions .utility-action {
  display: none;
}

.add-button {
  background: rgba(37, 211, 102, 0.14);
  color: var(--green);
}

.icon-button:hover {
  background: rgba(134, 150, 160, 0.14);
}

.back-button {
  display: none;
  flex: 0 0 auto;
}

svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.search-box {
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.search-box svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.search-box input,
.composer input {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 999px;
  outline: none;
  background: var(--header);
  color: var(--text);
}

.search-box input {
  min-height: 40px;
  padding: 0 14px;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  min-height: 32px;
  border: 0;
  border-radius: 999px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
  cursor: pointer;
}

.tabs button.is-active {
  background: rgba(37, 211, 102, 0.15);
  color: var(--green);
}

.add-friend {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.add-friend input {
  width: 100%;
  min-height: 38px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  padding: 0 11px;
  background: var(--header);
  color: var(--text);
}

.add-friend button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 13px;
  background: var(--green);
  color: #fff;
  font-weight: 850;
  cursor: pointer;
}

.add-friend p {
  grid-column: 1 / -1;
  min-height: 16px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.contact-list {
  min-height: 0;
  overflow: auto;
}

.empty-panel {
  margin: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: rgba(134, 150, 160, 0.08);
  font-size: 14px;
  line-height: 1.6;
}

.contact {
  width: 100%;
  min-height: 76px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.contact:hover,
.contact.is-active {
  background: rgba(134, 150, 160, 0.12);
}

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

.contact-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

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

.contact-name strong {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 15px;
}

.private-chip {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(108, 99, 255, 0.14);
  color: #5f54e8;
  font-size: 11px;
  font-weight: 900;
}

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

.contact-preview {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.unread {
  min-width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--green-2);
  color: #05291a;
  font-size: 12px;
  font-weight: 900;
}

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    linear-gradient(rgba(238, 244, 241, 0.74), rgba(238, 244, 241, 0.74)),
    repeating-linear-gradient(45deg, transparent 0 22px, rgba(18, 140, 126, 0.05) 22px 23px);
}

.bottom-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  background: var(--header);
}

.bottom-nav button {
  min-height: 62px;
  display: grid;
  place-items: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.bottom-nav button.is-active {
  color: var(--green);
}

.bottom-nav svg {
  width: 22px;
  height: 22px;
}

.settings-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px 16px;
  background: var(--header);
  text-align: center;
}

.settings-card h2 {
  margin: 8px 0 0;
  font-size: 21px;
}

.settings-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.settings-role {
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(37, 211, 102, 0.16);
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
}

.settings-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.settings-actions button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar);
  color: var(--text);
  font-weight: 850;
  cursor: pointer;
}

.settings-actions .danger-row {
  border-color: rgba(217, 72, 15, 0.28);
  color: #d9480f;
}

.settings-note {
  margin: 16px 2px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 13, 16, 0.46);
}

.modal-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 10px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.modal-header p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.modal-form {
  display: grid;
  gap: 10px;
  padding: 10px 18px 18px;
}

.modal-form input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  padding: 0 13px;
  background: var(--header);
  color: var(--text);
}

.modal-form button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

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

.call-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 13, 16, 0.72);
}

.call-card {
  width: min(430px, 100%);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: #111b21;
  color: #e9edef;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.45);
}

.call-video-stage {
  position: relative;
  min-height: 280px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 18%, rgba(37, 211, 102, 0.18), transparent 36%),
    #0b141a;
}

.call-video-stage video {
  width: 100%;
  height: 100%;
  min-height: 280px;
  object-fit: cover;
  background: #0b141a;
}

#localVideo {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 112px;
  height: 84px;
  min-height: 0;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.34);
}

.call-avatar {
  width: 92px;
  height: 92px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--green), var(--green-2));
  color: #fff;
  font-size: 34px;
  font-weight: 950;
}

.call-info {
  padding: 18px 20px 8px;
  text-align: center;
}

.call-info h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.25;
}

.call-info p {
  margin: 8px 0 0;
  color: #aebac1;
  font-size: 13px;
  line-height: 1.5;
}

.call-actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 14px 18px 22px;
}

.call-button {
  min-width: 96px;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.call-button.accept {
  background: var(--green);
}

.call-button.decline {
  background: #d9480f;
}

body.dark .chat {
  background:
    linear-gradient(rgba(11, 20, 26, 0.86), rgba(11, 20, 26, 0.86)),
    repeating-linear-gradient(45deg, transparent 0 22px, rgba(37, 211, 102, 0.05) 22px 23px);
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 24px;
}

.day-divider {
  width: fit-content;
  margin: 0 auto 18px;
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  font-size: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

body.dark .day-divider {
  background: rgba(32, 44, 51, 0.9);
}

.message-row {
  display: flex;
  margin: 7px 0;
}

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

.bubble {
  max-width: min(68%, 520px);
  border-radius: 8px;
  padding: 9px 10px 7px;
  background: var(--bubble-them);
  color: var(--text);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}

.message-row.me .bubble {
  background: var(--bubble-me);
}

.bubble p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.message-image {
  display: block;
  width: min(280px, 68vw);
  max-height: 300px;
  object-fit: cover;
  border-radius: 7px;
}

.message-image + p {
  margin-top: 7px;
}

.sticker-message {
  font-size: 34px;
  line-height: 1.1;
}

.voice-message {
  display: grid;
  gap: 6px;
  min-width: min(250px, 62vw);
}

.voice-message audio {
  width: 100%;
  height: 34px;
}

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

.message-meta {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.message-row.me .message-meta {
  color: rgba(26, 66, 49, 0.72);
}

body.dark .message-row.me .message-meta {
  color: rgba(233, 237, 239, 0.62);
}

.composer {
  min-height: 72px;
  display: grid;
  grid-template-columns: auto auto auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 16px;
  background: var(--header);
}

.composer input {
  min-height: 46px;
  padding: 0 16px;
  background: var(--sidebar);
}

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

.icon-button.is-recording {
  background: #e5484d;
  color: #fff;
}

.icon-button.is-recording svg {
  stroke: currentColor;
}

.recording-status {
  grid-column: 1 / -1;
  width: fit-content;
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(229, 72, 77, 0.12);
  color: #c73338;
  font-size: 13px;
  font-weight: 700;
}

.send-button svg {
  width: 19px;
  height: 19px;
}

.sticker-tray {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 0 4px;
}

.sticker-tray button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar);
  font-size: 22px;
  cursor: pointer;
}

.sticker-tray button:hover {
  border-color: rgba(37, 211, 102, 0.5);
  background: rgba(37, 211, 102, 0.12);
}

@media (max-width: 820px) {
  body {
    display: block;
  }

  .phone-shell {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    grid-template-columns: 1fr;
    border: 0;
    border-radius: 0;
  }

  .sidebar {
    height: 100%;
    max-height: none;
    border-right: 0;
  }

  .sidebar-header,
  .chat-header {
    min-height: 64px;
    padding: 9px 12px;
  }

  .avatar {
    width: 42px;
    height: 42px;
  }

  .profile {
    gap: 10px;
  }

  .profile h1,
  .profile h2 {
    font-size: 17px;
  }

  .icon-button,
  .send-button {
    width: 38px;
    height: 38px;
  }

  .search-box {
    min-height: 56px;
    padding: 8px 12px;
  }

  .tabs {
    padding: 8px 12px;
  }

  .contact {
    min-height: 72px;
    padding: 9px 12px;
  }

  .bottom-nav button {
    min-height: 58px;
  }

  .chat {
    height: 100vh;
    height: 100dvh;
  }

  .phone-shell:not(.chat-open) .chat {
    display: none;
  }

  .phone-shell.chat-open .sidebar {
    display: none;
  }

  .phone-shell.chat-open .chat {
    display: grid;
  }

  .back-button {
    display: inline-grid;
  }

  .messages {
    padding: 18px 14px;
  }

  .bubble {
    max-width: 82%;
  }

  .message-image {
    width: min(240px, 72vw);
    max-height: 260px;
  }

  .composer {
    min-height: 62px;
    gap: 6px;
    padding: 8px 10px;
  }

  .composer input {
    min-height: 42px;
    padding: 0 13px;
  }

  .modal-backdrop {
    align-items: end;
    padding: 12px;
  }

  .modal-card {
    width: 100%;
  }

  .call-backdrop {
    padding: 12px;
  }

  .call-card {
    width: 100%;
  }

  .call-video-stage,
  .call-video-stage video {
    min-height: 240px;
  }

  #localVideo {
    width: 96px;
    height: 72px;
  }
}

.admin-body {
  display: block;
  min-height: 100vh;
  background: var(--page);
}

.admin-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 28px auto;
}

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.admin-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--sidebar);
  color: var(--text);
  text-decoration: none;
}

.danger-button {
  background: #ffe3e3;
  color: #c92a2a;
}

.notice,
.admin-panel,
.summary-card {
  border: 1px solid rgba(23, 35, 31, 0.1);
  border-radius: 8px;
  background: var(--sidebar);
  box-shadow: 0 14px 36px rgba(22, 37, 31, 0.08);
}

.notice {
  margin-bottom: 14px;
  padding: 14px 16px;
  color: #c92a2a;
  font-weight: 800;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.summary-card {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 18px;
}

.summary-card strong {
  color: var(--green);
  font-size: 30px;
}

.summary-card span {
  color: var(--muted);
  font-weight: 750;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.admin-panel {
  margin-bottom: 14px;
  padding: 18px;
}

.panel-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title h2 {
  margin: 0;
  font-size: 18px;
}

.panel-title span {
  color: var(--muted);
  font-size: 13px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
}

td small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--header);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.badge.good {
  background: rgba(37, 211, 102, 0.16);
  color: var(--green);
}

.badge.bad {
  background: #ffe3e3;
  color: #c92a2a;
}

.badge.warn {
  background: #fff3bf;
  color: #a15c00;
}

.row-actions button {
  min-height: 32px;
  background: var(--header);
  color: var(--text);
}

.message-cell {
  max-width: 420px;
  white-space: normal;
  overflow-wrap: anywhere;
}

@media (max-width: 860px) {
  .admin-topbar,
  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

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