/* ============================================================================
   Transactions — the Caçatais ledger.

   A register spread: the position (balance, escrow, lifetime in and out) and
   the filter rail sit in a sticky side column, the movements themselves run as
   a dense hairline-ruled table in the main column. Day headings carry the date
   so each row only carries its time.

   Colour is spent only where the system's semantics apply — violet for value
   held, green for solved and for money in, red for a penalty. Money out is
   body ink with a minus sign, not alarm red: spending Caçatais is what the
   platform is for, it is not an error.
   ========================================================================= */

.tx {
  padding-block: var(--sp-8) var(--sp-16);
}

.tx__head {
  margin-block-end: var(--sp-8);
}

.tx__title {
  font-size: var(--fs-3xl);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: var(--tr-display);
  color: var(--ink-050);
  margin: 0 0 var(--sp-2);
}

.tx__subtitle {
  color: var(--ink-300);
  max-width: 58ch;
  margin: 0;
}

.tx__layout {
  display: grid;
  gap: var(--sp-8);
}

/* ---------------------------------------------------------------------------
   The position — the system's ledger strip: cells separated by a 1px gap that
   shows the rule colour through, so the separators resolve on both axes and in
   both writing directions.
   ------------------------------------------------------------------------ */

.tx-position {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.tx-position__cell {
  background: var(--ink-900);
  padding: var(--sp-3) var(--sp-4);
  min-width: 0;
}

.tx-position__label {
  margin: 0 0 var(--sp-1);
}

.tx-position__value {
  font-size: var(--fs-lg);
  font-weight: 600;
  line-height: var(--lh-tight);
  letter-spacing: -0.01em;
  color: var(--ink-100);
  margin: 0;
}

.tx-position__value--accent {
  color: var(--accent);
}

.tx-position__value--locked {
  color: var(--locked);
}

.tx-position__value--in {
  color: var(--solved);
}

/* ---------------------------------------------------------------------------
   Filter rail — chips that wrap on narrow viewports, a list of rows in the
   side column. The current filter is drawn off aria-current with a raised
   fill, never the accent: the accent belongs to the balance.
   ------------------------------------------------------------------------ */

.tx-filters {
  margin-block-start: var(--sp-6);
}

.tx-filters__title {
  margin: 0 0 var(--sp-2);
}

.tx-filters__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  list-style: none;
  margin: 0;
  padding: 0;
}

.tx-filter {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 38px;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-300);
  text-decoration: none;
  transition: background-color var(--dur-1) var(--ease),
    color var(--dur-1) var(--ease);
}

.tx-filter:hover {
  background: var(--ink-800);
  color: var(--ink-050);
}

.tx-filter[aria-current="page"] {
  background: var(--ink-800);
  color: var(--ink-050);
}

.tx-filter__count {
  font-size: var(--fs-xs);
  color: var(--ink-300);
}

.tx-filter[aria-current="page"] .tx-filter__count {
  color: var(--ink-200);
}

/* ---------------------------------------------------------------------------
   The ledger
   ------------------------------------------------------------------------ */

/* The Isolation Rule, applied to figures. `.num` carries the mono face and
   tabular figures but not `direction`/`unicode-bidi` — only `.mono` and `.addr`
   do. Under dir="rtl" a leading "−" or "+" is a neutral character, so an
   un-isolated signed figure renders its sign on the trailing side and a debit
   reads as a credit. Every machine value on this surface is isolated. */
.tx-position__value,
.tx-filter__count,
.tx-amount,
.tx-row__balance .num,
.tx-row__time .num {
  direction: ltr;
  unicode-bidi: isolate;
}

.tx-ledger-wrap {
  background: var(--ink-850);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.tx-ledger {
  width: 100%;
  border-collapse: collapse;
}

.tx-ledger thead th {
  padding: var(--sp-3) var(--sp-4);
  background: var(--ink-900);
  border-block-end: 1px solid var(--line);
  text-align: start;
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--ink-400);
  white-space: nowrap;
}

/* The detail column absorbs the leftover width; every other column sizes to
   its own content. */
.tx-ledger thead th:nth-child(2) {
  width: 100%;
}

.tx-ledger__end {
  text-align: end;
}

.tx-day th {
  padding: var(--sp-2) var(--sp-4);
  background: var(--ink-900);
  border-block: 1px solid var(--line);
  text-align: start;
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--ink-300);
}

.tx-ledger tbody:first-of-type .tx-day th {
  border-block-start: 0;
}

.tx-row > * {
  padding: var(--sp-3) var(--sp-4);
  border-block-start: 1px solid var(--line);
  vertical-align: top;
}

