:root {
  --accent: #615eff;
  --accent-dark: #4f4ce0;
  --accent-soft: #ecebff;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --border: #e7e8f0;
  --text: #1b1b3a;
  --muted: #7c7d99;
  --green: #1aa663;
  --red: #e0414c;
  --amber: #e08a1a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

input, select, button, textarea { font-family: inherit; }

/* ===== Layout ============================================================ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 234px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 18px;
  text-decoration: none;
  color: var(--text);
}
.logo-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--accent);
  display: grid; place-items: center;
}
.logo-mark svg { width: 19px; height: 19px; }
.logo-text { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }

.sidebar-nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 9px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-ico { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-foot {
  margin-top: auto;
  padding: 12px 11px 4px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.content { flex: 1; min-width: 0; }
main { max-width: 1180px; margin: 0 auto; padding: 32px 38px 64px; }
.view { display: block; }
.hidden { display: none !important; }

/* ===== Page head ========================================================= */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}
.page-head.sub { align-items: center; margin: 4px 0 14px; }
.page-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.page-head h3 { font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
.head-actions { display: flex; gap: 8px; flex-shrink: 0; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 14px;
  font-size: 13px;
}
.breadcrumb a {
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
}
.breadcrumb a:hover { color: var(--text); }
.crumb-sep { color: var(--muted); }
.crumb-current { color: var(--text); font-weight: 600; }

/* ===== Panel + bảng ====================================================== */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: 15px; font-weight: 700; }
.panel-head .muted { margin-top: 2px; }
.panel-toolbar { padding: 12px 18px; border-bottom: 1px solid var(--border); }
.panel-toolbar input { max-width: 340px; }

