/* Layout on top of Bootstrap 5. The colors come from /theme.css (generated from
   BRAND_COLOR and SIDEBAR_COLOR); the fallbacks below are the house colors. */

/* All text is small: Bootstrap sizes buttons, fields, menus and tables in rem,
   so one number on the root scales them all (and the spacing in rem with them).
   81.25% is 13px at the browser's default size, and follows a person's own
   font-size setting. 75% is 12px, 87.5% is 14px, 100% is Bootstrap's 16px. */
html {
  font-size: 81.25%;
}

:root {
  --sidebar-width: 15rem;
  --rail-width: 3.4rem; /* the sidebar when it is collapsed: the brand mark and icons */
  --topbar-height: 3.4rem;
  --page-bg: #f9f9f9;
  --bs-body-font-family: "Helvetica Neue", Helvetica, Arial, "Liberation Sans", sans-serif;

  /* The house green instead of Bootstrap's. The lighter shades are what Bootstrap
     derives from a variant color: tint 80% and 60%, shade 60%. */
  --bs-success: #7bb859;
  --bs-success-rgb: 123, 184, 89;
  --bs-success-bg-subtle: #e5f1de;
  --bs-success-border-subtle: #cae3bd;
  --bs-success-text-emphasis: #314a24;

  /* Links are a light blue, lighter than the brand color. Bootstrap takes the
     color of a hovered link from the -rgb variable. */
  --bs-link-color: #4a9fd8;
  --bs-link-color-rgb: 74, 159, 216;
  --bs-link-hover-color: #3f87b8;
  --bs-link-hover-color-rgb: 63, 135, 184;

  /* Text is grey, not black. Bootstrap's body text is #212529 and what tables
     and emphasis use is pure black; hints and helper text stay a lighter grey. */
  --bs-body-color: #555;
  --bs-body-color-rgb: 85, 85, 85;
  --bs-emphasis-color: #555;
  --bs-emphasis-color-rgb: 85, 85, 85;
  --bs-secondary-color: #6c757d;
  --bs-secondary-color-rgb: 108, 117, 125;
}

/* The badge variants that Bootstrap prints in black. */
.text-bg-warning,
.text-bg-light,
.text-bg-info {
  color: var(--bs-body-color) !important;
}

/* Pages are light gray. Cards, tables and form fields take their white from
   --bs-body-bg, which stays as it is, so they stand out from the page. */
body {
  background-color: var(--page-bg);
}

/* White text on the green, with a darker green on hover and press. */
.btn-success {
  --bs-btn-color: #fff;
  --bs-btn-bg: #7bb859;
  --bs-btn-border-color: #7bb859;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #699c4c;
  --bs-btn-hover-border-color: #699c4c;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #629347;
  --bs-btn-active-border-color: #629347;
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: #7bb859;
  --bs-btn-disabled-border-color: #7bb859;
  --bs-btn-focus-shadow-rgb: 123, 184, 89;
}

.text-bg-success {
  color: #fff !important;
}

/* Room around the page content: between the sidebar and the content, and on the right. */
.page {
  padding: 1.5rem 1rem;
}

@media (min-width: 992px) {
  .page {
    padding: 1.75rem 2rem;
  }

  /* The top bar's content lines up with the page below it: the button's and the
     menu's own padding makes up the rest of the 2rem. */
  .topbar-inner {
    padding-left: 1.5rem;
    padding-right: 1.25rem;
  }
}

/* The empty "Choose a ..." option of a searchable select is only a hint. It
   goes as soon as the box is clicked, so the person can type at once. */
.ts-wrapper.focus .ts-control > input::placeholder {
  color: transparent;
}

