:root {
  --brand: #0088b0; --on-brand: #fff; --bg: #f4f6f7; --surface: #fff; --ink: #1b1f22; --dim: #5f6b73;
  --line: #dde3e7; --soft: #eceff1; --hover: #f1f4f6; --pick: #dff1f7; --out: #d3eef7; --on-out: #06303d; --in: #fff;
  --danger: #c62828; --alert: #d84315; --info: #0088b0; --silent: #90a4ae; --chat-bg: #eef1f3;
}
@media (prefers-color-scheme: dark) {
  :root { --brand: #4fc3e3; --on-brand: #00232e; --bg: #101315; --surface: #171b1e; --ink: #e4e8ea; --dim: #96a2a9;
    --line: #2b3236; --soft: #242a2e; --hover: #1e2428; --pick: #123846; --out: #0b4a5e; --on-out: #ddf3fa; --in: #20262a;
    --danger: #ef9a9a; --alert: #ff8a65; --info: #4fc3e3; --silent: #78909c; --chat-bg: #0d1012; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
#app { height: 100%; }
[hidden] { display: none !important; }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 14px; }
button:hover { background: var(--hover); }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); background: var(--brand); }
button.danger { color: var(--danger); }
button.icon { border: 0; background: none; width: 38px; height: 38px; padding: 0; border-radius: 50%; font-size: 20px; line-height: 1; color: var(--dim); flex: none; }
button.icon:hover { background: var(--hover); color: var(--ink); }
button:disabled { opacity: .5; cursor: default; }
input[type=text], textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input[type=text]:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--dim); }
label.check { display: flex; align-items: center; gap: 10px; color: var(--ink); font-size: 15px; margin: 0; padding: 7px 0; }

