:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f0f1f5;
  --border: #e3e5ec;
  --text: #1d1f26;
  --muted: #6b7080;
  --accent: #5865f2;
  --accent-soft: rgba(88, 101, 242, 0.12);
  --green: #23a55a;
  --green-soft: rgba(35, 165, 90, 0.12);
  --red: #e5484d;
  --red-soft: rgba(229, 72, 77, 0.12);
  --orange: #f0a020;
  --orange-soft: rgba(240, 160, 32, 0.14);
  --embed-bg: #f2f3f5;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214;
    --surface: #1b1c20;
    --surface-2: #232429;
    --border: #2e3036;
    --text: #e8e9ed;
    --muted: #9599a6;
    --accent: #7782ff;
    --accent-soft: rgba(119, 130, 255, 0.15);
    --embed-bg: #2b2d31;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111214;
  --surface: #1b1c20;
  --surface-2: #232429;
  --border: #2e3036;
  --text: #e8e9ed;
  --muted: #9599a6;
  --accent: #7782ff;
  --accent-soft: rgba(119, 130, 255, 0.15);
  --embed-bg: #2b2d31;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }

/* ── Boot / login ─────────────────────────────────────────── */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login {
  min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg);
}
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 40px 32px; width: 100%; max-width: 400px; text-align: center; box-shadow: var(--shadow); }
.login-card img { width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 16px; }
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card p { color: var(--muted); margin-bottom: 24px; }

/* ── Buttons & inputs ─────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; width: 100%; }

.input, .select, .textarea {
  width: 100%; min-height: 38px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { resize: vertical; min-height: 90px; font-family: inherit; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.color-input { display: flex; gap: 8px; }
.color-input input[type="color"] { width: 44px; height: 38px; padding: 2px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }

.check { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; user-select: none; }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.checks { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

/* ── Layout ───────────────────────────────────────────────── */
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.guild-switch { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.guild-switch:hover { background: var(--surface-2); }
.guild-switch .name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guild-switch .chev { color: var(--muted); }
.avatar { width: 36px; height: 36px; border-radius: 12px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; object-fit: cover; }
.avatar.round { border-radius: 50%; }
.avatar.lg { width: 56px; height: 56px; border-radius: 16px; font-size: 20px; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-section { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a .ico { width: 20px; text-align: center; }
.nav a .count { margin-left: auto; font-size: 11px; background: var(--red); color: #fff; padding: 0 7px; border-radius: 999px; font-weight: 700; }
.user-box { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.user-box .meta { flex: 1; min-width: 0; }
.user-box .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-box .meta span { color: var(--muted); font-size: 12px; }

.main { min-width: 0; padding: 28px 32px 64px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; letter-spacing: -.01em; }
.page-head p { color: var(--muted); margin-top: 2px; }
.topbar { display: none; }

/* ── Cards ────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15px; }
.card + .card, .stack > * + * { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .card + .card { margin-top: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: 8px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.stat .sub { color: var(--muted); font-size: 12px; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding: 20px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .bar i { width: 100%; max-width: 28px; background: var(--accent); border-radius: 6px 6px 3px 3px; min-height: 3px; opacity: .85; }
.bars .bar:hover i { opacity: 1; }
.bars .bar span { font-size: 10px; color: var(--muted); }

/* ── Tables / lists ───────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 20px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.toolbar .input, .toolbar .select { width: auto; flex: 1; min-width: 160px; }
.toolbar .select { flex: 0 0 auto; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.pager .btns { display: flex; gap: 8px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 32px; margin-bottom: 8px; }

/* ── Guild picker ─────────────────────────────────────────── */
.picker { max-width: 960px; margin: 0 auto; padding: 48px 16px; }
.picker h1 { font-size: 26px; text-align: center; }
.picker > p { text-align: center; color: var(--muted); margin: 6px 0 28px; }
.guilds { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.guild-card { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 24px 16px; cursor: pointer; text-align: center; transition: transform .15s, border-color .15s; }
.guild-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.guild-card b { font-size: 15px; }

/* ── Discord preview ──────────────────────────────────────── */
.preview { background: var(--embed-bg); border-radius: 10px; padding: 14px; }
.embed { border-left: 4px solid var(--accent); background: var(--surface); border-radius: 4px; padding: 10px 14px 12px; max-width: 520px; }
.embed .e-title { font-weight: 700; margin-bottom: 4px; }
.embed .e-desc { font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.embed .e-desc .sub { font-size: 12px; color: var(--muted); display: block; }
.embed .e-desc code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; font-size: 12px; }
.embed .e-desc .mention { background: var(--accent-soft); color: var(--accent); padding: 0 3px; border-radius: 3px; font-weight: 500; }
.embed img { max-width: 100%; border-radius: 6px; margin-top: 10px; }
.embed .e-foot { margin-top: 8px; font-size: 11.5px; color: var(--muted); }

/* ── Chat log ─────────────────────────────────────────────── */
.chat { max-height: 60vh; overflow-y: auto; }
.msg { display: flex; gap: 12px; padding: 10px 20px; }
.msg:hover { background: var(--surface-2); }
.msg .body { min-width: 0; flex: 1; }
.msg .head { display: flex; align-items: baseline; gap: 8px; }
.msg .head b { font-size: 14px; }
.msg .content { white-space: pre-wrap; word-break: break-word; }
.msg .atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.msg .atts img { max-width: 220px; max-height: 160px; border-radius: 8px; border: 1px solid var(--border); }

/* ── Emoji ────────────────────────────────────────────────── */
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; padding: 20px; }
.emoji-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border: 1px solid var(--border); border-radius: 12px; position: relative; }
.emoji-tile img { width: 40px; height: 40px; object-fit: contain; }
.emoji-tile span { font-size: 11px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emoji-tile .del { position: absolute; top: 4px; right: 4px; opacity: 0; }
.emoji-tile:hover .del { opacity: 1; }
.dropzone { border: 2px dashed var(--border); border-radius: 12px; padding: 24px; text-align: center; color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone img { width: 64px; height: 64px; object-fit: contain; margin: 0 auto 8px; }
.emoji-row { display: grid; grid-template-columns: 44px 1fr minmax(160px, 260px); gap: 12px; align-items: center; padding: 10px 20px; border-bottom: 1px solid var(--border); }
.emoji-row:last-child { border-bottom: none; }
.emoji-preview { width: 36px; height: 36px; display: grid; place-items: center; font-size: 22px; background: var(--surface-2); border-radius: 10px; }
.emoji-preview img { width: 24px; height: 24px; object-fit: contain; }

/* ── Modal & toast ────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(10, 12, 18, .55); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .15s; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; width: 100%; max-width: 640px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow); animation: pop .18s; }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-body.flush { padding: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--green); border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow); max-width: 360px; animation: pop .2s; }
.toast.error { border-left-color: var(--red); }

.text-row { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.text-row:last-child { border-bottom: none; }
.text-row .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.text-row .top code { font-size: 11px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-family: ui-monospace, monospace; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); padding: 2px 8px; border-radius: 6px; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.save-bar { position: sticky; bottom: 16px; display: flex; justify-content: flex-end; gap: 10px; padding: 12px 16px; margin-top: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 30; }
  .main { padding: 20px 16px 64px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-2 > .card + .card { margin-top: 0; }
  th, td { padding: 10px 14px; }
  .emoji-row { grid-template-columns: 40px 1fr; }
  .emoji-row > :last-child { grid-column: 1 / -1; }
}
