:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #6b7380;
  --border: #dfe3e8;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --ok-bg: #e7f6ec;
  --ok-text: #1d6b3a;
  --err-bg: #fdecec;
  --err-text: #a12828;
  --warn-bg: #fff4dc;
  --warn-text: #8a5a00;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --card: #1d2128;
    --text: #e6e9ee;
    --muted: #98a0ad;
    --border: #2f3540;
    --accent: #6e8ff0;
    --accent-text: #0f1115;
    --ok-bg: #173323;
    --ok-text: #8fdcaa;
    --err-bg: #3a1c1c;
    --err-text: #f2a3a3;
    --warn-bg: #3a2e12;
    --warn-text: #f0c86a;
  }
}

* { 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); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; word-break: break-all; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
[hidden] { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar .links { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; }
.topbar .links a { text-decoration: none; }
.logout { display: flex; gap: 0.5rem; align-items: center; margin: 0; }

main { max-width: 1040px; margin: 2rem auto; padding: 0 16px; }
main.narrow { max-width: 520px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.card.login { margin-top: 10vh; }
.card section + section, .card details + section { margin-top: 1.5rem; }
details { margin-top: 1.5rem; }
summary { cursor: pointer; font-weight: 600; margin-bottom: 0.75rem; }

.header-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.header-row h1 { margin: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.75rem 1rem; }
label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--text); margin-top: 0.75rem; }
.login label { margin-bottom: 0.75rem; }

input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  width: 100%;
  min-width: 0;
}
input[type=checkbox] { width: auto; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button, .button {
  font: inherit;
  display: inline-block;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.wide { width: 100%; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.danger, .danger { color: var(--err-text); }
button.link.danger { color: var(--err-text); }
button:disabled { opacity: 0.6; cursor: wait; }

.actions { display: flex; gap: 0.75rem; align-items: center; margin-top: 1.25rem; flex-wrap: wrap; }
.grid .actions { margin-top: 0; align-self: end; }
.danger-zone { margin: 0 0 2rem; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.5rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
.table select { width: auto; }
.card { overflow-x: auto; }

form.inline { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
form.inline label.check { margin: 0; }
form.inline input[type=password] { width: 200px; }

.badge { display: inline-block; font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }

.flash { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.error { background: var(--err-bg); color: var(--err-text); }

.hint { color: var(--muted); font-size: 0.875rem; margin: 0.5rem 0 0; }
.muted { color: var(--muted); }

.copy { display: flex; gap: 0.5rem; align-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.75rem; }
.copy code { flex: 1; }

.list { padding-left: 1.2rem; }
.list li { margin: 0.3rem 0; }

.test-result { white-space: pre-wrap; padding: 0.75rem 1rem; border-radius: 6px; background: var(--bg); margin-top: 1rem; font-size: 0.9rem; }
.test-result.ok { background: var(--ok-bg); color: var(--ok-text); }
.test-result.error { background: var(--err-bg); color: var(--err-text); }

@media (max-width: 640px) {
  main { margin: 1rem auto; }
  .card { padding: 1rem; }
  .topbar { padding: 0.75rem 16px; gap: 0.75rem; }
}
