:root {
  --bg: #ffffff;
  --bg-soft: #f4f4f5;
  --bg-header: #ffffff;
  --text: #111111;
  --text-soft: #707579;
  --border: #e4e4e6;
  --primary: #3390ec;
  --primary-text: #ffffff;
  --bubble-in: #ffffff;
  --bubble-out: #effdde;
  --bubble-in-border: #ededed;
  --danger: #e53935;
  --scrim: rgba(0, 0, 0, 0.35);
  --radius: 10px;
}

html.theme-dark {
  --bg: #17212b;
  --bg-soft: #0e1621;
  --bg-header: #17212b;
  --text: #f5f5f5;
  --text-soft: #8b9aa8;
  --border: #24313d;
  --primary: #5aa7ea;
  --primary-text: #ffffff;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --bubble-in-border: #24313d;
  --danger: #ff6b6b;
  --scrim: rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

#app {
  height: 100%;
  position: relative;
}

.hidden {
  display: none !important;
}

/* ---------- 图标（IconPark 线性） ---------- */

.ic {
  display: block;
  width: 22px;
  height: 22px;
  pointer-events: none;
}

.ic-sm {
  width: 18px;
  height: 18px;
}

.screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  -webkit-transform: translateZ(0);
}

.screen.active {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
}

/* ---------- 登录 / 配置 ---------- */

.setup-wrap {
  padding: 32px 24px 24px;
  padding-top: calc(32px + env(safe-area-inset-top));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.brand {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 8px;
}

.muted {
  color: var(--text-soft);
  font-size: 14px;
  margin: 0 0 24px;
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field > span {
  display: block;
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.field input {
  display: block;
  width: 100%;
  padding: 11px 12px;
  font-size: 16px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}

.field input:focus {
  border-color: var(--primary);
}

.btn {
  display: inline-block;
  padding: 11px 16px;
  font-size: 16px;
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--primary);
  text-align: center;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.btn:disabled {
  opacity: 0.5;
}

.btn-block {
  display: block;
  width: 100%;
  margin-top: 12px;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 500;
}

.btn-plain {
  background: var(--bg-soft);
  color: var(--text);
  border-color: var(--border);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--border);
}

.btn-link {
  color: var(--primary);
  font-size: 14px;
  padding: 8px;
}

.hint {
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.5;
  margin: 20px 0 0;
}

.status {
  min-height: 20px;
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--danger);
  white-space: pre-wrap;
}

/* ---------- 登录页签与二维码 ---------- */

.login-tabs {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  margin-bottom: 20px;
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 3px;
}

.tab {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  padding: 8px 0;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-soft);
  background: transparent;
  border: none;
  border-radius: 8px;
  -webkit-appearance: none;
  appearance: none;
}

.tab.active {
  background: var(--bg);
  color: var(--text);
  font-weight: 500;
}

.qr-box {
  position: relative;
  width: 100%;
  max-width: 240px;
  margin: 0 auto;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.qr-image {
  width: 100%;
  height: 220px;
}

.qr-image svg {
  display: block;
  width: 100%;
  height: 100%;
}

.qr-mask {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 20px;
  background: rgba(255, 255, 255, 0.94);
  color: #333333;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  border-radius: var(--radius);
}

.qr-status {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-soft);
  text-align: center;
  min-height: 20px;
}

.qr-status.error {
  color: var(--danger);
}

.diag {
  margin-top: 18px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-soft);
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  height: 52px;
  padding: 0 8px;
  padding-top: env(safe-area-inset-top);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
  padding-left: 8px;
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
}

.topbar-actions {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
}

.icon-btn {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.icon-btn:active {
  background: var(--bg-soft);
}

/* ---------- 滚动容器 ---------- */

.scroller {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

.empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-soft);
  font-size: 14px;
}

/* ---------- 会话列表 ---------- */

.dialog-list {
  background: var(--bg);
}

