/* Chat shell (ChatGPT-style layout). Default palette: dark wine + ivory (oweb); per-site brand.css overrides the variables. */

:root {
  --accent: #9b2139;
  --accent-2: #e07b8e;
  --accent-soft: rgba(184, 50, 77, .16);
  --ivory: #f5f1ea;
  --mark-glow: rgba(200, 64, 92, .35);
  --mark-glow-strong: rgba(200, 64, 92, .45);
  --avatar-from: #b8324d;
  --avatar-to: #4a0d1b;
  --overlay: rgba(8, 4, 5, .92);
  --overlay-strong: rgba(8, 4, 5, .94);
  --danger: #ef4444;
  --success: #22c55e;
  --warn: #f59e0b;
  --radius: 14px;
  --radius-lg: 22px;
  --sidebar-w: 272px;
  --thread-w: 768px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-brand: "Unbounded", "Segoe UI", system-ui, sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #140b0e;
  --bg-sidebar: #0d0709;
  --surface: #1f1417;
  --surface-2: #2b1b20;
  --hover: rgba(245, 241, 234, .06);
  --border: rgba(245, 241, 234, .1);
  --text: #f3ede9;
  --muted: #a8979b;
  --user-bubble: #3a1520;
  --shadow: 0 10px 40px rgba(0, 0, 0, .5);
  --scrim: rgba(5, 2, 3, .6);
  --ring: #f5f1ea;
  --oracle-pythia: #e0526d;
  --oracle-delphi: #f5f1ea;
  --oracle-sibyl: #d4a95c;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #fffdfb;
  --bg-sidebar: #f7f1ee;
  --surface: #f5eeeb;
  --surface-2: #ecdfdb;
  --hover: rgba(60, 10, 22, .05);
  --border: rgba(60, 10, 22, .11);
  --text: #1e1215;
  --muted: #7a6a6e;
  --user-bubble: #f3e4e6;
  --shadow: 0 10px 40px rgba(60, 10, 22, .14);
  --scrim: rgba(40, 8, 16, .35);
  --accent: #8a1b31;
  --accent-2: #8a1b31;
  --accent-soft: rgba(138, 27, 49, .09);
  --ring: #5a1222;
  --ring-back: #c8405c;
  --oracle-pythia: #b3243f;
  --oracle-delphi: #6b5d60;
  --oracle-sibyl: #a67a2c;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); }
body {
  font-family: var(--font);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); }
