:root {
  --bg: #10131a;
  --panel: #161a23;
  --panel-2: #1c212c;
  --line: #262c39;
  --text: #e6e9ef;
  --muted: #8a93a6;
  --accent: #5b9dff;
  --accent-dim: #2a4d80;
  --customer: #253048;
  --bot: #1d2530;
  --good: #4ec9a0;
  --warn: #e8b14a;
  --bad: #f0736a;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--good); }
.dot.bad { background: var(--bad); }
.topbar-meta { flex: 1; color: var(--muted); font-family: var(--mono); font-size: 12px; }
.topbar-actions { display: flex; gap: 8px; }
.api-base {
  width: 210px;
  font-family: var(--mono);
  font-size: 12px;
}

/* ---------- layout ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  gap: 1px;
  background: var(--line);
}
.panel { background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

/* ---------- controls ---------- */
input, select, textarea, button {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
}
input:focus, textarea:focus, select:focus { outline: 1px solid var(--accent-dim); border-color: var(--accent-dim); }
button { cursor: pointer; background: var(--accent-dim); border-color: transparent; }
button:hover:not(:disabled) { filter: brightness(1.2); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
button.ghost:hover:not(:disabled) { color: var(--text); }
button.danger:hover:not(:disabled) { color: var(--bad); border-color: var(--bad); }
button.icon { background: transparent; border: none; color: var(--muted); font-size: 15px; padding: 2px 6px; }

/* ---------- conversation list ---------- */
.new-form { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.new-form input { grid-column: 1 / -1; }
.conversation-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.conversation-list li {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.conversation-list li:hover { background: var(--panel-2); }
.conversation-list li.active { background: var(--panel-2); border-color: var(--accent-dim); }
.conv-handle { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-handle strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { font-size: 11px; color: var(--muted); font-family: var(--mono); margin-top: 2px; }
.conv-preview { font-size: 12px; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- chat ---------- */
.chat-head { align-items: flex-start; }
.chat-head-actions { display: flex; gap: 6px; }
#chat-title { font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--text); }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; padding: 9px 12px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; }
.msg.customer { align-self: flex-end; background: var(--customer); border-bottom-right-radius: 3px; }
.msg.bot { align-self: flex-start; background: var(--bot); border-bottom-left-radius: 3px; }
.msg .stamp { display: block; font-size: 10px; color: var(--muted); margin-top: 5px; font-family: var(--mono); }
/* Reply time, shaded against the turn budget. */
.msg .took.ok { color: var(--good); }
.msg .took.warn { color: var(--warn); }
.msg .took.bad { color: var(--bad); font-weight: 600; }
.msg .took.live { color: var(--muted); }
.msg.forward { border: 1px solid var(--warn); }
.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  margin-right: 6px;
}
.badge.forward { color: var(--warn); border-color: var(--warn); }
.badge.fallback { color: var(--bad); border-color: var(--bad); }
.empty { color: var(--muted); text-align: center; margin: auto; max-width: 260px; font-size: 13px; }

.composer { border-top: 1px solid var(--line); padding: 10px 14px 14px; }
.quick-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 11px; padding: 4px 8px; border-radius: 999px; }
.chip:hover:not(:disabled) { color: var(--text); border-style: solid; }
#composer-form { display: flex; gap: 8px; align-items: flex-end; }
#composer-input { flex: 1; resize: vertical; min-height: 44px; }

/* ---------- inspector ---------- */
.inspector-body { overflow-y: auto; padding: 12px 14px; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.insp-section h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.insp-section .value { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; }
.insp-section .value.mono { font-family: var(--mono); font-size: 11.5px; }
.insp-list { margin: 0; padding-left: 16px; }
.insp-list li { margin-bottom: 3px; }
.kv { display: flex; justify-content: space-between; gap: 10px; font-family: var(--mono); font-size: 11.5px; padding: 2px 0; }
.kv span:last-child { color: var(--muted); }
.bar { height: 5px; border-radius: 3px; background: var(--panel-2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--good); }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 10;
}
.toast.bad { border-color: var(--bad); color: var(--bad); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 220px 1fr; }
  .inspector { display: none; }
}
