/* ================================================================
   CSS Custom Properties (design tokens)
   ================================================================ */
:root {
  --kw-bg: #07101f;
  --kw-surface: #0e1c32;
  --kw-surface-alt: #132540;
  --kw-border: #1e3050;
  --kw-gold: #c9a227;
  --kw-gold-light: #e2bd5a;
  --kw-gold-dim: #7a5f14;
  --kw-text: #e8dfc8;
  --kw-text-muted: #8a9ab5;
  --kw-danger: #c0392b;
  --kw-success: #1f8f55;
  --kw-radius: 0.75rem;
}

/* ================================================================
   Base reset & global elements
   ================================================================ */
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--kw-bg);
  color: var(--kw-text);
  font-family: "Segoe UI", Tahoma, sans-serif;
  line-height: 1.5;
}

a { color: var(--kw-gold-light); text-decoration: none; }
a:hover { color: var(--kw-gold); text-decoration: underline; }

/* ================================================================
   App layout
   ================================================================ */
.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: #0a172b;
  border-right: 1px solid var(--kw-border);
  padding: 1rem;
}

.sidebar nav {
  display: grid;
  gap: 0.45rem;
  margin-top: 1rem;
}

.sidebar-link {
  display: block;
  border: 1px solid var(--kw-border);
  border-radius: 0.55rem;
  background: var(--kw-surface);
  padding: 0.5rem 0.7rem;
  color: var(--kw-text);
}

.sidebar-link:hover {
  text-decoration: none;
  border-color: var(--kw-gold-dim);
  color: var(--kw-gold-light);
}

.main-area {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ================================================================
   Topbar
   ================================================================ */
.topbar {
  background: var(--kw-surface);
  border-bottom: 1px solid var(--kw-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  padding: 0.75rem 1rem;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
}

.user-menu-wrap { position: relative; }

.user-menu-button {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  background: transparent;
  border: 1px solid var(--kw-border);
  color: var(--kw-text);
}

.user-menu-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--kw-gold-dim);
  object-fit: cover;
  background: #081224;
}

.user-menu-avatar-fallback {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--kw-gold-dim);
  background: var(--kw-surface-alt);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--kw-gold-light);
}

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  min-width: 220px;
  padding: 0.5rem;
  border-radius: 0.6rem;
  border: 1px solid var(--kw-border);
  background: var(--kw-surface);
  box-shadow: 0 8px 30px rgba(2, 7, 18, 0.45);
  display: none;
}

.user-menu-panel.open { display: block; }

.user-menu-meta {
  padding: 0.3rem 0.35rem 0.6rem;
  border-bottom: 1px solid var(--kw-border);
  margin-bottom: 0.5rem;
}

.user-menu-panel a {
  display: block;
  padding: 0.45rem 0.5rem;
  border-radius: 0.45rem;
  color: var(--kw-text);
}

.user-menu-panel a:hover {
  text-decoration: none;
  background: var(--kw-surface-alt);
}

/* ================================================================
   Main content shell & footer
   ================================================================ */
.shell { padding: 1rem; }
.shell-main { flex: 1; }

.app-footer {
  border-top: 1px solid var(--kw-border);
  background: var(--kw-surface);
  color: var(--kw-text-muted);
  font-size: 0.85rem;
  padding: 0.75rem 1rem;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  flex-wrap: wrap;
}

/* ================================================================
   Typography utilities
   ================================================================ */
.brand { color: var(--kw-gold); font-weight: 700; letter-spacing: 0.05em; }
.muted { color: var(--kw-text-muted); }
.section-title {
  margin: 0 0 0.65rem 0;
  color: var(--kw-gold-light);
  font-size: 1.05rem;
}

/* ================================================================
   Panels
   ================================================================ */
