/* Fonts are served from the project, so a slow or offline connection never leaves the page without them. */
@font-face {
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../vendor/fonts/barlow-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../vendor/fonts/barlow-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../vendor/fonts/barlow-latin-700-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Chakra Petch';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../vendor/fonts/chakra-petch-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Chakra Petch';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../vendor/fonts/chakra-petch-latin-700-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../vendor/fonts/jetbrains-mono-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../vendor/fonts/jetbrains-mono-latin-700-normal.woff2') format('woff2');
}

/* ---------------------------------------------------------------------
   XP Junkshop -- "Instrument panel" theme, fitted to the Carburetor.club
   reference: near-black ground, graphite instrument cards with thin
   bezel borders and sharp corners, one gauge-green accent for state and
   action, amber for tags, and a three-voice type system -- Chakra Petch
   for titles and controls, JetBrains Mono for labels and readouts,
   Barlow for body text. Green and red stay the gain/loss pair. Every
   text pair below clears WCAG AA. Layout is untouched: only color,
   type, radius and border treatment live here.
--------------------------------------------------------------------- */

:root {
  color-scheme: dark;
  --xp-ground: #0b0d0f; /* page ground and app shell */
  --xp-ground-deep: #0b0d0f;
  --xp-shell-line: #262c35;
  --xp-shell-text: #b8c4d1;
  --xp-shell-muted: #92a0b3;
  --xp-cream: #f5f8fa;
  --xp-primary: #7cff9e; /* gauge green: action, active state, gain */
  --xp-primary-dim: rgba(124, 255, 158, 0.12);
  --xp-primary-strong: #a8ffbf; /* hover */
  --xp-ink: #f5f8fa; /* main text */
  --xp-bg: #171b21; /* instrument card */
  --xp-panel: #121519;
  --xp-surface-muted: #090a0d; /* inset: fields, table heads */
  --xp-muted: #92a0b3; /* secondary text on cards (6.4:1) */
  --xp-line: #262c35; /* bezel line */
  --xp-edge: #38424f; /* control edge */
  --xp-danger: #ff524e; /* loss / error */
  --xp-positive: #7cff9e; /* gain */
  --xp-font-display: 'Chakra Petch', -apple-system, sans-serif;
  --xp-font-body: 'Barlow', -apple-system, sans-serif;
  --xp-font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --xp-radius: 4px;
  --xp-radius-lg: 6px;

  --xp-fg: var(--xp-ink);
  --xp-fg-muted: var(--xp-muted);
  --xp-fg-inv: #0b0d0f;

  /* Reskin Bootstrap's own variables (the pages also set
     data-bs-theme="dark") so components without a custom class below
     still pick up the palette automatically. */
  --bs-primary: var(--xp-primary);
  --bs-primary-rgb: 124, 255, 158;
  --bs-danger: var(--xp-danger);
  --bs-border-radius: var(--xp-radius);
  --bs-border-radius-lg: var(--xp-radius-lg);
  --bs-border-radius-sm: 2px;
  --bs-body-bg: var(--xp-bg);
  --bs-body-color: var(--xp-ink);
  --bs-link-color: var(--xp-primary);
  --bs-link-hover-color: var(--xp-primary-strong);
  --bs-body-font-family: var(--xp-font-body);
  --bs-body-font-weight: 500;
}

/* Tokens that differ between the two themes. Dark is the default; the
   daylight set below is switched on by data-bs-theme="light". */
