/* ============================================================
   framework.css — Shared CSS framework for internal apps
   Source of truth: libs/ui-kit/ui_kit/static/framework.css
   Each app serves it from {root}/ui-kit-static/ (ui_kit.mount_static)
   ============================================================ */

/* --- Tokens ------------------------------------------------ */

:root {
  /* Surfaces */
  --bg: hsl(30 8% 98%);
  --card: hsl(30 0% 100%);
  --foreground: hsl(30 0% 10%);
  --muted-fg: hsl(24 3% 35%);
  --border: hsl(30 8% 85%);
  --border-subtle: hsl(30 6% 91%);
  --accent: hsl(20 23% 94%);
  --accent-active: hsl(20 23% 90%);
  --table-header: hsl(30 6% 96%);

  /* Brand */
  --primary: hsl(210 100% 45%);
  --primary-fg: hsl(0 0% 100%);

  /* Status */
  --green: hsl(140 50% 38%);
  --red: hsl(0 62% 53%);
  --yellow: hsl(40 90% 50%);
  --color-status-success: hsl(140 50% 38%);
  --color-status-warning: hsl(40 90% 50%);
  --color-status-danger: hsl(0 62% 53%);
  --color-status-info: hsl(210 100% 45%);
  --color-status-muted: hsl(24 3% 55%);
  /* Warning as TEXT: the warning hue is too light to read on a light page
     (about 2:1). Badges and other warning text use this instead. */
  --color-status-warning-text: hsl(32 90% 30%);
  /* Success, danger, info and muted as TEXT (badges, amounts, hints). The base
     hues above pass 3:1 for icons and fills but not 4.5:1 for text; these pass
     4.5:1 on the card, the page and the 12% tint of their badge
     (tests/test_contrast.py). */
  --color-status-success-text: hsl(140 50% 31%);
  --color-status-danger-text: hsl(0 62% 47%);
  --color-status-info-text: hsl(210 100% 40%);
  --color-status-muted-text: hsl(24 3% 40%);
  /* The purple "linked" chip (an invoice linked to another record). */
  --badge-link-bg: hsl(280 60% 92%);
  --badge-link-text: hsl(280 60% 35%);

  /* Semantic aliases */
  --color-surface-page: var(--bg);
  --color-surface-card: var(--card);
  --color-surface-input: var(--card);
  --color-border-default: var(--border);
  --color-border-focus: var(--primary);

  /* Typography scale */
  --text-2xs: 0.625rem;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;

  /* Spacing (4px base) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  /* Misc */
  --radius: 0.6rem;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', monospace;

  /* Legacy aliases. Templates and app stylesheets used these names without
     them ever being defined, so the declarations silently fell back (or
     dropped). Defined here so they follow the theme; new code should use the
     canonical tokens above. */
  --fg: var(--foreground);
  --background: var(--bg);
  --hover-bg: var(--accent);
  --muted: var(--accent);
  --bg-muted: var(--accent);
  --bg-subtle: var(--table-header);
  --bg-offset: var(--table-header);
  --surface-2: var(--table-header);
  --danger: var(--color-status-danger);
  --warning: var(--color-status-warning);
  --blue: var(--color-status-info);
}

.dark {
  color-scheme: dark;
  --bg: hsl(220 5.5% 9%);
  --card: hsl(220 5.5% 10.5%);
  --foreground: hsl(220 2% 97%);
  --muted-fg: hsl(220 4% 67%);
  --border: hsl(220 3% 17%);
  --border-subtle: hsl(220 3% 14%);
  --accent: hsl(220 5% 14%);
  --accent-active: hsl(20 12% 18%);
  --primary: hsl(210 100% 66%);
  --primary-fg: hsl(220 4% 10%);
  --table-header: hsl(220 5% 12%);
  --color-status-success: hsl(140 50% 45%);
  --color-status-warning: hsl(40 90% 55%);
  --color-status-warning-text: hsl(40 90% 60%);
  --color-status-success-text: hsl(140 50% 45%);
  --color-status-danger-text: hsl(0 62% 64%);
  --color-status-info-text: hsl(210 100% 66%);
  --color-status-muted-text: hsl(220 4% 55%);
  --badge-link-bg: hsl(280 35% 24%);
  --badge-link-text: hsl(280 70% 85%);
  --color-status-danger: hsl(0 62% 58%);
  --color-status-info: hsl(210 100% 66%);
  --color-status-muted: hsl(220 4% 55%);
}

/* --- Reset ------------------------------------------------- */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: var(--text-sm);
  line-height: 1.5;
  background: var(--bg);
  color: var(--foreground);
}
[x-cloak] { display: none !important; }

/* --- Layout ------------------------------------------------ */

.container { max-width: 1400px; margin: 0 auto; padding: 0 var(--space-5) 3rem; }

/* --- Typography -------------------------------------------- */

.mono { font-family: var(--font-mono); font-size: 0.8rem; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.clickable { cursor: pointer; }
.text-right { text-align: right; }
.icon-inline { width: 0.875rem; height: 0.875rem; vertical-align: -2px; margin-right: 0.25rem; }
.icon-inline-sm { width: 0.75rem; height: 0.75rem; vertical-align: -1px; margin-right: 0.25rem; }
.icon-btn-icon { width: 1rem; height: 1rem; margin: 0; vertical-align: middle; }
.fw-medium { font-weight: 500; }
.fw-semibold { font-weight: 600; }
.text-2xs { font-size: var(--text-2xs); }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.section-title { font-weight: 600; font-size: 0.8125rem; }
.section-label {
  font-size: 0.6875rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted-fg);
}
.text-label { font-size: 0.6875rem; color: var(--muted-fg); }

/* --- Color utilities --------------------------------------- */

.text-muted { color: var(--muted-fg); }
.text-green { color: var(--color-status-success-text); }
.text-red { color: var(--color-status-danger-text); }
.text-amber { color: hsl(35 90% 50%); }
.text-primary { color: var(--primary); }

