/*
 * Isolated presentation layer for the finance and cash-desk ledgers.
 * The shared finance DOM remains the source of truth: no columns or actions
 * are hidden here, and wide ledgers stay horizontally accessible.
 */

.finance-page {
  --finance-ink: #172448;
  --finance-muted: #66728c;
  --finance-line: #dde4ef;
  --finance-line-soft: #e9edf4;
  --finance-surface: #fff;
  --finance-soft: #f7f9fc;
  --finance-accent: #112262;
  --finance-highlight: #ffcc05;
  gap: 16px;
  color: var(--finance-ink);
}

.finance-page *,
.finance-page *::before,
.finance-page *::after {
  box-sizing: border-box;
}

.finance-page > * { min-width: 0; }

.finance-page .finance-heading {
  min-height: 56px;
  padding: 0 2px;
  align-items: center;
}

.finance-page .finance-heading > div:first-child {
  min-width: 0;
}

.finance-page .finance-heading .eyebrow {
  margin: 0 0 4px;
  color: #71809d;
  font-size: .65rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.finance-page .finance-heading h1 {
  color: var(--finance-ink);
  font-size: clamp(1.16rem, 1.7vw, 1.42rem);
  font-weight: 780;
  letter-spacing: -.025em;
  line-height: 1.2;
}

.finance-page .finance-heading__actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.finance-page .finance-heading__actions > button {
  border-radius: 9px;
  box-shadow: 0 4px 12px rgb(17 34 98 / 8%);
}

.finance-page .finance-filters {
  padding: 15px;
  border: 1px solid var(--finance-line);
  border-radius: 13px;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 11px;
  background: var(--finance-surface);
  box-shadow: 0 7px 22px rgb(17 34 98 / 5%);
}

.finance-page .finance-filter {
  gap: 6px;
}

.finance-page .finance-filter > span {
  color: #53617d;
  font-size: .67rem;
  font-weight: 760;
  letter-spacing: .012em;
}

.finance-page .finance-filter input,
.finance-page .finance-filter select,
.finance-page .finance-filter textarea {
  height: 40px;
  border-color: #c8d1e0;
  border-radius: 8px;
  background: #fbfcfe;
  color: #243254;
  font-size: .75rem;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.finance-page .finance-filter input:hover,
.finance-page .finance-filter select:hover,
.finance-page .finance-filter textarea:hover {
  border-color: #94a1ba;
  background: #fff;
}

.finance-page .finance-filter input:focus,
.finance-page .finance-filter select:focus,
.finance-page .finance-filter textarea:focus {
  border-color: var(--finance-accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgb(17 34 98 / 10%);
}

.finance-page .finance-filters > .primary-button {
  min-width: 120px;
  min-height: 40px;
  border-radius: 8px;
}

.finance-page .finance-feedback {
  min-height: 0;
  margin: -5px 2px 0;
}

.finance-page .finance-feedback:not(:empty) {
  min-height: 34px;
  padding: 9px 11px;
  border: 1px solid #d8e6df;
  border-radius: 8px;
  background: #f3faf6;
  color: #246746;
}

.finance-page .finance-feedback--error:not(:empty) {
  border-color: #efcecc;
  background: #fff5f4;
  color: #a83230;
}

.finance-page .finance-results {
  overflow: hidden;
  border: 1px solid var(--finance-line);
  border-radius: 13px;
  background: var(--finance-surface);
  box-shadow: 0 9px 28px rgb(17 34 98 / 6%);
}

.finance-page .finance-table-region {
  position: relative;
  max-height: min(68vh, 720px);
  overflow: auto;
  outline: 0;
  scrollbar-gutter: stable;
}

.finance-page .finance-table-region:focus-visible {
  box-shadow: inset 0 0 0 2px rgb(17 34 98 / 15%);
}

.finance-page .finance-table {
  min-width: 880px;
  color: #293653;
  font-size: .72rem;
}

.finance-page .finance-table th,
.finance-page .finance-table td {
  height: 43px;
  padding: 9px 12px;
  border-bottom-color: var(--finance-line-soft);
}

.finance-page .finance-table thead th {
  position: sticky;
  z-index: 4;
  top: 0;
  background: #f4f6fa;
  box-shadow: inset 0 -1px 0 #dce2ed;
  color: #4c5974;
  font-size: .64rem;
  font-weight: 780;
  letter-spacing: .025em;
  text-transform: uppercase;
}

.finance-page .finance-table thead th:first-child,
.finance-page .finance-table tbody td:first-child,
.finance-page .finance-table tfoot th:first-child {
  position: sticky;
  left: 0;
  min-width: 72px;
  box-shadow: 1px 0 0 #e1e6ef, 7px 0 14px rgb(17 34 98 / 3%);
}

.finance-page .finance-table thead th:first-child {
  z-index: 6;
  background: #eef2f8;
}

.finance-page .finance-table tbody td:first-child {
  z-index: 2;
  background: #fff;
}

.finance-page .finance-table tbody tr:nth-child(even) td {
  background: #fbfcfe;
}

.finance-page .finance-table tbody tr:nth-child(even) td:first-child {
  background: #f8fafe;
}

.finance-page .finance-table tbody tr:not(.finance-table__empty):hover td,
.finance-page .finance-table tbody tr:not(.finance-table__empty):focus td {
  background: #fffbea;
}

.finance-page .finance-table tbody tr:not(.finance-table__empty):focus-visible {
  outline: 2px solid rgb(17 34 98 / 20%);
  outline-offset: -2px;
}

.finance-page .finance-table tfoot th {
  position: sticky;
  z-index: 3;
  bottom: 0;
  border-top: 1px solid #cfd7e6;
  background: #edf2fa;
  box-shadow: 0 -5px 14px rgb(17 34 98 / 4%);
  color: #182b61;
  font-weight: 790;
}

.finance-page .finance-table tfoot th:first-child {
  z-index: 5;
  background: #e9eef7;
}

.finance-page .finance-status,
.finance-page .finance-state-badge {
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 15%);
  font-size: .64rem;
  font-weight: 770;
  line-height: 1.2;
}

.finance-page .finance-pagination {
  min-height: 42px;
  padding: 2px;
  justify-content: flex-end;
}

.finance-page .finance-inspector {
  border: 1px solid var(--finance-line);
  border-radius: 13px;
  background: #fff;
  box-shadow: 0 10px 28px rgb(17 34 98 / 7%);
}

.finance-page .finance-inspector__header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--finance-line-soft);
  background: #f7f9fc;
}

