/* ═══════════════════════════════════════════════════════
   Components — Filters, Tables, Cards, Gallery, etc.
   ═══════════════════════════════════════════════════════ */

/* ── Filter Bar ── */
.filter-bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  animation: fadeIn 0.3s ease-out;
}

/* Search input */
.filter-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.filter-search-icon {
  position: absolute;
  left: 9px;
  color: var(--text-muted);
  pointer-events: none;
}

.filter-search {
  font-family: var(--font-body);
  font-size: 0.76rem;
  font-weight: 400;
  padding: 6px 10px 6px 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  outline: none;
  width: 180px;
  transition: all 0.15s;
  letter-spacing: 0.01em;
}

.filter-search::placeholder { color: var(--text-muted); }
.filter-search:hover { border-color: var(--text-muted); }
.filter-search:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); width: 220px; }

/* Range filter */
.filter-range {
  display: flex;
  align-items: center;
  gap: 4px;
}

.filter-range-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 2px;
}

.filter-range-sep {
  color: var(--text-muted);
  font-size: 0.76rem;
}

.filter-input {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  outline: none;
  width: 52px;
  text-align: center;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
}

.filter-input::-webkit-outer-spin-button,
.filter-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.filter-input:hover { border-color: var(--text-muted); }
.filter-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }

.filter-select {
  font-family: var(--font-body);
  font-size: 0.76rem;
  font-weight: 500;
  padding: 6px 28px 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  outline: none;
  transition: all 0.15s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23636d88' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  letter-spacing: 0.02em;
}

.filter-select:hover { border-color: var(--text-muted); }
.filter-select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }

/* Filter custom dropdowns */
.filter-custom-select {
  position: relative;
  display: inline-block;
}

.filter-custom-select .custom-select-trigger {
  font-size: 0.76rem;
  font-weight: 500;
  padding: 6px 28px 6px 10px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  width: auto;
}

.filter-custom-select .custom-select-dropdown {
  min-width: 160px;
}

.filter-custom-select .custom-select-option {
  font-size: 0.76rem;
  padding: 6px 10px;
}

.filter-clear {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.filter-clear:hover {
  color: var(--red);
  border-color: var(--red);
}

.filter-count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Table Wrapper ── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  animation: fadeUp 0.5s ease-out 0.1s both;
}

/* ── Runs Table ── */
.runs-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.runs-table th {
  text-align: left;
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: relative;
  background: var(--bg-elevated);
  transition: color 0.12s;
}

.runs-table th:hover { color: var(--accent); }

.runs-table th .sort-arrow {
  margin-left: 3px;
  font-size: 0.55rem;
  color: var(--accent);
  vertical-align: 1px;
}

/* Column resize handle */
.runs-table th .col-resize {
  position: absolute;
  right: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  cursor: col-resize;
  z-index: 1;
  border-radius: 2px;
  transition: background 0.1s;
}

.runs-table th .col-resize:hover,
.runs-table th .col-resize.active {
  background: var(--accent);
}

.runs-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
  transition: background 0.08s;
}

.runs-table tbody tr:last-child td { border-bottom: none; }

.runs-table tbody tr:hover td {
  background: var(--bg-hover);
}

/* ── Group Rows ── */
.group-header {
  cursor: pointer;
}

.group-header td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  background: var(--bg-surface);
}

.group-header:hover td {
  background: var(--bg-hover);
}

.group-toggle {
  display: inline-block;
  width: 14px;
  font-size: 0.55rem;
  color: var(--text-muted);
  margin-right: 6px;
  transition: color 0.12s;
}

.group-header:hover .group-toggle {
  color: var(--accent);
}

.group-name {
  font-family: var(--font-body);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.group-summary {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-style: italic;
}

.group-count {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--accent);
  margin-left: 8px;
  font-weight: 500;
  background: var(--accent-dim);
  padding: 1px 8px;
  border-radius: 3px;
  letter-spacing: 0.02em;
}

