:root {
  --bg: #FFFFFF;
  --bg-soft: #F7F6F3;
  --bg-sheet: #FFFFFF;
  --line: rgba(20, 20, 18, 0.09);
  --line-strong: rgba(20, 20, 18, 0.18);
  --text: #1A1A18;
  --text-2: #6B6A65;
  --text-3: #9A9893;
  --primary: #185FA5;
  --primary-dark: #0C447C;
  --primary-soft: #E6F1FB;
  --bubble-peer: #F1EFE8;
  --danger: #A32D2D;
  --danger-soft: #FCEBEB;
  --shadow: 0 8px 32px rgba(20, 20, 18, 0.10);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161A;
    --bg-soft: #1E1E23;
    --bg-sheet: #202025;
    --line: rgba(255, 255, 255, 0.10);
    --line-strong: rgba(255, 255, 255, 0.22);
    --text: #EDEDEA;
    --text-2: #A3A29C;
    --text-3: #75746F;
    --primary: #4E8FD0;
    --primary-dark: #B5D4F4;
    --primary-soft: #1B2A3A;
    --bubble-peer: #2A2A30;
    --danger: #F09595;
    --danger-soft: #3A1E1E;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea { font-family: inherit; }
button { cursor: pointer; border: none; background: none; color: inherit; }

/* ------------------------------------------------ 登录 */

.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-soft);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg);
  border: 0.5px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px 22px;
  box-shadow: 0 1px 2px rgba(20, 20, 18, 0.04);
}

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

.login-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.login-logo svg { width: 19px; height: 19px; }

.login-title { font-size: 17px; font-weight: 500; margin: 0; line-height: 1.3; }
.login-sub { font-size: 12.5px; color: var(--text-2); margin: 2px 0 0; }

.field-label {
  display: block;
  font-size: 12.5px;
  color: var(--text-2);
  margin-bottom: 6px;
}

.field-input {
  width: 100%;
  font-size: 16px;
  padding: 11px 13px;
  border: 0.5px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.15s;
}
.field-input:focus { border-color: var(--primary); }
.field-input::placeholder { color: var(--text-3); }

.field-password { position: relative; }
.field-password .field-input { padding-right: 44px; }
.eye-btn {
  position: absolute;
  right: 4px;
  top: 0;
  height: 100%;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  margin-bottom: 16px;
}
.eye-btn svg { width: 17px; height: 17px; }

.login-error {
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  border-radius: 9px;
  padding: 9px 12px;
  margin-bottom: 14px;
}

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: #FFFFFF;
  font-size: 15px;
  font-weight: 500;
  padding: 12px;
  border-radius: 10px;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.82; }
.btn-primary:disabled { opacity: 0.45; }
.btn-small { width: auto; padding: 9px 18px; font-size: 13.5px; margin-top: 4px; }

.login-hint {
  font-size: 11.5px;
  color: var(--text-3);
  text-align: center;
  margin: 16px 0 0;
}

/* ------------------------------------------------ iOS 提示条 */

.ios-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-top, 0px));
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12.5px;
  line-height: 1.4;
  border-bottom: 0.5px solid var(--line);
}
.ios-banner-text { flex: 1; }
.ios-banner-btn {
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  flex-shrink: 0;
}
.ios-banner-close { font-size: 18px; color: var(--text-3); padding: 0 2px; flex-shrink: 0; }

/* ------------------------------------------------ 聊天主体 */

.chat-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  height: 100vh;
  height: 100dvh;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(9px + env(safe-area-inset-top, 0px)) 14px 9px;
  border-bottom: 0.5px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
  z-index: 10;
}

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

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  flex-shrink: 0;
}

.peer-meta { min-width: 0; }
.peer-name { font-size: 15px; font-weight: 500; line-height: 1.25; }
.peer-status {
  font-size: 11.5px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}
.peer-status .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-3);
  display: inline-block;
}
.peer-status.online .dot { background: #639922; }
.peer-status.online { color: #3B6D11; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  flex-shrink: 0;
}
.icon-btn:active { background: var(--bg-soft); }
.icon-btn svg { width: 19px; height: 19px; }

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px 6px;
  -webkit-overflow-scrolling: touch;
}

.messages-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.load-more-wrap { text-align: center; margin-bottom: 10px; }
.load-more {
  font-size: 12.5px;
  color: var(--text-2);
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--bg-soft);
}

