:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --other: #b5b3ab;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #262624;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --other: #5f5e5a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #262624;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --other: #5f5e5a;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--page); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.muted { color: var(--muted); }
.hidden { display: none !important; }

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.brand strong { font-size: 16px; }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
select, button, input[type=search] {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--axis); }

.tabs {
  display: flex; gap: 2px; padding: 0 20px; background: var(--surface);
  border-bottom: 1px solid var(--border); overflow-x: auto;
}
.tabs button {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none;
  padding: 10px 12px; color: var(--text-2); white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.count {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--critical); color: #fff; font-size: 11px; font-weight: 600; text-align: center;
}
.count:empty { display: none; }

main { padding: 16px 20px 40px; max-width: 1600px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

.banner { margin: 12px 20px 0; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--critical); }
.banner.info { border-color: var(--accent); }

.grid.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid .wide { grid-column: 1 / -1; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 16px; min-width: 0;
}
.grid .card { margin-bottom: 0; }
.grid + .card, .card + .grid { margin-top: 16px; }
.card h2 { font-size: 14px; margin: 0 0 6px; font-weight: 600; }
.card h2.mt { margin-top: 18px; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.hint { color: var(--text-2); font-size: 12px; margin: 0 0 10px; }
.filters { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.filters input[type=search] { min-width: 260px; }

.chart { position: relative; height: 220px; }
.chart.tall { height: 300px; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .label { color: var(--text-2); font-size: 12px; }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 2px; }
.tile .sub { color: var(--muted); font-size: 12px; }
.tile.bad { border-color: var(--critical); }
.tile.warn { border-color: var(--warning); }

/* Tables */
.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 420px; overflow-y: auto; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; }
dialog pre.plan { white-space: pre; overflow-x: auto; word-break: normal; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: top; }
th { color: var(--text-2); font-weight: 600; white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.sql { max-width: 520px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.mono, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
tr:hover td { background: var(--surface-2); }
a.sqlid { color: var(--accent); cursor: pointer; text-decoration: none; font-family: ui-monospace, Menlo, Consolas, monospace; }
a.sqlid:hover { text-decoration: underline; }
.empty { color: var(--muted); padding: 10px 0; }

/* Badges de severidade: ícone + rótulo, nunca só cor */
.sev { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.sev.critical { background: var(--critical); color: #fff; }
.sev.warning { background: var(--warning); color: #0b0b0b; }
.sev.info { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.sev.good { background: var(--good); color: #fff; }

/* Medidores */
.meter-row { display: grid; grid-template-columns: minmax(110px, 180px) 1fr minmax(120px, auto); gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--grid); }
.meter-row:last-child { border-bottom: 0; }
.meter-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.meter-row .name small { display: block; font-weight: 400; color: var(--muted); }
.meter-row .info { font-size: 12px; color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; }
.meter { position: relative; height: 12px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.meter > span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--s1); }
.meter > span.warn { background: var(--warning); }
.meter > span.crit { background: var(--critical); }
.meter > i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text-2); }

/* Árvore de bloqueio */
.lock-node { border-left: 3px solid var(--critical); padding: 8px 12px; margin: 8px 0; background: var(--surface-2); border-radius: 0 6px 6px 0; }
.lock-node.waiter { border-left-color: var(--warning); margin-left: 28px; }
.lock-node .line2 { color: var(--text-2); font-size: 12px; margin-top: 2px; }

.finding { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.finding:last-child { border-bottom: 0; }
.finding .cat { font-weight: 600; min-width: 150px; }
.finding .msg { flex: 1; }

.subtabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.subtabs button { padding: 3px 10px; font-size: 12px; }
.subtabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.thresholds { margin-top: 12px; color: var(--text-2); font-size: 12px; }
.thresholds code { margin-right: 14px; }

dialog { max-width: min(900px, 92vw); width: 100%; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); padding: 14px 16px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
dialog pre { white-space: pre-wrap; word-break: break-word; max-height: 65vh; overflow: auto; background: var(--surface-2);
  padding: 12px; border-radius: 6px; font-size: 12px; }

@media (max-width: 900px) {
  .grid.two { grid-template-columns: minmax(0, 1fr); }
  main { padding: 12px 16px 32px; }
  .topbar, .tabs { padding-left: 16px; padding-right: 16px; }
  .filters input[type=search] { min-width: 0; width: 100%; }
  .meter-row { grid-template-columns: 1fr; gap: 4px; }
  .meter-row .info { text-align: left; }
  .finding { flex-wrap: wrap; }
  .finding .cat { min-width: 0; }
}

/* ---- central: login, bancos, menus, formulários ---- */
a { color: var(--accent); }
.brand-link { color: inherit; text-decoration: none; }
#db-select { max-width: 220px; }
.age.stale { color: var(--critical); font-weight: 600; }
.user-menu { display: inline-flex; gap: 8px; align-items: center; padding-left: 10px; border-left: 1px solid var(--border); }
.user-menu small { margin-left: -4px; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.small { padding: 2px 8px; font-size: 12px; }
button.danger { color: var(--critical); }
.page-title { font-size: 18px; margin: 4px 0 14px; }

.db-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.db-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; color: inherit; text-decoration: none; }
.db-card:hover { border-color: var(--accent); }
.db-card.offline { border-color: var(--critical); }
.db-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 15px; }
.db-card-meta { font-size: 12px; color: var(--text-2); margin: 4px 0 10px; }
.db-card-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
.db-card-stats .label { display: block; font-size: 11px; color: var(--text-2); }
.db-card-stats .value { font-size: 20px; font-weight: 600; }
.db-card-stats .value.bad { color: var(--critical); }
.db-card-stats small { display: block; font-size: 11px; font-weight: 400; color: var(--text-2); }

.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box { width: min(380px, calc(100vw - 32px)); padding: 0; }
.login-box h1 { text-align: center; font-size: 20px; }
.login-box form, .form-grid { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
input:not([type=checkbox]):not([type=search]), textarea {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; }
.form-error { color: var(--critical); font-size: 13px; min-height: 1em; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
dialog form h2 { margin: 0; font-size: 15px; }
.token-box { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: var(--surface-2); padding: 10px;
  border-radius: 6px; word-break: break-all; white-space: pre-wrap; user-select: all; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }

@media (max-width: 900px) {
  .user-menu { border-left: 0; padding-left: 0; }
  .db-card-stats { grid-template-columns: repeat(2, 1fr); }
}
