:root {
  --bg:  #111111;
  --s1:  #1e1e1e;
  --s2:  #282828;
  --bd:  #333333;
  --tx:  #f0f0f0;
  --mu:  #888888;
  --di:  #2e2e2e;
  --bl:  #b07cff;
  --pu:  #7c3aed;
  --re:  #ef4444;
  --or:  #f59e0b;
  --gr:  #10b981;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--tx);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: inherit; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 3px; }

/* ── SCREENS ── */
.screen { display: none; min-height: 100vh; width: 100%; }
.screen.active { display: flex; }
.screen-center { align-items: center; justify-content: center; }

/* ── LOADING ── */
.loading-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 14px;
  z-index: 999;
}
.loading-overlay.hidden { display: none; }
.hidden { display: none !important; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--bd);
  border-top-color: var(--bl);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--mu); font-size: 0.82rem; }

/* ── LOGIN ── */
.login-box {
  background: var(--s1);
  border: 1px solid var(--bd);
  border-radius: 16px;
  padding: 48px 56px;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  max-width: 420px; width: 90%;
  box-shadow: 0 0 80px rgba(0,0,0,0.5);
}
.login-logo {
  font-size: 1.8rem; font-weight: 900;
  background: linear-gradient(135deg, #c5b4e3, #7c7fab);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}
.login-sub { color: var(--mu); font-size: 0.82rem; text-align: center; line-height: 1.6; }
.btn-google {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 24px;
  background: #fff; color: #333;
  border: none; border-radius: 8px;
  font-size: 0.88rem; font-weight: 600;
  transition: background 0.15s;
}
.btn-google:hover { background: #f5f5f5; }

/* ── NOT ADMIN ── */
.notadmin-box {
  background: var(--s1); border: 1px solid var(--bd); border-radius: 16px;
  padding: 40px 48px; max-width: 400px; width: 90%;
  text-align: center; display: flex; flex-direction: column; gap: 14px;
}
.notadmin-icon { font-size: 2.4rem; }
.notadmin-box h2 { font-size: 1.1rem; font-weight: 700; }
.notadmin-box p { color: var(--mu); font-size: 0.82rem; line-height: 1.6; }

/* ── TOP BAR ── */
#top-bar {
  height: 52px;
  background: #3F006C;
  border-bottom: 1px solid #5c00a0;
  display: flex; align-items: center;
  padding: 0 20px; gap: 16px;
  position: sticky; top: 0; z-index: 10;
}
.app-logo {
  font-weight: 800; font-size: 1rem;
  background: linear-gradient(135deg, #c5b4e3, #7c7fab);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 8px;
}
.app-logo-img { height: 28px; width: auto; }
.sp { flex: 1; }
#user-info { display: flex; align-items: center; gap: 10px; }
#user-info .uname { font-size: 0.82rem; color: var(--mu); }

/* ── MAIN LAYOUT ── */
#screen-app { flex-direction: column; }
.app-body { flex: 1; padding: 24px; max-width: 860px; width: 100%; margin: 0 auto; }

/* ── TABS ── */
.tab-bar {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--bd);
  margin-bottom: 24px;
}
.tab-btn {
  padding: 8px 16px;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--mu); font-size: 0.84rem; font-weight: 600;
  margin-bottom: -1px; cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--tx); }