:root {
  --xp-amber: #ffb000; /* tags, caution */
  --xp-amber-dim: rgba(255, 176, 0, 0.14);
  --xp-amber-line: rgba(255, 176, 0, 0.55);
  --xp-primary-line: var(--xp-primary-line);
  --xp-on-primary: #0b0d0f; /* text on the green fill */
  --xp-on-solid: #0b0d0f; /* text on solid green / red tags */
  --xp-edge-strong: #4a5666;
  --xp-raised: #1c2128;
  --xp-hover: rgba(255, 255, 255, 0.07);
  --xp-row-hover: rgba(124, 255, 158, 0.06);
  --xp-placeholder: #7d8a9b;
  --xp-focus-ring: rgba(124, 255, 158, 0.25);
  --xp-selection: rgba(124, 255, 158, 0.3);
  --xp-card-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  --xp-skel-a: #1c2128;
  --xp-skel-b: #262c35;
  --xp-fg-muted-ground: #b8c4d1;
}
[data-bs-theme='light'] {
  color-scheme: light;
  --xp-ground: #e8ecf0;
  --xp-ground-deep: #ffffff;
  --xp-shell-line: #cdd5de;
  --xp-shell-text: #3a4552;
  --xp-shell-muted: #5a6676;
  --xp-cream: #11161c;
  --xp-primary: #0b7a3b; /* deep green: 5.6:1 on white; white text on it passes */
  --xp-primary-dim: rgba(11, 122, 59, 0.1);
  --xp-primary-strong: #09622f;
  --xp-primary-line: rgba(11, 122, 59, 0.4);
  --xp-amber: #8a5a00;
  --xp-amber-dim: rgba(138, 90, 0, 0.1);
  --xp-amber-line: rgba(138, 90, 0, 0.45);
  --xp-ink: #11161c;
  --xp-bg: #ffffff;
  --xp-panel: #f4f6f8;
  --xp-surface-muted: #f1f4f7;
  --xp-muted: #4a5563;
  --xp-line: #d3dae2;
  --xp-edge: #7d8a9a;
  --xp-edge-strong: #5a6676;
  --xp-danger: #c0262d;
  --xp-positive: #0b7a3b;
  --xp-on-primary: #ffffff;
  --xp-on-solid: #ffffff;
  --xp-raised: #e6ebf0;
  --xp-hover: rgba(17, 22, 28, 0.06);
  --xp-row-hover: rgba(11, 122, 59, 0.07);
  --xp-placeholder: #5c6879;
  --xp-focus-ring: rgba(11, 122, 59, 0.3);
  --xp-selection: rgba(11, 122, 59, 0.25);
  --xp-card-shadow: 0 1px 2px rgba(17, 22, 28, 0.08);
  --xp-skel-a: #e6ebf0;
  --xp-skel-b: #d3dae2;
  --xp-fg-muted-ground: #4a5563;
  --bs-primary-rgb: 11, 122, 59;
}

body {
  background-color: var(--xp-ground);
  color: var(--xp-ink);
  font-family: var(--xp-font-body);
  scrollbar-color: var(--xp-edge) var(--xp-ground);
}
::selection {
  background: var(--xp-selection);
  color: var(--xp-ink);
}

.app-main {
  --xp-fg: var(--xp-ink);
  --xp-fg-muted: var(--xp-fg-muted-ground);
  --xp-fg-inv: var(--xp-ground);
  color: var(--xp-fg);
}
.card,
.table-responsive,
.modal-content {
  --xp-fg: var(--xp-ink);
  --xp-fg-muted: var(--xp-muted);
  --xp-fg-inv: var(--xp-ground);
  color: var(--xp-fg);
}
.text-muted {
  color: var(--xp-fg-muted) !important;
}

h1,
h2,
h3,
h4,
h5,
h6,
.h1,
.h2,
.h3,
.h4,
.h5,
.h6 {
  color: var(--xp-fg);
  font-family: var(--xp-font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
/* The one accent word in a page greeting. */
main h1 em {
  font-style: normal;
  color: var(--xp-primary);
}

/* ---- App shell: a top bar (brand + user info) with a persistent
   left sidebar for navigation below it, replacing the old top navbar. --- */
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background-color: var(--xp-ground-deep);
  border-bottom: 1px solid var(--xp-shell-line);
}
.app-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.app-brand .app-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--xp-radius);
  background-color: var(--xp-primary-dim);
  border: 1px solid var(--xp-primary-line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.app-brand .app-title {
  font-family: var(--xp-font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.2;
  color: var(--xp-cream);
}
.app-brand .app-subtitle {
  font-family: var(--xp-font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--xp-shell-muted);
  line-height: 1.2;
}
.app-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}
.app-user {
  text-align: right;
  font-size: 0.85rem;
  line-height: 1.25;
}
.app-user .app-user-name {
  font-weight: 700;
  color: var(--xp-cream);
}
.app-user .badge {
  background-color: var(--xp-amber-dim) !important;
  border: 1px solid var(--xp-amber-line);
  color: var(--xp-amber) !important;
  font-family: var(--xp-font-mono);
  letter-spacing: 0.1em;
}
#logoutBtn {
  border: 1px solid var(--xp-edge);
  color: var(--xp-cream);
  font-weight: 700;
  border-radius: var(--xp-radius);
}
#logoutBtn:hover {
  background-color: var(--xp-primary-dim);
  border-color: var(--xp-primary);
  color: var(--xp-primary);
}
.sidebar-toggle {
  border: 1px solid var(--xp-edge);
  border-radius: var(--xp-radius);
  background: transparent;
  color: var(--xp-cream);
  width: 38px;
  height: 38px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.app-shell {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - 65px);
}
.app-sidebar {
  width: 220px;
  flex-shrink: 0;
  background-color: var(--xp-ground-deep);
  border-right: 1px solid var(--xp-shell-line);
  min-height: calc(100vh - 65px);
  padding: 1rem 0.75rem;
  position: sticky;
  top: 0;
  align-self: flex-start;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--xp-radius);
  color: var(--xp-shell-text) !important;
  font-family: var(--xp-font-display);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  font-size: 0.8rem;
  text-decoration: none;
}
.sidebar-link i {
  font-size: 1.05rem;
  width: 20px;
  text-align: center;
}
.sidebar-link:hover {
  background-color: var(--xp-hover);
}
.sidebar-link.active-page {
  background-color: var(--xp-primary-dim);
  color: var(--xp-primary) !important;
  font-weight: 700;
}
.sidebar-link.active-page i {
  color: var(--xp-primary);
}
.app-main {
  flex: 1;
  min-width: 0;
  padding: 1.25rem 1.5rem 3rem;
}

