/**
 * LibZen Table — in-header funnel filters + filtered-out / empty states.
 *
 * Visual system is shared with PanelTable: load PanelTable.css first so fonts,
 * padding, borders, and spacing match exactly. This file adds the Excel-style
 * funnel glyph, the floating checklist menu, and empty / filtered-out states.
 *
 *   <link rel="stylesheet" href="../Panel/PanelTable.css">
 *   <link rel="stylesheet" href="table.css">
 */

/* —— header: label + funnel glyph (same row) —— */
.lz-tbl-th[data-filterable] {
  /* Keep clipped so narrow resize cannot spill into neighbor tracks. */
  overflow: hidden;
  text-overflow: clip;
  min-width: 0;
  /* Leave a strip for the resize rail so it does not cover the funnel. */
  padding-right: 0.85rem;
}

.lz-tbl-th-stack {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.2rem;
  min-width: 0;
  flex: 1 1 auto;
}

.lz-tbl-th-label {
  display: block;
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lz-tbl-th-center .lz-tbl-th-stack {
  justify-content: center;
}
.lz-tbl-th-center .lz-tbl-th-label {
  flex: 0 1 auto;
  text-align: center;
}

.lz-tbl-filter-btn {
  flex: 0 0 auto;
  position: relative;
  z-index: 6;
  width: 18px;
  height: 18px;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--libzen-text-muted, var(--muted));
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.55;
  user-select: none;
}
.lz-tbl-filter-btn:hover,
.lz-tbl-th.is-filter-open .lz-tbl-filter-btn,
.lz-tbl-filter-btn.is-active {
  opacity: 1;
  color: var(--libzen-accent, var(--accent));
  background: color-mix(in srgb, var(--libzen-accent, var(--accent)) 14%, transparent);
}
.lz-tbl-th.is-filter-active .lz-tbl-th-label {
  color: var(--libzen-text, var(--text));
}

/* —— header: sort arrow (double-click cycles up → down → table order) —— */
.lz-tbl-th-sortable {
  /* A double-click is the gesture, so the label must not select on the way. */
  user-select: none;
  -webkit-user-select: none;
  min-width: 0;
  overflow: hidden;
}
/* Non-filterable headers get the same strip so the rail cannot cover the arrow. */
.lz-tbl-th-sortable:not([data-filterable]) { padding-right: 0.85rem; }

/* The slot is always there — an empty one reads as table order — so turning a
   sort on cannot push the label into an ellipsis. */
.lz-tbl-sort {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 9px;
  line-height: 0;
  color: var(--libzen-accent, var(--accent));
}

.lz-tbl-th.is-sorted .lz-tbl-th-label { color: var(--libzen-text, var(--text)); }

/* Resize rail stays above the funnel hit target; stay inside clipped header. */
.lz-tbl-th[data-filterable] .lz-tbl-resize {
  z-index: 5;
  right: 0;
}

/* Host editors inside cells must shrink with the track. */
.lz-tbl-td input,
.lz-tbl-td select,
.lz-tbl-td textarea {
  max-width: 100%;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.lz-tbl-tr.is-filtered-out { display: none; }

.lz-tbl-empty {
  padding: 0.85rem 0.75rem;
  color: var(--libzen-text-muted, var(--muted));
  font-size: 0.88rem;
  font-style: italic;
}
.lz-tbl-empty[hidden] { display: none !important; }

/* Legacy below-header band / stacked Filter… input (removed on enhance). */
.lz-tbl-filters,
.lz-tbl-th .lz-tbl-filter {
  display: none !important;
}

/* —— floating Excel-style checklist menu —— */
.lz-tbl-filter-menu {
  position: fixed;
  z-index: 2400;
  width: 220px;
  max-height: min(360px, 70vh);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.45rem;
  box-sizing: border-box;
  border: 1px solid var(--libzen-border, var(--line));
  border-radius: 8px;
  background: var(--libzen-panel, var(--panel));
  color: var(--libzen-text, var(--text));
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  font: inherit;
  font-size: 0.82rem;
}

.lz-tbl-filter-search {
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 0.3rem 0.45rem;
  border: 1px solid var(--libzen-border, var(--line));
  border-radius: 5px;
  background: var(--libzen-surface, var(--panel-2, var(--panel)));
  color: inherit;
  font: inherit;
}
.lz-tbl-filter-search:focus {
  outline: none;
  border-color: var(--libzen-accent, var(--accent));
}

.lz-tbl-filter-actions {
  display: flex;
  gap: 0.65rem;
  padding: 0 0.1rem;
}
.lz-tbl-filter-link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--libzen-accent, var(--accent));
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}
.lz-tbl-filter-link:hover { text-decoration: underline; }

.lz-tbl-filter-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.15rem 0;
  border-top: 1px solid var(--libzen-border, var(--line));
  border-bottom: 1px solid var(--libzen-border, var(--line));
}

.lz-tbl-filter-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.22rem 0.3rem;
  border-radius: 4px;
  cursor: pointer;
  min-width: 0;
}
.lz-tbl-filter-option:hover {
  background: var(--libzen-surface-hover, var(--panel-2, var(--panel)));
}
.lz-tbl-filter-option input {
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--libzen-accent, var(--accent));
}
.lz-tbl-filter-option span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lz-tbl-filter-empty {
  margin: 0.4rem 0.3rem;
  color: var(--libzen-text-muted, var(--muted));
  font-style: italic;
}

.lz-tbl-filter-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}
.lz-tbl-filter-reset,
.lz-tbl-filter-apply {
  border: 1px solid var(--libzen-border, var(--line));
  border-radius: 5px;
  padding: 0.28rem 0.55rem;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}
.lz-tbl-filter-reset {
  background: transparent;
  color: var(--libzen-text, var(--text));
}
.lz-tbl-filter-apply {
  background: var(--libzen-accent, var(--accent));
  border-color: var(--libzen-accent, var(--accent));
  color: #fff;
}
.lz-tbl-filter-reset:hover {
  background: var(--libzen-surface-hover, var(--panel-2, var(--panel)));
}
.lz-tbl-filter-apply:hover { filter: brightness(1.06); }
