:root {
  --paper: #f5f2ea;
  --surface: #fbf9f4;
  --field: #ffffff;
  --ink: #1d211c;
  --muted: #5d6459;
  --faint: #8b9186;
  --line: #d9d4c5;
  --line-soft: #e7e3d7;
  --green: #2f6b3f;
  --green-ink: #ffffff;
  --green-soft: #e3eddc;
  --amber: #9a6a12;
  --amber-soft: #f6ecd2;
  --red: #a63a2b;
  --red-soft: #f6e1dc;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141713;
    --surface: #1a1e19;
    --field: #10130f;
    --ink: #e6e9e0;
    --muted: #a0a899;
    --faint: #717a6c;
    --line: #30362d;
    --line-soft: #252a23;
    --green: #7cbf86;
    --green-ink: #0f1a11;
    --green-soft: #1f2e21;
    --amber: #d9a441;
    --amber-soft: #2e2715;
    --red: #e0796a;
    --red-soft: #33201c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: 26px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 600; }
p { margin: 0; }
a { color: var(--green); }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side {
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; font-weight: 650; font-size: 17px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 8px; border-radius: 6px;
  color: var(--muted); text-decoration: none;
}
.nav a:hover { color: var(--ink); background: var(--line-soft); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--line-soft); font-weight: 600; }
.nav .sep { height: 1px; background: var(--line-soft); margin: 8px; }
.nav .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.side-foot { margin-top: auto; padding: 0 8px; font-size: 13px; color: var(--muted); display: grid; gap: 8px; justify-items: start; }
.who { display: flex; align-items: center; gap: 8px; color: var(--ink); min-width: 0; }
.who img { width: 24px; height: 24px; border-radius: 50%; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link:hover { color: var(--ink); }
.link.danger:hover { color: var(--red); }

.main { padding: 34px 40px 120px; max-width: 980px; width: 100%; }
/* Forms read best in a narrow column. Tables get the room the screen has. */
.main.wide { max-width: 1500px; }
.page-head { margin-bottom: 26px; }
.page-head p { color: var(--muted); margin-top: 4px; max-width: 62ch; }
.page-head .row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }

.section { border-top: 1px solid var(--line); padding: 20px 0 26px; }
.section > h2 { margin-bottom: 14px; }
.section > .section-note { color: var(--muted); margin: -8px 0 14px; max-width: 70ch; }

/* ---------- fields ---------- */
.field { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 6px 24px; padding: 10px 0; }
.field + .field { border-top: 1px solid var(--line-soft); }
.field-label label, .field-label .label { font-weight: 550; }
.field-label p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.field-body { min-width: 0; }
.field.wide { grid-template-columns: minmax(0, 1fr); }
.field-error { color: var(--red); font-size: 13px; margin-top: 5px; }
.field.has-error input, .field.has-error textarea, .field.has-error select { border-color: var(--red); }
.changed-mark { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--amber); margin-left: 6px; vertical-align: middle; }

input[type="text"], input[type="number"], input[type="password"], input[type="search"], textarea, select {
  width: 100%;
  font: inherit; color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
}
textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--green); outline-offset: 1px;
}
input[type="number"] { width: 120px; font-variant-numeric: tabular-nums; }
.with-unit { display: flex; align-items: center; gap: 8px; color: var(--muted); }
input[type="color"] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="text"] { width: 110px; font-family: var(--mono); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 36px; height: 20px; border-radius: 10px; background: var(--line); position: relative; transition: background .12s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--field); transition: transform .12s; box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--green); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  font: 12px var(--mono); color: var(--muted);
  background: transparent; border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 6px; cursor: pointer;
}
.chip:hover { color: var(--ink); border-color: var(--faint); }
.role-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.role-pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 12px; padding: 1px 4px 1px 9px; font-size: 13px; background: var(--surface); }
.role-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.role-pill button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 4px; }
.role-pill button:hover { color: var(--red); }
.hint { font-size: 13px; color: var(--muted); margin-top: 5px; }
.hint.warn { color: var(--amber); }

