/* 私聊 v0.3.0 — 第 3 步：界面与本地记录 */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c1e21;
  --text-dim: #7a7f87;
  --line: #e4e6ea;
  --accent: #3b6ff0;
  --accent-soft: #e8eefe;
  --danger: #e5484d;
  --ok: #2e9e5b;
  --radius: 14px;
}

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

/* 关键：防止作者 display 规则覆盖 hidden 属性（此 bug 曾导致双界面同时渲染） */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

#app { height: 100dvh; display: flex; flex-direction: column; }
#main { display: flex; flex-direction: column; height: 100%; min-height: 0; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.title-wrap { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.title-wrap h1 { margin: 0; font-size: 18px; line-height: 1.2; }
.peer-name {
  font-size: 12px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); cursor: pointer; padding: 6px; margin-right: -6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-off { background: #c2c7cf; }
.dot-on { background: var(--ok); }
.dot-wait { background: #e8a33d; }
.icon-btn {
  border: none; background: none; color: var(--text-dim);
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn:active { background: var(--accent-soft); }

/* ---------- 消息区 ---------- */
.msg-list {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 14px 12px 10px;
  display: flex; flex-direction: column; gap: 10px;
}
.empty { margin: auto; text-align: center; color: var(--text-dim); padding: 0 24px; }
.empty p { margin: 4px 0; }
.empty-sub { font-size: 13px; line-height: 1.7; }

.msg { display: flex; max-width: 82%; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; }

.bubble {
  position: relative;
  padding: 9px 12px 6px;
  border-radius: var(--radius);
  line-height: 1.55;
  word-break: break-word;          /* 长消息/URL 换行 */
  overflow-wrap: anywhere;
  white-space: pre-wrap;           /* 保留换行 */
  font-size: 15.5px;
}
.msg.in .bubble { background: var(--surface); border: 1px solid var(--line); border-top-left-radius: 4px; }
.msg.out .bubble { background: var(--accent); color: #fff; border-top-right-radius: 4px; }

.msg-meta {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; row-gap: 2px;
  margin-top: 3px; font-size: 11px; color: var(--text-dim);
}
.msg.out .msg-meta { color: rgba(255,255,255,.75); justify-content: flex-end; }
.msg.out.failed .msg-meta { color: #ffb4b6; }

.status { display: inline-flex; align-items: center; gap: 3px; flex-wrap: wrap; row-gap: 2px; }
.status .spin {
  width: 10px; height: 10px; border-radius: 50%;
  border: 1.5px solid currentColor; border-top-color: transparent;
  animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.copy-btn {
  border: none; background: none; color: inherit; opacity: .55;
  padding: 0 2px; cursor: pointer; font-size: 11px; line-height: 1;
  white-space: nowrap; flex-shrink: 0;
}
.copy-btn:active { opacity: 1; }

.retry-btn {
  margin-left: 4px;
  border: 1px solid currentColor; background: none; color: inherit;
  font-size: 11px; border-radius: 8px; padding: 1px 8px; cursor: pointer;
  white-space: nowrap; flex-shrink: 0;   /* 防止“重试”被挤成竖排 */
}

.err-hint { color: var(--danger); }
.msg.out.failed .err-hint { color: #ffd2d3; }

/* ---------- 输入区 ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
#input {
  flex: 1; resize: none;
  border: 1px solid var(--line); border-radius: 18px;
  padding: 9px 14px; font: inherit; font-size: 15.5px;
  max-height: 120px; outline: none; background: var(--bg);
  line-height: 1.45;
}
#input:focus { border-color: var(--accent); }
.btn-send {
  border: none; background: var(--accent); color: #fff;
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.btn-send:disabled { background: #c2c7cf; }
.btn-send:not(:disabled):active { filter: brightness(.92); }

/* ---------- 上滑面板 / 弹窗 / 提示 ---------- */
.sheet-mask, .modal-mask-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 8px 18px calc(env(safe-area-inset-bottom, 0px) + 18px);
  max-height: 86dvh; overflow-y: auto;
  max-width: 560px; margin: 0 auto;
}
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 14px; }
.sheet h2 { margin: 0 0 12px; font-size: 17px; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 5px; }
.field input {
  width: 100%; font: inherit; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; outline: none; background: var(--bg);
}
.field input:focus { border-color: var(--accent); }

.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
.info-row b { font-weight: 500; color: var(--text-dim); }

.btn-primary {
  width: 100%; margin-top: 8px;
  border: none; border-radius: 12px; padding: 13px;
  background: var(--accent); color: #fff; font: inherit; font-size: 16px; cursor: pointer;
}
.btn-primary:active { filter: brightness(.92); }
.btn-danger {
  width: 100%; margin-top: 16px;
  border: 1px solid var(--danger); border-radius: 12px; padding: 12px;
  background: none; color: var(--danger); font: inherit; font-size: 15px; cursor: pointer;
}
.btn-danger-solid {
  border: none; border-radius: 10px; padding: 10px 18px;
  background: var(--danger); color: #fff; font: inherit; cursor: pointer;
}
.btn-ghost {
  width: 100%; margin-top: 10px;
  border: none; border-radius: 12px; padding: 12px;
  background: var(--bg); color: var(--text-dim); font: inherit; cursor: pointer;
}

.about {
  margin-top: 18px; padding: 12px; border-radius: 12px;
  background: var(--bg); font-size: 12.5px; color: var(--text-dim); line-height: 1.7;
}
.about p { margin: 4px 0; }
.about b { color: var(--text); }

.modal {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  z-index: 60; background: var(--surface); border-radius: 16px;
  padding: 20px 18px 14px; width: min(86vw, 340px);
}
.modal-text { margin: 0 0 16px; font-size: 15px; line-height: 1.6; }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; }
.modal-btns .btn-ghost { width: auto; margin: 0; padding: 10px 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 90px);
  transform: translateX(-50%); z-index: 70;
  background: rgba(28,30,33,.92); color: #fff;
  font-size: 13.5px; padding: 9px 16px; border-radius: 20px;
  max-width: 80vw; text-align: center;
  animation: toast-in .18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } }

/* ---------- 配对面板 ---------- */
.pair-step { font-size: 14px; color: var(--text); line-height: 1.6; margin: 0 0 12px; }
.pair-hint { font-size: 13px; color: var(--text-dim); line-height: 1.6; margin: 0 0 12px; }
.pair-qr { display: block; margin: 0 auto 8px; max-width: 100%; }
.qr-hint { text-align: center; font-size: 12px; color: var(--text-dim); margin: 0 0 12px; }
.pair-btns { display: flex; gap: 10px; }
.pair-btns .btn-primary { flex: 1; margin-top: 0; }
.btn-scan {
  border: 1px solid var(--accent); border-radius: 12px; padding: 13px 20px;
  background: none; color: var(--accent); font: inherit; font-size: 15px; cursor: pointer;
  white-space: nowrap;
}
.pair-video {
  width: 100%; max-height: 40dvh; object-fit: cover;
  border-radius: 12px; margin-top: 12px; background: #000;
}
.pair-note {
  margin-top: 14px; padding: 10px 12px; border-radius: 12px;
  background: var(--bg); font-size: 12px; color: var(--text-dim); line-height: 1.7;
}
.field textarea {
  width: 100%; font: inherit; font-size: 13px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; outline: none;
  background: var(--bg); resize: none; line-height: 1.5;
  word-break: break-all;
}
.field textarea:focus { border-color: var(--accent); }
.field textarea[readonly] { color: var(--text-dim); }

/* ---------- 首次使用 ---------- */
.onboarding {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.onb-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 22px;
}
.onb-card h1 { margin: 0 0 6px; font-size: 26px; text-align: center; }
.onb-sub { text-align: center; color: var(--text-dim); font-size: 13.5px; line-height: 1.7; margin: 0 0 20px; }
.onb-error { color: var(--danger); font-size: 13px; margin: 0 0 8px; }
.onb-note { font-size: 12px; color: var(--text-dim); text-align: center; line-height: 1.7; margin: 14px 0 0; }
