:root {
  --bg: #0a0e13;
  --bg-soft: #0f151c;
  --panel: #121a23;
  --panel-2: #17212c;
  --line: #223040;
  --line-soft: #1a2633;
  --text: #e8eef5;
  --muted: #8ba0b6;
  --muted-2: #647a90;
  --accent: #21c997;
  --accent-dim: #0e6f55;
  --blue: #5aa9ff;
  --amber: #f0b34c;
  --red: #f06a6a;
  --violet: #a78bfa;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", "Consolas", "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(33, 201, 151, 0.10), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(90, 169, 255, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.hidden { display: none !important; }

/* ---------- login ---------- */

.login {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 70% 0%, rgba(33, 201, 151, 0.14), transparent 60%),
    var(--bg);
}

.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 34px 30px;
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--accent), #0c8a68);
  color: #04120d;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.04em;
}

.login-card h1 { font-size: 21px; margin-top: 18px; }
.login-card .sub { color: var(--muted); margin: 6px 0 24px; font-size: 13px; }
.login-card label { display: block; margin-bottom: 14px; }
.login-error {
  margin-top: 14px;
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
}
.login-hint {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

/* ---------- 2FA ---------- */

.twofa-qr {
  width: 176px;
  height: 176px;
  margin: 14px 0 10px;
  padding: 10px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line-soft);
}
.twofa-qr svg { width: 100%; height: 100%; display: block; }
.twofa-secret {
  display: inline-block;
  margin: 6px 0 4px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--surface-2, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--line-soft);
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 13px;
  letter-spacing: 0.08em;
  word-break: break-all;
}
.twofa-steps { color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
.twofa-codes {
  margin: 14px 0;
  padding: 14px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line-soft);
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 14px;
  line-height: 1.9;
  letter-spacing: 0.06em;
  white-space: pre;
  overflow-x: auto;
}
.twofa-details { margin-top: 16px; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.twofa-details summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.twofa-details summary:hover { color: var(--text); }
.twofa-details .row { margin-top: 12px; }

/* ---------- shell ---------- */

.app {
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line-soft);
  background: rgba(11, 16, 22, 0.72);
  backdrop-filter: blur(10px);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 2px 8px;
}
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.15; }
.brand-name span { display: block; color: var(--muted-2); font-size: 11px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border-radius: 10px;
  color: var(--muted);
  border: 1px solid transparent;
  cursor: pointer;
  background: none;
  text-align: left;
  width: 100%;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.03); color: var(--text); }
.nav-item.active { background: rgba(33, 201, 151, 0.10); color: var(--accent); border-color: rgba(33, 201, 151, 0.16); }
.nav-item .count {
  margin-left: auto;
  background: rgba(240, 179, 76, 0.16);
  color: var(--amber);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
}

