:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e1e3e8;
  --text: #16181d;
  --muted: #646a76;
  --accent: #5865f2;
  --accent-text: #ffffff;
  --green: #1f8a4c;
  --green-bg: #e3f4ea;
  --red: #c23a3a;
  --red-bg: #fbe7e7;
  --amber: #a06200;
  --amber-bg: #fdf0d9;
  --blue: #2f5fd0;
  --blue-bg: #e5ecfb;
  --gray-bg: #eceef2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #22262e;
    --border: #2e333c;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --accent: #6f7bf7;
    --green: #5cc98b;
    --green-bg: #173326;
    --red: #f07878;
    --red-bg: #3a1c1e;
    --amber: #f0b45a;
    --amber-bg: #3a2c14;
    --blue: #86a6f5;
    --blue-bg: #1c2a48;
    --gray-bg: #2a2e36;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}

* { 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); }
button, input, select, textarea { font: inherit; color: inherit; }
.loading { padding: 48px; text-align: center; color: var(--muted); }

/* Sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.signin-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 36px 32px; max-width: 380px; width: 100%; text-align: center; box-shadow: var(--shadow);
}
.signin-card h1 { margin: 0 0 6px; font-size: 22px; }
.signin-card p { color: var(--muted); margin: 0 0 24px; }
.discord-btn {
  display: inline-flex; align-items: center; gap: 10px; justify-content: center; width: 100%;
  background: #5865f2; color: #fff; text-decoration: none; padding: 12px 16px; border-radius: 8px; font-weight: 600;
}
.discord-btn:hover { background: #4752c4; }
.dev-links { margin-top: 18px; font-size: 13px; color: var(--muted); }
.dev-links a { margin: 0 4px; }

/* Layout */
header.top {
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 10px 24px; position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
nav.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav.tabs button {
  background: none; border: 0; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); white-space: nowrap;
}
nav.tabs button:hover { background: var(--surface-2); color: var(--text); }
nav.tabs button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.me { display: flex; align-items: center; gap: 8px; white-space: nowrap; margin-left: auto; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--gray-bg); object-fit: cover; flex: none; }
.avatar.sm { width: 22px; height: 22px; }
main { max-width: 1180px; margin: 0 auto; padding: 24px; }
h2 { font-size: 18px; margin: 0 0 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile.green .value { color: var(--green); }
.tile.red .value { color: var(--red); }
.tile.amber .value { color: var(--amber); }

/* Cards, tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.toolbar { padding: 12px; border-bottom: 1px solid var(--border); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; min-width: 180px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.who { display: flex; align-items: center; gap: 8px; }
.sub { color: var(--muted); font-size: 12px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; text-transform: capitalize; }
.b-pending { background: var(--amber-bg); color: var(--amber); }
.b-active { background: var(--blue-bg); color: var(--blue); }
.b-paused, .b-withdrawn { background: var(--gray-bg); color: var(--muted); }
.b-completed, .b-checkout { background: var(--green-bg); color: var(--green); }
.b-rejected, .b-decline { background: var(--red-bg); color: var(--red); }
.b-cancel { background: var(--amber-bg); color: var(--amber); }
.b-owner { background: var(--accent); color: var(--accent-text); }
.b-admin { background: var(--blue-bg); color: var(--blue); }
.b-member { background: var(--gray-bg); color: var(--muted); }
.counts { display: inline-flex; gap: 6px; font-variant-numeric: tabular-nums; }
.counts span { min-width: 24px; text-align: center; border-radius: 6px; padding: 0 6px; font-weight: 600; }
.counts .c { background: var(--green-bg); color: var(--green); }
.counts .d { background: var(--red-bg); color: var(--red); }
.counts .x { background: var(--amber-bg); color: var(--amber); }

/* Forms */
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.form-card { padding: 20px; max-width: 640px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; justify-content: flex-end; z-index: 20; }
.drawer {
  background: var(--bg); width: min(620px, 100%); height: 100%; overflow-y: auto; padding: 24px;
  border-left: 1px solid var(--border);
}
.drawer h3 { margin: 0; font-size: 18px; }
.section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-top: 16px; }
.section h4 { margin: 0 0 12px; font-size: 14px; }
dl.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; }
.result { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--border); }
.result:last-child { border-bottom: 0; }
.result .body { flex: 1; min-width: 0; }
.note { white-space: pre-wrap; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30;
}
#toast.show { opacity: 1; }

/* Store forms */
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 2px; margin: 0 0 16px; }
legend { font-weight: 700; padding: 0 6px; }
.span2 { grid-column: 1 / -1; }
.store-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.store-opt {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 10px 16px;
  cursor: pointer; font-weight: 600;
}
.store-opt:hover { background: var(--surface-2); }
.store-opt.on { border-color: var(--accent); background: var(--blue-bg); color: var(--accent); }
.secure-note {
  background: var(--green-bg); color: var(--text); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; font-size: 13px;
}
.secure-note strong { color: var(--green); }
dl.secret code { font-size: 13px; background: var(--surface-2); padding: 2px 6px; border-radius: 4px; word-break: break-all; }

@media (max-width: 720px) {
  header.top { flex-wrap: wrap; padding: 10px 16px; }
  nav.tabs { order: 3; flex-basis: 100%; }
  main { padding: 16px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .me .name { display: none; }
  .drawer { padding: 16px; }
  dl.kv { grid-template-columns: 100px 1fr; }
}

/* Disclaimer */
.disclaimer {
  white-space: pre-wrap; max-height: 260px; overflow-y: auto; font-size: 13px; line-height: 1.55;
  background: var(--surface-2); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px;
}
label.agree { display: flex; gap: 8px; align-items: center; font-weight: 600; margin-bottom: 12px; cursor: pointer; }
label.agree input { width: auto; margin: 0; }

/* Public page */
.public-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.public-head h1 { margin: 0; font-size: 22px; }
.rank { width: 36px; color: var(--muted); font-variant-numeric: tabular-nums; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
@media (max-width: 1320px) { header.top { flex-wrap: wrap; } nav.tabs { order: 3; flex-basis: 100%; } }
.hidden{display:none !important}
.export-box{margin-bottom:16px;padding:14px 16px}
.export-box .row{gap:12px;flex-wrap:wrap;align-items:center}
.export-box label{display:flex;gap:6px;align-items:center}
.export-box p{margin:10px 0 0}
th.check, td.check{width:36px;padding-right:0;cursor:default}
td.check input, th.check input{width:16px;height:16px;cursor:pointer;margin:0}
.sel-info{white-space:nowrap}
