:root {
  color-scheme: dark;
  --bg: #313338;
  --bg-alt: #2b2d31;
  --bg-input: #1e1f22;
  --text: #f2f3f5;
  --text-muted: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #da373c;
  --border: #3f4147;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "gg sans", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

.loading, .login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
}

.login-screen h1 { margin: 0; font-size: 1.4rem; }

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--accent);
  color: white;
}
button:hover { background: var(--accent-hover); }
button.secondary { background: var(--bg-input); color: var(--text); }
button.secondary:hover { background: #26272b; }
button.danger { background: var(--danger); }
button.danger:hover { background: #a12d29; }

a.login-link, a.invite-link {
  display: inline-block;
  text-decoration: none;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}

header.topbar .user { display: flex; align-items: center; gap: 10px; }
header.topbar img { width: 32px; height: 32px; border-radius: 50%; }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
}

@media (max-width: 860px) {
  main { grid-template-columns: minmax(0, 1fr); padding: 16px; }
}

.tab-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.tab-button {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
}
.tab-button:hover { background: #26272b; color: var(--text); }
.tab-button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 999px;
  margin-right: 6px;
  vertical-align: middle;
}
.badge-open { background: rgba(87, 242, 135, 0.15); color: #57f287; }
.badge-closed { background: rgba(153, 170, 181, 0.2); color: #99aab5; }

.guild-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.guild-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 16px 6px 6px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.guild-chip:hover { border-color: #57595e; background: #26272b; }
.guild-chip.active { background: rgba(88, 101, 242, 0.15); border-color: var(--accent); color: var(--text); }
.guild-chip:disabled { opacity: 0.6; cursor: default; }
.guild-chip:disabled:hover { border-color: var(--border); background: var(--bg-input); }
.guild-chip.active:disabled:hover { border-color: var(--accent); background: rgba(88, 101, 242, 0.15); }

.loading-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 48px 18px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.guild-chip-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.guild-chip-fallback {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.guild-chip-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guild-chip-add {
  width: 44px;
  height: 44px;
  padding: 0;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1;
  text-decoration: unset;
}
.guild-chip-add:hover { color: var(--text); border-color: var(--accent); background: #26272b; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
}
.empty-state p { margin-bottom: 20px; color: var(--text-muted); }
.invite-button-large {
  padding: 14px 28px;
  font-size: 1.05rem;
}

.archive-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.archive-header h2 { margin: 0; }
.archive-header button { padding: 6px 14px; font-size: 0.8rem; }

.options-container { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.option-row { display: flex; gap: 8px; }
.option-row .option-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.9rem;
  font-family: inherit;
}
.option-row .remove-option { padding: 6px 10px; }
.add-option { margin-bottom: 8px; }

.panel {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0;
}

.panel h2 {
  margin-top: 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.panel h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  margin: 24px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.panel h3:first-of-type { margin-top: 16px; padding-top: 0; border-top: none; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.field input[type="text"],
.field input[type="url"],
.field textarea,
.field select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.95rem;
  font-family: inherit;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input[type="color"] {
  width: 48px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
}

.form-actions { display: flex; gap: 10px; margin-top: 16px; }

.embed-form-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 28px;
  align-items: start;
  min-width: 0;
}
.embed-form-fields, .embed-form-preview { min-width: 0; }
.embed-form-preview { position: sticky; top: 20px; }
@media (max-width: 820px) {
  .embed-form-layout { grid-template-columns: minmax(0, 1fr); }
  .embed-form-preview { position: static; }
}

.fields-container { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.field-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}
.field-row-inputs { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.field-row-inputs .field-name,
.field-row-inputs .field-value {
  width: 100%;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 0.9rem;
  font-family: inherit;
}
.field-row-inputs .field-value { min-height: 50px; resize: vertical; }
.inline-label { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--text-muted); }
.field-row .remove-field { padding: 6px 10px; align-self: flex-start; }
.add-field { margin-bottom: 8px; }

.embed-preview {
  border-left: 4px solid var(--accent);
  background: #2b2d31;
  border-radius: 4px;
  padding: 12px 16px;
  max-width: 430px;
}
.embed-preview .ep-author {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.embed-preview .ep-author-icon { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; }
.embed-preview .ep-title { display: block; font-weight: 700; margin-bottom: 4px; color: var(--text); text-decoration: none; }
.embed-preview a.ep-title:hover { text-decoration: underline; }
.embed-preview .ep-desc { font-size: 0.9rem; white-space: pre-wrap; color: #dbdee1; margin-bottom: 8px; }
.embed-preview .ep-fields { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.embed-preview .ep-field { width: 100%; font-size: 0.85rem; }
.embed-preview .ep-field-inline { width: calc(33.333% - 7px); }
@media (max-width: 480px) {
  .embed-preview .ep-field-inline { width: 100%; }
}
.embed-preview .ep-field-name { font-weight: 700; margin-bottom: 2px; }
.embed-preview .ep-field-value { color: #dbdee1; white-space: pre-wrap; }
.embed-preview .ep-thumb { max-width: 80px; max-height: 80px; border-radius: 4px; float: right; margin-left: 8px; }
.embed-preview .ep-image { max-width: 100%; border-radius: 4px; margin-top: 8px; clear: both; }
.embed-preview .ep-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 8px;
  clear: both;
}
.embed-preview .ep-footer-icon { width: 16px; height: 16px; border-radius: 50%; object-fit: cover; }
.embed-preview .ep-empty { color: var(--text-muted); font-style: italic; }

.embed-list { list-style: none; margin: 0; padding: 0; }
.embed-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.embed-list li:last-child { border-bottom: none; }
.embed-list .meta { overflow: hidden; }
.embed-list .meta .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.embed-list .meta .sub { font-size: 0.8rem; color: var(--text-muted); }
.embed-list .actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.embed-list .actions button { padding: 6px 10px; font-size: 0.8rem; }

@media (max-width: 480px) {
  .embed-list li { flex-direction: column; align-items: stretch; gap: 10px; }
  .embed-list .actions { justify-content: flex-start; }
}

.error-banner {
  background: rgba(218, 55, 60, 0.15);
  border: 1px solid var(--danger);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.hint { font-size: 0.8rem; color: var(--text-muted); }
.full-width { grid-column: 1 / -1; }
