/* ================================================================
   AMIPI NACHA ACH Payment System — Design Tokens & Base Styles
   ================================================================
   All colors, fonts, spacing, and radii are defined here as CSS
   custom properties. To re-theme the app, edit ONLY these variables.
   ================================================================ */

:root {
  /* ── Color Palette — Clean Fintech Design ───────────────────── */
  /* Solid indigo primary (inspired by Stripe) */
  --color-primary:        #06006d; 
  --color-primary-hover:  #0e00ac;  /* Indigo-700 */
  --color-primary-light:  #EEF2FF;  /* Indigo-50 */
  --color-primary-dark:   #3730A3;  /* Indigo-800 */
  --color-primary-muted:  #818CF8;  /* Indigo-400 */

  /* Accent (same as primary for consistency) */
  --color-accent:         #4F46E5;
  --color-accent-hover:   #4338CA;
  --color-accent-light:   #EEF2FF;

  /* Error red */
  --color-danger:         #DC2626;  /* Red-600 */
  --color-danger-hover:   #B91C1C;  /* Red-700 */
  --color-danger-light:   #FEF2F2;  /* Red-50 */

  /* Warning amber */
  --color-warning:        #D97706;  /* Amber-600 */
  --color-warning-hover:  #B45309;  /* Amber-700 */
  --color-warning-light:  #FFFBEB;  /* Amber-50 */

  /* Success green */
  /* Emerald-700: Emerald-600 (#059669) measured 3.77:1 as white-on-green (Approve) and
     as green text on white, below the 4.5:1 WCAG AA minimum. */
  --color-success:        #047857;  /* Emerald-700 */
  --color-success-hover:  #065F46;  /* Emerald-800 */
  --color-success-light:  #ECFDF5;  /* Emerald-50 */

  /* Neutral backgrounds — calm, professional */
  --color-bg:             #FAFAFA;  /* Very light gray */
  --color-surface:        #f3f3f3;
  --color-surface-alt:    #F9FAFB;  /* Gray-50 */
  --color-surface-raised: #FFFFFF;

  /* Border colors — subtle definition */
  --color-border:         #E5E7EB;  /* Gray-200 */
  --color-border-light:   #F3F4F6;  /* Gray-100 */
  --color-border-strong:  #D1D5DB;  /* Gray-300 */
  --border-color:         #E2E8F0;  /* Alias for inline styles */
  --bg-card-hover:        #F8FAFC;  /* Alias for hover state */

  /* Text colors — strong readability */
  --color-text:           #111827;  /* Gray-900 */
  --color-text-secondary: #4B5563;  /* Gray-600 */
  /* #6B7280 measured 4.36:1 on the #f3f3f3 card surface (and 4.2-4.4 on the tinted
     alert/badge backgrounds): every hint, label and caption was below WCAG AA. */
  --color-text-muted:     #5F6673;
  --color-text-inverse:   #FFFFFF;

  /* Code/monospace styling */
  --color-code-bg:        #1F2937;  /* Gray-800 */
  --color-code-text:      #F9FAFB;  /* Gray-50 */

  /* ── Typography ─────────────────────────────────────────────── */
  --font-body:            'Poppins', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:            'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Courier New', monospace;
  --font-heading:         'Stack Sans Notch','Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --text-xs:              0.6875rem;   /* 11px */
  --text-sm:              0.79rem;    
  --text-base:            0.875rem;    /* 14px */
  --text-md:              0.9375rem;   /* 15px */
  --text-lg:              1.125rem;    /* 18px */
  --text-xl:              1.375rem;    /* 22px */
  --text-2xl:             1.75rem;     /* 28px */

  --font-weight-normal:   400;
  --font-weight-medium:   500;
  --font-weight-semibold: 600;
  --font-weight-bold:     700;

  /* ── Spacing ────────────────────────────────────────────────── */
  --space-xs:             0.25rem;   /* 4px  */
  --space-sm:             0.5rem;    /* 8px  */
  --space-md:             0.75rem;   /* 12px */
  --space-base:           1rem;      /* 16px */
  --space-lg:             1.5rem;    /* 24px */
  --space-xl:             2rem;      /* 32px */
  --space-2xl:            2.5rem;    /* 40px */
  --space-3xl:            3rem;      /* 48px */
  --space-4xl:            4rem;      /* 64px */

  /* ── Border Radius ──────────────────────────────────────────── */
  --radius-sm:            0.475rem;
  --radius-md:            0.67rem;  
  --radius-lg:            0.95rem; 
  --radius-xl:            1rem;      /* 16px */
  --radius-2xl:           1.25rem;   /* 20px */
  --radius-full:          9999px;

  /* ── Shadows — Subtle, Professional ─────────────────────────── */
  --shadow-xs:            0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-sm:            0 1px 3px 0 rgba(0, 0, 0, 0.1), 
                          0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md:            0 4px 6px -1px rgba(0, 0, 0, 0.1),
                          0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg:            0 10px 15px -3px rgba(0, 0, 0, 0.1),
                          0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl:            0 20px 25px -5px rgba(0, 0, 0, 0.1),
                          0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-2xl:           0 25px 50px -12px rgba(0, 0, 0, 0.25);

  /* ── Transitions ────────────────────────────────────────────── */
  --transition-fast:      150ms ease;
  --transition-base:      250ms ease;
  --transition-slow:      350ms ease;

  /* ── Z-index layers ─────────────────────────────────────────── */
  --z-dropdown:           100;
  --z-modal:              1000;
  --z-lock:               9999;   /* sign-in screen */
  --z-toast:              10000;  /* notifications stay readable above everything */
}

