/* =========================================================================
   AV Solutions ERP — brand theme
   Palette is defined once below and everything else (tints, shades,
   Bootstrap's own runtime CSS variables) is derived from it.
   ========================================================================= */

:root {
  /* ---- Brand (do not add other brand colours; derive from these) ---- */
  --brand-indigo: #2c3a63;
  --brand-terracotta: #b85530;
  --brand-offwhite: #f6f3ec;
  --brand-ink: #14161f;

  /* ---- Indigo tints/shades ---- */
  --indigo-50: #eceef4;
  --indigo-100: #d7dce8;
  --indigo-700: #223050;
  --indigo-900: #1a2440;

  /* ---- Terracotta tints/shades ---- */
  --terracotta-50: #fbeee7;
  --terracotta-100: #f5dbcb;
  --terracotta-600: var(--brand-terracotta);
  --terracotta-700: #9c4526;
  --terracotta-800: #7d3620;
  /* Darker accent for text/links on off-white (passes WCAG AA; the pure
     brand terracotta is reserved for buttons, markers, and large elements) */
  --terracotta-text: #964222;

  /* ---- Semantic colours (kept separate so terracotta never reads as an error) ---- */
  --color-success: #2f7d5b;
  --color-success-bg: #e6f2ec;
  --color-success-text: #1f5a40;

  --color-warning: #b7791f;
  --color-warning-bg: #fbf0dd;
  --color-warning-text: #8a5a14;

  --color-danger: #9b2c3a;
  --color-danger-bg: #f6e3e6;
  --color-danger-text: #7a222d;

  --color-info: var(--brand-indigo);
  --color-info-bg: var(--indigo-50);
  --color-info-text: var(--indigo-700);

  /* ---- Surfaces / text ---- */
  --surface-page: var(--brand-offwhite);
  --surface-card: #ffffff;
  --border-warm: #e6ddd0;
  --text-body: var(--brand-ink);
  --text-muted: rgba(20, 22, 31, 0.65);

  /* ---- Shape / elevation ---- */
  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 1rem;
  --shadow-soft: 0 1px 2px rgba(20, 22, 31, 0.04), 0 6px 16px rgba(20, 22, 31, 0.06);
  --shadow-pop: 0 10px 30px rgba(20, 22, 31, 0.12);

  /* ---- App shell ---- */
  --sidebar-width: 260px;
  --sidebar-rail-width: 4.5rem;

  /* ---- Typography ---- */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

  /* =======================================================================
     Bootstrap 5.3 theming hooks. Bootstrap reads most of these at the
     ROOT level (body, links, tables, cards, dropdowns, modals, toasts all
     reference them), so overriding them here re-themes those components
     without touching Bootstrap's own CSS file.
     ======================================================================= */
  --bs-body-font-family: var(--font-sans);
  --bs-body-color: var(--text-body);
  --bs-body-color-rgb: 20, 22, 31;
  --bs-body-bg: var(--surface-page);
  --bs-body-bg-rgb: 246, 243, 236;
  --bs-emphasis-color: var(--brand-ink);
  --bs-secondary-color: var(--text-muted);
  --bs-border-color: var(--border-warm);
  --bs-border-color-translucent: var(--border-warm);
  --bs-link-color: var(--terracotta-text);
  --bs-link-color-rgb: 150, 66, 34;
  --bs-link-hover-color: var(--terracotta-700);
  --bs-link-hover-color-rgb: 156, 69, 38;
  --bs-focus-ring-color: rgba(184, 85, 48, 0.25);

  --bs-primary: var(--brand-terracotta);
  --bs-primary-rgb: 184, 85, 48;
  --bs-success: var(--color-success);
  --bs-success-rgb: 47, 125, 91;
  --bs-success-bg-subtle: var(--color-success-bg);
  --bs-success-text-emphasis: var(--color-success-text);
  --bs-warning: var(--color-warning);
  --bs-warning-rgb: 183, 121, 31;
  --bs-warning-bg-subtle: var(--color-warning-bg);
  --bs-warning-text-emphasis: var(--color-warning-text);
  --bs-danger: var(--color-danger);
  --bs-danger-rgb: 155, 44, 58;
  --bs-danger-bg-subtle: var(--color-danger-bg);
  --bs-danger-text-emphasis: var(--color-danger-text);
  --bs-info: var(--color-info);
  --bs-info-bg-subtle: var(--color-info-bg);
  --bs-info-text-emphasis: var(--color-info-text);
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  background-color: var(--surface-page);
  color: var(--text-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--brand-ink);
}

.text-muted {
  color: var(--text-muted) !important;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* =========================================================================
   Focus rings
   ========================================================================= */
.btn:focus-visible,
.btn:focus,
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 0.2rem var(--bs-focus-ring-color);
  border-color: var(--brand-terracotta);
}