/* --- Spacing ----------------------------------------------- */

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-6 { margin-bottom: var(--space-6); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-5 { padding: var(--space-5); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.px-5 { padding-left: var(--space-5); padding-right: var(--space-5); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); }

/* --- Flex utilities ---------------------------------------- */

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-row { display: flex; align-items: center; gap: var(--space-2); }
.flex-row-xs { display: flex; align-items: center; gap: var(--space-1); }
.flex-row-sm { display: flex; align-items: center; gap: 0.75rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-between-baseline { display: flex; justify-content: space-between; align-items: baseline; }
.items-center { align-items: center; }
.items-baseline { align-items: baseline; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.ml-auto { margin-left: auto; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.whitespace-nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Nav links -------------------------------------------- */

nav { display: flex; gap: var(--space-1); overflow-x: auto; min-width: 0; }
nav button, nav a {
  background: none; border: none; color: var(--muted-fg);
  padding: 0.4rem 0.75rem; font-size: 0.8125rem; font-weight: 500;
  border-radius: calc(var(--radius) - 2px); white-space: nowrap; cursor: pointer;
  text-decoration: none;
}
nav button:hover, nav button.active, nav a:hover, nav a.active { color: var(--foreground); background: var(--accent); }

/* --- App header (ui_kit/app_header.html) ------------------- */

.app-header {
  display: flex; align-items: center; gap: var(--space-3); min-height: 3.5rem;
  background: var(--card); padding: var(--space-2) var(--space-3) var(--space-2) var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius); margin: var(--space-4) 0;
}
.app-header-brand {
  display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0;
  padding-right: var(--space-3); border-right: 1px solid var(--border);
  color: var(--foreground); text-decoration: none;
}
.app-header-name { font-weight: 600; font-size: 0.9375rem; white-space: nowrap; }
nav.app-header-tabs { flex: 1 1 auto; flex-wrap: wrap; }
nav.app-header-tabs a.active { color: var(--primary); background: hsl(210 100% 45% / 0.1); }
.dark nav.app-header-tabs a.active { background: hsl(210 100% 66% / 0.14); }
.app-header-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.app-header-slot { display: flex; align-items: center; gap: var(--space-2); }
.app-header-menu { position: relative; }

/* App icon tiles: tinted square + coloured glyph, one hue per app. */
.app-icon {
  --app-hue: 210;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 2rem; height: 2rem; border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--app-hue) 80% 50% / 0.12); color: hsl(var(--app-hue) 70% 38%);
}
.dark .app-icon { background: hsl(var(--app-hue) 70% 60% / 0.16); color: hsl(var(--app-hue) 80% 72%); }
.app-icon svg { width: 1.0625rem; height: 1.0625rem; }
.app-icon-backoffice { --app-hue: 210; }
.app-icon-middleoffice { --app-hue: 255; }
.app-icon-dispatch { --app-hue: 160; }
.app-icon-files { --app-hue: 35; }
.app-icon-atlar { --app-hue: 10; }

.app-header-icon-btn, .app-header-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; border-radius: 999px; border: none;
  background: none; color: var(--muted-fg); cursor: pointer; font: inherit;
}
.app-header-icon-btn:hover, .app-header-icon-btn.open { background: var(--accent); color: var(--foreground); }
.app-header-icon-btn svg { width: 1.25rem; height: 1.25rem; }
.app-header-avatar {
  background: hsl(210 100% 45% / 0.12); color: var(--primary);
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.02em;
}
.dark .app-header-avatar { background: hsl(210 100% 66% / 0.16); }
.app-header-avatar:hover, .app-header-avatar.open { box-shadow: 0 0 0 2px var(--primary); }
.app-header-avatar.static { width: 2.5rem; height: 2.5rem; font-size: var(--text-sm); cursor: default; box-shadow: none; }
.app-header-icon-btn:focus-visible, .app-header-avatar:focus-visible,
.app-header-popover a:focus-visible, .app-header-popover button:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}

.app-header-popover {
  position: absolute; top: calc(100% + 0.5rem); right: 0; z-index: 1000;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 32px hsl(0 0% 0% / 0.12), 0 2px 6px hsl(0 0% 0% / 0.06);
  padding: var(--space-2);
}
.dark .app-header-popover { box-shadow: 0 12px 32px hsl(0 0% 0% / 0.5); }
.app-switcher { width: 18.5rem; }
.app-switcher-group + .app-switcher-group { margin-top: var(--space-2); }
.app-switcher-label { font-size: var(--text-xs); color: var(--muted-fg); padding: var(--space-1) var(--space-2); }
.app-switcher-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2); border-radius: calc(var(--radius) - 2px);
  color: var(--foreground); text-decoration: none;
}
a.app-switcher-item:hover { background: var(--accent); }
.app-switcher-item.current { background: hsl(210 100% 45% / 0.08); }
.dark .app-switcher-item.current { background: hsl(210 100% 66% / 0.12); }
.app-switcher-item.disabled { opacity: 0.55; cursor: default; }
.app-switcher-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.app-switcher-name { font-weight: 500; }
.app-switcher-desc { font-size: var(--text-xs); color: var(--muted-fg); }
.app-switcher-check { width: 1rem; height: 1rem; color: var(--primary); flex-shrink: 0; }
.app-switcher-footer {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: var(--space-2); padding: var(--space-3) var(--space-2) var(--space-1);
  border-top: 1px solid var(--border); color: var(--foreground); text-decoration: none;
}
.app-switcher-footer:hover { color: var(--primary); }
.app-switcher-footer svg { width: 0.9rem; height: 0.9rem; color: var(--muted-fg); }

.account-menu { width: 19rem; padding: 0; }
.account-menu-user { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4); border-bottom: 1px solid var(--border); }
.account-menu-ident { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.35; }
.account-menu-name { font-weight: 600; }
.account-menu-email { font-size: var(--text-xs); color: var(--muted-fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu-section { padding: var(--space-2) var(--space-3) var(--space-3); border-bottom: 1px solid var(--border); }
.theme-switch {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 2px;
  background: var(--accent); border-radius: calc(var(--radius) - 2px);
}
.theme-switch button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem;
  padding: 0.35rem 0.5rem; border: 1px solid transparent; border-radius: calc(var(--radius) - 4px);
  background: none; color: var(--muted-fg); font: inherit; font-size: var(--text-xs); cursor: pointer;
}
.theme-switch button:hover { color: var(--foreground); }
.theme-switch button.active { background: var(--card); color: var(--foreground); border-color: var(--border); }
.theme-switch svg { width: 0.875rem; height: 0.875rem; }
.account-menu-signout {
  display: flex; align-items: center; gap: var(--space-3); margin: var(--space-2);
  padding: var(--space-2); border-radius: calc(var(--radius) - 2px);
  color: var(--foreground); text-decoration: none;
}
.account-menu-signout:hover { background: var(--accent); }
.account-menu-signout svg { width: 1rem; height: 1rem; color: var(--muted-fg); }

/* --- Cards ------------------------------------------------- */

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card.card-overflow { overflow: visible; }
.card-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: var(--space-3); }
.card-body { padding: var(--space-4) var(--space-5); }

/* --- Tables ------------------------------------------------ */

table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.table-wrap { overflow-x: auto; }
thead { background: none; }
th { padding: 0.6rem 0.75rem; color: var(--muted-fg); font-weight: 500; font-size: var(--text-xs); letter-spacing: 0.02em; text-align: left; }
td { padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border-subtle); }
tbody > tr:hover > td { background: var(--accent); }

.alloc-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.8125rem; background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.alloc-table th { padding: 0.5rem 0.75rem; color: var(--muted-fg); font-weight: 500; font-size: var(--text-xs); text-align: left; border-bottom: 1px solid var(--border); }
.alloc-table th.text-right { text-align: right; }
.alloc-table td { padding: 0.45rem 0.75rem; border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent); }
.alloc-table tbody tr:last-child td { border-bottom: none; }

.split-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.8125rem; table-layout: fixed; }
.split-table th, .split-table td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.split-table th { font-size: 0.6875rem; text-transform: uppercase; color: var(--muted-fg); font-weight: 500; }
.split-table .col-divider { border-right: 2px solid var(--border); }
.split-table .date-row td { background: var(--accent); font-weight: 600; font-size: var(--text-xs); padding: 0.3rem 0.6rem; color: var(--muted-fg); }
.split-table .gray-fill { background: var(--accent); }
.split-table .cell-trunc { max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.split-table .cell-trunc > i { flex-shrink: 0; }
.split-table > tbody.dimmed { color: var(--muted-fg); }
.split-table > tbody.auto-matched { background: repeating-linear-gradient(-45deg, transparent, transparent 4px, hsl(270 50% 60% / 0.07) 4px, hsl(270 50% 60% / 0.07) 8px); }
.split-table > tbody.auto-matched > tr:hover { background-color: hsl(270 50% 60% / 0.04); }

/* State-pending: diagonal stripes for pending/locked/test states */
.state-pending { background: repeating-linear-gradient(-45deg, transparent, transparent 4px, hsl(270 50% 60% / 0.07) 4px, hsl(270 50% 60% / 0.07) 8px) !important; }
tr.state-pending > td { background: repeating-linear-gradient(-45deg, transparent, transparent 4px, hsl(270 50% 60% / 0.07) 4px, hsl(270 50% 60% / 0.07) 8px); }
tr.state-pending:hover > td { background: hsl(270 50% 60% / 0.04) !important; }
.modal-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,0.12); padding: 1rem; }
.modal-actions { display: flex; align-items: center; gap: var(--space-2); justify-content: flex-end; }
.split-table > tbody > tr:hover > td { background: transparent; }
.split-table > tbody > tr:hover { background-color: var(--accent); }
.split-table .btn-sm { padding-top: 0.18rem; padding-bottom: 0.18rem; }

