:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2f4059;
  --text: #e8eef7;
  --muted: #8fa3bf;
  --accent: #5b8def;
  --accent-hover: #7aa3f5;
  --naxx: #a78bfa;
  --aq40: #fbbf24;
  --success: #34d399;
  --error: #f87171;
  --discord: #5865f2;
  --radius: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.bg-pattern {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(91, 141, 239, 0.12), transparent 40%),
    radial-gradient(circle at 80% 0%, rgba(167, 139, 250, 0.1), transparent 35%),
    radial-gradient(circle at 50% 100%, rgba(251, 191, 36, 0.08), transparent 40%);
  pointer-events: none;
  z-index: 0;
}

.container {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.logo {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.logo.small { font-size: 1.1rem; margin-bottom: 0.25rem; }

h1 {
  margin: 0.25rem 0 0;
  font-size: 1.75rem;
}

h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  color: var(--muted);
  font-weight: 600;
}

.subtitle, .hint {
  color: var(--muted);
  margin: 0.35rem 0 0;
}

.error-banner {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--error);
  font-size: 0.9rem;
  text-align: left;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.login-card {
  max-width: 420px;
  margin: 10vh auto 0;
  text-align: center;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.user-panel {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-name { color: var(--muted); font-size: 0.95rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-card.naxx { border-color: rgba(167, 139, 250, 0.45); }
.stat-card.aq40 { border-color: rgba(251, 191, 36, 0.45); }

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0 1.25rem;
}

.last-sync, .sync-status { color: var(--muted); font-size: 0.9rem; }

body.sync-active {
  padding-bottom: 4.5rem;
}

.sync-progress-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 0.85rem 1.25rem 1rem;
  background: rgba(26, 35, 50, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
}

.sync-progress-bar[hidden] {
  display: none;
}

.sync-progress-text {
  margin: 0 0 0.55rem;
  font-size: 0.92rem;
  color: var(--text);
}

.sync-progress-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.sync-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #7dd3fc);
  border-radius: 999px;
  transition: width 0.35s ease;
}

.sync-progress-fill.indeterminate {
  width: 35%;
  animation: sync-indeterminate 1.4s ease-in-out infinite;
}

@keyframes sync-indeterminate {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(420%); }
}

.filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}

.search-card { margin-bottom: 1rem; }

.filter-drawer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  visibility: hidden;
}

.filter-drawer.is-open {
  pointer-events: auto;
  visibility: visible;
}

.filter-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.filter-drawer.is-open .filter-backdrop {
  opacity: 1;
}

.filter-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(22rem, 92vw);
  height: 100%;
  margin: 0;
  border-radius: 0;
  border-right: none;
  border-top: none;
  border-bottom: none;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.filter-drawer.is-open .filter-panel {
  transform: translateX(0);
}

body.filter-drawer-open {
  overflow: hidden;
}

.filter-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.filter-panel-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.filter-close-btn {
  min-width: 2.25rem;
  padding: 0.35rem 0.5rem;
  font-size: 1.1rem;
  line-height: 1;
}

.filter-panel-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.filter-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.filter-section select,
.filter-section input[type="number"] {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.92rem;
}

.class-filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.class-filter-chip {
  position: relative;
  cursor: pointer;
}

.class-filter-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.class-filter-chip .class-badge {
  display: block;
  width: 100%;
  text-align: center;
  opacity: 0.45;
  transition: opacity 0.15s ease, box-shadow 0.15s ease;
}

.class-filter-chip input:checked + .class-badge {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--accent);
}

.raid-filter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.raid-filter-chip {
  cursor: pointer;
}

.raid-filter-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.raid-filter-chip .raid-tag {
  display: inline-block;
  cursor: pointer;
  transition: box-shadow 0.15s ease;
}

.raid-filter-chip input:checked + .raid-tag {
  box-shadow: 0 0 0 2px var(--accent);
}

.filter-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filter-check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  color: var(--text);
  font-size: 0.92rem;
}