.dialog-row {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.dialog-row:active {
  background: var(--bg-soft);
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
  background: #7b8fa1;
  color: #ffffff;
  font-size: 18px;
  font-weight: 500;
  line-height: 48px;
  text-align: center;
  position: relative;
}

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

.dialog-main {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  min-width: 0;
  padding-left: 12px;
}

.dialog-line {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
}

.dialog-name {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 500;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.dialog-time {
  font-size: 12px;
  color: var(--text-soft);
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
  margin-left: 8px;
}

.dialog-preview {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  margin-top: 2px;
}

.dialog-text {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  min-width: 0;
  font-size: 14px;
  color: var(--text-soft);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.unread {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  margin-left: 8px;
  border-radius: 10px;
  background: var(--primary);
  color: #ffffff;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}

.pin {
  font-size: 12px;
  color: var(--text-soft);
  margin-right: 4px;
}

.avatar-icon {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  background: var(--bg-soft);
  color: var(--text-soft);
  border: 1px solid var(--border);
}

.row-action {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-left: 4px;
  padding: 0;
  color: var(--text-soft);
  background: transparent;
  border: none;
  border-radius: 18px;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
}

.row-action .ic {
  width: 20px;
  height: 20px;
}

.row-action:active {
  background: var(--bg-soft);
  color: var(--primary);
}

.archive-entry .dialog-name {
  font-weight: 500;
}

/* ---------- 聊天 ---------- */

.chat-topbar {
  padding-left: 4px;
}

.chat-head {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  min-width: 0;
  padding-left: 4px;
}

.chat-title {
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-subtitle {
  font-size: 12px;
  color: var(--text-soft);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.message-list {
  background: var(--bg-soft);
  padding: 8px 0;
}

#message-items {
  padding-bottom: 4px;
}

.msg-row {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  padding: 1px 8px;
}

.msg-row.out {
  -webkit-box-pack: end;
  -webkit-justify-content: flex-end;
  justify-content: flex-end;
}

.bubble {
  max-width: 82%;
  padding: 6px 9px 7px;
  border-radius: 12px;
  background: var(--bubble-in);
  border: 1px solid var(--bubble-in-border);
  font-size: 15px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  -webkit-user-select: text;
  user-select: text;
}

.msg-row.out .bubble {
  background: var(--bubble-out);
  border-color: transparent;
}

.msg-sender {
  font-size: 13px;
  font-weight: 500;
  color: var(--primary);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-meta {
  float: right;
  margin: 6px 0 0 8px;
  font-size: 11px;
  color: var(--text-soft);
  line-height: 1;
}

.msg-media {
  margin: -4px -6px 4px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-soft);
}

.msg-media img {
  display: block;
  max-width: 100%;
  max-height: 320px;
}

.msg-media-loading {
  padding: 26px 40px;
  font-size: 13px;
  color: var(--text-soft);
  text-align: center;
}

.msg-text {
  white-space: pre-wrap;
}

.msg-file-info {
  min-width: 0;
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
}

.msg-file {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  min-width: 180px;
  padding: 6px 4px;
}

.msg-file-icon {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}

.msg-file-name {
  font-size: 14px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.msg-file-size {
  font-size: 12px;
  color: var(--text-soft);
}

.msg-reply {
  padding: 3px 6px;
  margin-bottom: 4px;
  border-left: 2px solid var(--primary);
  background: rgba(51, 144, 236, 0.08);
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-soft);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.msg-actions {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  padding: 6px 8px 0;
}

.msg-actions .btn {
  font-size: 13px;
  padding: 4px 8px;
}

.chat-date {
  text-align: center;
  margin: 10px 0 6px;
  font-size: 12px;
  color: var(--text-soft);
}

.load-more {
  margin: 6px auto 10px;
  padding: 6px 14px;
  width: 140px;
  font-size: 13px;
  color: var(--primary);
  text-align: center;
  background: var(--bg);
  border-radius: 14px;
  cursor: pointer;
}

/* ---------- 输入栏 ---------- */

.composer {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: end;
  -webkit-align-items: flex-end;
  align-items: flex-end;
  padding: 6px 8px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}

.attach-btn {
  height: 36px;
  width: 36px;
}

#composer-input {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  min-height: 36px;
  max-height: 108px;
  margin: 0 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 16px;
  line-height: 20px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 18px;
  outline: none;
  resize: none;
  -webkit-appearance: none;
  appearance: none;
}

.send-btn {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  width: 44px;
  height: 36px;
  padding: 0;
  color: #ffffff;
  background: var(--primary);
  border: none;
  border-radius: 18px;
  -webkit-appearance: none;
  appearance: none;
}

.send-btn .ic {
  width: 20px;
  height: 20px;
}

.send-btn:disabled {
  opacity: 0.45;
}

.file-progress {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.82);
  color: #ffffff;
  font-size: 13px;
  border-radius: 8px;
  text-align: center;
  z-index: 30;
}

/* ---------- 设置 ---------- */

.settings-body {
  padding: 8px 16px 24px;
}

.settings-row {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.settings-row .btn {
  padding: 6px 10px;
  font-size: 14px;
}

.settings-body .btn-block {
  margin-top: 28px;
}

/* ---------- 提示 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  max-width: 80%;
  padding: 9px 14px;
  background: rgba(0, 0, 0, 0.82);
  color: #ffffff;
  font-size: 14px;
  border-radius: 8px;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  -webkit-transition: opacity 0.2s;
  transition: opacity 0.2s;
  z-index: 40;
}

.toast.show {
  opacity: 1;
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--scrim);
  z-index: 20;
}
