:root {
  --blue: #0c447c;
  --blue-2: #185fa5;
  --blue-soft: #e6f1fb;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #6b7785;
  --line: #e2e7ee;
  --bubble-other: #eef2f7;
  --ok: #0f6e56;   --ok-bg: #e1f5ee;
  --warn: #ba7517; --warn-bg: #faeeda;
  --err: #a32d2d;  --err-bg: #fbeaea;
  --radius-sm: 8px; --radius: 12px; --radius-lg: 16px; --radius-pill: 999px;
  --tap: 44px;
  --gap: 10px;
  --maxw: 560px;
  --shadow-card: none;
  --shadow-pop: none;
}

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

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px; line-height: 1.6;
  min-height: 100vh; min-height: 100dvh;
}

header {
  text-align: center;
  padding: 22px 16px 6px;
}
header h1 { margin: 0; font-size: 26px; font-weight: 500; color: var(--blue); letter-spacing: 1px; }
header .sub { margin: 6px 0 0; font-size: 13px; color: var(--muted); padding: 0 12px; }

.status {
  max-width: var(--maxw); margin: 12px auto 0;
  text-align: center; font-size: 13px; color: var(--muted);
  padding: 8px 12px; border-radius: 20px; background: var(--blue-soft);
}
.status.ok { color: var(--ok); background: var(--ok-bg); }
.status.err { color: var(--err); background: var(--err-bg); }
.status.warn { color: var(--warn); background: var(--warn-bg); }

.card {
  max-width: var(--maxw); margin: 14px auto;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 18px 16px;
  box-shadow: var(--shadow-card);
}
.card h2 { margin: 0 0 10px; font-size: 17px; font-weight: 500; color: var(--blue); }
.card h3 { margin: 18px 0 8px; font-size: 14px; font-weight: 500; color: var(--muted); }

.hidden { display: none !important; }

.role-btns { display: flex; gap: 12px; flex-wrap: wrap; }
.role-btns button { flex: 1 1 160px; }

button {
  border: none; border-radius: 10px;
  padding: 13px 16px; min-height: var(--tap);
  font-size: 15px; font-weight: 500; cursor: pointer;
  background: var(--bubble-other); color: var(--text);
  transition: filter .15s, background .15s;
}
button:active { filter: brightness(.93); }
button:hover { filter: brightness(1.04); }
button:focus-visible { outline: 2px solid var(--blue-2); outline-offset: 2px; }
button.primary { background: var(--blue-2); color: #fff; }
button.ghost { background: var(--bubble-other); color: var(--blue); }
button.small { padding: 6px 12px; min-height: 34px; font-size: 13px; }

.hint, .steps { color: var(--muted); font-size: 13px; }
.steps { padding-left: 18px; margin: 8px 0 14px; }
.steps li { margin: 4px 0; }

/* QR */
.qr-box {
  display: flex; justify-content: center; align-items: center;
  min-height: 60px; margin: 10px 0; padding: 12px;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  text-align: center; color: var(--muted); font-size: 13px;
  box-shadow: var(--shadow-card);
}
.qr-box svg { width: 100%; max-width: 240px; height: auto; }
.qr-box.small { max-width: 180px; margin: 8px auto; padding: 8px; border-radius: 10px; box-shadow: none; }

/* 房间号芯片 */
.room-code {
  display: block; width: fit-content; margin: 8px auto; padding: 8px 20px;
  background: #f1efe8; border-radius: var(--radius-sm);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 14px; font-weight: 500; color: var(--text);
  text-align: center; cursor: pointer;
  border: 1px solid transparent; transition: border-color .15s;
}
.room-code:hover { border-color: var(--line); }

.payload {
  width: 100%; margin: 8px 0; padding: 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 11px; color: var(--text);
}

.row { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.row button { flex: 1 1 140px; }

.scan-box video {
  width: 100%; max-height: 320px; border-radius: 10px;
  background: #000; object-fit: cover;
}

/* ============================================================
   聊天室（满屏 App 布局）
   ============================================================ */
#chatRoom {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; overflow: hidden;
  max-width: var(--maxw); margin: 0 auto; width: 100%;
  background: var(--card);
}
#chatRoom.card { box-shadow: none; border: none; border-radius: 0; padding: 0; margin-top: 0; }

/* 吸顶头部 */
.chat-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; flex-shrink: 0;
  border-bottom: 1px solid var(--line); background: var(--card);
}
.chat-tag {
  font-size: 11px; color: #fff; background: var(--blue-2);
  display: inline-block; padding: 2px 8px; border-radius: 10px;
}
.chat-room { font-size: 15px; color: var(--blue); font-weight: 500; margin-top: 4px; }
.chat-room span { font-family: ui-monospace, Menlo, Consolas, monospace; }
.chat-state { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* 状态点 */
.conn-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle; position: relative; top: -1px;
  background: var(--muted); transition: background .3s;
}
.conn-dot.ok { background: var(--ok); }
.conn-dot.warn { background: var(--warn); }
.conn-dot.err { background: var(--err); }
.conn-dot.pulse { animation: connPulse 1.4s ease infinite; }

