/* BunChat: phone first, light and dark. */
:root {
  --bg: #f7f5f2; --panel: #ffffff; --line: #e6e2dc; --text: #1d1b19; --muted: #77716a; --accent: #c9792e; --accent-text: #ffffff;
  --mine: #f3e3cf; --theirs: #ffffff; --note: #8a847c; --ok: #2f8f4e; --warn: #b5461f; --code: #f1eee9; --react: #e4e0da;
  --safe-top: env(safe-area-inset-top); --safe-bottom: env(safe-area-inset-bottom);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151515; --panel: #1f1f1f; --line: #2e2e2e; --text: #ece9e4; --muted: #9a948c; --accent: #e0954d; --accent-text: #1a1209;
    --mine: #3a2c1d; --theirs: #242424; --note: #8f8a83; --ok: #5cc27d; --warn: #f08a5d; --code: #2a2a2a; --react: #3a3a3a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Noto Sans CJK SC", sans-serif; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.center { text-align: center; }
.muted { color: var(--muted); }
/* The banner (OMEN out of reach) above the page, not over it: the header's buttons (back, settings) stay usable. */
body { display: flex; flex-direction: column; height: 100dvh; }
#view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#banner { flex: none; z-index: 20; padding: calc(var(--safe-top) + 6px) 14px 6px; background: var(--warn); color: #fff; font-size: 14px; text-align: center; }
body:has(#banner:not([hidden])) header.bar { padding-top: 8px; }
/* A newer page on OMEN: a tap reloads (above the page, like the offline banner) */
.update { flex: none; padding: calc(var(--safe-top) + 6px) 14px 6px; background: var(--accent); color: var(--accent-text); font-size: 14px; text-align: center; cursor: pointer; }
.update + #banner, body:has(.update) header.bar { padding-top: 8px; }
#toast { position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 90px); transform: translateX(-50%); z-index: 30; max-width: 86vw;
  background: rgba(30, 28, 26, 0.92); color: #fff; padding: 9px 14px; border-radius: 12px; font-size: 14px; }

header.bar { display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-top) + 8px) 10px 8px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 52px; }
header.bar h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.bar .sub { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
header.bar .titlelink { display: flex; align-items: center; gap: 9px; cursor: pointer; min-width: 0; }
header.bar .titletext { display: flex; flex-direction: column; min-width: 0; }
header.bar .titletext .name { overflow: hidden; text-overflow: ellipsis; }
/* Pictures: the list's (44 px), the chat header's, a chat's own page's. */
img.avatar.pic { object-fit: cover; background: var(--line); display: block; }
.chatinfo { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 10px 0 18px; }
.chatinfo h2 { margin: 6px 0 0; font-size: 20px; }
.iconbtn { border: 0; background: none; padding: 6px 9px; font-size: 20px; border-radius: 10px; min-width: 40px; min-height: 40px; cursor: pointer; }
.iconbtn:active { background: var(--line); }

/* Login */
.login { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; }
.login img { width: 96px; height: 96px; border-radius: 22px; }
.login h1 { margin: 0; font-size: 28px; }
.big { border: 0; border-radius: 14px; padding: 14px 26px; font-size: 17px; font-weight: 600; background: var(--accent); color: var(--accent-text); cursor: pointer; }
.big:disabled { opacity: 0.5; }
.plain { border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; background: var(--panel); cursor: pointer; }
.danger { color: var(--warn); }

/* Chat list */
.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chatrow { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.avatar.cc { background: #7a6ad8; }
.avatar.muse { background: #2f9e6e; font-size: 15px; }
.avatar.chatgpt { background: #6b7280; font-size: 15px; }
.avatar.whatsapp { background: #1fa855; }
.small { font-size: 12px; }
.avatar { width: 44px; height: 44px; border-radius: 12px; flex: none; display: grid; place-items: center; font-weight: 700; color: #fff; background: #d0743a; }
.chatrow .main { flex: 1; min-width: 0; }
.chatrow .top { display: flex; justify-content: space-between; gap: 8px; }
.chatrow .name { font-weight: 600; }
.chatrow .time { font-size: 12px; color: var(--muted); flex: none; }
.chatrow .last { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 9px; margin-left: 6px; vertical-align: 1px; background: var(--line); color: var(--muted); font-weight: 500; }
.pill.working { background: #f6dcc0; color: #8a4b12; }
.pill.waiting { background: #f9d6cb; color: #9a3415; }
.pill.offline { background: #ddd; color: #666; }
@media (prefers-color-scheme: dark) { .pill.working { background: #4b3520; color: #f3c28f; } .pill.waiting { background: #4d2a20; color: #f6a588; } .pill.offline { background: #333; color: #aaa; } }

/* Messages */
.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 10px 16px; display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }
.older { align-self: center; margin: 6px 0; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0 2px; }
.msg { max-width: 86%; padding: 8px 11px; border-radius: 15px; word-wrap: break-word; overflow-wrap: anywhere; position: relative; }
.msg.in { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 5px; }
.msg.out { align-self: flex-start; background: var(--theirs); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.note { align-self: center; background: none; color: var(--note); font-size: 13px; padding: 2px 8px; text-align: center; max-width: 94%; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg.in .text { white-space: pre-wrap; }
.msg .where { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg.pending { opacity: 0.75; }
.msg.failed { opacity: 1; cursor: pointer; box-shadow: inset 0 0 0 1px var(--warn); }
/* Claude (or Muse) at work: three dots taking turns, as WhatsApp's "typing" bubble. */
.msg.typing { display: flex; gap: 5px; align-items: center; padding: 13px 15px; }
.msg.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: 0.35; animation: typing 1.2s infinite ease-in-out; }
.msg.typing i:nth-child(2) { animation-delay: 0.2s; }
.msg.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.35; } 30% { transform: translateY(-4px); opacity: 0.95; } }
@media (prefers-reduced-motion: reduce) { .msg.typing i { animation: none; opacity: 0.6; } }
/* A reaction, as WhatsApp shows one: a small pill on the bubble's lower edge (half in, half out), bottom left, ringed
   in the page's own colour; room left below so it never covers the next message, and the bubble wide enough that it
   doesn't run into the time. */
.msg.reacted { margin-bottom: 14px; min-width: 92px; }
.msg .react { position: absolute; left: 10px; bottom: -13px; font-size: 12px; line-height: 1; padding: 3px 6px; border-radius: 12px;
  background: var(--react); border: 2px solid var(--bg); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); user-select: none; }
.msg.failed .meta { color: var(--warn); }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md table { margin: 0.45em 0; }
.md ul, .md ol { padding-left: 1.3em; }
.md h1, .md h2, .md h3, .md h4 { font-size: 1.02em; margin: 0.6em 0 0.3em; }
.md code { background: var(--code); border-radius: 5px; padding: 0.05em 0.3em; font: 0.88em ui-monospace, Menlo, monospace; }
.md pre { background: var(--code); border-radius: 8px; padding: 8px 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--line); margin-left: 0; padding-left: 10px; color: var(--muted); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 3px 7px; }
.md img { max-width: 100%; }
.pic { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin: 2px 0; }
.file { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 10px; background: var(--code); text-decoration: none; color: var(--text); margin: 2px 0; max-width: 100%; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.choices button { border: 1px solid var(--accent); color: var(--accent); background: none; border-radius: 10px; padding: 6px 11px; cursor: pointer; text-align: left; }
.choices button.on { background: var(--accent); color: var(--accent-text); }
.q { margin-top: 8px; }
.q .qtext { font-weight: 600; margin-bottom: 4px; }

/* Composer */
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(var(--safe-bottom) + 8px); background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 18px; padding: 8px 12px; font: inherit; background: var(--bg); color: var(--text);
  max-height: 40vh; min-height: 38px; line-height: 1.35; }
.composer .send { border: 0; border-radius: 19px; min-width: 38px; height: 38px; background: var(--accent); color: var(--accent-text); font-size: 18px; cursor: pointer; }
.composer.readonly { justify-content: center; }
.composer.readonly p { margin: 6px 8px; text-align: center; font-size: 14px; }
/* /push and /stop above Claude's message box: small, out of the chat's way (they only fill the box) */
.quick { display: flex; gap: 6px; padding: 5px 10px 0; background: var(--panel); border-top: 1px solid var(--line); }
.quick button { font: inherit; font-size: 12.5px; line-height: 1; padding: 5px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); cursor: pointer; }
.quick button:active { background: var(--code); color: var(--text); }
.quick + .composer { border-top: 0; }
.attachments { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 10px 0; background: var(--panel); }
.chip { font-size: 13px; padding: 4px 8px; border-radius: 9px; background: var(--code); display: inline-flex; gap: 6px; align-items: center; }
.chip button { border: 0; background: none; padding: 0 2px; cursor: pointer; }
.menu { position: absolute; right: 10px; top: calc(var(--safe-top) + 52px); z-index: 10; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,0.15); overflow: hidden; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px 18px; border-bottom: 1px solid var(--line); cursor: pointer; }
.menu button:last-child { border-bottom: 0; }

/* Settings */
.settings { flex: 1; overflow-y: auto; padding: 12px 14px calc(var(--safe-bottom) + 20px); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 8px; }
.card .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.card .row:first-of-type { border-top: 0; }
.card p { margin: 6px 0; font-size: 14px; }
.card input[type=text] { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; font: inherit; background: var(--bg); color: var(--text); margin: 6px 0; }
.card .btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.login .card { width: 100%; max-width: 380px; text-align: left; }
/* (sizes last: they win over the kinds' font sizes) */
.avatar.av-small { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }
.avatar.av-big { width: 112px; height: 112px; border-radius: 26px; font-size: 36px; }
