/* Ruleset Tables & Filters */

/* Sidebar Layout */
.ruleset-layout {
  display: flex;
  gap: var(--space-lg);
  height: calc(100vh - 220px);
  min-height: 400px;
}

.ruleset-sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  overflow: visible;
  padding-right: var(--space-sm);
}

.ruleset-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 900px;
}

.ruleset-table-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-xs);
}

/* Page header with title and count */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 0;
  padding-bottom: 0;
}

.page-header h1 {
  margin: 0 0 16px 0;
}

.page-header .results-count {
  font-size: var(--text-sm);
  color: var(--text-muted);
  position: relative;
  bottom: 0;
}

/* Filter Container */
.ruleset-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

/* Filter Header */
.filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.filter-header-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-reset-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.filter-reset-icon:hover:not(.disabled) {
  background: var(--bg-elevated);
  border-color: var(--accent-secondary);
  color: var(--accent-secondary);
}

.filter-reset-icon.disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

.filter-reset-icon svg {
  width: 16px;
  height: 16px;
}

/* Sidebar-specific filter styles */
.ruleset-sidebar .ruleset-filters {
  flex-direction: column;
  margin-bottom: 0;
}

.ruleset-sidebar .filter-row {
  flex-direction: column;
}

.ruleset-sidebar .filter-group {
  width: 100%;
}

.ruleset-sidebar .filter-group.filter-wide {
  min-width: 100%;
}

.ruleset-sidebar .filter-bottom-row {
  flex-direction: column;
  gap: var(--space-sm);
}

.ruleset-sidebar .filter-search {
  width: 100%;
}

.ruleset-sidebar .filter-reset {
  width: 100%;
  text-align: center;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  min-width: 150px;
}

.filter-group.filter-wide {
  min-width: 180px;
}

.filter-group label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-select {
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.filter-select:hover,
.filter-select:focus {
  border-color: var(--accent-secondary);
  outline: none;
}

.filter-search {
  position: relative;
  width: 100%;
}

.filter-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.filter-search input {
  width: 100%;
  padding: var(--space-xs) var(--space-sm) var(--space-xs) 32px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  transition: border-color var(--transition-fast);
}

.filter-search input:focus {
  border-color: var(--accent-secondary);
  outline: none;
}

.filter-search input::placeholder {
  color: var(--text-muted);
}

.filter-divider {
  width: 100%;
  height: 1px;
  background: var(--border-color);
  margin: var(--space-sm) 0;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  width: 100%;
}

.filter-bottom-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
  margin-top: var(--space-xs);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--border-color);
}

.filter-reset {
  padding: var(--space-xs) var(--space-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.filter-reset:hover {
  background: var(--bg-elevated);
  border-color: var(--accent-secondary);
  color: var(--text-primary);
}

/* Multi-select dropdown */
.filter-multiselect {
  position: relative;
  min-width: 150px;
}

.filter-multiselect-btn {
  width: 100%;
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  cursor: pointer;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color var(--transition-fast);
}

.filter-multiselect-btn:hover,
.filter-multiselect-btn:focus {
  border-color: var(--accent-secondary);
  outline: none;
}

.filter-multiselect-btn::after {
  content: '▼';
  font-size: 10px;
  margin-left: var(--space-xs);
  color: var(--text-muted);
}

.filter-multiselect-btn.active::after {
  content: '▲';
}

/* Inactive state (showing "Alle") */
.filter-multiselect-btn.inactive .filter-multiselect-text {
  color: var(--text-muted);
}

/* Active state (filter selected) */
.filter-multiselect-btn.has-selection {
  border-color: var(--accent-secondary);
  background: var(--bg-tertiary);
}

.filter-multiselect-btn.has-selection .filter-multiselect-text {
  color: var(--accent-secondary);
  font-weight: 600;
}

.filter-multiselect-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 100;
  margin-top: 2px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  max-height: 350px;
  overflow-y: auto;
}

.filter-multiselect.open .filter-multiselect-dropdown {
  display: block;
}

/* Dropdown opens upward when not enough space below */
.filter-multiselect.open-up .filter-multiselect-dropdown {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 2px;
}

.filter-multiselect-option {
  display: flex;
  align-items: center;
  padding: var(--space-xs) var(--space-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.filter-multiselect-option:hover {
  background: var(--bg-tertiary);
}

.filter-multiselect-option input[type="checkbox"] {
  margin-right: var(--space-xs);
  accent-color: var(--accent-secondary);
}

.filter-multiselect-option label {
  cursor: pointer;
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-primary);
  text-transform: none;
  font-weight: normal;
}

.filter-multiselect-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  background: var(--accent-secondary);
  color: white;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  margin-left: var(--space-xs);
}

/* Results Count */
.results-count {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
}

.results-count strong {
  color: var(--accent-secondary);
}

/* Ruleset Table */
.ruleset-table-container {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  scrollbar-color: var(--border-color) var(--bg-secondary);
}

.ruleset-table-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.ruleset-table-container::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 4px;
}

