/* ─── Tag Manager ──────────────────────────────────────────────────── */

.tm-page-bg {
  --surface: var(--bg-secondary);
  --surface-alt: rgba(255,255,255,0.05);
  min-height: 100vh;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(59,130,246,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(139,92,246,0.04) 0%, transparent 50%),
    var(--bg-primary);
}

.tm-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* Header */
.tm-header {
  margin-bottom: 28px;
}
.tm-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 6px 0;
}
.tm-header p {
  font-size: var(--font-sm);
  color: var(--text-muted);
  margin: 0;
}
.tm-stats-row {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.tm-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 20px;
  min-width: 140px;
}
.tm-stat-card .tm-stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent-light);
}
.tm-stat-card .tm-stat-label {
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

/* Tabs */
.tm-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.tm-tab {
  padding: 10px 18px;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tm-tab:hover {
  color: var(--text-primary);
}
.tm-tab.active {
  color: var(--accent-light);
  border-bottom-color: var(--accent-light);
}

/* Search */
.tm-search {
  margin-bottom: 20px;
}
.tm-search input {
  width: 100%;
  max-width: 400px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: var(--font-sm);
}
.tm-search input::placeholder {
  color: var(--text-muted);
}

/* ─── Filter Bar ─────────────────────────────────────────────────── */

.tm-filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.tm-filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tm-filter-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tm-filter-select,
.tm-filter-bar .tm-search-input {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: var(--font-sm);
  font-family: inherit;
  min-width: 180px;
  transition: border-color 0.2s;
}
.tm-filter-select:hover,
.tm-filter-bar .tm-search-input:hover {
  border-color: var(--border-light);
}
.tm-filter-select:focus,
.tm-filter-bar .tm-search-input:focus {
  outline: none;
  border-color: var(--accent-light);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}
.tm-filter-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}
.tm-filter-reset {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--font-xs);
  cursor: pointer;
  transition: all 0.2s;
  align-self: flex-end;
}
.tm-filter-reset:hover {
  color: var(--text-primary);
  border-color: var(--border-light);
  background: rgba(255,255,255,0.03);
}
.tm-active-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-self: flex-end;
}
.tm-active-filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 11px;
  background: rgba(59, 130, 246, 0.12);
  color: var(--accent-light);
  cursor: pointer;
  transition: background 0.15s;
}
.tm-active-filter-pill:hover {
  background: rgba(59, 130, 246, 0.2);
}
.tm-active-filter-pill .tm-x {
  font-weight: 700;
  font-size: 12px;
  margin-left: 2px;
  opacity: 0.7;
}

/* ─── Browse Tab ─────────────────────────────────────────────────── */

.tm-domain-section {
  margin-bottom: 28px;
}
.tm-domain-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  cursor: pointer;
  user-select: none;
}
.tm-domain-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}
.tm-domain-count {
  font-size: var(--font-xs);
  color: var(--text-muted);
  background: var(--surface-alt, rgba(255,255,255,0.05));
  padding: 2px 8px;
  border-radius: 10px;
}
.tm-domain-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.tm-domain-chevron.open {
  transform: rotate(90deg);
}

.tm-tags-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
  padding-left: 8px;
}
.tm-tag-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.tm-tag-card:hover {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.15);
}
.tm-tag-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.tm-tag-card-stats {
  display: flex;
  gap: 12px;
  font-size: var(--font-xs);
  color: var(--text-muted);
}
.tm-tag-card-stats span {
  display: flex;
  align-items: center;
  gap: 3px;
}
.tm-tag-bar {
  height: 3px;
  border-radius: 2px;
  background: rgba(59, 130, 246, 0.15);
  margin-top: 8px;
  overflow: hidden;
}
.tm-tag-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent-light);
  transition: width 0.3s;
}

/* Custom tags section */
.tm-custom-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.tm-custom-section h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 12px 0;
}
.tm-custom-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tm-custom-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: var(--font-xs);
  background: rgba(139, 92, 246, 0.15);
  color: var(--purple, #a78bfa);
}
.tm-custom-pill .tm-custom-cnt {
  font-weight: 600;
}

/* ─── Coverage Tab ───────────────────────────────────────────────── */

.tm-coverage-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}
.tm-coverage-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.tm-coverage-panel h4 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 12px 0;
}
.tm-rank-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.tm-rank-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: var(--font-xs);
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.tm-rank-list li:last-child {
  border-bottom: none;
}
.tm-rank-count {
  font-weight: 600;
  color: var(--accent-light);
  font-variant-numeric: tabular-nums;
}