/* --- Badges ------------------------------------------------ */

.badge {
  display: inline-flex; align-items: center; padding: 0.125rem 0.5rem;
  border-radius: 9999px; font-size: 0.6875rem; font-weight: 600;
}
.badge-success { background: hsl(140 50% 38% / 0.12); color: var(--color-status-success-text); }
.badge-warning { background: hsl(40 90% 50% / 0.14); color: var(--color-status-warning-text); }
.badge-danger { background: hsl(0 62% 53% / 0.12); color: var(--color-status-danger-text); }
.badge-info { background: hsl(210 100% 45% / 0.12); color: var(--color-status-info-text); }
.badge-muted { background: hsl(24 3% 35% / 0.12); color: var(--color-status-muted-text); }

/* --- Buttons ----------------------------------------------- */

.btn {
  padding: 0.4rem 0.85rem; border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border); background: var(--card);
  font-size: 0.8125rem; font-weight: 500; cursor: pointer;
  color: var(--foreground); text-decoration: none; display: inline-flex; align-items: center; gap: var(--space-2);
}
.btn:hover { background: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: none; }
.btn-primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn-primary:hover { background: hsl(210 100% 55%); border-color: hsl(210 100% 55%); }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--foreground); }
.btn-secondary:hover { background: var(--accent); }
.btn-danger { background: var(--color-status-danger); color: #fff; border-color: var(--color-status-danger); }
.btn-danger:hover { background: hsl(0 62% 63%); border-color: hsl(0 62% 63%); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: var(--text-xs); }

/* --- Forms ------------------------------------------------- */

.form-group { margin-bottom: var(--space-3); }
.form-group label { display: block; font-size: var(--text-xs); font-weight: 500; color: var(--muted-fg); margin-bottom: var(--space-1); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.4rem 0.6rem; border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px); background: var(--card);
  font-size: 0.8125rem; color: var(--foreground); line-height: 1.4;
}
/* One chevron and one gap for every standalone select (form, filter bar, ad hoc).
   The mid-grey fill reads on both the light and the dark card. */
.form-group select, .ui-filter-field select, .ui-select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a8a8a' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.5rem center; padding-right: 1.75rem;
  text-overflow: ellipsis;
}
.ui-select {
  padding: 0.25rem 1.75rem 0.25rem 0.5rem; font-size: var(--text-xs);
  border: 1px solid var(--border); border-radius: var(--radius);
  background-color: var(--card); color: var(--foreground);
}
.form-group input:focus, .form-group select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.form-row { display: flex; gap: var(--space-3); }
.form-row > .form-group { flex: 1; }
.form-row > .form-actions { padding-top: 1.3rem; margin-bottom: var(--space-3); }

/* --- Stats ------------------------------------------------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-6); }
.stat-value { font-size: var(--text-2xl); font-weight: 600; }
.stat-label { font-size: 0.6875rem; color: var(--muted-fg); text-transform: uppercase; letter-spacing: 0.05em; }

/* --- KPI cards --------------------------------------------- */

.kpi-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-2) var(--space-3); min-width: 100px; }
.kpi-label { font-size: 0.6875rem; color: var(--muted-fg); font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-size: var(--text-lg); font-weight: 600; font-family: var(--font-mono); margin-top: 0.15rem; }

/* --- Progress bars ----------------------------------------- */

.progress-inline { height: 4px; border-radius: 9999px; background: var(--color-border-default); overflow: hidden; }
.progress-inline-fill { height: 100%; border-radius: 9999px; }
.progress-success { background: var(--color-status-success); }
.progress-warning { background: var(--color-status-warning); }
.progress-danger { background: var(--color-status-danger); }

/* --- Row state accents (4px left border) ------------------- */
tr.row-done { border-left: 4px solid var(--color-status-success); }
tr.row-skipped { border-left: 4px solid var(--color-status-warning); }
tr.row-danger { border-left: 4px solid var(--color-status-danger); }
tr.row-done > td:first-of-type,
tr.row-skipped > td:first-of-type,
tr.row-danger > td:first-of-type { padding-left: calc(0.75rem - 2px); }

/* --- Match proximity glow ---------------------------------- */
.match-exact { color: var(--color-status-success-text); text-shadow: 0 0 6px var(--color-status-success); }
.match-close { color: var(--color-status-success-text); text-shadow: 0 0 4px color-mix(in srgb, var(--color-status-success) 50%, transparent); }

/* --- Invoice reference styling by financing status --- */
.ref-financed { color: var(--primary); text-shadow: 0 0 6px color-mix(in srgb, var(--primary) 30%, transparent); cursor: pointer; }
.ref-plain { color: color-mix(in srgb, var(--primary) 40%, var(--muted-fg)); cursor: pointer; }
.match-near  { color: var(--color-status-warning-text); text-shadow: 0 0 3px color-mix(in srgb, var(--color-status-warning) 40%, transparent); }
.highlight-glow { animation: amber-pulse 2s ease-in-out; }
@keyframes amber-pulse {
  0%, 100% { background: transparent; }
  15%, 60% { background: hsl(35 90% 50% / 0.15); box-shadow: inset 0 0 0 1px hsl(35 90% 50% / 0.3); }
}

/* --- Inner cards (nested content blocks) ------------------- */

.inner-card {
  background: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  margin-bottom: var(--space-2);
  overflow: hidden;
}
.inner-card-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-fg);
  margin-bottom: 0.35rem;
}
.inner-card-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin: -0.6rem -0.75rem 0.5rem;
  border-radius: 6px 6px 0 0;
  overflow: visible;
}
.inner-card-tab {
  flex: 1;
  text-align: center;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-fg);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  background: var(--background);
  border: none;
  border-right: 1px solid var(--border);
  position: relative;
}
.inner-card-tab:last-child { border-right: none; }
.inner-card-tab.active {
  background: var(--accent);
  color: var(--foreground);
  margin-bottom: -1px;
  border-bottom: 1px solid var(--accent);
}
.inner-card-tab:disabled { opacity: 0.4; cursor: not-allowed; }
.inner-card table { font-size: 0.8125rem; width: calc(100% + 1.5rem); margin: 0 -0.75rem -0.75rem; }
.inner-card table tr:last-child td { border-bottom: none; }
.inner-card table tr:last-child td:first-child { border-bottom-left-radius: 5px; }
.inner-card table tr:last-child td:last-child { border-bottom-right-radius: 5px; }
.inner-card th { font-size: 0.6875rem; }
.inner-card th:first-child, .inner-card td:first-child { padding-left: 0.75rem; }
.inner-card th:last-child, .inner-card td:last-child { padding-right: 0.75rem; }