/* ── Modal Dialog Components ──────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: var(--z-modal, 1000);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-md, 16px);
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
}

.modal-backdrop.active {
  display: flex !important;
}

.modal-card {
  background: var(--color-surface-raised, #ffffff);
  border-radius: var(--radius-xl, 16px);
  padding: var(--space-xl, 24px);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--color-border, #e2e8f0);
  width: 100%;
  max-width: 760px;
  max-height: 85vh;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  animation: modalSlideUp 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  margin: auto;
}

.modal-card:focus {
  outline: none;
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}


/* ================================================================
   Global Reset & Base
   ================================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

code, pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}


/* ================================================================
   Component: Buttons
   ================================================================
   Usage:  .btn + modifier (.btn-primary, .btn-secondary, etc.)
   ================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  box-shadow: var(--shadow-xs);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}
.btn-primary:active:not(:disabled) {
  background: var(--color-primary-dark);
  box-shadow: none;
}

.btn-secondary {
  background-color: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover:not(:disabled) {
  background-color: var(--color-surface-alt);
  border-color: var(--color-border-strong);
}

.btn-accent {
  background: var(--color-accent);
  color: var(--color-text-inverse);
  border-color: var(--color-accent);
}
.btn-accent:hover:not(:disabled) {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}

.btn-danger {
  background-color: var(--color-danger);
  color: var(--color-text-inverse);
  border-color: var(--color-danger);
}
.btn-danger:hover:not(:disabled) {
  background-color: var(--color-danger-hover);
  border-color: var(--color-danger-hover);
}

/* Approve / Activate. Used in Admin Review but never defined, so "Approve" rendered as
   an unstyled grey button beside a red "Reject". */
.btn-success {
  background-color: var(--color-success);
  color: var(--color-text-inverse);
  border-color: var(--color-success);
}
.btn-success:hover:not(:disabled) {
  background-color: var(--color-success-hover);
  border-color: var(--color-success-hover);
}

/* Amber-700 fill: white on Amber-600 was 3.19:1. */
.btn-warning {
  background-color: var(--color-warning-hover);
  color: var(--color-text-inverse);
  border-color: var(--color-warning-hover);
}
.btn-warning:hover:not(:disabled) {
  background-color: #92400E;
  border-color: #92400E;
}

/* Low-emphasis destructive action (row "Delete"), replacing per-button inline styles. */
.btn-danger-soft {
  background: var(--color-danger-light);
  color: var(--color-danger-hover); /* Red-600 on Red-50 was 4.41:1 */
  border-color: #FECACA;
  box-shadow: none;
}
.btn-danger-soft:hover:not(:disabled) {
  background: #FEE2E2;
  border-color: #FCA5A5;
}

/* Compact chips (placeholder inserts, table row actions). Used but never defined. */
.btn-xs {
  padding: 0.2rem 0.55rem;
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
  gap: var(--space-xs);
}
.btn.btn-xs {
  min-height: 1.6rem;
}

