/* ============================================================
   私信 · 样式
   暗色为主：这是个聊天窗口，不是文档页面；暗底在手机上更省电，
   也让加密状态这类提示不刺眼。
   ============================================================ */

:root {
  --bg:        #131011;
  --surface:   #1c191a;
  --surface-2: #262223;
  --line:      #322c2e;
  --line-2:    #453d40;
  --ink:       #f0ece9;
  --dim:       #a49c97;
  --faint:     #7d7570;
  --mine:      #2f4a3d;
  --mine-line: #3d6350;
  --theirs:    #262223;
  --accent:    #7fb08f;
  --danger:    #e08a82;
  --warn:      #d9b06a;

  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei",
          "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --r: 10px;
  --r-sm: 7px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

.hidden { display: none !important; }
.spacer { flex: 1; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

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

.top {
  flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 12px clamp(14px, 3vw, 22px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding-top: max(12px, env(safe-area-inset-top));
}
.top-title { min-width: 0; }
.top-title strong { display: block; font-size: 1rem; font-weight: 600; }
.top-title .sub { display: block; font-size: 0.76rem; color: var(--dim); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; flex: none;
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--dim);
  cursor: pointer;
  transition: background 130ms ease-out, color 130ms ease-out;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------------- 通用块 ---------------- */

.pane {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: clamp(18px, 4vw, 30px) clamp(14px, 3vw, 22px) 28px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
.pane h1 { margin: 0 0 10px; font-size: 1.3rem; font-weight: 600; letter-spacing: 0.01em; }
.lead { margin: 0 0 22px; color: var(--dim); font-size: 0.9rem; }
.lead.small { font-size: 0.84rem; margin-bottom: 10px; }
.lead b { color: var(--ink); font-weight: 600; }

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 5px; color: var(--dim); font-size: 0.8rem; }
.field input, .field textarea, .field select {
  width: 100%; min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 0.92rem;
}
.field textarea { resize: vertical; font-family: var(--mono); font-size: 0.8rem; line-height: 1.5; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 7px 15px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--ink);
  font: inherit; font-size: 0.9rem; font-weight: 500;
  cursor: pointer;
  transition: background 130ms ease-out, border-color 130ms ease-out, opacity 130ms ease-out;
}
.btn:hover { background: var(--line); border-color: var(--faint); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #10231a; }
.btn.primary:hover { background: #93c2a2; border-color: #93c2a2; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--dim); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); border-color: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.note { margin-top: 10px; font-size: 0.82rem; color: var(--dim); min-height: 1.2em; }
.note.err { color: var(--danger); }
.note.ok { color: var(--accent); }
.hint { margin: 0 0 12px; color: var(--faint); font-size: 0.8rem; }
.rule { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }

.adv { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.adv summary { cursor: pointer; color: var(--dim); font-size: 0.86rem; }
.adv > *:not(summary) { margin-top: 12px; }

.code-box {
  padding: 14px;
  border: 1px dashed var(--line-2); border-radius: var(--r);
  background: var(--surface);
  font-family: var(--mono); font-size: 0.78rem; line-height: 1.55;
  word-break: break-all;
  user-select: all;
}
.waiting { margin-top: 14px; color: var(--warn); font-size: 0.85rem; }
.waiting::after { content: ''; animation: dots 1.4s steps(4, end) infinite; }
@keyframes dots { 0% { content: '' } 25% { content: '·' } 50% { content: '··' } 75% { content: '···' } }

/* 安全码 */
.sas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}
.sas span {
  padding: 9px 6px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface);
  font-family: var(--mono); font-size: 1rem; font-weight: 600;
  text-align: center; letter-spacing: 0.06em;
}
.sas.small span { font-size: 0.82rem; padding: 6px 4px; }

.panel {
  margin-bottom: 18px; padding: 16px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface);
}
.panel h3 { margin: 0 0 12px; font-size: 0.9rem; font-weight: 600; }
.kv { display: flex; gap: 12px; align-items: baseline; padding: 4px 0; font-size: 0.84rem; }
.kv span { flex: none; width: 76px; color: var(--faint); }
.kv b { font-weight: 500; min-width: 0; }

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

.chat {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  min-height: 0;
  max-width: 780px; width: 100%; margin: 0 auto;
}

.msgs {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px clamp(12px, 3vw, 22px) 8px;
  display: flex; flex-direction: column; gap: 8px;
}

.m { max-width: min(78%, 560px); display: flex; flex-direction: column; }
.m.out { align-self: flex-end; align-items: flex-end; }
.m.in  { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--theirs);
  white-space: pre-wrap;
  word-break: break-word;
}
.m.out .bubble { background: var(--mine); border-color: var(--mine-line); }

.meta {
  margin: 3px 4px 0;
  font-family: var(--mono); font-size: 0.68rem; color: var(--faint);
}
.m.error .bubble { border-color: var(--danger); color: var(--danger); background: transparent; }

/* 文件气泡 */
.file {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 13px; min-width: 210px;
}
.file-icon { flex: none; color: var(--dim); }
.file-body { min-width: 0; }
.file-name { font-size: 0.88rem; word-break: break-all; }
.file-size { font-family: var(--mono); font-size: 0.7rem; color: var(--dim); }
.file a, .file button {
  flex: none;
  min-height: 30px; padding: 4px 11px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: transparent; color: var(--ink);
  font: inherit; font-size: 0.8rem; text-decoration: none;
  cursor: pointer;
}
.file a:hover, .file button:hover { background: var(--line); }
.file-expired { color: var(--warn); font-size: 0.74rem; }

.daysep {
  align-self: center;
  margin: 12px 0 4px;
  color: var(--faint); font-size: 0.72rem; font-family: var(--mono);
}

.empty-chat {
  margin: auto; text-align: center;
  color: var(--faint); font-size: 0.86rem; line-height: 1.9;
}

/* 附件预览 */
.attach-preview {
  display: flex; align-items: center; gap: 10px;
  margin: 0 clamp(12px, 3vw, 22px) 6px;
  padding: 8px 12px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); font-size: 0.82rem;
}
.attach-size { color: var(--dim); font-family: var(--mono); font-size: 0.72rem; }

/* 输入区 */
.composer {
  flex: none;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px clamp(12px, 3vw, 22px);
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.composer textarea {
  flex: 1;
  min-height: 40px; max-height: 160px;
  padding: 9px 12px;
  border: 1px solid var(--line-2); border-radius: var(--r);
  background: var(--bg); color: var(--ink);
  font: inherit; font-size: 0.92rem;
  resize: none;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.composer .icon-btn { width: 40px; height: 40px; }

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

.toast {
  position: fixed; left: 50%; bottom: 22px;
  transform: translate(-50%, 10px);
  z-index: 60;
  max-width: min(90vw, 420px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--ink); color: var(--bg);
  font-size: 0.84rem; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity 160ms ease-out, transform 160ms ease-out;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #1b1210; }

@media (max-width: 520px) {
  .m { max-width: 88%; }
  .kv { flex-direction: column; gap: 2px; }
  .kv span { width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