.panel {
  background: var(--kw-surface);
  border: 1px solid var(--kw-border);
  border-radius: var(--kw-radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.panel h1, .panel h2, .panel h3 { margin-top: 0; color: var(--kw-gold-light); }

/* ================================================================
   Nav links & pills
   ================================================================ */
.nav-links {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.pill-link {
  border: 1px solid var(--kw-border);
  border-radius: 999px;
  background: var(--kw-surface-alt);
  padding: 0.25rem 0.75rem;
}

/* ================================================================
   Grid & cards
   ================================================================ */
.grid {
  display: grid;
  gap: 0.75rem;
}

.grid.cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.card {
  background: var(--kw-surface-alt);
  border: 1px solid var(--kw-border);
  border-radius: var(--kw-radius);
  padding: 0.75rem;
}

.card .label { color: var(--kw-text-muted); font-size: 0.85rem; }
.card .value { font-size: 1.2rem; font-weight: 700; margin-top: 0.2rem; }

/* ================================================================
   Controls row
   ================================================================ */
.controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

/* ================================================================
   Form elements
   ================================================================ */
input, select, button, textarea {
  background: #0b1628;
  color: var(--kw-text);
  border: 1px solid var(--kw-border);
  border-radius: 0.45rem;
  padding: 0.45rem 0.6rem;
}

button {
  background: linear-gradient(135deg, #b5891c, var(--kw-gold));
  color: #0a0e1a;
  font-weight: 600;
  cursor: pointer;
}

button.primary {
  background: linear-gradient(135deg, #b5891c, var(--kw-gold));
  color: #0a0e1a;
}

button.secondary {
  background: var(--kw-surface-alt);
  color: var(--kw-text);
}

button.warning {
  background: linear-gradient(135deg, #aa7d1f, #d39c2d);
  color: #130e02;
}

button.danger {
  background: linear-gradient(135deg, #8d2d23, #c0392b);
  color: #fff1ef;
}

button:disabled { opacity: 0.6; cursor: not-allowed; }

/* Field group: label stacked above input */
.field-group {
  display: grid;
  gap: 0.35rem;
}

/* ================================================================
   Tom Select overrides
   ================================================================ */
.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
  background: #0b1628;
  color: var(--kw-text);
  border: 1px solid var(--kw-border);
  border-radius: 0.45rem;
  box-shadow: none;
}

.ts-wrapper.focus .ts-control {
  border-color: var(--kw-gold-dim);
  box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.2);
}

.ts-wrapper .ts-control input { color: var(--kw-text); }

.ts-dropdown {
  background: #0b1628;
  color: var(--kw-text);
  border: 1px solid var(--kw-border);
}

.ts-dropdown .active {
  background: var(--kw-surface-alt);
  color: var(--kw-gold-light);
}

.ts-wrapper.multi .ts-control > div {
  background: var(--kw-surface-alt);
  color: var(--kw-text);
  border: 1px solid var(--kw-border);
}

.ts-wrapper.plugin-remove_button .item .remove { color: var(--kw-text-muted); }

/* ================================================================
   Feedback / alert banners
   ================================================================ */
.feedback {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.45rem;
  border: 1px solid var(--kw-border);
  background: #0b1628;
}

.feedback.success {
  border-color: rgba(31, 143, 85, 0.8);
  color: #8ff0bb;
}

.feedback.error {
  border-color: rgba(192, 57, 43, 0.8);
  color: #ffb0a6;
}

/* ================================================================
   Tables
   ================================================================ */
table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: var(--kw-radius);
}

th, td {
  border-bottom: 1px solid var(--kw-border);
  padding: 0.55rem 0.6rem;
  text-align: left;
}

th { background: var(--kw-surface-alt); color: var(--kw-gold-light); }

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable .sort-indicator {
  margin-left: 0.35rem;
  color: var(--kw-text-muted);
  font-size: 0.75rem;
}

tr:nth-child(even) td { background: rgba(255, 255, 255, 0.015); }

/* ================================================================
   Code / pre blocks
   ================================================================ */
pre {
  background: #081224;
  border: 1px solid var(--kw-border);
  border-radius: var(--kw-radius);
  padding: 0.75rem;
  overflow-x: auto;
}

/* ================================================================
   Status pills
   ================================================================ */
.status-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.78rem;
  border: 1px solid var(--kw-border);
  background: #0b1628;
}

.status-pill.ok      { color: #8ff0bb; border-color: rgba(31, 143, 85, 0.8); }
.status-pill.warn    { color: #ffd591; border-color: rgba(201, 162, 39, 0.8); }
.status-pill.bad     { color: #ffb0a6; border-color: rgba(192, 57, 43, 0.8); }
.status-pill.planned { color: #a0c4ff; border-color: rgba(100, 149, 237, 0.8); }

/* Live-pulse animation (auto-refresh active indicator) */
@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(143, 240, 187, 0.08); }
  50%       { box-shadow: 0 0 0 6px rgba(143, 240, 187, 0.2); }
}

.status-pill.live-pulse { animation: livePulse 2s ease-in-out infinite; }

/* ================================================================
   Icon thumbnails & placeholders
   ================================================================ */
.icon-thumb {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 0.3rem;
  border: 1px solid var(--kw-border);
  background: #081224;
}

.icon-placeholder {
  width: 28px;
  height: 28px;
  border: 1px solid var(--kw-border);
  border-radius: 0.3rem;
  background: #081224;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ================================================================
   Spinner
   ================================================================ */
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(138, 154, 181, 0.3);
  border-top-color: var(--kw-gold-light);
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
}

/* ── Button loading state ─────────────────────────────────────────── */
button.loading {
  pointer-events: none;
  opacity: 0.75;
}
button.loading::after {
  content: "";
  display: inline-block;
  width: 0.65em;
  height: 0.65em;
  margin-left: 0.45em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: -0.1em;
}

/* ================================================================
   Modals
   ================================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 16, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 1rem;
}

#error-modal-backdrop { z-index: 100; }
.modal-backdrop.open { display: flex; }
.modal-backdrop .modal {
  box-shadow: 0 24px 60px rgba(1, 6, 14, 0.45);
}
.modal-backdrop.info .modal {
  border-color: rgba(31, 143, 85, 0.3);
}
.modal-backdrop.warning .modal {
  border-color: rgba(226, 189, 90, 0.35);
}
.modal-backdrop.error .modal {
  border-color: rgba(192, 57, 43, 0.35);
}
.modal-backdrop.info .modal-header {
  background: var(--kw-surface-alt);
  color: var(--kw-text);
  border-bottom: 1px solid rgba(138, 154, 181, 0.16);
}
.modal-backdrop.warning .modal-header {
  background: linear-gradient(90deg, rgba(226, 189, 90, 0.18), rgba(226, 189, 90, 0.3));
  color: var(--kw-text);
  border-bottom: 1px solid rgba(226, 189, 90, 0.25);
}
.modal-backdrop.error .modal-header {
  background: linear-gradient(90deg, rgba(192, 57, 43, 0.2), rgba(192, 57, 43, 0.34));
  color: #fff1ef;
  border-bottom: 1px solid rgba(192, 57, 43, 0.28);
}
#page-content-shell.blurred {
  filter: blur(2px);
  transition: filter 0.2s ease;
}

.modal {
  width: min(680px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--kw-surface);
  border: 1px solid var(--kw-border);
  border-radius: var(--kw-radius);
  padding: 1rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: -1rem -1rem 0.75rem -1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--kw-radius) var(--kw-radius) 0 0;
}

.modal-header h3 {
  margin: 0;
}

/* ================================================================
   Charts
   ================================================================ */
.chart-wrap {
  background: #081224;
  border: 1px solid var(--kw-border);
  border-radius: var(--kw-radius);
  padding: 0.5rem;
}

/* ================================================================
   Inline badges (for mentions, roles, labels inside text)
   ================================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--kw-border);
  font-size: 0.75rem;
  line-height: 1.25;
  white-space: nowrap;
  background: #0b1628;
  color: var(--kw-text);
}

.badge.secondary { background: var(--kw-surface-alt); }
.badge.warning   { background: rgba(201, 162, 39, 0.15); color: var(--kw-gold-light); border-color: var(--kw-gold-dim); }
.badge.muted     { color: var(--kw-text-muted); }

/* ================================================================
   Responsive
   ================================================================ */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--kw-border);
  }
}

/* ================================================================
   Auth shell (login / access denied)
   ================================================================ */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

/* ================================================================
   Login page
   ================================================================ */
.login-shell {
  width: min(620px, 100%);
  display: grid;
  gap: 1.25rem;
}

.login-panel {
  background:
    radial-gradient(1200px 250px at -10% -25%, rgba(88, 101, 242, 0.22), transparent 45%),
    radial-gradient(800px 180px at 120% 120%, rgba(201, 162, 39, 0.16), transparent 45%),
    var(--kw-surface);
  border: 1px solid rgba(110, 134, 188, 0.32);
  border-radius: 1.15rem;
  padding: 2rem;
  box-shadow: 0 28px 64px rgba(2, 7, 18, 0.5);
  backdrop-filter: blur(3px);
}

.login-header {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 1.35rem;
}

.login-title-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.discord-badge {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.75rem;
  background: rgba(88, 101, 242, 0.16);
  border: 1px solid rgba(88, 101, 242, 0.5);
}

.discord-badge svg {
  width: 21px;
  height: 21px;
  fill: #8ea2ff;
}

.login-title {
  margin: 0;
  line-height: 1.15;
}

.login-subtitle {
  margin: 0;
  color: var(--kw-text-muted);
  font-size: 1.15rem;
  line-height: 1.45;
}

.discord-login-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.95rem 1rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #5865f2;
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}

.discord-login-btn:hover {
  text-decoration: none;
  background: #4f5bdd;
  color: #fff;
}

.discord-login-btn:focus-visible {
  outline: 2px solid #8ea2ff;
  outline-offset: 2px;
}

.discord-login-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.login-meta {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--kw-text-muted);
}

