:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --surface-strong: #eef3f0;
  --text: #18201c;
  --text-soft: #68736d;
  --text-faint: #929b96;
  --line: #e2e8e4;
  --line-strong: #d3dbd6;
  --accent: #1aa06d;
  --accent-strong: #118257;
  --accent-soft: #e5f6ee;
  --accent-ink: #0b6040;
  --danger: #c74e4e;
  --danger-soft: #fff0ef;
  --warning: #9c6d17;
  --warning-soft: #fff7df;
  --shadow: 0 18px 45px rgba(31, 48, 40, .07);
  --shadow-sm: 0 8px 24px rgba(31, 48, 40, .055);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --sidebar: 244px;
}

html[data-theme="dark"] {
  --bg: #101412;
  --surface: #171c19;
  --surface-soft: #1b211e;
  --surface-strong: #222a26;
  --text: #f3f7f5;
  --text-soft: #9eaaa4;
  --text-faint: #6f7974;
  --line: #29322d;
  --line-strong: #344038;
  --accent: #49cf98;
  --accent-strong: #5dddA6;
  --accent-soft: #17372a;
  --accent-ink: #98ebc8;
  --danger: #ef8581;
  --danger-soft: #3b2221;
  --warning: #ecc56f;
  --warning-soft: #362d1a;
  --shadow: 0 18px 45px rgba(0, 0, 0, .25);
  --shadow-sm: 0 8px 24px rgba(0, 0, 0, .18);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button, select { cursor: pointer; }
textarea { resize: vertical; }
[hidden] { display: none !important; }

::selection { background: var(--accent-soft); color: var(--accent-ink); }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 28px;
  padding: 32px 20px;
  background:
    radial-gradient(circle at 20% 10%, rgba(26,160,109,.08), transparent 32%),
    radial-gradient(circle at 90% 90%, rgba(26,160,109,.05), transparent 28%),
    var(--bg);
}
.auth-brand, .brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  font-weight: 760;
  letter-spacing: -.02em;
}
.auth-brand { font-size: 22px; }
.brand-button {
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: inline-grid;
  place-items: center;
  background: var(--text);
  color: var(--surface);
  font-weight: 850;
  letter-spacing: -.06em;
  box-shadow: var(--shadow-sm);
}
.auth-card {
  width: min(100%, 430px);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 6px 0 8px; font-size: 30px; letter-spacing: -.035em; }
.auth-foot { color: var(--text-faint); font-size: 13px; margin: 0; }

.eyebrow {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.muted { color: var(--text-soft); }
.stack { display: grid; gap: 16px; margin-top: 24px; }

.field { display: grid; gap: 7px; }
.field > span { font-size: 13px; font-weight: 680; color: var(--text); }
.field small { color: var(--text-faint); font-weight: 500; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border .16s ease, box-shadow .16s ease, background .16s ease;
}
input, select { min-height: 44px; padding: 0 13px; }
textarea { padding: 12px 13px; line-height: 1.55; }
input:focus, textarea:focus, select:focus {
  border-color: color-mix(in srgb, var(--accent) 75%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-soft) 80%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }

.button {
  border: 1px solid transparent;
  border-radius: 12px;
  min-height: 42px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 720;
  transition: transform .14s ease, background .14s ease, border .14s ease, opacity .14s ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.button-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.button-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.button-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.button-secondary:hover { background: var(--surface-soft); }
.button-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, var(--line)); }
.button-lg { min-height: 48px; }
.full-width { width: 100%; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  padding: 24px 18px 18px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 30;
}
.brand { padding: 0 10px; min-height: 44px; }
.brand-name { font-size: 18px; }
.nav { display: grid; gap: 5px; margin-top: 34px; }
.nav-item {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 0 12px;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text-soft);
  font-weight: 650;
  text-align: left;
}
.nav-item:hover { background: var(--surface-soft); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav-icon {
  width: 24px;
  display: inline-grid;
  place-items: center;
  font-size: 18px;
}
.sidebar-bottom { margin-top: auto; display: grid; gap: 12px; }
.soft-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text-soft);
}
.user-mini {
  display: grid;
  grid-template-columns: 36px 1fr 32px;
  align-items: center;
  gap: 9px;
  padding: 10px 8px;
  border-top: 1px solid var(--line);
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 760;
  flex: none;
}
.user-mini-copy { min-width: 0; display: grid; }
.user-mini-copy strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-mini-copy span { font-size: 11px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  display: inline-grid;
  place-items: center;
}
.icon-button:hover { background: var(--surface-soft); }

