/* The look of every page, on top of Bootstrap 5.3 (D-111). Flat colours only: no gradients anywhere.
   Light and dark are two palettes chosen on purpose, not one inverted. Colours are tokens below; the rest of the file
   uses them. static/js/theme.js sets data-bs-theme on <html> to "light" or "dark" (System follows the phone/computer).
   D-111 update: deep green and near-black ink, in the Material 3 manner Google Stitch uses: depth from tinted surfaces and
   hairlines instead of shadows, a pale "container" tint for the chosen thing, rounder corners. */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../fonts/inter-latin-wght-normal.woff2") format("woff2-variations"), url("../fonts/inter-latin-wght-normal.woff2") format("woff2");
}

/* ---------------------------------------------------------------- tokens: light */
:root, [data-bs-theme=light] {
  --app-canvas: #f3f5f2;            /* page behind the cards: a grey with a little green in it */
  --app-hover: #e3f1e9;             /* hovered or chosen row in a list */
  --app-highlight: #fdecb5;         /* matched words in search */
  --app-sidebar-w: 15.5rem;

  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bs-body-color: #17201b;
  --bs-body-color-rgb: 23, 32, 27;
  --bs-body-bg: #ffffff;            /* cards, menus, the top bar, the side menu */
  --bs-body-bg-rgb: 255, 255, 255;
  --bs-emphasis-color: #0b130f;
  --bs-emphasis-color-rgb: 11, 19, 15;
  --bs-secondary-color: rgba(23, 32, 27, .66);
  --bs-secondary-color-rgb: 23, 32, 27;
  --bs-secondary-bg: #e7ece8;
  --bs-tertiary-bg: #f6f8f6;
  --bs-border-color: #dde3de;
  --bs-border-color-translucent: rgba(13, 38, 25, .10);
  --bs-heading-color: #0b130f;
  --bs-code-color: #3c4a42;         /* M-Pesa codes and references: quiet, not pink */

  --bs-primary: #146c4a;
  --bs-primary-rgb: 20, 108, 74;
  --bs-primary-text-emphasis: #0b4a32;
  --bs-primary-bg-subtle: #dff1e7;  /* the "container" tint: chosen menu item, selected chips */
  --bs-primary-border-subtle: #a9d6bd;
  --bs-link-color: #0f6242;
  --bs-link-color-rgb: 15, 98, 66;
  --bs-link-hover-color: #0b4a32;
  --bs-link-hover-color-rgb: 11, 74, 50;
  --bs-focus-ring-color: rgba(20, 108, 74, .28);

  /* Information banners: a quiet blue tint, not Bootstrap's bright cyan */
  --bs-info-text-emphasis: #0b4a6e;
  --bs-info-bg-subtle: #e8f2f9;
  --bs-info-border-subtle: #c2dbee;

  --bs-box-shadow-sm: none;         /* cards are flat: a hairline on the tinted page is enough */
  --bs-box-shadow: 0 6px 20px rgba(13, 38, 25, .10);
  --bs-border-radius-sm: .5rem;
  --bs-border-radius: .625rem;
  --bs-border-radius-lg: 1rem;

  /* Primary button: white text at 6.4:1 */
  --app-btn: #146c4a;
  --app-btn-hover: #0f5c3e;
  --app-btn-active: #0b4a32;
  --app-btn-text: #ffffff;
  /* Dark button (one per page at most, used for "the main thing to do now") */
  --app-ink: #17201b;
  --app-ink-hover: #0b130f;
  --app-ink-text: #ffffff;

  /* Charts (checked for colour-blind separation and contrast): series 1-3, a pale partner of series 1,
     and how late money is, from just due to very late. Green, amber and blue also differ in lightness. */
  --chart-1: #1a7f56;
  --chart-1-soft: #b5dcc6;
  --chart-2: #d97706;
  --chart-3: #2563eb;
  --chart-4: #d6457f;
  --chart-5: #6d4fc9;
  --chart-neutral: #a3aba6;         /* the middle of a good-to-bad scale, and "other" */
  --chart-late-1: #f2a07b;
  --chart-late-2: #e0603a;
  --chart-late-3: #b83a1b;
  --chart-late-4: #7f230e;
  --chart-text: #59615c;
  --chart-grid: rgba(13, 38, 25, .08);
}

