:root {
  --bg: #ffffff; --soft: #f4f6f7; --line: #e3e7ea; --ink: #0f172a; --muted: #64748b;
  --teal: #0f766e; --teal2: #14b8a6; --gold: #d4a017; --red: #dc2626; --amber: #b45309; --green: #15803d;
  --r: 18px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overflow: hidden; }
a { color: var(--teal); }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .pad { padding: 6px 12px; }
.err { color: var(--red); min-height: 0; margin: 4px 0 0; } .err:empty { display: none; }
.ok-text { color: var(--green); } .warn-text { color: var(--amber); }
.btn, button.primary, button.ghost { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 999px; padding: 10px 16px; border: 1px solid var(--line); background: var(--bg); text-decoration: none; font-weight: 600; font-size: .92rem; min-height: 42px; }
button.primary, a.btn.primary, .btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.primary:disabled { opacity: .45; cursor: not-allowed; }
.ghost.danger { color: var(--red); border-color: #fecaca; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; font-size: 1.25rem; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--soft); } .icon-btn.small { width: 32px; height: 32px; font-size: 1rem; }
.pill { display: inline-block; font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); font-weight: 600; white-space: nowrap; }
.pill.bad { background: #fee2e2; color: var(--red); } .pill.warn { background: #fef3c7; color: var(--amber); } .pill.ok { background: #dcfce7; color: var(--green); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: .85rem; font-weight: 600; color: #334155; }
.form input, .form textarea, .pub-form input { width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 16px; }
.form .check, label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.form .check input { width: auto; }
.logo, .hello-logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--teal2), var(--teal)); color: #fff; font-weight: 800; }
.brandmark { display: flex; gap: 10px; align-items: center; } .brandmark small { display: block; color: var(--muted); font-size: .75rem; }

