:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #059669;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
  --shadow-lg: 0 4px 12px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 650; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 650; margin: 0 0 14px; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
h4 { font-size: 12px; font-weight: 600; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
hr { border: none; border-top: 1px solid var(--line); margin: 22px 0; }
code { background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; font-size: 13px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; height: 60px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); letter-spacing: -.02em; }
.brand span { color: var(--accent); }
.topbar nav { display: flex; align-items: center; gap: 6px; }
.topbar nav a { color: var(--text-2); padding: 7px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; }
.topbar nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }

.wrap { max-width: 1040px; margin: 0 auto; padding: 30px 28px 70px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: #fff;
  padding: 9px 16px; border-radius: 9px; border: 1px solid transparent; cursor: pointer;
  font-size: 14px; font-weight: 550; box-shadow: var(--shadow); transition: background .12s;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.ghost { background: var(--surface); border-color: var(--line-strong); color: var(--text); box-shadow: none; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
button.link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 0; font-weight: 500; }
button.link:hover { text-decoration: underline; }
button.link.danger { color: var(--danger); }
form.inline { display: inline; }

/* Cards / panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; box-shadow: var(--shadow); }
.panel.narrow { max-width: 520px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.banner { padding: 13px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 14px; }
.banner.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }

/* Page head */
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.row-actions { display: flex; gap: 8px; align-items: center; }

/* Hero / landing */
.hero { padding: 44px 0 24px; max-width: 620px; }
.hero h1 { font-size: 32px; letter-spacing: -.02em; }
.lead { font-size: 17px; color: var(--text-2); }
.cards, .grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin-top: 22px; }
.card h3 { margin-top: 0; }
.guildcard { display: flex; flex-direction: column; gap: 12px; color: var(--text); transition: border-color .12s, box-shadow .12s; }
.guildcard:hover { border-color: var(--accent); box-shadow: var(--shadow-lg); text-decoration: none; }
.ghead { display: flex; align-items: center; gap: 10px; }
.gicon { width: 36px; height: 36px; border-radius: 9px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; }

/* Guild layout with sidebar */
.guildlayout { display: grid; grid-template-columns: 210px 1fr; gap: 26px; align-items: start; }
.sidebar { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 2px; }
.sidebar a { padding: 9px 12px; border-radius: 8px; color: var(--text-2); font-size: 14px; font-weight: 500; }
.sidebar a:hover { background: var(--surface); text-decoration: none; color: var(--text); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar .sep { height: 1px; background: var(--line); margin: 8px 4px; }

/* Forms */
label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 4px; color: var(--text-2); }
.stack > label { margin-bottom: 14px; }
input[type=text], input[type=number], input[type=password], textarea, select {
  width: 100%; margin-top: 5px; padding: 9px 11px; background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 8px; font-size: 14px; font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.sub { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.inline-form { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-form.tiny input { margin-top: 0; padding: 6px 8px; font-size: 12px; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Toggle switches */
.toggles { display: flex; flex-direction: column; gap: 4px; margin-bottom: 18px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 4px; border-bottom: 1px solid var(--line); margin: 0; cursor: pointer; font-weight: 500; color: var(--text); }
.toggles .switch:last-child { border-bottom: none; }
.switch .switch-text { display: flex; flex-direction: column; }
.switch .switch-text small { color: var(--muted); font-weight: 400; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.track { position: relative; flex-shrink: 0; width: 40px; height: 22px; background: var(--line-strong); border-radius: 999px; transition: background .15s; }
.track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background: #fff; border-radius: 50%; box-shadow: var(--shadow); transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }

/* Checkbox role lists */
.rolelist { display: grid; gap: 2px; max-height: 240px; overflow: auto; padding: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 0; padding: 5px 6px; border-radius: 6px; font-weight: 400; color: var(--text); }
.chk:hover { background: var(--surface); }
.chk input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Portals */
.portalcard { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; background: var(--surface); box-shadow: var(--shadow); }
.portalhead { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.portalcard > summary { cursor: pointer; font-weight: 600; }
.portalcard details { margin: 8px 0; }
.portalcard details > summary { cursor: pointer; color: var(--accent); font-size: 14px; margin: 8px 0; font-weight: 500; }
.optitem { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 8px 0; background: var(--surface-2); }
.optitem > summary { cursor: pointer; font-weight: 500; }
.portalcard h4 { margin-top: 14px; }
.post-box { background: var(--accent-soft); border: 1px solid #c7d2fe; border-radius: 8px; padding: 12px 14px; margin: 10px 0; }
.qrow { display: grid; grid-template-columns: 1fr 130px 1.3fr; gap: 6px; margin-bottom: 6px; }
.qrow input, .qrow select { margin-top: 0; }
@media (max-width: 640px) { .qrow { grid-template-columns: 1fr; } }

/* Tables */
table.kv { width: 100%; border-collapse: collapse; }
table.kv th { text-align: left; color: var(--muted); font-weight: 500; width: 160px; padding: 7px 0; vertical-align: top; }
table.kv td { padding: 7px 0; }
.tablewrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); }
table.data td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: none; }
td.actions { display: flex; flex-direction: column; gap: 6px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .num { display: block; font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat .lbl { color: var(--muted); font-size: 13px; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); }
.badge.ok { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.badge.warn { background: var(--danger-soft); color: #b91c1c; border-color: #fecaca; }
.badge.mild { background: #fffbeb; color: #b45309; border-color: #fde68a; }

.danger-zone { border-color: #fca5a5; }
.warnlist, .warnlist li { list-style: none; padding: 0; margin: 0; }
.warnlist li { padding: 8px 0; border-bottom: 1px solid var(--line); }

/* Bars */
.bar { display: flex; align-items: center; gap: 10px; margin: 7px 0; font-size: 13px; }
.barlabel { width: 96px; color: var(--muted); flex-shrink: 0; text-align: right; }
.bartrack { flex: 1; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; height: 18px; overflow: hidden; }
.barfill { display: block; height: 100%; background: var(--accent); }
.barval { width: 34px; text-align: right; font-weight: 600; }

.foot { text-align: center; color: var(--muted); padding: 26px; border-top: 1px solid var(--line); font-size: 13px; background: var(--surface); }
.foot .dot { margin: 0 8px; }

@media (max-width: 820px) {
  .guildlayout { grid-template-columns: 1fr; }
  .sidebar { position: static; flex-direction: row; flex-wrap: wrap; margin-bottom: 8px; }
}
@media (max-width: 640px) {
  .cols { grid-template-columns: 1fr; }
  .wrap { padding: 20px 16px 50px; }
  .topbar { padding: 0 16px; }
}