.inner-card-filter {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.3rem 0.5rem;
  margin-bottom: 0.5rem;
}
.inner-card-filter input[type="search"],
.inner-card-filter input[type="text"] {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.75rem;
  min-width: 0;
  padding: 0.15rem 0.25rem;
}
.inner-card-filter select {
  border: none;
  background: transparent;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--muted-fg);
  cursor: pointer;
  padding: 0.15rem 0.25rem;
}

/* --- Sortable table headers -------------------------------- */

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable::after {
  content: '▾';
  display: inline-block;
  width: 0.75em;
  text-align: center;
  margin-left: 0.2em;
  color: var(--border);
  font-size: 0.75em;
}
th.sortable.sort-asc::after { content: '▲'; color: var(--primary); }
th.sortable.sort-desc::after { content: '▼'; color: var(--primary); }
/* The real control inside a sortable header: a button that looks like the header text. */
.th-sort { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: inherit; }

/* --- Sidebar cards (aliases) ------------------------------- */

.sidebar-card { background: var(--accent); border: 1px solid var(--border); border-radius: 6px; padding: 0.6rem 0.75rem; margin-bottom: var(--space-2); overflow: hidden; }
.sidebar-card-label { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted-fg); margin-bottom: 0.35rem; }
.sidebar-card table { font-size: 0.75rem; width: calc(100% + 1.5rem); margin: 0 -0.75rem -0.75rem; }
.sidebar-card table tr:last-child td { border-bottom: none; }
.sidebar-card table tr:last-child td:first-child { border-bottom-left-radius: 5px; }
.sidebar-card table tr:last-child td:last-child { border-bottom-right-radius: 5px; }
.sidebar-card table th:first-child, .sidebar-card table td:first-child { padding-left: 0.75rem; }
.sidebar-card table th:last-child, .sidebar-card table td:last-child { padding-right: 0.75rem; }

.sidebar-invoice-card { border: 1px solid var(--border); border-radius: 5px; padding: 0.5rem 0.65rem; margin-bottom: 0.4rem; background: var(--card); }
.sidebar-invoice-card.overdue { border-color: var(--red); }

/* --- Timeline ---------------------------------------------- */

.tl-event { border-left: 4px solid var(--border); padding: 0.4rem 0 0.4rem 0.6rem; margin-left: -0.75rem; }
.tl-event:last-child { padding-bottom: 0; }
.tl-border-trade { border-left-color: var(--primary); }
.tl-border-payment { border-left-color: var(--green); }
.tl-border-adjustment { border-left-color: hsl(35 90% 50%); }
.tl-border-skip { border-left-color: var(--red); }
.tl-border-report { border-left-color: var(--muted-fg); }
.tl-border-credit_note { border-left-color: hsl(280 60% 55%); }
.tl-border-maturity { border-left-color: hsl(200 70% 50%); }
.tl-border-cancelled { border-left-color: var(--red); }
.tl-row { display: flex; align-items: baseline; gap: 0.5rem; font-size: 0.8125rem; }
.tl-row.tl-expandable { cursor: pointer; }
.tl-row.tl-expandable:hover { background: var(--accent); margin: -0.2rem -0.4rem; padding: 0.2rem 0.4rem; border-radius: 3px; }
.tl-collapsed { cursor: pointer; display: flex; align-items: baseline; gap: 0.4rem; font-size: 0.8125rem; }
.tl-collapsed:hover { background: var(--accent); margin: -0.2rem -0.4rem; padding: 0.2rem 0.4rem; border-radius: 3px; }
.tl-icon { flex-shrink: 0; width: 14px; display: flex; align-items: center; }
.tl-date { flex-shrink: 0; }
.tl-gap { padding-top: 0.8rem; }
.tl-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-amount { margin-left: auto; flex-shrink: 0; }
.tl-amount-neg { color: var(--color-status-danger-text); }
.tl-milestone .tl-label { font-weight: 600; }
.tl-operational { font-size: 0.75rem; color: var(--muted-fg); }
.tl-detail { padding: 0.4rem 0 0.2rem 1.6em; font-size: 0.8125rem; }
.tl-detail-grid { display: grid; grid-template-columns: 5.5rem 1fr; row-gap: 0.15rem; }

/* --- Invoice progress bar ---------------------------------- */
.inv-bar-container { display: flex; height: 1.5rem; border-radius: 6px; overflow: hidden; background: var(--border-subtle); }
.inv-bar + .inv-bar { border-left: 1px solid rgba(255,255,255,0.3); }
.inv-bar { height: 100%; transition: opacity 0.2s, filter 0.15s; cursor: default; }
.inv-bar:hover { filter: brightness(1.2); }
.inv-bar-advance, .inv-bar-advance-filled { background: var(--primary); }
.inv-bar-residual, .inv-bar-residual-filled { background: var(--green); }
.inv-bar-fees, .inv-bar-fees-filled { background: hsl(35 90% 50%); }
.inv-bar-credit-overlay { height: 1.5rem; margin-top: -1.5rem; border-radius: 6px; background: repeating-linear-gradient(135deg, hsl(280 60% 55% / 0.4), hsl(280 60% 55% / 0.4) 2px, transparent 2px, transparent 4px); pointer-events: none; }

/* --- Picker modal ------------------------------------------ */

.picker-overlay { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.35); }
.picker-modal { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); width: 750px; max-width: 92vw; max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
.picker-modal > div:last-of-type { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.picker-modal > div:last-of-type > div:last-of-type { flex: 1; overflow-y: auto; min-height: 0; }
.picker-modal .picker-scroll-section { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.picker-modal .picker-scroll-section > div:last-of-type { flex: 1; overflow-y: auto; min-height: 0; }
.picker-modal > div:last-of-type > div:last-of-type thead { position: sticky; top: 0; z-index: 1; background: var(--card); }
.picker-summary { border-bottom: 1px solid var(--border); font-size: 0.8125rem; flex-shrink: 0; }
.picker-summary table { width: 100%; }
.picker-summary th { padding: 0.3rem 0.75rem 0; }
.picker-summary td { padding: 0.3rem 0.75rem 0.4rem; }
.picker-summary td:nth-child(3), .picker-summary td:nth-child(4),
.picker-summary th:nth-child(3), .picker-summary th:nth-child(4) { width: 6.5rem; white-space: nowrap; }
.picker-summary td:first-child, .picker-summary th:first-child { width: 25%; max-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-summary tr:hover > td { background: transparent; }

/* --- Slide panel ------------------------------------------- */

.slide-panel {
  position: fixed; top: 0; right: 0; width: 560px; max-width: 100vw; height: 100vh;
  background: var(--card); border-left: 1px solid var(--border); z-index: 60;
  box-shadow: -4px 0 24px rgba(0,0,0,0.15); overflow-y: auto; padding: var(--space-6);
}
.slide-backdrop { position: fixed; inset: 0; z-index: 50; }

/* --- Action bar / Filter bar ------------------------------- */

.action-bar { padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); display: flex; align-items: center; gap: var(--space-4); }
.filter-bar { padding: var(--space-2) var(--space-5); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: var(--space-2); }
.input-filter { padding: 0.25rem 0.5rem; font-size: var(--text-xs); border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px); background: var(--card); color: var(--foreground); }

/* --- Icon button ------------------------------------------- */

.icon-btn { background: none; border: none; cursor: pointer; color: var(--muted-fg); padding: 0.2rem; line-height: 1; font-size: 1rem; border-radius: 3px; vertical-align: middle; min-width: 1.25rem; text-align: center; }
.icon-btn.icon-btn-sm { font-size: 0.75rem; min-width: 1rem; }
.icon-btn.small { font-size: 0.85rem; }
.icon-btn:hover { color: var(--foreground); background: var(--accent); }
.add-invoice-btn { color: var(--muted-fg); font-size: var(--text-sm); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; width: 1.5rem; height: 1.5rem; border-radius: 50%; border: 1px dashed var(--border); }
.add-invoice-btn:hover { color: var(--primary); border-color: var(--primary); }
.add-more-btn { font-size: 0.6875rem; color: var(--muted-fg); cursor: pointer; opacity: 0.6; display: inline-flex; align-items: center; gap: 0.2rem; margin-top: 0.15rem; }
.add-more-btn:hover { opacity: 1; color: var(--primary); }

/* --- Interactive link -------------------------------------- */

.link-primary { cursor: pointer; color: var(--primary); text-decoration: none; }
.link-primary:hover { text-decoration: underline; }
.link-credit { cursor: pointer; color: var(--color-status-danger-text); text-decoration: none; }
.link-credit:hover { text-decoration: underline; }
.badge-credit { background: hsl(0 62% 53% / 0.1); color: var(--color-status-danger-text); }

/* --- Dropzone ---------------------------------------------- */

.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-1); padding: var(--space-4) var(--space-6); border: 2px dashed var(--border); border-radius: var(--radius); cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.dropzone > * { pointer-events: none; }
.dropzone > input { pointer-events: auto; }
.dropzone:focus-within { outline: 2px solid var(--color-border-focus); outline-offset: 2px; border-color: var(--primary); }
.dropzone-active { border-color: var(--primary); background: hsl(210 100% 50% / 0.04); }
.dropzone-done { border-color: var(--color-status-success); background: hsl(140 50% 38% / 0.04); }

