:root {
  --navy: #1f3a5f;
  --navy-2: #2c4f7c;
  --bg: #f3f4f6;
  --card: #ffffff;
  --ink: #1b1f24;
  --muted: #667085;
  --line: #e4e7ec;
  --me: #dbeafe;
  --red: #c62828;
  --red-bg: #fdecea;
  --amber: #b26a00;
  --amber-bg: #fff4dc;
  --green: #1e7b45;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang HK", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--navy-2); }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; background: var(--bg); }

header.top {
  background: var(--navy); color: #fff; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
}
header.top h1 { font-size: 17px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top .sub { font-size: 12px; opacity: .8; display: block; font-weight: 400; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #4ade80; display: inline-block; }
.dot.off { background: #f87171; }
.hbtn { background: rgba(255,255,255,.14); border: 0; color: #fff; border-radius: 8px; padding: 6px 10px; font-size: 14px; }

main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px 16px; }
main.chat { display: flex; flex-direction: column; }

nav.tabs {
  display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
nav.tabs button {
  flex: 1; border: 0; background: none; padding: 8px 2px 9px; font-size: 13px; color: var(--muted); position: relative;
}
nav.tabs button .ic { display: block; font-size: 20px; line-height: 1.2; }
nav.tabs button.on { color: var(--navy); font-weight: 600; }
.badge {
  position: absolute; top: 3px; left: calc(50% + 8px); background: var(--red); color: #fff; border-radius: 9px;
  font-size: 11px; min-width: 18px; height: 18px; line-height: 18px; padding: 0 5px; font-weight: 600;
}
.badge.inline { position: static; margin-left: 6px; display: inline-block; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; flex: none; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; white-space: nowrap; font-size: 14px; position: relative; }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }

.day { text-align: center; color: var(--muted); font-size: 12px; margin: 10px 0 6px; }
.msg { margin: 4px 0; display: flex; flex-direction: column; align-items: flex-start; }
.msg.mine { align-items: flex-end; }
.bubble { background: var(--card); border-radius: var(--radius); padding: 8px 11px; max-width: 86%; box-shadow: 0 1px 1px rgba(0,0,0,.04); white-space: pre-wrap; word-break: break-word; }
.mine .bubble { background: var(--me); }
.meta { font-size: 12px; color: var(--muted); margin: 0 4px 2px; display: flex; gap: 6px; align-items: center; }
.tag { font-size: 11px; background: var(--navy); color: #fff; border-radius: 4px; padding: 0 5px; }
.more { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 0 4px; }

.card { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin: 8px 0; box-shadow: 0 1px 2px rgba(0,0,0,.05); width: 100%; }
.card.important { border-left: 5px solid var(--amber); background: var(--amber-bg); }
.card.sos { border-left: 5px solid var(--red); background: var(--red-bg); }
.card .head { font-size: 13px; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; gap: 8px; }
.card .text { white-space: pre-wrap; word-break: break-word; }
.card.important .label { color: var(--amber); font-weight: 700; }
.card.sos .label { color: var(--red); font-weight: 700; }
.deleted { color: var(--muted); font-style: italic; font-size: 14px; }

.btn { border: 0; border-radius: 10px; padding: 10px 16px; background: var(--navy); color: #fff; font-weight: 600; }
.btn.ghost { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn.red { background: var(--red); }
.btn.ok { background: var(--green); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mt { margin-top: 10px; }

.composer { display: flex; gap: 8px; padding: 8px 10px; background: #fff; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { flex: 1; border: 1px solid var(--line); border-radius: 18px; padding: 8px 14px; resize: none; max-height: 140px; min-height: 40px; background: var(--bg); }
.composer .opts { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.composer .btn { border-radius: 18px; }

.sosfab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(76px + var(--safe-b));
  background: var(--red); color: #fff; border: 0; border-radius: 999px; padding: 12px 18px; font-weight: 700;
  box-shadow: 0 4px 12px rgba(198,40,40,.4); font-size: 16px; z-index: 5;
}
.sosfab.up { bottom: calc(140px + var(--safe-b)); }
main.chat { padding-bottom: 70px; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; font-size: 15px; }
.list .item { display: flex; align-items: center; gap: 10px; background: #fff; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.list .item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.list .item:last-child { border-radius: 0 0 var(--radius) var(--radius); border-bottom: 0; }
.list .item .grow { flex: 1; min-width: 0; }
.list .item .small { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.login { padding: 40px 22px; max-width: 420px; margin: 0 auto; width: 100%; }
.login h2 { margin: 0 0 6px; }
.login p { color: var(--muted); margin: 0 0 18px; }
.field { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fff; }
.code-input { font-size: 22px; letter-spacing: 4px; text-transform: uppercase; text-align: center; }
label.lbl { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
.err { color: var(--red); font-size: 14px; margin-top: 8px; min-height: 20px; }

.info { background: #fff; border-radius: var(--radius); padding: 14px 16px; white-space: pre-wrap; word-break: break-word; }
textarea.big { width: 100%; min-height: 50vh; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }

table.members { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; font-size: 14px; }
table.members th, table.members td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.members th { background: #f9fafb; font-weight: 600; font-size: 13px; color: var(--muted); }
table.members select { font-size: 13px; padding: 2px; max-width: 92px; }
table.members .tag, table.members .more { white-space: nowrap; }
table.members td:last-child, table.members td.code { white-space: nowrap; }
table.members td.code { font-size: 13px; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 1px; }
h3.sec { font-size: 15px; margin: 20px 0 8px; color: var(--navy); }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.modal { background: #fff; width: 100%; max-width: 560px; border-radius: 16px 16px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); max-height: 85vh; overflow-y: auto; }
.modal h3 { margin: 0 0 10px; }

.banner { background: var(--amber-bg); color: var(--amber); font-size: 14px; padding: 8px 12px; border-radius: 10px; margin-bottom: 10px; }

/* 列印登入卡 */
.print-wrap { padding: 16px; background: #fff; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
@media print { .cards { grid-template-columns: repeat(2, 1fr); } }
.lcard { border: 1px dashed #999; border-radius: 8px; padding: 10px; display: flex; gap: 10px; align-items: center; break-inside: avoid; page-break-inside: avoid; }
.lcard .qr svg { width: 110px; height: 110px; display: block; }
.lcard .nm { font-size: 18px; font-weight: 700; }
.lcard .cd { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 20px; letter-spacing: 2px; margin: 4px 0; }
.lcard .tiny { font-size: 11px; color: #444; word-break: break-all; }
@media print {
  .noprint { display: none !important; }
  body, #app { background: #fff; height: auto; max-width: none; }
  .print-wrap { padding: 0; }
}