.btn-sm {
  /* 4px of vertical padding left small buttons feeling cramped next to 44px inputs
     and gave them a touch target below the ~32px minimum. */
  padding: var(--space-sm) var(--space-base);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}

/*
 * Floor on button height.
 *
 * Around a hundred buttons carry inline `padding` and `font-size` overrides, which beat
 * any padding set in a stylesheet. The Admin user rows rendered at 17px tall and the
 * Cards/Table toggle at 22px — below a usable target, and these include destructive
 * actions like Deactivate. `min-height` is not among the properties those inline styles
 * set, so declaring it here takes effect without having to unpick every one of them.
 */
.btn,
.btn-sm {
  min-height: 2rem; /* 32px */
}
.btn-lg {
  min-height: 2.75rem;
}

/*
 * Horizontal scrolling for wide tables.
 *
 * `.table-responsive` was used in the markup in several places but NEVER DEFINED, so it
 * did nothing: the Audit Trail table pushed the page 683px wider than the viewport at
 * 390px, and 315px wider at tablet width. Fixed-width financial columns cannot usefully
 * reflow, so the table scrolls within its own container instead of dragging the page.
 */
.table-responsive {
  overflow-x: auto;
  width: 100%;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

/*
 * Segmented view toggle (Cards / Table). Was five inline declarations per button.
 */
.btn-toggle {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  box-shadow: none;
  gap: var(--space-xs);
}
.btn-toggle:hover:not(:disabled) {
  background: var(--color-surface-alt);
  color: var(--color-text);
}
.btn-toggle.active {
  background: var(--color-surface-raised);
  color: var(--color-primary);
  font-weight: var(--font-weight-semibold);
  box-shadow: var(--shadow-sm);
}

/* Container for a group of .btn-toggle options. */
.segmented-control {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--color-border-light);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  flex-wrap: wrap;
}
.segmented-control .btn-toggle {
  padding: var(--space-xs) var(--space-md);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
}

/*
 * Outlined button.
 *
 * The "Validate Batch" buttons each carried the same five hardcoded inline
 * declarations, repeated in the markup and again in the JS that builds additional
 * batches, so they drifted from the token scale. This is that treatment as one class.
 */
.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
  box-shadow: none;
}
.btn-outline:hover:not(:disabled) {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}
.btn-outline:active:not(:disabled) {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
}

/*
 * A row of buttons beneath a form or table. Replaces the inline
 * `display:flex; gap:...; margin-top:...` repeated at every such row.
 */
.action-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-md);
  margin-top: var(--space-lg);
}

/*
 * A row of controls that must wrap rather than widen the page.
 *
 * Several toolbars were inline `display: flex` with no `flex-wrap`, so at 390px they
 * stayed on one line and pushed the document 91px wider than the viewport, letting the
 * whole layout be dragged sideways.
 */
.toolbar-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-sm);
  min-width: 0;
}