.engine-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}
.engine-badge.merge { background: var(--accent-soft); color: var(--accent); }
.engine-badge.replacing { background: #fff3d4; color: var(--amber); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  background: #fbfbfd;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #fafaff; }
td.empty { text-align: center; color: var(--muted); padding: 32px; }

.col-dot { width: 20px; padding-right: 0 !important; }
.col-toggle { width: 70px; }

.link-name { font-weight: 700; color: var(--text); }
.mono { font-size: 13px; }
.sub { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }

/* Status dot */
.dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
}
.dot.running { background: var(--green); }
.dot.running::after { content: "✓"; color: #fff; font-size: 11px; font-weight: 900; }
.dot.error { background: var(--red); }
.dot.error::after { content: "!"; color: #fff; font-size: 11px; font-weight: 900; }
.dot.stopped { background: #cfd0dd; }

/* Connector icon cell */
.conn-cell { display: flex; align-items: center; gap: 9px; }
.conn-ico { width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0; }

/* ===== Badge / pill ====================================================== */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: capitalize;
}
.badge.kafka { background: #ecebff; color: var(--accent); }
.badge.clickhouse { background: #fff3d4; color: var(--amber); }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.pill.running { background: #e3f6ec; color: var(--green); }
.pill.stopped { background: #eef0f4; color: var(--muted); }
.pill.error { background: #fdebec; color: var(--red); }

/* ===== Nút =============================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 15px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .14s, border-color .14s;
}
.btn-ico { width: 12px; height: 12px; flex-shrink: 0; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); }
.btn.small { padding: 5px 11px; font-size: 12px; }
.btn.danger { color: var(--red); border-color: #f3c9cc; }
.btn.danger:hover { background: #fdebec; }

/* ===== Tabs ============================================================== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ===== Field ============================================================= */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field-group { display: flex; gap: 12px; }
.field-group .field { flex: 1; }
.field-group .grow { flex: 2; }
.field.checkbox { justify-content: flex-end; }
.field.checkbox label { display: flex; align-items: center; gap: 6px; color: var(--text); }

input, select {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  width: 100%;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.status { font-size: 13px; }
.status.ok { color: var(--green); }
.status.err { color: var(--red); }
.status.busy { color: var(--accent); }
.conn-status { font-size: 12px; color: var(--muted); }
.conn-status.ok { color: var(--green); }
.conn-status.err { color: var(--red); }
.conn-status.busy { color: var(--accent); }

.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.hint code, .sample-box code {
  background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 11px;
}

/* ===== Modal ============================================================= */
.modal { position: fixed; inset: 0; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 22, 50, .5); }
.modal-panel {
  position: relative;
  max-width: 520px;
  margin: 56px auto;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(20, 22, 50, .32);
  max-height: calc(100vh - 112px);
  display: flex;
  flex-direction: column;
}
.modal-panel.wide { max-width: 1080px; }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 17px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; font-weight: 700; }
.modal-x {
  background: none; border: none; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--muted);
}
.modal-x:hover { color: var(--text); }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 22px;
  border-top: 1px solid var(--border);
}

/* ===== Mapping =========================================================== */
.mode-tabs { display: flex; gap: 20px; padding: 2px 0; }
.mode-tabs label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.mode-tabs input { width: auto; }

.sample-box { margin: 16px 0; }
.sample-box h4, #sm-map-existing h4, #sm-map-new h4 {
  font-size: 13px; margin-bottom: 8px; color: var(--text);
}
.sample-box pre {
  background: #1b1b3a;
  color: #d6d7f5;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12px;
  max-height: 170px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.sql-opts { margin-top: 16px; }

.sql-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 18px;
  margin-bottom: 8px;
}
.sql-head .sql-title { margin: 0 !important; }
.sql-preview {
  width: 100%;
  display: block;
  background: #1b1b3a;
  color: #d6d7f5;
  border: 1px solid #343464;
  border-radius: 10px;
  padding: 13px 15px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  line-height: 1.6;
  min-height: 200px;
  resize: vertical;
}
.sql-preview:focus { outline: none; border-color: var(--accent); }

/* ===== Combobox có tìm kiếm ============================================== */
.combo { position: relative; }
.combo-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.combo-btn:hover { border-color: #cfd0e0; }
.combo-btn.open { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.combo-btn:disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; }
.combo-btn .combo-placeholder { color: var(--muted); }
.combo-caret { width: 13px; height: 13px; color: var(--muted); flex-shrink: 0; }
.combo-btn > span:first-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.combo-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(20, 22, 50, .18);
  padding: 8px;
  max-height: 320px;
  display: flex;
  flex-direction: column;
}
.combo-search { margin-bottom: 6px; }
.combo-list { overflow-y: auto; }
.combo-option {
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.combo-option:hover { background: var(--bg); }
.combo-option.selected { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.combo-empty { padding: 14px 10px; text-align: center; color: var(--muted); font-size: 12px; }

/* ===== Multi-broker (Bootstrap servers) ================================== */
.broker-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.broker-row .b-host { flex: 2; }
.broker-row .b-port { flex: 1; max-width: 120px; }
.broker-row .b-remove {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--muted);
  padding: 0 8px;
  line-height: 1;
}
.broker-row .b-remove:hover { color: var(--red); }

/* ===== Trang đăng nhập =================================================== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 370px;
  max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 30px 28px;
  box-shadow: 0 14px 44px rgba(20, 22, 50, .13);
}
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-card h1 { font-size: 20px; font-weight: 700; }
.login-card .muted { margin: 2px 0 22px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn {
  width: 100%;
  justify-content: center;
  margin-top: 8px;
  padding: 10px;
  font-size: 14px;
}
.login-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* Nút đăng xuất ở sidebar */
.sidebar-foot .logout-btn {
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.sidebar-foot .logout-btn:hover { background: var(--bg); color: var(--text); }

#sm-existing-table .col-type { color: var(--accent); font-size: 12px; }
#sm-existing-table input, table.design input { padding: 6px 9px; }
table.design .src-name { font-size: 13px; }
table.design .arrow-cell { color: var(--accent); text-align: center; width: 30px; font-weight: 700; }
table.design td:nth-child(4) { text-align: center; }
table.design .d-type { font-size: 12px; }

/* Công tắc bật/tắt */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #cdced9; border-radius: 999px; transition: .15s;
}
.switch .slider::before {
  content: ""; position: absolute; width: 15px; height: 15px;
  left: 2.5px; top: 2.5px; background: #fff; border-radius: 50%;
  transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:disabled + .slider { opacity: .5; cursor: not-allowed; }

/* ===== Toast ============================================================= */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 12px 20px;
  border-radius: 9px;
  font-size: 13px;
  max-width: 600px;
  box-shadow: 0 10px 30px rgba(20, 22, 50, .2);
  z-index: 60;
}
.toast.err { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
