:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-soft: #1d2130;
  --border: #2a2f42;
  --text: #e8eaf2;
  --muted: #9aa0b5;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #ed4245;
  --ok: #57d6a2;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: inherit; }
.brand-mark { font-weight: 700; font-size: 20px; letter-spacing: 0.5px; }
.brand-sub { color: var(--muted); font-size: 13px; }

.user-chip { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.user-chip strong { color: var(--text); font-weight: 600; }

.page { padding: 32px 28px 56px; width: min(1120px, 100%); margin: 0 auto; flex: 1; }

#auth-gate, #dash { animation: fade 0.25s ease; }
#auth-gate h1, .dash-head h1 { font-size: 22px; margin: 0; }
#auth-gate p { color: var(--muted); max-width: 560px; line-height: 1.7; }

.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 4px; }
.muted { color: var(--muted); font-size: 14px; margin: 4px 0 20px; }

.guild-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.card:hover { border-color: #3b415c; transform: translateY(-2px); }

.card-top { display: flex; align-items: center; gap: 12px; }
.guild-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--panel-soft); object-fit: cover; flex-shrink: 0;
  display: grid; place-items: center; color: var(--muted); font-size: 20px; font-weight: 700;
}
.guild-name { font-weight: 600; font-size: 15px; word-break: break-all; }
.guild-id { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; }

.card-body { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.state-ok { color: var(--ok); }
.state-none { color: var(--muted); }

.card-actions { display: flex; gap: 10px; margin-top: auto; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: #3b415c; }
.btn-small { padding: 7px 12px; font-size: 13px; }

.error { color: var(--danger); font-size: 14px; }
.badge {
  background: var(--panel-soft); border: 1px solid var(--border); color: var(--muted);
  font-size: 11px; padding: 2px 8px; border-radius: 999px; margin-left: 8px;
}
.badge-dev {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #f59e0b;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 500;
}

.loading { display: grid; place-items: center; min-height: 40vh; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

.plugin-dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  min-width: min(440px, 88vw);
}
.plugin-dialog::backdrop { background: rgba(6, 8, 14, 0.65); }
.plugin-dialog h2 { margin: 0 0 14px; font-size: 17px; }
.plugin-list { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.plugin-list li {
  background: var(--panel-soft); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.plugin-list .p-state { color: var(--muted); font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; }

/* AI Assistant Console inside Dialog */
.ai-messages {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}
.chat-msg {
  padding: 8px 12px;
  border-radius: 8px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-msg.user {
  background: rgba(88, 101, 242, 0.15);
  border: 1px solid rgba(88, 101, 242, 0.3);
  color: var(--text);
  align-self: flex-end;
}
.chat-msg.ai {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  align-self: flex-start;
}
.ai-input-row {
  display: flex;
  gap: 8px;
}
.ai-input {
  flex: 1;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  color: var(--text);
  font-size: 13px;
}
.ai-input:focus {
  outline: none;
  border-color: var(--accent);
}

.footer { padding: 14px 28px; border-top: 1px solid var(--border); background: var(--panel); color: var(--muted); font-size: 12px; }
#api-base { font-family: ui-monospace, monospace; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
