body { padding-bottom: env(safe-area-inset-bottom); }
.sortable th[data-sort] { cursor: pointer; white-space: nowrap; user-select: none; }
.sortable th[data-sort]::after { content: ' \2195'; opacity: .3; font-size: .8em; }
.sortable th.asc::after { content: ' \2191'; opacity: 1; }
.sortable th.desc::after { content: ' \2193'; opacity: 1; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--bs-border-color); border-left: 1px solid var(--bs-border-color); }
.cal-h { padding: .4rem; text-align: center; font-weight: 600; font-size: .8rem; background: var(--bs-tertiary-bg); border-right: 1px solid var(--bs-border-color); border-bottom: 1px solid var(--bs-border-color); }
.cal-d { min-height: 110px; padding: .25rem; border-right: 1px solid var(--bs-border-color); border-bottom: 1px solid var(--bs-border-color); cursor: pointer; overflow: hidden; }
.cal-d:hover { background: var(--bs-tertiary-bg); }
.cal-d.other { background: var(--bs-secondary-bg); opacity: .55; }
.cal-d.today { outline: 2px solid var(--bs-primary); outline-offset: -2px; }
.cal-n { font-size: .8rem; font-weight: 600; }
.cal-chip { display: block; font-size: .7rem; line-height: 1.2; padding: 1px 4px; margin-top: 2px; border-radius: 3px; background: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-chip.income { background: var(--bs-success-bg-subtle); color: var(--bs-success-text-emphasis); }
.cal-chip.optional { background: var(--bs-warning-bg-subtle); color: var(--bs-warning-text-emphasis); }
.cal-tot { font-size: .72rem; font-weight: 700; text-align: right; color: var(--bs-danger); }
.cal-tot.inc { color: var(--bs-success); }
@media (max-width: 767px) {
  .cal-d { min-height: 64px; }
  .cal-chip { display: none; }
  .cal-dots { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 2px; }
  .cal-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--bs-primary); display: inline-block; }
  .cal-dots i.income { background: var(--bs-success); }
  .cal-tot { font-size: .62rem; }
}
@media (min-width: 768px) { .cal-dots { display: none; } }
.stat { font-size: 1.6rem; font-weight: 700; }

/* ---- colour theme for tables ---- */
:root { --hdr-from: #2f5d9e; --hdr-to: #1f3f73; --hdr-fg: #fff; --tint: 47, 93, 158; }
.table > thead > tr > th, .table > thead th {
  background: linear-gradient(180deg, var(--hdr-from), var(--hdr-to)) !important; color: var(--hdr-fg) !important;
  border-bottom: 0 !important; box-shadow: none;
}
.table-striped > tbody > tr:nth-of-type(odd) > * { --bs-table-bg-type: rgba(var(--tint), .06); }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: rgba(var(--tint), .13); }
.table > tfoot td { background: rgba(var(--tint), .10) !important; }
.table > tfoot tr.text-success td { background: rgba(25,135,84,.12) !important; }
.cal-h { background: linear-gradient(180deg, var(--hdr-from), var(--hdr-to)); color: var(--hdr-fg); border-color: rgba(255,255,255,.15); }
.card > .table-responsive, .table-responsive.card { overflow-x: auto; }

/* ---- unified filter / search bar ---- */
.filter-bar { background: linear-gradient(180deg, #f4f7fc, #eaf0f9); border: 1px solid #d3dff0; border-radius: .75rem; padding: .7rem .85rem .8rem; box-shadow: 0 1px 2px rgba(31,63,115,.06); }
.filter-bar .fb-label { display: block; font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: #5a6f93; margin: 0 0 .2rem .15rem; }
.filter-bar .fb-label .bi { font-size: .7rem; opacity: .7; }
/* every control the same height */
.filter-bar .ms-dd > .btn, .filter-bar .fb-search .form-control, .filter-bar .fb-search .input-group-text, .filter-bar .fb-btn { height: 2.4rem; }
.filter-bar .ms-dd > .btn { font-size: .92rem; padding: 0 2rem 0 .75rem; background: #fff; border-color: #c5d3ea; color: #26324a; border-radius: .5rem; display: flex; align-items: center; }
.filter-bar .ms-dd > .btn::after { position: absolute; right: .75rem; top: 50%; margin-top: -.15em; }
.filter-bar .ms-dd { position: relative; }
.filter-bar .ms-dd > .btn:hover, .filter-bar .ms-dd > .btn.show { border-color: #2f5d9e; background: #fff; color: #1f3f73; }
.filter-bar .fb-search .input-group-text { background: #fff; border-color: #c5d3ea; color: #5a6f93; }
.filter-bar .fb-search .input-group-text:first-child { border-radius: .5rem 0 0 .5rem; }
.filter-bar .fb-search .input-group-text:last-child { border-radius: 0 .5rem .5rem 0; font-size: .78rem; font-weight: 600; color: #2f5d9e; background: #eef3fb; }
.filter-bar .fb-search .input-group-text:empty { display: none; }
.filter-bar .fb-search .form-control { font-size: .95rem; border-color: #c5d3ea; border-left: 0; padding-left: 0; box-shadow: none; }
.filter-bar .fb-search .form-control:last-child { border-radius: 0 .5rem .5rem 0; }
.filter-bar .fb-search:focus-within .input-group-text:first-child, .filter-bar .fb-search:focus-within .form-control { border-color: #2f5d9e; }
.filter-bar .fb-search:focus-within { box-shadow: 0 0 0 .18rem rgba(47,93,158,.18); border-radius: .5rem; }
.filter-bar .fb-btn { padding: 0 .95rem; font-size: .9rem; font-weight: 600; border-radius: .5rem; display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.filter-bar .btn-primary.fb-btn { background: linear-gradient(180deg, #2f5d9e, #1f3f73); border-color: #1f3f73; }
.filter-bar .btn-outline-secondary.fb-btn { background: #fff; border-color: #c5d3ea; color: #4a5d80; }
.filter-bar .btn-outline-secondary.fb-btn:hover { background: #fdeeee; border-color: #e3a3a3; color: #b02a2a; }

/* subtle column dividers in table headers */
.table > thead > tr > th + th { border-left: 1px solid rgba(255,255,255,.28) !important; }

/* Upcoming: calendar grid above the list shows chips on all screen sizes */
.cal.up .cal-d { cursor: default; min-height: 96px; }
.cal.up .cal-d:hover { background: transparent; }
.cal.up .cal-d.other { background: var(--bs-secondary-bg); opacity: .45; }
@media (max-width: 767px) {
  .cal.up .cal-d { min-height: 78px; padding: 2px; }
  .cal.up .cal-chip { display: block; font-size: .56rem; padding: 0 2px; }
  .cal.up .cal-chip b { display: none; }
  .cal.up .cal-n { font-size: .7rem; }
}

/* collapsible filter toggle button */
.fb-toggle { font-weight: 600; padding-top: .4rem; padding-bottom: .4rem; border-radius: .6rem; }
.fb-toggle .fb-chev { transition: transform .2s; }
.fb-toggle[aria-expanded="false"] .fb-chev { transform: rotate(-90deg); }

/* calendar grid: outer border matches the header colour so header and grid edges line up */
.cal { border: 1px solid var(--hdr-to); border-radius: .6rem; overflow: hidden; }
.cal-h { border-right-color: rgba(255,255,255,.22); border-bottom-color: transparent; }
.cal-h:nth-child(7n), .cal-d:nth-child(7n+7) { border-right: 0; }
.cal-d:nth-last-child(-n+7) { border-bottom: 0; }
