:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #263449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 18px; font-weight: 700; }
.brand span { color: var(--muted); font-weight: 400; font-size: 14px; margin-left: 6px; }

.status-pills { display: flex; gap: 8px; }
.pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 12px;
}
.pill.ok { color: var(--green); border-color: var(--green); }
.pill.bad { color: var(--red); border-color: var(--red); }

.tabs { display: flex; gap: 4px; padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--border); }
.tab {
  background: none;
  border: none;
  color: var(--muted);
  padding: 12px 18px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.view { display: none; padding: 20px; }
.view.active { display: block; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.card .num { font-size: 26px; font-weight: 700; }
.card .label { color: var(--muted); font-size: 12px; margin-top: 4px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 15px; }

.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.grid th { color: var(--muted); font-weight: 600; font-size: 12px; }
.grid tr:last-child td { border-bottom: none; }
.grid tbody tr.clickable { cursor: pointer; }
.grid tbody tr.clickable:hover { background: var(--panel-2); }

/* Pipeline table — bigger, cleaner rows */
#pipeline-table th { padding: 14px 14px; }
#pipeline-table td { padding: 18px 14px; }
#pipeline-table td:first-child strong { font-size: 15px; letter-spacing: 0.2px; }
.topic-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 9px;
  vertical-align: middle;
}
.topic-dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(74,222,128,.15); }
.topic-dot.off { background: var(--muted); }
.grid input, .grid select { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; width: 100%; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; }
.badge.green { background: rgba(74,222,128,.15); color: var(--green); }
.badge.red { background: rgba(248,113,113,.15); color: var(--red); }
.badge.gray { background: rgba(148,163,184,.15); color: var(--muted); }
.badge.blue { background: rgba(56,189,248,.15); color: var(--accent); }
.badge.yellow { background: rgba(251,191,36,.15); color: var(--yellow); }
.badge.orange { background: rgba(251,146,60,.15); color: #fb923c; }

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #0f172a; border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.small { padding: 3px 8px; font-size: 12px; }

.split { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }

.topic-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.topic-item:hover { background: var(--panel-2); }
.topic-item.active { background: var(--panel-2); border-left: 3px solid var(--accent); }
.topic-item .name { font-weight: 600; }
.topic-item .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.editor-meta { display: flex; gap: 24px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.editor-meta label { display: block; color: var(--muted); font-size: 11px; }
.editor-meta span { font-weight: 600; }

.editor-actions { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }

.sample-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 14px 16px; }
.sample-box label, .mapping-label, #test-result label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.sample-actions { display: flex; gap: 8px; margin-top: 8px; }
textarea, pre.mono {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}
textarea { resize: vertical; }
pre.mono { white-space: pre-wrap; word-break: break-word; }

.mapping-label { margin: 14px 16px 6px; }
#mapping-table { margin-bottom: 8px; }
#btn-add-row { margin: 0 16px 14px; }

#test-result { padding: 0 16px 14px; }
#table-columns { padding: 0 16px 16px; }

.logs { height: 60vh; overflow: auto; margin: 0; border: none; border-radius: 0; }

/* Live message feed */
.live-messages {
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
}
.msg { border-bottom: 1px solid var(--border); padding: 6px 0; }
.msg:last-child { border-bottom: none; }
.msg-head { display: flex; align-items: center; gap: 8px; }
.msg-time { color: var(--muted); font-size: 11px; }
.msg-body {
  margin: 4px 0 0;
  padding: 6px 8px;
  background: var(--panel);
  border-radius: 4px;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 140px;
  overflow: auto;
}
.msg-error { color: var(--red); font-size: 11px; margin-top: 3px; }

/* Minimal layout (sidebar + content) */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  padding: 16px 20px;
  height: calc(100vh - 57px);
}
.sidebar.hidden { display: none; }
.layout.no-sidebar { grid-template-columns: 1fr; }
.sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-head h2 { margin: 0; font-size: 15px; }
#topic-list { overflow-y: auto; flex: 1; }
.content { display: flex; flex-direction: column; min-width: 0; }
.content-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 12px;
}
.content-head h2 { margin: 0; font-size: 15px; }
.feed-full { flex: 1; max-height: none; }
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}
.dot.green { background: var(--green); }
.dot.gray { background: var(--muted); }

/* Top nav */
.nav { display: flex; gap: 6px; }
.nav-item {
  background: none; border: none; color: var(--muted);
  padding: 8px 16px; cursor: pointer; font-size: 14px; border-radius: 6px;
}
.nav-item:hover { color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); }

/* View panels */
.view-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* Configuration */
.config-body { flex: 1; overflow-y: auto; padding: 16px; }
.cfg-section { margin-bottom: 16px; }
.cfg-section > label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Configuration sub-tabs */
.cfg-tabs { display: flex; gap: 4px; }
.cfg-tab {
  background: none; border: none; color: var(--muted);
  padding: 6px 14px; cursor: pointer; font-size: 13px; border-radius: 6px;
}
.cfg-tab:hover { color: var(--text); }
.cfg-tab.active { background: var(--panel-2); color: var(--accent); }

/* DB form */
.db-form { display: flex; flex-direction: column; gap: 8px; }
.db-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.db-row label { color: var(--muted); font-size: 12px; display: block; }
.db-row input, .db-row select {
  width: 100%; margin-top: 4px; padding: 8px 10px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
#db-test-result { margin-top: 8px; font-size: 12px; }
#db-select-result { margin-top: 8px; font-size: 12px; }

/* Pipeline dashboard (full page) */
.dash-title { display: flex; align-items: center; gap: 10px; }
.dash-title h2 { margin: 0; }
.dash-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.dash-cards { grid-template-columns: repeat(3, 1fr); margin-bottom: 14px; }
.dash-info {
  font-size: 12px;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.dash-section label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.dash-msgs { max-height: 50vh; overflow-y: auto; }
.dash-history { max-height: 260px; overflow-y: auto; }

.muted { color: var(--muted); }
.pad { padding: 20px; }
.hidden { display: none !important; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: 420px; }
.modal-box h2 { margin-top: 0; }
.modal-box form label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.modal-box input { width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 8px; margin-top: 4px; }
.modal-box label.inline { display: flex; align-items: center; gap: 8px; color: var(--text); }
.modal-box label.inline input { width: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--panel-2); border: 1px solid var(--accent);
  padding: 12px 18px; border-radius: 8px; z-index: 200; max-width: 400px;
}

/* Login */
.login-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
}
.login-screen.hidden { display: none; }
.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  width: 360px;
  text-align: center;
}
.login-brand { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-brand span { color: var(--muted); font-weight: 400; font-size: 13px; }
.login-box form { text-align: left; margin-top: 18px; }
.login-box label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.login-box input {
  width: 100%; margin-top: 5px; padding: 9px 10px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.btn-block { width: 100%; padding: 10px; margin-top: 6px; }
.login-error { color: var(--red); font-size: 12px; margin-bottom: 10px; }
