/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d0f13;
  --bg2:         #13161c;
  --bg3:         #1a1e27;
  --border:      #252932;
  --text:        #e4e6eb;
  --text-muted:  #7a8090;
  --accent:      #02fe03;
  --accent-dim:  rgba(2,254,3,.12);
  --accent-glow: rgba(2,254,3,.25);
  --purple:      #7c5cfc;
  --purple-dim:  rgba(124,92,252,.15);
  --gold:        #f5c842;
  --silver:      #a8b4c0;
  --bronze:      #cd7f32;
  --danger:      #f04747;
  --success:     #43b581;
  --radius:      12px;
  --radius-sm:   8px;
  --sidebar-w:   240px;
  --transition:  .18s ease;
}

html { font-size: 15px; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
code {
  font-family: 'Fira Mono', 'Consolas', monospace;
  font-size: .85em;
  color: var(--text-muted);
}

/* ── App layout ───────────────────────────────────────────────────────────── */
body:not(.auth-page) {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-weight: 700;
  font-size: 1.1rem;
  padding: .25rem .5rem .75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  color: var(--accent);
  letter-spacing: .02em;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: .9rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item--active {
  background: var(--accent-dim);
  color: var(--accent);
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.sidebar__user-info { display: flex; flex-direction: column; min-width: 0; }
.sidebar__username {
  font-size: .88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar__logout {
  font-size: .78rem;
  color: var(--text-muted);
  transition: color var(--transition);
}
.sidebar__logout:hover { color: var(--danger); }

/* ── Avatar ───────────────────────────────────────────────────────────────── */
.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--border);
}
.avatar--placeholder {
  background: var(--accent-dim);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
}

/* ── Logo circle ──────────────────────────────────────────────────────────── */
.logo-circle {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 2px solid var(--accent);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.5rem;
  box-shadow: 0 0 20px var(--accent-glow);
}
.logo-circle--sm {
  width: 30px; height: 30px;
  font-size: .95rem;
  box-shadow: none;
}

/* ── Main area ────────────────────────────────────────────────────────────── */
.main {
  padding: 2rem 2.5rem;
  max-width: 1100px;
  width: 100%;
}

.page-header { margin-bottom: 2rem; }
.page-title { font-size: 1.6rem; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: .9rem; margin-top: .25rem; }

/* ── Section ──────────────────────────────────────────────────────────────── */
.section { margin-bottom: 2.5rem; }
.section-title {
  font-size: 1rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 1rem;
}

/* ── Flash messages ───────────────────────────────────────────────────────── */
.flash {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: .9rem;
  font-weight: 500;
}
.flash--error   { background: rgba(240,71,71,.15); border: 1px solid rgba(240,71,71,.4); color: #f87171; }
.flash--success { background: rgba(67,181,129,.12); border: 1px solid rgba(67,181,129,.4); color: var(--success); }

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  transition: border-color var(--transition);
}
.stat-card:hover { border-color: #3a3f4d; }

.stat-card__icon {
  width: 42px; height: 42px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-card__icon--text     { background: var(--accent-dim);  color: var(--accent); }
.stat-card__icon--voice    { background: var(--purple-dim);  color: var(--purple); }
.stat-card__icon--combined { background: rgba(245,200,66,.12); color: var(--gold); }

.stat-card__body { flex: 1; min-width: 0; }
.stat-card__label { font-size: .78rem; color: var(--text-muted); font-weight: 500; margin-bottom: .2rem; }
.stat-card__value { font-size: 1.8rem; font-weight: 700; line-height: 1; margin-bottom: .5rem; }
.stat-card__sub   { font-size: .75rem; color: var(--text-muted); margin-top: .35rem; }

/* ── XP bar ───────────────────────────────────────────────────────────────── */
.xp-bar {
  height: 8px; background: var(--bg3);
  border-radius: 99px; overflow: hidden;
}
.xp-bar__fill {
  height: 100%; background: var(--accent);
  border-radius: 99px;
  transition: width .4s ease;
  box-shadow: 0 0 6px var(--accent-glow);
}
.xp-bar__fill--voice { background: var(--purple); box-shadow: 0 0 6px rgba(124,92,252,.4); }
.xp-bar--sm { height: 5px; width: 100px; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: .5rem;
  margin-bottom: 1rem;
}
.tab {
  padding: .45rem 1rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: inherit;
  font-size: .88rem; font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.tab:hover { background: var(--bg3); color: var(--text); }
.tab--active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.tab-panel { display: none; }
.tab-panel--active { display: block; }

/* ── Leaderboard table ────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.lb-table {
  width: 100%; border-collapse: collapse;
  font-size: .88rem;
}
.lb-table thead tr {
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
}
.lb-table th {
  padding: .65rem 1rem; text-align: left;
  font-size: .75rem; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em;
}
.lb-table td {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.lb-table tbody tr:last-child td { border-bottom: none; }
.lb-table tbody tr { transition: background var(--transition); }
.lb-table tbody tr:hover { background: var(--bg3); }
.lb-row--me { background: var(--accent-dim) !important; }

.lb-rank { width: 48px; text-align: center; }
.lb-progress { width: 120px; }

.medal {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  font-weight: 700; font-size: .8rem;
  background: var(--bg3); color: var(--text-muted);
}
.medal--gold   { background: rgba(245,200,66,.2);  color: var(--gold);   box-shadow: 0 0 8px rgba(245,200,66,.3); }
.medal--silver { background: rgba(168,180,192,.15); color: var(--silver); }
.medal--bronze { background: rgba(205,127,50,.15);  color: var(--bronze); }

.level-badge {
  display: inline-block;
  background: var(--accent-dim); color: var(--accent);
  border-radius: 99px; padding: .15rem .5rem;
  font-size: .78rem; font-weight: 700;
}
.level-badge--voice { background: var(--purple-dim); color: var(--purple); }

.you-badge {
  display: inline-block; margin-left: .4rem;
  background: var(--accent-dim); color: var(--accent);
  border-radius: 99px; padding: .05rem .4rem;
  font-size: .7rem; font-weight: 700;
}

.role-badge {
  display: inline-block;
  background: rgba(124,92,252,.15); color: #a78bfa;
  border-radius: 99px; padding: .05rem .45rem;
  font-size: .7rem; font-weight: 600;
  letter-spacing: .01em;
}

.lb-user { display: flex; align-items: center; gap: .5rem; }

.lb-user__info {
  display: flex; flex-direction: column; gap: .15rem; line-height: 1.2;
}

.lb-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  border: 1px solid var(--border);
}
.lb-avatar--placeholder {
  background: var(--bg3); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .65rem 1.25rem;
  border-radius: var(--radius-sm);
  font-family: inherit; font-size: .9rem; font-weight: 600;
  cursor: pointer; border: none;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn--discord {
  background: #5865f2;
  color: #fff;
  gap: .5rem;
  font-size: 1rem;
  padding: .8rem 1.75rem;
  box-shadow: 0 4px 16px rgba(88,101,242,.35);
}
.btn--discord:hover { background: #4752c4; box-shadow: 0 4px 20px rgba(88,101,242,.5); transform: translateY(-1px); }
.btn--primary { background: var(--accent); color: #000; }
.btn--primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn--danger  { background: var(--danger); color: #fff; }
.btn--danger:hover { filter: brightness(1.1); }
.btn--full { width: 100%; }
.btn--sm { padding: .45rem .85rem; font-size: .85rem; }
.btn--xs { padding: .25rem .55rem; font-size: .76rem; }

/* ── Form elements ────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-label {
  display: flex; flex-direction: column; gap: .25rem;
  font-size: .88rem; font-weight: 600; margin-bottom: .5rem;
}
.form-hint { font-size: .78rem; color: var(--text-muted); font-weight: 400; }
.form-input {
  width: 100%; padding: .6rem .85rem;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: inherit; font-size: .9rem;
  transition: border-color var(--transition);
  resize: vertical;
}
.form-input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-input--sm { padding: .45rem .7rem; font-size: .85rem; }
select.form-input { cursor: pointer; }

.add-form__row {
  display: flex; gap: .75rem; align-items: center; flex-wrap: wrap;
}
.add-form__row .form-input--sm { flex: 1; min-width: 120px; }

.td-action { width: 90px; text-align: right; }
.empty-state { color: var(--text-muted); font-size: .88rem; padding: .5rem 0; }

/* ── Config editor ────────────────────────────────────────────────────────── */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}
.config-field { display: flex; flex-direction: column; gap: .35rem; }

.color-input-wrap { display: flex; gap: .5rem; align-items: center; }
.color-picker {
  width: 38px; height: 38px; padding: 2px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg3); cursor: pointer;
}
.config-actions { padding-top: .5rem; }

.text-muted { color: var(--text-muted); }

/* ── Auth page ────────────────────────────────────────────────────────────── */
.auth-page {
  display: flex !important;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(2,254,3,.04) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(124,92,252,.05) 0%, transparent 60%);
}
.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2.75rem 2.5rem;
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.setup-card { max-width: 500px; }

.auth-logo { margin-bottom: .25rem; }
.auth-title { font-size: 1.5rem; font-weight: 700; text-align: center; }
.auth-subtitle { font-size: .88rem; color: var(--text-muted); text-align: center; margin-bottom: .5rem; }

.setup-form { width: 100%; }

.setup-tip {
  display: flex; align-items: flex-start; gap: .5rem;
  background: rgba(124,92,252,.08); border: 1px solid rgba(124,92,252,.2);
  border-radius: var(--radius-sm); padding: .75rem;
  font-size: .8rem; color: var(--text-muted); line-height: 1.5;
  margin-top: .5rem;
}
.setup-tip svg { flex-shrink: 0; margin-top: 1px; color: var(--purple); }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body:not(.auth-page) {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: .75rem 1rem;
    gap: .75rem;
  }
  .sidebar__nav { flex-direction: row; flex: unset; }
  .sidebar__user { margin-top: 0; padding-top: 0; border-top: none; }
  .main { padding: 1.25rem; }
  .stats-grid { grid-template-columns: 1fr; }
}