/* --- Currency tabs ----------------------------------------- */

.ccy-tab { all: unset; display: flex; align-items: center; gap: 0.4rem; padding: 0 var(--space-6); border-left: 1px solid var(--border); cursor: pointer; font-size: 0.8125rem; font-weight: 500; transition: background 0.15s; }
.ccy-tab:hover { background: var(--accent); }
.ccy-tab-active { background: var(--accent-active); }
.ccy-tab-active:hover { background: var(--accent-active); filter: brightness(0.97); }
.ccy-tab-group { margin-left: auto; display: flex; }
.card-header-tabs { padding: 0; align-items: stretch; }
.card-header-title { padding: 0.6rem 1.25rem; }
.badge-dot { min-width: 1.25rem; text-align: center; }

.pill-tab { all: unset; display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.25rem 0.625rem; border-radius: 999px; border: 1px solid var(--border); cursor: pointer; font-size: 0.75rem; font-weight: 500; color: var(--muted-fg); transition: all 0.15s; margin-right: 0.25rem; }
.pill-tab:last-child { margin-right: 0; }
.pill-tab:hover { background: var(--accent); color: var(--fg); }
.pill-tab-active { background: var(--accent-active); color: var(--fg); border-color: var(--primary, #3b82f6); }

/* --- Dots / indicators ------------------------------------- */

.dot-red, .dot-amber { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; }
.dot-red { background: var(--red); }
.dot-amber { background: hsl(35 90% 50%); }

/* --- Expand panel ------------------------------------------ */

.expand-panel { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); background: var(--bg); }
.chevron { width: 1rem; height: 1rem; transition: transform 0.15s; display: inline-block; color: var(--muted-fg); }
.chevron-cell { width: 1.5rem; padding-left: 0.75rem; }
tr.detail-row:hover > td, tr.detail-row:hover { background: transparent !important; }

/* --- Toast ------------------------------------------------- */

.toast-container { position: fixed; bottom: var(--space-4); right: var(--space-4); z-index: 100; display: flex; flex-direction: column-reverse; gap: var(--space-2); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: start; gap: var(--space-2);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius); background: var(--card);
  border: 1px solid var(--border); box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  font-size: 0.8125rem; max-width: 360px; animation: toastIn 0.25s ease-out;
}
.toast-msg { flex: 1; }
.toast-close { background: none; border: none; color: var(--muted-fg); cursor: pointer; padding: 0; font-size: 1rem; line-height: 1; }
.toast-close:hover { color: var(--foreground); }
.toast-success { border-left: 3px solid var(--green); }
.toast-error { border-left: 3px solid var(--red); }
.toast.removing { animation: toastOut 0.2s ease-in forwards; }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }

/* --- PDF Preview Modal -------------------------------------- */
.pdf-modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.pdf-modal-content { width: 100%; max-width: 56rem; height: 90vh; display: flex; flex-direction: column; background: var(--bg); border-radius: var(--radius); overflow: hidden; box-shadow: 0 12px 40px rgba(0,0,0,0.2); }
.pdf-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.pdf-modal-frame { flex: 1; border: none; width: 100%; }

/* --- Claim row (sidebar) ----------------------------------- */
.claim-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0; }
.claim-voided { opacity: 0.4; }

/* --- Transitions (Alpine.js) ------------------------------- */

.transition { transition-property: transform; }
.ease-out { transition-timing-function: ease-out; }
.ease-in { transition-timing-function: ease-in; }
.duration-200 { transition-duration: 200ms; }
.duration-150 { transition-duration: 150ms; }
.translate-x-full { transform: translateX(100%); }
.translate-x-0 { transform: translateX(0); }

/* --- Inbox / split-panel layout ----------------------------- */

.inbox-layout {
  display: flex;
  height: calc(100vh - 5.5rem);
  margin: 0 calc(-1 * var(--space-5)) -3rem;
  overflow: hidden;
}
.inbox-list {
  width: 280px;
  min-width: 280px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.inbox-item {
  padding: var(--space-2) var(--space-5);
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
}
.inbox-item:hover { background: var(--accent); }
.inbox-item-active {
  background: var(--accent);
  border-left: 3px solid var(--primary);
  padding-left: calc(var(--space-5) - 3px);
}
.inbox-item-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--foreground);
}
.inbox-item-meta {
  margin-top: var(--space-1);
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
}
.inbox-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
  padding: 1.5rem;
}
.inbox-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted-fg);
  font-size: var(--text-sm);
}
.inbox-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.inbox-header-title {
  font-size: var(--text-base);
  font-weight: 600;
}
.inbox-header-meta {
  margin-top: var(--space-2);
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.inbox-content {
  flex: 1;
  overflow: hidden;
}

/* Legacy aliases */
.parties-layout { display: flex; height: calc(100vh - 5.5rem); margin: 0 calc(-1 * var(--space-5)) -3rem; }
.party-list-item { padding: var(--space-2) var(--space-5); cursor: pointer; border-bottom: 1px solid var(--border-subtle); }
.party-list-item:hover { background: var(--accent); }
.party-list-item-active { background: var(--accent); border-left: 3px solid var(--primary); padding-left: calc(var(--space-5) - 3px); }

/* --- Login page -------------------------------------------- */

.login-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem; width: 100%; max-width: 380px; text-align: center; }
.login-card h1 { font-size: var(--text-xl); font-weight: 600; margin-bottom: var(--space-1); }
.login-card p { color: var(--muted-fg); font-size: 0.8125rem; margin-bottom: var(--space-6); }
.btn-google { display: inline-flex; align-items: center; gap: 0.6rem; padding: 0.6rem var(--space-5); border-radius: calc(var(--radius) - 2px); border: 1px solid var(--border); background: var(--card); font-size: var(--text-sm); font-weight: 500; cursor: pointer; color: var(--foreground); text-decoration: none; }
.btn-google:hover { background: var(--accent); }
.btn-google svg { width: 1.125rem; height: 1.125rem; }
.error { margin-top: var(--space-4); padding: var(--space-2) var(--space-3); border-radius: calc(var(--radius) - 2px); background: hsl(0 62% 53% / 0.08); color: var(--color-status-danger-text); font-size: 0.8125rem; }

