/* ─── Table area ─── */
.nc-table-wrap {
  flex: 1;
  overflow: auto;
}

.nc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.nc-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--gray-50);
  color: var(--gray-500);
  font-weight: 500;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .35px;
  padding: 0 12px;
  height: 32px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  text-align: left;
  user-select: none;
}
.nc-table th:last-child { border-right: none; }
.nc-table th.num { text-align: right; }

.nc-table td {
  padding: 0 12px;
  height: 32px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  color: var(--gray-700);
  font-size: 13px;
  vertical-align: middle;
}
.nc-table td:last-child { border-right: none; }
.nc-table td:first-child { color: var(--gray-900); font-weight: 500; }

.nc-table.col-frozen th:first-child,
.nc-table.col-frozen td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
  border-right: none;
}
.nc-table.col-frozen th:first-child::after,
.nc-table.col-frozen td:first-child::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 2px;
  background: var(--gray-500);
  pointer-events: none;
}
.nc-table.col-frozen th:first-child { background: var(--gray-50); z-index: 3; }
.nc-table.col-frozen tbody tr:hover td:first-child { background: var(--gray-50) !important; }
.nc-table.col-frozen tbody tr.row-total td:first-child,
.nc-table.col-frozen tfoot tr.row-total td:first-child { background: var(--total-bg) !important; }

#freeze-col-btn.active { background: var(--brand-pale); color: var(--brand); border-color: var(--brand); }
.nc-table td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--gray-700); }

.nc-table tbody tr:hover td { background: var(--gray-50) !important; }
.nc-table tbody tr.row-clickable,
.nc-table tbody td.row-clickable { cursor: pointer; }

.nc-table tbody tr.row-total td,
.nc-table tfoot tr.row-total td {
  background: var(--total-bg) !important;
  font-weight: 600;
  color: var(--gray-900);
}
.nc-table tbody tr.row-total:hover td,
.nc-table tfoot tr.row-total:hover td { background: var(--total-bg-hover) !important; }

/* inter-manager: row whose debit ≠ sum of credits (Check ≠ 0) */
.nc-table tbody tr.row-check-fail td { background: var(--danger-bg) !important; }
.nc-table.col-frozen tbody tr.row-check-fail td:first-child { background: var(--danger-bg) !important; }

/* Clickable money cells — every one opens a drilldown. Brand colour by default;
   the two below override it because the kind of money is what the colour says. */
.nc-table td.cell-unpaid,
.nc-table td.cell-total-unpaid,
.nc-table td.cell-payout,
.nc-table td.cell-collected,
.nc-table td.cell-billed {
  cursor: pointer;
  color: var(--brand);
  font-weight: 500;
  text-align: right;
  font-variant-numeric: tabular-nums;
  text-decoration: underline dotted;
}
.nc-table td.cell-unpaid:hover,
.nc-table td.cell-total-unpaid:hover,
.nc-table td.cell-payout:hover,
.nc-table td.cell-collected:hover,
.nc-table td.cell-billed:hover { text-decoration: underline; }

.nc-table td.cell-unpaid:hover,
.nc-table td.cell-total-unpaid:hover,
.nc-table td.cell-payout:hover { background: var(--brand-pale) !important; }

/* collected (cash received) — green */
.nc-table td.cell-collected { color: var(--money-in); }
.nc-table td.cell-collected:hover { background: var(--money-in-bg) !important; }

/* billed (invoiced) — blue */
.nc-table td.cell-billed { color: var(--money-billed); }
.nc-table td.cell-billed:hover { background: var(--money-billed-bg) !important; }

/* invoice url */
.nc-table td.cell-link a { color: var(--brand); text-decoration: underline dotted; font-size: 11px; }
.nc-table td.cell-link a:hover { text-decoration: underline; }

/* inline invoice link inside invoice_number cell */
.nc-table td.cell-inv-link a { color: inherit; text-decoration: underline dotted; }
.nc-table td.cell-inv-link a:hover { text-decoration: underline; }
.table-external-icon { font-size: 10px; }

/* Shared custom-cell utilities */
.nc-table td.table-cell-muted, .nc-table td .table-cell-muted { color: var(--gray-500); }
.nc-table td.table-cell-strong, .nc-table td .table-cell-strong { font-weight: 500; }
.nc-table td.table-cell-small { font-size: 12px; }
.nc-table td.table-cell-tiny { font-size: 11px; }
.nc-table td.table-cell-nowrap { white-space: nowrap; }
#invoice-email-audit-table td { vertical-align: top; white-space: normal; padding-top: 10px; padding-bottom: 10px; }
#invoice-email-audit-table td:first-child { white-space: nowrap; }
#invoice-email-audit-table summary { cursor: pointer; font-weight: 500; }
#invoice-email-audit-table .audit-history-item { margin-top: 10px; }
#invoice-email-audit-table .audit-history-item + .audit-history-item { border-top: 1px solid var(--border); padding-top: 10px; }
.table-group-entry {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin: 2px 4px 2px 0;
}
.nc-btn.table-action-mini {
  padding: 0 4px;
  height: 18px;
  min-width: 0;
  font-size: 10px;
  line-height: 1;
}

