/* ============================================================
   Elysia Admin — Standalone Control Panel
   ============================================================ */

:root {
  --bg: #140a24;
  --surface: #241640;
  --surface-2: #2e1d54;
  --surface-3: #3a2870;
  --border: #4a2d7a;
  --text: #f5efe6;
  --muted: #b8a8d8;
  --accent: #e8c468;
  --accent-2: #b06bf5;
  --accent-3: #ff5e7a;
  --success: #6ee7a8;
  --warning: #fbbf24;
  --danger: #ef4444;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", "Cascadia Code", Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  background-image:
    radial-gradient(1000px 500px at 80% -10%, rgba(176, 107, 245, 0.14), transparent 60%),
    radial-gradient(800px 400px at 10% 10%, rgba(232, 196, 104, 0.08), transparent 60%);
  background-attachment: fixed;
}

/* ---- Layout ---- */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: linear-gradient(180deg, var(--surface) 0%, #1d1233 100%);
  border-right: 1px solid var(--border);
  padding: 0;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar__brand {
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, rgba(232, 196, 104, 0.07), rgba(176, 107, 245, 0.07));
}

.sidebar__logo {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  filter: drop-shadow(0 0 8px rgba(232, 196, 104, 0.4));
}

.sidebar__brand h1 {
  font-size: 19px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.02em;
}

.sidebar__brand span {
  font-size: 10px;
  color: var(--muted);
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.sidebar__nav {
  padding: 8px 0 16px;
  flex: 1;
}

.nav-section {
  padding: 18px 24px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  opacity: 0.7;
  font-family: var(--mono);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 24px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: all 0.15s;
  border-left: 3px solid transparent;
  position: relative;
}

.nav-item:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-item.is-active {
  color: var(--accent);
  background: linear-gradient(90deg, rgba(232, 196, 104, 0.1), transparent 80%);
  border-left-color: var(--accent);
}

.nav-item.is-active svg {
  filter: drop-shadow(0 0 6px rgba(232, 196, 104, 0.5));
}

.nav-item svg {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  opacity: 0.85;
}

.sidebar__footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}

.user-card img {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

#user-name { font-size: 13px; font-weight: 600; color: var(--text); }
.user-card__role {
  font-size: 10px;
  color: var(--accent);
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.sidebar__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.sidebar__btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--border);
  transition: all 0.15s;
  cursor: pointer;
}

.sidebar__btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar__btn--ghost {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar__btn--ghost:hover {
  background: var(--surface-3);
  border-color: var(--accent);
  color: var(--accent);
}

.sidebar__btn--danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(239,68,68,0.3);
}

.sidebar__btn--danger:hover {
  background: rgba(239,68,68,0.1);
  border-color: var(--danger);
}

.sidebar__copy {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}

/* ---- Main content ---- */
.main {
  flex: 1;
  padding: 32px 40px;
  overflow-y: auto;
}

.main__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.main__header h2 {
  font-size: 24px;
  font-weight: 700;
}

.main__header p {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}

.btn--primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a0a2e;
}

.btn--primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(232,196,104,0.3); }

.btn--ghost {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn--ghost:hover { background: var(--surface-3); }

.btn--danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--border);
}

.btn--danger:hover { background: rgba(239,68,68,0.1); border-color: var(--danger); }

.btn--sm { padding: 6px 12px; font-size: 13px; }

.btn svg { width: 16px; height: 16px; }

/* ---- Cards / Tables ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card__header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card__header h3 {
  font-size: 16px;
  font-weight: 600;
}

.card__body { padding: 20px; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge--hero { background: rgba(232,196,104,0.15); color: var(--accent); }
.badge--anti-hero { background: rgba(176,107,245,0.15); color: var(--accent-2); }
.badge--villain { background: rgba(255,94,122,0.15); color: var(--accent-3); }
.badge--other { background: rgba(184,168,216,0.15); color: var(--muted); }

/* ---- Forms ---- */
.form-group { margin-bottom: 20px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group select {
  cursor: pointer;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.member-list {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: var(--bg);
}

.member-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.member-check:hover { background: var(--surface); }
.member-check input { accent-color: var(--accent); }
.member-check em { color: var(--muted); font-size: 12px; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.is-open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal__header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal__header h3 { font-size: 18px; font-weight: 700; }

.modal__close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.modal__close:hover { color: var(--text); background: var(--surface-2); }

.modal__close svg { width: 22px; height: 22px; }

.modal__body { padding: 24px; }

.modal__footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* ---- Stats grid ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-card__label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-card__value {
  font-size: 32px;
  font-weight: 700;
}

.stat-card__value span {
  font-size: 14px;
  color: var(--muted);
  font-weight: 400;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s;
}

.toast.is-show { transform: translateY(0); opacity: 1; }
.toast--success { background: var(--success); color: #1a0a2e; }
.toast--error { background: var(--danger); color: #fff; }

/* ---- Empty state ---- */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

.empty svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: 0.5; }

/* ---- Actions cell ---- */
.actions {
  display: flex;
  gap: 8px;
}

/* ---- Page visibility ---- */
.page { display: none; }
.page.is-active { display: block; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--surface-3); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; }
  .sidebar__nav { display: flex; overflow-x: auto; padding: 8px; }
  .nav-item { padding: 10px 16px; border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; }
  .nav-item.is-active { border-left: none; border-bottom-color: var(--accent); }
  .main { padding: 20px; }
  .form-row { grid-template-columns: 1fr; }
}

/* ---- AI Chat ---- */
.ai-chat {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.ai-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-chat__msg {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  max-width: 85%;
}

.ai-chat__msg--user {
  margin-left: auto;
  flex-direction: row;
}

.ai-chat__avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--surface-3), var(--surface-2));
  border: 1px solid var(--border);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ai-chat__avatar img {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  filter: drop-shadow(0 0 4px rgba(232, 196, 104, 0.5));
}

.ai-chat__avatar svg {
  width: 20px;
  height: 20px;
}

.ai-chat__avatar--user {
  background: var(--muted);
}

.ai-title { display: flex; align-items: center; gap: 14px; }
.ai-title__logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  filter: drop-shadow(0 0 10px rgba(232, 196, 104, 0.45));
}