/* Separates a trailing "add another" control from the block it appends to. */
.action-row-standalone {
  margin-top: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.btn-lg {
  padding: var(--space-base) var(--space-2xl);
  font-size: var(--text-md);
}

.btn-block {
  width: 100%;
}

.btn .spinner {
  width: 1em;
  height: 1em;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ================================================================
   Component: Form Fields
   ================================================================ */

.form-group {
  display: flex;
  flex-direction: column;
  /* 4px put the label almost touching its input. */
  gap: var(--space-sm);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
}

.form-input,
.form-select {
  height: 2.75rem;
  padding: 0 var(--space-base);
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background-color: var(--color-surface-raised);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), 
              box-shadow var(--transition-fast);
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-input:hover:not(:focus):not(:disabled):not([readonly]) {
  border-color: #9CA3AF;
}

/* Non-editable fields must read as such: grey fill, no hover affordance. */
.form-input:disabled,
.form-input[readonly],
.form-select:disabled {
  background-color: var(--color-surface-alt);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
  cursor: not-allowed;
}
.form-input[readonly] {
  cursor: default;
}

/* Native file pickers inside .form-input: the browser button sat at the top edge. */
input[type="file"].form-input {
  height: auto;
  min-height: 2.75rem;
  padding: 0.4rem var(--space-sm);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
}
input[type="file"].form-input::file-selector-button {
  margin-right: var(--space-md);
  padding: 0.45rem var(--space-base);
  font: inherit;
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
input[type="file"].form-input:hover::file-selector-button {
  background: var(--color-border-light);
}

.form-input::placeholder {
  color: var(--color-text-muted);
}

.form-input.is-error {
  border-color: var(--color-danger);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  min-height: 1rem;
}

/* Compact input (inline email edit in Payment History). Used but never defined. */
.form-input-sm {
  height: 1.9rem;
  padding: 0 var(--space-sm);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
}

/* The global reset zeroed textarea padding and .form-input fixed a 44px height, so the
   change-request reason box showed barely one line. */
textarea.form-input {
  height: auto;
  min-height: 4.5rem;
  padding: var(--space-sm) var(--space-base);
  line-height: 1.5;
  resize: vertical;
}


/* ================================================================
   Component: Cards
   ================================================================ */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-base);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}


/* ================================================================
   Component: Badges
   ================================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem var(--space-md);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  border: 1px solid;
}

.badge-success { 
  background: var(--color-success-light); 
  color: #065F46; 
  border-color: #6EE7B7;
}
.badge-danger { 
  background: var(--color-danger-light); 
  color: #991B1B; 
  border-color: #FCA5A5;
}
.badge-warning { 
  background: var(--color-warning-light); 
  color: #92400E; 
  border-color: #FCD34D;
}
.badge-info { 
  background: var(--color-primary-light); 
  color: var(--color-primary-dark); 
  border-color: #A5B4FC;
}
/* The next three were used (role badges, audit actions, account types) but never
   defined, so they rendered as bare outlines: Admin and User looked identical. */
.badge-primary {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  border-color: #C7D2FE;
}
.badge-secondary,
.badge-neutral {
  background: var(--color-border-light);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}
.badge-neutral {
  text-transform: capitalize;
}
.badge-trace {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border-color: var(--color-border-strong);
  font-family: var(--font-mono);
  border-radius: var(--radius-sm);
  letter-spacing: 0.03em;
}


/* ================================================================
   Component: Tables
   ================================================================ */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

/*
 * Tables fit their container rather than scrolling inside it.
 *
 * An earlier revision set `min-width: max-content` here so wide tables would scroll. That
 * made the Vendor Book table 1383px inside a 1334px wrapper at full desktop width, which
 * both drew a horizontal scrollbar and CLIPPED the Actions column -- the Delete button was
 * cut in half. Sizing to the container and letting cells wrap is the correct fix; the
 * wrapper keeps `overflow-x: auto` purely as a last resort, and with the table fitting it
 * never renders a bar.
 */
.payments-table-wrap,
.table-responsive {
  min-width: 0;
  /* Containing block for absolutely-positioned content (e.g. .sr-only header text), so
     it is clipped by the wrapper's horizontal scroll instead of widening the page. */
  position: relative;
}
.payments-table-wrap > .data-table,
.table-responsive > .data-table,
.table-responsive > .table {
  width: 100%;
  table-layout: auto;
}

/*
 * Long values must wrap instead of setting a wide minimum for the whole column. Headers
 * were `white-space: nowrap`, so "Payee / Vendor Name" and "Account Number" each demanded
 * their full single-line width and together pushed the table past its container.
 */
.data-table th,
.table-responsive .table th {
  white-space: normal;
}
.data-table td,
.table-responsive .table td {
  /*
   * `break-word`, NOT `anywhere`.
   *
   * `overflow-wrap: anywhere` lets a cell's MINIMUM width fall to a single character, and
   * an auto-layout table honours that. On the Audit Trail, where one cell holds a very
   * long payload, the browser gave that cell nearly all the width and squeezed Timestamp,
   * User and Target Entity down to one character per line - the text rendered vertically.
   *
   * `break-word` keeps each cell's minimum at its longest word, so no column can be
   * starved that way, while still breaking a word that genuinely cannot fit.
   */
  overflow-wrap: break-word;
}

/*
 * The audit payload is the one cell allowed to break mid-token, so it can absorb the
 * slack instead of a single long entry dictating every other column's width.
 */
.data-table td[data-label="Details"],
.table-responsive .table td[data-label="Details"] {
  overflow-wrap: anywhere;
}

/*
 * Keeping short structured values on one line is a nicety, so it only applies where there
 * is room. Below this width these minimums would exceed the container and bring back a
 * horizontal scrollbar; letting them wrap is safe because `overflow-wrap: break-word`
 * holds each cell's minimum at its longest word, so no column can collapse to a single
 * character the way it did with `anywhere`.
 */
@media (min-width: 1280px) {
  .data-table td[data-label="Timestamp"],
  .data-table td[data-label="User"],
  .data-table td[data-label="Action"],
  .data-table td[data-label="Entity"],
  .table-responsive .table td[data-label="Timestamp"],
  .table-responsive .table td[data-label="User"],
  .table-responsive .table td[data-label="Action"],
  .table-responsive .table td[data-label="Entity"] {
    white-space: nowrap;
  }
  .data-table td[data-label="Details"],
  .table-responsive .table td[data-label="Details"] {
    min-width: 18rem;
  }
}

/*
 * Short status pills must never break. Allowing cells to wrap made a narrow Status
 * column render "Active" as "Activ / e".
 */
.badge {
  white-space: nowrap;
}
/* Values that must never break mid-token. */
.data-table td .font-mono,
.data-table td.font-mono {
  white-space: nowrap;
}

.data-table th {
  text-align: left;
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 2px solid var(--color-border);
  background: var(--color-surface-alt);
  font-size: var(--text-xs);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
}

.data-table tbody tr:hover td {
  background: var(--color-primary-light);
}

.data-table .mono {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}


/* ================================================================
   Component: Alerts / Toasts
   ================================================================ */

.alert {
  padding: var(--space-base) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: 1.6;
  display: none;
  border: 1px solid;
  font-weight: var(--font-weight-normal);
}
.alert.show {
  /* Block, not flex: alerts hold running text mixed with <strong>/<br>, which flex split
     into side-by-side columns. */
  display: block;
  animation: alertSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes alertSlideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.alert-error,
.alert-danger {
  background: var(--color-danger-light);
  color: #991B1B;
  border-color: #FCA5A5;
}
/* Multi-line row errors ("Row 1: ...\nRow 2: ...") keep their line breaks. */
.batch-form-error {
  white-space: pre-line;
}

.alert-success {
  background: var(--color-success-light);
  color: #065F46;
  border-color: #6EE7B7;
}

.alert-warning {
  background: var(--color-warning-light);
  color: #92400E;
  border-color: #FCD34D;
}

.alert-info {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  border-color: #A5B4FC;
}


/* ================================================================
   Component: Floating Toast Notifications
   ================================================================ */
.toast-container {
  position: fixed;
  top: 96px; /* below the 84px sticky header, which toasts used to cover */
  right: 24px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: 420px;
  width: calc(100vw - 48px);
}

.toast-item {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
  background: white;
  border: 1px solid var(--color-border);
  color: var(--color-text);
  animation: toastSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast-item.toast-success {
  background: #F0FDF4;
  border-color: #86EFAC;
  color: #166534;
}

.toast-item.toast-error {
  background: #FEF2F2;
  border-color: #FCA5A5;
  color: #991B1B;
}

.toast-item.toast-warning {
  background: #FFFBEB;
  border-color: #FDE68A;
  color: #92400E;
}

.toast-item.toast-info {
  background: #EEF2FF;
  border-color: #C7D2FE;
  color: #3730A3;
}

.toast-close-btn {
  background: transparent;
  border: none;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  padding: 2px 4px;
  font-size: 14px;
  line-height: 1;
  border-radius: 4px;
}

.toast-close-btn:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.05);
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* ================================================================
   Layout: Header
   ================================================================ */

.app-header {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  padding: var(--space-lg) var(--space-2xl);
  display: flex;
  align-items: center;
  gap: var(--space-base);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: var(--z-dropdown);
}

.app-header h1 {
  font-size: var(--text-md);
  font-weight: var(--font-weight-bold);
}

.app-header .header-subtitle {
  font-size: var(--text-xs);
  opacity: 0.85;
  margin-left: auto;
}

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

.header-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--color-text-inverse);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-base);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-body);
}
.header-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}