/* 消息区 */
.chat-log {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 16px; display: flex; flex-direction: column; gap: 10px;
}
.chat-empty {
  flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; padding: 20px; text-align: center;
}

/* 新消息浮钮 */
.new-msg-btn {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--blue-2); color: #fff; border: none;
  padding: 6px 16px; border-radius: var(--radius-pill); font-size: 13px; font-weight: 500;
  cursor: pointer; box-shadow: var(--shadow-pop); z-index: 10;
  animation: fadeInUp .2s ease;
}
.new-msg-btn.hidden { display: none; }

/* 气泡 */
.bubble-row { display: flex; }
.bubble-row.me { justify-content: flex-end; }
.bubble-row.them { justify-content: flex-start; }
.bubble { max-width: 78%; background: var(--bubble-other); border-radius: 14px; padding: 8px 12px; font-size: 14px; }
.bubble-row.me .bubble { background: var(--blue-2); color: #fff; }
.bubble-name { font-size: 11px; opacity: .7; margin-bottom: 2px; }
.bubble-text { white-space: pre-wrap; word-break: break-word; }
.bubble-img { display: block; max-width: 100%; max-height: 220px; border-radius: var(--radius-sm); margin: 4px 0; cursor: zoom-in; }
.bubble-meta { font-size: 12px; margin-top: 4px; }
.bubble-dl { color: var(--blue-2); font-weight: 500; text-decoration: none; }
.bubble-row.me .bubble-dl { color: #fff; text-decoration: underline; }

/* 文件进度条 */
.bubble-progress {
  width: 100%; height: 4px; background: rgba(0,0,0,.1); border-radius: 2px; margin-top: 6px; overflow: hidden;
}
.bubble-row.me .bubble-progress { background: rgba(255,255,255,.25); }
.bubble-progress-bar { height: 100%; border-radius: 2px; background: var(--blue-2); transition: width .15s ease; }
.bubble-row.me .bubble-progress-bar { background: #fff; }

/* 邀请区（对方离开） */
.invite {
  margin: 0 16px 12px; padding: 14px 16px;
  background: var(--warn-bg); border-radius: var(--radius);
  text-align: center; border: 1px solid rgba(186,117,23,.2);
}
.invite .hint { margin: 0 0 8px; font-size: 13px; color: var(--warn); }

/* 底部输入栏 */
.chat-composer {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; flex-shrink: 0; overflow: hidden;
  padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
  border-top: 1px solid var(--line); background: var(--card);
}
.icon-btn {
  background: var(--bubble-other); border: none; cursor: pointer;
  width: 40px; height: 40px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: var(--blue-2); transition: background .15s; flex-shrink: 0;
}
.icon-btn:hover { background: #dde3eb; }
.icon-btn svg { width: 19px; height: 19px; }

#chatText {
  flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-pill); font-size: 14px; outline: none;
  transition: border-color .15s;
}
#chatText:focus { border-color: var(--blue-2); }
#chatSend {
  padding: 8px 16px; min-height: 40px; flex-shrink: 0;
  border-radius: var(--radius-pill);
}

/* 图片大图查看（Lightbox） */
.lightbox {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(10,14,20,.88);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out; padding: 16px;
}
.lightbox img {
  max-width: 96%; max-height: 94%;
  border-radius: var(--radius); background: #fff;
}

/* Toast */
.toast-container {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  z-index: 200; pointer-events: none; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #1c2733; color: #fff; padding: 10px 20px;
  border-radius: var(--radius-pill); font-size: 13px; text-align: center;
  box-shadow: var(--shadow-pop); pointer-events: auto;
  animation: toastIn .25s ease, toastOut .2s .8s ease forwards;
  white-space: nowrap;
}
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }

/* 拖拽遮罩（PC） */
.drop-mask {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(12,68,124,.88); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 500; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.drop-mask.hidden { display: none; }

/* 帮助 */
.help {
  max-width: var(--maxw); margin: 16px auto 40px;
  padding: 0 16px; font-size: 13px; color: var(--muted);
}
.help summary { cursor: pointer; color: var(--blue); font-weight: 500; }
.help ul { padding-left: 18px; }
.help li { margin: 6px 0; }

/* 动画 */
@keyframes connPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-6px); }
}

/* ============================================================
   PC 桌面端增强
   ============================================================ */
@media (min-width: 768px) {
  #chatRoom { border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); margin-top: 10px; margin-bottom: 10px; height: calc(100vh - 20px); height: calc(100dvh - 20px); }
  .chat-head { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .chat-composer { border-radius: 0 0 var(--radius-lg) var(--radius-lg); padding-bottom: 10px; padding: 10px 14px; gap: 8px; }
  .icon-btn { width: 44px; height: 44px; }
  .icon-btn svg { width: 20px; height: 20px; }
  #chatText { padding: 11px 14px; }
  #chatSend { padding: 10px 18px; min-height: 44px; }
  .qr-box svg { max-width: 280px; }
  .room-code { font-size: 16px; padding: 10px 28px; }
  .new-msg-btn { bottom: 100px; }
  .toast-container { bottom: 100px; }
}
