/**
 * LibZen PanelTable — table-mode container for Panel "items".
 *
 * Sits on top of the Panel base (panel.css supplies the --libzen-* theme tokens
 * and the .libzen-pn-collapse-chevron glyph; PanelDrag.js powers row reorder).
 *
 * Model: the container "knows" it is a table — every row shares one CSS-grid
 * column template (`--lz-tbl-cols`, set by PanelTable.js from the column defs +
 * any user-resized widths). Rows are draggable (reorder), groups collapse, and
 * column boundaries resize via drag handles in the header. One column is fluid
 * (`minmax(min,1fr)`) so a short grid fills the pane; a wide grid (many fixed
 * tracks, or user-resized columns) may overflow. Header and rows share one
 * scrollport so labels stay aligned with cells on both axes. PanelTable.fitHeight
 * caps the box to the viewport; the header pins with position: sticky.
 */

.lz-tbl {
  /* Fallback template; PanelTable.js overwrites this from the column defs. */
  --lz-tbl-cols: 22px minmax(120px, 1fr) 30px;
  --lz-tbl-grip: 22px;
  --lz-tbl-chev: 30px;
  border: 1px solid var(--libzen-border, var(--line));
  border-radius: 10px;
  /* One scrollport for header + rows. A split (body overflow-y: auto, header
     overflow: hidden) lets overflow-x compute to auto on the body only, so
     cells scroll sideways while labels stay put — PD (and every other column)
     then sits under the wrong header. Sticky top keeps labels visible while
     this box scrolls vertically. min-width: 0 lets a flex host shrink the
     table so wide tracks overflow here instead of stretching the pane. */
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--libzen-panel, var(--panel));
  color: var(--libzen-text, var(--text));
  margin: 0 0 1rem;
}

/* Header + each row shrink-wrap the column tracks, but never less than the
   pane, so 1fr still fills leftover space when the grid is narrower than the
   table. Same used width → labels stay over their cells. */
.lz-tbl-cols,
.lz-tbl-body,
.lz-tbl-group,
.lz-tbl-rows,
.lz-tbl-tr {
  width: max-content;
  min-width: 100%;
  box-sizing: border-box;
}

/* —— column header band (labels + resize handles) —— */
.lz-tbl-cols {
  display: grid;
  grid-template-columns: var(--lz-tbl-cols);
  align-items: stretch;
  flex: 0 0 auto;
  background: var(--libzen-surface, var(--panel-2, var(--panel)));
  border-bottom: 1px solid var(--libzen-border, var(--line));
  /* Pin in this table's scrollport (and in an ancestor when data-no-fit).
     Chromium will not stick an element whose overflow is not visible —
     cells still clip their own text. */
  position: sticky;
  top: 0;
  z-index: 5;
  overflow: visible;
}

/* Rows live in normal flow so they share the table's horizontal scroll.
   Height comes from the rows (flex: none); the table box scrolls vertically. */
.lz-tbl-body {
  flex: 0 0 auto;
  min-height: 0;
  overflow: visible;
}

/*
 * data-no-fit: table grows with its rows and an ancestor scrolls.
 * The header is already sticky; keep overflow visible so it can pin in that
 * ancestor (same Chromium sticky + overflow rule as above).
 */
.lz-tbl[data-no-fit] {
  overflow: visible;
}

.lz-tbl-th {
  position: relative;
  display: flex;
  align-items: center;
  /* Allow fixed/minmax tracks to shrink without the header's min-content
     stretching into neighboring columns. */
  min-width: 0;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--libzen-text-muted, var(--muted));
  padding: 0.5rem 0.55rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}
.lz-tbl-th-center { justify-content: center; padding-left: 0.15rem; padding-right: 0.15rem; }
.lz-tbl-th-grip { padding: 0; }

/* Column resize handle: grab strip on the column's right edge.
   Always shows a faint rail so the handle is discoverable; accent on hover. */
