/*!
 * ZIC tables — the list-table standard
 * ============================================================================
 * Implements docs/TABLE_STANDARD.md. Loaded globally; applies to any element
 * carrying `.zic-table`, so a table opts in rather than being restyled by
 * default.
 *
 * The single-row rule (§2 of the standard) is the reason most of this exists:
 * a cell that wraps changes the row height per record, which destroys column
 * scanning. Every helper here is about keeping one line.
 */

/* ===========================================================================
 * 1. The table shell.
 * ======================================================================== */
.zic-table {
  /* Long content truncates instead of widening the table. */
  table-layout: auto;
  margin-block-end: 0;
}

/* The scroll container for narrow viewports (§4). */
.zic-table-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

/* ===========================================================================
 * 2. Single-row cells (§2).
 * ======================================================================== */
.zic-cell-truncate {
  max-inline-size: var(--zic-cell-truncate, 220px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A secondary value inline after the primary one — the identity pattern:
   "Legal Name · PTR-0001". Never a second line. */
.zic-cell-muted {
  font-weight: var(--zic-font-weight-regular);
  color: var(--zic-text-secondary);
}

.zic-cell-sub {
  color: var(--zic-text-secondary);
}

/* Money: amount and its currency code in one cell, digits aligned so the
   column reads as a column. */
.zic-cell-money {
  text-align: end;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Date cells. A date must never wrap: `table-layout: auto` will happily squeeze
   a date column to 87px between a nowrap money column and a nowrap actions
   column, at which point "12 Sep 2026" breaks into three lines and the row
   doubles in height. Verified on the quotations list before this rule existed. */
.zic-cell-date {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Counts inside a result cell ("12 ok / 3 err"). */
.zic-cell-count-ok {
  color: var(--zic-status-success-text);
  font-variant-numeric: tabular-nums;
}

.zic-cell-count-error {
  color: var(--zic-status-danger-text);
  font-variant-numeric: tabular-nums;
}

.zic-cell-sep {
  color: var(--zic-text-disabled);
}

/* Chips that must stay on one line. */
.zic-cell-chips {
  display: flex;
  align-items: center;
  gap: var(--zic-space-1);
  white-space: nowrap;
}

/* The inline status tick — a second state inside a cell that already holds one
   badge. Never a second badge. */
.zic-cell-tick {
  margin-inline-start: var(--zic-space-1);
  vertical-align: -0.1em;
}

/* The onboarding-source marker — a small text pill (not a `.badge`, so the
   status cell's "one badge per cell" contract still holds) beside the status.
   Its full reference lives in the element's title. */
.zic-source-badge {
  margin-inline-start: var(--zic-space-1);
  padding-block: 0.05em;
  padding-inline: 0.5em;
  border: 1px solid var(--zic-border-default);
  border-radius: var(--zic-radius-pill, 999px);
  color: var(--zic-text-secondary);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  vertical-align: 0.05em;
}

.zic-source-badge[data-source="BULK"] {
  border-color: var(--zic-status-info, var(--zic-border-default));
  color: var(--zic-status-info, var(--zic-text-secondary));
}

/* An inline warning beside a date. The detail lives in the icon's title. */
.zic-cell-warning {
  margin-inline-start: var(--zic-space-1);
  color: var(--zic-status-danger);
  vertical-align: -0.1em;
}

/* ===========================================================================
 * 3. Column priority (§4).
 *
 * Hidden rather than `display: none`-ed by a class on every cell: the priority
 * lives on the <th>, and these rules reach the matching <td> by position, so a
 * template declares it once per column instead of twice per row.
 * ======================================================================== */
@media (max-width: 1199.98px) {
  .zic-table th[data-col-p='3'],
  .zic-table td[data-col-p='3'] {
    display: none;
  }
}

@media (max-width: 991.98px) {
  .zic-table th[data-col-p='2'],
  .zic-table td[data-col-p='2'] {
    display: none;
  }
}

/* Below 768px the table scrolls and the identity column sticks. */
@media (max-width: 767.98px) {
  .zic-table th[data-col-p='1']:first-child,
  .zic-table td[data-col-p='1']:first-child {
    position: sticky;
    inset-inline-start: 0;
    z-index: 1;
    background-color: var(--zic-surface-primary);
  }

  /* The sticky cell has to outrank the row-hover background, or the identity
     column turns transparent as the pointer crosses the row. */
  .zic-table tbody tr:hover td[data-col-p='1']:first-child {
    background-color: var(--zic-surface-primary);
  }
}

/* ===========================================================================
 * 4. Row actions.
 *
 * Icon-only buttons in a trailing cell, plus an overflow menu when a row has
 * more actions than fit (§6 of the Prompt 2 spec: max 4 visible).
 * ======================================================================== */
.zic-table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--zic-space-1);
  white-space: nowrap;
}

/* The overflow toggle is the same size and weight as the icon buttons beside
   it, so the cluster reads as one control group. */
.zic-table-actions .dropdown-toggle::after {
  display: none;
}

.zic-table-actions .dropdown-menu {
  min-inline-size: 200px;
}