@media (max-width: 576px) {
  .app-topbar {
    padding: 0.6rem 0.85rem;
    gap: 0.5rem;
  }
  .app-brand .app-logo {
    width: 34px;
    height: 34px;
    font-size: 1.1rem;
  }
  .app-brand .app-title {
    font-size: 0.85rem;
    letter-spacing: 0.03em;
  }
  .app-brand .app-subtitle {
    display: none;
  }
  /* Let the title shrink instead of pushing Log out off the screen. */
  .app-brand {
    min-width: 0;
    flex: 1 1 auto;
  }
  .app-brand .app-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .app-topbar-right {
    gap: 0.5rem;
    flex-shrink: 0;
  }
  .app-user .app-user-name {
    display: none;
  }
  .app-user .badge {
    font-size: 0.72rem;
  }
  /* The title's wrapper must be allowed to shrink too, or the title runs underneath the buttons. */
  .app-brand > div:not(.app-logo) {
    min-width: 0;
  }
  #logoutBtn {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    white-space: nowrap;
  }
  .page-header {
    gap: 0.5rem;
    margin-bottom: 1rem;
  }
  .page-title-icon {
    width: 30px;
    height: 30px;
    min-width: 30px;
    font-size: 0.9rem;
  }
  .app-sidebar,
  .sidebar-backdrop {
    top: 59px;
  }
}

/* On narrow phones there is no room for the role tag next to the buttons; it is hidden there (it still shows on tablets and larger). */
@media (max-width: 430px) {
  .app-user {
    display: none;
  }
}

@media (max-width: 900px) {
  .sidebar-toggle {
    display: inline-flex;
  }
  .app-sidebar {
    position: fixed;
    left: 0;
    top: 65px;
    bottom: 0;
    z-index: 1040;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.15);
  }
  .app-sidebar.sidebar-open {
    transform: translateX(0);
  }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 65px;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1030;
  }
  .sidebar-backdrop.show {
    display: block;
  }
}

/* ---- Page header: icon badge + title, injected by renderNavbar() so
   every page gets the same treatment as its sidebar link. ---- */
