/* Dark theme — matches the original Shiny app's palette. */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: #1e1e1e;
  color: #d4d4d4;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
}

#app { display: flex; min-height: 100vh; }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
#sidebar {
  width: 280px;
  flex-shrink: 0;
  background: #2d2d2d;
  border-right: 1px solid #444;
  padding: 16px;
  overflow-y: auto;
  position: sticky; top: 0; max-height: 100vh;
}
#sidebar h1 { font-size: 16px; margin: 0 0 16px; color: #e0e0e0; }
#sidebar label {
  display: block;
  margin-bottom: 14px;
  color: #d4d4d4;
  font-size: 13px;
}
#sidebar select,
#sidebar input[type="text"] {
  width: 100%;
  background: #3c3c3c;
  color: #d4d4d4;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 5px 7px;
  margin-top: 4px;
  font-size: 13px;
}
#sidebar input[type="range"] {
  width: 100%;
  margin-top: 6px;
  accent-color: #009E73;
}
#sidebar .checkbox-label { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
#sidebar .checkbox-label input { transform: scale(1.1); accent-color: #009E73; }
#sidebar .hint { color: #888; font-size: 11px; flex-basis: 100%; margin-left: 22px; }
#sidebar .weights-box {
  border: 1px solid #444;
  border-radius: 4px;
  padding: 6px 10px 8px;
  margin: 8px 0;
}
#sidebar .weights-box legend { color: #d4d4d4; font-size: 12px; padding: 0 4px; }
#sidebar .weights-box label { font-size: 12px; margin-top: 6px; }
#sidebar .weights-box .hint { margin: 0 0 6px 0; }