/* --- Responsive -------------------------------------------- */

@media (max-width: 768px) {
  .container { padding: 0 var(--space-2) 3rem; }
  .app-header { flex-wrap: wrap; }
  nav { width: 100%; overflow-x: auto; }
  nav.app-header-tabs { order: 3; flex-wrap: nowrap; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  th, td { padding: 0.4rem 0.5rem; }
}

/* Spinner */
.spinner { display: inline-block; width: 0.75rem; height: 0.75rem; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Segmented button group */
.btn-group { position: relative; display: inline-flex; }
.btn-group > .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-group > .btn-split { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 1px solid var(--border); padding: 0.25rem 0.4rem; }
.btn-group > .btn-split:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-group .dropdown-item { cursor: pointer; }
.btn-group .dropdown-item:hover:not(.disabled) { background: var(--hover-bg, hsl(0 0% 95%)); }
.btn-group .dropdown-item.disabled { opacity: 0.5; cursor: not-allowed; }

/* Pagination control (segmented buttons) */
.pagination-wrap { padding: 0.75rem 1rem; text-align: center; border-top: 1px solid var(--border); }
.pagination-control { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.pg-btn { display: flex; align-items: center; justify-content: center; min-width: 2rem; padding: 0.3rem 0.5rem; font-size: var(--text-xs); color: var(--fg); background: var(--bg); text-decoration: none; cursor: pointer; border-right: 1px solid var(--border); user-select: none; }
.pg-btn:last-child { border-right: none; }
.pg-btn:hover:not(.pg-active):not(.pg-disabled):not(.pg-ellipsis) { background: var(--accent); }
.pg-active { background: var(--primary); color: #fff; font-weight: 600; cursor: default; }
.pg-disabled { opacity: 0.35; cursor: default; pointer-events: none; }
.pg-ellipsis { cursor: default; color: var(--muted-fg); min-width: 1.5rem; padding: 0.3rem 0.25rem; }
.pg-prev, .pg-next { font-weight: 600; }
button.pg-btn { font-family: inherit; border: 0; border-right: 1px solid var(--border); }
button.pg-btn:last-child { border-right: none; }

/* Tab attention dot */
.tab-dot-wrap { position: relative; }
.tab-dot { position: absolute; top: 2px; right: 2px; width: 6px; height: 6px; background: var(--red); border-radius: 50%; }

/* Inline spinner */
.spinner-sm { display: inline-block; width: 0.75rem; height: 0.75rem; border: 2px solid var(--border); border-top-color: var(--primary, #333); border-radius: 50%; animation: spin 0.6s linear infinite; }

/* Reports table: striped test/voided rows */
.reports-table tr.report-test { background: repeating-linear-gradient(-45deg, transparent, transparent 4px, hsl(270 50% 60% / 0.07) 4px, hsl(270 50% 60% / 0.07) 8px); }
.reports-table tr.report-voided { opacity: 0.5; text-decoration: line-through; }

/* Delivery icons */
.delivery-icons { display: flex; gap: 0.25rem; align-items: center; }
.delivery-icon { display: inline-flex; align-items: center; text-decoration: none; border-radius: 3px; padding: 2px; transition: background 0.1s; }
.delivery-icon:hover { background: var(--hover-bg, hsl(0 0% 93%)); }
.delivery-icon.delivered { color: hsl(145 60% 40%); }
.delivery-icon.failed { color: hsl(15 80% 50%); }

/* --- Combobox (filterable dropdown) ------------------------ */
.combobox { position: relative; }
.combobox-input {
  width: 100%; padding: 0.4rem 0.6rem; border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px); background: var(--card);
  font-size: 0.8125rem; color: var(--foreground); line-height: 1.4;
}
.combobox-input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.combobox-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 30;
  margin-top: 2px; max-height: 12rem; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.combobox-option {
  padding: 0.35rem 0.6rem; font-size: 0.8125rem; cursor: pointer;
}
.combobox-option:hover, .combobox-option.active { background: var(--accent); }
.combobox-empty { padding: 0.5rem 0.6rem; font-size: 0.75rem; color: var(--muted-fg); }

/* --- Staging environment banner ---------------------------- */
.staging-banner {
  position: sticky; top: 0; z-index: 9999;
  width: 100%; padding: 4px 0; margin: 0;
  background: var(--color-status-warning, #f59e0b);
  color: #000; text-align: center;
  font-weight: 600; font-size: 0.75rem;
}

/* --- Notice bar -------------------------------------------- */
.notice { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-4); border-radius: var(--radius); border: 1px solid var(--border); background: var(--card); cursor: pointer; }
.notice:hover { background: var(--accent); }
.notice-warn { border-color: hsl(40 90% 50% / 0.4); background: hsl(40 90% 50% / 0.06); }
.notice-warn:hover { background: hsl(40 90% 50% / 0.1); }

/* --- Global search ----------------------------------------- */
.search-filters { display: flex; gap: 0.375rem; margin-top: 0.5rem; flex-wrap: wrap; }
.search-pill { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.2rem 0.5rem; font-size: 0.6875rem; border: 1px solid var(--border); border-radius: 999px; background: var(--bg); color: var(--muted-fg); cursor: pointer; font-weight: 500; }
.search-pill:hover { border-color: var(--primary); color: var(--primary); }
.search-pill-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.search-pill-active:hover { background: var(--primary); color: #fff; }
.search-results { padding: 0.25rem 0; }
.search-result-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1.25rem; cursor: pointer; width: 100%; border: 0; background: none; font: inherit; color: inherit; text-align: left; }
.search-result-row:hover { background: var(--accent); }
.search-result-icon { flex-shrink: 0; color: var(--muted-fg); display: flex; }
.search-result-title { font-weight: 500; font-size: 0.8125rem; min-width: 0; flex: 1 1 auto; }
.search-result-sub { color: var(--muted-fg); font-size: 0.75rem; margin-left: auto; max-width: 45%; flex: 0 1 auto; }

/* Recent search history (client-side, localStorage) */
.search-recent { padding: 0.25rem 0 0.5rem; }
.search-recent-head { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 1.25rem 0.25rem; }
.search-recent-label { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted-fg); }
.search-recent-clear { border: none; background: none; padding: 0; font-size: 0.6875rem; color: var(--muted-fg); cursor: pointer; font-weight: 500; }
.search-recent-clear:hover { color: var(--primary); }
.search-recent-row .search-result-icon { color: var(--muted-fg); opacity: 0.7; }

/* --- Transaction highlight --------------------------------- */
@keyframes tx-highlight-fade { from { background: hsl(45 100% 90%); } to { background: transparent; } }
.tx-highlighted { animation: tx-highlight-fade 3s ease-out forwards; }
.tx-highlighted tr { background: inherit !important; }

/* Report preview modal */
.report-preview { font-size: 0.8125rem; }
.report-preview-header { padding: 1rem 1.25rem; border-bottom: 2px solid var(--border); }
.report-preview-header dl { display: grid; grid-template-columns: auto 1fr; gap: 0.2rem 1.5rem; margin: 0; }
.report-preview-header dt { padding: 0.15rem 0; }
.report-preview-header dd { padding: 0.15rem 0; margin: 0; }
.report-preview-section { margin-top: 1rem; }
.report-preview-section-label { padding: 0.5rem 1.25rem; position: sticky; top: 0; background: var(--bg); z-index: 2; border-bottom: 1px solid var(--border); }
.report-preview table { font-size: 0.8125rem; width: 100%; }
.report-preview th, .report-preview td { padding: 0.4rem 0.75rem; border: none; }
.report-preview .totals-row { font-weight: 600; border-top: 2px solid var(--border); }
.report-preview .empty-section { padding: 0.75rem 1.25rem; margin: 0; }

/* --- Picker utilities -------------------------------------- */

.picker-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.picker-tab-bar { padding: 0.5rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; gap: 0.375rem; align-items: center; }
.picker-search-wrap { padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border); position: relative; display: flex; align-items: center; gap: 0.5rem; }
.picker-type-filter { display: flex; flex-shrink: 0; order: 1; }
.picker-type-btn { display: flex; align-items: center; justify-content: center; width: 2rem; height: 2.125rem; border: 1px solid var(--border); background: var(--card); color: var(--muted-fg); cursor: pointer; padding: 0; }
.picker-type-btn:first-child { border-radius: calc(var(--radius) - 2px) 0 0 calc(var(--radius) - 2px); }
.picker-type-btn:last-child { border-left: none; border-radius: 0 calc(var(--radius) - 2px) calc(var(--radius) - 2px) 0; }
.picker-type-btn-active { background: var(--accent-active, hsl(220 14% 90%)); color: var(--primary); }
.picker-type-btn-credit-active { background: var(--accent-active, hsl(220 14% 90%)); color: var(--color-status-danger-text); }
.picker-search-input { flex: 1; padding: 0.5rem 2rem 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px); font-size: 0.875rem; width: 100%; }
.picker-search-field { position: relative; flex: 1; }
.picker-search-clear { position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: var(--muted-fg); font-size: 1rem; line-height: 1; }
.picker-results-scroll { overflow-y: auto; flex: 1; padding: 0; }
.picker-suggestion-scroll { overflow-y: auto; flex: 1; display: flex; flex-direction: column; }
.picker-suggestion-footer { padding: 0.75rem; margin-top: auto; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 1rem; }
.picker-reasoning { font-style: italic; color: var(--muted-fg); font-size: 0.75rem; margin: 0; flex: 1; }
.picker-empty { text-align: center; padding: 1.5rem; }
.picker-action-cell { min-width: 140px; text-align: right; }
.picker-action-inner { display: flex; justify-content: flex-end; }
.split-table td { min-height: 1.625rem; }
.picker-inline-input { width: 80px; padding: 0.2rem 0.4rem; font-size: 0.75rem; }
.icon-xs { width: 0.8rem; height: 0.8rem; }
.tab-divider { width: 1px; height: 1rem; background: var(--border); margin: 0 0.25rem; }
.badge-link { font-size: 0.625rem; background: var(--badge-link-bg); color: var(--badge-link-text); padding: 0.1rem 0.3rem; border-radius: 3px; }
.badge-link-voided { font-size: 0.625rem; background: var(--accent); color: var(--muted-fg); padding: 0.1rem 0.3rem; border-radius: 3px; text-decoration: line-through; }
.btn-2xs { padding: 0.2rem 0.4rem; font-size: 0.7rem; }
.flex-end { justify-content: flex-end; }
.clickable-label { cursor: pointer; }

/* Sidebar shared */
.sidebar-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 0.75rem; }
.sidebar-section-title { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted-fg); margin-bottom: 0.5rem; padding-bottom: 0.25rem; border-bottom: 1px solid var(--border); }
.sidebar-data-row { display: flex; justify-content: space-between; font-size: 0.8125rem; padding: 0.15rem 0; }
.sidebar-title-group { display: flex; align-items: center; gap: 0.5rem; }
.sidebar-padding { padding: 1.25rem; }
.sidebar-stat-row { display: flex; gap: 1.5rem; }
.contents { display: contents; }