html[data-theme="light"] a { color: var(--accent); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.between { justify-content: space-between; gap: 8px; }
.row.end { justify-content: flex-end; }
.center { text-align: center; }

/* ── App frame (height follows the visual viewport so the keyboard never hides the composer) */
.app {
  position: fixed;
  left: 0; right: 0;
  top: var(--app-top, 0px);
  height: var(--app-h, 100dvh);
  display: flex;
  overflow: hidden;
}

/* ── Buttons */
.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
  color: var(--text);
  transition: background .15s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { transform: scale(.96); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: 12px;
  font-weight: 600; font-size: 15px;
  text-decoration: none;
  transition: background .15s, opacity .15s, transform .1s;
  width: 100%;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.sm { min-height: 36px; padding: 0 14px; font-size: 14px; width: auto; border-radius: 10px; }
.btn-primary { background: var(--accent); color: #fff !important; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--surface); color: var(--text) !important; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { color: var(--danger); background: transparent; border: 1px solid var(--border); margin-top: 8px; }

/* ── Brand mark (orb + orbit + dot) */
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.mark { width: 30px; height: 30px; stroke: none; fill: none; overflow: visible; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-brand); font-weight: 600; font-size: 16px; letter-spacing: -.2px; }
.brand .mark { filter: drop-shadow(0 0 10px var(--mark-glow)); }
.boot-mark { width: 84px; height: 84px; filter: drop-shadow(0 0 28px var(--mark-glow-strong)); }
.boot-name { font-family: var(--font-brand); font-weight: 500; letter-spacing: 2px; font-size: 13px; color: var(--muted); text-transform: uppercase; }
.loader-mark { width: 30px; height: 30px; margin: 4px 0; filter: drop-shadow(0 0 8px var(--mark-glow)); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--avatar-from), var(--avatar-to));
  color: #fff; font-weight: 700; font-size: 13px; flex-shrink: 0;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 52px; height: 52px; font-size: 18px; }

/* ── Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  display: flex; flex-direction: column;
  padding: calc(10px + var(--safe-top)) 10px calc(10px + var(--safe-bottom));
  gap: 4px;
  z-index: 40;
  transition: transform .25s cubic-bezier(.3, .7, .3, 1), margin-left .25s cubic-bezier(.3, .7, .3, 1);
}
.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 8px; }
.sb-new, .sb-item {
  display: flex; align-items: center; gap: 10px;
  min-height: 42px; padding: 0 12px;
  border-radius: 10px;
  font-weight: 500;
  text-align: left;
}
.sb-new { background: var(--surface); }
.sb-new:hover, .sb-item:hover { background: var(--hover); }
.sb-new:hover { background: var(--surface-2); }
.sb-search-wrap {
  display: flex; align-items: center; gap: 8px;
  margin: 6px 0 4px; padding: 0 12px; min-height: 38px;
  border-radius: 10px; color: var(--muted);
  border: 1px solid var(--border);
}
.sb-search-wrap svg { width: 16px; height: 16px; }
.sb-search-wrap input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; font-size: 14px; color: var(--text); }
.sb-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; -webkit-overflow-scrolling: touch; }
.sb-group { font-size: 12px; font-weight: 600; color: var(--muted); padding: 14px 12px 6px; }
.chat-item {
  position: relative;
  display: flex; align-items: center;
  min-height: 40px; border-radius: 10px;
  padding-left: 12px;
  cursor: pointer;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--surface-2); }
.chat-item .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-item input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--accent); border-radius: 8px; padding: 6px 8px; font-size: 14px; outline: 0; margin-right: 6px; }
.chat-item .more { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; color: var(--muted); opacity: 0; }
.chat-item:hover .more, .chat-item.active .more { opacity: 1; }
@media (hover: none) { .chat-item .more { opacity: .7; } }
.sb-empty { color: var(--muted); font-size: 13px; padding: 16px 12px; }
.sb-guest { padding: 12px; color: var(--muted); font-size: 13px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.sb-bottom { display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--border); }
.sb-upgrade, .sb-profile {
  display: flex; align-items: center; gap: 10px;
  min-height: 48px; padding: 6px 10px; border-radius: 12px; text-align: left;
}
.sb-upgrade:hover, .sb-profile:hover { background: var(--hover); }
.sb-upgrade-icon { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); display: inline-flex; align-items: center; justify-content: center; color: var(--accent-2); }
.sb-upgrade-text, .sb-profile-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.sb-upgrade-text b, .sb-profile-text b { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-upgrade-text small, .sb-profile-text small { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-gear { color: var(--muted); width: 18px; height: 18px; }
.scrim { display: none; }

/* ── Main column */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--bg); }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: calc(6px + var(--safe-top)) 8px 6px;
  min-height: calc(54px + var(--safe-top));
  flex-shrink: 0;
}
.topbar-title {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 10px;
  min-width: 0;
}
.topbar-title:hover { background: var(--hover); }
.topbar-brand { font-family: var(--font-brand); font-weight: 600; font-size: 15px; letter-spacing: -.2px; white-space: nowrap; }
.topbar-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { width: 16px; height: 16px; color: var(--muted); }