/* Discord-like preview of a message */
.preview {
  margin-top: 8px; padding: 9px 12px;
  border-left: 3px solid var(--embed, var(--green));
  background: var(--surface);
  border-radius: 0 6px 6px 0;
  font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.preview .mention { background: color-mix(in srgb, #5865f2 22%, transparent); border-radius: 3px; padding: 0 2px; }
.preview-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); margin-top: 10px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 550; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 6px; padding: 7px 13px;
}
.btn { white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--red); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.savebar {
  position: fixed; left: 220px; right: 0; bottom: 0;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 12px 40px; display: flex; align-items: center; gap: 12px;
  transform: translateY(100%); transition: transform .16s ease-out;
}
.savebar.show { transform: none; }
.savebar .grow { flex: 1; color: var(--muted); }

/* ---------- tables and status ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px 9px 0; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
td.right, th.right { text-align: right; padding-right: 0; }
td.actions { width: 1%; white-space: nowrap; padding-right: 0; }
td.actions .btn-row { justify-content: flex-end; flex-wrap: nowrap; }
td.nowrap { white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.state { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.state.on::before { background: var(--green); }
.state.off::before { background: var(--red); }
.state.warn::before { background: var(--amber); }
.tag { display: inline-block; font-size: 12px; padding: 0 7px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.seeding { background: var(--green-soft); border-color: transparent; color: var(--green); font-weight: 600; }
.bar { height: 5px; width: 90px; border-radius: 3px; background: var(--line-soft); position: relative; overflow: hidden; display: inline-block; vertical-align: middle; margin-left: 8px; }
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--green); border-radius: 3px; }
.bar b { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--ink); opacity: .45; }
.sub { font-size: 13px; color: var(--muted); }

.notice { border: 1px solid var(--line); border-left: 3px solid var(--amber); background: var(--amber-soft); border-radius: 0 6px 6px 0; padding: 10px 14px; margin-bottom: 10px; }
.notice.bad { border-left-color: var(--red); background: var(--red-soft); }
.notice.good { border-left-color: var(--green); background: var(--green-soft); }

.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.figure { padding: 14px 16px; border-right: 1px solid var(--line-soft); }
.figure:last-child { border-right: 0; }
.figure b { display: block; font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.figure span { font-size: 13px; color: var(--muted); }

.steps { list-style: none; padding: 0; margin: 0; }
.steps li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.steps li:last-child { border-bottom: 0; }
.steps .check { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--faint); flex: none; display: grid; place-items: center; font-size: 11px; color: var(--green-ink); }
.steps .done .check { background: var(--green); border-color: var(--green); }
.steps .done .check::after { content: "✓"; }
.steps .done { color: var(--muted); }

.activity { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.activity li { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.activity time { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- rewards ---------- */
.reward { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 10px; background: var(--surface); }
.reward-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.4fr) 110px 110px; gap: 12px; align-items: end; }
.reward-grid label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.reward-grid input[type="number"] { width: 100%; }
.reward-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 12px; flex-wrap: wrap; }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink); padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 18px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 14, 10, .45); }
.dialog-body { padding: 22px 24px; display: grid; gap: 14px; }
.dialog-body h3 { font-size: 19px; }
.dialog-body label { display: block; font-weight: 550; margin-bottom: 4px; }
.dialog-body label.switch { display: inline-flex; font-weight: 400; margin: 0; }
.dialog-body .two { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 12px; }
.dialog-body .two input[type="number"] { width: 100%; }
.dialog-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--line); background: var(--surface); border-radius: 0 0 10px 10px; }
.test-result { font-size: 14px; padding: 8px 12px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); }
.test-result.ok { border-color: var(--green); color: var(--green); }
.test-result.fail { border-color: var(--red); color: var(--red); }

.toast { position: fixed; right: 20px; top: 20px; z-index: 50; display: grid; gap: 8px; max-width: 380px; }
.toast div { background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 6px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast div.bad { background: var(--red); color: #fff; }

.empty { border: 1px dashed var(--line); border-radius: 8px; padding: 28px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; font-size: 16px; }
.empty .btn { margin-top: 14px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type="search"] { max-width: 320px; }
.inline-edit { display: inline-flex; gap: 6px; align-items: center; }
.inline-edit input { width: 100px; padding: 3px 8px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); }
.login-card img { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 18px; }
.login-card h1 { margin-bottom: 6px; }
.login-card p { color: var(--muted); margin-bottom: 22px; }
.login-card .btn { width: 100%; padding: 10px; text-align: center; display: block; text-decoration: none; }
.login-card .small { font-size: 13px; margin-top: 18px; margin-bottom: 0; }

/* ---------- small screens ---------- */
.menu-btn { display: none; }
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; gap: 10px; }
  .side .nav, .side .side-foot { display: none; }
  .side.open .nav, .side.open .side-foot { display: flex; }
  .side.open .side-foot { display: grid; margin-top: 4px; }
  .brand { justify-content: space-between; padding: 0; }
  .brand > span { display: flex; align-items: center; gap: 10px; }
  .menu-btn { display: block; }
  .main { padding: 22px 16px 120px; }
  .field { grid-template-columns: minmax(0, 1fr); }
  .savebar { left: 0; padding: 10px 16px; }
  .reward-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .activity li { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .figure { border-right: 0; border-bottom: 1px solid var(--line-soft); }
  /* Tables scroll sideways inside their wrapper instead of squeezing the names into three lines. */
  .table-wrap table { min-width: 620px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