.tm-gaps-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-xs);
}
.tm-gaps-table th {
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tm-gaps-table td {
  padding: 8px 10px;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.tm-gap-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  margin-right: 3px;
}
.tm-gap-badge.no-venues {
  background: rgba(239, 68, 68, 0.2);
  color: var(--error);
}
.tm-gap-badge.low-coverage {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warning);
}
.tm-gap-badge.no-sponsors {
  background: rgba(139, 92, 246, 0.2);
  color: var(--purple, #a78bfa);
}
.tm-gap-badge.no-sessions {
  background: rgba(107, 114, 128, 0.2);
  color: var(--text-muted);
}

/* Domain distribution */
.tm-domain-dist {
  margin-top: 24px;
}
.tm-domain-dist-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: var(--font-xs);
}
.tm-domain-dist-name {
  width: 200px;
  color: var(--text-secondary);
  font-weight: 600;
  flex-shrink: 0;
}
.tm-domain-dist-bar {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.05);
  border-radius: 3px;
  overflow: hidden;
}
.tm-domain-dist-fill {
  height: 100%;
  background: var(--accent-light);
  border-radius: 3px;
  transition: width 0.3s;
}
.tm-domain-dist-val {
  width: 60px;
  text-align: right;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ─── Network Tab ────────────────────────────────────────────────── */

.tm-network-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.tm-pair-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.tm-pair-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.tm-pair-arrow {
  color: var(--text-muted);
  font-size: 10px;
}
.tm-pair-stats {
  display: flex;
  gap: 14px;
  font-size: var(--font-xs);
  color: var(--text-muted);
}
.tm-pair-stats strong {
  color: var(--accent-light);
}

/* ─── Admin Tab ──────────────────────────────────────────────────── */

.tm-admin-section {
  margin-bottom: 24px;
}
.tm-admin-section h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 12px 0;
}
.tm-merge-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.tm-merge-form select,
.tm-merge-form input {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: var(--font-sm);
}
.tm-merge-form select {
  min-width: 200px;
}
.tm-merge-btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  background: var(--accent-light);
  color: var(--text-on-accent, #fff);
  font-weight: 600;
  font-size: var(--font-sm);
  cursor: pointer;
}
.tm-merge-btn:hover {
  opacity: 0.9;
}
.tm-merge-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tm-alias-list {
  margin-top: 12px;
}
.tm-alias-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: var(--font-xs);
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.tm-alias-source {
  color: var(--warning);
  font-weight: 600;
  text-decoration: line-through;
}
.tm-alias-target {
  color: var(--success);
  font-weight: 600;
}

.tm-hidden-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.tm-hidden-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: var(--font-xs);
  background: rgba(107, 114, 128, 0.2);
  color: var(--text-muted);
  cursor: pointer;
}
.tm-hidden-pill:hover {
  background: rgba(107, 114, 128, 0.35);
}
.tm-hidden-pill .tm-x {
  font-weight: 700;
  margin-left: 2px;
}

/* Merge log */
.tm-merge-log {
  margin-top: 16px;
  max-height: 200px;
  overflow-y: auto;
}
.tm-merge-log-entry {
  font-size: 11px;
  color: var(--text-muted);
  padding: 3px 0;
}

/* ─── Detail Drawer ──────────────────────────────────────────────── */

.tm-detail-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0,0,0,0.5);
  z-index: 900;
}
.tm-detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(520px, 90vw);
  background: var(--bg-primary);
  border-left: 1px solid var(--border);
  z-index: 910;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  box-shadow: -4px 0 20px rgba(0,0,0,0.3);
}
.tm-detail-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
}
.tm-detail-close:hover {
  color: var(--text-primary);
}
.tm-detail-drawer h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px 0;
  padding-right: 40px;
}
.tm-detail-domain {
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-bottom: 16px;
}
.tm-detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.tm-detail-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}
.tm-detail-stat .tm-ds-val {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-light);
}
.tm-detail-stat .tm-ds-lbl {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}
.tm-detail-section {
  margin-top: 18px;
}
.tm-detail-section h4 {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 8px 0;
}
.tm-kw-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 160px;
  overflow-y: auto;
}
.tm-kw-pill {
  padding: 3px 9px;
  border-radius: 10px;
  font-size: 11px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent-light);
  white-space: nowrap;
}
.tm-related-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.tm-related-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 5px 0;
  font-size: var(--font-xs);
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.tm-related-list li > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tm-related-jaccard {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 11px;
}

/* ─── Loading / Empty states ─────────────────────────────────────── */

.tm-loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.tm-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: var(--font-sm);
}

/* Responsive */
@media (max-width: 768px) {
  .tm-coverage-summary {
    grid-template-columns: 1fr;
  }
  .tm-stats-row {
    flex-direction: column;
  }
}