.main { margin-left: var(--sidebar); min-height: 100vh; }
.topbar {
  height: 84px;
  padding: 0 clamp(24px, 4vw, 54px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h2 { margin: 2px 0 0; font-size: 20px; letter-spacing: -.025em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.page {
  display: none;
  padding: 10px clamp(24px, 4vw, 54px) 54px;
  animation: fadeIn .18s ease;
}
.page.active { display: block; }
@keyframes fadeIn { from { opacity: .35; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 760;
  white-space: nowrap;
}
.status-neutral { background: var(--surface-strong); color: var(--text-soft); }
.status-connected, .status-ai { background: var(--accent-soft); color: var(--accent-ink); }
.status-human { background: var(--warning-soft); color: var(--warning); }
.status-disconnected { background: var(--danger-soft); color: var(--danger); }

.hero-card {
  min-height: 220px;
  padding: clamp(28px, 4vw, 46px);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at 85% 20%, color-mix(in srgb, var(--accent-soft) 75%, transparent), transparent 30%),
    var(--surface);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
}
.hero-copy { max-width: 680px; }
.hero-copy h1 {
  max-width: 560px;
  margin: 8px 0 14px;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.02;
  letter-spacing: -.055em;
}
.hero-copy p { max-width: 590px; margin: 0; color: var(--text-soft); font-size: 17px; }

.step-grid, .stats-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 18px;
}
.step-card, .stat-card, .card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.step-card {
  min-height: 112px;
  padding: 18px;
  text-align: left;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 13px;
}
.step-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.step-number, .number-dot {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: inline-grid;
  place-items: center;
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 800;
}
.step-card strong { display: block; margin-bottom: 3px; }
.step-card p { margin: 0; color: var(--text-soft); font-size: 13px; }
.step-state {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 10px;
  color: var(--text-faint);
  white-space: nowrap;
}
.step-state-ready { color: var(--accent-ink); background: var(--accent-soft); border-color: transparent; }

.stat-card { padding: 20px; }
.stat-card span, .stat-card small { color: var(--text-soft); }
.stat-card span { font-size: 13px; font-weight: 650; }
.stat-card strong { display: block; margin: 10px 0 3px; font-size: 32px; letter-spacing: -.04em; }
.stat-card small { font-size: 12px; }

.clean-card { margin-top: 18px; padding: 26px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.card-head h3 { margin: 5px 0 0; font-size: 22px; letter-spacing: -.03em; }
.flow-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  margin-top: 30px;
}
.flow-item { display: grid; justify-items: center; text-align: center; gap: 5px; }
.flow-item > span {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 800;
}
.flow-item small { color: var(--text-soft); }
.flow-line { width: 56px; height: 1px; background: var(--line-strong); }

.section-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}
.section-intro h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: -.04em; }
.section-intro p { margin: 0; color: var(--text-soft); }
.select { background: var(--surface); }
.compact-select { width: min(260px, 100%); }

.empty-state {
  min-height: 370px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-xl);
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  padding: 36px;
  background: color-mix(in srgb, var(--surface) 75%, transparent);
}
.empty-state h3 { margin: 14px 0 5px; font-size: 21px; }
.empty-state p { max-width: 440px; margin: 0 0 20px; color: var(--text-soft); }
.empty-icon {
  width: 54px; height: 54px; border-radius: 17px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-ink); font-size: 25px;
}

