:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3fb;
  --line: #dce4f0;
  --text: #152033;
  --muted: #66758c;
  --brand: #0f67ff;
  --brand-2: #11a3b8;
  --success: #168a55;
  --danger: #d83232;
  --warning: #c77700;
  --shadow: 0 18px 45px rgba(20, 42, 77, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

a {
  color: var(--brand);
}

.boot {
  min-height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
}

.boot img {
  width: 84px;
  height: 84px;
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.boot strong {
  color: var(--text);
  font-size: 26px;
}

.auth-page {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr);
  background: var(--surface);
}

.auth-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 42px;
  border-right: 1px solid var(--line);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 34px;
}

.auth-brand img,
.top-brand-main > img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
}

.auth-brand b {
  font-size: 28px;
}

.auth-title {
  margin: 0 0 8px;
  font-size: 30px;
}

.auth-subtitle {
  margin: 0 0 26px;
  color: var(--muted);
  line-height: 1.6;
}

.auth-tabs,
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 8px;
}

.auth-tabs button,
.segmented button {
  height: 38px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

.auth-tabs button.active,
.segmented button.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 5px rgba(20, 42, 77, 0.08);
}

.form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

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

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

.input,
.textarea,
.select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.input,
.select {
  height: 44px;
  padding: 0 12px;
}

.textarea {
  min-height: 42px;
  max-height: 140px;
  padding: 11px 12px;
  resize: vertical;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: rgba(15, 103, 255, 0.62);
  box-shadow: 0 0 0 3px rgba(15, 103, 255, 0.12);
}

.primary,
.secondary,
.ghost,
.danger,
.icon-btn {
  height: 40px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}

.primary {
  background: var(--brand);
  color: #fff;
  padding: 0 16px;
}

.secondary {
  background: #e8f2ff;
  color: #0759d6;
  padding: 0 14px;
}

.ghost {
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
}

.danger {
  background: #ffecec;
  color: var(--danger);
  padding: 0 12px;
}

.icon-btn {
  width: 40px;
  min-width: 40px;
  background: var(--surface-2);
  color: var(--text);
}

.auth-visual {
  display: grid;
  place-items: center;
  padding: 42px;
  background:
    linear-gradient(135deg, rgba(15, 103, 255, 0.12), transparent 42%),
    linear-gradient(315deg, rgba(17, 163, 184, 0.16), transparent 38%),
    #f7faff;
}

.preview-phone {
  width: min(390px, 92%);
  min-height: 620px;
  border: 1px solid rgba(21, 32, 51, 0.12);
  border-radius: 34px;
  padding: 18px;
  background: #111b2f;
  box-shadow: var(--shadow);
}