/* Child rows */
.child-row td {
  background: var(--bg-elevated);
}

.child-row:hover td {
  background: var(--bg-hover);
}

.child-row td:first-child {
  border-left: 2px solid var(--accent);
}

/* ── Cell Styles ── */
.run-name {
  font-weight: 600;
  color: var(--accent);
  transition: color 0.12s;
  letter-spacing: 0.005em;
}

.run-name:hover {
  color: var(--accent-hover);
  text-decoration: none;
}

.note-cell {
  font-size: 0.76rem;
  color: var(--accent);
  font-weight: 500;
  max-width: 240px;
  letter-spacing: 0.005em;
}

.git-hash {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  background: var(--bg-surface);
  padding: 2px 7px;
  border-radius: 3px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all 0.12s;
  letter-spacing: 0.02em;
}

.git-hash:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
  text-decoration: none;
}

.models-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 22px;
  text-align: center;
}

.scenario-cell {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.scenario-range {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-left: 2px;
}

.date-cell {
  font-size: 0.78rem;
  white-space: nowrap;
  color: var(--text-secondary);
}

.date-time {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-left: 4px;
}

/* ── Elo Value ── */
.elo-value {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ── Tags ── */
.tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  padding: 2px 7px;
  border-radius: 3px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tag-lora { background: rgba(91, 156, 246, 0.12); color: var(--tag-lora); border: 1px solid rgba(91, 156, 246, 0.2); }
.tag-api { background: rgba(167, 139, 250, 0.12); color: var(--tag-api); border: 1px solid rgba(167, 139, 250, 0.2); }
.tag-base { background: rgba(100, 116, 139, 0.12); color: var(--tag-base); border: 1px solid rgba(100, 116, 139, 0.2); }

[data-theme="light"] .tag-lora { background: rgba(59, 130, 246, 0.08); color: #2563eb; border-color: rgba(59, 130, 246, 0.15); }
[data-theme="light"] .tag-api { background: rgba(139, 92, 246, 0.08); color: #7c3aed; border-color: rgba(139, 92, 246, 0.15); }
[data-theme="light"] .tag-base { background: rgba(100, 116, 139, 0.08); color: #475569; border-color: rgba(100, 116, 139, 0.15); }

/* ── Cards ── */
.card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
  animation: fadeUp 0.4s ease-out both;
}

.card:nth-child(2) { animation-delay: 0.05s; }
.card:nth-child(3) { animation-delay: 0.1s; }
.card:nth-child(4) { animation-delay: 0.15s; }
.card:nth-child(5) { animation-delay: 0.2s; }

.card h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 400;
  margin-bottom: 16px;
  color: var(--text);
  letter-spacing: 0.005em;
}

/* ── Run Detail Header ── */
.run-header {
  margin-bottom: 28px;
  animation: fadeUp 0.4s ease-out;
}

.run-header h2 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 400;
  margin-bottom: 10px;
  letter-spacing: -0.005em;
}

.run-meta {
  display: flex;
  gap: 16px;
  color: var(--text-muted);
  font-size: 0.82rem;
  flex-wrap: wrap;
}

.run-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Metrics Grid ── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}

.metric-item {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  transition: border-color 0.15s;
}

.metric-item:hover {
  border-color: var(--border);
}

.metric-label {
  font-family: var(--font-body);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ── Models Table (detail page) ── */
.models-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.models-table th {
  text-align: left;
  padding: 8px 12px;
  font-family: var(--font-body);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.models-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
}

.models-table tr:last-child td { border-bottom: none; }

.models-table tr:hover td {
  background: var(--bg-hover);
}

/* ── Charts ── */
.chart-card { padding: 0; overflow: hidden; }
.chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-scroll > div { min-width: 500px; }

/* ── Image Gallery ── */
.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.gallery-item {
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.2s;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
}

.gallery-item:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 16px rgba(0,0,0,0.2);
}

.gallery-item .img-wrap {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: transform 0.3s ease;
  padding: 8px;
}

.gallery-item:hover img {
  transform: scale(1.03);
}

.gallery-item .caption {
  padding: 8px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  border-top: 1px solid var(--border-light);
}

.gallery-item-wide {
  grid-column: 1 / -1;
}

.gallery-item-wide .img-wrap {
  aspect-ratio: auto;
  max-height: 480px;
}

/* ── Lightbox ── */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lightbox.active { display: flex; }

.lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

/* ── Spec Grid ── */
.spec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.spec-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color 0.15s;
}