.sidebar {
  --bs-offcanvas-width: var(--sidebar-width);
  --bs-offcanvas-bg: var(--sidebar-bg, #25364b);
  --bs-offcanvas-color: rgb(var(--sidebar-fg-rgb, 255, 255, 255));
}

.sidebar-close {
  filter: var(--sidebar-close-filter, invert(1) grayscale(100%) brightness(200%));
}

@media (min-width: 992px) {
  .offcanvas-lg.sidebar {
    position: fixed !important;
    inset: 0 auto 0 0;
    width: var(--sidebar-width) !important;
    background-color: var(--sidebar-bg, #25364b) !important;
    overflow-y: auto;
    z-index: 1030;
  }

  .app-main {
    margin-left: var(--sidebar-width);
  }

  /* The button in the top bar collapses the sidebar to a rail: the brand mark and
     an icon for each page, with the page's name as a tooltip (app.js). The page
     takes the width that is freed. The class sits on <html>, set by
     sidebar-init.js and app.js. */
  .offcanvas-lg.sidebar,
  .app-main {
    transition: width 0.15s ease, margin-left 0.15s ease;
  }

  html.sidebar-collapsed .offcanvas-lg.sidebar {
    width: var(--rail-width) !important;
    overflow-x: hidden;
  }

  html.sidebar-collapsed .app-main {
    margin-left: var(--rail-width);
  }

  html.sidebar-collapsed .sidebar-brand {
    justify-content: center;
    padding: 0;
  }

  html.sidebar-collapsed .brand-name {
    display: none;
  }

  html.sidebar-collapsed .brand-logo {
    max-width: 2rem;
    max-height: 2rem;
    object-fit: contain;
  }

  html.sidebar-collapsed .sidebar-nav .nav-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }

  html.sidebar-collapsed .sidebar-nav .nav-link i {
    font-size: 1.2rem;
  }

  /* The names are hidden for the eye, not for a screen reader. */
  html.sidebar-collapsed .nav-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* The headings (Main, Tools) become a thin line between the groups. */
  html.sidebar-collapsed .sidebar-heading {
    height: 1px;
    margin: 0.6rem 0.75rem;
    padding: 0;
    overflow: hidden;
    font-size: 0;
    background: rgba(var(--sidebar-fg-rgb, 255, 255, 255), 0.15);
  }

  html.sidebar-collapsed .sidebar-heading:first-child {
    display: none;
  }
}

@media (min-width: 992px) and (prefers-reduced-motion: reduce) {
  .offcanvas-lg.sidebar,
  .app-main {
    transition: none;
  }
}

.sidebar-brand {
  /* As tall as the top bar, so the name lines up with the page title. */
  height: var(--topbar-height);
  padding: 0 1.25rem;
  color: rgb(var(--sidebar-fg-rgb, 255, 255, 255));
  text-decoration: none;
}

.sidebar-brand:hover {
  color: rgb(var(--sidebar-fg-rgb, 255, 255, 255));
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--bs-primary);
  color: var(--brand-contrast, #fff);
  font-weight: 600;
}

.brand-logo {
  max-width: 8rem;
  max-height: 2rem;
}

.sidebar-nav {
  padding-bottom: 1rem;
}

.sidebar-heading {
  padding: 1rem 1.25rem 0.25rem;
  list-style: none;
  font-size: 0.875rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(var(--sidebar-fg-rgb, 255, 255, 255), 0.5);
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1.25rem;
  color: rgba(var(--sidebar-fg-rgb, 255, 255, 255), 0.75);
}

.sidebar-nav .nav-link:hover {
  color: rgb(var(--sidebar-fg-rgb, 255, 255, 255));
  background: rgba(var(--sidebar-fg-rgb, 255, 255, 255), 0.08);
}

.sidebar-nav .nav-link.active {
  color: rgb(var(--sidebar-fg-rgb, 255, 255, 255));
  background: rgba(var(--sidebar-fg-rgb, 255, 255, 255), 0.14);
  box-shadow: inset 3px 0 0 var(--bs-primary);
}

.login-card {
  width: 100%;
  max-width: 24rem;
}

.form-card {
  max-width: 40rem;
}

.search-box {
  max-width: 24rem;
}

/* Tables use the width of the page and wrap their cells onto a second line
   instead of scrolling sideways. Dates, amounts and badges stay on one line
   (text-nowrap); names, numbers and e-mail addresses wrap (.wrap), at spaces
   first and inside a word only when a single word is longer than the column.
   Every wrapping column keeps room for an ordinary word. Only below the xl
   breakpoint, on a narrow window or a phone, the wrapper (.table-responsive-xl)
   scrolls, and only if the columns still do not fit. */
.data-table {
  width: 100%;
}

.data-table > :not(caption) > * > * {
  padding: 0.45rem 0.5rem;
}

.data-table th {
  vertical-align: bottom;
}

.data-table .wrap {
  overflow-wrap: anywhere;
  min-width: 5.5rem;
}

.data-table .amount {
  font-variant-numeric: tabular-nums;
}

.preserve-lines {
  white-space: pre-wrap;
}

.list-target {
  transition: opacity 150ms ease-in;
}

.list-target.htmx-request {
  opacity: 0.6;
}

/* Tabs above a list (All, Open, Payed, Closed ...): only the active one is a
   button, the others are plain grey text that darkens on hover. */
.nav-pills {
  --bs-nav-link-color: #6c757d;
  --bs-nav-link-hover-color: var(--bs-body-color);
}

/* A choice among a few options in a form (Receipt or Payment, Open, Payed or
   Closed) looks the same: the chosen option is the button. */
.choice-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.choice-group .btn {
  --bs-btn-color: #6c757d;
  --bs-btn-bg: transparent;
  --bs-btn-border-color: transparent;
  --bs-btn-hover-color: var(--bs-body-color);
  --bs-btn-hover-bg: transparent;
  --bs-btn-hover-border-color: transparent;
  --bs-btn-active-color: var(--brand-contrast, #fff);
  --bs-btn-active-bg: var(--bs-primary);
  --bs-btn-active-border-color: var(--bs-primary);
  --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}

/* The page numbers are links too. The current page stays a button in the brand color. */
.pagination {
  --bs-pagination-color: var(--bs-link-color);
  --bs-pagination-hover-color: var(--bs-link-hover-color);
}

/* Bootstrap's badge text is .75em, 9px at this size: too small to read. */
.badge {
  --bs-badge-font-size: 0.875em;
}

/* A slim top bar: the button and the menu are as small as their text needs. */
.topbar {
  --bs-navbar-padding-y: 0.15rem;
  min-height: var(--topbar-height);
}

/* What a line of the Activity page changed: old value struck through, new one bold. */
.changes li {
  overflow-wrap: anywhere;
}

/* The values keep the line breaks a comment has; the markup around them does not. */
.change-value,
.change-old,
.change-new {
  white-space: pre-line;
}

.change-old {
  color: var(--bs-secondary-color);
  text-decoration: line-through;
}

.change-new {
  font-weight: 600;
}

/* A line under the page title, which runs the width of the content, and room
   before what follows. The title row of every page has it. */
.page-head {
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--bs-border-color);
}

/* The filters of a list that are in force, above its table. */
.filter-chip a {
  text-decoration: none;
}

.filter-chip a:hover {
  color: var(--bs-body-color) !important;
}

/* Graphs. The charts are SVG drawn by the server (internal/charts). Each shape
   has a class that gives it a color, and takes that color as currentColor; the
   text and the lines of the axes are grey. */
:root {
  --chart-payment: var(--bs-primary);
  --chart-receipt: #7bb859;
  --chart-accent: #e0883a;
  --chart-other: #b9c0c7;
}

.c-payment {
  color: var(--chart-payment);
}

.c-receipt {
  color: var(--chart-receipt);
}

.c-accent {
  color: var(--chart-accent);
}

.c-other {
  color: var(--chart-other);
}

.chart {
  display: block;
  width: 100%;
  min-width: 34rem;
  height: auto;
}

/* The wide charts hold twenty-odd columns or a long list of names: below this
   width they scroll sideways instead of shrinking the text to nothing. */
.chart-scroll {
  overflow-x: auto;
}

.chart-scroll.wide .chart {
  min-width: 52rem;
}

.chart text {
  fill: var(--bs-secondary-color);
  font-size: 11px;
}

.chart .val {
  fill: var(--bs-body-color);
}

.chart .cum-tick {
  fill: var(--chart-accent);
}

.chart .grid {
  stroke: var(--bs-border-color);
  shape-rendering: crispEdges;
}

.chart .axis {
  stroke: #adb5bd;
  shape-rendering: crispEdges;
}

.chart a {
  cursor: pointer;
  text-decoration: none;
}

.chart a:hover .bar,
.chart a:focus .bar {
  opacity: 0.75;
}

.chart a:hover text.label {
  fill: var(--bs-body-color);
  text-decoration: underline;
}

/* The running share draws over the bars and must not catch their clicks. */
.chart .cum {
  pointer-events: none;
}

/* A point is a small dot with a wide invisible ring, so that it is easy to hover. */
.chart .dot {
  stroke: transparent;
  stroke-width: 12px;
  transform-box: fill-box;
  transform-origin: center;
}

.chart .dot:hover {
  transform: scale(1.5);
}

.swatch {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 2px;
  background-color: currentColor;
  vertical-align: -0.1rem;
}

/* The filters stay under the top bar while the charts scroll past, so the
   period can be changed from anywhere on the page. */
.graph-filters {
  position: sticky;
  top: var(--topbar-height);
  z-index: 5;
  margin-bottom: 1rem;
  padding: 0.6rem 0;
  background: var(--page-bg);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.3;
}

.stat-value a {
  color: inherit;
  text-decoration: none;
}

.stat-value a:hover {
  text-decoration: underline;
}

.chart-table summary {
  cursor: pointer;
  color: var(--bs-link-color);
}

/* The messages after an action are toasts in the top right corner, under the top
   bar and over the page, so they do not push it down (shared/_flash.html). The
   container does not catch clicks meant for the page; the toasts do. */
.flash-toasts {
  top: calc(var(--topbar-height) + 0.5rem);
  right: 0.75rem;
  max-width: calc(100vw - 1.5rem);
}