.preview-screen {
  height: 100%;
  min-height: 580px;
  border-radius: 24px;
  background: #f8fafc;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.preview-header {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.preview-header img {
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

.preview-list {
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.preview-row {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand);
}

.preview-chat {
  display: grid;
  gap: 8px;
  padding: 14px;
  align-content: end;
}

.bubble {
  max-width: 76%;
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 14px;
}

.bubble.left {
  justify-self: start;
  background: #fff;
  border: 1px solid var(--line);
}

.bubble.right {
  justify-self: end;
  color: #fff;
  background: var(--brand);
}

.message {
  min-height: 100%;
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 320px;
  background: var(--bg);
}

.sidebar,
.side-panel {
  min-width: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.side-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.top-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 76px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.top-brand-main {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.top-brand-main div,
.chat-title div {
  min-width: 0;
}

.top-brand-main strong,
.chat-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.sidebar-tools {
  padding: 12px 14px;
  display: grid;
  gap: 10px;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.list {
  overflow: auto;
  padding: 8px;
}

.list-section-title {
  padding: 10px 9px 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

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

.list-item:hover,
.list-item.active {
  background: var(--surface-2);
}

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

.avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: inherit;
}

.group-avatar {
  background: var(--brand-2);
}

.profile-avatar-xl {
  width: 72px;
  height: 72px;
  font-size: 24px;
}

.item-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.mini-tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  background: #e8f2ff;
  color: #0759d6;
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
}

.item-sub {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  min-width: 22px;
  height: 22px;
  border-radius: 99px;
  display: grid;
  place-items: center;
  padding: 0 7px;
  color: #fff;
  background: var(--danger);
  font-size: 12px;
}

.request-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 64px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.chat {
  min-width: 0;
  display: grid;
  grid-template-rows: 76px minmax(0, 1fr) auto;
  background: #eef3f8;
}

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

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

.back-btn {
  display: none;
}

.messages {
  overflow: auto;
  padding: 18px;
  display: grid;
  align-content: end;
  gap: 14px;
}

.empty {
  align-self: center;
  justify-self: center;
  text-align: center;
  color: var(--muted);
  max-width: 420px;
  line-height: 1.7;
  padding: 18px;
}

.msg {
  display: grid;
  grid-template-columns: 40px minmax(0, auto);
  gap: 9px;
  justify-content: start;
  align-items: end;
}

.msg.mine {
  grid-template-columns: minmax(0, auto) 40px;
  justify-content: end;
}

.msg.mine .avatar {
  grid-column: 2;
}

.msg.mine .msg-content {
  grid-column: 1;
  grid-row: 1;
  align-items: end;
}

.msg-content {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.msg-meta {
  color: var(--muted);
  font-size: 12px;
}

.msg-bubble {
  max-width: min(620px, 68vw);
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg.mine .msg-bubble {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

.msg-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.msg.mine .msg-actions {
  justify-content: flex-end;
}

.msg-actions .ghost {
  height: 28px;
  padding: 0 8px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  font-size: 12px;
}

.msg.system {
  display: block;
  text-align: center;
}

.msg.system .msg-bubble {
  display: inline-block;
  max-width: 80%;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.68);
}

.msg-file {
  display: flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
}

.msg-image {
  max-width: min(320px, 60vw);
  max-height: 360px;
  border-radius: 8px;
  display: block;
}

.composer {
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 12px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: end;
}

.side-scroll {
  overflow: auto;
  padding: 16px;
  display: grid;
  gap: 16px;
  align-content: start;
}

.panel-section {
  display: grid;
  gap: 10px;
}

.panel-section h3 {
  margin: 0;
  font-size: 17px;
}

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

.settings-panel {
  gap: 18px;
}

.settings-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.settings-head h3 {
  margin-bottom: 4px;
}

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

.group-panel {
  gap: 18px;
}

.mute-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.mute-box strong {
  display: block;
  margin-bottom: 4px;
}

.mute-note {
  padding: 10px 12px;
  border: 1px solid #ffd8a8;
  border-radius: 8px;
  background: #fff7ed;
  color: #9a5b00;
  font-size: 13px;
  line-height: 1.5;
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.setting-row span {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.setting-row small {
  color: var(--muted);
  font-size: 12px;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row-actions .ghost,
.row-actions .secondary,
.row-actions .danger {
  height: 32px;
  padding: 0 9px;
  font-size: 12px;
}

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

.feature-list span {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

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

.compact-results {
  max-height: 260px;
  overflow: auto;
}

.check-row,
.admin-row,
.result-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  min-height: 50px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

button.result-row {
  width: 100%;
  color: var(--text);
  text-align: left;
}

.message-result .item-sub {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.full-btn {
  width: 100%;
}

.check-row input {
  justify-self: center;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-tabs button.active {
  background: var(--brand);
  color: #fff;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stat b {
  display: block;
  font-size: 22px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 11px 16px;
  border-radius: 8px;
  background: rgba(21, 32, 51, 0.95);
  color: #fff;
  z-index: 30;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .side-panel {
    display: none;
  }
}

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

  .auth-panel {
    border-right: 0;
    padding: 28px 20px;
  }

  .auth-visual {
    display: none;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: 100%;
  }

  .chat {
    display: none;
    min-height: 100%;
  }

  .app-shell.mobile-chat .sidebar {
    display: none;
  }

  .app-shell.mobile-chat .chat {
    display: grid;
  }

  .back-btn {
    display: inline-flex;
  }

  .messages {
    padding: 14px 10px;
  }

  .msg-bubble {
    max-width: 72vw;
  }

  .request-card {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .request-card .row-actions,
  .request-card .mini-tag {
    grid-column: 2;
    justify-self: start;
  }

  .setting-row {
    grid-template-columns: 1fr;
  }

  .setting-row button {
    justify-self: start;
  }

  .composer {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}
