:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-alt: #162032;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.subtitle { font-size: 0.78rem; color: var(--muted); font-family: var(--mono); }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--err);
  box-shadow: 0 0 8px rgba(239,68,68,.5);
}
.brand-dot.ok { background: var(--ok); box-shadow: 0 0 8px rgba(34,197,94,.6); }
.brand-dot.warn { background: var(--warn); box-shadow: 0 0 8px rgba(245,158,11,.6); }

.conn-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
input, select, textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 0.85rem;
}
input:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
#brokerUrl { width: 230px; font-family: var(--mono); font-size: 0.8rem; }
#username { width: 120px; }
#password { width: 140px; }
.remember-lbl { display: flex; align-items: center; gap: 5px; font-size: 0.8rem; color: var(--muted); cursor: pointer; }

.btn {
  border: none;
  border-radius: 6px;
  padding: 7px 13px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #082f49; }
.btn-danger { background: var(--err); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 4px 9px; font-size: 0.78rem; }

.kpis {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 10px 18px;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--border);
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  min-width: 140px;
}
.kpi-label { display: block; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-val { font-size: 0.98rem; font-family: var(--mono); }
.kpi-actions { margin-left: auto; display: flex; gap: 8px; }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(290px, 38%) 1fr;
  gap: 12px;
  padding: 12px 18px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 0.95rem; }
#filterInput { flex: 1; max-width: 260px; }

.tree-container { flex: 1; overflow: auto; padding: 8px; font-size: 0.84rem; }
.empty-state { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 0.88rem; }

.tree-node { margin-left: 14px; border-left: 1px dashed #334155; padding-left: 8px; }
.tree-root > .tree-node { margin-left: 0; border-left: none; padding-left: 0; }
.tree-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 7px;
  border-radius: 6px;
  cursor: pointer;
}
.tree-row:hover { background: rgba(56,189,248,.1); }
.tree-row.active { background: rgba(56,189,248,.22); outline: 1px solid rgba(56,189,248,.45); }
.tree-row.flash { animation: flashBg 0.8s ease; }
@keyframes flashBg { from { background: rgba(34,197,94,.35); } to { background: transparent; } }
.tree-name { font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-val { color: var(--accent); font-family: var(--mono); font-size: 0.78rem; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-count { font-size: 0.7rem; color: var(--muted); background: var(--bg); padding: 1px 6px; border-radius: 10px; }

.detail-panel { justify-content: space-between; }
.detail-top { flex: 1; display: flex; align-items: center; justify-content: center; }
.detail-content { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
.topic-title-wrap { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.topic-path { font-family: var(--mono); font-size: 0.92rem; color: var(--accent); word-break: break-all; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 0.72rem; padding: 2px 7px; border-radius: 5px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.badge-retain { color: var(--warn); border-color: rgba(245,158,11,.4); }

.payload-box, .spark-box, .history-box { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.box-label { font-size: 0.74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
#selPayload {
  margin: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: var(--mono);
  font-size: 0.84rem;
  max-height: 190px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
#sparkSvg { width: 100%; height: 70px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
.history-table-wrap { max-height: 190px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th, td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); font-family: var(--mono); }
th { background: var(--panel-alt); color: var(--muted); position: sticky; top: 0; }

.publish-box { padding: 10px 14px; background: var(--panel-alt); display: flex; flex-direction: column; gap: 8px; }
.pub-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#pubTopic { flex: 1; min-width: 180px; font-family: var(--mono); }
#pubPayload { width: 100%; font-family: var(--mono); resize: vertical; }

.toast {
  position: fixed; bottom: 16px; right: 16px;
  background: #1e293b; border: 1px solid var(--accent);
  color: var(--text); padding: 10px 14px; border-radius: 8px;
  font-size: 0.84rem; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
}