/* ================================================================
   Layout: Main Container
   ================================================================ */

.main-container {
  max-width: 1440px;
  width: 95%;
  margin: var(--space-xl) auto;
  padding: 0 var(--space-base);
}

/*
 * Payment History needs more room than the other screens. Widening .main-container for
 * it moved the tab bar sideways each time the tab was opened; instead the History panel
 * alone breaks out of the container, symmetrically, up to 1720px.
 */
#view-history.active {
  --history-width: max(100%, min(1720px, calc(100vw - 4rem)));
  width: var(--history-width);
  margin-left: calc((100% - var(--history-width)) / 2);
}


/* ================================================================
   Layout: Tabs
   ================================================================ */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border-light);
  margin-bottom: var(--space-xl);
  /*
   * Six tabs do not fit a narrow viewport. Wrap onto a second line rather than scroll:
   * an `overflow-x: auto` strip reserves a scrollbar gutter and draws a bar across the
   * navigation even at full desktop width, where the tabs fit perfectly well.
   */
  flex-wrap: wrap;
}

.tab {
  padding: var(--space-md) var(--space-xl);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  border: none;
  background: none;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: var(--font-body);
  transition: color var(--transition-fast), 
              border-color var(--transition-fast),
              background-color var(--transition-fast);
}

.tab:hover {
  color: var(--color-text-secondary);
  background-color: var(--color-surface-alt);
}