/* ================================================================
   Dashboard – overview cards
   ================================================================ */
.overview-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.overview-card {
  display: block;
  text-decoration: none;
  background: #0b1628;
  border: 1px solid var(--kw-border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
}

.overview-card .label {
  color: var(--kw-text-muted);
  font-size: 0.82rem;
}

.overview-card .value {
  margin-top: 0.2rem;
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--kw-text);
}

/* ================================================================
   User Management page
   ================================================================ */
.users-toolbar { display: grid; gap: 0.55rem; }

.users-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.users-toolbar-row.live   { margin-bottom: 0.1rem; }
.users-toolbar-row.search { margin-bottom: 0.15rem; }

.users-toolbar-row input[type="text"],
.users-toolbar-row input[type="number"],
.users-toolbar-row select { min-width: 110px; }

#search { min-width: min(360px, 55vw); }

.users-toolbar .check-option {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.filter-tristate {
  padding: 0.2rem 0.6rem;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.filter-tristate[data-filter-state="is"] {
  background: rgba(31, 143, 85, 0.2);
  border-color: rgba(31, 143, 85, 0.5);
  color: #6fcf97;
}

.filter-tristate[data-filter-state="is-not"] {
  background: rgba(192, 57, 43, 0.2);
  border-color: rgba(192, 57, 43, 0.5);
  color: #e57368;
}

#users-last-updated { margin-left: auto; white-space: nowrap; }

@media (max-width: 1100px) {
  #users-last-updated { margin-left: 0; width: 100%; }
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--kw-border);
  object-fit: cover;
  background: #081224;
}

.user-avatar-shell {
  position: relative;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.user-avatar-shell .icon-placeholder {
  width: 38px;
  height: 38px;
  border-radius: 999px;
}

/* Presence indicator dots (user list) */
.presence-indicator {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid var(--kw-surface);
  box-shadow: 0 0 0 1px rgba(30, 48, 80, 0.8);
}

.presence-indicator.online  { background: #2ecc71; }
.presence-indicator.idle    { background: #f1c40f; }
.presence-indicator.dnd     { background: #e74c3c; }
.presence-indicator.offline { background: #6d7b96; }

.presence-indicator.mobile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #041629;
}

.presence-indicator.mobile.online { background: #2ecc71; }
.presence-indicator.mobile.idle   { background: #f1c40f; }
.presence-indicator.mobile.dnd    { background: #e74c3c; }

.presence-indicator.mobile svg { width: 10px; height: 10px; fill: currentColor; }

/* Voice state flags */
.voice-flags { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.25rem; }

.voice-flag {
  font-size: 0.72rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  border: 1px solid var(--kw-border);
  background: #0b1628;
  color: var(--kw-text-muted);
}

/* Role badges (user list) */
.role-badges { display: flex; flex-wrap: wrap; gap: 0.28rem; }

.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--kw-border);
  font-size: 0.72rem;
  line-height: 1.25;
  white-space: nowrap;
  background: #0b1628;
  color: var(--kw-text);
}

/* ================================================================
   User Detail page
   ================================================================ */
.profile-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 0.75rem;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 999px;
  border: 1px solid var(--kw-border);
  background: #081224;
  object-fit: cover;
}

.profile-avatar-shell {
  position: relative;
  width: 72px;
  height: 72px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.profile-avatar-shell .icon-placeholder {
  width: 72px;
  height: 72px;
  border-radius: 999px;
}

/* Presence indicator (user detail profile) */
.profile-presence-indicator {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid var(--kw-surface);
  box-shadow: 0 0 0 1px rgba(30, 48, 80, 0.8);
}

.profile-presence-indicator.online  { background: #2ecc71; }
.profile-presence-indicator.idle    { background: #f1c40f; }
.profile-presence-indicator.dnd     { background: #e74c3c; }
.profile-presence-indicator.offline { background: #6d7b96; }

.profile-presence-indicator.mobile {
  color: #041629;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.profile-presence-indicator.mobile.online { background: #2ecc71; }
.profile-presence-indicator.mobile.idle   { background: #f1c40f; }
.profile-presence-indicator.mobile.dnd    { background: #e74c3c; }

.profile-presence-indicator.mobile svg { width: 10px; height: 10px; fill: currentColor; }

/* Role badges (user detail) */
.profile-role-badges { margin-top: 0.35rem; display: flex; flex-wrap: wrap; gap: 0.3rem; }

.profile-role-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--kw-border);
  font-size: 0.72rem;
  line-height: 1.25;
  white-space: nowrap;
  background: #0b1628;
  color: var(--kw-text);
}

/* ================================================================
   Live Chat page
   ================================================================ */
.chat-message {
  display: flex;
  gap: 0.75rem;
  padding: 0.55rem 0.25rem;
  border-bottom: 1px solid var(--kw-border);
  position: relative;
}

.chat-message:last-child { border-bottom: none; }
.chat-message:hover { background: rgba(255, 255, 255, 0.03); }

.chat-avatar-wrap {
  flex-shrink: 0;
  width: 40px;
  height: 36px;
  position: relative;
  align-self: flex-start;
}

.chat-avatar { width: 36px; height: 36px; border-radius: 50%; display: block; }

.chat-presence {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--kw-surface);
  position: absolute;
  bottom: 0;
  right: 0;
}

.chat-presence.online  { background: #43b581; }
.chat-presence.idle    { background: #faa61a; }
.chat-presence.dnd     { background: #f04747; }
.chat-presence.offline { background: #747f8d; }

.chat-body { flex: 1; min-width: 0; }

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 0.1rem;
}

.chat-name { font-weight: 600; }
.chat-ts { font-size: 0.78em; color: var(--kw-text-muted); }

.chat-content {
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.45;
}

.chat-content .discord-heading {
  color: inherit;
  font-weight: 700;
  margin: 0 0 0.15rem;
  line-height: 1.35;
}

.chat-content .discord-heading-1 {
  font-size: 1.45em;
}

.chat-content .discord-heading-2 {
  font-size: 1.3em;
}

.chat-content .discord-heading-3 {
  font-size: 1.15em;
}

.chat-content .discord-heading-4 {
  font-size: 1.05em;
}

.chat-content .discord-heading-5 {
  font-size: 0.95em;
}

.chat-content .discord-heading-6 {
  font-size: 0.85em;
}

.chat-content ul,
.chat-content ol {
  margin: 0.2rem 0 0.2rem 1.25rem;
  padding: 0;
  line-height: 1.35;
}

.chat-content li {
  margin: 0;
}

.chat-emoji { width: 22px; height: 22px; vertical-align: middle; object-fit: contain; }

/* Reply-to banner */
.chat-reply {
  font-size: 0.8em;
  color: var(--kw-text-muted);
  margin-bottom: 0.3rem;
  padding-left: 0.6rem;
  border-left: 2px solid var(--kw-border);
  display: flex;
  gap: 0.3rem;
  align-items: baseline;
  flex-wrap: wrap;
}

.chat-reply a { text-decoration: none; }

.chat-reply-author { font-weight: 600; color: var(--kw-gold-light); }
.chat-reply-author:hover { text-decoration: underline; }

.chat-reply-content {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40ch;
}

/* Reactions */
.chat-reactions { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }

.chat-reaction {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--kw-border);
  border-radius: 12px;
  padding: 0.1rem 0.45rem;
  font-size: 0.82em;
}

.chat-reaction img { width: 18px; height: 18px; object-fit: contain; }

/* Hover action buttons */
.chat-actions {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

.chat-message:hover .chat-actions { opacity: 1; pointer-events: all; }

.chat-actions button {
  padding: 0.12rem 0.4rem;
  font-size: 0.72em;
  line-height: 1.4;
  border-radius: 0;
}

/* Channel select optgroup styling */
#channel-select optgroup { font-style: normal; }

/* ================================================================
   Audit Log page
   ================================================================ */
.audit-user-picker { position: relative; min-width: 300px; }

.audit-user-picker .picker-input-wrap { display: flex; gap: 0.35rem; }

.audit-user-picker input { width: 100%; }

.audit-user-picker .picker-clear { padding: 0.45rem 0.6rem; }

.audit-user-picker .picker-panel {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--kw-border);
  border-radius: 0.55rem;
  background: #0b1628;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  z-index: 40;
  display: none;
}

.audit-user-picker .picker-panel.open { display: block; }

.audit-user-picker .picker-option {
  width: 100%;
  background: transparent;
  border: 0;
  border-bottom: 1px solid rgba(30, 48, 80, 0.6);
  color: var(--kw-text);
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-radius: 0;
  font-weight: 500;
}

.audit-user-picker .picker-option:hover {
  background: var(--kw-surface-alt);
  color: var(--kw-gold-light);
}

.audit-user-picker .picker-empty { padding: 0.5rem 0.65rem; color: var(--kw-text-muted); }

.audit-content {
  max-width: 500px;
  overflow: hidden;
  text-overflow: ellipsis;
  word-wrap: anywhere;
}

/* JSON syntax highlighting in audit detail modal */
#audit-detail-metadata .json-string  { color: #6abf69; }
#audit-detail-metadata .json-number  { color: #49a8f0; }
#audit-detail-metadata .json-boolean { color: #f08d49; font-weight: bold; }
#audit-detail-metadata .json-null    { color: #f04949; font-weight: bold; }
#audit-detail-metadata .json-key     { color: #f0c849; }
#audit-detail-metadata .json-bracket { color: #f0f0f0; }

/* ================================================================
   Blacklist page
   ================================================================ */
.badge-blacklisted { background: rgba(192, 57, 43, 0.18); color: #e57368; border-color: rgba(192, 57, 43, 0.45); }
.badge-cleared     { background: rgba(31, 143, 85, 0.15);  color: #6fcf97; border-color: rgba(31, 143, 85, 0.4); }
.badge-attempts    { background: rgba(230, 126, 34, 0.15); color: #f39c12; border-color: rgba(230, 126, 34, 0.4); }

.actions-vertical {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  min-width: 9rem;
}

.actions-vertical button { width: 100%; }

#edit-reason-text { width: 100%; min-height: 7rem; resize: vertical; }

.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }

/* ================================================================
   Item Management page
   ================================================================ */
.icon-upload-grid {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 0.75rem;
  align-items: stretch;
}

.icon-preview-large {
  width: 110px;
  height: 110px;
  border-radius: 0.6rem;
  border: 1px solid var(--kw-border);
  object-fit: contain;
  background: #081224;
}

.icon-preview-shell {
  width: 110px;
  height: 110px;
  border-radius: 0.6rem;
  border: 1px solid var(--kw-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #081224;
}

.dropzone {
  border: 1px dashed var(--kw-border);
  border-radius: 0.6rem;
  padding: 0.8rem;
  background: #081224;
  color: var(--kw-text-muted);
  display: grid;
  gap: 0.6rem;
}

.dropzone.dragover { border-color: var(--kw-gold); color: var(--kw-gold-light); }

.item-icon-cell .icon-thumb,
.item-icon-cell .icon-placeholder { width: 56px; height: 56px; border-radius: 0.45rem; }

.item-form-grid { display: grid; gap: 0.75rem; }
.item-form-grid .controls label { min-width: 130px; }

/* ================================================================
   Treasure Hunt page
   ================================================================ */
.treasure-form-grid { display: grid; gap: 0.8rem; }

.treasure-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}

.treasure-field { display: grid; gap: 0.35rem; }

.treasure-field label { font-size: 0.88rem; color: var(--kw-text-muted); }

.reward-item-cell { display: inline-flex; align-items: center; gap: 0.55rem; }
