/**
 * Beauty CSS
 *
 * Purpose: Visual styling (colors, typography, forms, etc.)
 */

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  padding: 0;
  color: var(--color-text);
  background-color: var(--color-background);
}

/* Links: default to no underline, warm blue-gray color for internal navigation */
a {
  color: var(--color-link);
  text-decoration: none;
}

a:visited {
  color: var(--color-link);
}

/* Heading scale: shifted down one notch from browser defaults */
h1 { font-size: 1.5em; }
h2 { font-size: 1.17em; }
h3 { font-size: 1em; }
h4 { font-size: 0.83em; }
h5 { font-size: 0.67em; }
h6 { font-size: 0.5em; }

/* Vertical rhythm: consistent spacing between major block elements */
h1, h2, h3, form, table {
  margin-block-end: var(--space-lg);
  margin-inline: 0;
}

h2 {
  margin-block-start: 0;
  margin-block-end: 0;
  padding-block-start: var(--space-md);
  padding-block-end: var(--space-lg);
  position: sticky;
  top: 0;
  background: var(--color-background);
  z-index: 2;
}

/* Form controls: Override browser defaults.
 * Remove all borders, margins, padding - use background color to indicate editability.
 * Inspired by monochrome terminals: background color is the affordance.
 * Minimal vertical padding gives editable areas natural proportions. */
input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  background-color: var(--color-editable-background);
  color: var(--color-text);
  border: 0;
  margin: 0;
  padding-block: var(--input-vertical-natural);
  padding-inline: 0;
}

/* Options inside select: match the color scheme */
select > option {
  background-color: var(--color-editable-background);
}

/* ============================================================================
 * Adding Machine Widget
 * ============================================================================ */