.ruleset-table-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.ruleset-table-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.ruleset-table {
  width: 100%;
  border-collapse: collapse;
}

.ruleset-table thead {
  background: var(--bg-tertiary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.ruleset-table th {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--accent-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
  user-select: none;
  transition: background var(--transition-fast);
}

/* Only show pointer and hover when sortable */
.ruleset-table th[data-sort] {
  cursor: pointer;
}

.ruleset-table th[data-sort]:hover {
  background: var(--bg-elevated);
}

.ruleset-table th.sorted-asc::after {
  content: ' ▲';
  font-size: var(--text-xs);
}

.ruleset-table th.sorted-desc::after {
  content: ' ▼';
  font-size: var(--text-xs);
}

.ruleset-table td {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

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

.ruleset-table tbody tr:hover {
  background: var(--bg-tertiary);
}

.ruleset-table tbody tr {
  cursor: pointer;
  transition: background var(--transition-fast);
}

/* Name column styling */
.ruleset-table td.name-cell {
  font-weight: 600;
  font-family: var(--font-display);
  color: var(--accent-secondary);
}

.ruleset-table td.name-cell a {
  color: inherit;
  text-decoration: none;
}

.ruleset-table td.name-cell a:hover {
  text-decoration: underline;
}

/* Level/Points badge */
.level-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 var(--space-xs);
  background: var(--bg-tertiary);
  color: var(--accent-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* Type badges */
.type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
}

.type-badge.merit {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.type-badge.flaw {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

/* Homebrew badge */
.homebrew-badge {
  display: inline-block;
  padding: 2px 8px;
  margin-left: var(--space-sm);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
  color: white;
  vertical-align: middle;
}

.homebrew-info {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-xs);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.homebrew-source,
.homebrew-author {
  display: inline-block;
}

/* Checkbox filter */
.filter-checkbox {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  margin: var(--space-sm) 0;
  margin-left: 4px;
}

.filter-checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  user-select: none;
}

.filter-checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-secondary);
  cursor: pointer;
}

.filter-checkbox-label span {
  font-weight: 500;
}

/* Homebrew label in table */
.homebrew-label {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1;
}

/* Source tags */
.source-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.source-tag {
  display: inline-block;
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* Roll display */
.roll-display {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Cost display */
.cost-display {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Level group headers - sticky below table header */
.level-group-header {
  position: sticky;
  top: 55px; /* Height of thead row */
  z-index: 5;
}

.level-group-header td {
  background: var(--bg-primary);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: var(--space-xs) var(--space-md);
  border-bottom: 1px solid var(--border-color);
  border-top: 1px solid var(--border-color);
}

.level-group-header:first-child td {
  border-top: none;
}

.level-group-header:hover {
  background: var(--bg-primary) !important;
  cursor: default;
}

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

/* Loading state */
.ruleset-loading {
  text-align: center;
  padding: var(--space-xl);
  color: var(--text-muted);
}

/* Empty state */
.ruleset-empty {
  text-align: center;
  padding: var(--space-xl);
  color: var(--text-muted);
}

.ruleset-empty-icon {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-sm);
}

/* Responsive */
@media (max-width: 1024px) {
  .ruleset-layout {
    flex-direction: column;
    height: auto;
  }

  .ruleset-sidebar {
    width: 100%;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .ruleset-main {
    max-width: 100%;
  }

  .ruleset-table-container {
    max-height: 60vh;
  }
}

@media (max-width: 768px) {
  .filter-row {
    flex-direction: column;
  }

  .filter-group {
    width: 100%;
  }

  .filter-group.filter-wide {
    min-width: 100%;
  }

  .filter-bottom-row {
    flex-direction: column;
    gap: var(--space-sm);
  }

  .filter-search {
    width: 100%;
  }

  .filter-reset {
    width: 100%;
    text-align: center;
  }

  .ruleset-table th,
  .ruleset-table td {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--text-xs);
  }

  /* Hide less important columns on mobile */
  .ruleset-table th.hide-mobile,
  .ruleset-table td.hide-mobile {
    display: none;
  }

  .ruleset-table-container {
    max-height: 50vh;
  }
}
