:root {
  --bg: #121212;
  --bg-2: #171717;
  --surface: #1c1c1c;
  --surface-2: #232323;
  --border: #2e2e2e;
  --border-strong: #3e3e3e;
  --text: #ededed;
  --muted: #8f8f8f;
  --brand: #3ecf8e;
  --brand-dim: rgba(62, 207, 142, .14);
  --warn: #f5a623;
  --warn-dim: rgba(245, 166, 35, .14);
  --danger: #f06a6a;
  --danger-dim: rgba(240, 106, 106, .14);
  --info: #6aa9f0;
  --info-dim: rgba(106, 169, 240, .14);
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8f9fa; --bg-2: #fcfcfc; --surface: #ffffff; --surface-2: #f3f4f5;
    --border: #e4e5e7; --border-strong: #cfd1d4; --text: #1c1c1c; --muted: #6b6f76;
    --brand: #1f9d63; --brand-dim: rgba(31, 157, 99, .12);
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error-text { color: var(--danger); margin: 0; }

/* ---------- botoes e campos */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px;
  border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #0b2a1b; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { height: 26px; padding: 0 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: 6px; padding: 6px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-dim); }
select { height: 30px; padding: 0 8px; }

/* ---------- login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: radial-gradient(600px 300px at 50% 0%, var(--brand-dim), transparent); }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card .btn { height: 36px; justify-content: center; }
.login-card p { margin: 0; }

/* ---------- layout */
.app { display: grid; grid-template-columns: 240px 1fr; height: 100%; }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.sidebar nav { flex: 1; overflow: auto; padding: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; padding: 16px 16px 12px; }
.brand.big { font-size: 20px; padding: 0; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--brand), #249b66); position: relative; }
.logo::after { content: ""; position: absolute; inset: 5px 6px; border: 2px solid #0b2a1b; border-radius: 50% / 30%; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 16px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 6px; color: var(--muted); cursor: pointer; font-size: 13.5px; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); }
.conn-group { margin-bottom: 2px; }
.conn-group .sub { padding: 2px 0 6px 26px; display: grid; gap: 1px; }
.conn-group .sub .nav-item { padding: 5px 10px; font-size: 13px; }
.conn-group .sub .nav-item.active { color: var(--brand); background: var(--brand-dim); }
.conn-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.up { background: var(--brand); box-shadow: 0 0 0 3px var(--brand-dim); }
.dot.down { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-dim); }
.dot.disabled { background: var(--border-strong); }
.sidebar-foot { border-top: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sidebar-foot #me { flex: 1; text-align: right; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { height: 52px; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--bg-2); }
.crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; }
.crumbs .sep { color: var(--border-strong); }
.crumbs b { font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.view { flex: 1; overflow: auto; padding: 24px; min-height: 0; }
.view.flush { padding: 0; overflow: hidden; display: flex; }

h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 15px; font-weight: 600; margin: 28px 0 10px; }
h2:first-child { margin-top: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }

/* ---------- cards e tiles */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
a.card:hover { border-color: var(--border-strong); background: var(--surface-2); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head .title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.tile .label { color: var(--muted); font-size: 12.5px; }
.tile .value { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 3px; }
.bar.warn > i { background: var(--warn); }
.bar.danger > i { background: var(--danger); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; font-weight: 500; border: 1px solid var(--border-strong); color: var(--muted); white-space: nowrap; }
.badge.green { color: var(--brand); border-color: transparent; background: var(--brand-dim); }
.badge.red { color: var(--danger); border-color: transparent; background: var(--danger-dim); }
.badge.amber { color: var(--warn); border-color: transparent; background: var(--warn-dim); }
.badge.blue { color: var(--info); border-color: transparent; background: var(--info-dim); }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.type-postgres { color: #6aa9f0; }
.type-mysql { color: #f5a623; }
.type-redis { color: #f06a6a; }

/* ---------- tabelas */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: auto; max-width: 100%; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
.grid th, .grid td { padding: 7px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; white-space: nowrap; }
.grid th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 500; font-size: 12px; z-index: 1; }
.grid th.sortable { cursor: pointer; user-select: none; }
.grid th.sortable:hover { color: var(--text); }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: var(--surface-2); }
.grid tr.clickable { cursor: pointer; }
.grid td.num, .grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td.wrap { white-space: pre-wrap; word-break: break-word; min-width: 280px; max-width: 640px; }
.grid td.data { max-width: 360px; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 12.5px; }
.grid td .null { color: var(--muted); font-style: italic; font-size: 11.5px; }
.grid td .badges { min-width: 220px; }
.grid .rownum { color: var(--muted); width: 1%; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 9px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap; font-size: 13.5px; background: none; border-top: 0; border-left: 0; border-right: 0; font-family: inherit; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }
.tab .count { color: var(--muted); font-size: 11.5px; margin-left: 4px; }

/* ---------- editor de tabelas (2 paineis) */
.split { display: grid; grid-template-columns: 280px 1fr; width: 100%; min-height: 0; }
.split .list { border-right: 1px solid var(--border); background: var(--bg-2); display: flex; flex-direction: column; min-height: 0; }
.split .list .search { padding: 12px; border-bottom: 1px solid var(--border); }
.split .list .search input { width: 100%; }
.split .list .items { overflow: auto; flex: 1; padding: 6px; }
.split .detail { overflow: auto; padding: 20px 24px; min-width: 0; }
.schema-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 8px 4px; }
.t-item { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--muted); }
.t-item:hover { background: var(--surface-2); color: var(--text); }
.t-item.active { background: var(--brand-dim); color: var(--brand); }
.t-item .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-item .s { font-size: 11px; }

.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 10px 0; color: var(--muted); font-size: 12.5px; flex-wrap: wrap; }
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

/* ---------- SQL */
.sql-editor { width: 100%; min-height: 180px; resize: vertical; font-family: var(--mono); font-size: 13px; line-height: 1.55; padding: 12px 14px; background: var(--surface); tab-size: 2; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 8px; background: var(--info-dim); color: var(--text); font-size: 13px; margin-bottom: 16px; }
.notice.warn { background: var(--warn-dim); }
.notice.error { background: var(--danger-dim); }
.notice svg { color: var(--info); margin-top: 2px; }
.notice.warn svg { color: var(--warn); }
.notice.error svg { color: var(--danger); }
pre.value { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow: auto; max-height: 60vh; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; margin: 0; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.loading::before { content: ""; display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); max-height: 42vh; }
  .brand { padding: 12px 16px 4px; }
  .topbar { padding: 0 16px; height: auto; min-height: 52px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .view { padding: 16px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .value { font-size: 18px; }
  .split { grid-template-columns: 1fr; grid-template-rows: 220px 1fr; }
  .split .list { border-right: 0; border-bottom: 1px solid var(--border); }
  .split .detail { padding: 16px; }
  .view.flush { overflow: auto; }
}