.nc-table td.table-empty {
  height: 64px;
  padding: 16px;
  color: var(--gray-400);
  text-align: center;
  font-weight: 400;
}
.nc-table td.table-error { color: #dc3545; }

/* sortable column headers */
.nc-table th[data-col] { padding-right: 28px; }
.sort-icon { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); border: 0; background: var(--gray-50); padding: 0; font-style: normal; color: var(--gray-400); font-size: 10px; cursor: pointer; }
.sort-icon::after { content: "↕"; }
th.sort-asc  .sort-icon { color: var(--gray-700); }
th.sort-asc  .sort-icon::after { content: "↑"; }
th.sort-desc .sort-icon { color: var(--gray-700); }
th.sort-desc .sort-icon::after { content: "↓"; }
.sort-icon:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.nc-table.resizable-table {
  table-layout: fixed;
}
.nc-table.resizable-table th,
.nc-table.resizable-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}
.nc-table.resizable-table th:has(.col-tip) { overflow: visible; }
.nc-table th .col-heading { display: flex; align-items: center; min-width: 0; }
.nc-table th .col-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
  z-index: 4;
}
.col-resizer:hover,
.col-resizer:focus-visible {
  background: var(--brand);
  outline: none;
}
body.resizing-column {
  cursor: col-resize;
  user-select: none;
}

/* row number col */
.nc-table th.col-num, .nc-table td.col-num {
  color: var(--gray-400);
  font-size: 11px;
  text-align: right;
  width: 44px;
  min-width: 44px;
  font-weight: 400;
}

/* ─── Column tooltip (used in table headers) ─── */
.col-tip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  margin-left: 4px;
  position: relative;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: help;
  vertical-align: middle;
}
.col-tip i {
  font-size: 10px;
  color: var(--gray-400);
  transition: color .12s;
}
.col-tip:hover i { color: var(--gray-600); }

.col-tip::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-900);
  color: #fff;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.45;
  padding: 6px 10px;
  border-radius: var(--radius);
  white-space: normal;
  width: max-content;
  max-width: 240px;
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.col-tip::before {
  content: "";
  position: absolute;
  top: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom-color: var(--gray-900);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  z-index: 200;
}
.col-tip:hover::after,
.col-tip:hover::before,
.col-tip:focus::after,
.col-tip:focus::before { opacity: 1; }
.col-tip:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ─── Trailing blank column — absorbs leftover width so data columns don't stretch ─── */
.nc-table th.col-spacer,
.nc-table td.col-spacer { border-right: none; width: 100%; padding: 0; }

/* ─── Touch: larger row tap targets ─── */
@media (pointer: coarse) {
  .nc-table th, .nc-table td { height: 40px; }
}

/* ─── Drilldown table overrides ─── */

/* Table wrapper — outer border + horizontal scroll */
.dd-tbl-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

/* Min-width ensures horizontal scroll rather than column collapse; last-column border closes the frame */
.dd-pane .nc-table,
.dd-page .nc-table {
  min-width: 1100px;
}
.dd-pane .nc-table th:last-child, .dd-page .nc-table th:last-child { border-right: 1px solid var(--border); }
.dd-pane .nc-table td:last-child, .dd-page .nc-table td:last-child { border-right: 1px solid var(--border); }

/* Sticky header needs top offset equal to the pane header height so it doesn't slide under it */
.dd-pane-body .nc-table th { top: 0; }

/* ─── Editable invoice email cells ─── */
.nc-table td.invoice-email {
  cursor: text;
  min-width: 180px;
  white-space: normal;
  overflow-wrap: anywhere;
}
.nc-table td.invoice-email:empty::before {
  content: "—";
  color: var(--gray-500);
}
.nc-table td.invoice-email:hover {
  background: var(--gray-50);
}
.nc-table td.invoice-email:focus {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
  background: var(--brand-bg);
}

/* Customers (Finance Team) — every column has a COL_WIDTHS entry, so fixed
   layout is safe and stops one long client name absorbing the whole table.
   max-width on a td is ignored under table-layout: auto, hence the override. */
#customers-table { table-layout: fixed; }
#customers-table th,
#customers-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Per-row Zoho refresh. The sync skips the billing-address fetch when it already
   holds one, so this is the escape hatch for a contact whose address changed. */
#customers-table td.cell-refresh { padding: 0; text-align: center; }
#customers-table .nc-btn-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  justify-content: center;
}
#customers-table .nc-btn-icon i { margin: 0; }
/* Brand-coloured where no address is stored — the rows worth clicking. */
#customers-table .nc-btn-icon.is-missing { color: var(--brand); }
#customers-table .nc-btn-icon i.spin { animation: spin .6s linear infinite; }