/* ---------------------------------------------------------------- tokens: dark */
[data-bs-theme=dark] {
  color-scheme: dark;
  --app-canvas: #0f1411;            /* never pure black */
  --app-hover: #1b2e24;
  --app-highlight: #5c4813;

  --bs-body-color: #dfe5e0;
  --bs-body-color-rgb: 223, 229, 224;
  --bs-body-bg: #171d1a;            /* surfaces are lighter than the page, instead of shadows */
  --bs-body-bg-rgb: 23, 29, 26;
  --bs-emphasis-color: #ffffff;
  --bs-emphasis-color-rgb: 255, 255, 255;
  --bs-secondary-color: rgba(223, 229, 224, .68);
  --bs-secondary-color-rgb: 223, 229, 224;
  --bs-secondary-bg: #252c28;
  --bs-tertiary-bg: #1c231f;
  --bs-border-color: #2b3530;
  --bs-border-color-translucent: rgba(255, 255, 255, .08);
  --bs-heading-color: #eef3ef;
  --bs-code-color: #bfc9c2;

  /* As in Material 3 dark: the accent is a light tone with dark text on it, so it does not glare. */
  --bs-primary: #5cc290;
  --bs-primary-rgb: 92, 194, 144;
  --bs-primary-text-emphasis: #b4ebce;
  --bs-primary-bg-subtle: #12301f;
  --bs-primary-border-subtle: #23573c;
  --bs-link-color: #7fd6aa;
  --bs-link-color-rgb: 127, 214, 170;
  --bs-link-hover-color: #b4ebce;
  --bs-link-hover-color-rgb: 180, 235, 206;
  --bs-focus-ring-color: rgba(127, 214, 170, .35);

  /* Colours on a dark page are a little softer, so they do not glare. */
  --bs-success-text-emphasis: #6ee7b7;
  --bs-success-bg-subtle: #0f2a22;
  --bs-success-border-subtle: #1d4f40;
  --bs-warning-text-emphasis: #fcd34d;
  --bs-warning-bg-subtle: #2e2510;
  --bs-warning-border-subtle: #5c4813;
  --bs-danger-text-emphasis: #fca5a5;
  --bs-danger-bg-subtle: #2f1517;
  --bs-danger-border-subtle: #5e2a2e;
  --bs-info-text-emphasis: #7dd3fc;
  --bs-info-bg-subtle: #0f2533;
  --bs-info-border-subtle: #1e4a63;

  --bs-box-shadow-sm: none;         /* depth comes from the lighter surface and its border */
  --bs-box-shadow: 0 8px 24px rgba(0, 0, 0, .45);

  --app-btn: #6fd3a1;               /* dark text on it at 8.7:1 */
  --app-btn-hover: #8be0b5;
  --app-btn-active: #5cc290;
  --app-btn-text: #05281a;
  --app-ink: #dfe5e0;
  --app-ink-hover: #ffffff;
  --app-ink-text: #0f1411;

  --chart-1: #3fa673;
  --chart-1-soft: #24503a;
  --chart-2: #c2850e;
  --chart-3: #4a8ae0;
  --chart-4: #d9578b;
  --chart-5: #8c74e6;
  --chart-neutral: #66706a;
  --chart-late-1: #f4b08f;
  --chart-late-2: #e2774d;
  --chart-late-3: #c4532a;
  --chart-late-4: #9a3519;
  --chart-text: #a3aca6;
  --chart-grid: rgba(255, 255, 255, .08);
}

/* ---------------------------------------------------------------- base */
body { background: var(--app-canvas); font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, .h1, .h2, .h3, .h4 { letter-spacing: -.018em; font-weight: 650; }
h5, h6, .h5, .h6 { font-weight: 600; }
.page { max-width: 960px; }
.page.page-wide { max-width: 1240px; }
/* Long codes, emails and links break instead of pushing a phone screen sideways. */
main { overflow-wrap: break-word; }
.narrow { max-width: 440px; }
.num, .table td.text-end { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--bs-link-color); outline-offset: 2px; }
.btn:focus-visible, .form-control:focus-visible, .form-select:focus-visible { outline: 0; }
::selection { background: var(--bs-primary-bg-subtle); color: var(--bs-emphasis-color); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

/* ---------------------------------------------------------------- the frame: side menu on a laptop, top bar on a phone */
@media (min-width: 992px) {
  .app-shell.has-sidebar { display: flex; align-items: flex-start; }
  .has-sidebar .app-body { flex: 1 1 auto; min-width: 0; }
  .has-sidebar .page { max-width: 1120px; }
}
.app-sidebar { position: sticky; top: 0; width: var(--app-sidebar-w); flex: 0 0 var(--app-sidebar-w); height: 100vh; overflow-y: auto;
               padding: 1rem .75rem 1.5rem; background: var(--bs-body-bg); border-right: 1px solid var(--bs-border-color); }
.app-brand { display: flex; align-items: center; gap: .5rem; padding: .25rem .75rem 1rem; color: var(--bs-emphasis-color);
             font-weight: 700; letter-spacing: -.02em; text-decoration: none; }
.app-brand:hover { color: var(--bs-emphasis-color); }
.app-brand-mark { display: inline-grid; place-items: center; width: 1.75rem; height: 1.75rem; border-radius: .5rem;
                  background: var(--app-btn); color: var(--app-btn-text); font-size: .95rem; }
.app-nav-label { padding: 1rem .75rem .35rem; font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
                 color: var(--bs-secondary-color); }
.app-nav { list-style: none; margin: 0; padding: 0; }
.app-nav-link { display: flex; align-items: center; gap: .65rem; padding: .45rem .75rem; border-radius: 999px; font-size: .9rem;
                color: var(--bs-body-color); text-decoration: none; }
.app-nav-link .bi { font-size: 1rem; color: var(--bs-secondary-color); }
.app-nav-link:hover { background: var(--bs-secondary-bg); color: var(--bs-emphasis-color); }
.app-nav-link.active { background: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis); font-weight: 600; }
.app-nav-link.active .bi { color: inherit; }