/* =========================================================================
   Buttons — Bootstrap bakes colours into each .btn-* block's own local
   custom properties, so we re-declare those same properties here (loaded
   after bootstrap.min.css) rather than fight the compiled utility classes.
   ========================================================================= */
.btn {
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.btn-primary {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--terracotta-600);
  --bs-btn-border-color: var(--terracotta-600);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--terracotta-700);
  --bs-btn-hover-border-color: var(--terracotta-700);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--terracotta-800);
  --bs-btn-active-border-color: var(--terracotta-800);
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: var(--terracotta-600);
  --bs-btn-disabled-border-color: var(--terracotta-600);
  --bs-btn-focus-shadow-rgb: 184, 85, 48;
}

.btn-outline-secondary,
.btn-outline-primary {
  --bs-btn-color: var(--brand-indigo);
  --bs-btn-border-color: var(--brand-indigo);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--brand-indigo);
  --bs-btn-hover-border-color: var(--brand-indigo);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--indigo-700);
  --bs-btn-active-border-color: var(--indigo-700);
  --bs-btn-focus-shadow-rgb: 44, 58, 99;
}

.btn-danger,
.btn-outline-danger {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--color-danger);
  --bs-btn-border-color: var(--color-danger);
  --bs-btn-hover-bg: var(--color-danger-text);
  --bs-btn-hover-border-color: var(--color-danger-text);
  --bs-btn-active-bg: var(--color-danger-text);
  --bs-btn-active-border-color: var(--color-danger-text);
  --bs-btn-outline-color: var(--color-danger);
  --bs-btn-focus-shadow-rgb: 155, 44, 58;
}
.btn-outline-danger {
  --bs-btn-color: var(--color-danger);
  --bs-btn-bg: transparent;
  --bs-btn-hover-color: #fff;
}

.btn-link {
  color: var(--terracotta-text);
}
.btn-link:hover {
  color: var(--terracotta-700);
}

.btn[disabled],
.btn.disabled {
  opacity: 0.65;
}

/* =========================================================================
   Cards, tables, forms
   ========================================================================= */
.card {
  --bs-card-border-color: var(--border-warm);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}

.card-header {
  background-color: #fff;
  border-bottom: 1px solid var(--border-warm);
  font-weight: 600;
}

.table {
  --bs-table-bg: var(--surface-card);
  vertical-align: middle;
}

.table > thead > tr > th {
  background-color: var(--indigo-50);
  color: var(--indigo-700);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  border-bottom: 1px solid var(--border-warm);
  white-space: nowrap;
}

.table > tbody > tr:hover > * {
  background-color: var(--brand-offwhite);
}

/* =========================================================================
   Tables that fit (shared across every list and detail table).
   No page scrolls sideways. A table sits in a .table-fit wrapper, which is a
   container: lower-priority columns hide as the WRAPPER narrows (not the
   viewport), so the expanded sidebar, the rail, the mobile drawer and the
   narrow panels of the detail pages are all handled by the same rules.

     cp-1  hidden under 520px     cp-3  hidden under 1100px
     cp-2  hidden under 800px     cp-4  hidden under 1280px

   The classes go on the <th>; site.js (syncFitColumns) copies them onto every
   cell of that column, including rows DataTables adds later. Columns without a
   cp-N class always show: the identifying column, the key status or amount
   column and the row actions. Widths: fc-* classes on the <th> (fixed layout).
   Rows stay one line high: text truncates with an ellipsis plus a tooltip, and
   collections show a couple of chips plus a "+N" badge (renderChipOverflow in
   site.js). See CLAUDE.md "List layout".
   ========================================================================= */
.table-fit {
  container-type: inline-size;
  width: 100%;
}
.table-fit table {
  table-layout: fixed;
  width: 100%;
}

.table-fit th,
.table-fit td {
  overflow: hidden;
  text-overflow: ellipsis;
}
/* DataTables sets content-box on cells, which would add the padding to every fc-* width */
.table-fit .table th,
.table-fit .table td {
  box-sizing: border-box;
}
.table-fit .table:not(.table-allow-wrap) td,
.table-fit .table:not(.table-allow-wrap) th {
  white-space: nowrap;
}

/* Import previews and the like: wrap instead of truncating, still no scrollbar */
.table-fit .table-allow-wrap td,
.table-fit .table-allow-wrap th {
  white-space: normal;
  overflow-wrap: anywhere;
}
.table-fit .table-allow-wrap td .form-select,
.table-fit .table-allow-wrap td .form-control {
  width: 100%;
  min-width: 0;
}

