/* ============================================================
   tables.css — the data-table system, plus the Tally-style
   report blocks (which intentionally imitate Tally's own printed
   report look and are kept close to the original).
   ============================================================ */

/* ---------------- base table ---------------- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
  background: var(--color-surface);
}

th, td {
  text-align: left;
  padding: var(--row-pad-y) var(--row-pad-x);
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-surface-2);
  color: var(--text-secondary);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-border-strong);
  vertical-align: middle;
}
th.right, td.right { text-align: right; }

tbody tr { transition: background var(--dur-fast) var(--ease); }
tbody tr:hover td { background: var(--color-surface-2); }
tbody tr:last-child td { border-bottom: none; }

tr[onclick] { cursor: pointer; }
tr[onclick]:hover td { background: var(--color-primary-soft); }

tbody tr.selected td { background: var(--color-primary-soft); }

/* numeric columns line up */
td.num, td.amt, td.amt2, .right { font-variant-numeric: tabular-nums; }

/* ---------------- scroll container ----------------
   Wide accounting tables scroll inside their own box so the page
   body never scrolls sideways. The existing markup already wraps
   tables in <div style="overflow-x:auto">; .table-wrap is the
   named version for migrated pages. */
.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 70vh;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}
.table-wrap table { font-size: var(--text-sm); }

/* tables that sit directly inside a .section get the section's frame */
.section > table,
.section > div[style*="overflow-x"] > table { border-radius: 0; }
.section > div[style*="overflow-x"] {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

/* ---------------- density ---------------- */
.density-comfortable { --row-pad-y: 12px; --row-pad-x: 14px; }
.density-compact     { --row-pad-y: 8px;  --row-pad-x: 12px; }
.density-dense       { --row-pad-y: 4px;  --row-pad-x: 10px; }
.density-dense table { font-size: var(--text-xs); }

/* ---------------- sortable headers ---------------- */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text-primary); background: var(--color-surface-3); }
th.sortable::after { content: '↕'; opacity: .3; margin-left: var(--space-xs); font-size: 10px; }
th.sort-asc::after  { content: '↑'; opacity: 1; color: var(--color-primary); }
th.sort-desc::after { content: '↓'; opacity: 1; color: var(--color-primary); }

/* ---------------- pagination ---------------- */
.pagination {
  display: flex; align-items: center; gap: var(--space-sm);
  padding: var(--space-md) 0 0;
  flex-wrap: wrap;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.pagination .spacer { margin-left: auto; }
.pagination button {
  min-width: var(--control-h-sm); height: var(--control-h-sm);
  padding: 0 var(--space-sm);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--text-primary);
  font-size: var(--text-sm);
}
.pagination button:hover:not(:disabled) { background: var(--color-surface-2); }
.pagination button.active {
  background: var(--color-primary); color: var(--text-inverse);
  border-color: var(--color-primary); font-weight: var(--weight-semibold);
}
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------------- voucher blocks (day-book style) ---------------- */
tr.vhead td { font-weight: var(--weight-semibold); }
tbody.vblk  { border-bottom: 1px solid var(--color-border); }
tbody.lvblk { border-bottom: 1px solid var(--color-border); }

/* ============================================================
   TALLY-STYLE REPORTS
   These deliberately mirror TallyPrime's own on-screen report
   appearance so accountants recognise them. Kept close to the
   original, harmonised with the new border radii and type.
   ============================================================ */
.tally {
  background: var(--tally-paper);
  color: var(--tally-ink);
  border: 1px solid var(--tally-line);
  border-radius: var(--radius-md);
  overflow: hidden;
  font-size: var(--text-sm);
  box-shadow: var(--shadow-sm);
}
.tally .thead {
  background: var(--tally-head);
  color: var(--tally-head-text);
  font-weight: var(--weight-bold);
  padding: var(--space-sm) var(--space-md);
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--space-md);
}
.tally .sub {
  background: var(--tally-sub);
  color: var(--tally-ink);
  padding: var(--space-xs) var(--space-md);
  display: flex; justify-content: space-between;
  border-bottom: 1px solid var(--tally-line);
}
.tally .cols { display: flex; }
.tally .side { flex: 1; min-width: 0; }
.tally .side.left { border-right: 2px solid var(--tally-line); }
.tally-meta {
  text-align: center; padding: var(--space-xs);
  color: var(--tally-ink-faint); font-size: var(--text-xs);
  border-bottom: 1px solid var(--tally-line);
}

