/*
 * Over — Data table
 */

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  overflow: hidden;
}

.table thead th {
  text-align: left;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-dim);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

.table tbody td {
  font-size: var(--fs-base);
  color: var(--text);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 0.12s; }
.table tbody tr:hover { background: var(--surface-hover); }

.table__muted { color: var(--text-faint); }

/* ── View renderer (Views module "table" kind) ── */

/* Horizontal scroll lives on this wrapper only, so the surrounding page never
   scrolls sideways (Notion-style: the table scrolls, not the section). */
.view-tablescroll {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  background: var(--surface);
}

/* Inside the scroller the table keeps its min-width (set inline from column
   widths) and drops its own border/radius (the wrapper owns them). */
.view-tablescroll > .table {
  border: none;
  border-radius: 0;
}

/* Fixed layout so per-column widths are honoured and long cells clip cleanly. */
.table--view { table-layout: fixed; }
.table--view tbody td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Right-align numeric columns (header + cells). */
.table--view th.is-num,
.table--view td.is-num { text-align: right; }
.table--view td.table__cell--center { text-align: center; }

/* Header: clickable label (sort) + a resize grip on the right edge. */
.table--view thead th { position: relative; }
.table__th-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  user-select: none;
  min-width: 0;
}
.table__th-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table__coltype {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--fw-normal);
  flex: none;
}
.table__sortdir { color: var(--accent); margin-left: auto; flex: none; }

.table__resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 1;
}
.table__resizer:hover { background: var(--accent); opacity: 0.5; }
body.is-col-resizing { cursor: col-resize; user-select: none; }

/* Typed cell content. */
.vcell-primary { color: var(--text); font-weight: var(--fw-medium); }
.vcell-muted { color: var(--text-faint); }
.vcell-check { color: var(--success); display: inline-flex; }
.vcell-badges { display: inline-flex; gap: var(--sp-1); flex-wrap: wrap; }
.vcell-link { color: var(--accent); text-decoration: none; }
.vcell-link:hover { text-decoration: underline; }

/* Consistent checkbox control (identical in every state). */
.vcheck {
  width: var(--icon);
  height: var(--icon);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: transparent;
  transition: background 0.12s, border-color 0.12s;
}
.vcheck:hover { border-color: var(--accent); }
.vcheck.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--white);
}
.vcheck svg { width: 12px; height: 12px; }
.vcheck:disabled { opacity: 0.5; cursor: default; }

/* Select popover (replaces the raw <select> for a consistent look). */
.vpopover {
  position: fixed;
  z-index: var(--z-menu);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: var(--sp-1);
  max-height: 260px;
  overflow-y: auto;
}
.vpopover__list { display: flex; flex-direction: column; gap: 2px; }
.vpopover__opt {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  text-align: left;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-sm);
}
.vpopover__opt:hover { background: var(--surface-hover); }
.vpopover__opt.is-current { background: var(--surface-hover); }

/* Record picker (table-style relation dropdown with search). Mirrors .vpopover:
   a floating surface, but wide enough to hold the design-system table + a search bar. */
.vpicker {
  position: fixed;
  z-index: var(--z-menu);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: var(--sp-2);
  width: 420px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.vpicker__search {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--sp-1) var(--sp-2);
  height: var(--field-h);
}
.vpicker__body {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
}
/* Read-only preset of the table, used inside the picker (no fixed layout / chrome). */
.table--pick { border: none; border-radius: 0; }
.table--pick thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.vpicker__row { cursor: pointer; }
.vpicker__row:hover { background: var(--surface-hover); }

/* Relation (link) value: the resolved target label. */
.vcell-rel { color: var(--accent); }

/* Meta line above a view (record count). */
.view-meta {
  color: var(--text-dim);
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-3);
}

/* Loading / empty / error states. */
.view-state {
  padding: var(--sp-5);
  text-align: center;
  color: var(--text-dim);
  font-size: var(--fs-base);
}
.view-state--error { color: var(--danger); }

/* Toolbar (New row, Filter, sort chip, sample seed). */
.view-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
  flex-wrap: wrap;
}
/* A count sitting inside the toolbar is pushed to the right and drops its
   standalone bottom margin (actions left · count right). */
.view-toolbar .view-meta {
  margin: 0 0 0 auto;
}
.view-toolbar--empty { margin-top: var(--sp-3); justify-content: center; }
.btn.is-active { border-color: var(--accent); color: var(--text); }

