/* ══════════════════════════════════════════════════════════════════
   REPERTOIRE PERFORMANCE TREE ("OPENING LAB") STYLES
   
   Note: The tabular Moves Explorer design and stacked W/D/L progress 
   bars were heavily inspired by the 'openingtree' project
   (https://github.com/openingtree/openingtree).
   ══════════════════════════════════════════════════════════════════ */

#page-repertoire-tree {
  min-height: 100vh;
  background: #090d16;
  color: #e2e8f0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: none;
  overflow-x: hidden;
  touch-action: manipulation;
  width: 100%;
  max-width: 100vw;
}

#page-repertoire-tree.active {
  display: flex !important;
}

#page-repertoire-tree * {
  box-sizing: border-box;
}

.rep-header-pill {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(52, 211, 153, 0.35);
  margin-left: 8px;
}

@media (max-width: 640px) {
  .rep-header-pill {
    display: none;
  }
}

.rep-main-container {
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-x: hidden;
  min-width: 0;
}

@media (max-width: 768px) {
  .rep-main-container {
    padding: 12px 12px 48px;
    gap: 14px;
  }
}

@media (max-width: 480px) {
  .rep-main-container {
    padding: 8px 8px 40px;
    gap: 10px;
  }
}

/* ── TOOLBAR & SWITCHERS ── */
.rep-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: #111827;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid #1f2937;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.rep-color-switch,
.rep-view-switch {
  display: flex;
  background: #0b1120;
  border: 1px solid #233149;
  border-radius: 8px;
  padding: 3px;
  gap: 4px;
}

.rep-color-btn,
.rep-view-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.rep-color-btn:hover,
.rep-view-btn:hover {
  color: #f8fafc;
}