.lz-tbl-resize {
  position: absolute;
  top: 0;
  bottom: 0;
  right: -5px;
  width: 10px;
  cursor: col-resize;
  touch-action: none;
  z-index: 4;
}
.lz-tbl-resize::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 1px;
  /* Always visible on light and dark panels — not hover-only. */
  background: color-mix(
    in srgb,
    var(--libzen-border, var(--line, #2d3a4f)) 55%,
    var(--libzen-text-muted, var(--muted, #94a3b8)) 45%
  );
  opacity: 0.95;
}
.lz-tbl-resize::after {
  content: '';
  position: absolute;
  top: 22%;
  bottom: 22%;
  left: 3px;
  width: 3px;
  background: transparent;
  border-radius: 2px;
  transition: background 0.15s;
}
.lz-tbl-resize:hover::before,
.lz-tbl-resize-active .lz-tbl-resize::before,
.lz-tbl-resize:hover::after,
.lz-tbl-resize-active .lz-tbl-resize::after {
  background: var(--libzen-accent, var(--accent));
}
body.lz-tbl-resizing { cursor: col-resize; user-select: none; }

/* —— group section (group name + collapse-all chevron) —— */
.lz-tbl-group + .lz-tbl-group { border-top: 1px solid var(--libzen-border, var(--line)); }

.lz-tbl-group-head {
  display: flex;
  align-items: center;
}
.lz-tbl-group-toggle {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  background: transparent;
  border: 0;
  color: var(--libzen-text, var(--text));
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
}
.lz-tbl-group-toggle:hover { background: var(--libzen-surface-hover, var(--panel-2, var(--panel))); }
.lz-tbl-group-add {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-right: 0.5rem;
  padding: 0;
  border: 1px solid var(--libzen-border, var(--line));
  border-radius: 6px;
  background: transparent;
  color: var(--libzen-text-muted, var(--muted));
  cursor: pointer;
}
.lz-tbl-group-add:hover {
  color: var(--libzen-text, var(--text));
  border-color: var(--libzen-accent, var(--accent));
  background: var(--libzen-surface-hover, var(--panel-2, var(--panel)));
}
.lz-tbl-group-add svg { width: 14px; height: 14px; display: block; }
.lz-tbl-group-count {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--libzen-text-muted, var(--muted));
}
.lz-tbl-group.is-collapsed .lz-tbl-rows { display: none; }

/* —— rows —— */
.lz-tbl-tr {
  display: grid;
  grid-template-columns: var(--lz-tbl-cols);
  align-items: center;
  border-top: 1px solid var(--libzen-border, var(--line));
}
.lz-tbl-tr:hover { background: var(--libzen-surface-hover, var(--panel-2, var(--panel))); }

.lz-tbl-td {
  min-width: 0;
  padding: 0.5rem 0.55rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.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-td-center { display: flex; justify-content: center; padding-left: 0.15rem; padding-right: 0.15rem; }
.lz-tbl-td-name { font-weight: 600; }
.lz-tbl-td-name a { color: inherit; text-decoration: none; }
.lz-tbl-td-name a:hover { text-decoration: underline; }
.lz-tbl-td-muted { color: var(--libzen-text-muted, var(--muted)); font-size: 0.82rem; }
/* Wrapping cell (e.g. an Activities list) — show the full content inline by
   growing the row's height rather than truncating. */
.lz-tbl-td-wrap { white-space: normal; overflow-wrap: anywhere; }

.lz-tbl-grip {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--libzen-text-muted, var(--muted));
  cursor: grab;
  user-select: none;
  font-size: 0.9rem;
  line-height: 1;
}
.lz-tbl-grip:active { cursor: grabbing; }

/* —— drag feedback —— */
.lz-tbl-tr.is-dragging { opacity: 0.45; }
.lz-tbl-tr.drop-before { box-shadow: inset 0 2px 0 0 var(--libzen-accent, var(--accent)); }
.lz-tbl-tr.drop-after { box-shadow: inset 0 -2px 0 0 var(--libzen-accent, var(--accent)); }

/* Optional tiny inline save indicator (apps can drop a .lz-tbl-status span in a cell). */
.lz-tbl-status {
  font-size: 0.7rem;
  color: var(--libzen-text-muted, var(--muted));
  opacity: 0;
  transition: opacity 0.3s ease, color 0.15s ease;
}
.lz-tbl-status.is-visible { opacity: 1; }
.lz-tbl-status.is-ok { color: var(--ok, #4ade80); }
.lz-tbl-status.is-err { color: var(--danger, #f87171); }