/* Exposure widget */
.exposure-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin-top: 0.25rem; display: flex; }
.exposure-bar-current { background: var(--primary); height: 100%; }
.exposure-bar-overdue { background: var(--color-status-danger); height: 100%; }
.exposure-party { margin-top: 0.5rem; }
.exposure-party-header { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.75rem; }
.exposure-party-name { font-weight: 500; }
.exposure-party-role { color: var(--muted-fg); font-size: 0.6875rem; }

/* Mini calendar */
.inv-cal { width: 100%; }
.inv-cal-header { font-size: 0.6rem; font-weight: 600; text-align: center; color: var(--muted-fg); margin-bottom: 0.25rem; text-transform: uppercase; letter-spacing: 0.04em; display: grid; grid-template-columns: 1rem 1fr 1rem; align-items: center; }
.inv-cal-nav { cursor: pointer; color: var(--primary); font-size: 0.75rem; font-weight: 700; user-select: none; text-align: center; }
.inv-cal-nav:hover { opacity: 0.7; }
.inv-cal-nav-off { visibility: hidden; }
.inv-cal-days { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 0.5rem; font-weight: 600; color: var(--muted-fg); margin-bottom: 0.15rem; }
.inv-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 0.6rem; line-height: 1.8; }
.inv-cal-cell { position: relative; border-radius: 2px; }
.inv-cal-active { background: color-mix(in srgb, var(--primary) 15%, transparent); }
.inv-cal-today { font-weight: 700; }
.inv-cal-today::after { content: ''; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 4px; height: 2px; border-radius: 2px; background: var(--primary); }
.inv-cal-maturity { color: #fff; background: var(--primary); border-radius: 3px; box-shadow: 0 2px 6px -1px color-mix(in srgb, var(--primary) 50%, transparent); }
.inv-cal-maturity-overdue { color: var(--color-status-danger-text); border-radius: 3px; box-shadow: inset 0 0 0 1.5px var(--red); font-weight: 700; }
.inv-cal-trade { font-weight: 700; border: 1px solid var(--primary); border-radius: 3px; }
.inv-cal-reminder { box-shadow: inset 0 0 0 1.5px var(--red); border-radius: 3px; color: var(--color-status-danger-text); font-weight: 600; }
.inv-cal-reminder-fired { background: var(--red); color: #fff; border-radius: 3px; font-weight: 600; }
.inv-cal-overdue { background: color-mix(in srgb, var(--red) 10%, transparent); }
.inv-cal-collection { box-shadow: inset 0 0 0 1.5px var(--muted-fg); border-radius: 3px; font-weight: 600; }
.inv-cal-collection-fired { background: var(--muted-fg); color: #fff; border-radius: 3px; font-weight: 600; }

/* Invoice sidebar shared */
.inv-copyable { cursor: pointer; border-radius: 2px; padding: 0 0.15rem; }
.inv-copyable:hover { background: var(--accent); }
.inv-pending-note { font-size: 0.75rem; color: var(--muted-fg); margin-bottom: 0.5rem; }
.inv-summary { display: flex; justify-content: space-between; margin-top: 0.4rem; font-size: 0.75rem; }
.inv-amount-row { display: flex; gap: 0.5rem; margin-bottom: var(--space-2); }
.inv-amount-card { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0.6rem 0.5rem; background: var(--accent); border: 1px solid var(--border); border-radius: 6px; gap: 0.25rem; }
.inv-thumb-card { flex: 0 0 100px; align-self: stretch; display: flex; align-items: center; justify-content: center; background: var(--accent); border: 1.5px solid var(--border); border-radius: 6px; padding: 4px; text-decoration: none; transition: border-color 0.15s; }
.inv-thumb-card:hover { border-color: var(--primary); }
.inv-thumb-empty { opacity: 0.5; pointer-events: none; }
.inv-thumb-img { width: 100%; height: 100%; object-fit: cover; border-radius: 4px; }
.inv-thumb-icon { width: 1.5rem; height: 1.5rem; color: var(--muted-fg); }

/* ============================================================
   ui-kit components (libs/ui-kit/ui_kit/templates/ui_kit/*)
   ============================================================ */

/* --- Keyboard focus ------------------------------------------
   One visible ring for everything a keyboard can reach. :focus-visible
   keeps mouse clicks ring-free. */
.btn:focus-visible, a:focus-visible, button:focus-visible, summary:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible,
[tabindex]:focus-visible, .pg-btn:focus-visible {
  outline: 2px solid var(--color-border-focus); outline-offset: 1px;
}
tr[tabindex]:focus-visible > td { background: var(--accent); }
tr[tabindex]:focus-visible { outline-offset: -2px; }

/* --- Loading (htmx) ------------------------------------------
   htmx adds .htmx-request to the requesting element (or its hx-indicator
   target). A button shows a spinner and cannot be clicked twice; a region
   marked .ui-loading-region dims and shows a bar while it reloads. */
.btn.htmx-request { position: relative; pointer-events: none; color: transparent !important; }
.btn.htmx-request::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 0.8rem; height: 0.8rem;
  border: 2px solid var(--muted-fg); border-right-color: transparent; border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.btn-primary.htmx-request::after, .btn-danger.htmx-request::after { border-color: var(--primary-fg); border-right-color: transparent; }
.ui-loading-region { position: relative; }
.ui-loading-region::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; z-index: 2;
  background: linear-gradient(90deg, transparent, var(--primary), transparent) 0 0 / 40% 100% no-repeat;
  opacity: 0; transition: opacity 0.15s;
}
.ui-loading-region.htmx-request::before { opacity: 1; animation: ui-loadbar 0.9s linear infinite; }
.ui-loading-region.htmx-request tbody { opacity: 0.55; transition: opacity 0.15s; }
@keyframes ui-loadbar { from { background-position: -40% 0; } to { background-position: 140% 0; } }

/* --- Toast variants (ui_kit/feedback.html) ------------------- */
.toast-warning { border-left: 3px solid var(--color-status-warning); }
.toast-info { border-left: 3px solid var(--color-status-info); }

/* --- Dialog (ui_kit/feedback.html, ui_kit/dialog.html) ------- */
.ui-dialog {
  margin: auto; /* the reset's margin:0 would pin a modal <dialog> to the top-left */
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
  background: var(--card); color: var(--foreground); width: min(400px, 92vw);
  box-shadow: 0 12px 40px rgba(0,0,0,0.22);
}
.ui-dialog::backdrop { background: rgba(0,0,0,0.35); }
.ui-dialog-body { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-3); }
.ui-dialog-title { font-size: var(--text-base); font-weight: 600; margin: 0; }
.ui-dialog-text { font-size: var(--text-sm); color: var(--muted-fg); margin: 0; white-space: pre-line; }
.ui-dialog-text:first-child { color: var(--foreground); }
.ui-dialog-input { width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px); font-size: var(--text-sm); background: var(--card); color: var(--foreground); }
.ui-dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-1); }

