/* ── Datatable  -  IBM Carbon DataTable-style picker component ──────────
   Used by: agents.html (tools picker, skills picker)
   IDs are generated by the datatable partial with a {prefix} convention.
   ─────────────────────────────────────────────────────────────────── */

/* ── Container ───────────────────────────────────────────────────── */
.dt-box   { border: 1px solid var(--border); }
.dt-inner { overflow-y: auto; max-height: 240px; background: var(--panel-bg); }

/* ── Toolbar ─────────────────────────────────────────────────────── */
.dt-toolbar {
  display: flex; align-items: center;
  padding: 0 0 0 0.75rem; height: 3rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.dt-title {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-secondary); flex-shrink: 0;
}
.dt-count-badge {
  background: var(--blue-60); color: var(--text-on-color);
  font-size: 0.6875rem; padding: 0.1rem 0.4rem;
  font-weight: 600; border-radius: 0.75rem; margin-left: 0.375rem;
}

/* ── Toolbar action area ─────────────────────────────────────────── */
.dt-toolbar-actions {
  display: flex; align-items: center; flex-shrink: 0;
  margin-left: auto; height: 100%;
}
.dt-toolbar.search-active .dt-toolbar-actions {
  flex: 1; margin-left: 0;
}

/* ── Search area ─────────────────────────────────────────────────── */
.dt-search-area {
  display: flex; align-items: center;
  width: 0; overflow: hidden; opacity: 0;
  border: 2px solid transparent;
  background: var(--surface); height: 100%;
  transition: width .28s cubic-bezier(0.4,0,0.2,1), opacity .2s ease, border-color .15s ease;
}
.dt-toolbar.search-active .dt-search-area {
  flex: 1; width: auto; opacity: 1; border-color: var(--blue-60); overflow: visible;
}
html.dark .dt-toolbar.search-active .dt-search-area { border-color: var(--blue-40); }

.dt-search-icon  { flex-shrink: 0; margin: 0 0.5rem; color: var(--text-secondary); pointer-events: none; }
.dt-search-field {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 0.8125rem; color: var(--text); padding: 0.375rem 0;
  min-width: 0; font-family: inherit;
}
.dt-search-clear {
  display: flex; align-items: center; justify-content: center;
  width: 2rem; height: 100%; background: none; border: none;
  cursor: pointer; color: var(--text-secondary); flex-shrink: 0;
}
.dt-search-clear:hover { color: var(--text); }

/* Hide the search toggle button when search is active */
.dt-toolbar.search-active .dt-search-toggle-btn { display: none; }

/* ── Toolbar icon buttons ────────────────────────────────────────── */
.dt-tb-btn {
  display: flex; align-items: center; justify-content: center;
  width: 3rem; height: 3rem; background: none; border: none; cursor: pointer;
  color: var(--text-secondary); transition: background .1s, color .1s;
}
.dt-tb-btn:hover { background: var(--hover-bg, rgba(0,0,0,.06)); color: var(--text); }
html.dark .dt-tb-btn:hover { background: rgba(255,255,255,.08); }
.dt-tb-btn.active {
  background: var(--surface); color: var(--text);
  outline: 2px solid var(--blue-60); outline-offset: -2px;
}