.page-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}
.page-title-icon {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: var(--xp-radius);
  background-color: var(--xp-primary-dim);
  border: 1px solid var(--xp-primary-line);
  color: var(--xp-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

/* ---- Empty states: tables/lists with nothing to show. ---- */
.empty-state-cell {
  padding: 2.5rem 1rem !important;
}
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  color: var(--xp-fg-muted);
  font-weight: 600;
  font-size: 0.9rem;
}
.empty-state i {
  font-size: 1.6rem;
  color: var(--xp-edge);
}

/* ---- Cards: graphite instrument panels with a thin bezel line. ---- */
.card {
  background-color: var(--xp-bg);
  border: 1px solid var(--xp-line);
  border-radius: var(--xp-radius-lg);
  box-shadow: var(--xp-card-shadow);
}

.summary-card .card-body {
  padding: 1.1rem 1.25rem;
}
.summary-card .icon-badge {
  width: 40px;
  height: 40px;
  border-radius: var(--xp-radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: var(--xp-primary-dim);
  border: 1px solid var(--xp-primary-line);
  color: var(--xp-primary);
  font-size: 1.1rem;
  margin-bottom: 0.6rem;
}
.summary-card .label {
  color: var(--xp-muted);
  font-family: var(--xp-font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
}
.summary-card .value {
  font-size: clamp(1.05rem, 1.2vw + 0.8rem, 1.5rem);
  font-family: var(--xp-font-mono);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--xp-ink);
  white-space: nowrap;
  overflow-wrap: normal;
}

/* Analytics: groups related charts/tables under a labeled section
   (Business Performance, Material Analysis, Price Analysis, Business
   Insights) so a dense page reads as a few clear zones instead of one
   long undifferentiated scroll. */
.analytics-section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--xp-line);
}
.analytics-section-icon {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: var(--xp-radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: var(--xp-primary-dim);
  border: 1px solid var(--xp-primary-line);
  color: var(--xp-primary);
  font-size: 1rem;
}

/* ---- Buttons: uppercase Chakra Petch; green fill for the one primary
   action, graphite outline for everything else. ---- */
.btn {
  border-radius: var(--xp-radius);
  font-family: var(--xp-font-display);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.55rem 1.1rem;
}
.btn-primary,
.btn-cta {
  background-color: var(--xp-primary);
  border: 1px solid var(--xp-primary);
  color: var(--xp-on-primary);
}
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active,
.btn-cta:hover,
.btn-cta:focus-visible {
  background-color: var(--xp-primary-strong) !important;
  border-color: var(--xp-primary-strong) !important;
  color: var(--xp-on-primary) !important;
}
.btn-secondary {
  background-color: var(--xp-panel);
  border: 1px solid var(--xp-edge);
  color: var(--xp-ink);
}
.btn-secondary:hover {
  background-color: var(--xp-raised);
  color: var(--xp-ink);
  border-color: var(--xp-edge-strong);
}
.btn-outline-secondary {
  border: 1px solid var(--xp-edge);
  color: var(--xp-fg);
}
.btn-outline-secondary:hover {
  background-color: var(--xp-hover);
  border-color: var(--xp-edge-strong);
  color: var(--xp-fg);
}
.btn-outline-danger {
  border: 1px solid var(--xp-danger);
  color: var(--xp-danger);
}
.btn-outline-danger:hover {
  background-color: var(--xp-danger);
  border-color: var(--xp-danger);
  color: var(--xp-on-solid);
}
.btn-outline-warning {
  border: 1px solid var(--xp-amber);
  color: var(--xp-amber);
}
.btn-outline-warning:hover {
  background-color: var(--xp-amber);
  border-color: var(--xp-amber);
  color: var(--xp-on-solid);
}
.btn-sm {
  border-radius: 3px;
  font-weight: 600;
}

/* ---- Forms: inset dark fields with a graphite edge; green focus. ---- */
.form-control,
.form-select {
  border: 1px solid var(--xp-edge);
  border-radius: var(--xp-radius);
  background-color: var(--xp-surface-muted);
  color: var(--xp-ink);
}
.form-control:focus,
.form-select:focus {
  border-color: var(--xp-primary);
  background-color: var(--xp-surface-muted);
  color: var(--xp-ink);
  box-shadow: 0 0 0 3px var(--xp-focus-ring);
}
.form-control::placeholder {
  color: var(--xp-placeholder);
}
.form-control:disabled {
  background-color: var(--xp-panel);
  color: var(--xp-fg-muted);
}
.form-label {
  font-family: var(--xp-font-mono);
  font-weight: 700;
  color: var(--xp-fg-muted);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.form-control-sm,
.form-select-sm {
  border-radius: 3px;
}

/* ---- Tables ---- */
.table-responsive {
  background-color: var(--xp-bg);
  border: 1px solid var(--xp-line);
  border-radius: var(--xp-radius-lg);
  overflow-x: auto; /* a wide table scrolls sideways on a phone or tablet instead of being cut off */
  overflow-y: hidden;
}
.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--xp-ink);
  --bs-table-border-color: var(--xp-line);
  --bs-table-hover-bg: rgba(124, 255, 158, 0.06);
  --bs-table-hover-color: var(--xp-ink);
  color: var(--xp-ink);
  margin-bottom: 0;
}
.table td {
  font-variant-numeric: tabular-nums;
}
.table > thead {
  background-color: var(--xp-surface-muted);
}
.table-light {
  --bs-table-bg: var(--xp-surface-muted);
  --bs-table-color: var(--xp-fg-muted);
  --bs-table-border-color: var(--xp-line);
}
.table > thead th {
  font-family: var(--xp-font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--xp-edge) !important;
  color: var(--xp-fg-muted);
}
.table-hover > tbody > tr:hover > * {
  background-color: var(--xp-row-hover);
}

