:root {
  --bg: #f5f2ec; --card: #ffffff; --ink: #1c2230; --muted: #6a7182; --line: #e4dfd5;
  --accent: #0d6e66; --accent-soft: #dcefec; --warm: #c9591d; --warm-soft: #fbe9dd;
  --ok: #2c7a4b; --radius: 14px; --shadow: 0 1px 2px rgba(28,34,48,.06), 0 6px 20px rgba(28,34,48,.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 14px; font-weight: 600; }
.btn:hover { border-color: #cfc8ba; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--warm); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 12px; outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 64px; }
label.field { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 5px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; background: #eee9df; color: var(--muted); }
.pill.live, .pill.completed { background: var(--accent-soft); color: var(--accent); }
.pill.flag, .pill.abandoned { background: var(--warm-soft); color: var(--warm); }
.pill.active { background: #e6ecfb; color: #2d4fa3; }
.brandmark { font-weight: 800; letter-spacing: -.02em; font-size: 18px; }
.brandmark span { color: var(--accent); }

/* ---------- landing ---------- */
.landing { max-width: 760px; margin: 0 auto; padding: 72px 24px; }
.landing h1 { font-size: 40px; line-height: 1.1; margin: 18px 0 14px; }
.landing p { font-size: 17px; color: var(--muted); max-width: 600px; }

/* ---------- console ---------- */
.topbar { display: flex; align-items: center; gap: 14px; padding: 12px 22px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.shell { display: grid; grid-template-columns: 270px 1fr; min-height: calc(100vh - 53px); }
.side { border-right: 1px solid var(--line); padding: 16px; background: #faf8f3; }
.side .item { display: block; width: 100%; text-align: left; border: 1px solid transparent; background: transparent; border-radius: 10px; padding: 10px 12px; margin-bottom: 4px; }
.side .item:hover { background: #f0ece3; }
.side .item.on { background: var(--card); border-color: var(--line); box-shadow: var(--shadow); }
.side .item b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main { padding: 22px 26px 60px; min-width: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 14px 0 20px; }
.tab { border: 0; background: none; padding: 9px 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.on { color: var(--ink); border-bottom-color: var(--accent); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.qcard { margin-bottom: 14px; }
.qcard h3 { font-size: 15px; margin: 4px 0 2px; }
.bar { display: grid; grid-template-columns: minmax(44px, 150px) 1fr 74px; gap: 10px; align-items: center; margin-top: 8px; font-size: 13px; }
.bar .track { height: 18px; background: #f1ede5; border-radius: 6px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 6px; transition: width .5s ease; }
.bar .n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.grow-row { margin-top: 10px; }
.stack { display: flex; height: 22px; border-radius: 6px; overflow: hidden; background: #f1ede5; margin-top: 3px; }
.stack .seg { display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; min-width: 0; overflow: hidden; white-space: nowrap; }
.s0 { background: #cfd8d6; color: #44505a !important; } .s1 { background: #8fc1ba; } .s2 { background: #3f978d; } .s3 { background: #0d6e66; } .s4 { background: #094e48; } .s5 { background: #06332f; }
.hist { display: flex; align-items: flex-end; gap: 4px; height: 90px; margin-top: 12px; }
.hist .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 11px; color: var(--muted); }
.hist .col i { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; transition: height .5s ease; }
.quote { border-left: 3px solid var(--accent-soft); padding: 4px 0 4px 10px; margin-top: 10px; font-size: 14px; }
.quote .en { color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font-size: 12px; background: #f1ede5; border-radius: 999px; padding: 3px 9px; }
.feed { max-height: 360px; overflow: auto; }
.feed .ev { font-size: 13px; padding: 7px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; }
.feed .ev time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.feed .ev.flag, .feed .ev.redirect, .feed .ev.moved_on { color: var(--warm); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px; border-bottom: 1px solid #f0ece3; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #faf8f3; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl.xt th { white-space: normal; vertical-align: bottom; max-width: 110px; }
.tbl tr.tot td { font-weight: 700; border-top: 2px solid var(--line); }
.qedit { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; background: #fff; }
.qedit .grid { display: grid; grid-template-columns: 1fr 170px; gap: 10px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; margin-right: 14px; }
.notice { padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600; }
.notice.err { background: var(--warm-soft); color: var(--warm); }
.modal { position: fixed; inset: 0; background: rgba(28,34,48,.45); display: flex; justify-content: flex-end; z-index: 20; }
.modal .sheet { width: min(520px, 100%); background: var(--bg); height: 100%; overflow: auto; padding: 20px; }
.login { max-width: 380px; margin: 14vh auto; }
.linkbox { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: #f1ede5; border-radius: 10px; padding: 10px 12px; word-break: break-all; }

/* ---------- conversation (respondent + transcript) ---------- */
.msg { max-width: 86%; padding: 10px 14px; border-radius: 16px; margin: 6px 0; white-space: pre-wrap; word-wrap: break-word; animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg.bot { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; align-self: flex-start; }
.msg.bot.question { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); font-weight: 600; }
.msg.bot .hint { display: block; font-weight: 400; font-size: 13px; color: var(--muted); margin-top: 3px; }
.msg.user { background: var(--accent); color: #fff; border-bottom-right-radius: 5px; align-self: flex-end; }
.msg .meta { display: block; font-size: 11px; opacity: .7; margin-top: 3px; font-weight: 400; }
.msg.safety, .msg.flagged { border-color: var(--warm); }

.sv { max-width: 560px; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
.sv header { padding: 12px 16px 8px; }
.sv .progress { height: 5px; background: #e7e1d6; border-radius: 99px; overflow: hidden; margin-top: 8px; }
.sv .progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s ease; }
.sv .thread { flex: 1; overflow-y: auto; padding: 8px 16px 12px; display: flex; flex-direction: column; }
.sv .dock { padding: 8px 14px calc(12px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.sv .quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.sv .quick button { border: 1.5px solid var(--accent); color: var(--accent); background: #fff; border-radius: 999px; padding: 8px 14px; font-weight: 600; }
.sv .quick button.on { background: var(--accent); color: #fff; }
.sv .quick.scale button { padding: 8px 0; width: 40px; }
.sv .compose { display: flex; gap: 8px; align-items: center; }
.mic { flex: none; width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: var(--shadow); }
.mic svg { width: 24px; height: 24px; }
.mic.live { background: var(--warm); animation: ring 1.2s infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(201,89,29,.5); } 100% { box-shadow: 0 0 0 16px rgba(201,89,29,0); } }
.mic.speaking { background: #9fb9b5; }
.iconbtn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 10px; font-size: 12px; font-weight: 700; color: var(--muted); }
.iconbtn.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.sv .status { font-size: 12px; color: var(--muted); min-height: 18px; margin-bottom: 6px; }
.typing { align-self: flex-start; color: var(--muted); font-size: 13px; padding: 6px 4px; }
.welcome { padding: 28px 22px; overflow: auto; }
.welcome h1 { font-size: 26px; margin: 10px 0 8px; }
.consent { display: flex; gap: 10px; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 16px 0; font-size: 13px; }
.consent input { margin-top: 3px; width: 18px; height: 18px; flex: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .cols { grid-template-columns: 1fr; }
  .qedit .grid { grid-template-columns: 1fr; }
}