/* ── Toolbar popovers ────────────────────────────────────────────── */
.dt-tb-popover-wrap { position: relative; }
.dt-tb-dropdown {
  position: absolute; top: 100%; right: 0;
  background: var(--panel-bg); border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  z-index: 100; min-width: 14rem;
}
.dt-tb-dropdown-head {
  padding: 0.625rem 1rem; font-size: 0.75rem; font-weight: 600;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
.dt-tb-checkbox {
  display: flex; align-items: center; gap: 0.625rem;
  padding: 0.625rem 1rem; font-size: 0.875rem; color: var(--text);
  cursor: pointer; user-select: none;
}
.dt-tb-checkbox input[type="checkbox"] {
  width: 1rem; height: 1rem; accent-color: var(--blue-60); cursor: pointer; flex-shrink: 0;
}
.dt-tb-dropdown-footer { display: flex; border-top: 1px solid var(--border); }
.dt-tb-footer-reset, .dt-tb-footer-apply {
  flex: 1; padding: 0.75rem 1rem; font-size: 0.875rem; font-weight: 500;
  border: none; cursor: pointer; font-family: inherit;
}
.dt-tb-footer-reset       { background: var(--gray-80, #393939); color: var(--gray-10, #f4f4f4); }
.dt-tb-footer-reset:hover { background: var(--btn-secondary-hover, #474747); }
.dt-tb-footer-apply       { background: var(--blue-60); color: var(--text-on-color); }
.dt-tb-footer-apply:hover { background: var(--blue-70, #0353e9); }
.dt-tb-action-item {
  display: block; width: 100%; padding: 0.75rem 1rem;
  font-size: 0.875rem; color: var(--text); background: none;
  border: none; cursor: pointer; text-align: left; font-family: inherit;
  border-bottom: 1px solid var(--border); transition: background .1s;
}
.dt-tb-action-item:last-child { border-bottom: none; }
.dt-tb-action-item:hover { background: var(--hover-bg, rgba(0,0,0,.06)); }
html.dark .dt-tb-action-item:hover { background: rgba(255,255,255,.08); }

/* ── Select-all header ──────────────────────────────────────────── */
.dt-select-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.dt-select-all-cb {
  width: 1rem; height: 1rem; accent-color: var(--blue-60);
  cursor: pointer; flex-shrink: 0;
}
.dt-select-header-label {
  font-size: 0.875rem; font-weight: 600; color: var(--text);
}

/* ── Data rows (JS-rendered, align with column headers) ─────────── */
.dt-data-row {
  display: flex; align-items: center;
  padding: 0 0.75rem; min-height: 3rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg); transition: background 0.1s;
}
.dt-data-row:last-child { border-bottom: none; }
.dt-data-row:hover { background: var(--hover-bg); }

/* ── Expandable rows ────────────────────────────────────────────── */
.dt-expand-row { display: none; background: var(--layer); border-bottom: 1px solid var(--border); }
.dt-expand-row--open { display: table-row; }
.dt-expand-row td, .dt-expand-row > div { padding: 1rem; }
.dt-expand-btn { background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 0.25rem; display: flex; align-items: center; transition: transform 0.15s; }
.dt-expand-btn--open { transform: rotate(180deg); }

/* ── Batch action bar ───────────────────────────────────────────── */
.dt-batch-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 1rem; background: var(--blue-60);
  color: var(--text-on-color);
}
.dt-batch-count { font-size: 0.875rem; font-weight: 400; }
.dt-batch-actions { display: flex; align-items: center; gap: 0.5rem; }

/* ── Legacy rows (non-column-header mode) ───────────────────────── */
.dt-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
}
.dt-row:last-child  { border-bottom: none; }
.dt-row:hover       { background: var(--surface); }
.dt-row--selected   { background: var(--selected-bg, #e0e0e0); }
html.dark .dt-row--selected { background: var(--selected-bg, #353535); }
.dt-row--selected:hover { background: var(--selected-bg, #e0e0e0); }
html.dark .dt-row--selected:hover { background: var(--selected-bg, #3d3d3d); }
.dt-row-info        { flex: 1; min-width: 0; }
.dt-row-name-line   { display: flex; align-items: center; gap: 0.375rem; flex-wrap: wrap; }
.dt-row-name        { font-size: 0.875rem; font-weight: 500; color: var(--text); }
.dt-row-desc        { font-size: 0.75rem; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Type badges */
.dt-type-tag {
  font-size: 0.75rem; font-weight: 400; padding: 0 0.5rem;
  height: 1.5rem; display: inline-flex; align-items: center;
  border-radius: 1rem; line-height: 1; white-space: nowrap;
}
.dt-type-tag--internal { background: var(--gray-20, #e0e0e0); color: var(--gray-100, #161616); }
html.dark .dt-type-tag--internal { background: var(--gray-70, #525252); color: var(--gray-10, #f4f4f4); }
.dt-type-tag--external { background: var(--blue-20, #d0e2ff); color: var(--blue-70, #0043ce); }
html.dark .dt-type-tag--external { background: var(--blue-80, #002d9c); color: var(--blue-30, #a6c8ff); }
.dt-type-tag--skill    { background: rgba(15,98,254,.1); color: var(--blue-60); border: 1px solid rgba(15,98,254,.2); font-family: 'IBM Plex Mono', monospace; }
html.dark .dt-type-tag--skill { background: rgba(120,169,255,.12); color: var(--blue-40); border-color: rgba(120,169,255,.25); }
.dt-type-tag--autoload { background: rgba(36,161,72,.1); color: var(--green-60, #198038); border: 1px solid rgba(36,161,72,.2); }
html.dark .dt-type-tag--autoload { color: var(--green-40, #42be65); background: rgba(66,190,101,.1); border-color: rgba(66,190,101,.25); }

.dt-count-label { font-size: 0.75rem; font-weight: 400; color: var(--blue-60); }
.dt-conn-error { display:inline-flex; align-items:center; gap:0.25rem; font-size:0.75rem; color:var(--support-warning); font-weight:500; cursor:default; }
.dt-row--error { background: rgba(245,166,35,.05); }
html.dark .dt-row--error { background: rgba(245,166,35,.07); }

/* ── Carbon toggle (row on/off) ──────────────────────────────────── */
.dt-toggle       { display: inline-flex; align-items: center; cursor: pointer; }
.dt-toggle input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.dt-toggle-track {
  position: relative; width: 2rem; height: 1rem;
  background: var(--gray-40, #8d8d8d); border-radius: 0.5rem;
  transition: background .15s; flex-shrink: 0;
}
.dt-toggle input:checked ~ .dt-toggle-track { background: var(--blue-60); }
.dt-toggle-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px;
  background: var(--icon-on-color, #fff); border-radius: 50%; transition: transform .15s;
}
.dt-toggle input:checked ~ .dt-toggle-track .dt-toggle-thumb { transform: translateX(1rem); }
.dt-toggle:focus-within .dt-toggle-track { outline: 2px solid var(--blue-60); outline-offset: 2px; }

/* ── Empty / message ─────────────────────────────────────────────── */
.dt-message { padding: 0.75rem; font-size: 0.8125rem; color: var(--text-secondary); }
.dt-empty-link { color: var(--blue-60); text-decoration: none; }
html.dark .dt-empty-link { color: var(--blue-40); }
.dt-empty-link:hover { text-decoration: underline; }

/* ══════════════════════════════════════════════════════════════════════
   Persistent Toolbar variant
   ══════════════════════════════════════════════════════════════════════ */

/* ── Title block ───────────────────────────────────────────────────── */
.dt-toolbar--persistent {
  flex-wrap: wrap; padding: 0; height: auto; min-height: 3rem;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.dt-toolbar-title-block {
  display: flex; flex-direction: column; justify-content: center;
  padding: 0.75rem 1rem; flex-shrink: 0;
}
.dt-title--persistent {
  font-size: 0.875rem; font-weight: 600;
  text-transform: none; letter-spacing: normal; color: var(--text);
}
.dt-subtitle {
  font-size: 0.75rem; font-weight: 400; color: var(--text-secondary);
  margin-top: 0.125rem;
}

/* ── Persistent actions bar ────────────────────────────────────────── */
.dt-toolbar-actions--persistent {
  display: flex; align-items: center; margin-left: auto;
  height: 3rem; gap: 0; flex: 1; min-width: 0;
}

/* ── Always-visible search ─────────────────────────────────────────── */
.dt-search-persistent {
  display: flex; align-items: center; height: 3rem;
  background: var(--panel-bg); border-left: 1px solid var(--border);
  flex: 1; min-width: 0;
  transition: border-color .15s ease;
}
.dt-search-persistent:focus-within {
  outline: 2px solid var(--blue-60); outline-offset: -2px;
}
html.dark .dt-search-persistent:focus-within {
  outline-color: var(--blue-40);
}
.dt-search-persistent .dt-search-icon { flex-shrink: 0; margin: 0 0.5rem; color: var(--text-secondary); }
.dt-search-persistent .dt-search-field { flex: 1; min-width: 0; }
.dt-search-persistent .dt-search-clear { height: 3rem; }

/* ── Primary action button ─────────────────────────────────────────── */
.dt-primary-action {
  height: 3rem; padding: 0 1rem; white-space: nowrap;
  font-size: 0.875rem; border-radius: 0;
}

/* ── Column headers (Carbon DataTable) ─────────────────────────────── */
.dt-col-header {
  display: flex; align-items: stretch;
  background: var(--gray-20, #e0e0e0); border-bottom: 1px solid var(--border);
}
html.dark .dt-col-header { background: var(--gray-70, #525252); }
.dt-col-cell {
  display: flex; align-items: center;
  font-size: 0.8125rem; font-weight: 600;
  color: var(--text); padding: 0;
  min-height: 3rem;
}
.dt-col-cell:not(.dt-col-cell--sortable) { padding: 0 1rem; }
.dt-col-cell--check { justify-content: center; }
.dt-col-cell--check input[type="checkbox"] {
  width: 1rem; height: 1rem; accent-color: var(--blue-60); cursor: pointer;
}
.dt-col-cell:not([style*="width"]) { flex: 1; }
.dt-col-label { font-size: 0.8125rem; font-weight: 600; color: var(--text); }

/* ── Sort button (Carbon spec: fills the entire header cell) ───────── */
.dt-sort-btn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; height: 100%; min-height: 3rem;
  padding: 0 0.5rem 0 1rem;
  background: transparent; border: none; cursor: pointer;
  font: inherit; color: var(--text); text-align: left;
  transition: background 0.1s;
}
.dt-sort-btn:hover { background: var(--gray-30, #c6c6c6); }
html.dark .dt-sort-btn:hover { background: var(--gray-60, #6f6f6f); }
.dt-sort-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.dt-sort-btn__inner {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; gap: 0.5rem;
}

/* Sort icons: show only the icon matching current sort state */
.dt-sort-icon { flex-shrink: 0; opacity: 0; transition: opacity 0.1s, transform 0.1s; }
.dt-sort-icon--unsorted { opacity: 1; }
.dt-sort-btn:hover .dt-sort-icon--unsorted { opacity: 1; }
.dt-sort-icon--asc, .dt-sort-icon--desc { display: none; }

/* Active sort states */
.dt-sort-btn[data-sort-dir="asc"] .dt-sort-icon--unsorted { display: none; }
.dt-sort-btn[data-sort-dir="asc"] .dt-sort-icon--asc { display: block; opacity: 1; }
.dt-sort-btn[data-sort-dir="desc"] .dt-sort-icon--unsorted { display: none; }
.dt-sort-btn[data-sort-dir="desc"] .dt-sort-icon--desc { display: block; opacity: 1; }

/* Active sort column gets highlighted bg */
.dt-col-cell--sortable:has(.dt-sort-btn[data-sort-dir="asc"]),
.dt-col-cell--sortable:has(.dt-sort-btn[data-sort-dir="desc"]) {
  background: var(--gray-30, #c6c6c6);
}
html.dark .dt-col-cell--sortable:has(.dt-sort-btn[data-sort-dir="asc"]),
html.dark .dt-col-cell--sortable:has(.dt-sort-btn[data-sort-dir="desc"]) {
  background: var(--gray-60, #6f6f6f);
}

/* ── Persistent inner (taller scroll area) ─────────────────────────── */
.dt-inner--persistent { max-height: none; }

/* ── Row size variants (Carbon DataTable density) ──────────────────── */
.dt-size-xs .dt-data-row,
.dt-size-xs .dt-row      { min-height: 1.5rem; padding-top: 0.125rem; padding-bottom: 0.125rem; }
.dt-size-xs .dt-col-cell,
.dt-size-xs .dt-sort-btn  { min-height: 1.5rem; }
.dt-size-sm .dt-data-row,
.dt-size-sm .dt-row       { min-height: 2rem; padding-top: 0.25rem; padding-bottom: 0.25rem; }
.dt-size-sm .dt-col-cell,
.dt-size-sm .dt-sort-btn  { min-height: 2rem; }
.dt-size-lg .dt-data-row,
.dt-size-lg .dt-row       { min-height: 4rem; }
.dt-size-lg .dt-col-cell,
.dt-size-lg .dt-sort-btn  { min-height: 4rem; }
.dt-size-xl .dt-data-row,
.dt-size-xl .dt-row       { min-height: 4.5rem; }
.dt-size-xl .dt-col-cell,
.dt-size-xl .dt-sort-btn  { min-height: 4.5rem; }

/* ── Pagination wrapper ───────────────────────────────────────────── */
.dt-pagination-wrap { border-top: 1px solid var(--border); }
