:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16181d;
  --muted: #69707d;
  --accent: #5865f2;
  --accent-text: #ffffff;
  --danger: #d93a3a;
  --ok: #1f9d55;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #181b20;
    --surface-2: #20242b;
    --border: #2b3038;
    --text: #e8eaee;
    --muted: #9198a4;
    --accent: #7983f5;
    --danger: #f06363;
    --ok: #3ec27a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }

.boot { padding: 48px; text-align: center; color: var(--muted); }

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  text-align: center;
}
.login-card h1 { font-size: 20px; margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.login-card .error { color: var(--danger); margin: 16px 0 0; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-weight: 700; font-size: 15px; padding: 0 10px 16px; }
.nav-btn {
  all: unset;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
}
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.nav-btn:focus-visible { outline: 2px solid var(--accent); }

.me {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
}
.me img { width: 28px; height: 28px; border-radius: 50%; }
.me span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { padding: 28px 32px 64px; max-width: 980px; width: 100%; }
main h2 { font-size: 20px; margin: 0 0 4px; }
.lead { color: var(--muted); margin: 0 0 20px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card h3 { font-size: 15px; margin: 0 0 4px; }
.card .hint { color: var(--muted); margin: 0 0 14px; font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 20px; font-weight: 650; margin-top: 2px; }

/* ---------- Forms ---------- */
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 180px; min-width: 0; }
.field label { font-size: 12px; color: var(--muted); }
input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button.btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  white-space: nowrap;
}
button.btn:disabled { opacity: .55; cursor: progress; }
button.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
button.btn.small { padding: 4px 10px; font-size: 13px; }
button.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.discord-btn { width: 100%; padding: 11px 14px; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; margin-top: 14px; border-top: 1px solid var(--border); }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item img { width: 30px; height: 30px; border-radius: 50%; flex: none; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow-wrap: anywhere; }
.item .sub { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.item .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.item .actions select { width: auto; padding: 4px 8px; }
.gap-top { margin-top: 8px; }
.pre { white-space: pre-wrap; }
.pay-preview { max-width: 180px; max-height: 240px; border-radius: 8px; border: 1px solid var(--border); }
.pay-preview-row { align-items: flex-start; }
.pay-preview-row:not(:has(img:not([hidden]))) { display: none; }
.item img.pay-thumb, .pay-thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); flex: none; }
.empty-thumb { display: grid; place-items: center; color: var(--muted); }
input[type="file"] { padding: 6px; }
.empty { color: var(--muted); padding: 14px 0 2px; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.badge.ok { color: var(--ok); }
.badge.off { color: var(--danger); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { width: auto; accent-color: var(--accent); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0 0 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.guild-picker { margin-bottom: 16px; max-width: 360px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    padding: 10px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    align-items: center;
  }
  .brand { display: none; }
  .nav-btn { white-space: nowrap; }
  .me { margin: 0; border: 0; padding: 0 0 0 8px; }
  .me span { display: none; }
  main { padding: 20px 16px 48px; }
  .item { flex-wrap: wrap; }
  .item .actions { width: 100%; justify-content: flex-start; }
}