.sidebar-foot { margin-top: auto; display: grid; gap: 9px; }
.mode-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 11px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
}
.mode-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(33, 201, 151, 0.12); }
.mode-chip.danger { border-color: rgba(240, 106, 106, 0.35); color: #ffb3b3; }
.mode-chip.danger .dot { background: var(--red); box-shadow: 0 0 0 4px rgba(240, 106, 106, 0.12); }
.mode-chip.sim { border-color: rgba(240, 179, 76, 0.35); color: #ffd18a; }
.mode-chip.sim .dot { background: var(--amber); box-shadow: 0 0 0 4px rgba(240, 179, 76, 0.12); }
.mode-chip.manual { border-color: rgba(90, 169, 255, 0.35); color: #a8d0ff; }
.mode-chip.manual .dot { background: var(--blue); box-shadow: 0 0 0 4px rgba(90, 169, 255, 0.12); }

.main { min-width: 0; padding: 24px 30px 60px; }

.topbar {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 24px;
}
.topbar h1 { font-size: 24px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.topbar-actions { margin-left: auto; display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 13px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: #1d2936; border-color: #2c3d50; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #032018; }
.btn.primary:hover { background: #2ad9a4; }
.btn.danger { background: rgba(240, 106, 106, 0.12); border-color: rgba(240, 106, 106, 0.35); color: #ffb3b3; }
.btn.danger:hover { background: rgba(240, 106, 106, 0.2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
.btn.icon { padding: 7px; width: 32px; height: 32px; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  background: #0c131a;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(33, 201, 151, 0.55);
  box-shadow: 0 0 0 3px rgba(33, 201, 151, 0.10);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
label.field { display: block; margin-bottom: 13px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
label.field .hint { display: block; color: var(--muted-2); font-size: 11.5px; margin-top: 5px; font-weight: 400; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row.three { grid-template-columns: repeat(3, 1fr); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { width: auto; accent-color: var(--accent); }
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch .track { width: 38px; height: 21px; border-radius: 999px; background: #2a3948; position: relative; transition: background 0.15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: #93a6b8; transition: transform 0.15s, background 0.15s; }
.switch input:checked + .track { background: rgba(33, 201, 151, 0.35); }
.switch input:checked + .track::after { transform: translateX(17px); background: var(--accent); }

/* ---------- cards / grids ---------- */

.grid { display: grid; gap: 14px; }
.grid.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.k2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  background: linear-gradient(180deg, rgba(23, 33, 44, 0.9), rgba(18, 26, 35, 0.92));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 18px;
}
.card.pad-sm { padding: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h3 { font-size: 14px; }
.card-head .muted { margin-left: auto; font-size: 12px; color: var(--muted); }

.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.kpi .value { font-size: 30px; font-weight: 750; letter-spacing: -0.03em; margin-top: 10px; line-height: 1; }
.kpi .value small { font-size: 14px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.kpi .foot { color: var(--muted-2); font-size: 11.5px; margin-top: 9px; }
.kpi.accent .value { color: var(--accent); }
.kpi.amber .value { color: var(--amber); }
.kpi.red .value { color: var(--red); }
.kpi.blue .value { color: var(--blue); }
.kpi.green .value { color: var(--accent); }
.kpi.violet .value { color: var(--violet); }

.funnel-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) 44px; gap: 10px; align-items: center; margin-bottom: 10px; }
.funnel-track { height: 10px; background: #0c131a; border: 1px solid var(--line-soft); border-radius: 999px; overflow: hidden; }
.funnel-bar { height: 100%; background: linear-gradient(90deg, var(--accent), #0c8a68); border-radius: 999px; transition: width 0.25s; }
.funnel-row strong { text-align: right; font-size: 13px; }

/* ---------- table ---------- */

.table-wrap { overflow: auto; border: 1px solid var(--line-soft); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-2);
  font-weight: 700;
  padding: 11px 14px;
  background: #0d141b;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background 0.12s; }
tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--muted-2); font-size: 11.5px; margin-top: 2px; }
.preview { max-width: 380px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-full { margin-top: 6px; }
.msg-full summary {
  cursor: pointer;
  font-size: 11.5px;
  color: var(--muted);
  list-style: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 340px;
}
.msg-full summary::-webkit-details-marker { display: none; }
.msg-full summary::before { content: '▸ '; color: var(--muted-2); }
.msg-full[open] summary::before { content: '▾ '; }
.msg-full pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 6px 0 0;
  max-width: 420px;
  max-height: 260px;
  overflow: auto;
}
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.green { background: rgba(33, 201, 151, 0.12); color: var(--accent); border-color: rgba(33, 201, 151, 0.22); }
.badge.amber { background: rgba(240, 179, 76, 0.12); color: var(--amber); border-color: rgba(240, 179, 76, 0.22); }
.badge.red { background: rgba(240, 106, 106, 0.12); color: var(--red); border-color: rgba(240, 106, 106, 0.22); }
.badge.blue { background: rgba(90, 169, 255, 0.12); color: var(--blue); border-color: rgba(90, 169, 255, 0.22); }
.badge.violet { background: rgba(167, 139, 250, 0.12); color: var(--violet); border-color: rgba(167, 139, 250, 0.22); }
.badge.gray { background: rgba(139, 160, 182, 0.10); color: var(--muted); border-color: rgba(139, 160, 182, 0.18); }

.chips { display: flex; gap: 5px; flex-wrap: wrap; }

/* ---------- lists ---------- */

.list { display: flex; flex-direction: column; }
.list-row {
  display: flex;
  gap: 11px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line-soft);
  align-items: flex-start;
}
.list-row:last-child { border-bottom: none; }
.list-row .ico {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--panel-2); color: var(--muted); flex: 0 0 auto;
}
.list-row .body { min-width: 0; flex: 1; }
.list-row .title { font-size: 12.5px; font-weight: 600; }
.list-row .desc { color: var(--muted-2); font-size: 11.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .when { color: var(--muted-2); font-size: 11px; white-space: nowrap; }

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted-2);
  font-size: 13px;
}
.empty strong { display: block; color: var(--muted); margin-bottom: 5px; font-size: 14px; }

/* ---------- filters ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar .search { position: relative; flex: 1; min-width: 220px; max-width: 380px; }
.toolbar .search svg { position: absolute; left: 10px; top: 9px; color: var(--muted-2); width: 16px; height: 16px; }
.toolbar .search input { padding-left: 33px; }
.segmented { display: inline-flex; background: #0c131a; border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted); padding: 6px 11px; border-radius: 7px;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.segmented button.active { background: var(--panel-2); color: var(--text); }
.segmented button .n { color: var(--muted-2); margin-left: 4px; font-size: 11px; }

/* ---------- rule cards ---------- */

.rule-card { display: flex; flex-direction: column; gap: 13px; }
.rule-top { display: flex; align-items: flex-start; gap: 12px; }
.rule-top .name { font-size: 14px; font-weight: 700; }
.rule-top .desc { color: var(--muted-2); font-size: 12px; margin-top: 3px; }
.rule-top .right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.rule-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.rule-foot { display: flex; gap: 8px; align-items: center; margin-top: auto; padding-top: 4px; }
.rule-foot .spacer { margin-left: auto; }

/* ---------- drawer / modal ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 11, 0.62);
  backdrop-filter: blur(3px);
  z-index: 60;
  display: flex;
  justify-content: flex-end;
}
.overlay.center { align-items: center; justify-content: center; padding: 24px; }

.drawer {
  width: min(760px, 100%);
  height: 100%;
  background: var(--bg-soft);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  box-shadow: -30px 0 80px rgba(0, 0, 0, 0.4);
  animation: slideIn 0.18s ease-out;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0.6; } to { transform: translateX(0); opacity: 1; } }
.drawer-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.drawer-head h2 { font-size: 18px; }
.drawer-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.drawer-head .close { margin-left: auto; }
.drawer-body { padding: 20px 22px 40px; overflow: auto; flex: 1; }
.drawer-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  gap: 9px;
  align-items: center;
  background: var(--panel);
}

.modal {
  width: min(760px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  animation: pop 0.16s ease-out;
}
@keyframes pop { from { transform: scale(0.985); opacity: 0.6; } to { transform: scale(1); opacity: 1; } }
.modal-head { padding: 20px 22px 0; display: flex; align-items: flex-start; gap: 12px; }
.modal-head h2 { font-size: 18px; }
.modal-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.modal-head .close { margin-left: auto; }
.modal-body { padding: 18px 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line-soft); display: flex; gap: 9px; justify-content: flex-end; align-items: center; }
.modal-foot .left { margin-right: auto; }

/* ---------- transcript ---------- */

.transcript {
  background: #0a1118;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 14px;
  max-height: 380px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg { max-width: 82%; padding: 9px 12px; border-radius: 12px; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }
.msg.in { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line-soft); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: rgba(33, 201, 151, 0.12); border: 1px solid rgba(33, 201, 151, 0.18); border-bottom-right-radius: 4px; }
.msg.note { align-self: center; background: rgba(240, 179, 76, 0.08); border: 1px dashed rgba(240, 179, 76, 0.25); color: var(--amber); font-size: 11.5px; }
.msg .meta { display: block; font-size: 10px; color: var(--muted-2); margin-bottom: 3px; }

.draft-box { position: relative; }
.draft-box textarea { min-height: 150px; font-size: 14px; line-height: 1.6; }
.draft-foot { display: flex; gap: 10px; align-items: center; margin-top: 8px; color: var(--muted-2); font-size: 11.5px; }
.draft-foot .counter.warn { color: var(--amber); }

.notice {
  border: 1px solid rgba(240, 179, 76, 0.25);
  background: rgba(240, 179, 76, 0.07);
  color: #ffd18a;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  margin-bottom: 14px;
}
.notice.red { border-color: rgba(240, 106, 106, 0.3); background: rgba(240, 106, 106, 0.08); color: #ffb3b3; }
.notice.green { border-color: rgba(33, 201, 151, 0.25); background: rgba(33, 201, 151, 0.07); color: #8ff0cf; }

/* ---------- toast ---------- */

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  box-shadow: var(--shadow);
  max-width: 380px;
  animation: pop 0.16s ease-out;
}
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }

/* ---------- misc ---------- */

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 14px; }
.mt-lg { margin-top: 22px; }
.divider { height: 1px; background: var(--line-soft); margin: 18px 0; }
.flex { display: flex; align-items: center; gap: 9px; }
.spacer { margin-left: auto; }
.stack { display: grid; gap: 12px; }
.two-col { display: grid; grid-template-columns: 1.25fr 0.75fr; gap: 14px; align-items: start; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-2); font-weight: 700; margin: 26px 0 10px; }
.section-title:first-child { margin-top: 0; }
.inline-note { color: var(--muted-2); font-size: 11.5px; }
.settings-card h3 { font-size: 14px; margin-bottom: 4px; }
.settings-card .desc { color: var(--muted-2); font-size: 12px; margin-bottom: 14px; }
.health { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.health-item { border: 1px solid var(--line-soft); border-radius: 10px; padding: 10px 12px; background: #0d141b; }
.health-item .k { font-size: 11px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.health-item .v { font-size: 12px; margin-top: 4px; }

/* ---------- graph editor ---------- */

.graph-overlay {
  position: fixed;
  inset: 0;
  z-index: 75;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.graph-header {
  height: 62px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.graph-header h2 { font-size: 15px; }
.graph-header .sub { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.graph-header .spacer { flex: 1; }
.graph-main { flex: 1; display: flex; min-height: 0; }
.graph-canvas {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  background-color: #080d12;
  background-image: radial-gradient(circle, #1c2937 1px, transparent 1px);
  background-size: 22px 22px;
}
.graph-canvas.panning { cursor: grabbing; }
.graph-world { position: absolute; left: 0; top: 0; width: 4000px; height: 3000px; transform-origin: 0 0; pointer-events: none; }
#graph-svg { position: absolute; left: 0; top: 0; width: 4000px; height: 3000px; pointer-events: none; overflow: visible; }
#graph-svg .edge-hit { pointer-events: stroke; cursor: pointer; }
#graph-svg .edge-item:hover .edge-line { stroke-width: 4; }
#graph-svg .edge-del { opacity: 0; pointer-events: none; cursor: pointer; transition: opacity 0.12s; }
#graph-svg .edge-item:hover .edge-del { opacity: 1; pointer-events: all; }
#graph-svg .edge-del circle { fill: #0a1118; stroke: var(--red); stroke-width: 1.6; }
#graph-svg .edge-del path { stroke: var(--red); stroke-width: 1.8; stroke-linecap: round; fill: none; }
#graph-svg .edge-del:hover circle { fill: var(--red); }
#graph-svg .edge-del:hover path { stroke: #fff; }
#graph-nodes { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
#graph-nodes .gnode { pointer-events: auto; }
.gnode {
  position: absolute;
  width: 250px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  user-select: none;
  cursor: grab;
}
.gnode:active { cursor: grabbing; }
.gnode.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(33, 201, 151, 0.25), 0 10px 30px rgba(0, 0, 0, 0.35); }
.gnode-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 30px 9px 11px;
  border-bottom: 1px solid var(--line-soft);
  cursor: grab;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.gnode-head:active { cursor: grabbing; }
.gnode-head .tag { margin-left: auto; font-size: 9.5px; color: var(--muted-2); }
.gnode-del {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted-2);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s, border-color 0.12s;
  z-index: 6;
}
.gnode:hover .gnode-del, .gnode.selected .gnode-del { opacity: 1; }
.gnode-del:hover { color: var(--red); border-color: var(--red); }
.gnode-body { padding: 10px 12px 14px; }
.gnode-title { font-size: 13px; font-weight: 650; line-height: 1.3; }
.gnode-sub { font-size: 11px; color: var(--muted-2); margin-top: 4px; }
.gnode-desc { font-size: 11.5px; color: var(--muted); margin-top: 6px; max-height: 44px; overflow: hidden; }
.gnode-start { background: linear-gradient(180deg, rgba(90, 169, 255, 0.12), var(--panel)); border-color: rgba(90, 169, 255, 0.35); }
.gnode-action .gnode-head { color: var(--blue); }
.gnode-decision { border-color: rgba(240, 179, 76, 0.35); }
.gnode-decision .gnode-head { color: var(--amber); }
.gnode-wait { border-color: rgba(167, 139, 250, 0.35); }
.gnode-wait .gnode-head { color: var(--violet); }
.gnode-join { border-color: rgba(90, 169, 255, 0.45); }
.gnode-join .gnode-head { color: var(--blue); }
.gport {
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #0a1118;
  border: 2px solid var(--muted);
  cursor: crosshair;
  z-index: 4;
}
.gport:hover { background: var(--accent); border-color: var(--accent); }
.gport.in { left: -8px; top: 50%; transform: translateY(-50%); }
.gport.out { right: -8px; }
.gport.out.default { top: 50%; transform: translateY(-50%); }
.gport.out.true { top: 38%; border-color: var(--accent); }
.gport.out.false { top: 70%; border-color: var(--red); }
.port-label { position: absolute; right: 14px; font-size: 9px; font-weight: 700; pointer-events: none; }
.port-label.true { top: 34%; color: var(--accent); }
.port-label.false { top: 66%; color: var(--red); }
.graph-panel { width: 350px; flex: 0 0 auto; border-left: 1px solid var(--line); background: var(--bg-soft); overflow: auto; padding: 18px; }
.graph-panel h3 { font-size: 14px; }
.graph-panel .sub { color: var(--muted-2); font-size: 11.5px; margin: 4px 0 14px; }
.graph-zoom { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 6px; z-index: 5; }
.graph-zoom .btn { background: var(--panel); }
.graph-hint { font-size: 11.5px; color: var(--muted-2); line-height: 1.55; margin-top: 8px; }
.graph-edge-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: 12px; }
.graph-edge-row:last-child { border-bottom: none; }
.graph-edge-row .spacer { margin-left: auto; }

.graph-history {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 92%;
  z-index: 12;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-left: 1px solid var(--line);
  box-shadow: -14px 0 34px rgba(0, 0, 0, 0.4);
}
.graph-history[hidden] { display: none; }
.graph-history-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.graph-history-head h3 { font-size: 14px; }
.graph-history-head .spacer { flex: 1; }
.graph-history-list { overflow: auto; padding: 6px 16px 18px; }
.version-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.version-row:last-child { border-bottom: none; }
.version-row .version-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.version-row .version-name { font-size: 12.5px; margin-top: 6px; color: var(--text); }
.version-row .version-meta { font-size: 11px; color: var(--muted-2); margin-top: 4px; line-height: 1.5; }
.version-row .version-actions { display: flex; gap: 6px; margin-top: 8px; }
.version-current { font-size: 11px; color: var(--muted-2); }
.graph-history-empty { padding: 26px 4px; color: var(--muted-2); font-size: 12px; line-height: 1.6; }

@media (max-width: 900px) {
  .graph-panel { width: 300px; }
}

@media (max-width: 1100px) {
  .grid.k4 { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .grid.k2[style] { grid-template-columns: 1fr !important; }
  .health { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 12px; gap: 14px; }
  .sidebar .brand { flex: 0 0 auto; }
  .nav { flex-direction: row; gap: 4px; }
  .nav-item span { display: none; }
  .nav-item .count { display: none; }
  .sidebar-foot { margin-top: 0; display: none; }
  .main { padding: 18px 16px 50px; }
  .topbar { flex-direction: column; }
  .topbar-actions { margin-left: 0; }
  .grid.k3, .grid.k2, .grid.k4 { grid-template-columns: 1fr; }
  .row, .row.three { grid-template-columns: 1fr; }
  .preview { max-width: 200px; }
}