.tab.active {
  color: var(--color-primary);
  font-weight: var(--font-weight-semibold);
  border-bottom-color: var(--color-primary);
  background-color: transparent;
}


/* ================================================================
   Layout: Views (Tab Panels)
   ================================================================ */

.view {
  display: none;
}
.view.active {
  display: block;
}


/* ================================================================
   Utility: Grid Layouts
   ================================================================ */

.grid-2 {
  display: grid;
  /*
   * minmax(0, 1fr) rather than 1fr. `1fr` expands to minmax(auto, 1fr), and that `auto`
   * minimum is the item's min-content width, so a card whose contents measured 330px
   * forced a 330px track inside a 272px container and the page could be scrolled
   * sideways. minmax(0, ...) lets the track shrink and the content wrap.
   */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-base);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-base);
}

.full-width {
  grid-column: 1 / -1;
}


/* ================================================================
   Utility: Flex Helpers
   ================================================================ */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-xs  { gap: var(--space-xs); }
.gap-sm  { gap: var(--space-sm); }
.gap-md  { gap: var(--space-md); }
.gap-base { gap: var(--space-base); }
.gap-lg  { gap: var(--space-lg); }


/* ================================================================
   Utility: Text
   ================================================================ */

.text-center { text-align: center; }
.text-muted  { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger-hover); } /* Red-600 was 4.35:1 on cards */

/* Visually hidden, still announced by screen readers. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.text-sm     { font-size: var(--text-sm); }
.text-xs     { font-size: var(--text-xs); }
.font-mono   { font-family: var(--font-mono); }
.font-bold   { font-weight: var(--font-weight-bold); }


/* Accessibility Focus Ring States */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
.tab:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ================================================================
   Responsive
   ================================================================ */

@media (max-width: 1280px) {
  .tab {
    padding: var(--space-md) var(--space-base);
  }
}

@media (max-width: 1024px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/*
 * Below 820px six tabs cannot share one row. Wrapping left one tab orphaned on a second
 * row (or three rows on a phone); a single swipeable row keeps the navigation one line
 * tall. The scrollbar itself is hidden, and the active tab is scrolled into view (api.js).
 */
@media (max-width: 820px) {
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
            mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  }
  .tabs::-webkit-scrollbar {
    display: none;
  }
  .tab {
    flex: 0 0 auto;
    white-space: nowrap;
    scroll-snap-align: start;
  }
}

@media (max-width: 768px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    /* minmax(0, 1fr), not 1fr: see the note on .grid-2. */
    grid-template-columns: minmax(0, 1fr);
  }

  .app-header {
    flex-wrap: wrap;
    padding: var(--space-md) var(--space-base);
  }

  .app-header .header-subtitle {
    width: 100%;
    margin-left: 0;
    order: 3;
  }
}

