/* Automation Studio — standalone frontend */
:root {
  --bg: #0d1117;
  --bg2: #131a23;
  --panel: #161e29;
  --panel2: #1b2530;
  --border: #263241;
  --border2: #33445a;
  --text: #dce4ee;
  --muted: #8296ac;
  --accent: #4f8ff7;
  --accent2: #6aa5ff;
  --green: #34c98e;
  --red: #f0616d;
  --orange: #f2a854;
  --purple: #a78bfa;
  --radius: 10px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 232px; min-width: 232px; background: var(--bg2);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.brand-icon {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #7c3aed); font-size: 20px;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; color: var(--muted);
  text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 500;
}
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active { background: rgba(79,143,247,.14); color: var(--accent2); }
.nav-ic { width: 18px; text-align: center; }
.badge {
  margin-left: auto; background: var(--red); color: #fff; font-size: 11px;
  border-radius: 10px; padding: 1px 7px; font-weight: 700;
}
.hidden { display: none !important; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); }
.conn-status { font-size: 12px; }
.conn-ok { color: var(--green); } .conn-bad { color: var(--red); } .conn-unknown { color: var(--muted); }

/* ---------- main ---------- */
.main { flex: 1; overflow: auto; padding: 24px 28px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 21px; font-weight: 700; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ---------- generic ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; background: var(--panel2);
  color: var(--text); border: 1px solid var(--border2); padding: 8px 14px;
  border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  background: #0f1620; color: var(--text); border: 1px solid var(--border2);
  border-radius: 7px; padding: 8px 10px; font-size: 13px; font-family: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
label.f-label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.checkbox-row input { width: auto; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px){ .grid.cols-4 { grid-template-columns: repeat(2, 1fr);} }

.stat-num { font-size: 28px; font-weight: 800; margin-top: 4px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat-accent { color: var(--accent2); } .stat-red { color: var(--red); }
.stat-green { color: var(--green); } .stat-orange { color: var(--orange); }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:hover td { background: rgba(79,143,247,.05); }
.tbl tr.clickable { cursor: pointer; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.pill.sev-info { background: rgba(79,143,247,.16); color: var(--accent2); }
.pill.sev-warning { background: rgba(242,168,84,.16); color: var(--orange); }
.pill.sev-critical { background: rgba(240,97,109,.16); color: var(--red); }
.pill.st-open { background: rgba(240,97,109,.16); color: var(--red); }
.pill.st-acknowledged { background: rgba(242,168,84,.16); color: var(--orange); }
.pill.st-resolved { background: rgba(52,201,142,.16); color: var(--green); }
.pill.st-on { background: rgba(52,201,142,.16); color: var(--green); }
.pill.st-off { background: rgba(130,150,172,.16); color: var(--muted); }
.pill.src { background: rgba(167,139,250,.15); color: var(--purple); }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }

.empty { text-align: center; color: var(--muted); padding: 48px 0; }
.empty .big { font-size: 40px; margin-bottom: 10px; }

/* toggle switch */
.switch { position: relative; width: 36px; height: 20px; display: inline-block; cursor: pointer; }
.switch input { display: none; }
.switch .track { position: absolute; inset: 0; border-radius: 20px; background: var(--border2); transition: .15s; }
.switch .thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track + .thumb { left: 18px; }

/* toast */
#toast-holder { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast {
  background: var(--panel2); border: 1px solid var(--border2); border-left: 4px solid var(--accent);
  padding: 11px 16px; border-radius: 8px; min-width: 240px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: slide-in .18s ease;
}
.toast.err { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } }

/* drawer + modal */
.drawer-mask { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 560px; max-width: 92vw;
  background: var(--bg2); border-left: 1px solid var(--border); z-index: 201;
  display: flex; flex-direction: column; animation: drawer-in .18s ease;
}
@keyframes drawer-in { from { transform: translateX(60px); opacity: .4; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-body { flex: 1; overflow: auto; padding: 18px 20px; }
.drawer-title { font-weight: 700; font-size: 16px; }

/* ============================ RULE EDITOR ============================ */
.editor-layout { display: flex; flex-direction: column; height: calc(100vh - 48px); }
.editor-head { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.editor-head input.rule-name { width: 300px; font-size: 15px; font-weight: 700; }
.editor-main { flex: 1; display: flex; gap: 14px; min-height: 0; }

/* canvas */
.canvas-wrap {
  flex: 1; position: relative; border: 1px solid var(--border); border-radius: var(--radius);
  background:
    radial-gradient(circle, #1c2635 1px, transparent 1px) 0 0 / 22px 22px,
    var(--bg2);
  overflow: hidden; min-width: 0;
}
.canvas-inner { position: absolute; inset: 0; }
svg.edges { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
svg.edges path { stroke: var(--border2); stroke-width: 2; fill: none; }
svg.edges path.active-edge { stroke: var(--accent); }

.fnode {
  position: absolute; width: 220px; background: var(--panel); border: 1px solid var(--border2);
  border-radius: 12px; cursor: grab; user-select: none; box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
.fnode:active { cursor: grabbing; }
.fnode.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(79,143,247,.35); }
.fnode-head { display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.fnode-ic { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: 14px; flex-shrink: 0; }
.fnode.trigger .fnode-ic { background: rgba(79,143,247,.18); }
.fnode.cond .fnode-ic { background: rgba(167,139,250,.18); }
.fnode.action .fnode-ic { background: rgba(52,201,142,.18); }
.fnode-kind { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
.fnode-title { font-size: 13px; font-weight: 600; line-height: 1.25; }
.fnode-body { padding: 8px 12px; color: var(--muted); font-size: 12px; min-height: 30px; }
.fnode-del {
  position: absolute; top: -9px; right: -9px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--red); color: #fff; border: none; cursor: pointer; font-size: 11px;
  display: none; line-height: 1;
}
.fnode:hover .fnode-del { display: block; }
.canvas-hint { position: absolute; bottom: 10px; left: 12px; color: var(--muted); font-size: 11px; }
.add-action-fab { position: absolute; top: 12px; right: 12px; z-index: 5; }

/* inspector panel */
.inspector {
  width: 380px; min-width: 380px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); overflow: auto; padding: 16px;
}
.inspector h3 { font-size: 14px; margin-bottom: 4px; }
.inspector .sub { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.divider { border-top: 1px solid var(--border); margin: 14px 0; }

/* condition builder */
.cond-group { border: 1px solid var(--border2); border-radius: 8px; padding: 10px; margin-top: 8px; background: rgba(0,0,0,.12); }
.cond-group-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.cond-group-head select { width: auto; }
.cond-row { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.cond-row select.c-field { flex: 2.2; min-width: 0; }
.cond-row select.c-op { flex: 1.6; min-width: 0; }
.cond-row .c-val { flex: 1.8; min-width: 0; }
.cond-row .rm { flex-shrink: 0; }
.cond-add-row { margin-top: 8px; display: flex; gap: 8px; }

/* template variable chips */
.var-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.var-chip {
  font-family: var(--mono); font-size: 11px; background: rgba(79,143,247,.12);
  color: var(--accent2); border-radius: 5px; padding: 2px 7px; cursor: pointer;
}
.var-chip:hover { background: rgba(79,143,247,.28); }

/* test panel */
.test-panel { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 12px; }
.test-result { margin-top: 10px; font-size: 13px; }
.trace-row { font-family: var(--mono); font-size: 11.5px; padding: 4px 8px; border-radius: 5px; margin-top: 4px; background: rgba(0,0,0,.2); display: flex; gap: 8px; }
.trace-ok { color: var(--green); } .trace-fail { color: var(--red); }
.verdict { font-weight: 800; padding: 8px 12px; border-radius: 8px; margin-top: 8px; }
.verdict.fire { background: rgba(52,201,142,.14); color: var(--green); }
.verdict.nofire { background: rgba(240,97,109,.12); color: var(--red); }

/* multi select chips */
.chips-input { display: flex; flex-wrap: wrap; gap: 5px; padding: 6px; border: 1px solid var(--border2); border-radius: 7px; background: #0f1620; }
.chips-input .chip { background: var(--panel2); border-radius: 5px; padding: 2px 8px; font-size: 12px; display: inline-flex; gap: 6px; align-items: center; }
.chips-input .chip button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 11px; }
.chips-input input { border: none; background: transparent; flex: 1; min-width: 90px; padding: 3px; }

/* bar chart */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 110px; margin-top: 12px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar { width: 100%; border-radius: 4px 4px 0 0; background: var(--accent); min-height: 2px; position: relative; }
.bar .crit { position: absolute; bottom: 0; left: 0; right: 0; background: var(--red); border-radius: 0; }
.bar-lbl { font-size: 9px; color: var(--muted); white-space: nowrap; }

/* login */
.login-wrap { min-height: calc(100vh - 48px); display: grid; place-items: center; }
.login-card { width: 380px; max-width: 92vw; padding: 26px; }
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.login-btn { width: 100%; justify-content: center; margin-top: 16px; padding: 10px; }
.login-error {
  margin-top: 12px; background: rgba(240,97,109,.12); color: var(--red);
  border-radius: 7px; padding: 9px 12px; font-size: 13px;
}
.login-foot { margin-top: 16px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.login-foot a { color: var(--accent2); margin-left: 4px; }

/* sidebar user box */
.user-box { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #7c3aed); font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.user-meta { min-width: 0; flex: 1; }
.user-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--muted); }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
pre.json { font-family: var(--mono); font-size: 11.5px; background: rgba(0,0,0,.25); padding: 10px; border-radius: 8px; overflow: auto; max-height: 300px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; margin: 16px 0 8px; }
