:root {
  --bg: #f4f6f2;
  --surface: #ffffff;
  --ink: #15201b;
  --muted: #6c7771;
  --line: #e2e7e2;
  --green: #1e8f5a;
  --green-dark: #147346;
  --soft: #e9f6ef;
  --danger: #b74343;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top, #e4f3e9, var(--bg) 44%); }
.login-card { width: min(420px, 100%); background: var(--surface); padding: 42px; border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 24px 70px rgba(25, 61, 42, .11); }
.brand-mark { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; background: var(--ink); color: white; font-weight: 800; font-size: 25px; margin-bottom: 30px; }
.brand-mark.small { width: 34px; height: 34px; border-radius: 10px; font-size: 17px; margin: 0; }
h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: 30px; }
h2 { margin-bottom: 0; font-size: 27px; }
h3 { margin-bottom: 18px; }
.muted, small { color: var(--muted); }
.eyebrow { color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .12em; margin-bottom: 7px; }
label { display: grid; gap: 7px; color: #465049; font-size: 13px; font-weight: 650; margin-top: 20px; }
input, textarea, select { border: 1px solid var(--line); border-radius: 11px; padding: 12px 13px; background: #fbfcfb; color: var(--ink); outline: none; transition: .2s; }
input:focus, textarea:focus, select:focus { border-color: #7bc49d; box-shadow: 0 0 0 3px rgba(30, 143, 90, .1); }
textarea { resize: vertical; line-height: 1.5; }
.primary, .secondary, .send-button { border: 0; border-radius: 11px; padding: 12px 17px; font-weight: 750; }
.primary { width: 100%; margin-top: 24px; background: var(--green); color: white; }
.primary:hover, .send-button:hover { background: var(--green-dark); }
.secondary { background: #eef1ee; color: var(--ink); }
.error { color: var(--danger); font-size: 13px; margin: 12px 0 0; }
.success { color: var(--green); font-size: 13px; margin: 12px 0 0; }
.app { min-height: 100vh; display: grid; grid-template-columns: 230px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 16px; background: #101915; color: white; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 11px; font-size: 19px; font-weight: 800; padding: 0 9px 28px; }
.brand .brand-mark { background: var(--green); }
nav { display: grid; gap: 5px; }
.nav-item { border: 0; background: transparent; color: #aeb8b2; text-align: left; padding: 12px 13px; border-radius: 10px; font-weight: 650; display: flex; justify-content: space-between; }
.nav-item:hover, .nav-item.active { color: white; background: rgba(255,255,255,.08); }
.badge { background: var(--green); color: white; padding: 1px 7px; border-radius: 99px; font-size: 11px; }
.sidebar-bottom { margin-top: auto; border-top: 1px solid rgba(255,255,255,.1); padding: 18px 9px 0; display: grid; gap: 14px; }
.connection { display: flex; align-items: center; gap: 8px; color: #c1cbc5; font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #d09a3b; }
.dot.ready { background: #42ca83; box-shadow: 0 0 0 4px rgba(66,202,131,.12); }
.link-button { border: 0; color: #8f9b94; background: transparent; text-align: left; padding: 0; font-size: 12px; }
main { min-width: 0; padding: 30px 38px 50px; }
header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.bot-toggle { margin: 0; display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 10px 12px 10px 15px; }
.bot-toggle span { display: grid; font-size: 12px; }
.bot-toggle small { font-size: 10px; }
.bot-toggle input, .mini-toggle input { display: none; }
.bot-toggle i { width: 42px; height: 24px; background: #ccd3ce; border-radius: 99px; position: relative; transition: .2s; }
.bot-toggle i::after { content: ""; position: absolute; width: 18px; height: 18px; top: 3px; left: 3px; background: white; border-radius: 50%; transition: .2s; box-shadow: 0 2px 6px rgba(0,0,0,.18); }
.bot-toggle input:checked + i { background: var(--green); }
.bot-toggle input:checked + i::after { transform: translateX(18px); }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }
.metrics article, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.metrics article { display: grid; }
.metrics span { color: var(--muted); font-size: 12px; font-weight: 700; }
.metrics strong { font-size: 34px; margin: 9px 0 4px; }
.metrics small { font-size: 11px; }
.grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
.panel-title { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.pill { border-radius: 99px; background: #fff5dc; color: #896516; padding: 6px 10px; font-size: 11px; font-weight: 750; }
.pill.ready { background: var(--soft); color: var(--green-dark); }
.qr-area, .ready-state { display: flex; align-items: center; gap: 22px; padding: 18px 0; }
.qr-area img { width: 180px; border: 1px solid var(--line); border-radius: 12px; }
.qr-area p, .ready-state p { color: var(--muted); line-height: 1.5; }
.success-icon { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 50%; background: var(--soft); color: var(--green); font-size: 26px; font-weight: 900; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 20px; }
.steps li { display: flex; gap: 13px; }
.steps li > span { flex: 0 0 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--soft); color: var(--green); font-weight: 800; }
.steps p { color: var(--muted); font-size: 12px; margin: 3px 0 0; }
.conversation-layout { height: calc(100vh - 132px); grid-template-columns: 330px 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.conversation-layout:not(.hidden) { display: grid; }
.conversation-list-panel { border-right: 1px solid var(--line); min-width: 0; min-height: 0; }
.search { padding: 14px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; }
.conversation-list { height: calc(100% - 70px); min-height: 0; overflow-y: auto; scrollbar-gutter: stable; }
.conversation-item { width: 100%; border: 0; border-bottom: 1px solid #eef1ee; background: white; padding: 15px; text-align: left; display: grid; grid-template-columns: 42px 1fr auto; gap: 11px; }
.conversation-item:hover, .conversation-item.active { background: #f3f8f5; }
.avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: #e5eee9; color: #2f5944; font-weight: 800; }
.conversation-meta { min-width: 0; }
.conversation-meta strong, .conversation-meta span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-meta span { color: var(--muted); font-size: 12px; margin-top: 5px; }
.conversation-side { text-align: right; font-size: 10px; color: var(--muted); }
.conversation-side b { display: inline-grid; place-items: center; min-width: 19px; height: 19px; background: var(--green); color: white; border-radius: 99px; margin-top: 7px; }
.chat-panel { min-width: 0; min-height: 0; position: relative; overflow: hidden; }
.chat-panel.empty { display: grid; place-items: center; text-align: center; color: var(--muted); }
.empty-icon { width: 58px; height: 58px; display: grid; place-items: center; background: var(--soft); color: var(--green); border-radius: 18px; margin: 0 auto 15px; font-size: 22px; }
#activeChat { height: 100%; min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.chat-header { display: flex; justify-content: space-between; gap: 18px; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.chat-header h3 { margin: 0 0 3px; }
.chat-header p { color: var(--muted); font-size: 12px; margin: 0; }
.chat-actions { display: flex; align-items: center; gap: 12px; }
.chat-actions select { padding: 8px 10px; }
.mini-toggle { margin: 0; display: flex; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; }
.mini-toggle:has(input:checked) { border-color: #e8b7b7; background: #fff4f4; color: var(--danger); }
.human-notice { background: #fff5dc; color: #795b17; padding: 10px 18px; font-size: 12px; }
.human-notice button { border: 0; background: transparent; color: var(--green-dark); font-weight: 750; }
.messages { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: 22px; background: #f7f8f6; display: flex; flex-direction: column; gap: 9px; }
.messages::-webkit-scrollbar, .conversation-list::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb, .conversation-list::-webkit-scrollbar-thumb { background: #bac5be; border: 2px solid transparent; border-radius: 99px; background-clip: padding-box; }
.messages::-webkit-scrollbar-track, .conversation-list::-webkit-scrollbar-track { background: transparent; }
.message { max-width: min(72%, 620px); border-radius: 13px; padding: 10px 12px; background: white; border: 1px solid var(--line); box-shadow: 0 2px 4px rgba(0,0,0,.02); }
.message.out { align-self: flex-end; background: #dcf4e5; border-color: #c6e9d4; }
.message p { margin: 0; white-space: pre-wrap; line-height: 1.45; font-size: 13px; }
.message time { display: block; color: #839087; font-size: 9px; text-align: right; margin-top: 5px; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 13px; border-top: 1px solid var(--line); }
.composer textarea { resize: none; min-height: 44px; max-height: 120px; }
.send-button { background: var(--green); color: white; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.settings-grid .panel:last-child { grid-column: 1 / -1; }
.settings-grid .wide { grid-column: 1 / -1; }
.json-editor { min-height: 300px; font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 12px; tab-size: 2; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.response-controls { grid-template-columns: 1fr 1fr 1fr; }
.check { display: flex; align-items: center; gap: 9px; }
.check input { width: 17px; height: 17px; accent-color: var(--green); }
.toast { position: fixed; right: 24px; bottom: 24px; background: var(--ink); color: white; padding: 12px 16px; border-radius: 10px; font-size: 12px; transform: translateY(90px); opacity: 0; transition: .25s; }
.toast.show { transform: translateY(0); opacity: 1; }
@media (max-width: 900px) {
  .app { grid-template-columns: 74px 1fr; }
  .sidebar { padding: 18px 10px; }
  .brand > span:last-child, .nav-item { font-size: 0; }
  .nav-item { height: 42px; }
  .nav-item::first-letter { font-size: 16px; }
  .connection span:last-child, .link-button { display: none; }
  main { padding: 24px 18px; }
  .grid, .settings-grid { grid-template-columns: 1fr; }
  .response-controls { grid-template-columns: 1fr; }
  .settings-grid .panel:last-child { grid-column: auto; }
  .conversation-layout { grid-template-columns: 270px 1fr; }
}
@media (max-width: 680px) {
  .app { display: block; }
  .sidebar { position: fixed; z-index: 10; bottom: 0; top: auto; width: 100%; height: 64px; padding: 8px; flex-direction: row; align-items: center; }
  .brand, .sidebar-bottom { display: none; }
  nav { width: 100%; grid-template-columns: repeat(3, 1fr); }
  .nav-item { font-size: 11px; text-align: center; justify-content: center; }
  .nav-item::first-letter { font-size: inherit; }
  main { padding: 20px 14px 82px; }
  header { align-items: start; }
  .bot-toggle span { display: none; }
  .metrics { grid-template-columns: 1fr; }
  .conversation-layout:not(.hidden) { display: block; height: auto; }
  .conversation-list-panel { height: 280px; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat-panel { height: 560px; }
  .qr-area { flex-direction: column; align-items: start; }
  .chat-header { align-items: start; }
  .chat-actions { flex-direction: column; align-items: stretch; }
}