.finance-page .finance-inspector__grid {
  padding: 15px 16px;
}

.finance-page .app-modal__surface,
.finance-page .cash-entry-form,
.finance-page .collection-create-form,
.finance-page .invoice-create-form {
  border-radius: 15px;
  box-shadow: 0 24px 70px rgb(11 24 66 / 22%);
}

@media (max-width: 980px) {
  .finance-page .finance-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .finance-page .finance-filters > .primary-button {
    width: 100%;
  }
}

@media (max-width: 680px) {
  .finance-page {
    gap: 12px;
  }

  .finance-page .finance-heading {
    min-height: 0;
    padding: 0;
    margin: 0;
    gap: 12px;
  }

  .finance-page .finance-heading__actions {
    display: flex;
    width: 100%;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
  }

  .finance-page .finance-heading__actions > *,
  .finance-page .finance-heading__actions > .icon-only-button {
    width: auto;
    flex: 0 1 auto;
  }

  .finance-page .finance-filters {
    padding: 13px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .finance-page .finance-filters > .primary-button { width: auto; grid-column: 1 / -1; justify-self: end; }

  .finance-page .finance-table-region {
    max-height: none;
  }

  .finance-page .finance-table {
    min-width: 760px;
  }

  .finance-page .finance-table th,
  .finance-page .finance-table td {
    padding-inline: 10px;
  }

  .finance-page .finance-pagination {
    justify-content: space-between;
  }
}

@media (prefers-reduced-motion: reduce) {
  .finance-page *,
  .finance-page *::before,
  .finance-page *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  /* Keep the portal on the invoice's named page too. Returning from the
     child's named page to an auto-page container can add an empty last page. */
  .document-print-root[data-print-orientation="portrait"]:has(> .finance-invoice-print) {
    page: express24-document-portrait;
  }

  .document-print-root[data-print-orientation="landscape"]:has(> .finance-invoice-print) {
    page: express24-document-landscape;
  }

  .finance-invoice-print__table thead {
    display: table-header-group;
  }

  .finance-invoice-print__table .finance-invoice-print__summary {
    display: table-row-group;
    break-inside: avoid;
    page-break-inside: avoid;
    break-before: avoid;
  }

  .finance-invoice-print__table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .finance-invoice-print__table .finance-invoice-print__money {
    white-space: nowrap;
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  .finance-page .finance-heading__actions,
  .finance-page .finance-filters,
  .finance-page .finance-pagination,
  .finance-page .finance-inspector {
    display: none !important;
  }

  .finance-page .finance-results,
  .finance-page .finance-table-region {
    max-height: none;
    overflow: visible;
    border: 0;
    box-shadow: none;
  }

  .finance-page .finance-table thead th,
  .finance-page .finance-table tbody td:first-child,
  .finance-page .finance-table tfoot th {
    position: static;
  }
}