.adding-machine-collapsed {
  position: fixed;
  bottom: 0;
  right: 16px;
  z-index: 1000;
  background: var(--color-background);
  border: 1px solid var(--color-border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  box-shadow: -2px -2px 8px var(--color-shadow-strong);
  transition: all 0.2s ease;
}

.adding-machine-tab {
  padding: 8px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  font-family: 'Courier New', 'Consolas', 'Monaco', monospace;
  font-size: 14px;
}

.adding-machine-tab:hover {
  background-color: var(--color-editable-background);
}

.calculator-icon {
  /* sized by .icon class */
}

.total-preview {
  font-weight: bold;
  min-width: 60px;
  text-align: right;
}

.adding-machine-body {
  display: none;
  padding: 16px;
  border-top: 1px solid var(--color-border);
  min-width: 200px;
  background: var(--color-background);
}

.adding-machine-collapsed.expanded .adding-machine-body {
  display: block;
}

.adding-machine-display {
  font-family: 'Courier New', 'Consolas', 'Monaco', monospace;
  font-size: 14px;
}

.adding-machine-tape {
  height: 225px;
  overflow-y: auto;
  margin-bottom: 8px;
  padding: 8px;
  background-color: var(--color-editable-background);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
}

.tape-entry {
  text-align: right;
  padding: 2px 4px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  border-radius: 2px;
}

.tape-entry:hover {
  background-color: var(--color-hover-tint);
}

.tape-entry.editing {
  background-color: var(--color-editing-background);
  font-weight: bold;
}

.tape-entry.positive {
  color: var(--color-text);
}

.tape-entry.negative {
  color: var(--color-editing-negative);
}

.adding-machine-input {
  width: 100%;
  text-align: right;
  margin-bottom: 8px;
  padding: 8px;
  background-color: var(--color-editable-background);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: 'Courier New', 'Consolas', 'Monaco', monospace;
  font-size: 14px;
  box-sizing: border-box;
}

.adding-machine-input.editing-mode {
  background-color: var(--color-editing-background);
  border-color: var(--color-editing-border);
  font-weight: bold;
}

.adding-machine-total {
  text-align: right;
  font-weight: bold;
  font-size: 16px;
  padding: 8px;
  background-color: var(--color-background);
  border-radius: 4px;
  border-top: 2px solid var(--color-border);
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}

.adding-machine-buttons {
  display: flex;
  gap: 8px;
}

.adding-machine-buttons button {
  flex: 1;
  padding: 8px;
  cursor: pointer;
  background-color: var(--color-editable-background);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: 'Courier New', 'Consolas', 'Monaco', monospace;
}

.adding-machine-buttons button:hover {
  background-color: var(--color-background);
}

/* Highlight source field when adding machine is active */
.am-source-field {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

/* ============================================================================
 * Header and Footer
 * ============================================================================ */

.layout-container > header {
  background-color: var(--color-background-header);
  border-bottom: 1px solid var(--color-border);
}

.layout-container > header h1 {
  margin: 0;
  font-size: 1.25rem;
}

.layout-container > header h1 a {
  text-decoration: none;
  color: var(--color-text);
}

.layout-container > footer {
  background-color: var(--color-background-header);
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
  color: var(--color-text);
  opacity: 0.7;
}

/* Disabled inputs and selects: keep original color but make it muted and ghosted */
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* File input: style the browser's file selector button */
input[type="file"]::file-selector-button {
  font-family: inherit;
  font-size: inherit;
  background-color: var(--color-primary-light);
  color: var(--color-primary-dark);
  border: 0;
  padding-block: var(--input-vertical-natural);
  padding-inline: 1rem;
  margin: 0;
  margin-inline-end: 1rem;
  cursor: pointer;
}

/* Buttons: use background color to indicate actionability (like inputs use for editability).
 * Match input vertical padding for alignment, generous horizontal padding for click target. */
button {
  font-family: inherit;
  font-size: inherit;
  background-color: var(--color-editable-background);
  color: var(--color-text);
  border: 0;
  padding-block: var(--input-vertical-natural);  /* Match inputs for vertical alignment */
  padding-inline: 1rem;  /* 16px - horizontal breathing room */
  margin: 0;
  cursor: pointer;
}

/* Disabled buttons: keep original color but make it muted and ghosted */
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Primary button: for safe/primary actions like save
 * Light background with darker text for subtle presence, clear purpose */
button.primary {
  background-color: var(--color-primary-light);
  color: var(--color-primary-dark);
}

/* Secondary button: for less prominent actions like cancel
 * Uses its own color - clearly a button, distinct from headers and editable fields
 * Maintains affordance while respecting the "white = fillable" design language */
button.secondary {
  background-color: var(--color-secondary-light);
  color: var(--color-secondary-dark);
}

/* Danger button: for destructive actions like delete
 * Light background with darker text for subtle presence, clear purpose */
button.danger {
  background-color: var(--color-danger-light);
  color: var(--color-danger-dark);
}

/* Form field wrapper: label above input pattern */
.beauty-label-over-input {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: flex-start;
}

/* Form layout: horizontal flow with wrapping */
.beauty-form-horizontal {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.beauty-form-vertical {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.beauty-form-vertical label {
  display: block;
  margin-bottom: 0.25rem;
}

.beauty-button-row {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

/* Negative numbers: display in financial negative color */
[data-value^="-"] {
  color: var(--color-negative);
}

/* Card layout: horizontal flow with larger gap for major page sections */
.beauty-card-horizontal {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xl);
}

/* Tables: remove cell spacing for continuous backgrounds */
table {
  border-spacing: 0;
}

/* Scrollable table wrapper: creates scroll context for sticky header */
.scrollable-table-wrapper {
  max-height: 80vh;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.scrollable-table-wrapper table thead th {
  position: sticky;
  top: 0;
  background-color: var(--color-background-header);
  z-index: 1;
}

/* Table header and footer: background color for visual distinction */
thead {
  background-color: var(--color-background-header);
}

tfoot {
  background-color: var(--color-background-footer);
}

/* Footer cells: match header padding and make bold */
tfoot td {
  padding-block: 0.28125rem;  /* Match header padding for consistent visual weight */
  font-weight: bold;
}

/* Table cells: right padding for columns, vertical padding for row spacing, center alignment */
td, th {
  padding-right: var(--space-md);
  padding-block: var(--table-row-vertical-natural);
  vertical-align: middle;
}

/* Label column in label-value tables: prevent wrapping */
.col-1-right td:first-child {
  white-space: nowrap;
}

/* Table rows: min-height to match rows with inputs/buttons
 * Calculation: line-height (1.2 * 16px = 19.2px) + input padding (2 * 3px = 6px) + cell padding (2 * 2.5px = 5px) ≈ 31px */
tbody tr {
  height: 31px;
}

/* Greenbar pattern: 3-row bands with alternating background
 * Inspired by classic greenbar computer paper - easier to track rows in dense tables
 * First 3 rows: normal background, Next 3 rows: lighter with borders, repeat
 * Apply to tables with class="greenbar"
 * Uses "of :not(.d-none)" so filtered/hidden rows don't break the pattern */
.greenbar tbody tr:nth-child(6n+1 of :not(.d-none)),
.greenbar tbody tr:nth-child(6n+2 of :not(.d-none)),
.greenbar tbody tr:nth-child(6n+3 of :not(.d-none)) {
  background-color: var(--color-background);
}

.greenbar tbody tr:nth-child(6n+4 of :not(.d-none)),
.greenbar tbody tr:nth-child(6n+5 of :not(.d-none)),
.greenbar tbody tr:nth-child(6n+6 of :not(.d-none)) {
  background-color: var(--color-greenbar-alternate);
}

/* Borders to define the greenbar bands */
.greenbar tbody tr:nth-child(6n+4 of :not(.d-none)) td {
  border-top: 1px solid var(--color-background-header);
}

.greenbar tbody tr:nth-child(6n+6 of :not(.d-none)) td {
  border-bottom: 1px solid var(--color-background-header);
}

/* Selected row highlight for detail views */
.greenbar tbody tr.row-selected {
  background-color: var(--color-primary-light);
  box-shadow: inset 3px 0 0 var(--color-primary);
}

/* Deleted row styling */
.greenbar tbody tr.rule-deleted {
  opacity: 0.5;
  text-decoration: line-through;
}

/* Last column: no right padding */
td:last-child, th:last-child {
  padding-right: 0;
}

/* Table headers: default to left alignment, more vertical padding for prominence, bold text */
th {
  text-align: left;
  padding-block: 0.28125rem;  /* Match button padding for better visual weight */
  font-weight: bold;
}

/* Table column alignment: Apply class to <table> element to align specific columns.
 * Example: <table class="col-3-right col-4-center"> will right-align column 3 and center column 4
 * throughout the entire table (thead, tbody, tfoot). */
.col-1-right :is(td, th):nth-child(1) {
  text-align: right;
}

.col-2-right :is(td, th):nth-child(2) {
  text-align: right;
}

.col-3-right :is(td, th):nth-child(3) {
  text-align: right;
}

.col-4-right :is(td, th):nth-child(4) {
  text-align: right;
}

.col-5-right :is(td, th):nth-child(5) {
  text-align: right;
}

.col-6-right :is(td, th):nth-child(6) {
  text-align: right;
}

/* Numeric column alignment: Right-align with generous left padding to prevent crowding.
 * Use for numeric columns that need visual separation (financial data, statistics, etc.)
 * Example: <table class="col-2-number col-3-number col-4-number"> */
.col-1-number :is(td, th):nth-child(1) {
  text-align: right;
  padding-left: 1rem;
}

.col-2-number :is(td, th):nth-child(2) {
  text-align: right;
  padding-left: 1rem;
}

.col-3-number :is(td, th):nth-child(3) {
  text-align: right;
  padding-left: 1rem;
}

.col-4-number :is(td, th):nth-child(4) {
  text-align: right;
  padding-left: 1rem;
}

.col-5-number :is(td, th):nth-child(5) {
  text-align: right;
  padding-left: 1rem;
}

.col-6-number :is(td, th):nth-child(6) {
  text-align: right;
  padding-left: 1rem;
}

/* Semantic column styling: Apply classes to <th> elements, styles propagate to entire column.
 * Opt-in with class="apply-column-classes" on <table>.
 * Available classes: "right" (right-align), "number" (right-align + left padding), "center"
 * Example: <table class="apply-column-classes"><th class="number">Balance</th></table> */

/* Right-aligned columns */
table.apply-column-classes:has(th:nth-child(1).right) :is(td, th):nth-child(1) {
  text-align: right;
}

table.apply-column-classes:has(th:nth-child(2).right) :is(td, th):nth-child(2) {
  text-align: right;
}

table.apply-column-classes:has(th:nth-child(3).right) :is(td, th):nth-child(3) {
  text-align: right;
}

table.apply-column-classes:has(th:nth-child(4).right) :is(td, th):nth-child(4) {
  text-align: right;
}

table.apply-column-classes:has(th:nth-child(5).right) :is(td, th):nth-child(5) {
  text-align: right;
}

table.apply-column-classes:has(th:nth-child(6).right) :is(td, th):nth-child(6) {
  text-align: right;
}

table.apply-column-classes:has(th:nth-child(7).right) :is(td, th):nth-child(7) {
  text-align: right;
}

table.apply-column-classes:has(th:nth-child(8).right) :is(td, th):nth-child(8) {
  text-align: right;
}

/* Numeric columns (right-align + left padding for separation) */
table.apply-column-classes:has(th:nth-child(1).number) :is(td, th):nth-child(1) {
  text-align: right;
  padding-left: 1rem;
}

table.apply-column-classes:has(th:nth-child(2).number) :is(td, th):nth-child(2) {
  text-align: right;
  padding-left: 1rem;
}

table.apply-column-classes:has(th:nth-child(3).number) :is(td, th):nth-child(3) {
  text-align: right;
  padding-left: 1rem;
}

table.apply-column-classes:has(th:nth-child(4).number) :is(td, th):nth-child(4) {
  text-align: right;
  padding-left: 1rem;
}

table.apply-column-classes:has(th:nth-child(5).number) :is(td, th):nth-child(5) {
  text-align: right;
  padding-left: 1rem;
}

table.apply-column-classes:has(th:nth-child(6).number) :is(td, th):nth-child(6) {
  text-align: right;
  padding-left: 1rem;
}

table.apply-column-classes:has(th:nth-child(7).number) :is(td, th):nth-child(7) {
  text-align: right;
  padding-left: 1rem;
}

table.apply-column-classes:has(th:nth-child(8).number) :is(td, th):nth-child(8) {
  text-align: right;
  padding-left: 1rem;
}

/* Center-aligned columns */
table.apply-column-classes:has(th:nth-child(1).center) :is(td, th):nth-child(1) {
  text-align: center;
}

table.apply-column-classes:has(th:nth-child(2).center) :is(td, th):nth-child(2) {
  text-align: center;
}

table.apply-column-classes:has(th:nth-child(3).center) :is(td, th):nth-child(3) {
  text-align: center;
}

table.apply-column-classes:has(th:nth-child(4).center) :is(td, th):nth-child(4) {
  text-align: center;
}

table.apply-column-classes:has(th:nth-child(5).center) :is(td, th):nth-child(5) {
  text-align: center;
}

table.apply-column-classes:has(th:nth-child(6).center) :is(td, th):nth-child(6) {
  text-align: center;
}

table.apply-column-classes:has(th:nth-child(7).center) :is(td, th):nth-child(7) {
  text-align: center;
}

table.apply-column-classes:has(th:nth-child(8).center) :is(td, th):nth-child(8) {
  text-align: center;
}

.col-1-bold :is(td, th):nth-child(1) {
  font-weight: bold;
}

.col-1-center :is(td, th):nth-child(1) {
  text-align: center;
}

.col-2-center :is(td, th):nth-child(2) {
  text-align: center;
}

.col-3-center :is(td, th):nth-child(3) {
  text-align: center;
}

.col-4-center :is(td, th):nth-child(4) {
  text-align: center;
}

.col-5-center :is(td, th):nth-child(5) {
  text-align: center;
}

.col-6-center :is(td, th):nth-child(6) {
  text-align: center;
}

/* Center checkboxes within centered cells */
td.text-center input[type="checkbox"] {
  display: block;
  margin: 0 auto;
}

/* Utility: vertical stack with consistent gap */
.beauty-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* Utility: extra top margin for dialog button rows (additive with gap) */
.dialog-buttons {
  margin-block-start: var(--space-lg);
}

/* Utility: separated box with top and bottom borders */
.beauty-separated-box {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  border-top: 1px solid var(--color-text);
  border-bottom: 1px solid var(--color-text);
  padding-block: var(--space-md);
  margin-block: var(--space-md);
}

/* Dialog (modal) styling */
dialog {
  background-color: var(--color-background);
  color: var(--color-text);
  border: none;
  border-radius: 0.25rem;  /* Subtle rounding - understated */
  padding: var(--space-lg);
  max-width: 600px;
}

dialog::backdrop {
  background-color: var(--color-overlay);
  backdrop-filter: blur(2px);
}

/* Paper: looks like a piece of paper */
.paper {
  background-color: var(--color-background-paper);
  padding: var(--space-lg);
  border-radius: 0.5rem;
}

/* Report Layout: controls sidebar + scrollable paper report side-by-side */
.report-layout {
  display: flex;
  gap: var(--space-lg);
  height: 80vh;
}

.report-controls {
  flex: 0 0 280px;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  align-self: flex-start;
}

.report-controls-stretch {
  align-self: stretch;
}

.report-layout > .paper {
  flex: 1;
  overflow-y: auto;
}

.report-paper-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.report-paper-column > .paper {
  flex: 1;
  overflow-y: auto;
}

.paper .scrollable-table-wrapper thead th {
  background-color: var(--color-background-paper);
}

.col-budget-group {
  background-color: var(--color-group-tint);
}

.paper thead .th-budget-group {
  background-color: var(--color-background-group-header);
}

.paper-print-btn {
  position: sticky;
  top: var(--space-sm);
  float: right;
  z-index: 1;
}

/* Action Box and Alert styles are in components.css */

/* Attention/warning state for form controls that need user action */
.needs-attention {
  background-color: var(--color-warning-background);
  border: 2px solid var(--color-warning-border);
  padding: 0.5rem;
  border-radius: 0.25rem;
}

/* Drawer styles are in components.css */

/* ============================================================================
 * Standardized Page Layout Patterns
 * ============================================================================ */

/* Page Container: consistent padding, natural width from content */
.page-container {
  padding: var(--space-lg);
}

/* Page Controls Zone: boxes the selector/filter/action area separate from data tables */
.page-controls {
  border: 1px solid var(--color-background-header);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
  border-radius: 4px;
}

/* Page Header: sticky title row with optional action links */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-sm);
  position: sticky;
  top: 0;
  background: var(--color-background);
  z-index: 2;
  padding-block-start: var(--space-md);
  padding-block-end: var(--space-lg);
}

.page-header h2 {
  margin: 0;
  padding: 0;
  position: static;
  background: none;
  z-index: auto;
}

.page-header-actions {
  display: flex;
  gap: var(--space-md);
  align-items: center;
}

.page-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Entity Selector Row: dropdown + action buttons */
.entity-selector-row {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: var(--space-lg);
}

/* Filter Bar: collapsible filter controls */
.filter-bar {
  background: var(--color-background-subtle);
  padding: var(--space-md);
  border-radius: 4px;
  margin-bottom: var(--space-lg);
}

.filter-bar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.filter-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  align-items: center;
}

/* Data Section: tables grouped by category */
.data-section {
  margin-bottom: var(--space-xl);
}

.data-section:last-child {
  margin-bottom: 0;
}

.data-section-header {
  margin-bottom: var(--space-md);
}

.data-section-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

/* Table Container: wrapper for tables with actions */
.table-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* Fixed column width utilities for consistent table layouts */
.col-width-sm { width: 80px; min-width: 80px; }
.col-width-md { width: 120px; min-width: 120px; }
.col-width-lg { width: 180px; min-width: 180px; }
.col-width-xl { width: 240px; min-width: 240px; }

/* Modal enhancements */
dialog.modal-standard {
  min-width: 400px;
  max-width: 600px;
}

dialog.modal-wide {
  min-width: 600px;
  max-width: 800px;
}

dialog h3 {
  margin-top: 0;
  margin-bottom: var(--space-md);
}

/* Label-value table pattern (for info display in modals) */
.label-value-table {
  width: 100%;
}

.label-value-table td:first-child {
  font-weight: 600;
  padding-right: 1rem;
  white-space: nowrap;
}

/* Utility: section divider */
.section-divider {
  border-top: 1px solid var(--color-border);
  margin-block: var(--space-lg);
}


/* AutoNumeric negative value styling */
input.autoNumeric-negative {
  color: var(--color-negative);
}

/* Parent-table details pattern: The 1: side of a 1:M relationship
 * Used for detail cards that sit alongside related tables
 * Light background extends to bottom, content stays at top */
.parent-table-details {
  background-color: var(--color-greenbar-alternate);
  border-radius: 4px;
  padding: 0 2rem 2rem 2rem;
  min-height: calc(100vh - 16rem);
}

/* Child table rows pattern: The :M side of a 1:M relationship
 * Used for tables that sit alongside a parent detail card
 * Extra left padding creates visual separation from the parent */
.child-table-rows {
  padding-left: 2rem;
}

/* ============================================================================
 * Main Menu Cards
 * ============================================================================ */

.main-menu {
  display: flex;
  flex-wrap: wrap;
}

.menu-card {
  display: inline-block;
  background-color: var(--color-background-paper);
  padding: var(--space-lg);
  border-radius: 0.5rem;
  vertical-align: top;
  margin-right: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.menu-card h3 {
  margin: 0 0 var(--space-md) 0;
}

.menu-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.menu-item {
  padding: var(--space-sm) 0;
}

.menu-item a {
  font-weight: 600;
}

.menu-item-description {
  display: block;
  color: var(--color-text);
  opacity: 0.7;
  font-size: 0.875rem;
}

/* ============================================================================
 * UTILITY CLASSES
 *
 * Naming conventions:
 * - Display: d-{value}
 * - Flex: flex-{property}, justify-{value}, align-{value}
 * - Spacing: {property}{side}-{size} (mt-md, pb-lg, etc.)
 * - Sizing: w-{value}, max-w-{value}, min-w-{value}
 * - Text: text-{property}
 * - Font: font-{property}
 *
 * Size scale (uses design tokens where possible):
 * - sm = var(--space-sm) = 0.5rem
 * - md = var(--space-md) = 1rem
 * - lg = var(--space-lg) = 1.5rem
 * - xl = var(--space-xl) = 3rem
 * ============================================================================ */

/* Display */
.d-none { display: none; }
.d-block { display: block; }
.d-flex { display: flex; }
.d-grid { display: grid; }
.d-inline-block { display: inline-block; }

/* Flexbox */
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.flex-grow { flex-grow: 1; }
.flex-wrap { flex-wrap: wrap; }
.flex-column { flex-direction: column; }
.justify-start { justify-content: flex-start; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.justify-between { justify-content: space-between; }
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }

/* Gap - using tokens */
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }

/* Cursor */
.cursor-pointer { cursor: pointer; }

/* Width */
.w-100 { width: 100%; }
.w-fit { width: fit-content; }
.min-w-200 { min-width: 200px; }
.min-w-300 { min-width: 300px; }
.min-w-400 { min-width: 400px; }
.max-w-300 { max-width: 300px; }
.max-w-400 { max-width: 400px; }
.max-w-500 { max-width: 500px; }
.max-w-600 { max-width: 600px; }

/* Height */
.max-h-400 { max-height: 400px; overflow-y: auto; }
.max-h-460 { max-height: 460px; overflow-y: auto; }
.max-h-600 { max-height: 600px; overflow-y: auto; }

/* Margin - using tokens */
.mt-0 { margin-top: 0; }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }
.mb-0 { margin-bottom: 0; }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }
.ml-sm { margin-left: var(--space-sm); }
.ml-md { margin-left: var(--space-md); }
.mr-sm { margin-right: var(--space-sm); }
.mr-md { margin-right: var(--space-md); }

