:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface-2: #efeee8; --text: #1c2420; --muted: #5d6a63; --line: #dcdcd3;
  --brand: #1f6b45; --brand-ink: #ffffff; --brand-soft: #e3f0e8; --warn: #9a5b00; --warn-soft: #fbefd9; --err: #b3261e;
  --me: #1f6b45; --me-ink: #ffffff; --radius: 12px; --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614; --surface: #1a201d; --surface-2: #232b27; --text: #e7ece9; --muted: #9aa8a0; --line: #2e3833;
    --brand: #5fbf8a; --brand-ink: #0e1a13; --brand-soft: #1f3328; --warn: #f0b45a; --warn-soft: #3a2c14; --err: #ff8a80;
    --me: #2f7d55; --me-ink: #ffffff; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121614; --surface: #1a201d; --surface-2: #232b27; --text: #e7ece9; --muted: #9aa8a0; --line: #2e3833;
  --brand: #5fbf8a; --brand-ink: #0e1a13; --brand-soft: #1f3328; --warn: #f0b45a; --warn-soft: #3a2c14; --err: #ff8a80;
  --me: #2f7d55; --me-ink: #ffffff; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }
.muted { color: var(--muted); }

.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; letter-spacing: -.01em; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--brand); position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 6px 5px 6px 7px; border-left: 3px solid var(--brand-ink); border-bottom: 3px solid var(--brand-ink); transform: rotate(-45deg) translate(1px, -2px); }

.btn { border: 1px solid var(--line); background: var(--surface); padding: .5rem .9rem; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- sign in ---------- */
body.login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 1.6rem; line-height: 1.2; margin: 1rem 0 .5rem; }
.lede { color: var(--muted); margin: 0 0 1.25rem; }
.demo-box { background: var(--brand-soft); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 1.25rem; }
.demo-box p { margin: .25rem 0 .75rem; }
.cap { margin: 0 0 .75rem; min-height: 78px; }
form label { display: block; margin-bottom: .75rem; font-size: .9rem; color: var(--muted); }
form input { display: block; width: 100%; margin-top: .25rem; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.legal { margin: .5rem 0 0; font-size: .78rem; color: var(--muted); }
.legal a { color: var(--muted); }
.newhere { margin: 1.25rem 0 0; font-size: .9rem; color: var(--muted); }
.newhere a { color: var(--brand); font-weight: 600; }
.err { color: var(--err); min-height: 1.2em; margin: 0 0 .5rem; font-size: .9rem; }

/* ---------- panel ---------- */
body.app { display: flex; flex-direction: column; height: 100dvh; }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.site { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; font-weight: 600; }
.site #biz { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: .78rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.actions { display: flex; align-items: center; gap: 8px; }
.usage { font-size: .85rem; color: var(--muted); margin-right: 4px; }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 240px; padding: 6px; z-index: 5; }
.menu-list a, .menu-list button { display: block; width: 100%; text-align: left; padding: .55rem .7rem; border: 0; background: none; border-radius: 6px; color: var(--text); text-decoration: none; cursor: pointer; }
.menu-list a:hover, .menu-list button:hover { background: var(--surface-2); }

