:root {
  --bg: #1e1f22; --bg2: #2b2d31; --bg3: #313338; --bg4: #383a40; --line: #3f4147;
  --text: #dbdee1; --muted: #949ba4; --head: #f2f3f5;
  --brand: #5865f2; --brand2: #4752c4; --green: #23a55a; --red: #da373c; --yellow: #f0b232;
  --radius: 8px; --shadow: 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "gg sans", "Noto Sans", "Segoe UI", system-ui, sans-serif; }
a { color: #00a8fc; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { color: var(--head); margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 24px; } h2 { font-size: 19px; } h3 { font-size: 16px; } h4 { font-size: 14px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.row { display: flex; align-items: center; } .gap { gap: 8px; } .wrap { flex-wrap: wrap; } .grow { flex: 1; } .between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 20; height: 56px; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; background: var(--bg2); border-bottom: 1px solid var(--bg); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--head); font-weight: 700; font-size: 17px; }
.brand:hover { text-decoration: none; }
.logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--brand); font-size: 17px; }
.userbox { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--bg4); object-fit: cover; }

/* Layout */
.app { min-height: calc(100vh - 56px); }
.loading { padding: 60px; text-align: center; color: var(--muted); }
.container { max-width: 1100px; margin: 0 auto; padding: 32px 20px 120px; }
.guild-layout { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 56px); }
.sidebar { background: var(--bg2); padding: 16px 10px; border-right: 1px solid var(--bg); position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; }
.sidebar .guild-head { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.sidebar .guild-head img, .gicon { width: 40px; height: 40px; border-radius: 12px; background: var(--bg4); display: grid; place-items: center; font-weight: 700; color: var(--head); flex: none; }
.sidebar .guild-head b { color: var(--head); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--bg4); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--bg4); color: var(--head); }
.nav .sep { height: 1px; background: var(--line); margin: 8px 6px; }
.content { padding: 28px 32px 140px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* Cards */
.card { background: var(--bg2); border-radius: var(--radius); padding: 18px 20px; }
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.guilds { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.guild-card { background: var(--bg2); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.guild-card .gicon { width: 72px; height: 72px; border-radius: 24px; font-size: 22px; }
.guild-card img.gicon { object-fit: cover; }
.guild-card b { color: var(--head); }
.stat { background: var(--bg2); border-radius: var(--radius); padding: 16px 18px; }
.stat .v { font-size: 26px; font-weight: 700; color: var(--head); }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

/* Section (Accordion) */
details.section { background: var(--bg2); border-radius: var(--radius); margin-bottom: 10px; }
details.section > summary { cursor: pointer; list-style: none; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; font-weight: 600; color: var(--head); }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::after { content: '▸'; color: var(--muted); transition: transform .15s; }
details.section[open] > summary::after { transform: rotate(90deg); }
details.section > summary .desc { font-weight: 400; color: var(--muted); font-size: 12.5px; margin-left: 10px; }
details.section > .body { padding: 4px 18px 18px; border-top: 1px solid var(--line); }
details.sub { background: var(--bg3); border-radius: 6px; margin-top: 10px; }
details.sub > summary { cursor: pointer; padding: 10px 14px; font-weight: 600; color: var(--head); }
details.sub > .body { padding: 4px 14px 14px; }

/* Fields */
.field { padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,.04); }
.field:last-child { border-bottom: 0; }
.field > label, .field .flabel { display: block; font-weight: 600; color: var(--head); margin-bottom: 4px; font-size: 13.5px; }
.field .help { color: var(--muted); font-size: 12.5px; margin: 0 0 8px; }
.field.inline { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.field.inline > div:first-child { flex: 1; }
.field.inline .help { margin: 0; }
input[type=text], input[type=number], input[type=password], input[type=url], input[type=time], textarea, select {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--bg); border-radius: 6px; padding: 9px 10px; font: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
input[type=color] { width: 44px; height: 36px; border: 0; padding: 0; background: none; cursor: pointer; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--bg4); color: var(--text); }
.pill.premium { background: rgba(240,178,50,.15); color: var(--yellow); }
.pill.ok { background: rgba(35,165,90,.18); color: #57f287; }
.pill.bad { background: rgba(218,55,60,.18); color: #ff8b8e; }

/* Switch */
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #80848e; border-radius: 999px; cursor: pointer; transition: .15s; }
.switch span::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(18px); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg4); padding: 3px 6px 3px 10px; border-radius: 4px; font-size: 13px; }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.chip button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; }
.chip button:hover { color: var(--red); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--brand); color: #fff; border: 0; border-radius: 4px; padding: 8px 16px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--brand2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #4e5058; } .btn.secondary:hover { background: #6d6f78; }
.btn.success { background: var(--green); } .btn.success:hover { background: #1a8b4a; }
.btn.danger { background: var(--red); } .btn.danger:hover { background: #a12828; }
.btn.ghost { background: transparent; color: var(--text); } .btn.ghost:hover { text-decoration: underline; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.iconbtn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; padding: 4px 6px; border-radius: 4px; }
.iconbtn:hover { background: var(--bg4); color: var(--text); }

/* Panel list */
.panel-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.panel-tab { background: var(--bg2); color: var(--text); border: 1px solid transparent; border-radius: 6px; padding: 8px 14px; cursor: pointer; font: inherit; }
.panel-tab.active { border-color: var(--brand); color: var(--head); background: var(--bg4); }
.panel-tab .id { color: var(--muted); font-size: 12px; margin-left: 6px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; background: var(--bg2); padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px; }

/* Perm grid */
.perm-grid { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; }
.perm-grid .pname { font-size: 13px; padding: 4px 0; }
.tri { display: inline-flex; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.tri button { background: var(--bg); border: 0; color: var(--muted); width: 32px; height: 26px; cursor: pointer; font-size: 13px; }
.tri button.on.deny { background: var(--red); color: #fff; }
.tri button.on.neutral { background: #4e5058; color: #fff; }
.tri button.on.allow { background: var(--green); color: #fff; }
.perm-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

/* List editor */
.list-item { background: var(--bg3); border-radius: 6px; padding: 12px 14px; margin-bottom: 10px; }
.list-item .li-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-weight: 600; color: var(--head); }

/* Discord preview */
.preview { background: var(--bg3); border-radius: 6px; padding: 12px 14px; margin-top: 10px; }
.preview .pv-label { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; margin-bottom: 8px; }
.dmsg { display: flex; gap: 12px; }
.dmsg .dav { width: 40px; height: 40px; border-radius: 50%; background: var(--brand); flex: none; display: grid; place-items: center; }
.dmsg .dname { color: var(--head); font-weight: 600; }
.dmsg .dbot { background: var(--brand); color: #fff; font-size: 10px; padding: 1px 4px; border-radius: 3px; margin-left: 4px; font-weight: 600; vertical-align: 2px; }
.dmsg .dcontent { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.dembed { background: var(--bg2); border-left: 4px solid var(--brand); border-radius: 4px; padding: 8px 12px 10px; margin-top: 6px; max-width: 480px; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.dembed .et { color: var(--head); font-weight: 600; } .dembed .ed { white-space: pre-wrap; font-size: 13.5px; word-break: break-word; }
.dembed .ea { font-size: 12.5px; font-weight: 600; color: var(--head); }
.dembed .ef { font-size: 11.5px; color: var(--muted); grid-column: 1 / -1; }
.dembed .eimg { grid-column: 1 / -1; max-width: 100%; border-radius: 4px; }
.dembed .ethumb { width: 64px; height: 64px; border-radius: 4px; object-fit: cover; }
.dbuttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dbtn { padding: 5px 14px; border-radius: 3px; font-size: 13px; font-weight: 500; color: #fff; }
.dbtn.primary { background: var(--brand); } .dbtn.secondary { background: #4e5058; } .dbtn.success { background: #248046; } .dbtn.danger { background: var(--red); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: rgba(255,255,255,.02); }
.table-wrap { overflow-x: auto; }
.filter-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-row input, .filter-row select { max-width: 240px; }

/* Chart */
.chart { width: 100%; height: 220px; }
.chart rect.bar { fill: var(--brand); } .chart rect.bar:hover { fill: #7984f5; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart line { stroke: var(--line); }
.bar-row { display: grid; grid-template-columns: 160px 1fr 60px; gap: 10px; align-items: center; padding: 6px 0; }
.bar-track { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); }

/* Savebar & Toast */
.savebar { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(720px, calc(100% - 32px)); background: #111214; color: var(--head); border-radius: 8px; padding: 10px 12px 10px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; box-shadow: var(--shadow); z-index: 50; animation: up .2s ease; }
.savebar.shake { animation: shake .4s; }
@keyframes up { from { transform: translate(-50%, 30px); opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translate(calc(-50% - 6px)); } 40%, 80% { transform: translate(calc(-50% + 6px)); } }
.toast { position: fixed; right: 20px; top: 70px; background: var(--bg4); color: var(--head); padding: 12px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 60; max-width: 360px; border-left: 4px solid var(--green); }
.toast.error { border-left-color: var(--red); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.hero { text-align: center; padding: 80px 20px; }
.hero h1 { font-size: 34px; }
.hero p { color: var(--muted); max-width: 520px; margin: 10px auto 24px; font-size: 15px; }
.vars { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 16px; font-size: 12.5px; }
.vars code { cursor: pointer; }
.warn { background: rgba(240,178,50,.1); border: 1px solid rgba(240,178,50,.35); color: #f5d38a; border-radius: 6px; padding: 10px 14px; margin-bottom: 14px; }

@media (max-width: 860px) {
  .guild-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav .sep { display: none; }
  .content { padding: 20px 16px 140px; }
  .grid.cols-2, .grid.cols-3, .perm-cols { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 100px 1fr 50px; }
  .topbar { padding: 0 16px; }
}