.instance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(285px, 1fr));
  gap: 14px;
}
.instance-card { padding: 20px; }
.instance-card-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.instance-card h3 { margin: 0; font-size: 18px; }
.instance-card p { margin: 5px 0 0; color: var(--text-soft); font-size: 13px; }
.instance-meta { margin-top: 22px; padding-top: 15px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.instance-meta .button { flex: 1; }

.agent-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(330px, .65fr);
  gap: 18px;
  align-items: start;
}
.agent-form { padding: 26px; }
.form-section { display: grid; gap: 18px; }
.section-label { display: flex; align-items: flex-start; gap: 12px; }
.section-label h3 { margin: 0; font-size: 19px; }
.section-label p { margin: 4px 0 0; color: var(--text-soft); font-size: 13px; max-width: 620px; }
.divider { height: 1px; background: var(--line); margin: 26px 0; }
.context-area { min-height: 230px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.agent-savebar {
  position: sticky;
  bottom: 14px;
  margin: 28px -10px -10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  box-shadow: var(--shadow);
}
.toggle-row { display: flex; align-items: center; gap: 11px; }
.toggle-row strong { display: block; font-size: 13px; }
.toggle-row small { color: var(--text-soft); display: block; }
.switch { position: relative; width: 42px; height: 24px; display: inline-block; }
.switch input { width: 0; height: 0; opacity: 0; position: absolute; }
.switch-ui {
  position: absolute; inset: 0; border-radius: 999px; background: var(--line-strong); transition: .18s ease;
}
.switch-ui::after {
  content: "";
  position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 5px rgba(0,0,0,.18); transition: .18s ease;
}
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(18px); }
.save-actions { display: flex; align-items: center; gap: 12px; }
.save-status { color: var(--text-soft); font-size: 12px; }