.trow {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: var(--space-sm);
  padding: 2px var(--space-md);
  align-items: baseline;
}
.trow .amt, .trow .amt2 {
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 120px;
}
.tgrp   { font-weight: var(--weight-bold); background: var(--tally-grp); }
.tled   { padding-left: 26px; color: var(--tally-ink-soft); }
.tled .name { color: var(--tally-ink); }
.tsum   {
  border-top: 1px solid var(--tally-ink);
  border-bottom: 1px solid var(--tally-ink);
  font-weight: var(--weight-bold);
  background: var(--tally-band);
}
.tprofit { font-weight: var(--weight-bold); }
.tally .grand { border-top: 2px solid var(--tally-ink); font-weight: 800; }

/* ============================================================
   DATA TABLE COMPONENT (Phase 5)
   ============================================================ */
.dt { display: flex; flex-direction: column; gap: var(--space-md); }

.dt-bar {
  display: flex; align-items: flex-end; gap: var(--space-md);
  flex-wrap: wrap;
}
.dt-bar .field { margin-bottom: 0; flex: 0 1 172px; }
.dt-bar-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-sm); }

.dt-search {
  position: relative; display: flex; align-items: center;
  flex: 1 1 260px; min-width: 0;
}
.dt-search .i {
  position: absolute; left: var(--space-md);
  color: var(--text-tertiary); pointer-events: none;
}
.dt-search input {
  width: 100%; height: var(--control-h-md);
  padding: 0 var(--space-md) 0 36px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
}
.dt-search input::placeholder { color: var(--text-tertiary); }
.dt-search input:focus {
  outline: none; border-color: var(--color-primary); box-shadow: var(--focus-ring);
}
.dt-search input::-webkit-search-cancel-button { cursor: pointer; }

/* density switch */
.dt-density { display: inline-flex; border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); overflow: hidden; }
.dt-density button {
  width: 30px; height: var(--control-h-md);
  background: var(--color-surface); border: none;
  color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center;
  border-right: 1px solid var(--color-border);
}
.dt-density button .i { width: 14px; height: 14px; }
.dt-density button:last-child { border-right: none; }
.dt-density button:hover { background: var(--color-surface-2); color: var(--text-primary); }
.dt-density button.on { background: var(--color-primary-soft); color: var(--color-primary); }

/* pager */
.pagination .dt-count { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.pagination .dt-count b { color: var(--text-primary); }
.pagination .ell { color: var(--text-tertiary); padding: 0 2px; }

/* skeleton rows inside the table keep column widths stable */
.dt tbody .skeleton-line { height: 10px; }

@media (max-width: 640px) {
  .dt-bar-right { margin-left: 0; width: 100%; }
  .dt-bar .field { flex: 1 1 140px; }
  .pagination { justify-content: center; }
  .pagination .spacer { margin-left: 0; width: 100%; height: 0; }
}

/* inline editable cell (bank account numbers) */
.dt-inline {
  height: var(--control-h-sm); width: 200px; max-width: 100%;
  padding: 0 var(--space-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono); font-size: var(--text-xs);
}
.dt-inline:focus { outline: none; border-color: var(--color-primary); box-shadow: var(--focus-ring); }
td .mono, .mono { font-family: var(--font-mono); font-size: var(--text-xs); }

/* Legacy tables wrapped automatically by the shell: same frame as
   .table-wrap, but no forced max-height so a short table does not
   gain a pointless scrollbar. */
.table-wrap.auto-wrap { max-height: none; }
.section > .table-wrap.auto-wrap { margin-top: var(--space-sm); }