/* auth screens */
.view.auth { height: 100%; overflow: auto; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(180deg, #f0fdfa, #fff 40%); }
.auth-card { width: 100%; max-width: 420px; } .auth-card.wide { max-width: 760px; }
.auth-card h1 { font-size: 1.6rem; margin: 28px 0 14px; }
.legal-footer, .app-footer { margin: 22px 0 0; text-align: center; font-size: .72rem; color: var(--muted); line-height: 1.45; font-weight: 500; }
.app-footer { margin: 0; padding: 6px 16px calc(8px + var(--safe-b)); border-top: 1px solid var(--line); background: #fff; }
.tiers { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.tier { border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 4px; }
.tier.current { border-color: var(--teal); box-shadow: 0 0 0 2px #ccfbf1; }
.tiers.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.sheet-body > * { min-width: 0; }

/* app shell */
.chat-app { height: 100dvh; display: flex; }
.drawer { position: fixed; inset: 0 auto 0 0; width: min(84vw, 320px); background: var(--soft); z-index: 30; transform: translateX(-102%); transition: transform .22s ease; display: flex; flex-direction: column; padding-top: var(--safe-t); }
.drawer.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.2); }
.scrim { position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 25; }
.drawer-head { padding: 14px 14px 8px; }
.drawer-new { margin: 6px 12px; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; text-align: left; font-weight: 600; }
.drawer-scroll { flex: 1; overflow: auto; padding: 0 8px; }
.drawer h3 { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 8px 6px; }
.bot-list, .conv-list, .vault-list, .costs, .ledger, .tb-links, .leads, .mem { list-style: none; margin: 0; padding: 0; }
.bot-list li { display: flex; align-items: center; }
.bot { flex: 1; display: flex; gap: 10px; align-items: center; border: 0; background: transparent; padding: 8px; border-radius: 12px; text-align: left; min-width: 0; }
.bot.active, .conv.active { background: #e2e8f0; }
.bot-txt { min-width: 0; } .bot-txt small { display: block; color: var(--muted); font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { flex: none; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--teal2), var(--teal)); color: #fff; font-weight: 700; font-size: .85rem; }
.avatar.helper { background: linear-gradient(135deg, #f59e0b, #d97706); } .avatar.bank { background: #e0f2fe; }
.link-btn { border: 0; background: transparent; color: var(--teal); font-weight: 600; padding: 8px; }
.conv { width: 100%; border: 0; background: transparent; text-align: left; padding: 9px 10px; border-radius: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }
.drawer-foot { border-top: 1px solid var(--line); padding: 8px 8px calc(8px + var(--safe-b)); display: grid; }
.menu-item { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 10px; border-radius: 10px; text-align: left; font-size: .92rem; }
.menu-item:hover { background: #e2e8f0; } .menu-item .pill { margin-left: auto; } .menu-item.toggle input { margin-left: auto; width: 18px; height: 18px; }
.mi { width: 22px; text-align: center; } .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.chat-top { display: flex; align-items: center; gap: 6px; padding: calc(6px + var(--safe-t)) 8px 6px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.92); backdrop-filter: blur(8px); }
.chat-title { flex: 1; min-width: 0; text-align: center; line-height: 1.15; }
.chat-title strong { display: block; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .chat-title small { color: var(--muted); font-size: .72rem; }
.credits { border: 1px solid var(--line); background: #f0fdfa; color: var(--teal); border-radius: 999px; padding: 5px 10px; font-weight: 700; font-size: .9rem; }
.credits small { font-weight: 500; font-size: .7rem; }
@media (max-width: 400px) { .credits small { display: none; } .credits::before { content: "◎ "; font-weight: 500; } } .credits.low { background: #fef3c7; color: var(--amber); }
.banner { font-size: .72rem; text-align: center; padding: 4px 10px; background: #fffbeb; color: #92400e; border-bottom: 1px solid #fde68a; }

.thread { flex: 1; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }
.empty { margin: auto 0; text-align: center; padding: 10px 6px 20px; }
.hello-logo { width: 56px; height: 56px; border-radius: 18px; font-size: 1.6rem; }
.empty h1 { font-size: 1.45rem; margin: 14px 0 6px; } .empty p { margin: 0 auto 18px; max-width: 34ch; font-size: .92rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 9px 13px; font-size: .86rem; }
.chip:hover { background: var(--soft); }

.msg { display: flex; gap: 8px; align-items: flex-start; max-width: 100%; }
.msg.user { justify-content: flex-end; }
.bubble-col { display: grid; gap: 8px; min-width: 0; max-width: 88%; }
.msg.user .bubble-col { justify-items: end; }
.msg.assistant .bubble-col { flex: 1; max-width: calc(100% - 38px); }
.bubble { white-space: pre-wrap; word-wrap: break-word; line-height: 1.45; font-size: .98rem; }
.msg.user .bubble { background: var(--soft); padding: 10px 14px; border-radius: 20px 20px 6px 20px; }
.msg.assistant .bubble { padding: 4px 2px; }
.bubble.error { color: var(--red); }
.bubble.typing { display: flex; gap: 4px; padding: 10px 2px; } .bubble.typing i { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; animation: blink 1.2s infinite; }
.bubble.typing i:nth-child(2) { animation-delay: .2s; } .bubble.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.att-list { display: flex; gap: 6px; flex-wrap: wrap; } .att-img { max-width: 160px; border-radius: 12px; }
.att-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 4px 8px; font-size: .8rem; }
.att-chip button { border: 0; background: transparent; padding: 0 2px; }

/* inline cards */
.card-x { border: 1px solid var(--line); border-radius: var(--r); background: #fff; overflow: hidden; box-shadow: 0 1px 2px rgba(15,23,42,.05); }
.card-body { padding: 12px 14px; display: grid; gap: 8px; } .card-body p { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; } .actions > * { flex: 1; }
.card-x.mini { padding: 8px 12px; font-size: .85rem; color: #334155; display: flex; gap: 6px; flex-wrap: wrap; }
.sources a { font-size: .8rem; }
.site-thumb { position: relative; height: 190px; overflow: hidden; background: var(--soft); border-bottom: 1px solid var(--line); }
.site-thumb iframe { width: 250%; height: 475px; border: 0; transform: scale(.4); transform-origin: 0 0; pointer-events: none; background: #fff; }
.thumb-tag { position: absolute; left: 10px; top: 10px; background: rgba(15,23,42,.8); color: #fff; font-size: .72rem; padding: 3px 8px; border-radius: 999px; }
.pub-form { display: grid; gap: 6px; margin-top: 4px; } .pub-form p { margin: 0; }
.confirm-card { border-color: #fcd34d; background: #fffdf5; }
.flyer-card img { display: block; width: 100%; max-height: 420px; object-fit: contain; background: var(--soft); }
.doc-ico { font-size: 1.3rem; } .doc-card .row { justify-content: flex-start; } .excerpt { white-space: pre-wrap; max-height: 5.5em; overflow: hidden; }
.bot-card .row { justify-content: flex-start; }
.tb-logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: #111827; color: #facc15; font-weight: 800; font-size: .72rem; }
.tb-card .row strong { flex: 1; } .tb-links li { padding: 6px 0; border-top: 1px solid var(--line); } .tb-links a { font-weight: 600; text-decoration: none; }
.post-text { background: var(--soft); border-radius: 12px; padding: 10px; white-space: pre-wrap; font-size: .92rem; }
.task-shot { width: 100%; border-radius: 12px; border: 1px solid var(--line); }
.confirm { border: 1px solid #fcd34d; background: #fffbeb; border-radius: 14px; padding: 10px 12px; display: grid; gap: 6px; } .confirm p { margin: 0; }
.confirm.high { border-color: #fca5a5; background: #fef2f2; }
.result { background: #f0fdf4; border-radius: 12px; padding: 10px; }
.steps summary { cursor: pointer; color: var(--muted); } .steps ol { padding-left: 18px; margin: 6px 0 0; font-size: .82rem; display: grid; gap: 4px; }
.vault-card { border-color: #99f6e4; background: #f0fdfa; }
.leads li { border-top: 1px solid var(--line); padding: 6px 0; font-size: .82rem; }

/* composer */
.composer { padding: 6px 10px 8px; background: #fff; }
.attach-row { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 4px 6px; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; border: 1px solid var(--line); border-radius: 28px; padding: 6px; background: var(--soft); }
.composer textarea { flex: 1; min-height: 40px; align-self: center; border: 0; background: transparent; resize: none; padding: 9px 4px; max-height: 160px; font-size: 16px; line-height: 1.35; outline: none; }
.icon-btn.attach { border-radius: 50%; font-size: 1.4rem; color: #475569; }
.mic, .send { flex: none; width: 52px; height: 52px; border-radius: 50%; border: 0; display: grid; place-items: center; background: var(--teal); color: #fff; box-shadow: 0 4px 14px rgba(15,118,110,.35); }
.mic svg, .send svg { width: 26px; height: 26px; fill: currentColor; }
.send { background: var(--ink); box-shadow: none; width: 44px; height: 44px; margin: 4px; }

/* listening overlay */
.listening { position: fixed; inset: 0; z-index: 40; background: linear-gradient(180deg, #042f2e, #0f766e); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; text-align: center; }
.pulse { width: 120px; height: 120px; border-radius: 50%; background: #14b8a6; display: grid; place-items: center; animation: pulse 1.6s infinite; }
.pulse svg { width: 54px; height: 54px; fill: #fff; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(94,234,212,.55); } 70% { box-shadow: 0 0 0 36px rgba(94,234,212,0); } 100% { box-shadow: 0 0 0 0 rgba(94,234,212,0); } }
.listen-label { font-size: .9rem; opacity: .8; margin: 0; letter-spacing: .05em; text-transform: uppercase; }
.live-text { font-size: 1.35rem; line-height: 1.35; max-width: 30ch; min-height: 3em; margin: 0; }
.listen-actions { display: flex; gap: 10px; } .listen-actions .ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); } .listen-actions .primary { background: #fff; color: var(--teal); border-color: #fff; }

/* bottom sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 35; background: rgba(15,23,42,.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 88dvh; background: #fff; border-radius: 22px 22px 0 0; display: flex; flex-direction: column; padding-bottom: var(--safe-b); animation: up .2s ease; }
.sheet-wrap.tall .sheet { height: 92dvh; max-height: 92dvh; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: #cbd5e1; margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px 0 18px; } .sheet-head h2 { font-size: 1.1rem; margin: 0; }
.sheet-body { overflow-x: hidden; overflow-y: auto; padding: 8px 18px 18px; display: grid; gap: 12px; align-content: start; flex: 1; }
.sheet-body h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 8px 0 0; }
.meter-card { background: linear-gradient(135deg, #f0fdfa, #ecfeff); border: 1px solid #99f6e4; border-radius: 16px; padding: 14px; display: grid; gap: 6px; }
.big { font-size: 2.4rem; font-weight: 800; color: var(--teal); }
.bar { height: 8px; background: #d1fae5; border-radius: 4px; overflow: hidden; } .bar span { display: block; height: 100%; background: var(--teal); }
.topup { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 14px; padding: 12px; } .topup > div { flex: 1; }
.costs li, .ledger li { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); }
.vault-list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); } .vault-list li > span:nth-child(2) { flex: 1; }
.mem li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.page-tabs { display: flex; gap: 6px; overflow-x: auto; } .site-full { width: 100%; flex: 1; min-height: 60dvh; border: 1px solid var(--line); border-radius: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .88rem; z-index: 50; max-width: 90vw; }

/* wider screens: sidebar stays open, chat column centred */
@media (min-width: 900px) {
  .drawer { position: static; transform: none; width: 280px; border-right: 1px solid var(--line); }
  .scrim, #menuBtn { display: none !important; }
  .thread, .composer { width: 100%; max-width: 780px; margin: 0 auto; }
  .chat-title { text-align: left; padding-left: 8px; }
}

/* plan sheet: weekly uses, AI credits, top-up */
.big .of { font-size: 1rem; font-weight: 600; color: var(--muted); margin-left: 4px; }
.ai-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid #fde68a; background: #fffbeb; border-radius: 16px; padding: 12px 14px; }
.ai-card .big2 { font-size: 1.9rem; font-weight: 800; color: #b45309; line-height: 1.1; } .ai-card > .small { max-width: 17ch; text-align: right; }
.topup-box { border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; display: grid; gap: 8px; } .topup-box p { margin: 0; }
.tu-chips { justify-content: flex-start; } .tu-chips .chip { padding: 7px 12px; }
.tu-row { display: flex; align-items: center; gap: 8px; } .tu-row .cur { font-weight: 700; color: var(--muted); }
.tu-row input { flex: 1; min-width: 0; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); font-size: 16px; }
.pay-step { border: 1px dashed #f59e0b; background: #fffbeb; border-radius: 14px; padding: 12px; display: grid; gap: 8px; }
.pay-tag { font-size: .75rem; font-weight: 700; color: #92400e; text-transform: uppercase; letter-spacing: .04em; }
.pay-line { display: flex; justify-content: space-between; } button.wide { width: 100%; }
.notice.ok-box { background: #dcfce7; color: #166534; border-radius: 14px; padding: 10px 14px; font-weight: 600; }
.ledger .src { font-style: normal; font-size: .72rem; color: var(--muted); background: var(--soft); border-radius: 999px; padding: 1px 7px; margin-left: 4px; }
.notice { background: #f1f5f9; color: #334155; border-radius: 14px; padding: 10px 14px; font-weight: 600; }
.tier .pick { margin-top: 6px; min-height: 40px; border: 0; border-radius: 10px; background: var(--teal); color: #fff; font-weight: 700; font-size: .78rem; padding: 6px 4px; cursor: pointer; }
.tier .pick:disabled { opacity: .55; }
.linkish { background: none; border: 0; padding: 6px 0; color: var(--muted); text-decoration: underline; font: inherit; cursor: pointer; min-height: 40px; }