/* Top bar */
.navbar { --bs-navbar-brand-color: var(--bs-emphasis-color); --bs-navbar-brand-hover-color: var(--bs-emphasis-color); }
.navbar-brand { letter-spacing: -.02em; display: inline-flex; align-items: center; gap: .5rem; }
.navbar .nav-link.active { color: var(--bs-emphasis-color); font-weight: 500; }

/* Page title row: title and its one or two main buttons */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head h1 { margin-bottom: 0; }
.page-head form .form-select, .page-head form .form-control { width: auto; max-width: 100%; }
.page-head .lead-text { color: var(--bs-secondary-color); font-size: .875rem; margin: .15rem 0 0; }

/* Cards: flat, a hairline border and rounder corners. */
.card { --bs-card-border-color: var(--bs-border-color); --bs-card-cap-bg: var(--bs-tertiary-bg);
        --bs-card-border-radius: var(--bs-border-radius-lg); --bs-card-inner-border-radius: calc(var(--bs-border-radius-lg) - 1px); }
.card-title-sm { font-size: .8rem; font-weight: 600; letter-spacing: .02em; color: var(--bs-secondary-color); margin-bottom: .5rem; }

/* Figure tiles: a label, a big number, a line of context */
.stat { height: 100%; padding: 1rem; background: var(--bs-body-bg); border: 1px solid var(--bs-border-color); border-radius: var(--bs-border-radius-lg); }
.stat-label { font-size: .8rem; color: var(--bs-secondary-color); }
.stat-value { font-size: clamp(1.1rem, .9rem + .55vw, 1.4rem); font-weight: 650; letter-spacing: -.02em; line-height: 1.3; font-variant-numeric: tabular-nums; color: var(--bs-emphasis-color); }
.stat-note { font-size: .8rem; }
.stat .spark { display: block; width: 100%; height: 28px; margin: .35rem 0 .15rem; overflow: visible; }
.spark polyline { fill: none; stroke: var(--chart-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round;
                  vector-effect: non-scaling-stroke; }
.stat-bad .spark polyline { stroke: var(--chart-late-2); }

/* The reports dashboard (D-113): a section menu, a highlights card, and charts in cards with their table below. */
.report-nav { position: sticky; top: 0; z-index: 5; display: flex; gap: .35rem; overflow-x: auto; padding: .5rem 0; margin-bottom: 1rem;
              background: var(--app-canvas); scrollbar-width: none; }
.report-nav a { flex: 0 0 auto; padding: .3rem .8rem; border-radius: 999px; font-size: .85rem; color: var(--bs-body-color);
                text-decoration: none; border: 1px solid var(--bs-border-color); background: var(--bs-body-bg); }
.report-nav a:hover { background: var(--app-hover); border-color: var(--bs-primary-border-subtle); }
.report-section { scroll-margin-top: 3.5rem; margin-bottom: 2rem; }
.report-section > h2 { font-size: 1.05rem; margin-bottom: .2rem; }
.report-section > .section-lead { font-size: .85rem; color: var(--bs-secondary-color); margin-bottom: .9rem; }
.chart-card { height: 100%; display: flex; flex-direction: column; padding: 1rem 1rem .75rem; background: var(--bs-body-bg);
              border: 1px solid var(--bs-border-color); border-radius: var(--bs-border-radius-lg); }
.chart-card h3 { font-size: .9rem; font-weight: 600; margin: 0; color: var(--bs-emphasis-color); }
.chart-card .chart-sub { font-size: .8rem; color: var(--bs-secondary-color); margin: .1rem 0 .6rem; }
.chart-card .chart-figure { font-size: 1.35rem; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums;
                            color: var(--bs-emphasis-color); line-height: 1.2; }
.chart-box { position: relative; flex: 1 1 auto; min-height: 220px; }
.chart-box.h-sm { min-height: 180px; }
.chart-box.h-lg { min-height: 300px; }
.chart-box.donut { flex: 0 0 auto; height: 190px; min-height: 0; }
.chart-card details { margin-top: .6rem; font-size: .8rem; }
.chart-card details summary { color: var(--bs-secondary-color); cursor: pointer; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin: 0 0 .5rem; padding: 0; list-style: none; font-size: .8rem;
                color: var(--bs-secondary-color); }
.chart-legend .key { display: inline-block; width: .65rem; height: .65rem; margin-right: .35rem; border-radius: 2px; vertical-align: -.05rem; }
.chart-legend .key-line { height: 2px; width: .9rem; border-radius: 1px; vertical-align: .2rem; }
.highlights { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem 1.5rem; grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr)); }
.highlights li { display: flex; gap: .6rem; align-items: flex-start; font-size: .875rem; }
.highlights .bi { flex: 0 0 auto; font-size: 1rem; line-height: 1.3; }
.hl-good .bi { color: var(--bs-success-text-emphasis); }
.hl-bad .bi { color: var(--bs-danger-text-emphasis); }
.hl-note .bi { color: var(--bs-info-text-emphasis); }
.bar-cell { display: flex; align-items: center; gap: .5rem; }
.bar-cell .bar-track { flex: 1 1 auto; height: 6px; border-radius: 3px; background: var(--bs-secondary-bg); overflow: hidden; }
.bar-cell .bar-fill { height: 100%; border-radius: 3px; background: var(--chart-late-2); }
/* Payment charts across the app (D-114): progress rings drawn on the server, and a month-by-month strip. */
.ring { position: relative; display: inline-grid; place-items: center; flex: 0 0 auto; width: 4.5rem; height: 4.5rem; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.4; }
.ring-track { stroke: var(--bs-secondary-bg); }
.ring-arc { stroke: var(--chart-1); stroke-linecap: round; }
.ring-bad .ring-arc { stroke: var(--chart-late-2); }
.ring-value { position: absolute; font-size: .95rem; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums;
              color: var(--bs-emphasis-color); }