/* A cell holding a multi-line note or description */
.table-fit .table td.cell-wrap {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Hidden columns: shown again once the wrapper is wide enough */
.cp-1, .cp-2, .cp-3, .cp-4 {
  display: none;
}
@container (min-width: 520px) {
  .cp-1 { display: table-cell; }
}
@container (min-width: 800px) {
  .cp-2 { display: table-cell; }
}
@container (min-width: 1100px) {
  .cp-3 { display: table-cell; }
}
@container (min-width: 1280px) {
  .cp-4 { display: table-cell; }
}
/* Fixed column widths. Columns with no fc-* class share what is left, so the
   text columns (name, client, title) take the slack. */
.fc-date   { width: 7.75rem; }
.fc-datetime { width: 9.25rem; }
.fc-wide   { width: 10.75rem; }
.fc-status { width: 7.5rem; }
.fc-num    { width: 6.25rem; }
.fc-code   { width: 6rem; }
.fc-money  { width: 8.75rem; }
.fc-short  { width: 7.75rem; }
.fc-check  { width: 3.5rem; }
.fc-select { width: 9.5rem; }
.fc-move   { width: 7rem; }
.fc-statuspair { width: 11.5rem; }
.fc-datebadge { width: 13.5rem; }
.fc-period { width: 16rem; }
/* Action column: n buttons side by side (--act-size is bigger on touch screens) */
.fc-act-1, .fc-act-2, .fc-act-3, .fc-act-4, .fc-act-5 {
  --act-size: 2.1rem;
  --act-gap: 0rem;
  --act-pad: 1rem;
  width: calc(var(--act-n) * var(--act-size) + (var(--act-n) - 1) * var(--act-gap) + var(--act-pad));
}
.fc-act-1 { --act-n: 1; }
.fc-act-2 { --act-n: 2; }
.fc-act-3 { --act-n: 3; }
.fc-act-4 { --act-n: 4; }
.fc-act-5 { --act-n: 5; }
/* One or two icon buttons are narrower than the word "Actions": the header keeps
   its text for screen readers only */
.table-fit .table > thead > tr > th.fc-act-1,
.table-fit .table > thead > tr > th.fc-act-2 {
  font-size: 0;
  letter-spacing: 0;
}

/* Rows with more buttons than fit show only the primary ones under 520px: the
   column says how many (fc-t0-N) and the secondary buttons carry ab-1 */
@container (max-width: 519.98px) {
  .fc-t0-1 { --act-n: 1; }
  .fc-t0-2 { --act-n: 2; }
  /* Narrowest width: smaller fixed columns, 36px action buttons, a compact status badge */
  .table-fit [class*="fc-act-"] { --act-size: 2.25rem; --act-gap: 0rem; --act-pad: 0.6rem; }
  .table-fit th,
  .table-fit td { padding-left: 0.3rem; padding-right: 0.3rem; }
  .table-fit .icon-action-btn { width: 2.25rem; height: 2.25rem; }
  .table-fit .icon-action-btn + .icon-action-btn { margin-left: 0; }
  /* The 36px buttons make rows 1px taller than the fixed row height: keep every row equal */
  .table-fit table.table:has(.icon-action-btn) > tbody > tr { height: 2.85rem; }
  /* Columns showing fewer buttons than they hold have no room for the word "Actions" */
  .table-fit .table > thead > tr > th[class*="fc-t0-"] { font-size: 0; letter-spacing: 0; }
  .fc-date { width: 7.1rem; }
  .fc-datetime { width: 8.25rem; }
  .fc-money { width: 8rem; }
  .fc-short { width: 7.25rem; }
  .fc-select { width: 8.75rem; }
  .fc-statuspair { width: 9rem; }
  .fc-status { width: 6.9rem; }
  .table-fit .table > thead > tr > th { font-size: 0.72rem; letter-spacing: 0.02em; }
  .table-fit .badge-status { padding: 0.25rem 0.5rem; font-size: 0.72rem; }
  .table-fit .badge-status::before { display: none; }
}
.ab-1 {
  display: none !important;
}
@container (min-width: 520px) {
  .ab-1 { display: inline-flex !important; }
}

/* Chips and ellipsis inside a cell never push the column wider */
.table-fit .cell-ellipsis {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table-fit .cell-chips {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
  overflow: hidden;
}
.table-fit .cell-chips > .cell-ellipsis {
  display: inline-block;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}
.table-fit .chip-overflow-badge {
  flex: none;
  cursor: default;
}
.table-fit .badge-status {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
}
.table-fit .actions-cell {
  white-space: nowrap;
}

/* Server-rendered buttons are separated by whitespace: collapse it so the
   action column is exactly n buttons wide (the buttons restore their own size) */
.table-fit td:has(> .icon-action-btn) {
  font-size: 0;
  line-height: 0;
}

/* A row with no action button stays as tall as the rows that have one */
.table-fit .table:has(.icon-action-btn) > tbody > tr {
  height: 2.7rem;
}

/* Input tables (Payment schedule): each row becomes a labelled card under 768px.
   The cells carry data-label; the header row is dropped. */
@container (max-width: 767.98px) {
  .table-fit .table.table-stack,
  .table-fit .table.table-stack > tbody,
  .table-fit .table.table-stack > tbody > tr,
  .table-fit .table.table-stack > tbody > tr > td {
    display: block;
    width: 100%;
  }
  .table-fit .table.table-stack > thead {
    display: none;
  }
  .table-fit .table.table-stack > tbody > tr {
    position: relative;
    height: auto;
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    background: var(--surface-card);
    border: 1px solid var(--border-warm);
    border-radius: var(--radius-md);
  }
  .table-fit .table.table-stack > tbody > tr > td {
    padding: 0.25rem 0;
    border: 0;
    white-space: normal;
    overflow: visible;
  }
  .table-fit .table.table-stack > tbody > tr > td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
  }
  .table-fit .table.table-stack > tbody > tr > td:last-child {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    width: auto;
    padding: 0;
  }
}

.form-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--brand-ink);
}