.filter-note {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.filter-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.is-hidden { display: none !important; }

.class-badge {
  --class-color: #6b7280;
  display: inline-block;
  padding: 0.18rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: color-mix(in srgb, var(--class-color) 28%, transparent);
  color: var(--class-color);
  border: 1px solid color-mix(in srgb, var(--class-color) 50%, transparent);
}

.class-priest.class-badge,
.class-rogue.class-badge {
  color: #1f2937;
  background: color-mix(in srgb, var(--class-color) 75%, #374151);
  border-color: color-mix(in srgb, var(--class-color) 85%, #6b7280);
}

tr.row-inactive td {
  opacity: 0.72;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.search-form input[type="search"] {
  flex: 1;
  min-width: 200px;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
}

.live-result {
  margin-top: 0.75rem;
  color: var(--accent);
  font-size: 0.92rem;
}

.player-link {
  color: var(--text);
  text-decoration: none;
}

.player-link:hover { color: var(--accent); }

.wcl-link {
  color: inherit;
  font-weight: 600;
  text-decoration: none;
}

.wcl-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.date { font-variant-numeric: tabular-nums; color: var(--muted); }
.muted { color: var(--muted); font-size: 0.9em; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-discord {
  margin-top: 1.5rem;
  background: var(--discord);
  color: #fff;
  width: 100%;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  padding: 0.75rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable:hover {
  color: var(--text);
}

th.sortable.sorted {
  color: var(--accent);
}

.sort-indicator {
  font-size: 0.7rem;
  opacity: 0.85;
}

.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, monospace; color: var(--muted); }
.total { font-weight: 700; color: var(--accent); }

.empty { color: var(--muted); margin: 0; }

.tab-nav {
  display: inline-flex;
  gap: 0.35rem;
  padding: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.tab-btn {
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.tab-btn.active,
.tab-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.import-panel { width: min(36rem, 96vw); }

.import-instructions {
  margin: 0.5rem 0 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.85rem;
}

.import-instructions summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
}

.import-instructions ol {
  margin: 0.65rem 0 0;
  padding-left: 1.25rem;
}

.import-instructions li + li {
  margin-top: 0.35rem;
}

.import-instructions code,
.import-instructions kbd {
  font-family: ui-monospace, monospace;
  font-size: 0.9em;
}

.import-instructions kbd {
  padding: 0.1rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

.import-textarea {
  width: 100%;
  min-height: 240px;
  margin: 0.75rem 0 1rem;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  resize: vertical;
}

.import-status {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 1.25rem;
}

.item-icon {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 0.5rem;
  border: 1px solid var(--border);
  background: #111;
}

.item-icon.large {
  width: 44px;
  height: 44px;
}

.loot-item-btn,
.player-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}

.loot-item-btn:hover,
.player-btn:hover {
  color: var(--accent);
}

.loot-item-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.loot-tags { display: inline-flex; gap: 0.25rem; flex-wrap: wrap; }

.loot-tag {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(91, 141, 239, 0.15);
  color: var(--accent);
}

.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: rgba(91, 141, 239, 0.06); }

.date-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}

.date-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  padding: 1rem 1.1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, transform 0.1s;
}

.date-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.date-card-date {
  font-size: 1.05rem;
  font-weight: 700;
}

.date-card-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-root[hidden] { display: none; }

body.modal-open { overflow: hidden; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal {
  position: relative;
  z-index: 1;
  width: min(720px, 96vw);
  max-height: 85vh;
  overflow: auto;
  margin: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--text);
}

.modal-subtitle { margin: 0 0 1rem; }

.modal-item-head {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.raid-tag {
  display: inline-block;
  margin-right: 0.25rem;
  margin-bottom: 0.15rem;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.35);
}

.wowhead-link {
  color: var(--text);
  text-decoration: none;
}

.wowhead-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.btn-danger {
  color: var(--error);
  border-color: rgba(248, 113, 113, 0.45);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.12);
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.admin-meta, .admin-meta code {
  color: var(--muted);
  font-size: 0.9rem;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.history-item .message {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.85rem;
}

.badge {
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.status-success .badge { background: rgba(52, 211, 153, 0.15); color: var(--success); }
.status-error .badge { background: rgba(248, 113, 113, 0.15); color: var(--error); }
.status-running .badge { background: rgba(91, 141, 239, 0.15); color: var(--accent); }

@media (max-width: 640px) {
  .topbar { flex-direction: column; }
  .history-item { grid-template-columns: 1fr; }
}

.app-nav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  padding: 0.35rem;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 0.75rem;
}

.app-nav-link {
  padding: 0.45rem 0.9rem;
  border-radius: 0.5rem;
  color: #cbd5e1;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
}

.app-nav-link:hover {
  background: rgba(148, 163, 184, 0.12);
  color: #f8fafc;
}

.app-nav-link.active {
  background: rgba(99, 102, 241, 0.22);
  color: #e0e7ff;
}

.fairness-badge {
  display: inline-block;
  padding: 0.18rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.fairness-badge.high {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.45);
}

.fairness-badge.low {
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.4);
}

.fairness-badge.average {
  color: #cbd5e1;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.fairness-badge.warn {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.fairness-badge.muted {
  color: var(--muted);
  background: rgba(107, 114, 128, 0.12);
  border: 1px solid rgba(107, 114, 128, 0.25);
}

tr.fairness-high td:first-child {
  box-shadow: inset 3px 0 0 rgba(239, 68, 68, 0.75);
}

tr.fairness-low td:first-child {
  box-shadow: inset 3px 0 0 rgba(34, 197, 94, 0.65);
}

.filter-field {
  display: inline-flex;
  flex-direction: column;
  gap: 0.2rem;
}

.filter-field select,
.filter-field input[type="number"] {
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
}