/* ── Thread */
.thread { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.thread-inner { max-width: var(--thread-w); margin: 0 auto; padding: 8px 16px 24px; min-height: 100%; display: flex; flex-direction: column; }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 24px 0 8px; }
.empty-mark { width: 76px; height: 76px; margin-bottom: 4px; filter: drop-shadow(0 0 26px var(--mark-glow-strong)); animation: float 6s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-5px) rotate(-3deg); } }
.empty h1 { font-size: 26px; font-weight: 600; letter-spacing: -.3px; }
.empty-lead { color: var(--text); opacity: .82; font-size: 15px; max-width: 440px; }
.empty-oracles { color: var(--muted); font-size: 13px; }
.empty-note { color: var(--muted); font-size: 12.5px; max-width: 420px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; max-width: 560px; margin-top: 18px; }
.suggestion {
  text-align: left; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 14px; line-height: 1.35;
  transition: background .15s;
}
.suggestion:hover { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.suggestion b { font-weight: 600; }
.suggestion small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.messages { display: flex; flex-direction: column; gap: 22px; }
.msg { display: flex; flex-direction: column; min-width: 0; }
.msg.user { align-items: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble);
  padding: 10px 16px; border-radius: 20px;
  max-width: min(85%, 600px);
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.ai .body { min-width: 0; overflow-wrap: anywhere; }
.msg-actions { display: flex; gap: 2px; margin-top: 4px; margin-left: -8px; color: var(--muted); }
.msg.user .msg-actions { margin-right: -8px; margin-left: 0; opacity: 0; transition: opacity .15s; }
.msg.user:hover .msg-actions { opacity: 1; }
@media (hover: none) { .msg.user .msg-actions { display: none; } }
.msg-actions button, .msg-actions a { width: 32px; height: 32px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; color: inherit; }
.msg-actions button:hover, .msg-actions a:hover { background: var(--hover); color: var(--text); }
.msg-actions svg { width: 16px; height: 16px; }
.msg-note { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* Markdown */
.md > *:first-child { margin-top: 0; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md table, .md h1, .md h2, .md h3, .md h4 { margin: 0 0 12px; }
.md > *:last-child { margin-bottom: 0; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3, .md h4 { font-size: 1.05em; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 4px 0; }
.md li > p { margin: 0; }
.md blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface); }
.md code { font-family: var(--mono); font-size: .88em; background: var(--surface); padding: 2px 5px; border-radius: 6px; }
.md img { max-width: 100%; border-radius: 12px; }
.code-block { border-radius: 12px; overflow: hidden; background: #1e1e24; margin: 0 0 12px; border: 1px solid rgba(255,255,255,.06); }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; font-size: 12px; color: #a9a6b6; background: #2a2931; font-family: var(--font); }
.code-head button { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #d4d2dc; padding: 4px 8px; border-radius: 6px; }
.code-head button:hover { background: rgba(255,255,255,.08); }
.code-head svg { width: 14px; height: 14px; }
.code-block pre { margin: 0; padding: 14px; overflow-x: auto; }
.code-block pre code { background: none !important; padding: 0; font-size: 13px; line-height: 1.55; color: #e6e4ee; }

/* Council */
.council { display: flex; flex-direction: column; gap: 10px; }
.voice { border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.voice-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 10px 14px; text-align: left;
  font-size: 13.5px;
}
.voice-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--vc); box-shadow: 0 0 10px var(--vc); flex-shrink: 0; }
.voice-head b { font-weight: 600; }
.voice-head small { color: var(--muted); font-size: 12.5px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-head .chev { transition: transform .2s; }
.voice.collapsed .voice-head .chev { transform: rotate(-90deg); }
.voice.collapsed .voice-body { display: none; }
.voice-body { padding: 0 14px 14px; }
.voice[data-voice="pythia"] { --vc: var(--oracle-pythia); }
.voice[data-voice="delphi"] { --vc: var(--oracle-delphi); }
.voice[data-voice="sibyl"] { --vc: var(--oracle-sibyl); }
.voice.pending .voice-body { color: var(--muted); }
.shimmer { display: flex; flex-direction: column; gap: 8px; }
.shimmer span { height: 10px; border-radius: 6px; background: linear-gradient(90deg, var(--surface) 0, var(--surface-2) 40%, var(--surface) 80%); background-size: 200% 100%; animation: sh 1.3s linear infinite; }
.shimmer span:nth-child(2) { width: 85%; } .shimmer span:nth-child(3) { width: 60%; }
@keyframes sh { to { background-position: -200% 0; } }
.voice-silent { color: var(--muted); font-style: italic; font-size: 14px; }

.typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }

.gen-image { max-width: min(380px, 82vw); width: 100%; }
.gen-image img { width: 100%; border-radius: 16px; display: block; }
.gen-image .ph { aspect-ratio: 1; border-radius: 16px; background: linear-gradient(90deg, var(--surface) 0, var(--surface-2) 40%, var(--surface) 80%); background-size: 200% 100%; animation: sh 1.3s linear infinite; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }

.inline-card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 10px; background: var(--surface);
}
.inline-card p { font-size: 14px; }
.inline-card .row { flex-wrap: wrap; }

/* ── Scroll-to-bottom */
.scroll-down {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--composer-h, 120px) + 10px);
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; z-index: 5;
}
.scroll-down svg { width: 18px; height: 18px; }