@media (max-width: 640px) {
  .app-header {
    flex-wrap: nowrap;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
  }
  .app-header h1 {
    font-size: var(--text-sm);
    white-space: nowrap;
    min-width: 0;
  }
  /* "— Chase ACH NACHA Generator" wrapped the title onto two lines. */
  .app-header .header-title-suffix,
  .app-header .header-subtitle {
    display: none;
  }
  .header-actions {
    margin-left: auto;
    gap: var(--space-sm);
    min-width: 0;
  }
  .header-actions .header-username {
    max-width: 7rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .header-btn {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--text-xs);
    white-space: nowrap;
  }
  .toast-container {
    top: 64px;
    right: 12px;
    width: calc(100vw - 24px);
  }

  .tab {
    padding: var(--space-sm) var(--space-base);
    font-size: var(--text-xs);
    white-space: nowrap;
  }
}


/* ================================================================
   Small-screen safety net
   ================================================================ */
/*
 * ~80 rows in the dashboard are inline `display: flex` with no `flex-wrap`. Individually
 * converting each risks changing layouts that are fine; but on a narrow screen wrapping
 * is essentially always what is wanted, and not wrapping lets a row push the whole
 * document wider than the viewport so the page can be dragged sideways.
 *
 * Scoped to the app content: the header and modal internals keep their own layout.
 * Tables are excluded because they scroll inside their wrapper instead of reflowing.
 */
@media (max-width: 820px) {
  .main-container div[style*="display: flex"],
  .main-container div[style*="display:flex"] {
    flex-wrap: wrap;
  }

  /* ...except a row holding a dialog's close button: that pushed the X below the
     title. The title shrinks instead. */
  .main-container div[style*="display: flex"]:has(> [data-modal-dismiss]),
  .main-container div[style*="display:flex"]:has(> [data-modal-dismiss]) {
    flex-wrap: nowrap;
    align-items: flex-start;
  }
  .main-container div:has(> [data-modal-dismiss]) > :not([data-modal-dismiss]) {
    min-width: 0;
  }

  /* Long primary actions should use the full width rather than overflow it. */
  .main-container .btn-lg {
    width: 100%;
  }
}

/*
 * Phones: let a tall dialog scroll with the page instead of inside an 85vh box, where
 * its action buttons were cut off below the fold of a second scroll area.
 */
@media (max-width: 640px) {
  .modal-backdrop {
    align-items: flex-start;
    padding: var(--space-sm);
  }
  .modal-card {
    max-height: none;
    padding: var(--space-lg) var(--space-base);
  }
}

/*
 * Long unbroken strings — vendor emails, references — otherwise establish a wide
 * min-content width that a grid track has to honour, overflowing narrow screens.
 */
.card,
.vendor-card,
.data-table td {
  /*
   * `word-break: break-word` is deliberately NOT used here: it behaves like
   * `overflow-wrap: anywhere`, which lets a table cell's minimum width fall to one
   * character and let the Audit Trail render its columns vertically.
   */
  overflow-wrap: break-word;
}

/*
 * Very narrow screens (<=400px).
 *
 * `.btn` sets `white-space: nowrap` so labels never break mid-phrase, which is right at
 * normal widths. At 320px a label like "Upload & Parse Spreadsheet" is wider than the
 * available column and pushed the page sideways. Allow wrapping here only.
 */
@media (max-width: 400px) {
  .main-container .btn {
    white-space: normal;
    max-width: 100%;
    text-align: center;
  }
  /* Short labels never need to wrap, and breaking them split words ("Vie w"). */
  .main-container .btn-sm,
  .main-container .btn-xs,
  .main-container .btn-toggle {
    white-space: nowrap;
  }

  /* Reclaim horizontal space that padding consumes at this width. */
  .main-container {
    width: 100%;
    padding: 0 var(--space-sm);
  }
  .card {
    padding: var(--space-base);
  }
}


/* ================================================================
   Narrow screens: stack table rows instead of scrolling
   ================================================================ */
/*
 * A nine-column vendor table cannot fit a phone, and a horizontal scrollbar hides the
 * Actions column behind a gesture nobody discovers. Below 768px each row becomes a block
 * with its column name beside the value, taken from the `data-label` on each cell.
 *
 * This applies to `.stack-on-mobile` only, so tables whose columns are meant to be read
 * across (the manual payment entry grid) keep their layout.
 */
/*
 * 1100px, not 768px: these tables carry up to nine columns plus a group of row action
 * buttons, and between roughly 770px and 1100px they still could not fit and fell back to
 * a horizontal scrollbar. Stacking is more readable there than a squeezed table.
 */
