:root {
  --bg: #0b1220;
  --panel: #121a2b;
  --border: #243049;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --accent: #38bdf8;
  --ok: #34d399;
  --err: #f87171;
  --warn: #fbbf24;
  --in: #a78bfa;
  --out: #38bdf8;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: #0e1626;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; flex-direction: column; gap: 0.15rem; }
.brand strong { font-size: 1.05rem; }
.muted { color: var(--muted); font-size: 0.8rem; }
.top-actions { display: flex; gap: 0.5rem; align-items: center; }
.pill {
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.pill.on { border-color: var(--ok); color: var(--ok); }
.pill.off { color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 1fr;
  gap: 0.75rem;
  padding: 0.75rem;
  min-height: calc(100vh - 64px);
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}
.panel h2 {
  margin: 0 0 0.7rem;
  font-size: 0.95rem;
  font-weight: 650;
}
.log-panel {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  min-height: 420px;
}
.log-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.log-head h2 { margin: 0; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
}
label.block { margin-top: 0.55rem; }
label.check {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  margin: 0.55rem 0;
  color: var(--text);
  font-size: 0.85rem;
}
input, select, textarea {
  background: #0a101c;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  font-size: 0.85rem;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; resize: vertical; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}
.form-grid.cols-3 { grid-template-columns: 110px 1fr 1fr; }
.span2 { grid-column: span 2; }
.row { display: flex; align-items: center; }
.gap { gap: 0.45rem; }
.hint { font-size: 0.75rem; color: var(--muted); margin: 0.55rem 0; }
.hint code {
  background: #0a101c;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  color: var(--accent);
  font-size: 0.72rem;
  word-break: break-all;
}

.btn {
  border: 1px solid var(--border);
  background: #1a2438;
  color: var(--text);
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.btn:hover { border-color: #3b4d6e; }
.btn.primary { background: #0c4a6e; border-color: #0284c7; }
.btn.danger { background: #3f1d1d; border-color: #7f1d1d; color: #fecaca; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: wait; }

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.65rem;
  align-items: center;
}
.preset-group-label {
  width: 100%;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-top: 0.45rem;
  margin-bottom: 0.1rem;
}
.preset-group-label:first-child { margin-top: 0; }
.presets button {
  font-size: 0.72rem;
  padding: 0.28rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #0a101c;
  color: var(--muted);
  cursor: pointer;
}
.presets button:hover, .presets button.active {
  color: var(--text);
  border-color: var(--accent);
}
.panel-lead {
  font-size: 0.78rem;
  color: var(--muted);
  margin: -0.35rem 0 0.75rem;
  line-height: 1.45;
}
.info-card {
  margin: 0.65rem 0;
  padding: 0.65rem 0.75rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(56, 189, 248, 0.25);
  background: rgba(56, 189, 248, 0.06);
}
.info-card-title {
  font-size: 0.78rem;
  font-weight: 650;
  margin-bottom: 0.35rem;
  color: #7dd3fc;
}
.hook-urls {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.45rem;
  font-size: 0.75rem;
}
.hook-urls code {
  color: var(--accent);
  word-break: break-all;
  font-size: 0.72rem;
}
.m0 { margin: 0; }
.preset-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin: -0.25rem 0 0.65rem;
  font-size: 0.75rem;
}
.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #0a101c;
  color: var(--muted);
  font-size: 0.7rem;
}
.meta-pill.scope {
  border-color: rgba(52, 211, 153, 0.35);
  color: #6ee7b7;
}
.meta-pill.scope code {
  color: #a7f3d0;
  font-size: 0.68rem;
}
.meta-hint {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
  flex: 1 1 12rem;
}

.log {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem;
  background: #0a101c;
  max-height: calc(100vh - 280px);
}
.ev {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  background: #10192b;
}
.ev:hover { border-color: #3b4d6e; }
.ev.in { border-left: 3px solid var(--in); }
.ev.out { border-left: 3px solid var(--out); }
.ev.system { border-left: 3px solid var(--warn); opacity: 0.85; }
.ev-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}
.ev-title { font-size: 0.85rem; font-weight: 600; }
.ev-meta { font-size: 0.72rem; color: var(--muted); }
.ev-sub {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ev-preview {
  margin-top: 0.3rem;
  font-size: 0.72rem;
  color: #a5b4c8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.85;
}
.badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  margin-right: 0.25rem;
}
.badge.ok { color: var(--ok); border-color: #065f46; }
.badge.err { color: var(--err); border-color: #7f1d1d; }
.badge.in { color: var(--in); }
.badge.out { color: var(--out); }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  background: #0a101c;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem;
  max-height: 220px;
  overflow: auto;
}
.mono.small { font-size: 0.7rem; max-height: 140px; margin-top: 0.5rem; }
.hidden { display: none !important; }

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  width: min(980px, 96vw);
  max-height: 92vh;
  padding: 0;
  margin: auto;
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog[open] { display: flex; flex-direction: column; }
.dlg { display: flex; flex-direction: column; max-height: 92vh; min-height: 0; width: 100%; }
.dlg-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dlg-head-text { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.dlg-head-text strong { font-size: 0.95rem; }
.dlg-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: rgba(0,0,0,0.15);
}
.dlg-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 0.45rem 0.45rem 0 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.dlg-tab:hover { color: var(--text); background: rgba(148,163,184,0.08); }
.dlg-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}
.dlg-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.85rem 1rem 1.1rem;
}
.dlg-panel { display: none; }
.dlg-panel.active { display: block; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.85rem;
}
.meta-cell {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: #0a101c;
  padding: 0.45rem 0.55rem;
  min-width: 0;
}
.meta-k {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.meta-v {
  display: block;
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
  color: var(--text);
}

.detail-section { margin-bottom: 0.9rem; }
.detail-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.btn.xs { padding: 0.2rem 0.45rem; font-size: 0.7rem; }

.hdr-wrap {
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  overflow: hidden;
  background: #0a101c;
}
.hdr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.hdr-table tr + tr td { border-top: 1px solid rgba(148,163,184,0.1); }
.hdr-table td { padding: 0.4rem 0.55rem; vertical-align: top; }
.hdr-table .hk {
  width: 11rem;
  color: #7dd3fc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
  white-space: nowrap;
}
.hdr-table .hv code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  color: #e2e8f0;
  word-break: break-all;
  white-space: pre-wrap;
}
.code-block {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  background: #0a101c;
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  padding: 0.7rem 0.8rem;
  max-height: min(48vh, 420px);
  overflow: auto;
  color: #e2e8f0;
}
.empty-block {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.55rem 0.7rem;
  border: 1px dashed var(--border);
  border-radius: 0.55rem;
  background: rgba(0,0,0,0.15);
}

/* Parameter builder */
.param-builder {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: #0a101c;
  padding: 0.55rem 0.6rem 0.65rem;
}
.param-builder-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  font-size: 0.78rem;
  font-weight: 650;
}
.param-builder-head .tiny { font-weight: 500; margin-left: auto; }
.param-rows { display: flex; flex-direction: column; gap: 0.35rem; }
.param-row {
  display: grid;
  grid-template-columns: 1.6rem minmax(5rem, 0.9fr) 5.2rem minmax(0, 1.4fr) 1.6rem;
  gap: 0.35rem;
  align-items: center;
}
.param-row.off { opacity: 0.45; }
.param-en { display: flex; align-items: center; justify-content: center; margin: 0; }
.param-key, .param-place, .param-val input, .param-val select {
  width: 100%;
  min-width: 0;
  background: #121a2b;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 0.4rem;
  padding: 0.35rem 0.4rem;
  font-size: 0.78rem;
}
.param-val { min-width: 0; }
.param-del { padding: 0.2rem 0.35rem !important; }
.preview-box {
  margin-top: 0.55rem;
  padding: 0.45rem 0.55rem;
  border-radius: 0.5rem;
  border: 1px dashed var(--border);
  background: rgba(0,0,0,0.15);
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.preview-line {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  min-width: 0;
}
.preview-line code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #7dd3fc;
  word-break: break-all;
  flex: 1;
}
.raw-toggle {
  margin-top: 0.55rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.raw-toggle summary { cursor: pointer; user-select: none; }
.raw-toggle textarea {
  width: 100%;
  margin-top: 0.4rem;
  background: #0a101c;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 0.45rem;
  padding: 0.45rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}
.raw-toggle textarea:disabled { opacity: 0.4; }
.hint.tiny, .tiny { font-size: 0.7rem; }
#param-empty-hint.hidden { display: none; }

@media (max-width: 960px) {
  .grid { grid-template-columns: 1fr; }
  .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .hdr-table .hk { width: 7rem; }
  .param-row {
    grid-template-columns: 1.5rem 1fr;
  }
  .param-place, .param-val { grid-column: 2; }
}