.ai-chat__bubble {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.ai-chat__msg--user .ai-chat__bubble {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.ai-chat__bubble p { margin: 0 0 8px; }
.ai-chat__bubble p:last-child { margin-bottom: 0; }
.ai-chat__bubble ul, .ai-chat__bubble ol { margin: 0 0 8px; padding-left: 20px; }
.ai-chat__bubble li { margin: 4px 0; }
.ai-chat__bubble strong { color: var(--accent); }
.ai-chat__msg--user .ai-chat__bubble strong { color: #fff; }
.ai-chat__bubble code {
  background: rgba(0,0,0,0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.ai-chat__bubble pre {
  background: rgba(0,0,0,0.3);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.ai-chat__bubble a { color: var(--accent); text-decoration: underline; }

/* Typing indicator */
.ai-chat__typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 18px;
}

.ai-chat__typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.4s infinite ease-in-out;
}

.ai-chat__typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-chat__typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input area */
.ai-chat__input-area {
  display: flex;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.ai-chat__input-area textarea {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

.ai-chat__input-area textarea:focus {
  border-color: var(--accent);
}

.ai-chat__input-area .btn {
  align-self: flex-end;
  white-space: nowrap;
}

/* Scrollbar */
.ai-chat__messages::-webkit-scrollbar { width: 6px; }
.ai-chat__messages::-webkit-scrollbar-track { background: transparent; }
.ai-chat__messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.ai-chat__messages::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* Universe Guide */
.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.guide-item {
  display: flex;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.02);
}

.guide-item--ok { border-left: 3px solid #4ade80; }
.guide-item--warn { border-left: 3px solid #facc15; }

.guide-item__icon svg {
  width: 20px;
  height: 20px;
  color: var(--accent);
}

.guide-item__body { flex: 1; min-width: 0; }

.guide-item__name {
  font-weight: 600;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.guide-item__status {
  font-size: 0.75rem;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.guide-item--ok .guide-item__status { background: rgba(74, 222, 128, 0.15); color: #4ade80; }
.guide-item--warn .guide-item__status { background: rgba(250, 204, 21, 0.15); color: #facc15; }

.guide-item__desc {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 3px;
}

.guide-item__detail {
  font-size: 0.78rem;
  color: var(--accent);
  margin-top: 6px;
  opacity: 0.9;
}

.guide-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

@media (max-width: 900px) {
  .guide-cols { grid-template-columns: 1fr; }
}

.card__header--do h3 { color: #4ade80; }
.card__header--dont h3 { color: #f87171; }
.card__hint { font-size: 0.78rem; color: var(--muted); font-weight: 400; }

.guide-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.guide-list li {
  font-size: 0.88rem;
  line-height: 1.5;
  padding-left: 24px;
  position: relative;
}

.guide-list--do li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: #4ade80;
  font-weight: 700;
}

.guide-list--dont li::before {
  content: "✗";
  position: absolute;
  left: 0;
  color: #f87171;
  font-weight: 700;
}

.guide-list strong { color: var(--text); }
.guide-list--do strong { color: #e2e8f0; }

.empty-note { color: var(--muted); font-size: 0.85rem; }

/* ---- List search toolbar ---- */
.list-toolbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-input {
  width: 100%;
  max-width: 340px;
  padding: 9px 14px 9px 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font);
  transition: border-color 0.15s, box-shadow 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b8a8d8' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
  background-size: 16px;
}

.search-input::placeholder { color: var(--muted); opacity: 0.7; }

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232, 196, 104, 0.12);
}