/* Filter panel. */
.vfilter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  margin-bottom: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.vfilter-rows { display: flex; flex-direction: column; gap: var(--sp-2); }
.vfilter-row { display: flex; align-items: center; gap: var(--sp-2); }
.vfilter-select,
.vfilter-input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--sp-1) var(--sp-2);
  height: var(--navitem-h);
}
.vfilter-select { min-width: 130px; }
.vfilter-input { flex: 1; min-width: 120px; }
.vfilter-spacer { flex: 1; }
.vfilter-foot { display: flex; gap: var(--sp-2); }
.vfilter-remove:hover { color: var(--danger); }

/* Edit-view panel (column show/hide + reorder; grouping). Same surface + rhythm as
   the filter panel — one panel role, no lookalike. */
.veditview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  margin-bottom: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.veditview__section { display: flex; flex-direction: column; gap: var(--sp-2); }
.veditview__title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-dim);
  margin: 0;
}
.veditview__cols { display: flex; flex-direction: column; gap: var(--sp-1); }
.veditview__col { display: flex; align-items: center; gap: var(--sp-2); }
.veditview__coltype {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  flex: none;
  width: var(--icon);
  text-align: center;
}
.veditview__collabel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.veditview__move { display: flex; gap: var(--sp-1); flex: none; }
.veditview__grouprow { display: flex; align-items: center; gap: var(--sp-2); }

/* Active-filter chips. */
.vchips { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.vchip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 2px var(--sp-2);
}
.vchip__x { color: var(--text-faint); font-size: var(--fs-xs); }
.vchip__x:hover { color: var(--danger); }

/* Inline editing. */
.table--editable .table__cell--editable { cursor: pointer; }
.table--editable .table__cell--editable:hover { background: var(--surface-hover); }
.table--editable .table__cell--editable.is-editing { padding: var(--sp-1) var(--sp-2); }
.table--editable .table__cell--editable.is-saving { opacity: 0.6; }

.vcell-editor {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  padding: var(--sp-1) var(--sp-2);
}

/* Fixed-width actions column (matches ACTIONS_W in table.js). Tight horizontal
   padding so the draft Save+Cancel pair fits without widening the column. */
.table__actions-head,
.table__actions {
  text-align: center;
  white-space: nowrap;
  padding-left: var(--sp-2);
  padding-right: var(--sp-2);
}
.table__row-del { color: var(--text-faint); padding: var(--sp-1); opacity: 0; transition: opacity 0.12s, color 0.12s; }
.table__row-del:hover { color: var(--danger); }
/* Declutter: reveal the delete affordance on row hover / keyboard focus. */
.table--view tbody tr:hover .table__row-del,
.table__row-del:focus-visible { opacity: 1; }

.table__empty {
  text-align: center;
  padding: var(--sp-6) var(--sp-4) !important;
}
.table__empty-msg { color: var(--text-dim); margin: 0 0 var(--sp-2); }

/* ── Grouping (group header row per distinct value; collapsible) ── */
.table__grouprow td { background: var(--surface-hover); }
.table__group {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.table__group-toggle {
  color: var(--text-dim);
  padding: var(--sp-1);
  display: inline-flex;
  flex: none;
}
.table__group-label { font-weight: var(--fw-medium); color: var(--text); }
.table__group-count {
  color: var(--text-faint);
  font-size: var(--fs-sm);
}

/* ── Draft new-row (pinned top, ignores sort/filter until saved) ── */

/* Dim existing rows so focus is on the record being added. */
.table--view.is-drafting tbody tr.is-dim { opacity: 0.4; }
.table--view.is-drafting tbody tr.is-dim:hover { opacity: 0.55; }

.table__row--draft td {
  background: var(--surface-hover);
  border-bottom: 1px solid var(--border);
}
.table__row--draft td:first-child { box-shadow: inset 2px 0 0 var(--accent); }

/* Draft cells use persistent inline inputs (an inline add form). */
.table__row--draft .vcell-editor { border-color: var(--border); }
.table__row--draft .vcell-editor:focus { border-color: var(--accent); outline: none; }

.table__actions--draft { display: flex; gap: var(--sp-1); justify-content: center; }
.table__row-save { color: var(--success); padding: var(--sp-1); }
.table__row-save:hover { color: var(--success); background: var(--surface-hover); }
.table__row-cancel { color: var(--text-faint); padding: var(--sp-1); }
.table__row-cancel:hover { color: var(--danger); }

.view-meta--draft { color: var(--accent); }

/* ── Toasts (transient feedback, replaces alert) ── */
.view-toasts {
  position: fixed;
  bottom: var(--sp-5);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: var(--z-menu);
  pointer-events: none;
}
.view-toast {
  pointer-events: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-sm);
  opacity: 0;
  transform: translateY(var(--sp-1));
  transition: opacity 0.18s, transform 0.18s;
}
.view-toast.is-in { opacity: 1; transform: translateY(0); }
.view-toast--error { border-color: var(--danger); color: var(--text); }
