/* ============================================================
   FLOW Mega Apps — Shared Data Table
   Companion stylesheet to js/components/data-table.js.

   THE RULE: the table fits the viewport. There is no horizontal
   scrolling on a .dt table — width is won back through density,
   hidden columns, and the row expander, never by pushing content
   off-screen. `table-layout:fixed` shares the width out rather
   than letting one long client name drag the table 400px wide.
   ============================================================ */

.dt {
  --dt-row-pad-y: 7px;
  --dt-font: 12px;
  --dt-head-font: 10.5px;
  --dt-sticky-left: 0px;
  position: relative;
}

/* ---- toolbar ---------------------------------------------- */
.dt-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}
.dt-toolbar-left { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.dt-toolbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}
.dt-count {
  font-size: 11px;
  color: var(--muted, #8c8497);
  white-space: nowrap;
}

/* Segmented density control */
.dt-seg {
  display: inline-flex;
  border: 1px solid var(--border, #e5e2ea);
  border-radius: var(--radius-sm, 6px);
  overflow: hidden;
  background: var(--card, #fff);
}
.dt-seg-btn {
  border: 0;
  background: transparent;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary, #5a5267);
  cursor: pointer;
  line-height: 1.6;
}
.dt-seg-btn + .dt-seg-btn { border-left: 1px solid var(--border, #e5e2ea); }
.dt-seg-btn:hover { background: var(--border-light, #efedf2); }
.dt-seg-btn.is-on {
  background: var(--primary, #6337D8);
  color: #fff;
}

.dt-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  border: 1px solid var(--border, #e5e2ea);
  border-radius: var(--radius-sm, 6px);
  background: var(--card, #fff);
  color: var(--text-secondary, #5a5267);
  cursor: pointer;
}
.dt-icon-btn:hover { background: var(--border-light, #efedf2); color: var(--text, #13061C); }

/* ---- column manager --------------------------------------- */
.dt-colmenu-wrap { position: relative; }
.dt-colmenu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  width: 236px;
  max-height: 340px;
  overflow-y: auto;
  padding: 10px;
  background: var(--card, #fff);
  border: 1px solid var(--border, #e5e2ea);
  border-radius: var(--radius, 10px);
  box-shadow: var(--card-shadow-hover, 0 4px 12px rgba(19, 6, 28, .1));
}
.dt-colmenu[hidden] { display: none; }
.dt-colmenu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 2px;
}
.dt-colmenu-hint {
  margin: 0 0 8px;
  font-size: 10.5px;
  color: var(--muted, #8c8497);
}
.dt-link {
  border: 0;
  background: none;
  padding: 0;
  font-size: 11px;
  color: var(--primary, #6337D8);
  cursor: pointer;
  text-decoration: underline;
}
.dt-collist { list-style: none; margin: 0; padding: 0; }
.dt-colitem {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  border-radius: var(--radius-sm, 6px);
  cursor: grab;
  font-size: 12px;
}
.dt-colitem:hover { background: var(--border-light, #efedf2); }
.dt-colitem.is-dragging { opacity: .45; }
.dt-colgrip { color: var(--muted, #8c8497); display: inline-flex; flex: 0 0 auto; }
.dt-collabel {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
  cursor: pointer;
}
.dt-collabel span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- scroll container + table ------------------------------ */
/* overflow-x:hidden is the whole point: a .dt table must never be
   solved with sideways scrolling. Vertical scroll is fine and is
   what makes the sticky header worth having. */
/* Scroll is now ALLOWED — truncation is not. A table whose measured natural
   widths exceed the container scrolls at full width rather than squeezing. */
.dt-viewport { position: relative; }

.dt-scroll {
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--border-light, #efedf2);
  border-radius: var(--radius-sm, 6px);
  scrollbar-gutter: auto;
  scrollbar-width: auto;
  scrollbar-color: var(--muted, #8c8497) var(--border-light, #efedf2);
}
.dt-scroll:focus-visible { outline: 2px solid var(--primary, #6337D8); outline-offset: 1px; }

/* Always visible — Windows/Chrome hides overlay scrollbars until hover,
   which is exactly when the user does not yet know the table scrolls. */
.dt-scroll::-webkit-scrollbar,
.dt-scrollbar-top::-webkit-scrollbar { height: 12px; width: 12px; }
.dt-scroll::-webkit-scrollbar-track,
.dt-scrollbar-top::-webkit-scrollbar-track { background: var(--border-light, #efedf2); border-radius: 6px; }
.dt-scroll::-webkit-scrollbar-thumb,
.dt-scrollbar-top::-webkit-scrollbar-thumb {
  background: var(--muted, #8c8497); border-radius: 6px;
  border: 2px solid var(--border-light, #efedf2);
}

/* Mirror scrollbar above the header, synced in JS. Hidden unless needed. */
.dt-scrollbar-top {
  display: none;
  overflow-x: auto;
  overflow-y: hidden;
  height: 12px;
  margin-bottom: 4px;
}
.dt-scrollbar-top.is-on { display: block; }
.dt-scrollbar-top > div { height: 1px; }

/* Edge shadows — only while there IS more content that way. */
.dt-edge {
  position: absolute; top: 0; bottom: 0; width: 20px;
  pointer-events: none; opacity: 0; transition: opacity .15s ease; z-index: 4;
}
.dt-edge.is-on { opacity: 1; }
.dt-edge--left  { left: 0;  background: linear-gradient(to right, rgba(19,6,28,.15), transparent); }
.dt-edge--right { right: 0; background: linear-gradient(to left,  rgba(19,6,28,.15), transparent); }

.dt-table {
  table-layout: fixed;
  width: 100%;
  border-collapse: separate;   /* separate, not collapse: collapsed
                                  borders detach from sticky cells and
                                  the header ends up with no bottom rule
                                  while scrolling. */
  border-spacing: 0;
  font-size: var(--dt-font);
}

/* ---- header ------------------------------------------------ */
.dt-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--card, #fff);
  padding: 6px 8px;
  font-size: var(--dt-head-font);
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--text-secondary, #5a5267);
  border-bottom: 1px solid var(--border, #e5e2ea);
  text-align: left;
  vertical-align: middle;
}
/* Headers stay on ONE line. The old behaviour wrapped them and
   produced stacks like "COMPA / NY NAME"; the component ships a
   short label instead and hands the full one to the tooltip. */
.dt-th-inner {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
}
.dt-th-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dt-sortable { cursor: pointer; user-select: none; }
.dt-sortable:hover { color: var(--text, #13061C); background: var(--border-light, #efedf2); }
.dt-th.is-sorted { color: var(--primary, #6337D8); }
.dt-sort-arrow { font-size: 8px; flex: 0 0 auto; }

/* ---- resize handle ----------------------------------------- */
/* Sits fully INSIDE the cell. An earlier version used right:-3px to
   straddle the border, which pushed the last column 3px past the
   container and reintroduced the horizontal scrollbar this whole
   component exists to avoid. */
.dt-resize {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
}
.dt-resize:hover { background: var(--primary-light, #8976FF); opacity: .5; }
/* The handle is absolutely positioned against the th, which is already
   a containing block by virtue of position:sticky. */
body.dt-resizing { cursor: col-resize; user-select: none; }

/* ---- body cells -------------------------------------------- */
.dt-table tbody td {
  padding: var(--dt-row-pad-y) 8px;
  border-bottom: 1px solid var(--border-light, #efedf2);
  overflow: hidden;
  vertical-align: middle;
}
/* NO ELLIPSIS ANYWHERE (2026-08-03 governing rule). Columns are measured to
   their widest real value, so a nowrap cell always has room. The only cells
   that are ever visually shortened are .dt-cell--wrap, which wrap to three
   lines and then offer a "more" button into the row expander — a cut-off
   word is never left for the user to guess at. */
.dt-cell {
  white-space: nowrap;
  min-width: 0;
}
.dt-cell--wrap {
  white-space: normal;
  overflow-wrap: anywhere;
  overflow: hidden;
  /* Three lines, clipped cleanly. Deliberately NOT -webkit-line-clamp, which
     appends an ellipsis. */
  max-height: calc(3 * 1.35em);
  line-height: 1.35;
}
.dt-more {
  display: inline-block;
  margin-top: 2px;
  padding: 0 5px;
  border: 1px solid var(--border, #e5e2ea);
  border-radius: 999px;
  background: var(--card, #fff);
  color: var(--primary, #6337D8);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.5;
  cursor: pointer;
}
.dt-more:hover { background: var(--border-light, #efedf2); }
.dt-row:hover > td { background: var(--border-light, #efedf2); }
.dt-row.is-open > td { background: color-mix(in srgb, var(--primary, #6337D8) 7%, transparent); }

/* Opt-in cell classes, passed by a column's `cellClass`. */
.dt-mono { font-family: ui-monospace, Menlo, Consolas, monospace; }

.dt-al-left   { text-align: left; }
.dt-al-center { text-align: center; }
.dt-al-right  { text-align: right; font-variant-numeric: tabular-nums; }

/* Inputs and selects that modules render inside cells must not blow
   the row height out or overflow their column. */
.dt-table tbody td input,
.dt-table tbody td select,
.dt-table tbody td textarea {
  max-width: 100%;
  font-size: inherit;
}

/* ---- lead columns (expander / checkbox) -------------------- */
.dt-lead { text-align: center; padding-left: 4px !important; padding-right: 4px !important; }
.dt-exp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--muted, #8c8497);
  cursor: pointer;
  transition: transform .12s ease;
}
.dt-exp-btn:hover { background: var(--border, #e5e2ea); color: var(--text, #13061C); }
.dt-exp-btn.is-open { transform: rotate(90deg); color: var(--primary, #6337D8); }

/* ---- sticky first column ----------------------------------- */
/* Keeps the row identifiable while the eye travels right. The left
   offset is measured in JS (the lead columns' real widths) and set
   as --dt-sticky-left. */
.dt-table .dt-sticky-col {
  position: sticky;
  left: var(--dt-sticky-left);
  z-index: 1;
  background: var(--card, #fff);
}
.dt-table thead .dt-sticky-col { z-index: 3; }
.dt-row:hover > td.dt-sticky-col { background: var(--border-light, #efedf2); }
.dt-lead {
  position: sticky;
  z-index: 1;
  background: var(--card, #fff);
}
.dt-lead-exp { left: 0; }
/* The checkbox sits after the 30px expander — unless the table has no
   expander, in which case it is the first cell and belongs at 0. */
.dt-lead-check { left: 0; }
.dt-lead-exp + .dt-lead-check { left: 30px; }
.dt-table thead .dt-lead { z-index: 3; }
.dt-row:hover > td.dt-lead { background: var(--border-light, #efedf2); }

/* ---- sticky right column (Actions) ------------------------- */
.dt-table .dt-sticky-right {
  position: sticky;
  right: 0;
  z-index: 2;
  background: var(--card, #fff);
  box-shadow: -6px 0 8px -8px rgba(19, 6, 28, .35);
}
.dt-table thead .dt-sticky-right { z-index: 4; }
.dt-row:hover > td.dt-sticky-right { background: var(--border-light, #efedf2); }

/* ---- fullscreen -------------------------------------------- */
/* Whole viewport, no sidebar, no card chrome. The layout is re-measured on
   entry, so a table that scrolled inside a card often fits outright here. */
body.dt-fullscreen-open { overflow: hidden; }
.dt.dt--fullscreen {
  position: fixed;
  inset: 0;
  z-index: 900;
  margin: 0;
  padding: 12px 14px 14px;
  background: var(--card, #fff);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.dt.dt--fullscreen .dt-toolbar {
  position: sticky;   /* filters, search, density, columns, export stay put */
  top: 0;
  z-index: 5;
  background: var(--card, #fff);
  padding-bottom: 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border-light, #efedf2);
}
.dt.dt--fullscreen .dt-viewport { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.dt.dt--fullscreen .dt-scroll { flex: 1 1 auto; max-height: none !important; }

/* ---- density ----------------------------------------------- */
.dt--compact     { --dt-row-pad-y: 3px;  --dt-font: 11.5px; }
.dt--comfortable { --dt-row-pad-y: 7px;  --dt-font: 12px; }
.dt--expanded    { --dt-row-pad-y: 10px; --dt-font: 12.5px; }

/* Expanded is the only density that lets a cell wrap — and only to
   TWO lines. Unbounded wrapping was the old bug: one long Daily
   Issue description turned a row into a 160px block. The clamp is on
   .dt-cell, so the td keeps its table-cell display and the row height
   stays uniform. */
/* Expanded lets wrapping columns use more vertical room. Still no
   -webkit-line-clamp: it appends an ellipsis, which the governing rule
   forbids. A clean max-height clip plus the "more" button instead. */
.dt--expanded .dt-cell--wrap { max-height: calc(5 * 1.35em); }
.dt--compact .dt-cell--wrap { max-height: calc(2 * 1.35em); }
/* A cell holding controls keeps one line — clamping a box that
   contains an <input> or <select> mangles their layout. */
.dt--expanded .dt-cell:has(input),
.dt--expanded .dt-cell:has(select),
.dt--expanded .dt-cell:has(button),
.dt--expanded .dt-cell:has(textarea) {
  display: block;
  white-space: nowrap;
}

/* ---- expander detail panel --------------------------------- */
/* The primary readability fix: every field, including the columns
   hidden from the grid, laid out full width below the row. */
.dt-detail-row > td {
  padding: 0 !important;
  white-space: normal !important;
  background: color-mix(in srgb, var(--primary, #6337D8) 4%, transparent);
  border-bottom: 2px solid var(--border, #e5e2ea);
}
.dt-detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 8px 22px;
  padding: 12px 14px 14px calc(var(--dt-sticky-left) + 10px);
}
.dt-detail-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.dt-detail-item--wide { grid-column: 1 / -1; }
.dt-detail-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--muted, #8c8497);
}
.dt-detail-value {
  font-size: 12.5px;
  color: var(--text, #13061C);
  overflow-wrap: anywhere;   /* a long URL or note wraps here rather
                                than widening the panel */
  white-space: pre-wrap;
}

/* ---- empty state ------------------------------------------- */
.dt-empty-row > td { padding: 0 !important; }
.dt-empty {
  padding: 26px 14px;
  text-align: center;
  font-size: 12px;
  color: var(--muted, #8c8497);
}

/* ---- tooltip ----------------------------------------------- */
/* Drawn by the component rather than relying on `title`, which
   takes ~1s to appear and cannot be styled. `title` is still set,
   so the value survives if this element is ever missing. */
.dt-tip {
  position: fixed;
  z-index: 9999;
  max-width: 380px;
  padding: 6px 9px;
  border-radius: var(--radius-sm, 6px);
  background: var(--text, #13061C);
  color: #fff;
  font-size: 11.5px;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 14px rgba(19, 6, 28, .22);
}
.dt-tip.is-on { opacity: 1; visibility: visible; }

/* ---- screen-reader only ------------------------------------ */
.dt-sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- narrow screens ---------------------------------------- */
/* Below ~900px the sticky first column costs more width than it
   returns, and the detail panel becomes the main way to read a row. */
@media (max-width: 900px) {
  .dt-table .dt-sticky-col { position: static; }
  .dt-detail { padding-left: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .dt-toolbar-right { margin-left: 0; }
}