/* ---- Nav tabs (e.g. New Transaction / Transaction History): match the
   graphite/green system instead of Bootstrap's default blue-ish active state. ---- */
.nav-tabs {
  border-bottom: 1px solid var(--xp-line);
  gap: 0.25rem;
}
.nav-tabs .nav-link {
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--xp-fg-muted);
  font-weight: 700;
  padding: 0.6rem 0.9rem;
  margin-bottom: -1.5px;
}
.nav-tabs .nav-link:hover {
  border-color: transparent;
  color: var(--xp-fg);
  background-color: var(--xp-hover);
}
.nav-tabs .nav-link.active {
  color: var(--xp-fg);
  background-color: transparent;
  border-color: var(--xp-primary);
  border-bottom-width: 3px;
}

/* ---- Badges: rounded pills, bold. ---- */
.badge {
  border-radius: 3px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.4em 0.7em;
}
/* Solid green / red tags carry dark text, not white. */
.badge[style*="--xp-positive"],
.badge[style*="--xp-danger"],
.badge.bg-primary,
.badge.bg-warning {
  color: var(--xp-on-solid) !important;
}
.badge {
  font-size: 0.75rem; /* never smaller than 12px, even inside small text */
}
.btn:not(.btn-ai) {
  white-space: nowrap; /* labels such as "Export CSV" stay on one line */
}

/* ---- Modals: match the card treatment. ---- */
.modal-content {
  border: 1px solid var(--xp-line);
  border-radius: var(--xp-radius-lg);
}
.modal-header,
.modal-footer {
  border-color: var(--xp-line);
}

/* ---- Alerts ---- */
.alert {
  border-radius: var(--xp-radius);
  border-width: 1.5px;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--xp-ground);
}

.login-card {
  width: 100%;
  max-width: 380px;
}
.login-card code {
  color: var(--xp-positive);
  background-color: var(--xp-surface-muted);
  padding: 0.1em 0.35em;
  border-radius: 6px;
}

/* ---- Dashboard: Fund Activity ledger ---- */
.dash-ledger-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--xp-line);
  font-size: 0.9rem;
  font-weight: 600;
}
.dash-ledger-total {
  border-bottom: none;
  border-top: 1px solid var(--xp-edge);
  margin-top: 0.3rem;
  padding-top: 0.7rem;
  font-weight: 800;
  font-size: 1rem;
}

/* ---- Dashboard: header row (greeting + date-range controls) ---- */
.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
}
.dash-header-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

/* KPI card supporting line: the vs-previous-period trend or the
   transaction-count/caption text under each Executive KPI value. */
.kpi-sub {
  font-size: 0.78rem;
  font-weight: 600;
  margin-top: 0.35rem;
}

/* ---- Dashboard: Business Pulse / Inventory Snapshot compact stats ---- */
.pulse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}
.pulse-label {
  font-family: var(--xp-font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--xp-muted);
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.pulse-value {
  font-family: var(--xp-font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  font-weight: 700;
  color: var(--xp-ink);
}

/* ---- Print (Print / Save as PDF buttons): the app shell (topbar,
   sidebar, filter forms, action buttons) has no place on a printed
   report -- only the actual data should print. Anything page-specific
   that also shouldn't print gets the "d-print-none" class Bootstrap
   already ships (used for filter bars, tabs, buttons). ---- */
@media print {
  .app-topbar,
  .app-sidebar,
  .sidebar-backdrop,
  .sidebar-toggle {
    display: none !important;
  }
  .app-shell {
    display: block !important;
  }
  .app-main {
    padding: 0 !important;
  }
}

.balance-in {
  color: var(--xp-positive);
  font-weight: 700;
}

.balance-out {
  color: var(--xp-danger);
  font-weight: 700;
}

/* ---- Keyboard focus: one visible ring on every interactive element,
   so tabbing never loses its place. Form fields keep their own ring. ---- */
a:focus-visible,
button:focus-visible,
.btn:focus-visible,
.sidebar-link:focus-visible,
.nav-link:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--xp-primary);
  outline-offset: 2px;
}

