/* 聊天室样式。无构建步骤；flex 带旧前缀，老浏览器退化为块级布局仍可用。 */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef0f4; --border: #dfe3ea;
  --text: #1b1f27; --muted: #6b7280; --accent: #2563eb; --accent-text: #ffffff;
  --mine: #dbe8ff; --theirs: #ffffff; --danger: #c2410c; --ok: #16a34a; --warn: #d97706;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418; --surface: #1b1e25; --surface-2: #232730; --border: #2e333d;
    --text: #e6e8ee; --muted: #9aa1ad; --accent: #4f8ef7; --accent-text: #0b1220;
    --mine: #1f3a66; --theirs: #1f232b; --danger: #f97316; --ok: #22c55e; --warn: #f59e0b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: #f6f7f9; background: var(--bg);
  color: #1b1f27; color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Noto Sans CJK SC", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.hidden { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }

.notice { padding: 16px; text-align: center; background: #fde68a; color: #1b1f27; }

/* ---------- 登录卡片 ---------- */
.screen { position: absolute; top: 0; right: 0; bottom: 0; left: 0; }
#auth, #unlock, #unsupported {
  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: 16px; overflow: auto;
  padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.card {
  width: 100%; max-width: 380px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); padding: 28px 24px;
}
.brand { text-align: center; margin-bottom: 20px; }
.brand img { display: block; margin: 0 auto 8px; }
.brand h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: .01em; }
.brand .sub, .card p.sub { color: var(--muted); margin: 6px 0 0; font-size: 14px; }
.card h1 { font-size: 22px; margin: 0 0 8px; }
.card p { color: var(--muted); }