/* ── Composer */
.composer-wrap { flex-shrink: 0; padding: 0 12px calc(8px + var(--safe-bottom)); }
.composer {
  max-width: var(--thread-w); margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 6px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .08);
}
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.composer-tools { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 6px 2px; }
.composer-tools:empty { display: none; }
.tool-chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 6px 0 10px; border-radius: 15px; background: var(--accent-soft); color: var(--accent-2); font-size: 13px; font-weight: 500; }
html[data-theme="light"] .tool-chip { color: var(--accent); }
.tool-chip button { width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.tool-chip button:hover { background: var(--hover); }
.tool-chip svg { width: 12px; height: 12px; }
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.composer-plus { width: 38px; height: 38px; border-radius: 50%; color: var(--muted); }
.composer textarea {
  flex: 1; min-width: 0;
  resize: none; border: 0; outline: 0; background: transparent;
  font-size: 16px; /* ≥16px: iOS does not zoom on focus */
  line-height: 1.45;
  padding: 8px 4px;
  max-height: 40vh;
}
.composer textarea::placeholder { color: var(--muted); }
.send-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--text); color: var(--bg);
  display: inline-flex; align-items: center; justify-content: center;
  transition: opacity .15s, transform .1s;
}
.send-btn:disabled { opacity: .25; cursor: default; }
.send-btn:active { transform: scale(.94); }
.send-btn .i-stop { display: none; fill: currentColor; stroke: none; }
.send-btn.busy .i-send { display: none; }
.send-btn.busy .i-stop { display: block; }
.composer-hint { text-align: center; font-size: 12px; color: var(--muted); padding: 6px 8px 0; min-height: 24px; }
.composer-hint a { cursor: pointer; }

/* ── Popovers */
.popover {
  position: fixed; z-index: 70;
  min-width: 240px; max-width: calc(100vw - 24px);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 16px; padding: 6px;
  box-shadow: var(--shadow);
  animation: pop .14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
.pop-title { font-weight: 600; font-size: 14px; padding: 8px 10px 2px; }
.pop-desc { font-size: 12.5px; color: var(--muted); padding: 0 10px 6px; }
.pop-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px; border-radius: 10px; min-height: 44px; }
.pop-item:hover { background: var(--hover); }
.pop-item b { display: block; font-weight: 500; font-size: 14px; }
.pop-item small { display: block; color: var(--muted); font-size: 12.5px; }
.pop-item.danger { color: var(--danger); }
.pop-item.on { background: var(--accent-soft); }
.pop-ico { width: 24px; text-align: center; font-size: 16px; }

