:root {
  font-family: Inter, "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  color: #19263c;
  background: #eef2f8;
  --ink: #19263c;
  --muted: #55637a;
  --quiet: #6d7a91;
  --line: #dfe6f0;
  --blue: #2655cb;
  --blue-deep: #1e47b1;
  --blue-wash: #e8efff;
  --paper: #fff;
  --surface: #f8faff;
  --shadow: 0 18px 60px #14244829, 0 5px 18px #172a4a14;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; height: 100dvh; min-height: 360px; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 3px;
}
a { color: var(--blue); text-underline-offset: 3px; }
[hidden] { display: none !important; }
svg { display: block; width: 19px; height: 19px; flex: none; }
h1, h2, p { margin: 0; }
.topbar {
  flex: none; height: 65px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; background: var(--paper); border-bottom: 1px solid var(--line); gap: 12px;
}
.brand { display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--ink); font-size: 18px; font-weight: 760; white-space: nowrap; }
.brand small { margin-left: 7px; color: var(--quiet); font-size: 12px; font-weight: 570; }
.logo { display: grid; place-items: center; width: 35px; height: 35px; border-radius: 10px; background: var(--blue); color: white; }
.logo svg { width: 20px; height: 20px; }
.top-actions, .system-state { display: flex; align-items: center; gap: 12px; }
.system-state { color: var(--muted); gap: 7px; font-size: 12px; white-space: nowrap; }
.system-state i, .status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 100%; background: #9aa7ba; }
.system-state i.ok, .status-dot.online { background: #218761; }
.system-state i.bad, .status-dot.error { background: #b84550; }
.status-dot.syncing, .status-dot.connecting { background: #b5751b; }
.button, .icon-button { border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; transition: background .15s, border-color .15s; }
.button { border: 1px solid transparent; min-height: 36px; padding: 7px 13px; font-weight: 670; font-size: 13px; white-space: nowrap; }
.button svg { width: 16px; height: 16px; }
.primary { background: var(--blue); color: white; }
.primary:hover:not(:disabled) { background: var(--blue-deep); }
.subtle { background: var(--paper); border-color: var(--line); color: var(--muted); }
.subtle:hover:not(:disabled), .icon-button:hover { background: #f0f4fb; color: var(--ink); }
.danger { background: var(--paper); border-color: #eed2d8; color: #a53043; }
.danger:hover:not(:disabled) { background: #fff1f3; }
.icon-button { border: 0; width: 36px; height: 36px; background: transparent; color: var(--muted); flex: none; }
.icon-button.small { width: 27px; height: 27px; }
.icon-button.small svg { width: 16px; height: 16px; }
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 223px minmax(270px, 330px) minmax(0, 1fr); }
.sidebar { padding: 24px 13px; border-right: 1px solid var(--line); background: #f3f6fc; overflow: auto; }
.sidebar-title { color: var(--quiet); font-size: 12px; font-weight: 740; margin: 0 8px 8px; display: flex; gap: 6px; align-items: center; }
.nav-item, .account-row { display: flex; align-items: center; gap: 9px; border: 0; border-radius: 8px; min-width: 0; text-align: left; width: 100%; background: transparent; }
.nav-item { padding: 10px 9px; font-size: 13px; color: var(--muted); font-weight: 630; margin-bottom: 2px; }
.nav-item svg { width: 16px; height: 16px; }
.nav-item:hover, .account-row:hover { background: #eaf0fa; }
.nav-item.selected, .account-row.selected { background: var(--blue-wash); color: #2349a6; }
.nav-count { margin-left: auto; min-width: 21px; padding: 1px 4px; font-variant-numeric: tabular-nums; text-align: center; color: var(--quiet); font-size: 11px; }
.nav-item.selected .nav-count { color: #2047aa; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 24px 3px 4px 0; padding-top: 14px; border-top: 1px solid var(--line); }
.section-head .sidebar-title { margin-bottom: 0; }
#account-capacity { font-weight: 540; }
.account-item { display: flex; align-items: center; gap: 2px; }
.account-row { flex: 1; padding: 7px 6px; margin: 3px 0; }
.account-row .avatar { flex: none; width: 30px; height: 30px; border-radius: 9px; font-size: 12px; }
.account-info { flex: 1; min-width: 0; }
.account-info strong, .account-info small { display: block; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.account-info strong { font-size: 12px; }
.account-info small { color: var(--quiet); font-size: 11px; margin-top: 1px; }
.account-empty { color: var(--quiet); padding: 6px 8px; font-size: 12px; }
.threads, .conversation { min-width: 0; min-height: 0; }
.threads { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--paper); }
.thread-head { padding: 21px 16px 13px; border-bottom: 1px solid var(--line); }
.thread-heading { display: flex; align-items: center; gap: 8px; margin-bottom: 15px; min-width: 0; }
.thread-heading h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 760; }
.pill { display: inline-flex; align-items: center; justify-content: center; min-width: 21px; min-height: 20px; padding: 2px 7px; border-radius: 6px; background: #edf1f8; font-size: 11px; color: var(--muted); font-weight: 680; }
.search { display: flex; align-items: center; gap: 8px; padding: 0 9px; background: #f6f8fc; border: 1px solid var(--line); border-radius: 8px; color: var(--quiet); }
.search svg { width: 16px; height: 16px; }
.search input { width: 100%; height: 34px; min-width: 0; outline: none; border: none; background: transparent; }
.search:focus-within { border-color: var(--blue); }
.search input:focus-visible { outline: none; }
#thread-list { flex: 1; overflow: auto; min-height: 0; padding: 5px 7px; }
#thread-footer { flex: none; padding: 9px; text-align: center; border-top: 1px solid var(--line); }
.empty-list { text-align: center; color: var(--quiet); padding: 33px 10px; font-size: 13px; }
.thread { width: 100%; min-width: 0; background: transparent; border: 1px solid transparent; border-radius: 9px; display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 8px; text-align: left; padding: 11px 6px; margin: 2px 0; }
.thread:hover { background: #f2f5fa; }
.thread.selected { background: #edf3ff; border-color: #d7e4ff; }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; background: #e2ebff; color: #2e51a5; font-weight: 740; font-size: 14px; align-self: start; }
.avatar.violet { background: #eee7fb; color: #6c4498; }
.avatar.teal { background: #dbf0ee; color: #276b69; }
.avatar.rose { background: #f8e5eb; color: #98506b; }
.thread-body, .thread-side { min-width: 0; }
.thread-body strong, .thread-preview, .thread-account { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-body strong { font-size: 13px; margin-bottom: 3px; }
.thread-preview { color: var(--muted); font-size: 12px; }
.thread-account { margin-top: 5px; color: #375baf; font-size: 11px; }
.thread-side { display: flex; flex-direction: column; align-items: end; gap: 5px; color: var(--quiet); font-size: 10px; padding-top: 2px; }
.unread-badge { background: var(--blue); color: white; border-radius: 7px; min-width: 16px; padding: 2px 4px; text-align: center; }
.due { color: #965b13; font-weight: 680; }
.conversation { background: var(--surface); position: relative; }
.blank { height: 100%; display: grid; place-items: center; padding: 24px; }
.empty-card { text-align: center; max-width: 360px; padding: 14px; }
.empty-art { display: grid; place-items: center; color: #416ae0; width: 76px; height: 76px; margin: 0 auto 20px; border-radius: 22px; background: #e7efff; border: 1px solid #d7e4ff; box-shadow: 0 8px 24px #386ed01c; }
.empty-art svg { width: 35px; height: 35px; }
.empty-card h2 { font-size: 21px; letter-spacing: -.3px; font-weight: 750; }
.empty-card p { margin: 10px auto 19px; color: var(--muted); line-height: 1.7; }
#active-chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { flex: none; display: flex; gap: 11px; align-items: center; padding: 16px 22px; min-height: 72px; background: var(--paper); border-bottom: 1px solid var(--line); }
.chat-head .avatar { width: 38px; height: 38px; align-self: center; }
.chat-heading { flex: 1; min-width: 0; }
.chat-heading h2 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-sender { color: var(--muted); font-size: 12px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }
.timeline { flex: 1; overflow: auto; min-height: 0; padding: 15px clamp(12px, 3vw, 42px) 22px; }
.history-control { text-align: center; margin-bottom: 13px; }
.history-control:has(button[hidden]) { display: none; }
.day { text-align: center; font-size: 11px; color: var(--quiet); font-weight: 640; margin: 13px 0; }
.message { display: flex; align-items: end; gap: 8px; margin-bottom: 8px; }
.message.out { justify-content: flex-end; }
.bubble { position: relative; max-width: min(85%, 520px); background: var(--paper); border: 1px solid var(--line); border-radius: 12px 12px 12px 3px; padding: 8px 10px 5px; overflow-wrap: anywhere; }
.out .bubble { background: #e7efff; border-color: #d9e5ff; border-radius: 12px 12px 3px 12px; }
.message-copy { white-space: pre-wrap; line-height: 1.55; }
.message-meta { display: flex; gap: 6px; justify-content: flex-end; color: #5d6d89; font-size: 10px; margin-top: 5px; }
.message-meta .failed { color: #a82e45; }
.attachment { display: inline-block; color: #2752b5; font-size: 12px; margin: 2px 0 5px; }
.composer { flex: none; padding: 12px clamp(12px, 3vw, 35px); border-top: 1px solid var(--line); background: var(--paper); }
.reply-account { color: #375baf; font-size: 12px; font-weight: 650; margin-bottom: 5px; }
.composer textarea { width: 100%; min-height: 60px; max-height: 25dvh; resize: vertical; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcff; }
.composer-footer { display: flex; justify-content: space-between; align-items: center; padding-top: 7px; gap: 12px; }
#reply-hint { color: var(--quiet); font-size: 11px; }
dialog { padding: 0; width: min(460px, calc(100% - 28px)); border: 1px solid var(--line); border-radius: 15px; background: white; color: var(--ink); box-shadow: var(--shadow); max-height: calc(100dvh - 25px); }
dialog::backdrop { background: #18284080; }
.dialog-card { padding: 22px; display: grid; gap: 14px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.dialog-head h2 { font-size: 19px; font-weight: 760; }
.dialog-card p { color: var(--muted); line-height: 1.65; }
.dialog-card label { display: grid; gap: 6px; color: var(--ink); font-weight: 640; font-size: 13px; }
.dialog-card input, .dialog-card select, .dialog-card textarea { width: 100%; padding: 9px 10px; border: 1px solid #cfd9e9; border-radius: 7px; background: #fbfcff; font-weight: 430; }
.dialog-card textarea { resize: vertical; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-card .form-error { color: #a53043; font-size: 12px; }
#auth-body .qr-panel { display: grid; justify-items: center; gap: 12px; text-align: center; }
.qr-panel img { width: 215px; height: 215px; border-radius: 9px; border: 1px solid var(--line); background: var(--paper); image-rendering: pixelated; }
#auth-body form { display: grid; gap: 10px; }
#notifications-form, #notifications-binding { display: grid; gap: 12px; }
#account-label-form { display: grid; gap: 12px; }
#notifications-command { font-family: monospace; font-size: 12px; }
.toast { position: fixed; bottom: 19px; right: 18px; max-width: min(410px, calc(100vw - 35px)); background: #263656; color: white; padding: 10px 13px; border-radius: 8px; box-shadow: var(--shadow); z-index: 4; font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.login-page { min-height: 100dvh; height: auto; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(390px, 100%); padding: 30px; background: var(--paper); border: 1px solid var(--line); border-radius: 15px; box-shadow: var(--shadow); display: grid; gap: 18px; }
.login-card h1 { font-size: 23px; margin-top: 8px; }
.login-card p { color: var(--muted); line-height: 1.65; }
.login-card form { display: grid; gap: 16px; }
.login-card label { display: grid; gap: 7px; font-size: 13px; font-weight: 640; }
.login-card input { width: 100%; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px; background: #fbfcff; }
.login-card .form-error { color: #a53043; font-size: 13px; }
@media (max-width: 980px) { .layout { grid-template-columns: 174px minmax(230px, 285px) minmax(0, 1fr); } }
/* Mobile uses one screen at a time; desktop keeps the three columns. */
.mobile-only { display: none; }
@media (max-width: 820px), (max-width: 980px) and (pointer: coarse) {
  .inbox-page { position: fixed; inset: 0; width: 100%; height: var(--app-height, 100dvh); min-height: 0; overflow: hidden; overscroll-behavior: none; }
  .mobile-only { display: flex; }
  .topbar { height: calc(60px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left)); }
  .brand { gap: 0; font-size: 23px; }
  .brand .logo, .brand-name, .system-state, #notifications-button, #settings-button, #logout-session { display: none; }
  .top-actions { gap: 0; }
  #new-message { height: 44px; width: 44px; padding: 0; background: transparent; color: var(--blue); border-radius: 50%; }
  #new-message svg { width: 23px; height: 23px; }
  .compose-label { display: none; }
  .layout { display: flex; flex: 1; min-height: 0; }
  .layout > .sidebar, .layout > .threads, .layout > .conversation, .layout > .mobile-settings { display: none; width: 100%; flex: 1; min-height: 0; }
  [data-mobile-screen="messages"] .layout > .threads { display: flex; }
  [data-mobile-screen="accounts"] .layout > .sidebar { display: block; }
  [data-mobile-screen="settings"] .layout > .mobile-settings { display: block; }
  [data-mobile-screen="chat"] .layout > .conversation { display: block; }
  [data-mobile-screen="chat"] .topbar, [data-mobile-screen="chat"] .mobile-nav { display: none; }
  [data-mobile-screen="accounts"] #new-message, [data-mobile-screen="settings"] #new-message { display: none; }
  .threads { border: 0; }
  .thread-head { padding: 7px max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); border-bottom: 1px solid #edf0f5; }
  .thread-heading { margin-bottom: 10px; gap: 6px; }
  .thread-heading h1 { font-size: 13px; color: var(--muted); font-weight: 620; }
  .thread-heading .pill { min-height: 18px; padding: 1px 5px; }
  #mobile-account-picker { margin-left: auto; min-height: 32px; font-size: 12px; padding: 3px 8px; border: 0; }
  #mobile-account-picker svg { width: 13px; height: 13px; transform: rotate(180deg); }
  .search { border: 0; border-radius: 12px; padding: 0 11px; background: #f1f4f8; }
  .search input { height: 42px; font-size: 16px; }
  .mobile-filters { gap: 20px; }
  .mobile-filters button { min-height: 47px; padding: 7px 2px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); font-size: 14px; font-weight: 650; display: flex; gap: 5px; align-items: center; }
  .mobile-filters button.selected { color: var(--blue); border-bottom-color: var(--blue); }
  .mobile-filters [data-count] { font-size: 11px; border-radius: 8px; padding: 1px 5px; background: #eef2f8; }
  .mobile-filters [data-count]:empty { display: none; }
  #thread-list { padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; }
  .thread { grid-template-columns: 49px minmax(0, 1fr) auto; column-gap: 12px; padding: 15px 7px; margin: 0; border-radius: 0; border-width: 0 0 1px; border-bottom-color: #eff2f6; min-height: 92px; }
  .thread.selected { border-color: #eff2f6; background: transparent; }
  .thread .avatar { width: 49px; height: 49px; border-radius: 50%; font-size: 19px; }
  .thread-body strong { font-size: 16px; margin-bottom: 3px; }
  .thread-preview { font-size: 14px; }
  .thread-account { font-size: 11px; margin-top: 4px; }
  .thread-side { font-size: 11px; padding-top: 2px; }
  #thread-footer { padding: 4px; }
  #more-chats { min-height: 40px; }
  .mobile-nav { flex: none; justify-content: space-around; border-top: 1px solid var(--line); background: var(--paper); padding: 6px env(safe-area-inset-right) max(7px, env(safe-area-inset-bottom)) env(safe-area-inset-left); }
  .mobile-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 49px; border: 0; padding: 4px; background: transparent; color: var(--quiet); font-size: 11px; font-weight: 630; }
  .mobile-nav button[aria-current="page"] { color: var(--blue); }
  .mobile-nav svg { width: 23px; height: 23px; }
  .mobile-nav-icon { position: relative; }
  #mobile-unread { position: absolute; top: -5px; left: 15px; border: 2px solid white; font-size: 9px; padding: 1px 4px; background: #d23d55; color: white; }
  .sidebar { padding: 8px max(16px, env(safe-area-inset-right)) 20px max(16px, env(safe-area-inset-left)); border: 0; background: var(--paper); overscroll-behavior: contain; }
  .sidebar .inbox-label, .sidebar #views { display: none; }
  .section-head { border: 0; margin: 0 0 8px; padding: 0; }
  .section-head .sidebar-title { margin: 0; font-size: 13px; }
  #add-account { height: 44px; width: 44px; color: var(--blue); }
  #add-account svg { width: 22px; height: 22px; }
  .mobile-all-accounts { width: 100%; min-height: 46px; border-radius: 12px; justify-content: flex-start; margin-bottom: 7px; padding: 11px 12px; }
  .account-item { gap: 8px; padding: 5px 0; border-bottom: 1px solid #eff2f6; }
  .account-row { padding: 11px 10px; gap: 12px; border-radius: 12px; min-height: 65px; }
  .account-row .avatar { width: 43px; height: 43px; border-radius: 50%; font-size: 17px; }
  .account-info strong { font-size: 15px; }
  .account-info small { font-size: 12px; margin-top: 4px; }
  .account-item > .icon-button { height: 44px; width: 44px; }
  .account-item > .icon-button svg { width: 20px; height: 20px; }
  .mobile-settings { padding: 18px max(18px, env(safe-area-inset-right)) 24px max(18px, env(safe-area-inset-left)); overflow: auto; background: #f3f6fb; }
  .mobile-settings-intro { display: flex; align-items: center; gap: 13px; padding: 2px 4px 24px; }
  .mobile-settings-intro .logo { width: 49px; height: 49px; border-radius: 15px; }
  .mobile-settings-intro h1 { font-size: 19px; }
  .mobile-settings-intro p { color: var(--muted); font-size: 12px; margin-top: 6px; }
  .mobile-setting-group { margin-bottom: 18px; padding: 0 14px; background: white; border-radius: 15px; }
  .mobile-setting-group button { display: flex; align-items: center; gap: 12px; min-height: 70px; width: 100%; border: 0; background: transparent; text-align: left; padding: 14px 0; font-size: 15px; }
  .mobile-setting-group button + button { border-top: 1px solid #edf0f5; }
  .mobile-setting-group button > span:nth-child(2) { flex: 1; min-width: 0; }
  .mobile-setting-group small { display: block; margin-top: 5px; font-size: 12px; color: var(--quiet); overflow-wrap: anywhere; }
  .chevron { font-size: 22px; color: #a1adbe; }
  .mobile-setting-group .mobile-logout { color: #a53043; min-height: 56px; }
  .back { display: inline-flex; height: 44px; width: 38px; margin-left: -5px; }
  .chat-head { gap: 8px; min-height: calc(64px + env(safe-area-inset-top)); padding: calc(8px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); }
  .chat-head .avatar { height: 36px; width: 36px; border-radius: 50%; }
  .chat-heading h2 { font-size: 16px; }
  #chat-sender { font-size: 11px; }
  #follow-up { width: 44px; height: 44px; padding: 0; border: 0; color: var(--blue); }
  #follow-up svg { width: 21px; height: 21px; }
  #follow-up-label { display: none; }
  #follow-up.has-followup { background: var(--blue-wash); }
  .conversation { background: #edf2f9; }
  .timeline { padding: 10px max(12px, env(safe-area-inset-right)) 16px max(12px, env(safe-area-inset-left)); overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; }
  .message { margin-bottom: 9px; }
  .bubble { max-width: 86%; padding: 9px 12px 6px; border: 0; border-radius: 15px 15px 15px 4px; box-shadow: 0 1px 2px #1328470a; }
  .out .bubble { background: #dce9ff; border-radius: 15px 15px 4px 15px; }
  .message-copy { font-size: 16px; line-height: 1.5; }
  .message-meta { font-size: 10px; }
  .day { margin: 16px 0; font-size: 11px; }
  .composer { display: grid; grid-template-columns: minmax(0, 1fr) 44px; gap: 6px 8px; align-items: end; padding: 7px max(10px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .keyboard-open .composer { padding-bottom: 8px; }
  .reply-account { grid-column: 1 / -1; margin: 0 3px; font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .composer textarea { min-height: 44px; height: 44px; max-height: min(140px, 28dvh); resize: none; border: 0; border-radius: 21px; padding: 11px 14px; font-size: 16px; line-height: 22px; background: #f0f3f8; }
  .composer-footer { padding: 0; display: block; }
  #reply-hint { display: none; }
  .composer-footer button { width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%; font-size: 0; gap: 0; }
  .composer-footer button svg { width: 21px; height: 21px; }
  dialog { max-height: calc(var(--app-height, 100dvh) - 24px); width: min(460px, calc(100% - 24px)); border-radius: 18px; overflow: auto; overscroll-behavior: contain; }
  .dialog-card { padding: 19px; gap: 16px; }
  .dialog-head h2 { font-size: 18px; }
  .dialog-head .icon-button { height: 44px; width: 44px; margin-right: -8px; }
  .dialog-card input, .dialog-card select, .dialog-card textarea, .login-card input { font-size: 16px; min-height: 44px; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions .button, .dialog-card form > .button { min-height: 44px; }
  .toast { left: 16px; right: 16px; bottom: calc(85px + env(safe-area-inset-bottom)); max-width: none; }
  [data-mobile-screen="chat"] .toast { bottom: calc(108px + env(safe-area-inset-bottom)); }
  .login-page { padding: max(22px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
  .login-card { padding: 24px; }
  .login-card .button { min-height: 46px; }
}

/* Inline media and the reply expression panel share the existing account session. */
.composer { position: relative; }
.composer-footer #reply-hint { margin-right: auto; }
#expressions-button { color: var(--quiet); }
#expressions-button[aria-expanded="true"] { color: var(--blue); background: var(--blue-wash); }
#expressions-button svg { width: 23px; height: 23px; }
.media-bubble { width: 280px; }
.sticker-bubble, .out .sticker-bubble { width: 180px; background: transparent; border: 0; box-shadow: none; }
.media-preview { width: 100%; min-height: 70px; aspect-ratio: 1.25; display: grid; place-items: center; overflow: hidden; border-radius: 9px; position: relative; background: #e7edf5; }
.media-preview.sticker-preview { aspect-ratio: 1 !important; background: transparent; }
.image-open { display: block; padding: 0; border: 0; background: transparent; width: 100%; height: 100%; cursor: zoom-in; }
.chat-image, .chat-video, .media-thumbnail { display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.sticker-canvas, .sticker-canvas canvas { width: 100% !important; height: 100% !important; }
.audio-preview { aspect-ratio: auto !important; min-height: 54px; background: transparent; }
.chat-audio { display: block; width: 100%; }
.media-placeholder { font-size: 12px; color: var(--muted); padding: 18px; text-align: center; }
.media-reveal { border: 0; width: 100%; height: 100%; background: #dbe3ef; min-height: 140px; }
.media-fallback { display: grid; gap: 7px; place-items: center; padding: 8px; width: 100%; height: 100%; }
.media-fallback .media-thumbnail { max-height: 140px; }
.media-fallback .button { white-space: normal; font-size: 11px; }
.media-viewer { width: min(1000px, calc(100vw - 28px)); max-height: calc(100dvh - 24px); background: #172134; color: white; border-color: #33415a; }
.media-viewer::backdrop { background: #0a1221d9; }
.viewer-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; font-weight: 650; }
.viewer-head .icon-button { color: white; }
.viewer-content { display: grid; place-items: center; padding: 0 10px 12px; overflow: auto; }
#viewer-image { max-width: 100%; max-height: calc(100dvh - 100px); display: block; object-fit: contain; }
.expression-panel { position: absolute; bottom: calc(100% + 7px); right: 16px; width: min(365px, calc(100vw - 32px)); height: 415px; max-height: calc(var(--app-height, 100dvh) - 225px); z-index: 3; display: flex; flex-direction: column; background: var(--paper); border: 1px solid var(--line); border-radius: 15px; box-shadow: var(--shadow); overflow: hidden; }
.expression-head { display: flex; align-items: center; padding: 4px 7px 0; border-bottom: 1px solid var(--line); flex: none; }
.expression-head [role="tablist"] { display: flex; flex: 1; gap: 4px; }
.expression-head [role="tab"] { border: 0; border-bottom: 2px solid transparent; min-height: 42px; padding: 7px 12px; background: transparent; font-size: 13px; font-weight: 650; color: var(--quiet); }
.expression-head [aria-selected="true"] { color: var(--blue); border-bottom-color: var(--blue); }
.expression-head .icon-button { width: 32px; height: 36px; }
.expression-search { margin: 10px 10px 4px; display: flex; align-items: center; gap: 7px; padding: 0 10px; background: #f1f4f8; border-radius: 18px; flex: none; }
.expression-search svg { width: 15px; height: 15px; color: var(--quiet); }
.expression-search input { min-width: 0; width: 100%; min-height: 34px; font-size: 13px; border: 0; outline: none; background: transparent; }
.expression-categories { display: flex; flex: none; overflow-x: auto; padding: 3px 9px 6px; gap: 3px; }
.expression-categories button { border: 0; padding: 7px 8px; white-space: nowrap; background: transparent; color: var(--muted); font-size: 11px; border-radius: 7px; }
.expression-categories [aria-pressed="true"] { color: var(--blue); background: var(--blue-wash); }
.expression-grid { overflow: auto; min-height: 0; flex: 1; align-content: start; padding: 7px; overscroll-behavior: contain; }
.emoji-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; }
.emoji-choice { padding: 4px 0; border: 0; min-height: 42px; background: transparent; border-radius: 9px; font-size: 26px; line-height: 1.25; font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif; }
.emoji-choice:hover { background: var(--blue-wash); }
.expression-footer { flex: none; padding: 9px 12px; color: var(--quiet); font-size: 11px; line-height: 1.5; border-top: 1px solid var(--line); }
.expression-empty { grid-column: 1 / -1; padding: 22px 12px; font-size: 13px; line-height: 1.75; color: var(--quiet); text-align: center; }
.sticker-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.expression-media-choice { display: block; border: 1px solid transparent; padding: 4px; border-radius: 10px; background: transparent; min-width: 0; cursor: pointer; }
.expression-media-choice:hover { background: var(--blue-wash); border-color: #d7e4ff; }
.expression-media-choice .media-preview { min-height: 0; width: 100%; height: auto; aspect-ratio: 1 !important; background: transparent; pointer-events: none; }
.expression-media-choice .media-placeholder { padding: 8px; font-size: 11px; }
.expression-media-choice .media-fallback .button { font-size: 10px; padding: 3px; }
@media (max-width: 820px), (max-width: 980px) and (pointer: coarse) {
  .composer { grid-template-columns: 36px minmax(0, 1fr) 44px; gap: 6px; }
  .composer textarea { grid-column: 2; grid-row: 2; }
  .composer-footer { display: contents; }
  .composer-footer #expressions-button { grid-column: 1; grid-row: 2; width: 36px; height: 44px; border-radius: 10px; color: var(--muted); background: transparent; }
  .composer-footer #expressions-button[aria-expanded="true"] { color: var(--blue); }
  .composer-footer [type="submit"] { grid-column: 3; grid-row: 2; }
  .expression-panel { left: 0; right: 0; bottom: 100%; width: 100%; height: min(390px, 50dvh); max-height: calc(var(--app-height, 100dvh) - 175px); border-radius: 16px 16px 0 0; }
  .expression-search input { font-size: 16px; min-height: 38px; }
  .expression-head .icon-button { width: 38px; height: 42px; }
  .expression-head [role="tab"] { min-height: 44px; padding-inline: 13px; }
  .expression-categories button { min-height: 36px; }
  .emoji-choice { min-height: 44px; }
  .expression-footer { padding: 7px 12px; }
  .media-viewer { width: calc(100vw - 16px); max-height: calc(var(--app-height, 100dvh) - 16px); }
  #viewer-image { max-height: calc(var(--app-height, 100dvh) - 90px); }
  .viewer-head .icon-button { width: 44px; height: 44px; }
}

.tenant-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: none; padding: 9px 20px; color: #815614; background: #fff7e8; border-bottom: 1px solid #f1d9aa; font-size: 13px; }
.tenant-banner .button { min-height: 32px; font-size: 12px; text-decoration: none; }
.top-actions > a { text-decoration: none; }
.audit-dialog { width: min(720px, calc(100% - 24px)); }
.audit-list { display: grid; gap: 10px; }
.audit-card { padding: 14px; background: white; border: 1px solid var(--line); border-radius: 10px; min-width: 0; }
.audit-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.audit-card-head strong { font-size: 13px; }
.audit-status { font-size: 11px; color: var(--muted); border-radius: 6px; padding: 3px 7px; background: #edf2f8; flex: none; }
.audit-status.sent, .audit-status.done { background: #e9f7ee; color: #207248; }
.audit-status.failed { background: #ffedf0; color: #a53043; }
.audit-status.pending, .audit-status.unknown, .audit-status.submitted { background: #fff4df; color: #8c641b; }
.audit-meta { font-size: 12px; line-height: 1.6; color: var(--quiet); margin-top: 6px; overflow-wrap: anywhere; }
.audit-content { margin-top: 9px; font-size: 13px; line-height: 1.6; color: var(--ink); overflow-wrap: anywhere; }
.audit-content summary { cursor: pointer; white-space: pre-wrap; }
.audit-content pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; padding: 10px; background: var(--surface); border-radius: 7px; }
.admin-page { background: #f2f5fa; }
.admin-topbar { flex: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 70px; padding: 14px max(22px, calc((100vw - 1180px) / 2)); background: white; border-bottom: 1px solid var(--line); }
.admin-topbar a { text-decoration: none; }
.admin-main { width: 100%; max-width: 1224px; margin: 0 auto; padding: 28px 22px 50px; flex: 1; min-height: 0; overflow: auto; }
.admin-heading, .admin-section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.admin-heading h1 { font-size: 25px; margin-bottom: 8px; }
.admin-heading p, .admin-section-head p { color: var(--muted); line-height: 1.6; font-size: 13px; }
.admin-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 14px; }
.admin-stats > div { display: grid; gap: 10px; background: white; padding: 20px; border: 1px solid var(--line); border-radius: 13px; }
.admin-stats span { color: var(--muted); font-size: 13px; }
.admin-stats strong { font-size: 27px; }
.admin-note { font-size: 12px; line-height: 1.7; color: var(--muted); margin: 12px 0 20px; }
.admin-toolbar { display: flex; gap: 12px; margin-bottom: 16px; }
.admin-toolbar .search { flex: 1; background: white; }
.admin-toolbar .search input { height: 39px; }
.merchant-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 14px; }
.merchant-card { min-width: 0; padding: 20px; background: white; border: 1px solid var(--line); border-radius: 13px; }
.merchant-card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.merchant-card h2 { font-size: 17px; overflow-wrap: anywhere; }
.merchant-status { white-space: nowrap; font-size: 11px; padding: 4px 7px; border-radius: 6px; }
.merchant-status.active { color: #22704a; background: #eaf6ef; }
.merchant-status.inactive { color: #925627; background: #fff0dc; }
.merchant-login { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.merchant-metrics { display: flex; gap: 20px; margin: 18px 0 12px; font-size: 14px; font-weight: 650; }
.merchant-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 18px; }
.merchant-actions a { text-decoration: none; }
.admin-audit { margin-top: 36px; }
.admin-section-head h2 { font-size: 19px; margin-bottom: 7px; }
.admin-section-head select { flex: none; max-width: 230px; padding: 9px; border: 1px solid var(--line); border-radius: 8px; background: white; }
#admin-audit-more { margin-top: 14px; }
.admin-page .form-error { color: #a53043; line-height: 1.6; }
.dialog-card .checkbox-label { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.dialog-card .checkbox-label input { width: 19px; height: 19px; min-height: 19px; margin: 0; }
#invite-link { font-size: 12px; }
@media (max-width: 820px), (max-width: 980px) and (pointer: coarse) {
  #admin-console, #audit-button { display: none; }
  .mobile-admin-link { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; text-decoration: none; color: var(--blue); font-size: 15px; border-bottom: 1px solid var(--line); }
  .tenant-banner { padding: 7px 10px; gap: 6px; font-size: 11px; }
  .tenant-banner .button { font-size: 10px; padding: 6px; }
  .admin-topbar { padding: calc(12px + env(safe-area-inset-top)) 16px 12px; }
  .admin-topbar .brand { font-size: 18px; }
  .admin-topbar .brand small { display: inline; font-size: 11px; }
  .admin-topbar > .button { font-size: 12px; min-height: 42px; padding: 8px; }
  .admin-main { padding: 22px 15px calc(30px + env(safe-area-inset-bottom)); }
  .admin-heading { align-items: flex-start; }
  .admin-heading h1 { font-size: 22px; }
  .admin-heading p { font-size: 12px; }
  .admin-heading .button { min-height: 44px; font-size: 12px; flex: none; }
  .admin-stats { gap: 8px; }
  .admin-stats > div { padding: 14px 10px; }
  .admin-stats span { font-size: 11px; }
  .admin-stats strong { font-size: 22px; }
  .admin-toolbar .search input { font-size: 16px; min-width: 0; height: 44px; }
  .admin-toolbar .button, .merchant-actions .button { min-height: 44px; }
  .merchant-card { padding: 17px; }
  .admin-section-head { align-items: stretch; flex-direction: column; gap: 12px; }
  .admin-section-head select { max-width: none; width: 100%; font-size: 16px; min-height: 44px; }
  #invite-link { font-size: 16px; }
}
.login-identity { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
.access-card .button { text-decoration: none; text-align: center; min-height: 44px; white-space: normal; }
.access-card .access-note { font-size: 12px; color: var(--quiet); }
@media (max-width: 1100px) { .login-identity { display: none; } }
@media (max-width: 820px), (max-width: 980px) and (pointer: coarse) { #switch-account { display: none; } }

/* Subscription and public pricing pages. */
.commerce-page { height: auto; min-height: 100dvh; display: block; background: #f7f9fd; }
.commerce-topbar { max-width: 1168px; margin: auto; min-height: 78px; padding: 18px 24px; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.commerce-topbar a { text-decoration: none; }
.commerce-main { max-width: 1120px; margin: 0 auto; padding: 0 24px 64px; }
.commerce-hero { padding: 76px 0 64px; max-width: 850px; }
.commerce-eyebrow { display: inline-block; color: var(--blue); font-size: 13px; font-weight: 700; letter-spacing: .08em; margin-bottom: 17px; }
.commerce-hero h1 { font-size: clamp(32px,4.5vw,53px); line-height: 1.35; letter-spacing: -.04em; margin-bottom: 24px; }
.commerce-hero p { color: var(--muted); font-size: 16px; line-height: 1.9; max-width: 660px; }
.commerce-features { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 25px; }
.commerce-features span { color: #365078; font-size: 12px; border: 1px solid #dce5f3; border-radius: 30px; padding: 8px 13px; background: white; }
.commerce-section-heading { display: flex; justify-content: space-between; gap: 20px; align-items: start; margin: 16px 0; }
.commerce-section-heading h2 { font-size: 23px; margin: 0 0 10px; }
.commerce-section-heading p { color: var(--muted); font-size: 13px; line-height: 1.8; max-width: 750px; }
.commerce-notice { color: #536680; background: #edf3fc; border-radius: 9px; padding: 12px 15px; line-height: 1.7; margin: 12px 0 20px; font-size: 12px; }
.plan-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 20px; margin: 20px 0 0; }
.plan-card { display: flex; flex-direction: column; padding: 28px; border: 1px solid var(--line); border-radius: 17px; background: white; }
.plan-card.featured { border-color: #8eaef7; box-shadow: 0 10px 34px #2655cb0b; }
.plan-kicker { color: var(--quiet); font-size: 12px; margin-bottom: 13px; }
.plan-card.featured .plan-kicker { color: var(--blue); }
.plan-card h3 { font-size: 22px; margin: 0 0 24px; }
.plan-price { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.plan-price strong { font-size: 39px; font-weight: 750; letter-spacing: -.04em; }
.plan-price span { font-size: 12px; color: var(--quiet); }
.plan-card ul { padding: 20px 0; margin: 0 0 10px; list-style: none; color: var(--muted); font-size: 13px; line-height: 2.3; }
.plan-card li::before { content: '✓'; color: #4773cf; padding-right: 9px; }
.plan-card .button { width: 100%; justify-content: center; margin-top: auto; min-height: 43px; }
.commerce-how { margin-top: 62px; padding-top: 32px; border-top: 1px solid var(--line); }
.commerce-how h2 { font-size: 22px; }
.commerce-how ol { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 28px; list-style-position: inside; padding: 0; margin: 24px 0; color: var(--blue); }
.commerce-how strong { color: var(--ink); font-size: 14px; }
.commerce-how li span { display: block; color: var(--muted); font-size: 13px; line-height: 1.8; margin-top: 10px; }
.commerce-how > p { color: var(--quiet); font-size: 12px; line-height: 1.8; }
.commerce-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.subscription-summary { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 38px 0 32px; }
.subscription-summary h1 { font-size: 28px; margin-bottom: 12px; }
.subscription-summary p { color: var(--muted); line-height: 1.8; font-size: 13px; }
.commerce-orders { margin-top: 38px; }
.commerce-orders h2 { font-size: 21px; margin-bottom: 18px; }
.order-list { display: grid; gap: 13px; }
.order-card { background: white; border: 1px solid var(--line); border-radius: 12px; padding: 19px; min-width: 0; }
.order-card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.order-card .button { margin-top: 12px; }
.order-tx { font-family: ui-monospace,monospace; font-size: 11px; overflow-wrap: anywhere; line-height: 1.8; margin-top: 7px; }
.checkout-card { width: min(100%,520px); }
.checkout-amount-label { margin-top: 10px; }
.checkout-amount { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 5px; }
.checkout-amount strong { font-size: 33px; color: var(--blue); letter-spacing: -.03em; }
.checkout-amount > span { color: var(--muted); font-size: 13px; }
.checkout-amount .button { margin-left: auto; font-size: 11px; }
.checkout-copy { font-size: 12px !important; line-height: 1.8; margin: 12px 0 !important; }
.checkout-qr { width: 160px; height: 160px; display: block; margin: 12px auto; background: white; }
#checkout-address { font-family: ui-monospace,monospace; font-size: 12px; }
#checkout-deadline { font-size: 12px; margin-top: 13px; }
.admin-billing { padding: 28px 0; border-top: 1px solid var(--line); margin-top: 34px; }
.billing-settings-form { padding: 22px; background: white; border: 1px solid var(--line); border-radius: 13px; margin-bottom: 16px; }
.billing-field-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; margin: 20px 0; }
.billing-settings-form label:not(.checkbox-label) { display: grid; gap: 8px; font-size: 12px; color: var(--muted); }
.billing-settings-form input:not([type=checkbox]), .billing-settings-form select { min-width: 0; width: 100%; border: 1px solid #d4dfed; border-radius: 8px; min-height: 41px; padding: 8px 11px; background: white; }
.billing-settings-form .checkbox-label { display: flex; align-items: center; gap: 10px; font-size: 13px; line-height: 1.7; }
.billing-settings-form [type=checkbox] { width: 18px; height: 18px; flex: none; }
.billing-price-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 15px; margin: 22px 0; }
.billing-price-row { display: grid; gap: 12px; border: 1px solid var(--line); border-radius: 9px; padding: 16px; }
.billing-price-row strong { font-size: 13px; }
#billing-scanner-state { margin-bottom: 30px; }
#billing-settings-form .audit-meta { margin: 12px 0; line-height: 1.8; }
@media (max-width: 820px) {
 .commerce-topbar { padding: 16px 18px; min-height: 70px; }.commerce-topbar .brand small { display: none; }
 .commerce-main { padding: 0 18px 38px; }.commerce-hero { padding: 38px 0; }.commerce-hero p { font-size: 14px; }
 .plan-grid { grid-template-columns: 1fr; gap: 14px; }.plan-card { padding: 24px; }.plan-card ul { padding: 14px 0; }.plan-card h3 { margin-bottom: 15px; }
 .commerce-how { margin-top: 36px; }.commerce-how ol { grid-template-columns: 1fr; gap: 18px; }
 .subscription-summary,.commerce-section-heading,.order-card-head { align-items: start; flex-direction: column; gap: 12px; }
 .billing-field-grid,.billing-price-grid { grid-template-columns: 1fr; }.billing-settings-form { padding: 16px; }
 .checkout-amount strong { font-size: 29px; }.commerce-topbar .commerce-actions { gap: 6px; }
 .top-actions > .subscription-control { display: none; }
}