/* --- Page header (ui_kit/page.html) -------------------------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.page-header-title { font-size: var(--text-lg); font-weight: 600; margin: 0; }
.page-header-desc { color: var(--muted-fg); font-size: 0.8125rem; margin-top: 0.125rem; }
.page-header-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* --- Filter bar (ui_kit/filters.html) ------------------------ */
.ui-filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-2) var(--space-3); padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border); }
.ui-filter-field { display: flex; flex-direction: column; gap: 0.2rem; }
.ui-filter-field > label { font-size: 0.6875rem; font-weight: 500; color: var(--muted-fg); }
.ui-filter-field input, .ui-filter-field select {
  height: 1.875rem; padding: 0 0.5rem; font-size: 0.8125rem; border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 3px); background-color: var(--card); color: var(--foreground); width: 9rem;
}
.ui-filter-field select { width: auto; padding-right: 1.75rem; }
.ui-filter-field.narrow input { width: 7rem; }
.ui-filter-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; padding: 0.4rem var(--space-5); border-bottom: 1px solid var(--border-subtle); font-size: var(--text-xs); min-height: 2.1rem; }
.ui-chip { display: inline-flex; align-items: center; gap: 0.25rem; background: var(--accent); border-radius: 999px; padding: 0.1rem 0.2rem 0.1rem 0.6rem; }
.ui-chip-remove { border: 0; background: none; color: var(--muted-fg); cursor: pointer; font-size: 0.875rem; line-height: 1; padding: 0.1rem 0.3rem; border-radius: 50%; }
.ui-chip-remove:hover { color: var(--foreground); background: var(--accent-active); }
.ui-chips-clear { border: 0; background: none; color: var(--primary); font: inherit; cursor: pointer; padding: 0 0.25rem; }
.ui-chips-hint { margin-left: auto; color: var(--muted-fg); }

/* --- Empty state (ui_kit/empty_state.html) ------------------- */
.ui-empty { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); text-align: center; padding: var(--space-8) var(--space-4); }
.ui-empty-title { font-weight: 600; font-size: var(--text-sm); }
.ui-empty-text { color: var(--muted-fg); font-size: 0.8125rem; }

/* --- List rows and inline links ---------------------------- */
/* :where() keeps the colour/font reset at zero specificity, so classes on the
   same element (.link-primary, .ref-financed, .ref-plain, .mono) win. */
:where(.link-button) { color: inherit; font: inherit; }
.link-button { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-button:hover { text-decoration: underline; }
.ref-icon { width: 0.875rem; height: 0.875rem; vertical-align: middle; margin-right: 0.25rem; }
tr.row-expandable { cursor: pointer; }
.chevron-open { transform: rotate(90deg); }
td.expand-cell { padding: 0; border-bottom: none; }
.list-footer { padding: 0.6rem var(--space-5); border-top: 1px solid var(--border-subtle); }
/* Skip link: off-screen until it takes keyboard focus (ui_kit/app_header.html). */
.skip-link { position: absolute; left: 0.5rem; top: -4rem; z-index: 1000; padding: 0.5rem 0.75rem; background: var(--card); color: var(--foreground); border: 2px solid var(--primary); border-radius: var(--radius); font-size: 0.8125rem; font-weight: 600; text-decoration: none; }
.skip-link:focus { top: 0.5rem; }
main[tabindex="-1"]:focus { outline: none; }
.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; }

/* --- Status badge (ui_kit/badge.html status_badge) ----------- */
.badge-dot { display: inline-flex; align-items: center; gap: 0.3rem; }
.badge-dot::before { content: ""; width: 0.375rem; height: 0.375rem; border-radius: 50%; background: currentColor; flex: none; }

@media (prefers-reduced-motion: reduce) {
  .btn.htmx-request::after, .ui-loading-region.htmx-request::before { animation-duration: 2.4s; }
}