.tab-btn.active { color: var(--bl); border-bottom-color: var(--bl); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── SECTION HEADER ── */
.section-hd {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
  color: var(--mu); text-transform: uppercase;
  margin-bottom: 10px; margin-top: 24px;
}
.section-hd:first-child { margin-top: 0; }

/* ── USER ROWS ── */
.user-list { display: flex; flex-direction: column; gap: 6px; }
.user-row {
  background: var(--s1); border: 1px solid var(--bd); border-radius: 10px;
  padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
}
.user-row:hover { border-color: #444; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  border: 2px solid var(--bd);
}
.user-avatar-placeholder {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--pu); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 0.88rem; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.user-email { font-size: 0.74rem; color: var(--mu); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  font-size: 0.58rem; font-weight: 700; letter-spacing: 0.05em;
  padding: 2px 6px; border-radius: 4px; text-transform: uppercase;
}
.badge-admin { background: rgba(176,124,255,0.15); color: var(--bl); }
.badge-pending { background: rgba(245,158,11,0.15); color: var(--or); }
.user-joined { font-size: 0.7rem; color: var(--mu); flex-shrink: 0; }
.user-actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

/* ── NAME EDIT ── */
.name-edit-wrap { display: flex; align-items: center; gap: 6px; }
.name-input {
  background: var(--bg); border: 1px solid var(--bd); border-radius: 6px;
  color: var(--tx); padding: 4px 8px; font-size: 0.84rem;
  width: 160px;
}
.name-input:focus { outline: none; border-color: var(--bl); }

/* ── BUTTONS ── */
.btn {
  padding: 5px 12px; border-radius: 7px;
  border: 1px solid var(--bd); background: var(--s2);
  color: var(--tx); font-size: 0.78rem; font-weight: 600;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: #333; border-color: #555; }
.btn-primary { background: var(--pu); border-color: var(--pu); color: #fff; }
.btn-primary:hover { background: #6d28d9; border-color: #6d28d9; }
.btn-danger { background: transparent; border-color: var(--re); color: var(--re); }
.btn-danger:hover { background: rgba(239,68,68,0.1); }
.btn-sm { padding: 4px 10px; font-size: 0.74rem; }
.btn-logout { background: none; border: none; color: var(--mu); font-size: 0.8rem; padding: 5px 10px; border-radius: 6px; }
.btn-logout:hover { background: var(--s2); color: var(--tx); }

/* ── EMPTY STATE ── */
.empty { font-size: 0.78rem; color: var(--mu); padding: 16px 0; text-align: center; }

/* ── TOAST ── */
#toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 999; }
.toast {
  padding: 10px 18px; border-radius: 8px; font-size: 0.82rem; font-weight: 500;
  animation: slideIn 0.2s ease; pointer-events: none;
}
.toast.success { background: #064e3b; color: #6ee7b7; border: 1px solid #065f46; }
.toast.error   { background: #450a0a; color: #fca5a5; border: 1px solid #7f1d1d; }
.toast.info    { background: var(--s2); color: var(--tx); border: 1px solid var(--bd); }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── APP COUNT ── */
.app-count { font-size: 0.72rem; color: var(--mu); margin-left: auto; }

/* ── SETTINGS ── */
.settings-group { margin-bottom: 16px; }
.settings-label {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--mu); margin-bottom: 6px;
}
.settings-input {
  width: 100%; background: var(--s1); border: 1px solid var(--bd);
  border-radius: 8px; color: var(--tx); padding: 8px 12px;
  font-size: 0.84rem; font-family: monospace;
}
.settings-input:focus { outline: none; border-color: var(--bl); }
.settings-hint { font-size: 0.68rem; color: var(--mu); margin-top: 4px; }
.settings-hint code { font-family: monospace; color: var(--bl); }

/* ── APPS ── */
.app-form {
  background: var(--s1); border: 1px solid var(--bd); border-radius: 10px;
  padding: 16px; margin-bottom: 16px;
}
.app-form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
@media (max-width: 560px) { .app-form-grid { grid-template-columns: 1fr; } }
.app-card-list { display: flex; flex-direction: column; gap: 8px; }
.app-card {
  background: var(--s1); border: 1px solid var(--bd); border-radius: 10px;
  padding: 14px 16px; display: flex; align-items: flex-start; gap: 14px;
}
.app-card:hover { border-color: #444; }
.app-card-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--pu), #4f46e5);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
}
.app-card-body { flex: 1; min-width: 0; }
.app-card-name { font-weight: 700; font-size: 0.92rem; }
.app-card-key {
  font-size: 0.68rem; font-family: monospace;
  color: var(--bl); margin-top: 1px;
}
.app-card-desc { font-size: 0.78rem; color: var(--mu); margin-top: 4px; }
.app-card-links { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.app-card-link {
  font-size: 0.7rem; color: var(--mu); text-decoration: none;
  display: flex; align-items: center; gap: 4px;
}
.app-card-link:hover { color: var(--bl); }
.app-card-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── MODAL ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--s1); border: 1px solid var(--bd); border-radius: 14px;
  padding: 24px; width: 420px; max-width: 92vw;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.modal-title { font-weight: 700; font-size: 0.96rem; margin-bottom: 16px; }
.modal-body  { margin-bottom: 16px; }
.modal-footer { display: flex; gap: 8px; }
select.settings-input { cursor: pointer; }
