:root {
  --bg: #ffffff; --bg-soft: #f4f5f7; --text: #15191e; --muted: #667080; --line: #e4e7eb;
  --accent: #06a24b; --accent-text: #ffffff; --bubble-in: #eef0f3; --bubble-out: #d9f5e3; --bubble-out-text: #0b2e19;
  --warn: #b45309; --warn-bg: #fef3c7; --danger: #b91c1c; --danger-bg: #fee2e2; --paid: #1d4ed8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a; --bg-soft: #1e2226; --text: #eceef1; --muted: #98a1ad; --line: #2b3036;
    --accent: #21b866; --accent-text: #06170d; --bubble-in: #262b30; --bubble-out: #14492a; --bubble-out-text: #dcf7e6;
    --warn: #fbbf24; --warn-bg: #3a2c0b; --danger: #fca5a5; --danger-bg: #3b1616; --paid: #93b4fd;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", Roboto, sans-serif; }
#app { height: 100dvh; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; font-size: 16px; color: inherit; }
.bar { flex: none; display: flex; align-items: center; gap: 8px; min-height: 52px; padding: calc(env(safe-area-inset-top) + 6px) 12px 6px; border-bottom: 1px solid var(--line); background: var(--bg); }
.bar h1 { flex: 1; min-width: 0; margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.icon-btn { min-width: 44px; min-height: 44px; display: grid; place-items: center; border-radius: 10px; font-size: 22px; }
.text-btn { min-height: 40px; padding: 0 12px; border-radius: 10px; font-size: 14px; background: var(--bg-soft); white-space: nowrap; }

.notice { flex: none; display: flex; gap: 8px; align-items: center; padding: 8px 12px; font-size: 14px; background: var(--warn-bg); color: var(--warn); }
.notice.danger { background: var(--danger-bg); color: var(--danger); }
.notice button { margin-left: auto; font-weight: 600; text-decoration: underline; min-height: 32px; white-space: nowrap; }

.filters { flex: none; display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.filters::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 34px; padding: 0 12px; border-radius: 17px; font-size: 14px; background: var(--bg-soft); color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.chip .count { font-weight: 600; margin-left: 4px; }

.search { flex: none; padding: 8px 12px 0; }
.search input { width: 100%; height: 38px; padding: 0 12px; border: 0; border-radius: 10px; background: var(--bg-soft); outline-color: var(--accent); }

.list { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.row { width: 100%; display: flex; gap: 12px; align-items: center; padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.avatar { flex: none; width: 46px; height: 46px; border-radius: 50%; object-fit: cover; background: var(--bg-soft); display: grid; place-items: center; font-weight: 600; color: var(--muted); }
.row-main { flex: 1; min-width: 0; }
.row-top, .row-bottom { display: flex; align-items: center; gap: 8px; }
.row-name { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { flex: none; font-size: 12px; color: var(--muted); }
.row-text { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .row-name { font-weight: 700; }
.row.unread .row-text { color: var(--text); }
.oa { flex: none; font-size: 11px; line-height: 18px; padding: 0 6px; border-radius: 5px; color: #fff; max-width: 96px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700; text-align: center; line-height: 20px; }
.free-tag { flex: none; font-size: 11px; font-weight: 600; color: var(--accent); }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }

.thread { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; margin: 8px 0; padding: 2px 10px; font-size: 12px; color: var(--muted); background: var(--bg-soft); border-radius: 10px; }
.msg { max-width: 82%; display: flex; flex-direction: column; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 8px 12px; border-radius: 16px; background: var(--bubble-in); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); }
.bubble a { color: inherit; text-decoration: underline; }
.bubble.gone { font-style: italic; color: var(--muted); }
.media { display: block; max-width: 100%; max-height: 320px; border-radius: 14px; background: var(--bg-soft); }
.sticker { width: 110px; height: 110px; object-fit: contain; }
.meta { margin-top: 2px; padding: 0 4px; font-size: 11px; color: var(--muted); }
.meta .paid { color: var(--paid); font-weight: 600; }

.composer { flex: none; display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px); border-top: 1px solid var(--line); background: var(--bg); }
.composer textarea { flex: 1; min-width: 0; max-height: 132px; padding: 9px 12px; border: 0; border-radius: 18px; background: var(--bg-soft); resize: none; outline-color: var(--accent); line-height: 1.35; }
.send { flex: none; min-height: 40px; padding: 0 12px; border-radius: 20px; background: var(--accent); color: var(--accent-text); font-size: 14px; font-weight: 600; white-space: nowrap; }
.send.paid { background: var(--paid); color: var(--bg); }
.send:disabled { opacity: .45; }

.login { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 24px; max-width: 420px; width: 100%; margin: 0 auto; }
.login h1 { margin: 0 0 8px; font-size: 24px; }
.login input { height: 46px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); outline-color: var(--accent); }
.login button { height: 46px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.login .err { color: var(--danger); font-size: 14px; min-height: 20px; }

.guide { flex: 1; overflow-y: auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px); max-width: 560px; width: 100%; margin: 0 auto; }
.guide h2 { margin: 20px 0 8px; font-size: 17px; }
.guide ol { margin: 0; padding-left: 22px; }
.guide li { margin: 8px 0; }
.guide .primary { display: block; width: 100%; min-height: 46px; margin: 12px 0; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.guide .ok { color: var(--accent); font-weight: 600; }
.guide p { margin: 8px 0; }
.kbd-icon { display: inline-block; padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-soft); }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translateX(-50%); max-width: calc(100vw - 32px); width: max-content; padding: 10px 14px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 10; }
#toast.show { opacity: 1; }