/* The day heading already draws the rule above the first row of its group. */
.tx-day + .tx-row > * {
  border-block-start: 0;
}

.tx-row:hover > * {
  background: var(--ink-800);
}

.tx-row__type {
  white-space: nowrap;
}

.tx-row__icon {
  display: inline-flex;
  vertical-align: middle;
  margin-inline-end: var(--sp-2);
  color: var(--ink-400);
}

.tx-row__type .chip {
  vertical-align: middle;
}

.tx-row__detail {
  min-width: 22ch;
  font-size: var(--fs-sm);
}

.tx-row__desc {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--ink-100);
  unicode-bidi: isolate;
}

/* Secondary ink, not tertiary: these sit on the row's hover fill, where
   --ink-400 drops to 4.31:1. */
.tx-row__party {
  display: block;
  margin-block-start: var(--sp-1);
  font-size: var(--fs-xs);
  color: var(--ink-300);
}

.tx-row__party-link {
  color: var(--ink-200);
  font-weight: 500;
  text-decoration: none;
  unicode-bidi: isolate;
  transition: color var(--dur-1) var(--ease);
}

.tx-row__party-link:hover {
  color: var(--ink-050);
  text-decoration: underline;
}

.tx-row__amount {
  text-align: end;
  white-space: nowrap;
}

.tx-amount {
  font-size: var(--fs-base);
  font-weight: 600;
}

/* Money in is confirmed value arriving — the system's claimed green. Money out
   stays body ink; red is reserved for something that actually went wrong. */
.tx-amount--in {
  color: var(--solved);
}

.tx-amount--out {
  color: var(--ink-100);
}

/* The running balance is keyed by the column head on wide viewports and by an
   inline micro label once the table stops being a table. */
.tx-row__key {
  display: none;
}

.tx-row__balance,
.tx-row__time {
  text-align: end;
  white-space: nowrap;
  font-size: var(--fs-sm);
  color: var(--ink-300);
}

.tx-pagination {
  margin-block-start: var(--sp-8);
  display: flex;
  justify-content: center;
}

/* ---------------------------------------------------------------------------
   Below 768px the table stops being a table: each row becomes a small grid of
   movement / amount, detail, then time and running balance.
   ------------------------------------------------------------------------ */

@media (max-width: 767px) {
  .tx {
    padding-block: var(--sp-6) var(--sp-12);
  }

  .tx__head {
    margin-block-end: var(--sp-6);
  }

  .tx__title {
    font-size: var(--fs-2xl);
  }

  .tx-ledger,
  .tx-ledger tbody,
  .tx-ledger tr,
  .tx-ledger th,
  .tx-ledger td {
    display: block;
  }

  .tx-ledger thead {
    display: none;
  }

  /* Qualified by the table so it outranks the `.tx-ledger tr` reset above;
     without the extra specificity the row stays a block and the cells stack in
     source order. */
  .tx-ledger tr.tx-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "type   amount"
      "detail detail"
      "time   balance";
    gap: var(--sp-1) var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-block-start: 1px solid var(--line);
  }

  .tx-day + .tx-row {
    border-block-start: 0;
  }

  .tx-row > * {
    padding: 0;
    border-block-start: 0;
  }

  .tx-row__type {
    grid-area: type;
  }

  .tx-row__amount {
    grid-area: amount;
  }

  .tx-row__detail {
    grid-area: detail;
    min-width: 0;
  }

  .tx-row__time {
    grid-area: time;
    text-align: start;
  }

  .tx-row__balance {
    grid-area: balance;
  }

  .tx-row__key {
    display: inline;
    margin-inline-end: var(--sp-1);
    color: var(--ink-400);
  }
}

@media (min-width: 1024px) {
  .tx__layout {
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-areas: "main side";
    column-gap: var(--sp-10);
  }

  .tx__main {
    grid-area: main;
    min-width: 0;
  }

  .tx__side {
    grid-area: side;
    position: sticky;
    top: calc(var(--h-header) + var(--sp-6));
    align-self: start;
  }

  /* In a 320px column the strip's cells are too narrow to hold a seven-figure
     balance at value scale, so the position turns into stacked label/value
     rows — which is also how a statement summary reads. */
  .tx-position {
    grid-template-columns: 1fr;
  }

  .tx-position__cell {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-4);
  }

  .tx-position__label {
    margin-block-end: 0;
  }

  .tx-filters__list {
    flex-direction: column;
    gap: 0;
  }

  .tx-filter {
    justify-content: space-between;
    min-height: 36px;
  }
}