.oracle-list { display: flex; flex-direction: column; gap: 2px; }
.oracle-opt { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; cursor: pointer; min-height: 52px; }
.oracle-opt:hover { background: var(--hover); }
.oracle-opt .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--vc); box-shadow: 0 0 10px var(--vc); flex-shrink: 0; }
.oracle-opt[data-voice="pythia"] { --vc: var(--oracle-pythia); }
.oracle-opt[data-voice="delphi"] { --vc: var(--oracle-delphi); }
.oracle-opt[data-voice="sibyl"] { --vc: var(--oracle-sibyl); }
.oracle-opt .txt { flex: 1; min-width: 0; }
.oracle-opt b { display: block; font-size: 14px; font-weight: 600; }
.oracle-opt small { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.switch { position: relative; width: 40px; height: 24px; border-radius: 12px; background: var(--surface-2); transition: background .15s; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.oracle-opt.on .switch { background: var(--accent); }
.oracle-opt.on .switch::after { transform: translateX(16px); }
.oracle-opt.locked { cursor: not-allowed; }
.oracle-opt.locked .switch { opacity: .55; }

/* ── Sheets */
.sheet-bg {
  position: fixed; inset: 0; z-index: 80;
  background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease-out;
}
.sheet-bg.center { align-items: center; padding: 16px; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px;
  max-height: calc(var(--app-h, 100dvh) - var(--safe-top) - 24px);
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: flex; flex-direction: column;
  animation: up .24s cubic-bezier(.3, .7, .3, 1);
  box-shadow: var(--shadow);
}
.sheet.narrow { max-width: 420px; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 20px; }
.sheet-head h2 { font-size: 18px; font-weight: 600; }
.sheet-body { overflow-y: auto; padding: 6px 16px calc(20px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
@media (min-width: 700px) {
  .sheet-bg { align-items: center; padding: 24px; }
  .sheet { border-radius: var(--radius-lg); }
}

.set-profile { display: flex; align-items: center; gap: 14px; padding: 4px 4px 0; }
.set-profile b { display: block; font-size: 16px; }
.set-profile small { color: var(--muted); font-size: 13px; }
.set-group { display: flex; flex-direction: column; gap: 6px; }
.set-label { font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 0 6px; text-transform: uppercase; letter-spacing: .4px; }
.set-card { background: var(--surface); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.set-card.links { padding: 4px; gap: 0; }
.set-sub { flex-direction: row; align-items: center; justify-content: space-between; }
.set-sub p { font-size: 13px; color: var(--muted); margin-top: 4px; }
.set-hint { font-size: 13px; color: var(--muted); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; }
.set-link { display: flex; justify-content: space-between; align-items: center; min-height: 46px; padding: 0 12px; border-radius: 10px; color: var(--text) !important; text-decoration: none; }
.set-link:hover { background: var(--hover); }
.set-link span:last-child { color: var(--muted); font-size: 18px; }
.set-card textarea, .set-card input[type="text"], .login-form input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; outline: 0; resize: vertical;
}
.set-card textarea:focus, .set-card input:focus, .login-form input:focus { border-color: var(--accent); }
.set-card .row.gap input { flex: 1; }
.copy-field { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 4px 4px 4px 12px; }
.copy-field code { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px; border: 1px solid var(--border); }
.seg button { padding: 6px 12px; border-radius: 8px; font-size: 13.5px; color: var(--muted); }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.active::before { background: var(--success); box-shadow: 0 0 8px var(--success); }
.badge.trial::before { background: var(--warn); }

.plans { display: flex; flex-direction: column; gap: 10px; }
.plan {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
}
.plan.best { border-color: var(--accent); background: var(--accent-soft); }
.plan b { display: block; font-size: 15px; }
.plan small { color: var(--muted); font-size: 13px; }
.plan-price { font-size: 18px; font-weight: 700; white-space: nowrap; }
.plan-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.pay-box { border: 1px solid var(--accent); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }

.login-tg { display: flex; justify-content: center; min-height: 0; }
.login-tg:empty { display: none; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.login-form { display: flex; flex-direction: column; gap: 10px; }
.form-error { color: var(--danger); font-size: 13px; }

.dialog { background: var(--bg); border-radius: 18px; padding: 20px; width: 100%; max-width: 360px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 18px; animation: pop .16s ease-out; }
.dialog p { font-size: 15px; }

/* ── Toast & boot */
.toast {
  position: fixed; left: 50%; top: calc(14px + var(--safe-top));
  transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  max-width: calc(100vw - 32px); z-index: 100;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }
.boot { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; gap: 18px; align-items: center; justify-content: center; z-index: 200; transition: opacity .3s; }
.boot.gone { opacity: 0; pointer-events: none; }

/* ── Install (PWA) */
.install-hero { display: flex; align-items: center; gap: 14px; }
.install-hero img { border-radius: 16px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); flex-shrink: 0; }
.install-hero p { font-size: 14px; color: var(--muted); }
.install-steps { list-style: none; counter-reset: st; display: flex; flex-direction: column; gap: 10px; }
.install-steps li { counter-increment: st; display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: var(--radius); padding: 12px; font-size: 14.5px; }
.install-steps li::before { content: counter(st); width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.install-steps .ios-ico { display: inline-flex; vertical-align: -4px; width: 22px; height: 22px; padding: 2px; border-radius: 6px; background: var(--surface-2); color: #0a84ff; }
.install-steps .ios-ico svg { width: 18px; height: 18px; }
.install-banner {
  position: fixed; z-index: 60; left: 12px; right: 12px;
  bottom: calc(var(--composer-h, 110px) + 10px + var(--app-bottom-gap, 0px));
  max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px 10px 12px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  animation: up .3s cubic-bezier(.3, .7, .3, 1);
}
.install-banner img { border-radius: 10px; flex-shrink: 0; }
.ib-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.ib-text b { font-size: 14px; }
.ib-text small { font-size: 12.5px; color: var(--muted); }
.ib-close { width: 34px; height: 34px; color: var(--muted); }

/* ── Mobile: sidebar becomes a drawer */
@media (max-width: 899px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(86vw, 320px);
    transform: translateX(-102%);
    box-shadow: var(--shadow);
  }
  .app.drawer-open .sidebar { transform: none; }
  .app.drawer-open .scrim { display: block; position: fixed; inset: 0; background: var(--scrim); z-index: 30; animation: fade .2s; }
  .suggestions { grid-template-columns: 1fr; }
  .suggestion:nth-child(n+4) { display: none; }
  .empty h1 { font-size: 23px; }
}

/* ── Desktop: persistent, collapsible sidebar */
@media (min-width: 900px) {
  .sb-close { display: inline-flex; }
  .app.sidebar-collapsed .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
  .app:not(.sidebar-collapsed) #btn-new { visibility: hidden; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .thread-inner { padding-left: 24px; padding-right: 24px; }
}
@media (min-width: 900px) {
  .app:not(.sidebar-collapsed) #btn-menu { visibility: hidden; width: 0; padding: 0; margin: 0; overflow: hidden; }
}

/* ── Attachments ─────────────────────────────────────────── */
.touch-only { display: none; }
@media (pointer: coarse) { .touch-only { display: flex; } }
.pop-sep { height: 1px; background: var(--border); margin: 4px 6px; }

.attach-tray { display: flex; gap: 8px; overflow-x: auto; padding: 6px 6px 2px; scrollbar-width: none; }
.attach-tray::-webkit-scrollbar { display: none; }
.att { position: relative; flex: 0 0 auto; height: 64px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); display: flex; align-items: center; overflow: hidden; }
.att.img { width: 64px; }
.att.img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att.file { gap: 10px; padding: 0 30px 0 10px; max-width: 220px; }
.att-ico { flex: 0 0 38px; height: 38px; border-radius: 10px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.att-meta { min-width: 0; }
.att-meta b { display: block; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-meta small { color: var(--muted); font-size: 12px; }
.att-x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,.65); color: #fff; display: flex; align-items: center; justify-content: center; }
.att-x svg { width: 12px; height: 12px; stroke: #fff; }
.att.busy::before { content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.45); z-index: 1; }
.att.busy::after { content: ""; position: absolute; left: 50%; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%; border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff; animation: att-spin .8s linear infinite; z-index: 2; }
.att.file.busy::after { left: 29px; }
@keyframes att-spin { to { transform: rotate(360deg); } }
.att.err { border-color: var(--danger); }
.att.err::before { content: "!"; position: absolute; left: 4px; bottom: 4px; width: 18px; height: 18px; border-radius: 50%; background: var(--danger); color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; z-index: 1; }
.att-edit { flex: 0 0 auto; align-self: center; height: 32px; padding: 0 12px; border-radius: 16px; border: 1px dashed var(--accent-2); color: var(--accent-2); font-size: 13px; white-space: nowrap; }
html[data-theme="light"] .att-edit { color: var(--accent); border-color: var(--accent); }
.att-edit.on { background: var(--accent-soft); border-style: solid; }

.msg-files { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-bottom: 6px; max-width: min(85%, 600px); }
.msg-files .mf-img { width: 104px; height: 104px; border-radius: 16px; overflow: hidden; cursor: zoom-in; background: var(--surface-2); padding: 0; }
.msg-files.single .mf-img { width: auto; height: auto; max-width: min(220px, 60vw); max-height: 260px; }
.msg-files .mf-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg-files.single .mf-img img { max-width: min(220px, 60vw); max-height: 260px; width: auto; height: auto; object-fit: contain; }
.msg-files .att.file { height: 56px; padding-right: 12px; text-decoration: none; color: inherit; }
.gen-image img { cursor: zoom-in; }
.gen-image .edit-badge { display: inline-block; margin-top: 8px; font-size: 12.5px; color: var(--muted); }

.drop-zone { position: absolute; inset: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.drop-zone > div { border: 2px dashed var(--accent-2); border-radius: 24px; padding: 40px 56px; text-align: center; }
.drop-zone span { display: block; font-size: 40px; margin-bottom: 8px; }
.drop-zone b { font-weight: 500; }

.lightbox { position: fixed; inset: 0; z-index: 90; background: var(--overlay); display: flex; align-items: center; justify-content: center; padding: 24px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }
.lightbox .icon-btn { position: absolute; top: calc(12px + env(safe-area-inset-top)); color: #fff; background: rgba(255,255,255,.08); }
.lightbox .icon-btn svg { stroke: #fff; }
.lb-close { right: 12px; }
.lb-dl { right: 60px; }
.brand-name em, .topbar-brand em { font-style: normal; color: var(--accent-2); }

/* ── Voice input ─────────────────────────────────────────── */
.mic-btn { flex-shrink: 0; width: 38px; height: 38px; border-radius: 50%; color: var(--muted); }
.mic-btn.recording { color: #fff; background: #d8304f; animation: mic-pulse 1.2s ease-in-out infinite; }
.mic-btn.busy { pointer-events: none; opacity: .5; }
@keyframes mic-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(216, 48, 79, .55); } 50% { box-shadow: 0 0 0 8px rgba(216, 48, 79, 0); } }

/* ── Edit own message ────────────────────────────────────── */
.edit-box { width: min(100%, 600px); background: var(--user-bubble); border-radius: 20px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.edit-box textarea { width: 100%; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; line-height: 1.5; }
.edit-box .row { justify-content: flex-end; }
.msg.user:focus-within .msg-actions { opacity: 1; }
@media (hover: none) { .msg.user .msg-actions { display: flex; opacity: .75; } }

/* ── Image aspect ratio ──────────────────────────────────── */
.aspect-seg { display: inline-flex; gap: 2px; padding: 2px; border-radius: 15px; background: var(--surface-2); }
.aspect-seg button { height: 26px; padding: 0 9px; border-radius: 13px; font-size: 12.5px; color: var(--muted); }
.aspect-seg button.on { background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
html[data-theme="light"] .aspect-seg button.on { color: var(--accent); }

/* ── Laptop camera ───────────────────────────────────────── */
.cam-modal { position: fixed; inset: 0; z-index: 95; background: var(--overlay-strong); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; }
.cam-modal video { max-width: min(960px, 100%); max-height: calc(100vh - 140px); border-radius: 16px; background: #000; transform: scaleX(-1); }
.cam-bar { display: flex; align-items: center; justify-content: space-between; width: min(360px, 100%); }
.cam-bar .icon-btn, .cam-spacer { width: 44px; height: 44px; }
.cam-bar .icon-btn { color: #fff; background: rgba(255,255,255,.1); }
.cam-bar .icon-btn svg { stroke: #fff; }
.cam-shot { width: 68px; height: 68px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px var(--overlay-strong), 0 0 0 7px #fff; transition: transform .1s; }
.cam-shot:active { transform: scale(.92); }
