/* ===================================================================
   StreamCFD Admin Table Tools: Universal Header Sort & Filter
   =================================================================== */

/* Header cell container with flex layout */
th.th-enhanced {
  position: relative;
  user-select: none;
}

.th-header-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 0.4rem;
}

.th-title-sort {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  flex: 1;
  min-width: 0;
  transition: color 0.15s ease;
}

.th-title-sort:hover {
  color: var(--accent-primary, #58a6ff);
}

.th-sort-icon {
  font-size: 0.7rem;
  opacity: 0.45;
  transition: opacity 0.15s, color 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.th-sort-icon.active-asc,
.th-sort-icon.active-desc {
  opacity: 1;
  color: var(--accent-primary, #58a6ff);
}

/* Filter Trigger Button in Header */
.th-filter-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted, #8b949e);
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: var(--radius-sm, 4px);
  font-size: 0.68rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.th-filter-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary, #f0f6fc);
  border-color: var(--border-color, #30363d);
}

.th-filter-btn.has-filter {
  color: #fff !important;
  background: var(--accent-primary, #238636) !important;
  border-color: var(--accent-primary, #238636) !important;
  box-shadow: 0 0 6px rgba(56, 139, 253, 0.5);
}

/* Floating Filter Popover Dropdown */
.th-filter-popover {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 9999;
  background: var(--bg-surface, #161b22);
  border: 1px solid var(--border-color, #30363d);
  border-radius: var(--radius-sm, 6px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.65);
  padding: 0.65rem 0.75rem;
  min-width: 230px;
  max-width: 300px;
  color: var(--text-primary, #f0f6fc);
  font-size: 0.76rem;
  text-transform: none;
  font-weight: 400;
  letter-spacing: normal;
  display: none;
  animation: popoverFadeIn 0.15s ease-out;
}

[data-theme="light"] .th-filter-popover {
  background: #ffffff;
  border-color: #d0d7de;
  box-shadow: 0 8px 24px rgba(140, 149, 159, 0.35);
  color: #1f2328;
}

@keyframes popoverFadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.th-filter-popover.open {
  display: block;
}

.th-filter-popover input[type="text"],
.th-filter-popover input[type="date"] {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-primary, #0d1117);
  border: 1px solid var(--border-color, #30363d);
  border-radius: 4px;
  color: var(--text-primary, #f0f6fc);
  padding: 0.32rem 0.55rem;
  font-size: 0.74rem;
  margin-bottom: 0.45rem;
}

[data-theme="light"] .th-filter-popover input[type="text"],
[data-theme="light"] .th-filter-popover input[type="date"] {
  background: #f6f8fa;
  border-color: #d0d7de;
  color: #1f2328;
}

.th-filter-popover input:focus {
  outline: none;
  border-color: var(--accent-primary, #58a6ff);
}

.th-date-range-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.th-date-range-row > div {
  flex: 1;
}

.th-date-range-row label {
  display: block;
  font-size: 0.66rem;
  color: var(--text-muted, #8b949e);
  margin-bottom: 0.15rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.th-quick-presets {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.th-preset-chip {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color, #30363d);
  color: var(--text-secondary, #8b949e);
  padding: 0.12rem 0.42rem;
  font-size: 0.67rem;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
}

.th-preset-chip:hover {
  background: var(--accent-primary, #58a6ff);
  color: #fff;
  border-color: var(--accent-primary, #58a6ff);
}

.th-filter-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-color, #30363d);
  padding-top: 0.45rem;
  margin-top: 0.25rem;
}

/* Active Table Filter Banner */
.table-filter-status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.65rem;
  background: rgba(56, 139, 253, 0.08);
  border: 1px solid rgba(56, 139, 253, 0.25);
  border-radius: var(--radius-sm, 4px);
  margin-bottom: 0.5rem;
  font-size: 0.74rem;
  color: var(--text-primary, #f0f6fc);
}

.table-filter-status-banner .clear-all-btn {
  background: transparent;
  border: 1px solid rgba(248, 81, 73, 0.4);
  color: #f85149;
  border-radius: 3px;
  padding: 0.1rem 0.45rem;
  font-size: 0.68rem;
  cursor: pointer;
  transition: background 0.15s;
}

.table-filter-status-banner .clear-all-btn:hover {
  background: rgba(248, 81, 73, 0.15);
}
