:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1d1d1f; --muted: #6b7280; --line: #e5e7eb; --brand: #1473fb;
  --ok: #16a34a; --warn: #d97706; --bad: #dc2626; --chip: #f3f4f6; --hover: #f9fafb; --code: #f3f4f6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #171a21; --text: #e6e8ec; --muted: #9aa3b2; --line: #272b35; --chip: #222733;
    --hover: #1d212a; --code: #222733;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: inherit; }
button { font: inherit; }
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.logo { font-weight: 800; font-size: 18px; padding: 4px 8px 12px; }
.logo span { color: var(--brand); }
.side select { width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); margin-bottom: 10px; }
.nav { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--text); text-decoration: none; }
.nav:hover { background: var(--hover); }
.nav.on { background: var(--chip); font-weight: 600; }
.nav .cnt { background: var(--bad); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.side .bottom { margin-top: auto; font-size: 12px; color: var(--muted); padding: 8px; }
.main { padding: 22px 26px; min-width: 0; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 2px; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .s { font-size: 12px; color: var(--muted); }
.two { grid-template-columns: 1fr 1fr; }
.three { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) { .two, .three { grid-template-columns: 1fr; } }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--hover); }
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 500; }
.btn:hover { background: var(--hover); }
.btn.p { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sp { flex: 1; }
input, textarea, select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; }
textarea { width: 100%; min-height: 90px; resize: vertical; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
label.f input:not([type=checkbox]), label.f select, label.f textarea { width: 100%; }
.pill { display: inline-block; border-radius: 10px; padding: 1px 8px; font-size: 11.5px; background: var(--chip); }
.pill.ai { background: #e0f2fe; color: #075985; }
.pill.needs_human { background: #fee2e2; color: #991b1b; }
.pill.human { background: #ede9fe; color: #5b21b6; }
.pill.closed { background: var(--chip); color: var(--muted); }
.pill.ok { background: #dcfce7; color: #166534; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.inbox { display: grid; grid-template-columns: 380px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .inbox { grid-template-columns: 1fr; } }
.clist { max-height: calc(100vh - 170px); overflow-y: auto; padding: 0; }
.citem { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.citem:hover { background: var(--hover); }
.citem.on { background: var(--chip); }
.citem .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.citem.unread .t::before { content: "● "; color: var(--brand); }
.thread { max-height: calc(100vh - 330px); overflow-y: auto; padding: 4px; }
.msg { margin: 10px 0; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg .bb { max-width: 80%; padding: 9px 12px; border-radius: 12px; background: var(--chip); white-space: pre-wrap; word-wrap: break-word; }
.msg.user .bb { background: var(--brand); color: #fff; }
.msg.agent .bb { border-left: 3px solid var(--brand); }
.msg .meta { font-size: 11px; color: var(--muted); margin: 3px 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.msg .prods { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; max-width: 80%; }
.msg .prods a { font-size: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; text-decoration: none; }
details.trace { font-size: 12px; max-width: 80%; }
details.trace pre { background: var(--code); padding: 8px; border-radius: 8px; overflow-x: auto; max-height: 300px; white-space: pre-wrap; }
.login { max-width: 360px; margin: 12vh auto; }
.chart { width: 100%; height: 220px; }
.bar { fill: var(--brand); opacity: .85; }
.bar2 { fill: #2563eb; opacity: .8; }
.axis { stroke: var(--line); }
.tick { fill: var(--muted); font-size: 10px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre.snip { background: var(--code); padding: 12px; border-radius: 10px; overflow-x: auto; font-size: 12px; white-space: pre; }
.toast { position: fixed; bottom: 20px; right: 20px; background: #111; color: #fff; padding: 10px 14px; border-radius: 10px; z-index: 99; }
.progress { height: 6px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); }
.insight li { margin: 4px 0; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* proactive editor */
.rule.off { opacity: .55; }
.rule .row > b { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tz-prev { display: flex; align-items: flex-end; gap: 10px; justify-content: flex-end; background: var(--chip); padding: 14px; border-radius: 12px; }
.tz-b { background: #fff; color: #1d1d1f; border-radius: 14px; padding: 10px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.12); max-width: 300px; font-size: 13.5px; }
.tz-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tz-chips span { border: 1px solid; border-radius: 14px; padding: 3px 9px; font-size: 12px; }
.tz-l { width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 22px; flex: none; }
table.replies td { vertical-align: top; }
