:root {
  color-scheme: dark;
  --bg: #0d1117; --panel: #12181f; --panel2: #161d26; --line: #232c38;
  --text: #d7dee7; --muted: #8b98a8; --accent: #4c8dff; --ok: #3fb950;
  --warn: #d29922; --bad: #f85149;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.error { color: var(--bad); }

/* --- вход --- */
body.gate { display: grid; place-items: center; min-height: 100vh; }
.gate-card {
  width: min(26rem, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 2rem; display: grid; gap: .75rem;
}
.gate-card h1 { margin: 0; font-size: 1.4rem; }
.gate-card input, .gate-card button { font: inherit; padding: .7rem .85rem; border-radius: 9px; }
.gate-card input { background: var(--bg); border: 1px solid var(--line); color: var(--text); }
.gate-card button { background: var(--accent); border: 0; color: #fff; font-weight: 600; cursor: pointer; }

/* --- каркас --- */
.layout { display: grid; grid-template-columns: 15rem 1fr 23rem; min-height: 100vh; }
.side {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 1.1rem .8rem;
}
.brand { font-weight: 700; font-size: 1.1rem; padding: 0 .6rem 1rem; }
.brand span { display: block; font-weight: 400; font-size: .72rem; color: var(--muted); }
.side nav { display: grid; gap: .15rem; }
.side nav a {
  color: var(--text); padding: .55rem .6rem; border-radius: 9px; display: grid; gap: .1rem;
}
.side nav a span { color: var(--muted); font-size: .74rem; }
.side nav a:hover { background: var(--panel2); }
.side nav a.on { background: var(--panel2); box-shadow: inset 2px 0 0 var(--accent); }
.side-foot {
  margin-top: auto; padding: .6rem; display: flex; justify-content: space-between;
  align-items: center; font-size: .8rem; color: var(--muted);
}
.main { padding: 1.5rem 1.8rem 3rem; min-width: 0; }
.top { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.top h1 { font-size: 1.3rem; margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .8rem; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem;
}
.card .n { font-size: 1.7rem; font-weight: 700; }
.card .l { color: var(--muted); font-size: .82rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem 1.2rem; margin-top: 1rem; }
.panel h2 { font-size: 1rem; margin: 0 0 .6rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: .8rem; }
.empty { color: var(--muted); font-size: .9rem; padding: .6rem 0; }
.steps { margin: 0; padding-left: 1.1rem; color: var(--muted); font-size: .88rem; }
.steps li { margin: .2rem 0; }

/* --- панель агента --- */
.agent {
  background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.agent-head {
  display: flex; align-items: center; gap: .5rem; padding: .9rem 1rem;
  border-bottom: 1px solid var(--line); font-weight: 600;
}
.agent-head .dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--ok); }
.agent-head button {
  margin-left: auto; background: transparent; border: 1px solid var(--line);
  color: var(--muted); border-radius: 7px; width: 1.6rem; cursor: pointer;
}
.agent-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.agent.collapsed .agent-body { display: none; }
.agent-log { flex: 1; overflow-y: auto; padding: .9rem 1rem; display: grid; gap: .7rem; align-content: start; }
.msg { border-radius: 10px; padding: .55rem .7rem; white-space: pre-wrap; word-break: break-word; font-size: .89rem; }
.msg.user { background: #1b2a3d; justify-self: end; max-width: 92%; }
.msg.assistant { background: var(--panel2); }
.msg.sys { color: var(--muted); font-size: .8rem; background: transparent; padding: 0; }
.agent-form { display: flex; gap: .5rem; padding: .8rem; border-top: 1px solid var(--line); }
.agent-form textarea {
  flex: 1; resize: none; font: inherit; padding: .55rem .7rem; border-radius: 9px;
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
}
.agent-form button {
  font: inherit; padding: 0 1rem; border-radius: 9px; border: 0; background: var(--accent);
  color: #fff; font-weight: 600; cursor: pointer;
}
.agent-form button[disabled] { opacity: .5; cursor: default; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 12rem 1fr; }
  .agent { position: fixed; right: 0; top: 0; width: min(23rem, 100vw); z-index: 10; }
  .agent.collapsed { height: auto; }
}