/* ---- Reduced motion: keep the state change, drop the movement. ---- */
@media (prefers-reduced-motion: reduce) {
  .app-sidebar {
    transition: none;
  }
}

/* ---- Print: ink on paper, not the dark console. ---- */
@media print {
  body {
    background: #fff !important;
  }
  .app-main,
  .app-main * {
    color: #000 !important;
    background: transparent !important;
    box-shadow: none !important;
    border-color: #bbb !important;
  }
}

/* ---- Dashboard: Business Insights list (owner) ---- */
.dash-insights .list-group-item {
  background-color: transparent;
  color: var(--xp-ink);
  border-color: var(--xp-line);
  padding: 0.6rem 0;
  font-size: 0.9rem;
  font-weight: 600;
}

/* ---- Loading and failure states ---- */
.is-loading {
  position: relative;
  color: transparent !important;
}
.is-loading * {
  color: transparent !important;
}
.is-loading::after {
  content: '';
  position: absolute;
  left: 0;
  top: 15%;
  height: 70%;
  width: 7.5em;
  max-width: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--xp-skel-a) 25%, var(--xp-skel-b) 50%, var(--xp-skel-a) 75%);
  background-size: 200% 100%;
  animation: xp-shimmer 1.3s linear infinite;
}
@keyframes xp-shimmer {
  to {
    background-position: -200% 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .is-loading::after {
    animation: none;
  }
}
.chart-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  font-weight: 600;
  color: var(--xp-fg-muted);
  pointer-events: none;
}

/* Long names wrap inside their cell instead of stretching the table. */
.cell-wrap {
  overflow-wrap: anywhere;
  min-width: 0;
}
/* A very large peso amount is trimmed rather than spilling out of its card. */
.summary-card .value {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ---- Theme switch button ---- */
.theme-toggle {
  border: 1px solid var(--xp-edge);
  border-radius: var(--xp-radius);
  background: transparent;
  color: var(--xp-cream);
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--xp-hover);
}
.theme-toggle-floating {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 10;
}

/* ---- Phones: bigger labels, 44px touch targets, and 16px fields so
   iOS doesn't zoom the page when a field is focused. Layout is unchanged. ---- */
@media (max-width: 576px) {
  .form-label,
  .table > thead th,
  .summary-card .label,
  .pulse-label {
    font-size: 0.8rem;
  }
  .form-control,
  .form-select,
  .btn,
  .btn-sm {
    min-height: 44px;
  }
  .form-control,
  .form-select {
    font-size: 1rem;
  }
  .theme-toggle,
  .sidebar-toggle {
    width: 40px;
    height: 40px;
  }
  .summary-card .label {
    letter-spacing: 0.03em;
  }
  .sidebar-link {
    padding: 0.8rem 0.8rem;
  }
}

/* ---- AI interpretation (Analytics) ---- */
.btn-ai {
  border: 1px solid var(--xp-primary);
  color: var(--xp-primary);
  font-weight: 700;
  border-radius: var(--xp-radius);
  white-space: nowrap;
}
.btn-ai:hover:not(:disabled) {
  background-color: var(--xp-primary-dim);
  color: var(--xp-primary);
}
@media (max-width: 576px) {
  .btn-ai {
    white-space: normal; /* wraps instead of pushing the page wider than the screen */
    text-align: left;
  }
}
.ai-box {
  border: 1px solid var(--xp-primary-line);
  border-left: 4px solid var(--xp-primary);
  background-color: var(--xp-primary-dim);
  border-radius: var(--xp-radius);
  padding: 0.85rem 1rem;
  font-size: 0.92rem;
}
.ai-box pre {
  white-space: pre-wrap;
  font-size: 0.75rem;
  max-height: 14rem;
  overflow: auto;
}
@media print {
  .btn-ai { display: none !important; }
}

/* ---- Demonstration-data notice (under the top bar on every page) ---- */
.demo-notice {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 1.25rem;
  background-color: var(--xp-amber-dim);
  border-bottom: 1px solid var(--xp-amber-line);
  color: var(--xp-cream);
  font-size: 0.8rem;
  line-height: 1.3;
}
.demo-notice strong {
  color: var(--xp-amber);
}
.demo-notice .btn-close {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 0.7rem;
}
@media (max-width: 576px) {
  .demo-notice {
    padding: 0.4rem 0.85rem;
    font-size: 0.75rem;
  }
}
@media print {
  .demo-notice { display: none !important; }
}