.rep-color-btn.active,
.rep-view-btn.active {
  background: #1e293b;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

/* ── HERO METRIC CARDS ── */
.rep-hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

@media (max-width: 640px) {
  .rep-hero-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

.rep-hero-card {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

@media (max-width: 640px) {
  .rep-hero-card {
    padding: 10px 10px;
    gap: 8px;
  }
}

.rep-hero-card:hover {
  transform: translateY(-2px);
  border-color: #374151;
}

.rep-hero-icon {
  font-size: 1.8rem;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}

@media (max-width: 640px) {
  .rep-hero-icon {
    font-size: 1.3rem;
    padding: 6px;
  }
}

.rep-hero-content {
  flex: 1;
  min-width: 0;
}

.rep-hero-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
  margin-bottom: 2px;
}

@media (max-width: 640px) {
  .rep-hero-label {
    font-size: 0.68rem;
  }
}

.rep-hero-val {
  font-size: 1.15rem;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 640px) {
  .rep-hero-val {
    font-size: 0.95rem;
  }
}

.rep-hero-sub {
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 2px;
}

@media (max-width: 640px) {
  .rep-hero-sub {
    display: none;
  }
}

.card-weapon .rep-hero-icon {
  background: rgba(16, 185, 129, 0.12);
}
.card-weapon .rep-hero-val {
  color: #34d399;
}

.card-leak .rep-hero-icon {
  background: rgba(239, 68, 68, 0.12);
}
.card-leak .rep-hero-val {
  color: #f87171;
}

/* ── SPLIT VIEW (BOARD + TREE) ── */
.rep-split-view {
  display: grid;
  grid-template-columns: minmax(0, 460px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
  width: 100%;
  min-width: 0;
}

@media (max-width: 960px) {
  .rep-split-view {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }
}

/* ── LEFT COLUMN: BOARD CARD ── */
.rep-board-col {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

#page-repertoire-tree .rep-board-card {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  min-width: 0;
}

@media (max-width: 600px) {
  #page-repertoire-tree .rep-board-card {
    padding: 10px;
    gap: 8px;
  }
}

.rep-board-wrapper {
  width: 100%;
  max-width: min(460px, calc(100vw - 32px), calc(100vh - 220px));
  aspect-ratio: 1 / 1;
  position: relative;
  margin: 0 auto;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  touch-action: manipulation;
}

.rep-chessground {
  width: 100%;
  height: 100%;
  position: relative;
}

.rep-chessground .cg-wrap,
.rep-chessground cg-container,
.rep-chessground cg-board {
  width: 100% !important;
  height: 100% !important;
  position: absolute;
  top: 0;
  left: 0;
  touch-action: manipulation;
}

.rep-board-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: 100%;
}

@media (max-width: 480px) {
  .rep-board-controls {
    grid-template-columns: repeat(2, 1fr);
  }
}

.rep-board-controls .btn {
  width: 100%;
  padding: 7px 6px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.rep-current-fen {
  font-family: monospace;
  font-size: 0.72rem;
  background: #0b1120;
  border: 1px solid #1e293b;
  color: #94a3b8;
  padding: 6px 10px;
  border-radius: 6px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

/* ── RIGHT COLUMN: TREE & DIAGNOSTICS ── */
.rep-tree-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  min-width: 0;
}

/* Breadcrumbs */
.rep-breadcrumbs-card {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 10px;
  padding: 10px 16px;
  width: 100%;
  min-width: 0;
}

.rep-breadcrumbs-title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #64748b;
  margin-bottom: 4px;
}

.rep-breadcrumbs-trail {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.rep-crumb {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  background: #1e293b;
  color: #cbd5e1;
  cursor: pointer;
  transition: all 0.15s ease;
}

.rep-crumb:hover {
  background: #334155;
  color: #ffffff;
}

.rep-crumb.active {
  background: #0ea5e9;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(14, 165, 233, 0.4);
}

/* Candidates Table */
.rep-candidates-card {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  width: 100%;
  min-width: 0;
}

.rep-candidates-header {
  padding: 14px 18px;
  border-bottom: 1px solid #1f2937;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

@media (max-width: 600px) {
  .rep-candidates-header {
    padding: 10px 12px;
  }
}

.rep-candidates-title {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rep-badge-count {
  background: #1e293b;
  color: #94a3b8;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 0.72rem;
}

.rep-candidates-hint {
  font-size: 0.75rem;
  color: #64748b;
}

@media (max-width: 600px) {
  .rep-candidates-hint {
    display: none;
  }
}

.rep-moves-table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

.rep-moves-table {
  width: 100%;
  min-width: 460px;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.rep-moves-table th {
  background: #0b1120;
  color: #94a3b8;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  border-bottom: 1px solid #1f2937;
}

.rep-moves-table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

.rep-move-row {
  cursor: pointer;
  transition: background 0.15s ease;
}

.rep-move-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.rep-move-san {
  font-weight: 700;
  font-family: monospace;
  font-size: 0.95rem;
  color: #f1f5f9;
  display: flex;
  align-items: center;
  gap: 6px;
}

.rep-opening-tag {
  font-size: 0.72rem;
  color: #64748b;
  font-weight: 400;
}

/* W/D/L Stacked Progress Bar */
.rep-wdl-bar {
  display: flex;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: #1e293b;
  margin-bottom: 4px;
}

.rep-wdl-w {
  background: #10b981;
}

.rep-wdl-d {
  background: #64748b;
}

.rep-wdl-l {
  background: #ef4444;
}

.rep-wdl-legend {
  font-size: 0.7rem;
  color: #94a3b8;
  display: flex;
  justify-content: space-between;
}

/* Status Badges */
.rep-status-pill {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  display: inline-block;
}

.rep-status-pill.solid {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(52, 211, 153, 0.4);
}

.rep-status-pill.leak {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(248, 113, 113, 0.4);
}

.rep-status-pill.balanced {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.4);
}

.rep-empty-table {
  text-align: center;
  padding: 24px;
  color: #64748b;
  font-style: italic;
}

/* ── LEAK DIAGNOSTIC CARD ── */
.rep-leak-card {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.08) 0%, rgba(17, 24, 39, 1) 100%);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fadeIn 0.3s ease;
}

.rep-leak-badge {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #f87171;
}

.rep-leak-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
}

.rep-leak-desc {
  font-size: 0.85rem;
  color: #cbd5e1;
  line-height: 1.45;
}

.rep-leak-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}

/* ── SPARRING CHALLENGE CARD ── */
.rep-spar-card {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.12) 0%, #111827 100%);
  border: 1px solid rgba(14, 165, 233, 0.4);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rep-spar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rep-spar-title {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #38bdf8;
}

.rep-spar-body p {
  font-size: 0.86rem;
  color: #e2e8f0;
  margin: 0 0 6px;
}

.rep-spar-eval {
  font-size: 0.78rem;
  color: #94a3b8;
  font-family: monospace;
}

.rep-spar-controls {
  display: flex;
  gap: 8px;
}

/* ── REPERTOIRE GAMES DRAWER ── */
.rep-games-drawer {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 14px 16px;
}

.rep-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.rep-drawer-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.rep-drawer-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.rep-game-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #0b1120;
  border: 1px solid #1e293b;
  border-radius: 6px;
  font-size: 0.82rem;
}

.rep-game-result-win {
  color: #34d399;
  font-weight: 700;
}

.rep-game-result-loss {
  color: #f87171;
  font-weight: 700;
}

.rep-game-result-draw {
  color: #94a3b8;
  font-weight: 700;
}