.form-text {
  color: var(--text-muted);
}

.form-control,
.form-select {
  border-color: var(--border-warm);
  border-radius: var(--radius-sm);
}

.form-control::placeholder {
  color: rgba(20, 22, 31, 0.4);
}

.invalid-feedback {
  color: var(--color-danger);
}

.form-control.is-invalid,
.form-select.is-invalid {
  border-color: var(--color-danger);
}

/* Two-column form layout for desktop; collapses to one column on phones */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.5rem;
}
.form-grid .form-group.span-2 {
  grid-column: 1 / -1;
}
@media (max-width: 767.98px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* =========================================================================
   Status badges — soft tinted background, darker text of the same hue
   ========================================================================= */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  font-size: 0.78125rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
}
.badge-status::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background-color: currentColor;
}
.badge-status.badge-success { background-color: var(--color-success-bg); color: var(--color-success-text); }
.badge-status.badge-warning { background-color: var(--color-warning-bg); color: var(--color-warning-text); }
.badge-status.badge-danger  { background-color: var(--color-danger-bg);  color: var(--color-danger-text); }
.badge-status.badge-info    { background-color: var(--color-info-bg);    color: var(--color-info-text); }
.badge-status.badge-neutral { background-color: var(--indigo-50);        color: var(--text-muted); }

/* =========================================================================
   Empty state
   ========================================================================= */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}
.empty-state .empty-state-icon {
  font-size: 2.25rem;
  color: var(--indigo-100);
  margin-bottom: 0.75rem;
}
.empty-state h5 {
  color: var(--brand-ink);
  margin-bottom: 0.25rem;
}

/* =========================================================================
   App shell: sidebar + topbar
   ========================================================================= */
.app-shell {
  min-height: 100vh;
}

.app-content {
  flex: 1 1 0;
  min-width: 0;
}

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  /* Plain solid colour: no gradients or patterns anywhere in the shell */
  background-color: var(--brand-offwhite);
  border-right: 1px solid var(--border-warm);
  color: var(--brand-ink);
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(20, 22, 31, 0.25) transparent;
}
.app-sidebar > * {
  flex-shrink: 0;
}

.app-sidebar .brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.25rem 1.25rem 1rem;
  color: var(--brand-ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.app-sidebar .brand-full {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}
.app-sidebar .brand-rail {
  display: none;
}
.app-sidebar .brand-logo {
  max-height: 2rem;
  max-width: 9rem;
}
.app-sidebar .brand-favicon {
  width: 2rem;
  height: 2rem;
  object-fit: contain;
}
.app-sidebar .brand .brand-mark {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  background: var(--brand-terracotta);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.app-sidebar .nav-section-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 1rem 1.25rem 0.4rem;
}

.app-sidebar .nav {
  padding: 0 0.6rem;
}

.app-sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--brand-ink);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.65rem;
  font-size: 0.9rem;
  font-weight: 500;
  position: relative;
  border-left: 3px solid transparent;
  margin-bottom: 0.1rem;
  white-space: nowrap;
}
.app-sidebar .nav-link:focus-visible {
  outline: 2px solid var(--brand-terracotta);
  outline-offset: -2px;
  box-shadow: none;
}
.app-sidebar .nav-link i {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  opacity: 0.9;
}
.app-sidebar .nav-link:hover:not(.disabled) {
  background-color: rgba(20, 22, 31, 0.06);
  color: var(--brand-ink);
}
.app-sidebar .nav-link.active {
  background-color: rgba(20, 22, 31, 0.07);
  color: var(--brand-ink);
  border-left-color: var(--brand-terracotta);
  font-weight: 600;
}
.app-sidebar .nav-link.disabled {
  color: rgba(20, 22, 31, 0.4);
  cursor: default;
  pointer-events: none;
}
.app-sidebar .nav-link .soon-tag {
  margin-left: auto;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(20, 22, 31, 0.08);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
}