.day-divider {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-3);
  margin: 10px 0 4px;
}

.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }

.bubble {
  max-width: 74%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-row.theirs .bubble {
  background: var(--bubble-peer);
  border-bottom-left-radius: 5px;
}
.msg-row.mine .bubble {
  background: var(--primary);
  color: #FFFFFF;
  border-bottom-right-radius: 5px;
}

.bubble.pending { opacity: 0.72; }
.bubble.failed { background: var(--danger-soft); color: var(--danger); border-bottom-right-radius: 5px; }

.bubble-image {
  padding: 0;
  overflow: hidden;
  border-radius: 14px;
  background: var(--bubble-peer);
  line-height: 0;
  cursor: zoom-in;
}
.bubble-image img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 240px;
  max-height: 320px;
  object-fit: cover;
}
.bubble-image.loading {
  width: 160px;
  height: 120px;
  background: linear-gradient(100deg, var(--bubble-peer) 30%, var(--bg-soft) 50%, var(--bubble-peer) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer {
  from { background-position: 150% 0; }
  to { background-position: -50% 0; }
}

.typing-hint {
  font-size: 11.5px;
  color: var(--text-3);
  padding: 0 16px 4px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 0.5px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}

.composer-img { color: var(--text-2); }

.composer-input {
  flex: 1;
  font-size: 16px;
  line-height: 1.45;
  padding: 9px 12px;
  border: 0.5px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  resize: none;
  max-height: 132px;
  overflow-y: hidden;
  outline: none;
  transition: border-color 0.15s;
}

.empty-state {
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 56px 20px;
}
.composer-input:focus { border-color: var(--primary); }
.composer-input::placeholder { color: var(--text-3); }

.btn-send {
  background: var(--primary);
  color: #FFFFFF;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: 10px;
  flex-shrink: 0;
  margin-bottom: 1px;
}
.btn-send:disabled { opacity: 0.4; }
.btn-send:active:not(:disabled) { opacity: 0.82; }

/* ------------------------------------------------ 上传进度 */

.upload-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 18, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 70;
}
.upload-box {
  background: var(--bg-sheet);
  border-radius: var(--radius);
  padding: 18px 20px;
  width: 220px;
  box-shadow: var(--shadow);
}
.upload-bar {
  height: 5px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.upload-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--primary);
  transition: width 0.2s;
}
.upload-text {
  font-size: 12.5px;
  color: var(--text-2);
  margin-top: 10px;
  text-align: center;
}

/* ------------------------------------------------ 设置面板 */

.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 18, 0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 80;
}

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg-sheet);
  border-radius: 18px 18px 0 0;
  padding: 6px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 500;
  padding: 10px 0 4px;
}
.sheet-head .icon-btn { font-size: 22px; color: var(--text-3); width: 32px; }

.sheet-block {
  border-top: 0.5px solid var(--line);
  padding: 14px 0;
}
.sheet-block:first-of-type { border-top: none; }

.sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 0;
}
.sheet-title { font-size: 14px; font-weight: 500; }
.sheet-title-standalone { margin-bottom: 10px; }
.sheet-desc { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.btn-ghost {
  font-size: 12.5px;
  color: var(--primary);
  border: 0.5px solid var(--line-strong);
  border-radius: 8px;
  padding: 6px 13px;
  flex-shrink: 0;
}
.btn-ghost:active { background: var(--bg-soft); }

.btn-danger {
  width: 100%;
  color: var(--danger);
  font-size: 14px;
  padding: 11px;
  border-radius: 10px;
  background: var(--danger-soft);
}

.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute;
  inset: 0;
  background: var(--line-strong);
  border-radius: 999px;
  transition: background 0.2s;
}
.switch span::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(18px); }

.sheet-foot {
  font-size: 11px;
  color: var(--text-3);
  text-align: center;
  margin: 6px 0 0;
  line-height: 1.6;
}

/* ------------------------------------------------ 灯箱与提示 */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 16px;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translate(-50%, 12px);
  background: rgba(26, 26, 24, 0.9);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

[hidden] { display: none !important; }

@media (min-width: 720px) {
  .messages { padding: 16px 24px 6px; }
  .composer { padding: 10px 24px 12px; }
  .chat-header { padding: 12px 24px; }
}
