:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #16181d; --muted: #6b7280; --line: #e3e6eb;
  --accent: #5b3df5; --accent-ink: #ffffff; --err: #c2261d; --code: #f0f1f4;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --panel: #171a21; --text: #e8eaee; --muted: #9aa1ad; --line: #272b34;
          --accent: #8b74ff; --accent-ink: #0f1115; --err: #ff7a70; --code: #1f232b; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; padding: 8px 14px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button:disabled { opacity: .6; cursor: wait; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
button.small { padding: 4px 10px; font-size: 12px; margin: 4px 0 8px; }
input, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 12px; margin-top: 14px; }
.erro { color: var(--err); }

.brand { display: flex; gap: 10px; align-items: center; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; }
.login-card form { display: grid; gap: 14px; margin-top: 22px; }
.login-card label { display: grid; gap: 6px; font-weight: 500; }
.login-card .erro { margin: 0; }

/* app */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.top nav { display: flex; gap: 6px; align-items: center; }
.top nav form { margin: 0 0 0 8px; }
.tab { background: transparent; color: var(--muted); font-weight: 500; }
.tab.active { background: var(--code); color: var(--text); }
.layout { display: grid; grid-template-columns: 290px 1fr; min-height: calc(100vh - 60px); }
.side { border-right: 1px solid var(--line); padding: 16px; overflow: auto; max-height: calc(100vh - 60px); }
.side h2, .main h2 { font-size: 15px; margin: 0 0 10px; }
.side h3 { font-size: 13px; margin: 18px 0 4px; }
.side ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 2px; }
.tbl, .col { width: 100%; text-align: left; background: transparent; color: var(--text); padding: 6px 8px; font-weight: 500; border-radius: 6px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
/* tabelas: nome em cima, contagem embaixo (não corta em telas estreitas) */
.tbl { flex-direction: column; align-items: flex-start; gap: 1px; }
.tbl span { overflow-wrap: anywhere; }
.col code { overflow-wrap: anywhere; }
.tbl:hover, .col:hover { background: var(--code); }
.tbl small, .col small { color: var(--muted); font-weight: 400; font-size: 11px; white-space: nowrap; }
.col code { font-size: 12px; }
.main { padding: 16px 20px; min-width: 0; }
.editor-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; }
#sql { min-height: 170px; resize: vertical; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--code); }
.status { margin: 10px 0; }
.table-wrap { overflow: auto; max-height: 60vh; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel); font-weight: 600; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.null { color: var(--muted); }
#fontes-hashes td:last-child { font-family: ui-monospace, Menlo, monospace; font-size: 11px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
}