/* ---------------------------------------------------------------- the door */
.door { height: 100%; overflow: auto; }
.door > div { max-width: 860px; margin: 0 auto; padding: 36px 20px; text-align: center; }
.ways { display: flex; gap: 20px; align-items: stretch; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.way { flex: 1 1 340px; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px 22px 18px; }
.way h2 { font-size: 17px; margin: 0 0 4px; }
.keybox { height: 100%; border-radius: 12px; }
.keybox.drop { outline: 2px dashed var(--brand); outline-offset: 6px; }
.keybox form { display: flex; flex-direction: column; gap: 8px; }
.keybox input[type=text] { text-align: center; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .06em; }
.keybox .or { margin: 16px 0 8px; }
button.wide { width: 100%; padding: 11px 14px; margin-top: 14px; }
.door h1 { font-size: 24px; margin: 0 0 6px; }
.qr-frame { display: inline-block; background: #fff; border-radius: 14px; padding: 6px; margin: 18px 0 8px; border: 1px solid var(--line); }
.qr-frame canvas { display: block; width: 264px; height: 264px; image-rendering: pixelated; }
.qr-frame.stale canvas { opacity: .08; }
.check-number { font-size: 32px; font-weight: 700; letter-spacing: .18em; margin: 2px 0; }
.steps { text-align: left; margin: 16px auto; padding-left: 22px; color: var(--dim); }
.steps li { margin: 4px 0; }
details { text-align: left; margin-top: 16px; color: var(--dim); font-size: 13px; }
.code-text { word-break: break-all; user-select: all; color: var(--ink); background: var(--soft); padding: 8px; border-radius: 8px; }
.door form { text-align: left; }
.banner { background: var(--soft); border-radius: 10px; padding: 10px 14px; margin: 10px 0; color: var(--danger); }

/* ---------------------------------------------------------------- two panes */
.shell { height: 100%; display: flex; }
.side { width: 340px; flex: none; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line); min-width: 0; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); }
.bar { display: flex; align-items: center; gap: 6px; padding: 8px 10px 8px 16px; min-height: 56px; background: var(--surface); border-bottom: 1px solid var(--line); flex: none; }
.bar .title { flex: 1; min-width: 0; }
.bar .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
.bar .title span { display: block; font-size: 12.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { padding: 8px 12px; flex: none; }
.search input { border-radius: 18px; padding: 7px 14px; background: var(--soft); border-color: transparent; }
.list { flex: 1; overflow-y: auto; }
.row { display: flex; gap: 12px; align-items: center; padding: 9px 14px; cursor: pointer; }
.row:hover { background: var(--hover); }
.row.on { background: var(--pick); }
.avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 17px; }
.row .text { flex: 1; min-width: 0; }
.row .name { display: flex; gap: 8px; align-items: baseline; }
.row .name b { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.row .name time { font-size: 12px; color: var(--dim); flex: none; }
.row .last { display: flex; gap: 8px; align-items: center; }
.row .last span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--dim); font-size: 14px; }
.row.unread .last span { color: var(--ink); font-weight: 600; }
.badge { background: var(--brand); color: var(--on-brand); border-radius: 10px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.badge.muted { background: var(--silent); }
.empty { padding: 40px 24px; text-align: center; color: var(--dim); }
.status { font-size: 12.5px; color: var(--dim); padding: 6px 16px; border-top: 1px solid var(--line); flex: none; }
.status.bad { color: var(--danger); }

/* ---------------------------------------------------------------- a conversation */
.thread { flex: 1; overflow-y: auto; padding: 10px 0 6px; overflow-anchor: none; }
.thread .inner { max-width: 820px; margin: 0 auto; padding: 0 14px; }
.day { text-align: center; margin: 12px 0 8px; }
.day span { background: var(--soft); color: var(--dim); font-size: 12px; border-radius: 10px; padding: 2px 10px; }
.sys { text-align: center; color: var(--dim); font-size: 13px; margin: 8px 0; }
.msg { display: flex; margin: 2px 0; }
.msg.me { justify-content: flex-end; }
.bubble { max-width: min(78%, 560px); background: var(--in); border-radius: 14px; padding: 7px 11px 5px; box-shadow: 0 1px 0 rgba(0, 0, 0, .06); }
.msg.me .bubble { background: var(--out); color: var(--on-out); }
.bubble .who { font-size: 13px; font-weight: 600; color: var(--brand); margin-bottom: 1px; }
.bubble .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .body a, .card .body a { color: var(--brand); }
.bubble .meta { font-size: 11px; opacity: .65; text-align: right; margin-top: 1px; }
.bubble.failed .meta { color: var(--danger); opacity: 1; cursor: pointer; }
.card { max-width: min(86%, 560px); background: var(--in); border: 1px solid var(--line); border-left: 5px solid var(--info); border-radius: 12px; padding: 9px 12px 7px; margin: 6px 0; }
.card.alert { border-left-color: var(--alert); }
.card.silent { border-left-color: var(--silent); }
.card .who { font-size: 12px; color: var(--dim); }
.card .head { font-weight: 700; margin-top: 1px; }
.card .body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 3px; }
.card .foot { display: flex; align-items: center; margin-top: 4px; }
.card .foot time { flex: 1; font-size: 11px; color: var(--dim); }
.card .foot a { color: var(--brand); font-weight: 600; text-decoration: none; padding: 2px 6px; }
.more { text-align: center; padding: 6px; }
.more button { font-size: 13px; padding: 4px 12px; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px; background: var(--surface); border-top: 1px solid var(--line); flex: none; }
.composer textarea { resize: none; border-radius: 18px; padding: 9px 14px; max-height: 140px; min-height: 40px; line-height: 1.35; }
.composer button { width: 40px; height: 40px; border-radius: 50%; padding: 0; flex: none; font-size: 18px; }
.notice { text-align: center; color: var(--dim); padding: 14px; background: var(--surface); border-top: 1px solid var(--line); }
.blank { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--dim); padding: 24px; text-align: center; }

/* ---------------------------------------------------------------- menus and dialogs */
.menu { position: fixed; z-index: 50; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); padding: 4px; min-width: 190px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; border-radius: 6px; padding: 8px 12px; }
.menu button:hover { background: var(--hover); }
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 20px 22px; width: min(430px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { font-size: 18px; margin: 0 0 6px; }
dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.picklist { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 2px 12px; margin-top: 8px; }
.picklist .row { padding: 8px 0; cursor: default; }
.picklist .row:hover { background: none; }
.picklist .avatar { width: 34px; height: 34px; font-size: 14px; }
.picklist .who-row { cursor: pointer; }
.picklist .who-row:hover { background: var(--hover); }

/* ---------------------------------------------------------------- one pane: a phone, or the popup inside the CRM */
@media (max-width: 720px) {
  .side { width: 100%; border-right: 0; }
  .shell.chatting .side { display: none; }
  .shell:not(.chatting) .main { display: none; }
  .back { display: inline-flex !important; }
  .bubble { max-width: 84%; }
}
.back { display: none; align-items: center; justify-content: center; }
body.embed .door > div { padding: 14px 12px; }
body.embed .way { padding: 16px; }
body.embed .qr-frame canvas { width: 220px; height: 220px; }