.tabs { display: -webkit-box; display: -webkit-flex; display: flex; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.tab { -webkit-box-flex: 1; -webkit-flex: 1; flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; min-height: 40px; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.form label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
.form label small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.form input {
  display: block; width: 100%; margin-top: 6px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 12px; font-size: 16px; /* 16px：iOS 聚焦不自动放大 */
  min-height: 46px; -webkit-appearance: none; appearance: none;
}
.form input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(37,99,235,.18); }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 14px; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 10px; padding: 12px; min-height: 46px;
  font-weight: 600; background: var(--surface-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:disabled { opacity: .6; cursor: default; }
.btn.link { background: transparent; color: var(--accent); margin-top: 6px; font-weight: 500; }
.error { color: var(--danger); font-size: 14px; min-height: 1.4em; margin: 10px 0 0; }

/* ---------- 聊天 ---------- */
#chat {
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-orient: vertical; -webkit-flex-direction: column; flex-direction: column;
  height: 100%; height: 100dvh;
}
.topbar {
  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: 10px 12px 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
  -webkit-flex-shrink: 0; flex-shrink: 0;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar .meta { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-right: 6px; vertical-align: 1px; }
.dot.on { background: var(--ok); } .dot.off { background: var(--danger); }
.icon-btn { background: transparent; border: 0; width: 44px; height: 44px; border-radius: 50%; color: var(--muted); display: inline-block; vertical-align: middle; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { vertical-align: middle; }

.banner { padding: 10px 16px; font-size: 14px; background: #fff7ed; color: #9a3412; border-bottom: 1px solid #fed7aa; -webkit-flex-shrink: 0; flex-shrink: 0; }
@media (prefers-color-scheme: dark) { .banner { background: #3b2410; color: #fdba74; border-color: #7c3a12; } }

.messages {
  -webkit-box-flex: 1; -webkit-flex: 1 1 auto; flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 12px 8px; overscroll-behavior: contain;
}
.day { text-align: center; color: var(--muted); font-size: 12px; margin: 14px 0 8px; }
.day span { background: var(--surface-2); padding: 3px 10px; border-radius: 999px; }
.msg { max-width: 78%; margin: 2px 0; clear: both; }
.msg.theirs { float: left; }
.msg.mine { float: right; }
.msg .who { font-size: 12px; color: var(--muted); margin: 8px 0 2px 10px; }
.msg.mine .who { display: none; }
.bubble {
  display: inline-block; max-width: 100%; padding: 8px 12px; border-radius: var(--radius);
  background: var(--theirs); border: 1px solid var(--border); box-shadow: 0 1px 1px rgba(0,0,0,.04);
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; word-break: break-word;
  -webkit-user-select: text; user-select: text;
}
.msg.mine .bubble { background: var(--mine); border-color: transparent; }
.msg.first .bubble { border-top-left-radius: 6px; } .msg.mine.first .bubble { border-top-left-radius: var(--radius); border-top-right-radius: 6px; }
.msg .time { font-size: 11px; color: var(--muted); margin: 2px 10px 0; }
.msg.mine .time { text-align: right; }
.msg.pending .bubble { opacity: .6; }
.msg.failed .bubble { border-color: var(--danger); color: var(--danger); }
.msg.locked .bubble { color: var(--muted); font-style: italic; }
.msg.system { float: none; max-width: 100%; text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0; }
.clearfix { clear: both; height: 0; }

.jump {
  position: absolute; left: 50%; bottom: 84px; -webkit-transform: translateX(-50%); transform: translateX(-50%);
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 999px; padding: 8px 14px;
  box-shadow: var(--shadow); font-weight: 600;
}

.composer {
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-align: end; -webkit-align-items: flex-end; align-items: flex-end;
  padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); -webkit-flex-shrink: 0; flex-shrink: 0;
}
.composer textarea {
  -webkit-box-flex: 1; -webkit-flex: 1; flex: 1; resize: none; max-height: 140px; min-height: 44px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 22px; padding: 11px 14px; font-size: 16px;
  line-height: 1.35; -webkit-appearance: none; appearance: none; overflow-y: hidden; /* 单行时不露滚动条；超过最大高度由 JS 切回 auto */
}
.composer textarea:focus { border-color: var(--accent); outline: none; }
.btn.send { width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%; margin-left: 8px; background: var(--accent); color: var(--accent-text); -webkit-flex-shrink: 0; flex-shrink: 0; }
.btn.send:disabled { opacity: .45; cursor: default; }
.btn.send svg { vertical-align: middle; position: relative; left: 1px; }

/* ---------- 成员抽屉 ---------- */
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: 300px; max-width: 86%;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); overflow-y: auto; z-index: 20;
}
.drawer-head { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-align: center; align-items: center; -webkit-box-pack: justify; justify-content: space-between; }
.drawer h2 { font-size: 17px; margin: 0; }
.me { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin: 12px 0; }
.me .label { font-size: 12px; color: var(--muted); }
.me code { display: block; font-size: 13px; margin: 4px 0; word-break: break-all; }
.me .hint { margin: 4px 0 0; }
.member-list { list-style: none; margin: 0; padding: 0; }
.member-list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.member-list .name { font-weight: 600; }
.member-list .name .dot { margin-left: 8px; }
.member-list code { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.scrim { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.35); z-index: 10; }

/* ---------- 进度遮罩 ---------- */
.busy { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.45); z-index: 100;
  display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-align: center; align-items: center; -webkit-box-pack: center; justify-content: center; }
.busy-box { background: var(--surface); border-radius: 14px; padding: 22px 26px; width: 280px; text-align: center; box-shadow: var(--shadow); }
.busy-box p { margin: 12px 0; color: var(--muted); font-size: 14px; }
.spinner { width: 28px; height: 28px; margin: 0 auto; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; -webkit-animation: spin .9s linear infinite; animation: spin .9s linear infinite; }
@-webkit-keyframes spin { to { -webkit-transform: rotate(360deg); } }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); -webkit-transition: width .2s; transition: width .2s; }

@media (min-width: 720px) {
  .messages { padding: 16px 10%; }
  .msg { max-width: 64%; }
  .composer { padding-left: 10%; padding-right: 10%; }
}
@media (prefers-reduced-motion: reduce) { * { -webkit-transition: none !important; transition: none !important; -webkit-animation: none !important; animation: none !important; } }