.app-sidebar .sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.app-topbar {
  background-color: #fff;
  border-bottom: 1px solid var(--border-warm);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.app-topbar .page-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-topbar .breadcrumb {
  margin: 0;
  font-size: 0.8125rem;
}

.sidebar-toggle {
  display: inline-flex;
  flex-shrink: 0;
  border: 1px solid var(--border-warm);
  background: #fff;
  border-radius: var(--radius-sm);
  width: 2.5rem;
  height: 2.5rem;
  align-items: center;
  justify-content: center;
  color: var(--brand-indigo);
  font-size: 1.25rem;
}
.sidebar-toggle:hover {
  background-color: var(--indigo-50);
}
.sidebar-toggle:focus-visible {
  outline: 2px solid var(--brand-terracotta);
  outline-offset: 2px;
}

.sidebar-backdrop {
  display: none;
}

.user-menu-toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border: none;
  background: transparent;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
}
.user-menu-toggle:hover {
  background-color: var(--brand-offwhite);
}
.user-menu-toggle .user-name {
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--indigo-50);
  color: var(--brand-indigo);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8125rem;
  flex-shrink: 0;
}

.app-main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 1.75rem;
}

/* Desktop: the toggle collapses the sidebar to an icon-only rail. The state
   class sits on <html> (see site.js) and only means anything at this width. */
@media (min-width: 992px) {
  .app-sidebar {
    transition: width 0.2s ease;
  }
  .sidebar-collapsed .app-sidebar {
    width: var(--sidebar-rail-width);
    scrollbar-width: none;
  }
  .sidebar-collapsed .app-sidebar .brand {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }
  .sidebar-collapsed .app-sidebar .brand-full {
    display: none;
  }
  .sidebar-collapsed .app-sidebar .brand-rail {
    display: flex;
  }
  .sidebar-collapsed .app-sidebar .nav {
    padding: 0 0.5rem;
  }
  /* Group headings become a thin divider */
  .sidebar-collapsed .app-sidebar .nav-section-label {
    height: 1px;
    margin: 0.5rem 0.9rem;
    padding: 0;
    overflow: hidden;
    font-size: 0;
    background-color: rgba(20, 22, 31, 0.12);
  }
  .sidebar-collapsed .app-sidebar .nav-link {
    justify-content: center;
    padding: 0.6rem 0;
    border-right: 3px solid transparent;
  }
  .sidebar-collapsed .app-sidebar .nav-link i {
    font-size: 1.15rem;
  }
  /* The label stays for screen readers; sighted users get the tooltip */
  .sidebar-collapsed .app-sidebar .nav-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .sidebar-collapsed .app-sidebar .soon-tag,
  .sidebar-collapsed .app-sidebar .sidebar-footer {
    display: none;
  }
  /* Disabled items ignore the pointer, which would also stop their tooltip */
  .sidebar-collapsed .app-sidebar .nav-link.disabled {
    pointer-events: auto;
  }
}

/* Below desktop: an off-canvas drawer. visibility keeps its links out of the
   tab order while it is closed. */
@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    height: auto;
    max-width: 85vw;
    z-index: 1040;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  .app-sidebar.show {
    transform: translateX(0);
    visibility: visible;
    box-shadow: var(--shadow-pop);
    transition: transform 0.2s ease;
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 22, 31, 0.5);
    z-index: 1030;
  }
  .sidebar-backdrop.show {
    display: block;
  }
  body.sidebar-drawer-open {
    overflow: hidden;
  }
  .app-topbar {
    padding: 0.6rem 1rem;
    gap: 0.75rem;
  }
  .app-main {
    padding: 1.25rem;
  }
}

@media (max-width: 575.98px) {
  .app-main {
    padding: 1rem;
  }
}

/* A left panel squeezed next to an expanded sidebar is too narrow to use, so
   the two-panel detail pages stack until the rail frees up the room. */
@media (min-width: 992px) and (max-width: 1199.98px) {
  html:not(.sidebar-collapsed) .app-main .row > .col-lg-5,
  html:not(.sidebar-collapsed) .app-main .row > .col-lg-7 {
    flex: 0 0 100%;
    width: 100%;
  }
}

