:root {
  --bg: #f5f6f8; --panel: #fff; --line: #e4e7ec; --text: #1c2230; --muted: #6b7280;
  --accent: #4f46e5; --accent-soft: #eef0ff; --ok: #0f9960; --warn: #d97706; --bad: #dc2626;
  --user: #f1f3f7; --bot: #eef0ff; --op: #fff4e0; --radius: 12px;
  font-family: Inter, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
a { color: var(--accent); cursor: pointer; text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 16px; } h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .err { color: var(--bad); min-height: 18px; }
.layout { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side { background: #141827; color: #cfd3dc; padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 18px; color: #fff; padding: 0 8px; } .brand span { color: #8b8cf8; }
.brand.big { font-size: 28px; color: var(--text); }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a { color: #cfd3dc; padding: 9px 10px; border-radius: 8px; display: flex; justify-content: space-between; }
.side nav a:hover { background: #1f2438; } .side nav a.active { background: #2b3150; color: #fff; }
main { padding: 24px 28px; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } .g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 4px; } .stat .l { color: var(--muted); font-size: 12px; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font: inherit; color: var(--text); }
.btn:hover { border-color: #c7cbd4; } .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--bad); } .btn.ghost { background: transparent; color: inherit; border-color: #333a55; }
.btn.small { padding: 5px 10px; font-size: 12px; } .btn:disabled { opacity: .5; cursor: default; }
input, textarea, select { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; background: #fff; color: var(--text); }
textarea { resize: vertical; min-height: 80px; } input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .row > * { flex: 0 0 auto; } .grow { flex: 1 1 auto !important; }
table { width: 100%; border-collapse: collapse; } th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 500; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: #eef1f5; color: var(--muted); }
.pill.ok { background: #e3f6ee; color: var(--ok); } .pill.warn { background: #fff3e0; color: var(--warn); } .pill.bad { background: #fde8e8; color: var(--bad); }
.badge { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; }
.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 340px; display: flex; flex-direction: column; gap: 12px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: #141827; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 9; max-width: 420px; }
.chats { display: grid; grid-template-columns: 330px 1fr; gap: 14px; height: calc(100vh - 110px); }
.chat-list { overflow: auto; padding: 0; } .chat-item { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.chat-item:hover { background: #fafbfc; } .chat-item.active { background: var(--accent-soft); }
.chat-item .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.chat-item .p { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.chat-view { display: flex; flex-direction: column; padding: 0; min-width: 0; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; }
.msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.4; }
.msg.user { background: var(--user); align-self: flex-start; } .msg.assistant { background: var(--bot); align-self: flex-end; }
.msg.operator { background: var(--op); align-self: flex-end; } .msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.composer { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; } .composer textarea { min-height: 42px; height: 42px; }
.trace { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: #0f1320; color: #d7dbe6; border-radius: 10px; padding: 12px; overflow: auto; max-height: 520px; white-space: pre-wrap; }
.trace .k { color: #8b8cf8; } .trace .r { color: #9fd49f; }
.pg { display: grid; grid-template-columns: 1fr 420px; gap: 14px; height: calc(100vh - 110px); }
.bar { height: 90px; display: flex; align-items: flex-end; gap: 4px; } .bar div { background: var(--accent); flex: 1; border-radius: 3px 3px 0 0; min-height: 2px; }
.kb-doc { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; background: #c4c8d0; } .status-dot.on { background: var(--ok); }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; } .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .side nav { flex-direction: row; flex-wrap: wrap; } .g4 { grid-template-columns: repeat(2, 1fr); } .g2, .chats, .pg { grid-template-columns: 1fr; height: auto; }
  main { padding: 14px; } .msg { max-width: 90%; }
}