.btn-sm {
  background: #3c3c3c;
  color: #d4d4d4;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 6px;
  width: 100%;
}
.btn-sm:hover { background: #4c4c4c; color: #fff; }
.btn-primary {
  width: 100%;
  background: #1a3a2a;
  color: #fff;
  border: 1px solid #009E73;
  border-radius: 3px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
  font-weight: bold;
}
.btn-primary:hover { background: #205a3f; }
.btn-primary:disabled {
  background: #2a2a2a; border-color: #444; color: #666; cursor: not-allowed;
}

/* Pool chip multiselect (sidebar + builder) */
#pool-input-wrap, .pool-input-wrap {
  background: #3c3c3c;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 4px;
  margin-top: 4px;
  position: relative;
}
#pool-chips, .pool-chips, #pb-definite-chips, #pb-maybe-chips {
  display: flex; flex-wrap: wrap; gap: 3px;
}
#pool-search, #pb-definite-search, #pb-maybe-search {
  background: transparent !important;
  border: none !important;
  padding: 4px !important;
  flex: 1; min-width: 80px; outline: none;
}
.pool-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #1a3a2a;
  border: 1px solid #009E73;
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 12px;
  color: #fff;
}
.pool-chip img { width: 16px; height: 16px; border-radius: 2px; }
.pool-chip .x {
  cursor: pointer; color: #fff; padding: 0 2px;
  border-left: 1px solid #009E73; margin-left: 2px;
}
.pool-chip .x:hover { background: #D55E00; }

#pool-suggestions, .pool-suggestions {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 3px;
  margin-top: 2px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
}
#pool-suggestions.open, .pool-suggestions.open { display: block; }
.suggestion {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  cursor: pointer;
  color: #d4d4d4;
}
.suggestion img { width: 18px; height: 18px; border-radius: 2px; }
.suggestion:hover, .suggestion.active { background: #1a3a2a; color: #fff; }
.suggestion .pr { color: #888; font-size: 11px; margin-left: auto; }

#status { color: #888; font-size: 11px; margin-top: 12px; min-height: 14px; }

/* ── Main ─────────────────────────────────────────────────────────────── */
#main { flex: 1; padding: 16px; overflow-x: auto; min-width: 0; }

.tabs-top, .tabs-sub { display: flex; gap: 2px; margin-bottom: 8px; border-bottom: 1px solid #444; flex-wrap: wrap; }
.tabs-sub { margin-top: 0; margin-bottom: 12px; }
.tab-btn {
  background: #2d2d2d;
  color: #d4d4d4;
  border: 1px solid #444;
  border-bottom: none;
  border-radius: 3px 3px 0 0;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.tab-btn:hover { background: #353535; color: #fff; }
.tab-btn.active { background: #3c3c3c; color: #fff; border-color: #555; }
.tabs-sub .tab-btn { font-size: 12px; padding: 5px 10px; }

.view { display: none; }
.view.active { display: block; }

.section-h { color: #e0e0e0; font-size: 15px; margin: 18px 0 8px; }
.row-controls { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.row-controls label { display: block; min-width: 200px; color: #d4d4d4; font-size: 13px; }

#stats-banner { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.stat-pill {
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 13px;
}
.stat-pill.cov { border-color: #009E73; }
.stat-pill.unc { border-color: #D55E00; }
.stat-pill.delta-pos { border-color: #009E73; }
.stat-pill.delta-neg { border-color: #D55E00; }

#heatmap, #pb-selected-hm, #blind-scatter, #health-redundancy-heatmap { background: #1e1e1e; }
#health-redundancy-heatmap { margin-top: 32px; }

/* Heatmap key — explains bold (top-X) vs faint (other pool members) */
.hm-key {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 8px 12px;
  margin: 6px 0 10px;
  background: #232323;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  font-size: 12px;
  color: #aaa;
}
.hm-key .key-item { white-space: nowrap; }

#uncovered { margin-top: 14px; }
.cov-banner {
  background: #1a3a2a;
  border: 1px solid #009E73;
  border-radius: 4px;
  padding: 8px 12px;
  font-weight: bold;
  display: inline-block;
}
.uncov-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #2a2a2a;
  border: 1px solid #D55E00;
  border-radius: 5px;
  padding: 4px 8px;
  margin: 3px;
  font-size: 12px;
  line-height: 1.2;
}
.uncov-chip img { width: 18px; height: 18px; border-radius: 2px; }
.uncov-chip .best { color: #aaa; font-size: 10px; display: block; }
.uncov-header { color: #aaa; font-size: 13px; margin: 0 0 6px; }

.empty-msg { color: #888; padding: 30px 0; text-align: center; }

/* Equation card */
.eq-box {
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 13px;
  line-height: 1.5;
}
.eq-box .plain {
  color: #aaa;
  font-size: 11px;
  margin-top: 4px;
  border-top: 1px solid #3a3a3a;
  padding-top: 4px;
}

/* Tables */
.std-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 2px 2px;
  font-size: 13px;
}
.std-table th {
  color: #aaa;
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid #444;
  font-weight: normal;
}
.std-table td { padding: 4px 8px; line-height: 1.6; }
.ban-legend {
  display: flex; flex-wrap: wrap; gap: 6px 18px;
  margin: 8px 0 4px; color: #aaa; font-size: 12px; line-height: 1.5;
}
.ban-legend b { color: #d4d4d4; font-weight: 600; }
.std-table .th-desc {
  display: block;
  color: #888;
  font-weight: normal;
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0;
  margin-top: 2px;
}
.std-table tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
.std-table img { width: 22px; height: 22px; border-radius: 3px; vertical-align: middle; }

/* Color cells (correlation, blind z, ban score) */
.cell-pos, .cell-neg, .cell-na {
  text-align: center; color: #fff; font-weight: bold;
  border-radius: 3px; padding: 4px 8px;
}
.cell-na { color: #555; background: transparent; font-weight: normal; }

/* Ban tables grid: 5 columns side by side */
#ban-tables-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.ban-table-wrap {
  background: #232323;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  padding: 8px 10px;
  max-height: 600px;
  overflow-y: auto;
}
.ban-table-wrap h4 { margin: 0 0 6px; color: #e0e0e0; font-size: 13px; }
.ban-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ban-table th { color: #aaa; font-size: 11px; text-align: left; padding: 3px 4px; border-bottom: 1px solid #444; }
.ban-table td { padding: 3px 4px; border-bottom: 1px solid #4a4a4a; vertical-align: middle; }
.ban-table img { width: 28px; height: 28px; border-radius: 3px; vertical-align: middle; }
.ban-top-card {
  background: #1a3a2a; border: 1px solid #009E73; border-radius: 6px;
  padding: 10px 14px; margin-top: 8px; display: flex; align-items: center; gap: 12px;
}
.ban-top-card img { width: 40px; height: 40px; border-radius: 4px; }
.ban-top-card .label { font-size: 11px; color: #aaa; }
.ban-top-card .name { font-size: 18px; font-weight: bold; }
.ban-top-card .meta { font-size: 12px; color: #d4d4d4; margin-top: 3px; }

/* Pool Builder layout — controls across the top, full-width heatmap+table below */
.builder-grid { display: block; margin-top: 8px; }
.builder-controls {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: #232323; border: 1px solid #3a3a3a; border-radius: 4px;
}
.builder-controls > label {
  flex: 1 1 280px;
  display: block; margin-bottom: 0;
  color: #d4d4d4; font-size: 13px;
}
.builder-controls > label.compact-label { flex: 0 0 180px; }
#pb-combo-count {
  padding: 6px 10px; border-radius: 4px;
  background: #1a2a1f; border: 1px solid #2e6b4a; color: #6fe2b5; font-size: 12px;
  flex: 1 1 200px; align-self: center;
}
#pb-combo-count.over { background: #3a1a1a; border-color: #6b2e2e; color: #ff8a6a; }
#pb-build { flex: 0 0 140px; }

/* Replacement Finder */
#repl-locked-wrap {
  background: #2a2a2a; border: 1px solid #444; border-radius: 4px;
  padding: 8px 12px; margin: 8px 0;
}
#repl-locked-wrap label.lock-item {
  display: inline-flex; align-items: center; gap: 4px; margin-right: 12px;
  color: #d4d4d4; font-size: 12px;
}
#repl-locked-wrap img { width: 18px; height: 18px; border-radius: 2px; }
#repl-summary { margin: 10px 0; }

/* Welcome / landing tab */
.welcome-wrap { max-width: 1100px; margin: 12px auto; padding: 0 12px; }
.welcome-title { color: #d4d4d4; margin: 0 0 4px; font-size: 22px; }
.welcome-lead { color: #aaa; margin: 0 0 8px; }
.welcome-links { color: #888; font-size: 13px; margin: 0 0 18px; }
.welcome-links a { color: #6fe2b5; text-decoration: none; }
.welcome-links a:hover { color: #a4f0d3; text-decoration: underline; }
.welcome-links .sep { color: #555; margin: 0 6px; }
.welcome-group { margin: 18px 0; }
.welcome-group h3 {
  color: #6fe2b5; font-size: 14px; text-transform: uppercase;
  letter-spacing: 0.6px; margin: 0 0 8px; font-weight: 600;
}
.welcome-tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.welcome-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  background: #2a2a2a; border: 1px solid #444; border-radius: 6px;
  padding: 12px 14px; color: #d4d4d4; cursor: pointer; text-align: left;
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
}
.welcome-tile:hover { background: #353535; border-color: #6fe2b5; transform: translateY(-1px); }
.welcome-tile .wt-title { font-weight: 600; font-size: 14px; color: #e6c978; }
.welcome-tile .wt-desc { font-size: 12px; color: #bbb; line-height: 1.45; }

/* Selected row in tables — left bar + outline so per-cell background
   colors (matchup gold, synergy blue, blindability purple) stay visible. */
tr.selected td { box-shadow: inset 0 1px 0 rgba(0,158,115,0.7), inset 0 -1px 0 rgba(0,158,115,0.7); }
tr.selected td:first-child { box-shadow: inset 4px 0 0 #00b386, inset 0 1px 0 rgba(0,158,115,0.7), inset 0 -1px 0 rgba(0,158,115,0.7); }
tr.in-pool-row td { background: rgba(0, 158, 115, 0.08); }
.std-table tr[data-cand] { cursor: pointer; }
.std-table tr[data-cand]:hover td { box-shadow: inset 0 0 0 1px rgba(0,158,115,0.35); }

/* Compact table — narrower padding for dense scoring tables.
   width: auto so columns size to content instead of stretching to fill. */
.std-table.compact-table {
  width: auto;
  border-spacing: 1px 1px;
}
.std-table.compact-table th,
.std-table.compact-table td { padding: 3px 8px; font-size: 12px; white-space: nowrap; }
.std-table.compact-table th { font-size: 11px; }

/* Per-section horizontal scroll so the heatmap and the table can scroll
   independently of one another. */
#pb-result-table, #pb-selected-hm,
#repl-table, #repl-new-pool-hm,
#heatmap, #health-redundancy-heatmap {
  overflow-x: auto;
  max-width: 100%;
}

/* ── Pool strength summary (top of Pool Health tab) ────────────────────── */
.strength-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(240px, 1fr));
  gap: 12px;
  margin: 8px 0 16px;
}
.strength-cell {
  background: #2d2d2d;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.strength-label { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 0.5px; }
.strength-tier  { font-size: 22px; font-weight: 700; line-height: 1.1; }
.strength-plot  { height: 110px; }
.strength-meta  { font-size: 11px; color: #aaa; margin-top: 2px; }
.strength-meta b { color: #d4d4d4; }