/* Padding - using tokens */
.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }
.pt-sm { padding-top: var(--space-sm); }
.pt-md { padding-top: var(--space-md); }
.pt-lg { padding-top: var(--space-lg); }
.pb-sm { padding-bottom: var(--space-sm); }
.pb-md { padding-bottom: var(--space-md); }
.pb-lg { padding-bottom: var(--space-lg); }

/* Text alignment */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Text color */
.text-secondary { color: var(--color-text-secondary); }
.text-danger { color: var(--color-danger); }
.text-green { color: var(--color-favorable); }
.text-red { color: var(--color-unfavorable); }

/* Value colors - for financial amounts */
.value-positive { color: var(--color-success); }
.value-negative { color: var(--color-negative); }

/* Font */
.font-bold { font-weight: bold; }
.font-semibold { font-weight: 600; }
.font-italic { font-style: italic; }
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.1rem; }

/* Background */
.bg-paper { background-color: var(--color-background-paper); }
.bg-subtle { background-color: var(--color-greenbar-alternate); }

/* Border */
.border-top { border-top: 1px solid var(--color-border); }
.border-bottom { border-bottom: 1px solid var(--color-border); }

/* Links */
.link-primary { color: var(--color-primary); }

/* Table section headers */
th.section-header { text-align: left; }
th.section-header-padded { text-align: left; padding-top: var(--space-md); }