@media (max-width: 1100px) {
  .stack-on-mobile thead {
    display: none;
  }
  .stack-on-mobile,
  .stack-on-mobile tbody,
  .stack-on-mobile tr,
  .stack-on-mobile td {
    display: block;
    width: 100%;
  }
  .stack-on-mobile tr {
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    padding: var(--space-sm);
    background: var(--color-surface);
  }
  /*
   * Each cell is a two-column grid: the column name on the left, the cell's content
   * stacked on the right. It used to be a space-between flex row, which laid a cell's
   * several children side by side (the Admin Review bank-details cell overlapped itself
   * and pushed the page 201px wide) and let the label shrink until it broke into letter
   * fragments ("DET AILS", "REA SON / NOT ES").
   */
  .stack-on-mobile td {
    display: grid;
    grid-template-columns: minmax(5.5rem, min(38%, 12rem)) minmax(0, 1fr);
    column-gap: var(--space-md);
    align-items: center;
    justify-items: start;
    padding: var(--space-sm) !important;
    border-bottom: 1px solid var(--color-border-light);
    text-align: left !important;
    min-width: 0;
  }
  .stack-on-mobile td > * {
    grid-column: 2;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  /* Monospaced cells are nowrap in the full table; stacked, they must wrap. */
  .stack-on-mobile td,
  .stack-on-mobile td.font-mono,
  .stack-on-mobile td .font-mono {
    white-space: normal;
  }
  /* Badges carry long action names (VENDOR_BANK_UPDATE_REJECTED) that overflowed. */
  .stack-on-mobile td .badge {
    white-space: normal;
    text-align: left;
    overflow-wrap: break-word; /* break at the <wbr> after "_" first, not mid-word */
  }
  /* Button groups keep their buttons whole and wrap as a group. */
  .stack-on-mobile td .vendor-card-actions,
  .stack-on-mobile td .history-action-group,
  .stack-on-mobile td .row-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-top: 0;
  }
  .stack-on-mobile td:last-child {
    border-bottom: none;
  }
  .stack-on-mobile td::before {
    content: attr(data-label);
    /* Row 1 only: spanning every row spread the label's height over empty tracks and
       left a blank band under one-line values. */
    grid-column: 1;
    grid-row: 1;
    align-self: start;
    padding-top: 0.15em;
    font-size: var(--text-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  /* A cell with no label (a spacer) should not reserve the label column. */
  .stack-on-mobile td:not([data-label])::before {
    content: none;
  }
  .stack-on-mobile td:not([data-label]) {
    display: block;
  }

  /*
   * A stacked table is already one column wide, so its wrapper has nothing to scroll.
   * Leaving `overflow-x: auto` on it still produced a bar, because the `::before` labels
   * contribute to scrollWidth and a pseudo-element cannot be shrunk from the DOM side.
   */
  .table-responsive:has(.stack-on-mobile),
  .payments-table-wrap:has(.stack-on-mobile) {
    overflow-x: visible;
  }

  /* Labels wrap between words only; breaking inside words produced "DET AILS". */
  .stack-on-mobile td::before {
    overflow-wrap: normal;
    word-break: normal;
  }
}


/* ================================================================
   Vendor Book
   ================================================================ */
.vendor-card-actions {
  display: flex;
  gap: var(--space-xs);
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: var(--space-md);
}
/* Cards in one grid row are equal height; keep their buttons on a common baseline
   instead of floating mid-card above a blank area. */
.vendor-card {
  display: flex;
  flex-direction: column;
}
.vendor-card > .vendor-card-actions {
  margin-top: auto;
  padding-top: var(--space-md);
}
/* In the table view the three row actions were stacked three buttons high. */
td .vendor-card-actions {
  flex-wrap: nowrap;
  margin-top: 0;
}

/* Inactive vendors are de-emphasised but stay readable. Used but never defined. */
.vendor-card.vendor-inactive {
  opacity: 0.8;
  border-color: var(--color-border-strong);
  background: var(--color-surface-alt);
}

/* A table row's action buttons stay side by side (Approve/Reject were stacked). */
.row-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-wrap: nowrap;
}

/* Admin Review: current vs requested bank details */
.bank-diff-cell div + div {
  margin-top: 2px;
}

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