/* =========================================================================
   Page header component
   ========================================================================= */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-header > div:first-child {
  min-width: 0;
}
.page-header h1 {
  font-size: 1.5rem;
  margin-bottom: 0.2rem;
}

/* =========================================================================
   Responsive page content. Everything here is shared so that views stay free
   of per-page breakpoints.
   ========================================================================= */

/* A long client name or email breaks rather than widening the page */
.app-main h1,
.app-main p,
.app-main dt,
.app-main dd,
.app-main .breadcrumb-item,
.modal-body {
  overflow-wrap: anywhere;
}

/* Section headers and button rows wrap. Plain .d-flex rows are left alone: an
   input at width 100% would drop its button to a new line at every width. */
.app-main .d-flex.justify-content-between:not(li),
.app-main .d-flex.justify-content-between:not(li) > .d-flex,
.app-main .d-flex.justify-content-end,
.app-main .mt-4.d-flex {
  flex-wrap: wrap;
  gap: 0.5rem;
}

.app-main .d-flex > .form-control {
  min-width: 0;
}
.app-main .d-flex.justify-content-between:not(li) > .d-flex > .form-select {
  width: auto;
}

/* Tab strips (Company Profile) wrap onto further rows: nothing scrolls sideways */
.nav-tabs {
  flex-wrap: wrap;
}
.nav-tabs .nav-link {
  white-space: nowrap;
}

/* A .row straight inside a tab pane would poke its negative margin out of the pane */
.tab-content > .tab-pane > .row {
  margin-left: 0;
  margin-right: 0;
}

/* Phone number rows: region and number, then label and the two buttons */
.phone-row-narrow {
  max-width: 9rem;
}
@media (max-width: 767.98px) {
  .phone-row-input-group {
    flex-wrap: wrap;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-warm);
  }
  .phone-row-input-group > [data-primary-badge] {
    flex: 0 0 auto;
    margin-right: 100%;
  }
  .phone-row-input-group > .form-control,
  .phone-row-input-group > .form-select {
    flex: 1 1 40%;
    max-width: none;
    min-width: 0;
  }
  /* Filter bars: two to a row, not one long column above the list */
  .card:has([data-filter-key]) .row > [class*="col-md-"] {
    flex: 0 0 50%;
    width: 50%;
  }
  .card:has([data-filter-key]) .form-select {
    padding-left: 0.5rem;
    padding-right: 1.5rem;
    background-position: right 0.35rem center;
    text-overflow: ellipsis;
  }
  /* Status count strips (Leads) */
  .row > .col {
    flex: 1 0 33.333%;
  }
}

/* =========================================================================
   Stat cards (dashboard)
   ========================================================================= */
.stat-card {
  background: #fff;
  border: 1px solid var(--border-warm);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: 100%;
}
.stat-card .stat-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--indigo-50);
  color: var(--brand-indigo);
  font-size: 1.1rem;
}
.stat-card .stat-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stat-card .stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--brand-ink);
}

/* =========================================================================
   Icon action buttons (edit/delete in tables)
   ========================================================================= */
.icon-action-btn {
  font-size: 1rem;
  width: 2.1rem;
  height: 2.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-warm);
  background: #fff;
  color: var(--brand-indigo);
}
.icon-action-btn:hover {
  background-color: var(--indigo-50);
}
.icon-action-btn.danger {
  color: var(--color-danger);
}
.icon-action-btn.danger:hover {
  background-color: var(--color-danger-bg);
}

/* =========================================================================
   Login
   ========================================================================= */
.login-page {
  min-height: 100vh;
  display: flex;
}

.login-brand-panel {
  flex: 1 1 45%;
  /* Solid indigo plus a faint diagonal stripe. The stripe lives on this panel only: the sidebar and top bar stay plain. */
  background-color: var(--brand-indigo);
  background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0 2px, transparent 2px 42px);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem;
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.login-brand-content {
  width: 100%;
  max-width: 28rem;
  margin: 0 auto;
}
/* Natural aspect ratio: only the height is set; contain stops any squeeze if max-width ever clamps the width */
.login-logo {
  display: block;
  flex: 0 0 auto;
  height: 4.5rem;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: left center;
  margin-bottom: 1.75rem;
}
.login-wordmark {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.75rem;
  min-width: 0;
}
.login-mark {
  flex: 0 0 auto;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: var(--radius-sm);
  background: var(--brand-terracotta);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 800;
}
.login-brand-panel .wordmark {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  min-width: 0;
  overflow-wrap: anywhere;
}
.login-brand-panel .tagline {
  font-size: 1.05rem;
  line-height: 1.55;
  color: rgba(246, 243, 236, 0.8);
  max-width: 26rem;
  margin: 0 0 1.75rem;
  padding-top: 1.25rem;
  border-top: 3px solid var(--brand-terracotta);
}
.login-points {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.85rem;
}
.login-points li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.95rem;
  color: rgba(246, 243, 236, 0.9);
}
.login-points i {
  flex: 0 0 auto;
  color: #e08a63;
  font-size: 1.1rem;
}

