/* ADRules — Vercel/shadcn light: #fafafa, Inter, shadow-as-border, black CTA */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #171717;
  --text-2: #666;
  --text-3: #999;
  --line: rgba(0,0,0,.08);
  --blue: #0068d6;
  --blue-bg: #ebf5ff;
  --green: #1a7f37;
  --green-bg: #e8f5ec;
  --red: #cf222e;
  --red-bg: #ffebe9;
  --amber: #9a6700;
  --amber-bg: #fff8c5;
  --shadow-1: 0 0 0 1px var(--line);
  --shadow-2: 0 0 0 1px var(--line), 0 2px 2px rgba(0,0,0,.04), 0 8px 8px -8px rgba(0,0,0,.04);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: Inter, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-feature-settings: "cv02","cv03";
}
h2 { font-size: 16px; font-weight: 600; letter-spacing: -0.02em; margin: 22px 0 10px; }
h2:first-child { margin-top: 0; }
.hint { color: var(--text-3); font-size: 12px; margin-top: 8px; }

/* ── topbar ── */
.topbar {
  height: 52px; background: var(--surface);
  box-shadow: var(--shadow-1);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 600; letter-spacing: -0.02em; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--blue); }
.brand-sub { color: var(--text-3); font-weight: 400; font-size: 12px; margin-left: 6px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* ── layout ── */
.layout { display: grid; grid-template-columns: 200px 1fr 320px; min-height: calc(100vh - 52px); }
.sidebar {
  background: var(--surface); box-shadow: var(--shadow-1);
  padding: 14px 10px; display: flex; flex-direction: column; gap: 2px;
}
.nav-item {
  border: none; background: none; text-align: left; padding: 8px 12px;
  border-radius: 6px; font: inherit; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--bg); color: var(--text); font-weight: 500; box-shadow: var(--shadow-1); }
.nav-badge {
  background: var(--blue-bg); color: var(--blue); font-size: 11px;
  padding: 1px 7px; border-radius: 999px; font-weight: 500;
}
.sidebar-foot { margin-top: auto; color: var(--text-3); font-size: 11px; padding: 12px; }

.content { padding: 20px 24px; overflow-x: auto; }
.view { display: none; }
.view.active { display: block; }

/* ── pills / buttons ── */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--bg); box-shadow: var(--shadow-1); color: var(--text-2);
}
.pill-green { background: var(--green-bg); color: var(--green); box-shadow: none; }
.pill-red { background: var(--red-bg); color: var(--red); box-shadow: none; }
.pill-amber { background: var(--amber-bg); color: var(--amber); box-shadow: none; }
.pill-blue { background: var(--blue-bg); color: var(--blue); box-shadow: none; }