.ring-sm { width: 3.25rem; height: 3.25rem; }
.ring-sm .ring-value { font-size: .75rem; }
.ring-stat { display: flex; align-items: center; gap: .9rem; }
.ring-stat .ring-text { min-width: 0; }
.month-strip { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; margin: 0; padding: 0; list-style: none; }
.month-strip li { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .7rem; color: var(--bs-secondary-color); }
.month-strip .ms-bar { position: relative; width: 100%; max-width: 1.6rem; height: 3.5rem; border-radius: 4px; overflow: hidden;
                       background: var(--bs-secondary-bg); }
.month-strip .ms-none .ms-bar { background: transparent; border: 1px dashed var(--bs-border-color); }
.month-strip .ms-fill { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 4px 4px 0 0; background: var(--chart-1); }
.month-strip .ms-late .ms-fill { background: var(--chart-late-1); }
.month-strip .ms-part .ms-fill { background: var(--chart-late-2); }
.month-strip .ms-unpaid .ms-bar { box-shadow: inset 0 0 0 2px var(--chart-late-4); }
.month-strip .ms-due .ms-fill { background: var(--chart-neutral); }
.month-strip .ms-mark { font-weight: 600; line-height: 1; min-height: .8rem; color: var(--bs-body-color); }
.chart-legend .key-paid { background: var(--chart-1); }
.chart-legend .key-late { background: var(--chart-late-1); }
.chart-legend .key-part { background: var(--chart-late-2); }
.chart-legend .key-unpaid { background: var(--chart-late-4); }
.chart-legend .key-due { background: var(--chart-neutral); }
.chart-legend .key-billed { background: var(--chart-1-soft); }
@media print {
  .report-nav, .report-actions, .page-head form { display: none !important; }
  .report-section { break-inside: avoid-page; }
  .chart-card details { display: none; }
  .chart-card, .stat { break-inside: avoid; box-shadow: none !important; }
  .table-responsive { overflow: visible !important; }
  tr { break-inside: avoid; }
  thead { display: table-header-group; }
}

/* Shortcut tiles on Home */
.tile { display: flex; align-items: center; gap: .85rem; height: 100%; padding: .9rem 1rem; color: var(--bs-body-color); text-decoration: none;
        background: var(--bs-body-bg); border: 1px solid var(--bs-border-color); border-radius: var(--bs-border-radius-lg); }