.login-form-panel {
  flex: 1 1 55%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--surface-page);
  padding: 2rem;
}

.login-card {
  width: 100%;
  max-width: 24rem;
}

.password-toggle {
  border: 1px solid var(--border-warm);
  border-left: none;
  background: #fff;
  color: var(--text-muted);
  min-width: 2.5rem;
}

@media (max-width: 991.98px) {
  .login-brand-panel { padding: 2rem; }
}

@media (max-width: 767.98px) {
  .login-page {
    flex-direction: column;
  }
  .login-brand-panel {
    flex: 0 0 auto;
    padding: 2rem 1.5rem;
  }
  .login-brand-content { max-width: none; }
  .login-logo { height: 3.5rem; margin-bottom: 1rem; }
  .login-wordmark { margin-bottom: 1rem; }
  .login-brand-panel .tagline { margin-bottom: 0; }
  .login-points { display: none; }
  .login-form-panel {
    flex: 1 1 auto;
  }
}

@media (max-width: 575.98px) {
  .login-brand-panel {
    padding: 1.25rem 1rem;
  }
  .login-logo { height: 2.75rem; margin-bottom: 0; }
  .login-wordmark { margin-bottom: 0; }
  .login-mark { width: 2.5rem; height: 2.5rem; font-size: 1rem; }
  .login-brand-panel .wordmark {
    font-size: 1.5rem;
  }
  .login-brand-panel .tagline { display: none; }
  .login-form-panel {
    align-items: flex-start;
    padding: 1.5rem 1rem;
  }
}

/* =========================================================================
   Toasts (flash messages)
   ========================================================================= */
/* Below the top bar, so a toast never sits on the menu button or user menu */
.app-main .toast-container {
  margin-top: 3.5rem;
}
.toast {
  --bs-toast-bg: #fff;
  max-width: calc(100vw - 2rem);
  box-shadow: var(--shadow-pop);
}
.toast-success { border-left: 4px solid var(--color-success); }
.toast-danger { border-left: 4px solid var(--color-danger); }
.toast-info { border-left: 4px solid var(--brand-indigo); }
.toast-warning { border-left: 4px solid var(--color-warning); }

/* =========================================================================
   DataTables layout: the controls wrap and the table fits (see
   configureDataTableDefaults in site.js)
   ========================================================================= */
.dt-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
}
.dt-table-scroll {
  min-width: 0;
}
.dt-table-scroll > table.dataTable {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}
.dataTables_wrapper .dt-controls .dataTables_info {
  padding-top: 0;
}
.dataTables_wrapper .dt-controls .dataTables_paginate {
  max-width: 100%;
  white-space: normal;
}
.dataTables_wrapper .dt-controls .pagination {
  flex-wrap: wrap;
  margin: 0;
}
@media (max-width: 575.98px) {
  /* Search and paging take a full line each, so nothing is squeezed */
  .dt-controls {
    padding: 0.75rem;
  }
  .dataTables_wrapper .dt-controls .dataTables_filter,
  .dataTables_wrapper .dt-controls .dataTables_filter label,
  .dataTables_wrapper .dt-controls .dataTables_paginate {
    width: 100%;
  }
  .dataTables_wrapper .dt-controls .dataTables_filter label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }
  .dataTables_wrapper .dt-controls .dataTables_filter input {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    margin-left: 0;
  }
}

/* =========================================================================
   DataTables theming
   ========================================================================= */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  border: 1px solid var(--border-warm);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.6rem;
}
.dataTables_wrapper .dataTables_length select {
  padding-right: 1.75rem;
}
.dataTables_wrapper .dataTables_filter input:focus {
  outline: none;
  box-shadow: 0 0 0 0.2rem var(--bs-focus-ring-color);
  border-color: var(--brand-terracotta);
}
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
  color: var(--text-muted);
  font-size: 0.875rem;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.65rem;
  margin-left: 0.15rem;
  color: var(--brand-indigo) !important;
  border: 1px solid transparent !important;
  background: transparent !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--indigo-50) !important;
  color: var(--brand-indigo) !important;
  border-color: var(--indigo-100) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
  color: var(--text-muted) !important;
  opacity: 0.5;
}
table.dataTable thead .sorting:after,
table.dataTable thead .sorting_asc:after,
table.dataTable thead .sorting_desc:after {
  opacity: 0.5;
}