/* Table row variants */
.begin-row {
  background-color: var(--color-greenbar-alternate);
  font-weight: 600;
}

.totals-row {
  background-color: var(--color-background-header);
  font-weight: bold;
}

/* Sortable table headers */
table[data-sortable] th[data-sort]::after {
  margin-left: 0.25em;
}

table[data-sortable] th[data-sort="asc"]::after {
  content: "\25B2";
}

table[data-sortable] th[data-sort="desc"]::after {
  content: "\25BC";
}

/* Column text filter indicators */
.column-filter-indicator {
  display: inline-block;
  margin-left: 0.5em;
  font-size: 0.8em;
  font-weight: normal;
  color: var(--color-primary);
  cursor: pointer;
  vertical-align: baseline;
}

.column-filter-indicator:hover {
  color: var(--color-danger);
}

/* Rule indicator: clickable badge showing a row was matched by rule */
.rule-indicator {
  font-size: 0.75em;
  font-weight: 600;
  color: var(--color-primary);
  opacity: 0.6;
  background: none;
  padding: 0 0.25em;
  cursor: pointer;
}

.rule-indicator:hover {
  opacity: 1;
}

/* ============================================================================
 * Print: show only the .paper report, suppress browser headers/footers
 * ============================================================================ */

@page {
  margin: 0;
}

@media print {
  /* Hide everything */
  body * {
    visibility: hidden;
  }

  /* Show only the paper report and its contents */
  .paper, .paper * {
    visibility: visible;
  }

  .paper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 1.5cm;
    box-sizing: border-box;
  }

  /* Hide the print button itself */
  .paper-print-btn {
    display: none;
  }
}

/* Error page */
.error-page {
  padding: var(--space-xl);
  max-width: 600px;
  margin: 0 auto;
  text-align: center;
}

.error-page-actions {
  margin-top: var(--space-lg);
  display: flex;
  gap: var(--space-md);
  justify-content: center;
}