.tile:hover { border-color: var(--bs-primary-border-subtle); background: var(--app-hover); color: var(--bs-emphasis-color); }
.tile-icon { display: inline-grid; place-items: center; flex: 0 0 2.5rem; width: 2.5rem; height: 2.5rem; border-radius: .75rem;
             background: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis); font-size: 1.15rem; }
.tile-title { font-weight: 600; color: var(--bs-emphasis-color); }
.tile-text { font-size: .8rem; color: var(--bs-secondary-color); }

/* Work lists (Today on Home): a count, then the link */
.task-count { display: inline-grid; place-items: center; min-width: 1.9rem; height: 1.6rem; padding: 0 .45rem; border-radius: 999px;
              background: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis); font-size: .8rem; font-weight: 650;
              font-variant-numeric: tabular-nums; }
.progress-thin { height: .375rem; }
.step-done { color: var(--bs-success-text-emphasis); }
.step-todo { color: var(--bs-secondary-color); }

.dropdown-menu { --bs-dropdown-border-color: var(--bs-border-color); --bs-dropdown-box-shadow: var(--bs-box-shadow);
                 --bs-dropdown-border-radius: var(--bs-border-radius-lg);
                 --bs-dropdown-link-active-bg: var(--bs-primary-bg-subtle); --bs-dropdown-link-active-color: var(--bs-primary-text-emphasis);
                 --bs-dropdown-link-hover-bg: var(--bs-tertiary-bg); box-shadow: var(--bs-dropdown-box-shadow); }
.table { --bs-table-hover-bg: var(--bs-tertiary-bg); --bs-table-striped-bg: var(--bs-tertiary-bg); }
.table > thead th { color: var(--bs-secondary-color); font-weight: 500; font-size: .8rem; }
.badge { font-weight: 600; }

/* ---------------------------------------------------------------- primary colour where Bootstrap compiled it in */
.btn { --bs-btn-font-weight: 500; }
.btn-primary {
  --bs-btn-color: var(--app-btn-text); --bs-btn-bg: var(--app-btn); --bs-btn-border-color: var(--app-btn);
  --bs-btn-hover-color: var(--app-btn-text); --bs-btn-hover-bg: var(--app-btn-hover); --bs-btn-hover-border-color: var(--app-btn-hover);
  --bs-btn-active-color: var(--app-btn-text); --bs-btn-active-bg: var(--app-btn-active); --bs-btn-active-border-color: var(--app-btn-active);
  --bs-btn-disabled-color: var(--app-btn-text); --bs-btn-disabled-bg: var(--app-btn); --bs-btn-disabled-border-color: var(--app-btn);
  --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn-outline-primary {
  --bs-btn-color: var(--bs-link-color); --bs-btn-border-color: var(--bs-primary-border-subtle);
  --bs-btn-hover-color: var(--app-btn-text); --bs-btn-hover-bg: var(--app-btn); --bs-btn-hover-border-color: var(--app-btn);
  --bs-btn-active-color: var(--app-btn-text); --bs-btn-active-bg: var(--app-btn-active); --bs-btn-active-border-color: var(--app-btn-active);
  --bs-btn-disabled-color: var(--bs-link-color); --bs-btn-disabled-border-color: var(--bs-primary-border-subtle);
  --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn-dark {
  --bs-btn-color: var(--app-ink-text); --bs-btn-bg: var(--app-ink); --bs-btn-border-color: var(--app-ink);
  --bs-btn-hover-color: var(--app-ink-text); --bs-btn-hover-bg: var(--app-ink-hover); --bs-btn-hover-border-color: var(--app-ink-hover);
  --bs-btn-active-color: var(--app-ink-text); --bs-btn-active-bg: var(--app-ink-hover); --bs-btn-active-border-color: var(--app-ink-hover);
  --bs-btn-disabled-color: var(--app-ink-text); --bs-btn-disabled-bg: var(--app-ink); --bs-btn-disabled-border-color: var(--app-ink);
}
.btn-outline-dark {
  --bs-btn-color: var(--bs-emphasis-color); --bs-btn-border-color: var(--bs-border-color);
  --bs-btn-hover-color: var(--app-ink-text); --bs-btn-hover-bg: var(--app-ink); --bs-btn-hover-border-color: var(--app-ink);
  --bs-btn-active-color: var(--app-ink-text); --bs-btn-active-bg: var(--app-ink-hover); --bs-btn-active-border-color: var(--app-ink-hover);
}
.btn-outline-secondary { --bs-btn-color: var(--bs-body-color); --bs-btn-bg: var(--bs-body-bg); --bs-btn-border-color: var(--bs-border-color);
                         --bs-btn-hover-bg: var(--bs-secondary-bg); --bs-btn-hover-color: var(--bs-emphasis-color);
                         --bs-btn-hover-border-color: var(--bs-border-color);
                         --bs-btn-active-bg: var(--bs-secondary-bg); --bs-btn-active-color: var(--bs-emphasis-color);
                         --bs-btn-active-border-color: var(--bs-border-color); }
.btn-light { --bs-btn-color: var(--bs-body-color); --bs-btn-bg: var(--bs-tertiary-bg); --bs-btn-border-color: var(--bs-border-color);
             --bs-btn-hover-color: var(--bs-emphasis-color); --bs-btn-hover-bg: var(--bs-secondary-bg); --bs-btn-hover-border-color: var(--bs-border-color); }
.form-control, .form-select { border-color: var(--bs-border-color); }
.form-control:focus, .form-select:focus, .form-check-input:focus {
  border-color: var(--bs-primary-border-subtle); box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color);
}
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary-bg-subtle); --bs-nav-pills-link-active-color: var(--bs-primary-text-emphasis);
             --bs-nav-pills-border-radius: 999px; }
