/* ================================================================
   Intersection table
   ================================================================ */
.intersect-controls {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.intersect-controls input[type="text"] {
  flex: 1;
  min-width: 200px;
}

.group-block {
  margin-bottom: 1.5rem;
}

.group-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  padding: .65rem 1rem;
  cursor: pointer;
  user-select: none;
}
.group-header:hover { border-color: var(--accent); }

.group-title {
  font-weight: 700;
  font-size: .95rem;
  flex: 1;
}

.group-count {
  background: var(--accent);
  border-radius: 50px;
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
  padding: .15rem .65rem;
}

.group-chevron {
  color: var(--text-muted);
  font-size: .85rem;
  transition: transform .2s;
}
.group-header.open .group-chevron { transform: rotate(90deg); }

.group-body {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow: clip;   /* clip visually but don't block child scroll contexts */
  display: none;
}
.group-body.open { display: block; }

.anime-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

.anime-table th {
  background: rgba(124,106,247,.12);
  color: var(--text-muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .45rem .9rem;
  text-align: left;
}

.anime-table td {
  padding: .42rem .9rem;
  border-top: 1px solid var(--border);
}

.anime-table tr:hover td { background: rgba(255,255,255,.03); }

.score-badge {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: .82rem;
  font-weight: 700;
  min-width: 36px;
  text-align: center;
  padding: .1rem .4rem;
  color: var(--accent2);
}

.score-user {
  color: var(--text-muted);
  border-color: transparent;
  background: transparent;
}

/* Scrollable table wrapper */
.table-scroll-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Sortable column headers */
.anime-table th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.anime-table th.sortable:hover {
  color: var(--text);
  background: rgba(124,106,247,.2);
}
.sort-icon {
  font-size: .7rem;
  margin-left: .25rem;
  opacity: .6;
}
.anime-table th.th-user {
  color: var(--accent);
}

/* Hours badge in group header */
.group-hours {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: .1rem .6rem;
  white-space: nowrap;
}

/* Share button */
.btn-share {
  background: transparent;
  border: 1px solid var(--accent2);
  color: var(--accent2);
  padding: .2rem .7rem;
  font-size: .8rem;
  border-radius: 6px;
  margin-left: auto;
}
.btn-share:hover {
  background: rgba(91,141,238,.15);
}

/* Import banner */
.import-banner {
  margin-top: .75rem;
  padding: .6rem 1rem;
  border-radius: 7px;
  font-size: .9rem;
}
.import-banner.info    { background: rgba(91,141,238,.15);  color: var(--accent2); border: 1px solid rgba(91,141,238,.3); }
.import-banner.success { background: rgba(74,222,128,.12);  color: var(--success); border: 1px solid rgba(74,222,128,.3); }
.import-banner.error   { background: rgba(248,113,113,.12); color: var(--error);   border: 1px solid rgba(248,113,113,.3); }

/* ================================================================
   Flat table stats bar (filtered intersection mode)
   ================================================================ */
.flat-table-stats {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-wrap: wrap;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  padding: .65rem 1rem;
  margin-bottom: 0;
}
.fts-label {
  flex: 1;
  font-size: .9rem;
  font-weight: 600;
}
.fts-include { color: var(--success); }
.fts-exclude { color: var(--error); }
.flat-table-stats + .table-scroll-wrap {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  /* no overflow:hidden – this element IS the scroll container */
}

/* ================================================================
   Group mean badge (intersection / franchise table headers)
   ================================================================ */
.group-mean {
  font-size: .78rem;
  font-weight: 600;
  color: var(--accent2);
  background: rgba(91,141,238,.13);
  border: 1px solid rgba(91,141,238,.3);
  border-radius: 50px;
  padding: .1rem .6rem;
  white-space: nowrap;
}

/* ================================================================
   Title links in intersection / franchise tables
   ================================================================ */
.title-link {
  color: inherit;
  text-decoration: none;
  transition: color .15s;
}
.title-link:hover {
  color: var(--accent, #5b8dee);
  text-decoration: underline;
}

/* ================================================================
   Genre badge in table group headers
   ================================================================ */
.group-genres {
  font-size: .74rem;
  font-weight: 400;
  color: var(--text-muted);
  opacity: .80;
  margin-left: .4rem;
}

/* ================================================================
   Mobile – intersection / franchise tables
   ================================================================ */
@media (max-width: 640px) {
  /* Allow group header to wrap so long genre badges don't overflow */
  .group-header {
    flex-wrap: wrap;
    row-gap: .35rem;
    padding: .55rem .75rem;
  }
  .group-title {
    font-size: .88rem;
    min-width: 0;
  }

  /* Hide the top-genres badge on mobile – it overflows small screens */
  .group-genres {
    display: none;
  }

  .group-hours,
  .group-mean {
    font-size: .7rem;
    padding: .08rem .5rem;
  }

  /* Stats bar (filtered flat-table mode) wraps nicely */
  .flat-table-stats {
    row-gap: .35rem;
    padding: .55rem .75rem;
  }
  .fts-label {
    font-size: .82rem;
    min-width: 0;
    flex-basis: 100%;   /* push stats to second line */
  }

  /* Table cells tighter on mobile */
  .anime-table {
    font-size: .8rem;
  }
  .anime-table th {
    padding: .35rem .55rem;
    font-size: .7rem;
  }
  .anime-table td {
    padding: .35rem .55rem;
  }

  .intersect-controls {
    gap: .45rem;
  }
}
