:root {
  --bg: #f4f5f7; --panel: #fff; --line: #e3e5ea; --text: #1d2129; --muted: #6b7280;
  --accent: #128c7e; --accent2: #075e54; --warn: #b45309; --warnbg: #fff7e6; --err: #b91c1c;
  --in: #fff; --out: #dcf8c6; --run: #2563eb;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; padding: 7px 12px; background: var(--accent); color: #fff; }
button:hover { background: var(--accent2); }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button.danger { background: #fff; color: var(--err); border: 1px solid #f1c4c4; }
button.link { background: none; color: var(--muted); padding: 8px; }
input, textarea, select { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #fff; color: var(--text); width: 100%; }
textarea { resize: vertical; }
.err { color: var(--err); }

.login { display: grid; place-items: center; height: 100vh; }
.login form { background: var(--panel); padding: 32px; border-radius: 14px; width: 320px; display: grid; gap: 12px; box-shadow: 0 8px 30px #0001; }
.login h1 { margin: 0 0 4px; font-size: 20px; }

.app { display: grid; grid-template-columns: 300px 1fr; height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.status { display: flex; gap: 6px; padding: 12px; flex-wrap: wrap; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 99px; background: #eee; color: var(--muted); }
.pill.ok { background: #dcfce7; color: #166534; }
.pill.bad { background: #fee2e2; color: var(--err); }
.qr { padding: 0 12px 12px; text-align: center; font-size: 12px; color: var(--muted); }
.qr img { width: 100%; max-width: 260px; }
.search { margin: 0 12px; width: calc(100% - 24px); }
.filters { display: flex; gap: 4px; padding: 8px 12px; }
.filters button { background: #f1f2f4; color: var(--muted); padding: 4px 9px; font-size: 12px; }
.filters button.on { background: var(--accent); color: #fff; }
.contacts { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.contacts li { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.contacts li:hover, .contacts li.on { background: #f0faf8; }
.contacts .n { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contacts .p { font-size: 12px; color: var(--accent2); }
.contacts .p.none { color: var(--warn); }
.contacts .t { font-size: 12px; color: var(--muted); grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; gap: 4px; align-items: start; }
.b { font-size: 11px; border-radius: 99px; padding: 1px 7px; background: var(--accent); color: #fff; }
.b.w { background: var(--warn); }
.b.r { background: var(--run); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 6px 8px 0; background: #e9ebef; overflow-x: auto; flex-shrink: 0; }
.tab { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 8px 8px 0 0; background: #dfe2e7; cursor: pointer; white-space: nowrap; font-size: 13px; }
.tab.on { background: var(--bg); font-weight: 600; }
.tab .x { color: var(--muted); padding: 0 2px; }
.tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.empty { margin: auto; color: var(--muted); }

.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.head .cname { font-weight: 700; font-size: 16px; border: 0; padding: 2px 4px; width: auto; }
.head .phone { color: var(--muted); margin-left: 6px; }
.bind { display: flex; gap: 6px; }
.bind select { width: 240px; }
.cols { flex: 1; display: grid; grid-template-columns: minmax(320px, 1fr) minmax(380px, 1.1fr); min-height: 0; }
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: #ece5dd; }
.msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 82%; padding: 6px 9px 4px; border-radius: 9px; background: var(--in); box-shadow: 0 1px 1px #0001; white-space: pre-wrap; word-wrap: break-word; }
.msg.out { align-self: flex-end; background: var(--out); }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; }
.msg img { max-width: 100%; max-height: 260px; border-radius: 6px; display: block; }
.msg audio, .msg video { max-width: 100%; }
.msg .tr { font-size: 13px; color: #374151; border-left: 3px solid var(--accent); padding-left: 6px; margin-top: 4px; }
.msg .req { font-size: 10px; color: var(--accent2); }
.composer { display: flex; gap: 8px; padding: 10px; background: #f0f0f0; }
.composer button { align-self: end; }

.work { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.card summary, .cardh { font-weight: 600; cursor: pointer; }
.cardh { cursor: default; margin-bottom: 8px; }
.pform { display: grid; gap: 8px; margin-top: 10px; }
.pform label { font-size: 12px; color: var(--muted); display: grid; gap: 3px; }
.pform .chk { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 13px; }
.pform .chk input { width: auto; }
.cmd { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: #f3f4f6; padding: 6px 8px; border-radius: 6px; display: flex; justify-content: space-between; gap: 6px; align-items: center; word-break: break-all; }
.manual { display: grid; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row select { width: auto; }

.req { border-left: 4px solid var(--line); }
.req.pending, .req.unbound { border-left-color: var(--warn); background: var(--warnbg); }
.req.running, .req.queued, .req.triage { border-left-color: var(--run); }
.req.done { border-left-color: var(--accent); }
.req.failed { border-left-color: var(--err); }
.req .top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.req .sum { font-weight: 600; margin-bottom: 6px; }
.req .risk { color: var(--warn); font-size: 13px; margin-bottom: 6px; }
.req textarea { margin: 4px 0; font-size: 13px; }
.req .result { white-space: pre-wrap; font-size: 13px; background: #f9fafb; border-radius: 8px; padding: 8px; max-height: 240px; overflow: auto; }
.req .logs { font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; white-space: pre-wrap; max-height: 260px; overflow: auto; background: #111827; color: #d1d5db; border-radius: 8px; padding: 8px; margin-top: 6px; }
.req .logs .tool { color: #93c5fd; }
.req .logs .error { color: #fca5a5; }
.req .logs .info { color: #9ca3af; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: #eef2ff; color: #3730a3; margin-right: 4px; }
.tag.complex { background: #fff1e6; color: var(--warn); }
.tag.simple { background: #dcfce7; color: #166534; }
.st { font-weight: 600; }

@media (max-width: 1000px) {
  .app { grid-template-columns: 1fr; }
  .side { max-height: 40vh; }
  .cols { grid-template-columns: 1fr; }
  .chat { min-height: 60vh; }
}