.nav-pills .nav-link.active { font-weight: 600; }
.nav { --bs-nav-link-color: var(--bs-link-color); --bs-nav-link-hover-color: var(--bs-link-hover-color); }
.navbar-nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-color: var(--bs-link-color); --bs-pagination-active-bg: var(--app-btn); --bs-pagination-active-color: var(--app-btn-text);
              --bs-pagination-active-border-color: var(--app-btn); --bs-pagination-focus-box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color);
              --bs-pagination-hover-color: var(--bs-link-hover-color); --bs-pagination-focus-color: var(--bs-link-hover-color); }
.list-group { --bs-list-group-active-bg: var(--bs-primary-bg-subtle); --bs-list-group-active-color: var(--bs-primary-text-emphasis);
              --bs-list-group-active-border-color: var(--bs-primary-border-subtle); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); --bs-progress-bg: var(--bs-secondary-bg); }
.accordion { --bs-accordion-btn-focus-box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color); }
.text-bg-primary { color: var(--app-btn-text) !important; background-color: var(--app-btn) !important; }

/* ---------------------------------------------------------------- dark-only fixes for light/dark utility classes */
[data-bs-theme=dark] .text-bg-light { color: var(--bs-body-color) !important; background-color: var(--bs-secondary-bg) !important; }
[data-bs-theme=dark] .text-bg-dark { color: var(--app-ink-text) !important; background-color: var(--app-ink) !important; }
[data-bs-theme=dark] .table-light { --bs-table-color: var(--bs-body-color); --bs-table-bg: var(--bs-tertiary-bg);
                                     --bs-table-border-color: var(--bs-border-color); }
