:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --text: #111318;
  --muted: #5f6673;
  --border: #e4e6ea;
  --accent: #2f5fd0;
  --accent-hover: #2752b8;
  --danger: #c0362c;
  --radius: 10px;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 var(--s3); letter-spacing: -0.01em; }
h2 { font-size: 1.125rem; margin: 0 0 var(--s3); }
p { margin: 0 0 var(--s4); }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.muted { color: var(--muted); }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s3) var(--s5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; font-size: 1.125rem; color: var(--text); letter-spacing: -0.02em; }
.brand:hover { color: var(--text); text-decoration: none; }
.bar-nav { display: flex; align-items: center; gap: var(--s4); }
.bar-nav form { margin: 0; }

.page { max-width: 880px; margin: 0 auto; padding: var(--s6) var(--s4) var(--s7); }
.center { display: grid; place-items: center; min-height: 100vh; padding: var(--s4); }

.card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s6);
}
.page .card { max-width: none; margin-top: var(--s5); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 40px;
  padding: 0 var(--s4);
  font: inherit;
  font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { background: var(--bg); border-color: #cfd3d9; }
.btn:active { background: #eceef1; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: #1f449a; border-color: #1f449a; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fdf2f1; border-color: var(--danger); }
.btn-quiet { border-color: transparent; background: transparent; }

.btn.busy::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

input[type="text"] {
  min-height: 40px;
  padding: 0 var(--s3);
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}
input[type="text"]:hover { border-color: #cfd3d9; }
input[type="text"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent); }
input[type="text"]:disabled { opacity: 0.55; cursor: not-allowed; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.check { display: inline-flex; align-items: center; gap: var(--s2); color: var(--muted); font-size: 0.9rem; }

.row { display: flex; gap: var(--s3); flex-wrap: wrap; }
.row input { flex: 1 1 200px; }

.alert {
  margin: 0 0 var(--s4);
  padding: var(--s3) var(--s4);
  color: var(--danger);
  background: #fdf2f1;
  border: 1px solid #f0c9c5;
  border-radius: var(--radius);
}
.alert-text { color: var(--danger); }

.notice {
  margin: 0 0 var(--s4);
  padding: var(--s3) var(--s4);
  background: #eef3fc;
  border: 1px solid #cddaf5;
  border-radius: var(--radius);
}

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: var(--s3) var(--s4); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
th { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg); }

.actions { display: flex; flex-direction: column; gap: var(--s2); }
form.inline { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; margin: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

@media (max-width: 600px) {
  .bar { padding: var(--s3) var(--s4); }
  .card { padding: var(--s5); }
}

/* Admin */
.subnav { display: flex; flex-wrap: wrap; gap: var(--s4); margin: 0 0 var(--s5); padding-bottom: var(--s3); border-bottom: 1px solid var(--border); }
.subnav a { color: var(--muted); font-weight: 550; }
.subnav a:hover { color: var(--text); }
.subnav a[aria-current="page"] { color: var(--text); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s4); }
.stats .card { margin-top: 0; }
.stat { font-size: 2rem; font-weight: 650; line-height: 1.1; margin: 0 0 var(--s1); }
textarea, select {
  min-height: 40px;
  padding: var(--s2) var(--s3);
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}
textarea:hover, select:hover { border-color: #cfd3d9; }
textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent); }
textarea:disabled, select:disabled { opacity: 0.55; cursor: not-allowed; }
form.stack { display: grid; gap: var(--s3); max-width: 480px; margin: 0 0 var(--s4); }
form.stack input[type="text"], form.stack textarea, form.stack select { width: 100%; }
.field { display: grid; gap: var(--s1); font-size: 0.9rem; color: var(--muted); }
.checks { display: grid; gap: var(--s2); }
.secret { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; }
.danger-zone { border-color: #f0c9c5; }