.spec-section:hover {
  border-color: var(--border);
}

.spec-section-title {
  font-family: var(--font-body);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-light);
}

.spec-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  gap: 12px;
}

.spec-row + .spec-row {
  border-top: 1px solid var(--border-light);
}

.spec-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.spec-value {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text);
  text-align: right;
  word-break: break-all;
}

/* ── Models table extras ── */
.rank-num {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  width: 20px;
  display: inline-block;
  text-align: center;
}

.mono-cell {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.ci-cell {
  white-space: nowrap;
  letter-spacing: 0.01em;
}

/* ── Collapsible ── */
.collapsible-header {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  transition: color 0.12s;
}

.collapsible-header:hover { color: var(--accent); }

.collapsible-header::before {
  content: "\25B6";
  font-size: 0.6rem;
  transition: transform 0.2s;
  color: var(--text-muted);
}

.collapsible-header.open::before {
  transform: rotate(90deg);
  color: var(--accent);
}

.collapsible-body {
  display: none;
  margin-top: 14px;
  font-size: 0.84rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.collapsible-body.open { display: block; }

.collapsible-body p {
  margin-bottom: 6px;
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-style: italic;
}

/* ── Loading ── */
.loading {
  text-align: center;
  padding: 64px;
  color: var(--text-muted);
  font-size: 0.88rem;
  letter-spacing: 0.02em;
}

.loading::after {
  content: "";
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-left: 10px;
  vertical-align: middle;
}

/* ── Error ── */
.error {
  text-align: center;
  padding: 64px;
  color: var(--red);
  font-size: 0.88rem;
}

.error a {
  color: var(--accent);
}

/* ── Custom dropdown ── */
.custom-select {
  position: relative;
  width: 100%;
}

.custom-select-trigger {
  font-family: var(--font-body);
  font-size: 0.82rem;
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 32px 9px 12px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  position: relative;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-trigger::after {
  content: "";
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--text-muted);
  transition: transform 0.15s;
}

.custom-select.open .custom-select-trigger::after {
  transform: translateY(-50%) rotate(180deg);
}

.custom-select-trigger:hover {
  border-color: var(--text-muted);
}

.custom-select.open .custom-select-trigger {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.custom-select-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-height: 180px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  padding: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.custom-select.open .custom-select-dropdown {
  display: block;
  animation: fadeUp 0.15s ease-out;
}


.custom-select-option {
  font-family: var(--font-body);
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: calc(var(--radius) - 1px);
  cursor: pointer;
  transition: all 0.1s;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-select-option:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.custom-select-option.selected {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

.model-logo {
  border-radius: 3px;
  object-fit: contain;
  vertical-align: middle;
  flex-shrink: 0;
  display: inline-block;
}

.custom-select-trigger .model-logo {
  margin-right: 4px;
}

.custom-select-option .option-check {
  width: 14px;
  flex-shrink: 0;
  color: var(--accent);
  opacity: 0;
}

.custom-select-option.selected .option-check {
  opacity: 1;
}

/* ── Toast notifications ── */
.va-toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.va-toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text-primary);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: auto;
}

.va-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.va-toast-warning {
  background: rgba(232, 164, 74, 0.12);
  border-color: rgba(232, 164, 74, 0.3);
}

.va-toast-info {
  background: rgba(91, 156, 246, 0.12);
  border-color: rgba(91, 156, 246, 0.3);
}

.va-toast-error {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
}