/* Red and green figures stay at 4.5:1 or more on a dark card. */
[data-bs-theme=dark] .text-danger { color: #f87171 !important; }
[data-bs-theme=dark] .text-success { color: #4ade80 !important; }
[data-bs-theme=dark] .text-bg-warning { background-color: #e0b13a !important; }
[data-bs-theme=dark] .text-bg-info { background-color: #4fb3dc !important; }
[data-bs-theme=dark] .text-bg-success { background-color: #1a7f5a !important; }
[data-bs-theme=dark] .text-bg-danger { background-color: #c43c3c !important; }

/* ---------------------------------------------------------------- pieces shared by many pages */
.cap-sensitive::after { content: " \26A0"; color: var(--bs-warning-text-emphasis); }

.global-search input { width: 100%; padding-left: 2rem; border-radius: 999px; background-color: var(--bs-tertiary-bg); }
.global-search .bi-search { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); font-size: .8rem; color: var(--bs-secondary-color); pointer-events: none; }
@media (min-width: 992px) { .global-search input { width: 16rem; } .org-switch select { max-width: 11rem; } }
.global-search-list { width: min(26rem, calc(100vw - 2rem)); max-height: 70vh; overflow-y: auto; top: 100%; right: 0; left: auto; margin-top: .25rem; z-index: 1050; }
@media (max-width: 991.98px) { .global-search-list { width: 100%; left: 0; } }
.account-name { max-width: 16rem; }
.global-search-list .gs-head { font-size: .7rem; letter-spacing: .04em; text-transform: uppercase; }
.global-search-list .gs-item { display: block; padding: .35rem .75rem; color: inherit; text-decoration: none; }
.global-search-list .gs-item[aria-selected="true"], .global-search-list .gs-item:hover { background: var(--app-hover); }
mark, .mark { background: var(--app-highlight); color: inherit; }
.global-search-list mark { padding: 0; }

/* Theme switch in the Account menu and the footer */
.theme-switch { display: inline-flex; gap: .125rem; padding: .125rem; border: 1px solid var(--bs-border-color); border-radius: 999px; background: var(--bs-tertiary-bg); }
.theme-switch button { border: 0; background: transparent; color: var(--bs-secondary-color); border-radius: 999px; padding: .2rem .6rem; font-size: .8rem; line-height: 1.4; }
.theme-switch button:hover { color: var(--bs-emphasis-color); }
.theme-switch button[aria-pressed="true"] { background: var(--bs-body-bg); color: var(--bs-emphasis-color); box-shadow: 0 0 0 1px var(--bs-border-color); }

/* Touch screens: small buttons and controls at least 40px high (D-096 item 4, doc 14 C3). */
@media (pointer: coarse) {
  .btn-sm, .form-control-sm, .form-select-sm { padding-top: .55rem; padding-bottom: .55rem; }
}

/* Paper is always light, whatever the screen shows, and has no menus. */
@media print {
  body { background: #fff; }
  .app-sidebar { display: none !important; }
}

/* Unit by unit (D-112): one small square a month; the colour comes from Bootstrap's status classes. */
.unit-month { display: inline-flex; align-items: center; justify-content: center; width: 1.35rem; height: 1.35rem;
  border-radius: .25rem; font-size: .7rem; font-weight: 600; line-height: 1; }
.unit-months { display: flex; gap: 2px; }

/* Replaces inline style="" attributes in templates (keeps the CSP strict). */
.accent-primary { --accent: var(--bs-primary); }
.accent-success { --accent: var(--bs-success); }
.accent-warning { --accent: var(--bs-warning); }
.accent-danger { --accent: var(--bs-danger); }
.accent-info { --accent: var(--bs-info); }
.pre-line { white-space: pre-line; }
.mw-16r { max-width: 16rem; }
.mw-46r { max-width: 46rem; }
.mw-640 { max-width: 640px; }
.mw-720 { max-width: 720px; }
.mw-760 { max-width: 760px; }
.mw-85p { max-width: 85%; }
.mh-12r { max-height: 12rem; overflow-y: auto; }
.minw-11r { min-width: 11rem; }
.w-2-5r { width: 2.5rem; }
.w-5-5r { width: 5.5rem; }
.w-9r { width: 9rem; }
.w-40p { width: 40%; }
.mw-560 { max-width: 560px; }
.mw-680 { max-width: 680px; }

/* ---------------------------------------------------------------- UI polish pass */
html { scroll-behavior: smooth; }
body { line-height: 1.55; font-size: .95rem; }
h1, .h1 { font-size: clamp(1.4rem, 1.15rem + 1vw, 1.85rem); }
h2, .h2 { font-size: clamp(1.2rem, 1.05rem + .6vw, 1.45rem); }
h3, .h3 { font-size: clamp(1.05rem, 1rem + .3vw, 1.2rem); }
a { text-underline-offset: .18em; }
main:focus { outline: 0; }

/* Keyboard users jump past the menu */
.skip-link { position: absolute; left: .75rem; top: -4rem; z-index: 2000; padding: .6rem 1rem; border-radius: var(--bs-border-radius);
             background: var(--app-ink); color: var(--app-ink-text); font-weight: 600; text-decoration: none; transition: top .15s; }
.skip-link:focus { top: .75rem; color: var(--app-ink-text); }
.notif-badge { font-size: .6rem; }

/* Buttons: one rhythm everywhere, a visible press, a busy state while a form is sending */
.btn { --bs-btn-border-radius: var(--bs-border-radius); --bs-btn-padding-y: .45rem; --bs-btn-padding-x: .95rem; --bs-btn-font-size: .9rem;
       display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
       transition: background-color .12s, border-color .12s, color .12s, transform .06s; }
.btn-sm { --bs-btn-padding-y: .3rem; --bs-btn-padding-x: .7rem; --bs-btn-font-size: .82rem; --bs-btn-border-radius: var(--bs-border-radius-sm); }
.btn-lg { --bs-btn-padding-y: .65rem; --bs-btn-padding-x: 1.25rem; --bs-btn-font-size: 1rem; }
.btn:active:not(:disabled):not(.disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--bs-link-color); outline-offset: 2px; box-shadow: none; }
.btn.is-busy { pointer-events: none; opacity: .8; }
.btn.is-busy::before { content: ""; width: .95em; height: .95em; border: 2px solid currentColor; border-right-color: transparent;
                       border-radius: 50%; animation: app-spin .7s linear infinite; }
@keyframes app-spin { to { transform: rotate(360deg); } }
.btn-outline-danger { --bs-btn-border-color: var(--bs-danger-border-subtle); }
[data-bs-theme=dark] .btn-outline-danger { --bs-btn-color: #f87171; --bs-btn-border-color: #5e2a2e; --bs-btn-hover-bg: #c43c3c;
                                           --bs-btn-hover-border-color: #c43c3c; --bs-btn-hover-color: #fff; }

/* Forms: clear labels, readable fields, errors you can see */
.form-label { font-size: .85rem; font-weight: 550; color: var(--bs-emphasis-color); margin-bottom: .3rem; }
.form-control, .form-select { padding: .5rem .8rem; background-color: var(--bs-body-bg); min-height: 2.5rem; }
.form-control-sm, .form-select-sm { min-height: 2rem; padding: .3rem .65rem; }
textarea.form-control { min-height: 5.5rem; }
.form-control::placeholder { color: var(--bs-secondary-color); opacity: .75; }
.form-control:disabled, .form-select:disabled, .form-control[readonly] { background-color: var(--bs-tertiary-bg); color: var(--bs-secondary-color); }
.form-text, .helptext { font-size: .8rem; color: var(--bs-secondary-color); }
.errorlist { list-style: none; margin: .3rem 0 0; padding: 0; font-size: .82rem; color: var(--bs-danger-text-emphasis); }
.invalid-feedback { font-size: .82rem; }
.form-check-input { width: 1.15em; height: 1.15em; margin-top: .2em; }
input[type=file].form-control { padding: .4rem .6rem; }

/* Alerts: flat, rounded, with a stripe of their colour */
.alert { --bs-alert-border-radius: var(--bs-border-radius); --bs-alert-padding-y: .75rem; --bs-alert-padding-x: 1rem;
         border-left-width: 4px; font-size: .9rem; }
.alert-autohide { transition: opacity .4s, transform .4s; }
.alert-autohide.is-leaving { opacity: 0; transform: translateY(-4px); }

/* Cards, lists and badges */
.card-header { font-weight: 600; font-size: .9rem; }
.tile { transition: background-color .12s, border-color .12s; }
.badge { letter-spacing: .01em; padding: .35em .6em; }

/* Tables: quiet header, comfortable rows, never squeezed on a phone */
.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table > thead th { white-space: nowrap; background: var(--bs-tertiary-bg); }
.table-responsive { border: 1px solid var(--bs-border-color); border-radius: var(--bs-border-radius-lg); background: var(--bs-body-bg); }
.table-responsive > .table { margin-bottom: 0; }
.table-responsive > .table > :last-child > tr:last-child > * { border-bottom-width: 0; }
.card .table-responsive { border: 0; border-radius: 0; }
.table td.text-muted[colspan], .table td.text-center[colspan] { padding: 1.75rem .75rem; text-align: center; }

/* Empty states: say what is missing and what to do about it */
.empty-state { display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: 2.25rem 1rem; text-align: center;
               color: var(--bs-secondary-color); background: var(--bs-body-bg); border: 1px dashed var(--bs-border-color);
               border-radius: var(--bs-border-radius-lg); }
.empty-state .bi { font-size: 1.75rem; color: var(--bs-primary); }
.empty-state h2, .empty-state h3 { font-size: 1rem; margin: 0; color: var(--bs-emphasis-color); }
.empty-state p { margin: 0; max-width: 28rem; font-size: .875rem; }

/* Menu: a clear current page */
.app-nav-link { transition: background-color .12s, color .12s; }
.app-nav-link.active { box-shadow: inset 3px 0 0 var(--bs-primary); }
.app-sidebar { scrollbar-width: thin; }
.navbar-toggler { border-color: var(--bs-border-color); }
.dropdown-item { padding: .5rem 1rem; }

/* Phones */
@media (max-width: 575.98px) {
  main.page { padding-left: .9rem; padding-right: .9rem; }
  .page-head { align-items: stretch; }
  .page-head > .btn { width: 100%; }
  .page-head form .form-select, .page-head form .form-control { width: 100%; }
  .card-body { padding: .9rem; }
  .table > :not(caption) > * > * { padding: .5rem .6rem; font-size: .85rem; }
  .btn-group { flex-wrap: wrap; }
  .modal-dialog { margin: .5rem; }
}
/* Touch screens: 16px fields so iPhones do not zoom in, and big enough targets for fingers */
@media (pointer: coarse) {
  .form-control, .form-select, .form-control-sm, .form-select-sm { font-size: 1rem; min-height: 2.75rem; }
  .btn { min-height: 2.75rem; }
  .btn-sm { min-height: 2.5rem; }
  .app-nav-link, .dropdown-item { min-height: 2.75rem; }
  .form-check-input { width: 1.4em; height: 1.4em; }
}
@media print { .skip-link, .alert-autohide { display: none !important; } }