.btn {
  font: inherit; font-weight: 500; padding: 6px 14px; border-radius: 6px;
  border: none; background: var(--surface); box-shadow: var(--shadow-1);
  cursor: pointer; color: var(--text);
}
.btn:hover { box-shadow: var(--shadow-2); }
.btn-primary { background: var(--text); color: #fff; box-shadow: none; }
.btn-primary:hover { background: #000; }
.btn-sm { padding: 3px 10px; font-size: 12px; }

/* ── KPI cards ── */
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi {
  background: var(--surface); border-radius: 8px; padding: 14px 16px;
  box-shadow: var(--shadow-1);
}
.kpi .k-label { color: var(--text-3); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .k-value { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .k-sub { color: var(--text-2); font-size: 12px; margin-top: 2px; }

/* ── panels / rule sets ── */
.panel { background: var(--surface); border-radius: 8px; padding: 16px; box-shadow: var(--shadow-1); }
.rs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.rs-card {
  background: var(--surface); border-radius: 8px; padding: 14px 16px;
  box-shadow: var(--shadow-1); cursor: pointer; transition: box-shadow .12s;
}
.rs-card:hover { box-shadow: var(--shadow-2); }
.rs-card h3 { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.rs-card .rs-meta { color: var(--text-3); font-size: 12px; margin: 6px 0 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.rs-phases { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.phase-chip {
  font-size: 11px; padding: 2px 8px; border-radius: 4px; background: var(--bg);
  box-shadow: var(--shadow-1); color: var(--text-2); font-variant-numeric: tabular-nums;
}

/* ── sim panel ── */
.sim-panel .sim-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sim-panel select, .sim-panel input {
  font: inherit; padding: 6px 10px; border-radius: 6px; border: none;
  box-shadow: var(--shadow-1); background: var(--surface); color: var(--text);
}
.sim-panel input[type=number] { width: 74px; }
.sep { width: 16px; }

/* ── tables ── */
.table {
  width: 100%; border-collapse: collapse; background: var(--surface);
  border-radius: 8px; overflow: hidden; box-shadow: var(--shadow-1);
  font-variant-numeric: tabular-nums;
}
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3); font-weight: 500; padding: 10px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg); }
.td-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.status-active { color: var(--green); }
.status-trashed { color: var(--red); }
.status-paused_rule { color: var(--amber); }
.status-paused_night { color: var(--text-3); }
.roi-good { color: var(--green); font-weight: 600; }
.roi-mid { color: var(--amber); font-weight: 600; }
.roi-bad { color: var(--red); font-weight: 600; }

/* ── filters ── */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-pill {
  font: inherit; font-size: 12px; padding: 4px 12px; border-radius: 999px;
  border: none; background: var(--surface); box-shadow: var(--shadow-1);
  cursor: pointer; color: var(--text-2);
}
.filter-pill.active { background: var(--text); color: #fff; box-shadow: none; }

/* ── templates ── */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.tpl-card { background: var(--surface); border-radius: 8px; padding: 16px; box-shadow: var(--shadow-1); display: flex; flex-direction: column; }
.tpl-card h3 { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 2px; }
.tpl-code { font-size: 11px; color: var(--text-3); font-family: ui-monospace, monospace; }
.tpl-desc { color: var(--text-2); font-size: 12.5px; line-height: 1.45; margin: 8px 0 12px; flex: 1; }
.tpl-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }

/* ── rules detail ── */
.rule-row { display: flex; align-items: flex-start; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.rule-row:last-child { border-bottom: none; }
.rule-kind {
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 7px; border-radius: 4px; font-weight: 600; flex-shrink: 0; margin-top: 2px;
}
.kind-phase { background: var(--blue-bg); color: var(--blue); }
.kind-global { background: var(--amber-bg); color: var(--amber); }
.kind-guardrail { background: var(--red-bg); color: var(--red); }
.rule-body { flex: 1; min-width: 0; }
.rule-name { font-weight: 500; }
.rule-cond { color: var(--text-2); font-size: 12.5px; margin-top: 2px; font-family: ui-monospace, monospace; }
.rule-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.switch { position: relative; width: 32px; height: 18px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: #ddd; border-radius: 999px; cursor: pointer; transition: .15s;
}
.switch .track:before {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch input:checked + .track { background: var(--text); }
.switch input:checked + .track:before { transform: translateX(14px); }

/* ── chat ── */
.chat {
  background: var(--surface); box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; height: calc(100vh - 52px);
  position: sticky; top: 52px;
}
.chat-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.chat-title { font-weight: 600; letter-spacing: -0.01em; }
.chat-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg {
  max-width: 92%; padding: 9px 12px; border-radius: 10px; font-size: 13px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.msg.user { align-self: flex-end; background: var(--text); color: #fff; border-bottom-right-radius: 3px; }
.msg.bot { align-self: flex-start; background: var(--bg); box-shadow: var(--shadow-1); border-bottom-left-radius: 3px; }
.msg.bot .mono { font-family: ui-monospace, monospace; font-size: 12px; }
.chat-input-row { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.chat-input-row input {
  flex: 1; font: inherit; padding: 8px 12px; border-radius: 6px; border: none;
  box-shadow: var(--shadow-1); background: var(--bg);
}
.chat-input-row input:focus { outline: none; box-shadow: 0 0 0 2px var(--text); }

/* ── modal ── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--surface); border-radius: 10px; padding: 22px; width: 320px; box-shadow: var(--shadow-2); }
.modal h3 { font-size: 15px; font-weight: 600; margin-bottom: 14px; letter-spacing: -0.01em; }
.modal label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); margin-bottom: 12px; }
.modal select, .modal input { font: inherit; padding: 7px 10px; border-radius: 6px; border: none; box-shadow: var(--shadow-1); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 170px 1fr; }
  .chat { position: fixed; right: 0; top: 52px; width: 320px; z-index: 30; transform: translateX(0); }
}

/* ═══ экран «Движок · дерево» (раунд 3) ═══ */
.engine-grid{display:grid;grid-template-columns:minmax(340px,460px) 1fr;gap:14px;align-items:start}
.engine-right{display:flex;flex-direction:column;gap:14px}
.engine-panel{max-height:78vh;overflow:auto}
.tree-box{font-size:12.5px;line-height:1.5}
.tree-node{border-left:1px solid var(--line);padding:3px 0 3px 8px}
.tree-node .tn-ico{display:inline-block;width:18px;color:var(--gold)}
.tree-node .tn-name{font-weight:600;color:var(--ink)}
.tree-node .tn-extra{color:var(--text-3);margin-left:8px;font-size:11.5px}
.t-set>.tn-name{font-size:14px}
.t-phase>.tn-name{color:var(--gold)}
.t-guardrail>.tn-name{color:#e08a4a}
.t-rule>.tn-name{color:#8fb7e8}
.t-cond>.tn-extra{font-family:ui-monospace,Menlo,monospace}
.table-scroll{max-height:340px;overflow:auto}
@media(max-width:1100px){.engine-grid{grid-template-columns:1fr}}