.test-panel { position: sticky; top: 20px; padding: 20px; min-height: 540px; display: flex; flex-direction: column; }
.test-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.test-head h3 { margin: 5px 0 0; font-size: 20px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px var(--accent-soft); margin: 7px; }
.test-messages { flex: 1; margin: 22px 0; display: flex; flex-direction: column; gap: 10px; overflow: auto; min-height: 310px; max-height: 480px; }
.bubble { max-width: 88%; padding: 11px 13px; border-radius: 15px; font-size: 13px; line-height: 1.45; }
.bubble-ai { align-self: flex-start; background: var(--surface-strong); border-bottom-left-radius: 5px; }
.bubble-user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.test-compose { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.test-compose textarea { min-height: 46px; max-height: 100px; }

.conversation-layout {
  height: calc(100vh - 148px);
  min-height: 570px;
  display: grid;
  grid-template-columns: minmax(245px, .72fr) minmax(420px, 1.5fr) minmax(260px, .72fr);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.conversation-list-pane, .memory-pane { background: var(--surface); min-width: 0; }
.conversation-list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.conversation-search { padding: 12px; border-bottom: 1px solid var(--line); }
.conversation-search input { background: var(--surface-soft); border-color: transparent; min-height: 40px; }
.conversation-list { overflow: auto; flex: 1; }
.conversation-item {
  width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent;
  padding: 14px; display: grid; grid-template-columns: 38px 1fr; gap: 10px; text-align: left;
}
.conversation-item:hover, .conversation-item.active { background: var(--surface-soft); }
.conversation-copy { min-width: 0; }
.conversation-line { display: flex; justify-content: space-between; gap: 8px; }
.conversation-line strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.conversation-line time { color: var(--text-faint); font-size: 10px; white-space: nowrap; }
.conversation-preview { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--text-soft); font-size: 12px; }
.conversation-preview span:first-child { min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mode-label.ai { color: var(--accent); }
.mode-label.human { color: var(--warning); }

.chat-pane { min-width: 0; background: var(--surface-soft); position: relative; }
.chat-placeholder { height: 100%; display: grid; place-items: center; align-content: center; text-align: center; color: var(--text-soft); }
.chat-placeholder h3 { margin: 13px 0 4px; color: var(--text); }
.chat-placeholder p { margin: 0; }
.active-chat { height: 100%; display: flex; flex-direction: column; }
.chat-head {
  min-height: 68px; padding: 10px 14px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.chat-person { min-width: 0; display: grid; flex: 1; }
.chat-person strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-person span { color: var(--text-faint); font-size: 11px; }
.chat-actions { display: flex; align-items: center; gap: 8px; }
.chat-actions .button { min-height: 36px; font-size: 12px; }
.message-list {
  flex: 1; overflow: auto; padding: 24px clamp(14px, 3vw, 34px);
  display: flex; flex-direction: column; gap: 7px;
}
.message {
  max-width: min(78%, 600px);
  padding: 9px 11px 6px;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.message.inbound { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 4px; }
.message.outbound { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.message-meta { margin-top: 4px; color: var(--text-faint); font-size: 9px; text-align: right; }
.human-notice {
  padding: 9px 14px; border-top: 1px solid color-mix(in srgb, var(--warning) 25%, var(--line));
  background: var(--warning-soft); color: var(--warning); display: flex; gap: 8px; justify-content: center; font-size: 12px;
}

.human-compose {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}
.human-compose textarea { min-height: 42px; max-height: 120px; resize: none; }
.message-media {
  display: block;
  max-width: min(100%, 360px);
  max-height: 320px;
  border-radius: 10px;
  margin-bottom: 7px;
}
.message-media.audio { width: min(320px, 100%); }
.message-file {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--accent-ink);
  text-decoration: none;
  font-weight: 650;
  margin-bottom: 6px;
}
.message-file:hover { text-decoration: underline; }
.memory-pane { border-left: 1px solid var(--line); padding: 20px; overflow: auto; }
.memory-head h3 { margin: 5px 0 5px; font-size: 18px; }
.memory-head p { color: var(--text-soft); font-size: 12px; margin: 0 0 20px; }
.memory-pane form { display: grid; gap: 14px; }
.memory-meta { display: flex; justify-content: space-between; color: var(--text-faint); font-size: 10px; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(12,17,14,.58);
  backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: min(100%, 500px);
  max-height: 90vh;
  overflow: auto;
  border-radius: var(--radius-xl);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 30px 90px rgba(0,0,0,.28);
  padding: 30px;
  position: relative;
}
.modal h2 { margin: 7px 0 8px; font-size: 26px; letter-spacing: -.035em; }
.modal-close {
  position: absolute; right: 14px; top: 14px; width: 34px; height: 34px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  font-size: 21px; line-height: 1;
}
.qr-step { text-align: center; }
.qr-visual {
  width: 260px; height: 260px; margin: 24px auto 14px;
  border: 1px solid var(--line); border-radius: 18px; background: #fff;
  display: grid; place-items: center; overflow: hidden; padding: 12px;
}
.qr-visual img { width: 100%; height: 100%; object-fit: contain; }
.pairing-code {
  margin: 12px auto; padding: 12px 16px; border-radius: 12px;
  background: var(--surface-strong); font-size: 22px; letter-spacing: .14em; font-weight: 800;
}
.qr-status { display: flex; justify-content: center; align-items: center; gap: 8px; color: var(--text-soft); font-size: 13px; }
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--line-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; z-index: 200; right: 20px; bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px; border-radius: 12px;
  background: var(--text); color: var(--surface); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: .2s ease; font-size: 13px;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); color: #fff; }

.mobile-nav { display: none; }
.mobile-only { display: none; }

@media (max-width: 1180px) {
  :root { --sidebar: 210px; }
  .agent-layout { grid-template-columns: 1fr; }
  .test-panel { position: static; min-height: 460px; }
  .conversation-layout { grid-template-columns: 260px 1fr; }
  .memory-pane { display: none; }
}

@media (max-width: 860px) {
  body { padding-bottom: 68px; }
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .topbar { height: 70px; padding: 0 18px; }
  .page { padding: 8px 16px 28px; }
  .mobile-nav {
    position: fixed; z-index: 60; left: 0; right: 0; bottom: 0;
    height: 66px; padding-bottom: env(safe-area-inset-bottom);
    display: grid; grid-template-columns: repeat(4,1fr);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(16px); border-top: 1px solid var(--line);
  }
  .mobile-nav-item {
    border: 0; background: transparent; display: grid; place-items: center; align-content: center; gap: 2px;
    color: var(--text-faint);
  }
  .mobile-nav-item span { font-size: 18px; }
  .mobile-nav-item small { font-size: 10px; font-weight: 650; }
  .mobile-nav-item.active { color: var(--accent); }
  .mobile-only { display: inline-grid; }
  .hero-card { min-height: 280px; display: grid; align-content: end; }
  .hero-copy h1 { font-size: 42px; }
  .step-grid, .stats-grid { grid-template-columns: 1fr; }
  .flow-row { grid-template-columns: 1fr; gap: 9px; }
  .flow-line { width: 1px; height: 26px; }
  .section-intro { align-items: stretch; flex-direction: column; }
  .compact-select { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .agent-savebar { align-items: stretch; flex-direction: column; }
  .save-actions { justify-content: flex-end; }
  .conversation-layout { height: calc(100vh - 162px); min-height: 530px; grid-template-columns: 1fr; }
  .conversation-list-pane { border-right: 0; }
  .chat-pane { display: none; }
  .conversation-layout.chat-open .conversation-list-pane { display: none; }
  .conversation-layout.chat-open .chat-pane { display: block; }
  .chat-actions .status-pill { display: none; }
  .chat-actions .button { padding: 0 10px; }
}

@media (max-width: 560px) {
  .auth-card { padding: 26px 20px; }
  .hero-card { padding: 26px 22px; }
  .hero-copy h1 { font-size: 35px; }
  .hero-copy p { font-size: 15px; }
  .step-card { grid-template-columns: 34px 1fr; }
  .step-state { grid-column: 2; justify-self: start; }
  .agent-form, .test-panel { padding: 18px; }
  .agent-savebar { position: static; margin: 24px 0 0; }
  .toggle-row { align-items: flex-start; }
  .save-actions { flex-direction: column; align-items: stretch; }
  .modal { padding: 25px 18px; }
  .qr-visual { width: 230px; height: 230px; }
  .human-notice { flex-direction: column; text-align: center; }
}

/* Stage 11: compact agent summary, natural messages and topic triggers */
.agent-main-column {
  display: grid;
  gap: 18px;
  min-width: 0;
}
.agent-summary-card {
  padding: 24px;
}
.summary-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.summary-top h3 {
  margin: 5px 0 0;
  font-size: 24px;
  letter-spacing: -.035em;
}
.summary-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 18px 0;
}
.summary-chip {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
}
.summary-context {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  margin-bottom: 16px;
}
.summary-context strong {
  display: block;
  font-size: 13px;
  color: var(--accent-ink);
  margin-bottom: 5px;
}
.summary-context p {
  margin: 0;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.55;
}

.topics-card {
  padding: 24px;
}
.topics-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}
.topics-head h3 {
  margin: 5px 0 4px;
  font-size: 20px;
  letter-spacing: -.03em;
}
.topics-head p {
  margin: 0;
  color: var(--text-soft);
  font-size: 13px;
}
.topics-empty {
  margin-top: 18px;
  min-height: 110px;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  background: var(--surface-soft);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  text-align: center;
  color: var(--text-soft);
  padding: 18px;
}
.topics-empty strong {
  color: var(--text);
}
.topics-empty span {
  font-size: 12px;
}
.topics-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}
.topic-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  padding: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topic-card-copy {
  min-width: 0;
  flex: 1;
}
.topic-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topic-card-title strong {
  font-size: 14px;
}
.topic-meta {
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
  margin-top: 5px;
}
.topic-card p {
  color: var(--text-soft);
  font-size: 12px;
  margin: 7px 0 0;
}
.topic-card-actions {
  display: flex;
  gap: 7px;
  flex: none;
}
.topic-card-actions .button {
  min-height: 34px;
  padding: 0 11px;
  font-size: 11px;
}
.topic-editor {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
  display: grid;
  gap: 16px;
}
.topic-editor-head,
.trigger-head,
.topic-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topic-editor-head h4 {
  margin: 4px 0 0;
  font-size: 18px;
}
.toggle-inline {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  font-weight: 700;
}
.trigger-section {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: var(--surface-soft);
}
.trigger-head {
  align-items: flex-start;
}
.trigger-head strong {
  display: block;
  font-size: 13px;
}
.trigger-head small {
  display: block;
  max-width: 510px;
  color: var(--text-soft);
  margin-top: 3px;
}
.trigger-head .button {
  min-height: 34px;
  white-space: nowrap;
}
.trigger-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.trigger-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px 34px;
  gap: 7px;
  align-items: center;
}
.trigger-row input,
.trigger-row select {
  min-height: 40px;
}
.trigger-remove {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-soft);
  font-size: 20px;
  display: grid;
  place-items: center;
}
.trigger-remove:hover {
  background: var(--danger-soft);
  color: var(--danger);
}
.topic-actions {
  justify-content: flex-end;
}

@media (max-width: 860px) {
  .topics-head,
  .topic-card,
  .topic-editor-head,
  .trigger-head {
    align-items: stretch;
    flex-direction: column;
  }
  .topic-card-actions {
    width: 100%;
  }
  .topic-card-actions .button {
    flex: 1;
  }
  .trigger-row {
    grid-template-columns: minmax(0, 1fr) 105px 34px;
  }
}

@media (max-width: 520px) {
  .agent-summary-card,
  .topics-card {
    padding: 18px;
  }
  .summary-top {
    flex-direction: column;
  }
  .trigger-row {
    grid-template-columns: 1fr 88px 32px;
  }
  .trigger-row input,
  .trigger-row select {
    padding-left: 9px;
    padding-right: 9px;
    font-size: 12px;
  }
}