.tabs { display: none; }
.main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(320px, 420px) 1fr; }
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--surface); }
.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: .6rem .85rem; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--me); color: var(--me-ink); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.note { align-self: center; background: none; color: var(--muted); font-size: .85rem; text-align: center; padding: 0; }
.msg.big { align-self: flex-start; background: var(--warn-soft); color: var(--text); }
.msg .meta { display: block; font-size: .75rem; color: var(--muted); margin-top: .3rem; }
.status { align-self: flex-start; color: var(--muted); font-size: .9rem; display: flex; align-items: center; gap: .5rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: .3rem .7rem; font-size: .85rem; cursor: pointer; }
.chip:hover { border-color: var(--brand); }
.ask { display: flex; gap: 8px; padding: 10px 16px 6px; border-top: 1px solid var(--line); }
.ask textarea { flex: 1; resize: none; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); max-height: 160px; }
.ask .btn { align-self: flex-end; }
.meter { display: flex; align-items: center; gap: 8px; padding: 2px 16px 4px; font-size: .8rem; color: var(--muted); }
.meter-label { white-space: nowrap; }
.meter-bar { flex: 1; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter-bar i { display: block; height: 100%; width: 0; background: var(--brand); border-radius: 999px; transition: width .4s; }
.meter-pct { min-width: 2.5em; text-align: right; font-variant-numeric: tabular-nums; }
.meter.warn .meter-bar i { background: var(--warn); }
.meter.out .meter-bar i { background: var(--err); }
.meter.warn .meter-pct, .meter.out .meter-pct { color: var(--warn); font-weight: 600; }
.fine { margin: 0; padding: 0 16px 10px; font-size: .75rem; color: var(--muted); }

.preview { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; font-size: .9rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: .3rem .8rem; cursor: pointer; font-size: .85rem; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.frame-wrap { flex: 1; min-height: 0; display: flex; justify-content: center; padding: 0 16px 16px; }
.frame-wrap iframe { border: 1px solid var(--line); border-radius: 14px; background: #fff; width: 100%; height: 100%; box-shadow: var(--shadow); transition: opacity .2s; }
.frame-wrap[data-w="phone"] iframe { max-width: 400px; border-radius: 22px; }
.frame-wrap.loading iframe { opacity: .55; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 999px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; }

@media (max-width: 800px) {
  .hide-sm { display: none; }
  .top { padding: 8px 12px; gap: 8px; }
  .site { overflow: hidden; }
  .site #biz { display: none; }
  .actions { gap: 6px; }
  .actions .btn { padding: .45rem .7rem; }
  .tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--line); }
  .tab { flex: 1; border: 0; background: none; padding: .6rem; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
  .tab.on { color: var(--text); border-bottom-color: var(--brand); }
  .main { grid-template-columns: 1fr; }
  .main[data-view="chat"] .preview, .main[data-view="preview"] .chat { display: none; }
  .chat { border-right: 0; }
  .frame-wrap { padding: 0 8px 8px; }
  .seg { display: none; }
  .frame-wrap[data-w="phone"] iframe { max-width: none; border-radius: 14px; }
}

/* ---------- own-domain sheet ---------- */
.sheet { width: min(640px, calc(100% - 32px)); max-height: calc(100dvh - 32px); border: 1px solid var(--line); border-radius: 16px; padding: 20px 24px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.sheet::backdrop { background: rgb(0 0 0 / .4); }
.sheet h2 { margin: 0 0 .5rem; font-size: 1.3rem; }
.sheet-close { float: right; margin: -6px -10px 0 0; }
.steps { padding-left: 1.2rem; }
.steps > li { margin: 0 0 1rem; }
.row { display: flex; gap: 8px; margin-top: .5rem; }
.row input { flex: 1; min-width: 0; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.hint { color: var(--muted); font-size: .88rem; margin: .4rem 0 0; }
.where { margin: .4rem 0 0; padding-left: 1.1rem; font-size: .92rem; }
.recs { border-collapse: collapse; margin-top: .5rem; font-size: .92rem; width: 100%; }
.recs th, .recs td { text-align: left; padding: .4rem .6rem; border-bottom: 1px solid var(--line); }
.recs th { color: var(--muted); font-weight: 600; }
.recs code { overflow-wrap: anywhere; }
.checks { list-style: none; padding: 0; margin: .6rem 0 0; font-size: .92rem; }
.checks li { padding: .3rem 0; }
.checks li.ok { color: var(--brand); font-weight: 600; }
.checks li.wait { color: var(--warn); }
@media (max-width: 800px) { .sheet { padding: 16px; } .recs th:nth-child(2), .recs td:nth-child(2) { white-space: nowrap; } }
