:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #627084;
  --border: #d9dee6;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --ok-bg: #e3f4e8;
  --ok-text: #14602b;
  --warn-bg: #fdf0d5;
  --warn-text: #7a4b00;
  --error-bg: #fbe3e1;
  --error-text: #8c1d18;
  --muted-bg: #eceff3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1b212b;
    --text: #e6e9ef;
    --muted: #96a2b4;
    --border: #2f3846;
    --accent: #5b9bff;
    --accent-text: #0b1220;
    --danger: #ff8a80;
    --ok-bg: #173523;
    --ok-text: #8fdca8;
    --warn-bg: #3a2c10;
    --warn-text: #f2c879;
    --error-bg: #3d1a18;
    --error-text: #ffb4ab;
    --muted-bg: #262d39;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.2rem; margin: 2rem 0 0.75rem; }
h3 { font-size: 1.05rem; margin: 0 0 0.75rem; }
code, .mono, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
.muted { color: var(--muted); }

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 1rem;
  padding: 0.75rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 600; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 0.25rem; flex: 1; }
.topbar nav a { padding: 0.35rem 0.7rem; border-radius: 6px; text-decoration: none; color: var(--text); }
.topbar nav a.active, .topbar nav a:hover { background: var(--muted-bg); }
.topbar form { margin: 0; }

.link-button { background: none; border: 0; padding: 0.35rem 0.7rem; color: var(--accent); cursor: pointer; font: inherit; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: 0.5rem; }
.actions form { margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; margin: 1rem 0; }
.card.narrow { max-width: 420px; margin: 4rem auto; }

.flash { padding: 0.75rem 1rem; border-radius: 6px; margin: 0 0 1rem; }
.flash ul { margin: 0; padding-left: 1.2rem; }
.flash-notice { background: var(--ok-bg); color: var(--ok-text); }
.flash-alert { background: var(--error-bg); color: var(--error-text); }

.field { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.25rem; }
.field label { font-weight: 600; font-size: 0.9rem; }
input[type=text], input[type=email], input[type=password], input[type=date], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.5rem 0.65rem; width: 100%;
}
textarea { resize: vertical; }

.button, input[type=submit] {
  display: inline-block; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  background: var(--accent); color: var(--accent-text); border: 1px solid var(--accent);
  border-radius: 6px; padding: 0.45rem 0.9rem;
}
.button-secondary { background: transparent; color: var(--accent); }
.button-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.button-small { padding: 0.2rem 0.6rem; font-size: 0.85rem; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
th, td { text-align: left; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.narrow-table { max-width: 520px; }
table form { margin: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; display: flex; flex-direction: column; }
.tile-value { font-size: 1.8rem; font-weight: 700; }
.tile-label { color: var(--muted); font-size: 0.85rem; }

.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; }
.badge-ok { background: var(--ok-bg); color: var(--ok-text); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-error { background: var(--error-bg); color: var(--error-text); }
.badge-muted { background: var(--muted-bg); color: var(--muted); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.5rem; margin: 0 0 1rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }

pre { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem 1rem; overflow-x: auto; margin: 0 0 1rem; }
pre.secret { font-size: 1.05rem; user-select: all; word-break: break-all; white-space: pre-wrap; }

.filters { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 140px; }
.filters .field.wide { min-width: 300px; flex: 1; }
.pagination { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }

@media (max-width: 640px) {
  .facts { grid-template-columns: 1fr; }
  table { display: block; overflow-x: auto; }
}
