:root {
  --bg: #0d1117; --panel: #151b23; --panel2: #1c2430; --line: #2a3441; --text: #e6edf3; --muted: #8b98a8;
  --accent: #4f8cff; --accent2: #2dd4bf; --ok: #3fb950; --warn: #d29922; --bad: #f85149;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
a { color: var(--accent); cursor: pointer; }
code { background: var(--panel2); padding: 2px 6px; border-radius: 4px; font-size: 13px; }
h1 { font-size: 22px; margin: 0 0 18px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 18px; }

.layout { display: flex; min-height: 100vh; }
.side { width: 220px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 18px 16px; font-size: 15px; }
.brand.big { font-size: 20px; padding: 0 0 4px; }
.logo { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border-radius: 8px; padding: 5px 7px; font-size: 12px; }
nav { display: flex; flex-direction: column; padding: 6px 8px; gap: 2px; flex: 1; }
nav a { color: var(--muted); padding: 8px 12px; border-radius: 6px; text-decoration: none; }
nav a:hover { background: var(--panel2); color: var(--text); }
nav a.active { background: var(--panel2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.side-foot { padding: 14px 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.live { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); display: inline-block; }
.live.ok i { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.live.bad i { background: var(--bad); }
main { margin-left: 220px; padding: 28px 32px; flex: 1; max-width: 1400px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.card.success { border-color: var(--ok); }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 18px; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.kpi .v { font-size: 24px; font-weight: 600; margin-top: 6px; }
.kpi .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .s { color: var(--muted); font-size: 12px; margin-top: 4px; }
@media (max-width: 1000px) { .grid.two { grid-template-columns: 1fr; } }

.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.head-row h1 { margin: 0; }
.inline { display: flex; gap: 8px; }
input, select, textarea { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 8px 14px; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--line); padding: 8px; }
.tbl td { border-bottom: 1px solid var(--line); padding: 9px 8px; vertical-align: middle; }
.tbl.small td { font-size: 12.5px; padding: 6px 8px; }
.tbl tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: var(--panel2); color: var(--muted); margin: 1px 2px 1px 0; }
.pill.ok { background: rgba(63,185,80,.15); color: var(--ok); }
.pill.bad { background: rgba(248,81,73,.15); color: var(--bad); }
.pill.warn { background: rgba(210,153,34,.15); color: var(--warn); }
.pill.acc { background: rgba(79,140,255,.15); color: var(--accent); }

.model-card { display: flex; flex-direction: column; gap: 10px; }
.model-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.model-card .name { font-weight: 600; font-size: 16px; word-break: break-all; }
.model-card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; font-size: 12px; }
.model-card .stats b { display: block; font-size: 15px; }
.model-card .btns { display: flex; gap: 6px; flex-wrap: wrap; }
.state { font-size: 12px; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.state i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.state.on i { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.bar { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }

.chart svg { width: 100%; height: 220px; display: block; }
.chart .empty { color: var(--muted); padding: 40px 0; text-align: center; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; background: var(--c); vertical-align: -1px; }

.sys-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.sys-row:last-child { border-bottom: none; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.form-grid label.wide, .form-grid .actions { grid-column: 1 / -1; }
.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; }
.actions { display: flex; gap: 10px; align-items: center; }
.keyval { font-family: Consolas, monospace; background: var(--bg); padding: 10px; border-radius: 6px; word-break: break-all; margin: 8px 0; border: 1px dashed var(--ok); }

.chat { display: flex; flex-direction: column; height: calc(100vh - 160px); }
.chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 12px; padding-bottom: 12px; }
.msg { max-width: 80%; padding: 10px 14px; border-radius: 10px; white-space: pre-wrap; line-height: 1.45; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.ai { align-self: flex-start; background: var(--panel2); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 6px; }
.chat-input { display: flex; gap: 10px; }
.chat-input textarea { flex: 1; resize: none; }

.steps li { margin: 10px 0; }
.logs { font-family: Consolas, monospace; font-size: 12px; white-space: pre-wrap; max-height: calc(100vh - 140px); overflow: auto; }

.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 360px; display: flex; flex-direction: column; gap: 12px; }
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.toast.bad { border-color: var(--bad); }
