:root {
  --navy: #0b1440;
  --primary: #1f3fbf;
  --primary-hover: #19349f;
  --bg: #f5f6f9;
  --surface: #ffffff;
  --line: #e4e7ee;
  --text: #171b2e;
  --muted: #667085;
  --soft: #eef1fb;
  --out: #d9fdd3;
  --green: #12805c;
  --green-soft: #e3f4ee;
  --amber: #a15c00;
  --red: #b42318;
  --red-soft: #fdecea;
  --radius: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif; }
h1, h2, p { margin: 0; }
h1 { font-size: 20px; letter-spacing: -0.01em; }
h2 { font-size: 15px; }
a { color: var(--primary); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.capital { text-transform: capitalize; }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

input, select, textarea { font: inherit; color: inherit; background: var(--surface); border: 1px solid #d3d8e3; border-radius: 8px; padding: 8px 11px; min-width: 0; }
input:disabled { background: var(--bg); color: var(--muted); }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
label input, label select { font-weight: 400; font-size: 14px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; font: inherit; font-weight: 550; padding: 7px 14px; border-radius: 8px; border: 1px solid #d3d8e3; background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--red); border-color: #f1c4bf; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; background: transparent; border-radius: 8px; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--bg); color: var(--text); }

.alert { padding: 10px 12px; border-radius: 8px; }
.alert.error { background: var(--red-soft); color: var(--red); }
.alert.success { background: var(--green-soft); color: var(--green); }
.tag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 20px; background: #eceef3; color: var(--muted); margin-left: 6px; }
td > .tag:first-child { margin-left: 0; }
.tag.green { background: var(--green-soft); color: var(--green); }

/* Sign in */
body.auth { display: grid; place-items: center; padding: 20px; background: var(--navy); }
.auth-card { width: min(380px, 100%); background: var(--surface); border-radius: 16px; padding: 32px; display: flex; flex-direction: column; gap: 14px; }
.auth-card img { border-radius: 12px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }
.error-code { font-size: 44px; font-weight: 700; color: var(--primary); }

/* Shell */
body.app { display: flex; height: 100dvh; overflow: hidden; }
.rail { width: 84px; flex: none; background: var(--navy); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 6px; }
.rail-logo img { border-radius: 9px; display: block; margin-bottom: 14px; box-shadow: 0 0 0 1px rgb(255 255 255 / .18); }
.rail-link { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 0; border-radius: 9px; color: #aab3d6; text-decoration: none; font-size: 11px; font-weight: 550; }
.rail-link:hover { color: #fff; background: rgb(255 255 255 / .07); }
.rail-link.active { color: #fff; background: rgb(255 255 255 / .13); }
.rail-spacer { flex: 1; }
.wa-pill { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 10.5px; color: #aab3d6; text-align: center; }
.wa-pill i { width: 10px; height: 10px; border-radius: 50%; background: #8b93ad; }
.wa-pill[data-state="ready"] i { background: #34d399; }
.wa-pill:is([data-state="qr"], [data-state="starting"], [data-state="connecting"], [data-state="waiting_lock"]) i { background: #fbbf24; }
.wa-pill:is([data-state="disconnected"], [data-state="stopped"], [data-state="offline"]) i { background: #f87171; }

/* Inbox */
.inbox { flex: 1; display: grid; grid-template-columns: 340px minmax(0, 1fr); min-width: 0; min-height: 0; }
.list-pane { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.pane-head { padding: 16px 16px 10px; display: flex; flex-direction: column; gap: 10px; }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.tabs button { font: inherit; font-weight: 550; font-size: 13px; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tabs b { font-size: 11px; background: #eceef3; border-radius: 10px; padding: 0 6px; margin-left: 2px; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item { width: 100%; display: flex; gap: 11px; text-align: left; font: inherit; color: inherit; background: none; border: 0; border-bottom: 1px solid #eff1f5; padding: 12px 16px; cursor: pointer; }
.chat-item:hover { background: #f8f9fc; }
.chat-item.selected { background: var(--soft); box-shadow: inset 3px 0 var(--primary); }
.chat-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-line strong, .preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-line strong { font-weight: 600; }
.chat-line time { font-size: 11.5px; color: var(--muted); flex: none; }
.preview { color: var(--muted); font-size: 13px; }
.chat-item.unread .preview { color: var(--text); font-weight: 550; }
.badge { flex: none; min-width: 19px; padding: 0 6px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 11.5px; font-weight: 600; text-align: center; }
.owner { font-size: 11.5px; color: var(--muted); }
.empty { padding: 32px 24px; text-align: center; color: var(--muted); position: absolute; width: 340px; max-width: 100%; margin-top: 150px; pointer-events: none; }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 650; font-size: 13px; background: #e4e9fb; color: #26399a; }
.tone-1 { background: #def2ea; color: #0f6b4f; }
.tone-2 { background: #fdeedc; color: #8a4b00; }
.tone-3 { background: #f2e6fb; color: #6b2a99; }
.tone-4 { background: #fde6ea; color: #9d2342; }
.tone-5 { background: #dff0f8; color: #0b5c7d; }

.thread-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.placeholder { margin: auto; text-align: center; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.placeholder svg { width: 42px; height: 42px; color: #a9b1c7; }
.thread { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.thread-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 11px 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
.thread-title { flex: 1; min-width: 140px; }
.thread-title h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-title p { font-size: 12.5px; }
.thread-actions { display: flex; gap: 8px; align-items: center; }
.assign { position: relative; }
.assign > .btn { width: 100%; max-width: 220px; overflow: hidden; text-overflow: ellipsis; justify-content: flex-start; }
.assign-menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 10; width: 270px; max-width: calc(100vw - 24px); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgb(11 20 64 / .18); padding: 8px; }
.assign-menu > p { font-size: 12px; font-weight: 600; color: var(--muted); padding: 2px 8px 6px; }
.assign-options { max-height: min(300px, 45vh); overflow-y: auto; }
label.assign-option { flex-direction: row; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 7px; font-size: 14px; font-weight: 400; cursor: pointer; }
.assign-option:hover { background: var(--bg); }
.assign-option input { width: 16px; height: 16px; margin: 0; flex: none; }
.assign-footer { display: flex; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }
.avatar.tiny { width: 26px; height: 26px; font-size: 10.5px; }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px clamp(14px, 4vw, 40px); background: #efeae2 url("/static/img/chat-bg.svg") repeat; }
#message-list { display: flex; flex-direction: column; gap: 6px; }
.older { display: flex; margin: 0 auto 10px; }
.day { align-self: center; font-size: 11.5px; font-weight: 600; color: #54656f; background: #fff; border-radius: 8px; padding: 3px 11px; margin: 8px 0; box-shadow: 0 1px 1px rgb(11 20 26 / .12); }
.msg { position: relative; max-width: min(560px, 82%); padding: 6px 9px 5px; border-radius: 8px; background: #fff; color: #111b21; box-shadow: 0 1px .5px rgb(11 20 26 / .16); align-self: flex-start; }
.msg.out { align-self: flex-end; background: var(--out); }
.msg.problem { background: var(--red-soft); }
.msg.tail { margin-top: 6px; }
.msg.tail::before { content: ""; position: absolute; top: 0; width: 9px; height: 12px; background: inherit; }
.msg.in.tail { border-top-left-radius: 0; }
.msg.in.tail::before { right: 100%; clip-path: polygon(0 0, 100% 0, 100% 100%); }
.msg.out.tail { border-top-right-radius: 0; }
.msg.out.tail::before { left: 100%; clip-path: polygon(0 0, 100% 0, 0 100%); }
.msg p { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg footer { display: flex; justify-content: flex-end; gap: 6px; font-size: 11px; color: var(--muted); }
.sender { display: flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 650; color: var(--primary); margin-bottom: 2px; }
.sender img { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; }
.ticks { letter-spacing: -2px; padding-right: 2px; }
.ticks.read { color: #53bdeb; font-weight: 700; }
.sender.c0 { color: #1f7aec; }
.sender.c1 { color: #d1456b; }
.sender.c2 { color: #0f8a6c; }
.sender.c3 { color: #8a4fd1; }
.sender.c4 { color: #c0620a; }
.sender.c5 { color: #00838f; }
.msg { scroll-margin: 80px; }
.msg-menu-btn { position: absolute; top: 2px; right: 2px; width: 26px; height: 22px; border: 0; border-radius: 6px; background: inherit; color: var(--muted); font-size: 13px; line-height: 1; cursor: pointer; opacity: 0; transition: opacity .12s; }
.msg:hover .msg-menu-btn, .msg-menu-btn:focus-visible, .msg-menu-btn[aria-expanded="true"] { opacity: 1; }
/* Touch screens have no hover: the button stays visible, so the bubble keeps room for it. */
@media (hover: none) { .msg-menu-btn { opacity: .7; } .msg { padding-right: 28px; } }
.msg-menu { position: fixed; z-index: 30; min-width: 170px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgb(11 20 64 / .18); display: flex; flex-direction: column; }
.msg-menu[hidden] { display: none; }
.msg-menu button { font: inherit; text-align: left; background: none; border: 0; border-radius: 7px; padding: 8px 12px; cursor: pointer; color: var(--text); }
.msg-menu button:hover, .msg-menu button:focus-visible { background: var(--bg); }
.fwd { display: block; font-size: 11.5px; font-style: italic; color: var(--muted); margin-bottom: 2px; }
.quote { display: flex; flex-direction: column; gap: 1px; width: 100%; min-width: 0; text-align: left; font: inherit; font-size: 12.5px; color: #3b4a54; background: rgb(11 20 26 / .05); border: 0; border-left: 4px solid #06cf9c; border-radius: 6px; padding: 5px 9px; margin: 2px 0 5px; cursor: pointer; }
.quote.me { border-left-color: #53bdeb; }
.quote strong { font-size: 12px; color: #06a07a; }
.quote.me strong { color: #1f7aec; }
.quote span { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: pre-wrap; }
.msg.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px #53bdeb; } 100% { box-shadow: 0 1px .5px rgb(11 20 26 / .16); } }
.reply-bar { width: 100%; display: flex; align-items: center; gap: 6px; background: var(--surface); border-radius: 8px; padding: 4px; }
.reply-bar .quote { margin: 0; cursor: default; }
.thread.selecting .msg { cursor: pointer; }
.thread.selecting .msg::after { content: ""; position: absolute; top: 50%; width: 18px; height: 18px; margin-top: -9px; border: 2px solid #8696a0; border-radius: 4px; background: #fff; }
.thread.selecting .msg.in::after { right: -30px; }
.thread.selecting .msg.out::after { left: -30px; }
.thread.selecting .msg.picked::after { background: #00a884; border-color: #00a884; box-shadow: inset 0 0 0 3px #fff; }
.thread.selecting .msg.in { margin-right: 34px; }
.thread.selecting .msg.out { margin-left: 34px; }
.thread.selecting .msg-menu-btn, .thread.selecting .composer, .thread.selecting .composer-note { display: none; }
.select-bar { display: flex; align-items: center; gap: 10px; padding: 10px 18px calc(10px + env(safe-area-inset-bottom)); background: #f0f2f5; border-top: 1px solid var(--line); }
.select-bar span { flex: 1; font-weight: 600; }
.forward-dialog { width: min(440px, calc(100vw - 32px)); }
.forward-list { list-style: none; margin: 0; padding: 0; max-height: min(360px, 50vh); overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.forward-list label { display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 8px 12px; font-weight: 400; cursor: pointer; border-bottom: 1px solid var(--line); }
.forward-list li:last-child label { border-bottom: 0; }
.forward-list label:hover { background: var(--bg); }
.forward-list input { width: 16px; height: 16px; margin: 0; flex: none; }
.forward-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.forward-count { margin-right: auto; align-self: center; }
.msg-error { font-size: 12px; color: var(--red); }
.msg img, .msg video { display: block; max-width: min(320px, 100%); max-height: 320px; border-radius: 6px; margin: 2px 0 4px; }
.msg img.sticker { max-width: 140px; }
.msg audio { display: block; max-width: 100%; }
.media-note { color: var(--muted); font-style: italic; font-size: 13px; }
.file-link { font-weight: 550; overflow-wrap: anywhere; }
.composer { position: relative; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; padding: 10px 18px calc(10px + env(safe-area-inset-bottom)); background: #f0f2f5; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 140px; line-height: 1.45; }
.composer .btn { height: 39px; }
.file-chip { width: 100%; display: flex; align-items: center; gap: 6px; background: var(--soft); border-radius: 8px; padding: 2px 4px 2px 12px; font-size: 13px; }
.file-chip span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mention-menu { position: absolute; bottom: calc(100% + 6px); left: 18px; z-index: 10; width: 300px; max-width: calc(100% - 36px); max-height: min(280px, 40vh); overflow-y: auto; margin: 0; padding: 6px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgb(11 20 64 / .18); }
.mention-menu li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.mention-menu li[aria-selected="true"], .mention-menu li:hover { background: var(--bg); }
.mention-menu li small { color: var(--muted); margin-left: auto; font-size: 12px; white-space: nowrap; }
.mention-menu li.note { cursor: default; color: var(--muted); }
.mention-menu li.note:hover { background: none; }
.mention { color: #027eb5; font-weight: 600; }
.composer-note { padding: 14px 18px calc(14px + env(safe-area-inset-bottom)); text-align: center; color: var(--amber); background: #fff7e8; border-top: 1px solid #f4e2bd; }

.tag.group { flex: none; margin: 0 auto 0 0; background: #def2ea; color: #0f6b4f; }
.block { display: block; }
fieldset.access { border: 1px solid var(--line); border-radius: 8px; margin: 0; padding: 10px 12px; display: flex; flex-direction: column; gap: 7px; }
fieldset.access legend { font-size: 13px; font-weight: 550; padding: 0 4px; }
label.check input { width: 16px; height: 16px; margin: 0; flex: none; }

/* Profile photos */
img.avatar { object-fit: cover; display: block; }
.avatar.small { width: 32px; height: 32px; font-size: 12px; }
.avatar.large { width: 72px; height: 72px; font-size: 24px; overflow: hidden; }
.avatar.large img { width: 100%; height: 100%; object-fit: cover; }
.photo-field { display: flex; align-items: center; gap: 16px; }
.photo-field strong { display: block; font-size: 13px; font-weight: 550; margin-bottom: 6px; }
.photo-field p { margin-top: 5px; }
.person { display: flex; align-items: center; gap: 10px; }
.person-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.person-info strong { font-weight: 550; overflow-wrap: anywhere; }
.person-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.person-tags:empty { display: none; }
.person-tags .tag { margin-left: 0; }
td.person-cell { white-space: normal; min-width: 240px; }
.tag.amber { background: #fff1d6; color: var(--amber); }
.rail-profile { margin-top: 8px; padding-top: 12px; border-top: 1px solid rgb(255 255 255 / .12); border-radius: 0 0 9px 9px; }
.rail-photo { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 2px rgb(255 255 255 / .22); }
span.rail-photo { display: grid; place-items: center; background: #e4e9fb; color: #26399a; font-size: 14px; font-weight: 700; }

/* Settings pages */
.page { flex: 1; overflow-y: auto; padding: 28px clamp(16px, 4vw, 40px); display: flex; flex-direction: column; gap: 18px; }
.page > * { width: min(680px, 100%); flex: none; }
.page.wide > * { width: min(960px, 100%); }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.page-head > div { flex: 1; min-width: 220px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 13px; }
.page > .log-card { width: min(960px, 100%); padding: 0 0 12px; gap: 0; }
.log-tabs { padding: 0 12px; }
.log-tabs button { font-size: 14px; padding: 12px 10px; }
.log-help { padding: 10px 20px 4px; }
.log-list { list-style: none; margin: 0; padding: 0 8px; max-height: 60vh; overflow-y: auto; }
.log-list li { display: grid; grid-template-columns: 132px 58px 1fr; gap: 10px; align-items: baseline; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.log-list li:last-child { border-bottom: 0; }
.log-list time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.log-list .detail { display: block; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; margin-top: 2px; }
.log-list .level { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 1px 6px; border-radius: 5px; text-align: center; background: #eceef3; color: var(--muted); }
.log-list .level.warn { background: #fff4e0; color: var(--amber); }
.log-list .level.error { background: var(--red-soft); color: var(--red); }
.log-list .level.ok { background: var(--green-soft); color: var(--green); }
.empty-log { padding: 16px 20px; }
#log-more { margin: 10px 20px 0; align-self: flex-start; }
@media (max-width: 640px) {
  .log-list li { grid-template-columns: 1fr auto; }
  .log-list li > div { grid-column: 1 / -1; }
}
.mfa-card { width: min(420px, 100%); }
.mfa-card.wide { width: min(520px, 100%); }
.mfa-card h2 { font-size: 16px; margin: 0 0 2px; }
.method { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.method p { margin: 0; }
.method .btn { flex: none; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.center { text-align: center; }
.link-btn { font: inherit; font-size: 13px; background: none; border: 0; padding: 4px 0; color: var(--primary); cursor: pointer; text-decoration: underline; }
.steps { margin: 0; padding-left: 18px; }
.totp-qr { align-self: center; border: 1px solid var(--line); border-radius: 10px; padding: 6px; background: #fff; image-rendering: pixelated; }
.secret { display: block; margin-top: 6px; padding: 8px 10px; background: var(--bg); border-radius: 8px; font-size: 13px; letter-spacing: .04em; overflow-wrap: anywhere; user-select: all; }
.backup-codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 18px; margin: 0; padding: 12px 12px 12px 34px; background: var(--bg); border-radius: 10px; font: 600 15px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: 16px; height: 16px; margin: 0; }
.mfa-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; }
.mfa-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.mfa-item:last-child { border-bottom: 0; }
.block { display: block; }
.warn-text { color: var(--amber); font-weight: 600; }
#mfa-totp-form input { flex: 1; min-width: 120px; }
.presence-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.presence-head h2 { margin: 0; }
textarea { resize: vertical; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.table-card { padding: 0; overflow-x: auto; position: relative; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tr.inactive td { color: var(--muted); }
dialog { width: min(420px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; border: 0; border-radius: 14px; padding: 24px; box-shadow: 0 20px 60px rgb(11 20 64 / .3); }
dialog::backdrop { background: rgb(11 20 64 / .45); }
.qr-box { display: flex; gap: 20px; flex-wrap: wrap; align-items: center; }
.qr-box img { border: 1px solid var(--line); border-radius: 8px; max-width: 100%; height: auto; }
.qr-box ol { margin: 0; padding-left: 20px; flex: 1; min-width: 200px; }

.toasts { position: fixed; right: 16px; bottom: 90px; display: flex; flex-direction: column; gap: 8px; z-index: 20; max-width: min(360px, calc(100vw - 32px)); }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 9px; box-shadow: 0 8px 24px rgb(11 20 64 / .25); }
.toast.error { background: var(--red); }
.toast.notify { display: flex; flex-direction: column; gap: 2px; cursor: pointer; border-left: 4px solid #25d366; }
.toast.notify span { opacity: .85; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notify-banner { display: flex; align-items: center; gap: 10px; margin: 10px 12px 0; padding: 10px 12px; border-radius: 10px; background: #fff4e0; color: var(--amber); font-size: 13px; font-weight: 550; }
.notify-banner span { flex: 1; }
.notify-banner .btn { flex: none; }
.toast.success { background: var(--green); }

@media (max-width: 760px) {
  body.app { flex-direction: column-reverse; }
  .rail { width: 100%; flex-direction: row; justify-content: space-around; padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); }
  .rail-logo, .rail-spacer { display: none; }
  .rail-link { padding: 6px 0; }
  .rail > .rail-link, .rail > .wa-pill { flex: 1 1 0; min-width: 0; }
  .rail-link span, .wa-pill > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rail-profile { margin-top: 0; padding-top: 6px; border-top: 0; border-radius: 9px; }
  .rail-photo { width: 22px; height: 22px; }
  .wa-pill { justify-content: center; gap: 6px; padding: 6px 0; }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .thread-pane { display: none; }
  .inbox.show-thread .list-pane { display: none; }
  .inbox.show-thread .thread-pane { display: flex; }
  body.inbox-page:has(.inbox.show-thread) .rail { display: none; }
  .empty { width: 100%; }
  .back { display: inline-grid; margin-left: -8px; }
  .thread-head { padding: 8px 12px; }
  .thread-actions { width: 100%; justify-content: flex-end; }
  .assign { flex: 1; }
  .assign > .btn { max-width: none; }
  .assign-menu { left: 0; right: auto; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .mention-menu { left: 10px; max-width: calc(100% - 20px); }
  input, select, textarea { font-size: 16px; }

  /* Thread header: name row, then the actions in one compact row */
  .thread-title { min-width: 0; }
  .thread-actions { gap: 6px; }
  .thread-actions .btn { padding: 6px 12px; font-size: 13.5px; }
  .messages { padding: 12px 12px; }
  .msg { max-width: 88%; }
  .msg img, .msg video { max-width: 100%; }
  .thread.selecting .msg { max-width: calc(88% - 34px); }
  .select-bar { padding-left: 12px; padding-right: 12px; }

  /* Inbox list */
  .pane-head { padding: 12px 14px 8px; }
  .tabs { padding: 0 6px; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: none; padding: 10px 8px; }
  .chat-item { padding: 11px 14px; }
  .notify-banner { margin: 8px 10px 0; font-size: 12.5px; }

  /* Settings pages */
  .page { padding: 18px 14px 24px; gap: 14px; }
  .page-head { gap: 12px; }
  .page-head > div { min-width: 0; flex-basis: 100%; }
  .card { padding: 16px; border-radius: 12px; }
  .page > .log-card { padding: 0 0 10px; }
  .log-help { padding: 10px 14px 4px; }
  .log-list { padding: 0 4px; }
  .log-list li { padding: 8px 10px; }
  .row > .btn { flex: 1 1 auto; }
  .row.end > .btn { flex: 0 0 auto; }
  .qr-box { justify-content: center; }
  .qr-box img { width: min(264px, 100%); }
  .method { flex-wrap: wrap; }
  .method .btn { width: 100%; }
  .mfa-item { flex-wrap: wrap; }
  .backup-codes { font-size: 14px; gap: 4px 12px; padding-left: 28px; }
  dialog { padding: 18px; width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
  .photo-field { gap: 12px; }
  .toasts { left: 12px; right: 12px; bottom: 78px; max-width: none; }

}

/* Team table becomes one card per person where five columns do not fit */
@media (max-width: 1000px) {
  .table-card thead { display: none; }
  .table-card table, .table-card tbody, .table-card tr, .table-card td { display: block; }
  .table-card tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .table-card tr:last-child { border-bottom: 0; }
  .table-card td { border: 0; padding: 2px 0; white-space: normal; min-width: 0; }
  .table-card td.email-cell { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; padding-top: 8px; }
  .table-card td.role-cell, .table-card td.status-cell { display: inline-block; margin-right: 8px; }
  .table-card td.actions-cell { display: flex; flex-wrap: wrap; gap: 6px; text-align: left; padding-top: 10px; }
  .table-card td.actions-cell .btn { flex: 1 1 auto; }
}

/* Sign-in pages on small phones */
@media (max-width: 420px) {
  body.auth { padding: 12px; }
  .auth-card { padding: 22px 18px; border-radius: 14px; }
  .rail-link span, .wa-pill > span { font-size: 10px; }
}
