/* Base styles: reset, text, buttons, cards, forms, tables and small utilities. */

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

h2 { font-size: 15px; margin: 0 0 12px; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.hint.notice { color: var(--warn); margin-top: 4px; }
.grow { flex: 1; }

/* Grid items may shrink below their content, so a wide table scrolls inside its card instead of widening the page. */
.grid > *, .two-columns > *, .tiles > *, .stat-grid > * { min-width: 0; }

/* ---------- Utilities ---------- */

.spaced { margin-top: 14px; }
.spaced-below { margin-bottom: 12px; }
.auto-width { width: auto; }

/* ---------- Buttons ---------- */

.btn {
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.1); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn:disabled { opacity: 0.5; cursor: default; }

.link { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }

.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.segmented.wrap { flex-wrap: wrap; }
.segmented button { background: none; border: 0; padding: 6px 12px; cursor: pointer; color: var(--muted); }
.segmented button.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* ---------- Forms ---------- */

input, select, textarea.plain {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.control { display: grid; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
.inline .btn { padding: 6px 14px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 10px; }
.form-grid label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.form-grid .wide { grid-column: 1 / -1; }

textarea.editor {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font: 13px/1.55 var(--mono);
  tab-size: 2;
}
textarea.rule-query { min-height: 70px; }

.error-box {
  background: var(--bad-soft);
  border: 1px solid var(--bad);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--bad);
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
}

/* ---------- Tables ---------- */

.table-wrap { max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 6px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; }
td.num { font-variant-numeric: tabular-nums; font-family: var(--mono); text-align: right; }
tr:hover td { background: var(--accent-soft); }

pre.code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
  font: 12px/1.6 var(--mono);
  margin: 8px 0 0;
  white-space: pre-wrap;
}

.loading { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 70px 20px; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
