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

:root {
  color-scheme: dark;
  --bg-body: #12151b;
  --bg-panel: #151b26;
  --bg-header: #0e1018;
  --bg-input: #1d2330;
  --border: #2a2f3a;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --text-gold: #e8c96a;
  --accent: #3b82f6;
  --accent-dim: #263144;
  --row-hover: #1d2535;
  --row-selected: #253247;
}

body {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg-body);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header / Tabs ── */
.topbar {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  height: 48px;
}
.topbar h1 {
  font-size: 1.1rem;
  text-transform: uppercase;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.title-icon {
  width: 28px;
  height: 28px;
  border-radius: 4px;
}
.title-meta { color: #D14A4A; }
.title-hunt { color: #ABD473; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 6px 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { background: var(--accent-dim); color: var(--text); }
.tab.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.meta { margin-left: auto; color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.get-addon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  text-decoration: none;
  border: 1px solid var(--border);
  transition: background 0.15s, color 0.15s;
}
.get-addon:hover { background: var(--accent); color: var(--bg-header); }

/* ── Tab content ── */
.tab-content { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.tab-content.active { display: flex; }

/* ══════════════════ BEAST BROWSER TAB ══════════════════ */

.controls {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(120px, 200px) auto minmax(80px, 130px) minmax(80px, 130px) auto;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.controls input,
.controls select,
.controls button {
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  padding: 0 10px;
  font-size: 0.82rem;
}
.controls button { cursor: pointer; background: var(--accent-dim); }
.controls button:hover { background: #2e4060; }

/* E/R/U filter checkboxes */
.eru-filter {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
}
.eru-filter label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.82rem;
  user-select: none;
}
.eru-filter input {
  width: 14px;
  height: 14px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

/* E/R/U colours (shared by header, checkboxes and row marks) */
.eru-e { color: #ff8f3f; }
.eru-r { color: #7fbfff; }
.eru-u { color: #e8c96a; }
.eru-mark { font-weight: 700; }

/* Faction reaction (Alliance / Horde) */
th.col-ah, td.col-ah {
  text-align: center;
  width: 46px;
  white-space: nowrap;
  padding-left: 4px;
  padding-right: 4px;
}
th.col-as, td.col-as {
  text-align: center;
  width: 44px;
  white-space: nowrap;
}
.ah-badge {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 16px;
  margin: 0 1px;
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  color: #10131a;
}
.react-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.react-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #10131a;
}
.react-hint { color: var(--text-muted); font-size: 11px; }
.react-friendly { background: #57b85a; }
.react-neutral  { background: #d9c24a; }
.react-hostile  { background: #d1584f; }
.react-unknown  { background: #4b5563; color: #e5e7eb; }

.browser-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 10px;
  padding: 10px;
  flex: 1;
  min-height: 0;
}
.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.panel-title { font-weight: 600; font-size: 0.9rem; }
.result-count { color: var(--text-muted); font-size: 12px; }

.table-wrap { overflow: auto; flex: 1; padding: 0 6px 6px; }

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid #1e2636;
  font-size: 0.8rem;
  vertical-align: top;
}
th {
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  z-index: 1;
  color: var(--text-muted);
  font-weight: 600;
}
th[data-sort] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th[data-sort]:hover { color: var(--text); }
th[data-sort].sort-asc::after  { content: ' \25B2'; font-size: 9px; opacity: 0.9; }
th[data-sort].sort-desc::after { content: ' \25BC'; font-size: 9px; opacity: 0.9; }

/* Compact Elite / Rare / Unique columns */
th.col-eru, td.col-eru {
  text-align: center;
  width: 30px;
  padding-left: 4px;
  padding-right: 4px;
}
tr.row-clickable { cursor: pointer; }
tr.row-clickable:hover { background: var(--row-hover); }
tr.selected { background: var(--row-selected); }

.details-panel { padding-bottom: 8px; }
#details { padding: 10px 12px; overflow: auto; font-size: 0.82rem; flex: 1; }

.kv {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 5px 10px;
  margin-bottom: 12px;
}
.kv .k { color: var(--text-muted); }

/* Beast header with model viewer (Beast Browser detail panel) */
.beast-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.beast-header .kv { flex: 1; min-width: 0; }

/* Map panel model viewer: full width, stacked below stats */
#map-beast-details .model-viewer-box {
  width: 100%;
  aspect-ratio: 1;
  height: auto;
}

/* Icons */
.icon {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  border-radius: 3px;
  image-rendering: pixelated;
  margin-right: 2px;
}

/* Ability hover + tooltip */
.ability-hover {
  cursor: help;
  border-bottom: 1px dotted var(--text-muted);
}
.ability-hover:hover { color: #fff; }

#tooltip.ability-tooltip {
  max-width: 280px;
  font-size: 0.78rem;
  line-height: 1.4;
}
.att-name { font-weight: 700; color: #fff; margin-bottom: 4px; font-size: 0.85rem; }
.att-cost { color: #4da6ff; }
.att-range { color: var(--text-muted); }
.att-cast { color: var(--text-muted); }
.att-cd { color: var(--text-muted); }
.att-desc { margin-top: 4px; color: #e8c96a; }

.spawn-table { width: 100%; border-collapse: collapse; }
.spawn-table th, .spawn-table td {
  border-bottom: 1px solid #1e2636;
  padding: 4px 6px;
  font-size: 0.75rem;
}

/* Zone link in details */
.zone-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}
.zone-link:hover { color: #60a5fa; }

/* Detail mini-maps */
#detail-maps { margin-top: 12px; margin-bottom: 12px; }
.detail-map-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.detail-map-tab {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.detail-map-tab:hover { color: var(--text); background: var(--row-hover); }
.detail-map-tab.active {
  background: var(--bg-panel);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
.detail-map-heading {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.detail-map-count { color: var(--text-muted); font-weight: 400; }
.detail-map-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  line-height: 0;
}
.detail-map-img {
  display: block;
  width: 100%;
  image-rendering: pixelated;
}
.detail-map-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: visible;
}
.detail-map-svg circle {
  pointer-events: all;
}

/* ══════════════════ PET FAMILIES TAB ══════════════════ */

.stat-toggle {
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.stat-toggle input { cursor: pointer; }

.families-layout {
  flex: 1;
  padding: 10px;
  min-height: 0;
  display: flex;
}
.families-layout .table-panel { flex: 1; }

#familiesTable th { white-space: nowrap; }
#familiesTable .col-family { min-width: 120px; }
#familiesTable .col-beasts,
#familiesTable .col-coords { text-align: right; width: 60px; vertical-align: middle; }
#familiesTable .col-abilities { min-width: 300px; line-height: 1.8; }
#familiesTable .col-diet { min-width: 100px; vertical-align: middle; }
#familiesTable .col-stat { text-align: center; width: 55px; vertical-align: middle; }
#familiesTable .col-family { vertical-align: middle; }

.stat-green { color: #40ff40; }
.stat-red   { color: #ff4040; }
.stat-blue  { color: #4da6ff; }

.ability-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.75rem;
  margin: 1px 2px;
  white-space: nowrap;
  cursor: help;
  vertical-align: middle;
}
.ability-chip:hover { background: var(--row-hover); color: #fff; }

/* ══════════════════ ZONE MAP TAB ══════════════════ */

.map-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#zoneSearch {
  margin: 8px;
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font-size: 0.82rem;
  flex-shrink: 0;
}
#zoneSearch::placeholder { color: #5a6070; }
#zoneSearch:focus { outline: none; border-color: var(--accent); }

#zone-list { overflow-y: auto; flex: 1; }
#zone-list::-webkit-scrollbar { width: 6px; }
#zone-list::-webkit-scrollbar-track { background: var(--bg-panel); }
#zone-list::-webkit-scrollbar-thumb { background: #3a3f50; border-radius: 3px; }

.zone-item {
  padding: 7px 14px;
  cursor: pointer;
  font-size: 0.8rem;
  border-bottom: 1px solid #1a1e28;
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.zone-item:hover { background: var(--row-hover); color: #fff; }
.zone-item.active { background: var(--row-selected); color: var(--accent); font-weight: 600; }
.zone-item .wma-id { color: #5a6070; font-size: 0.7rem; margin-left: 4px; }

#map-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

#map-title {
  font-size: 0.9rem;
  color: var(--text-gold);
  padding: 2px 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  flex-shrink: 0;
}

#map-container { position: relative; flex-shrink: 0; }
#map-img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 160px);
  image-rendering: pixelated;
}
#map-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: visible;
}
.dot {
  pointer-events: all;
  cursor: pointer;
  transition: r 0.1s;
}
.dot:hover { r: 7px; }

#legend {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(14, 16, 24, 0.9);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.72rem;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 260px;
  overflow-y: auto;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ── Tooltip ── */
#tooltip {
  position: fixed;
  background: var(--bg-header);
  border: 1px solid #4a4f5a;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 5px;
  font-size: 0.78rem;
  pointer-events: none;
  display: none;
  z-index: 200;
  max-width: 220px;
  line-height: 1.5;
}
#tooltip strong { color: var(--text-gold); display: block; }

#placeholder {
  color: var(--text-muted);
  font-size: 1rem;
  text-align: center;
}

/* ── 3D Model Viewer ── */
#model-viewer-container,
.model-viewer-box {
  width: 280px;
  height: 280px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1a1e26;
  overflow: hidden;
}
#model-viewer-container canvas,
.model-viewer-box canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Copy link button */
.copy-link-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.7rem;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
  color: var(--text-muted);
  transition: border-color 0.15s;
}
.copy-link-btn:hover { border-color: var(--accent); }

/* DB link */
.db-link {
  color: var(--accent);
  text-decoration: none;
}
.db-link:hover { text-decoration: underline; }

/* Unique-appearance badge */
.unique-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  color: #1a1a1a;
  background: var(--text-gold);
  border-radius: 3px;
  vertical-align: middle;
  white-space: nowrap;
}
.rank-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  color: #1a1a1a;
  border-radius: 3px;
  vertical-align: middle;
  white-space: nowrap;
}
.rank-badge.badge-elite { background: #ff8f3f; }
.rank-badge.badge-rare  { background: #7fbfff; }

/* ── Map details panel ── */
#map-details-panel {
  width: 380px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  overflow-y: auto;
}
#map-beast-details {
  padding: 10px;
  font-size: 0.82rem;
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  .controls { grid-template-columns: 1fr 1fr 1fr; }
  .browser-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .map-layout { flex-direction: column; }
  #sidebar { width: 100%; height: 180px; flex-shrink: 0; border-right: none; border-bottom: 1px solid var(--border); }
}

/* ── Legal Footer ── */
.legal-footer {
  background: var(--bg-header);
  border-top: 1px solid var(--border);
  padding: 6px 24px;
  color: #6b7280;
  font-size: 0.68rem;
  line-height: 1.5;
  text-align: center;
  flex-shrink: 0;
}
.legal-footer p { margin: 2px 0; }