/* Typeahead (clients, tags, ambiguous-client resolution) */
.typeahead-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1055;
  max-height: 16rem;
  overflow-x: hidden;
  overflow-y: auto;
  display: none;
}
.typeahead-menu.show {
  display: block;
}
.typeahead-secondary {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.dropdown-item.active .typeahead-secondary {
  color: inherit;
  opacity: 0.85;
}

/* Tag picker chips (Contact tags) */
.tag-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--indigo-50);
  color: var(--brand-indigo);
  font-size: 0.8125rem;
  font-weight: 500;
}
.tag-chip-remove {
  border: none;
  background: transparent;
  color: inherit;
  line-height: 1;
  padding: 0;
  font-size: 1rem;
  cursor: pointer;
}

/* =========================================================================
   Touch targets: about 40px on touch screens and on narrow windows. Kept last
   so these sizes win over the component rules above.
   ========================================================================= */
@media (pointer: coarse), (max-width: 991.98px) {
  .btn,
  .form-control,
  .form-select,
  .page-link,
  .user-menu-toggle,
  .nav-tabs .nav-link {
    min-height: 2.5rem;
  }
  /* iOS zooms the whole page into any input smaller than 16px */
  .form-control-sm,
  .form-select-sm {
    font-size: 1rem;
  }
  .icon-action-btn {
    width: 2.5rem;
    height: 2.5rem;
  }
  .icon-action-btn + .icon-action-btn {
    margin-left: 0.25rem;
  }
  .table-fit .table:has(.icon-action-btn) > tbody > tr {
    height: 3.1rem;
  }
  .fc-act-1, .fc-act-2, .fc-act-3, .fc-act-4, .fc-act-5 {
    --act-size: 2.5rem;
    --act-gap: 0.25rem;
  }
  .app-sidebar .nav-link {
    min-height: 2.75rem;
  }
  .btn-close {
    padding: 0.75rem;
  }
  .dropdown-item {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
  }
  .form-check {
    min-height: 2rem;
  }
  .form-check-input {
    width: 1.25rem;
    height: 1.25rem;
  }
  .tag-chip-remove {
    min-width: 1.75rem;
    min-height: 1.75rem;
  }
  .page-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
  }
}

/* =========================================================================
   Reports and dashboard finance (Phase 5)
   ========================================================================= */
/* Explanatory notes under report filters and figures */
.report-note {
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.report-note .bi {
  margin-right: 0.15rem;
}
/* Money in a stat tile: smaller than a count, and allowed to break rather than push the page sideways */
.stat-card .stat-value-money {
  font-size: clamp(1.1rem, 1rem + 1vw, 1.45rem);
  overflow-wrap: anywhere;
  line-height: 1.2;
}
/* A whole tile that links to its report */
a.stat-card-link {
  color: inherit;
  text-decoration: none;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
a.stat-card-link:hover,
a.stat-card-link:focus-visible {
  border-color: var(--brand-indigo);
  box-shadow: var(--shadow-pop);
}
/* Chart.js canvases: responsive inside a fixed-height box, never wider than their column */
.chart-box {
  position: relative;
  width: 100%;
  min-width: 0;
  height: 260px;
  overflow: hidden;
}
.min-w-0 {
  min-width: 0;
}
/* Report tables use tfoot for totals */
.table-fit .table > tfoot > tr > td {
  border-top: 2px solid var(--border-warm);
}
/* A small text flag inside a report cell ("rate missing", "Overdue", "now"). Unlike .badge-status it adds no
   vertical padding, so a row that has one stays the same height as its neighbours. The word is always shown,
   so the flag never relies on colour alone. */
.report-flag {
  display: inline;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 0 0.3rem;
  border-radius: 0.25rem;
  white-space: nowrap;
  vertical-align: baseline;
}
.report-flag-warning { color: var(--color-warning-text); background-color: var(--color-warning-bg); }
.report-flag-danger { color: var(--color-danger-text); background-color: var(--color-danger-bg); }
.report-flag-info { color: var(--color-info-text); background-color: var(--color-info-bg); }
/* Report tables: slightly smaller, tabular figures so long amounts with their currency code fit the money columns
   (anything longer still truncates with a tooltip, as in every list). */
.table-fit .report-table {
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}
/* Under 520px a report table shows one money column (the key amount), so it can take more of the width. */
@container (max-width: 519.98px) {
  .table-fit .report-table .fc-money { width: 10.5rem; }
}
/* A money column whose figures run long (signed P&L running totals and margins). The tables that use it keep few
   such columns visible at each width (see the cp-N classes on those pages), so it fits at every width. */
.fc-money-lg { width: 10.5rem; }

/* Website enquiries (SPEC.md 6c): submitted text is plain text; a message keeps its line breaks and is never HTML */
.ws-message {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ws-details dd {
  overflow-wrap: anywhere;
}
