body { background: #f7f7f9; }
main.container { max-width: 1100px; }

/* ------------------------------------------------------------------
   Accessibility baseline (WCAG 2.1 AA)
   ------------------------------------------------------------------ */

/* Skip link: off-screen until focused, then pinned top-left so a
   keyboard user can jump past the nav to the page content (WCAG 2.4.1). */
.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 2000;
  padding: 0.5rem 0.9rem;
  background: #0a58ca;  /* 6.4:1 white-on-blue — comfortably past AA */
  color: #fff;
  border-radius: 0.375rem;
  text-decoration: none;
  transition: top 0.15s ease-in-out;
}
.skip-link:focus {
  top: 0.5rem;
  color: #fff;
  outline: 3px solid #002b6b;
  outline-offset: 2px;
}

/* A clearly visible keyboard-focus ring on every interactive element
   (WCAG 2.4.7). Scoped to :focus-visible so it shows for keyboard/AT
   users without adding a ring on mouse click. Bootstrap sets its own
   focus shadow on many controls; this is the floor for everything it
   misses (custom links, sortable headers, badges-as-buttons, etc.). */
a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible,
.nav-link:focus-visible,
summary:focus-visible {
  outline: 3px solid #0d6efd;
  outline-offset: 2px;
  border-radius: 2px;
}

/* Honor users who ask for less motion (WCAG 2.3.3 / vestibular safety):
   drop the sidebar chevron spin, skip-link slide, and any Bootstrap
   transitions/animations rather than forcing movement on them. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ------------------------------------------------------------------
   "Folding" responsive table

   Add `table-stack` to a Bootstrap .table. On phones/small tablets
   (below the Bootstrap `md` breakpoint, matching the col-md-* forms
   these pages use) the header is hidden and every row collapses into a
   stacked card: each cell becomes its own line, labeled from the cell's
   `data-label` attribute. Above the breakpoint it's a normal table, so
   desktop is unchanged. (The global .table-responsive wrapper still
   wraps it but is inert here — a stacked table doesn't overflow.)
   ------------------------------------------------------------------ */
@media (max-width: 767.98px) {
  table.table-stack thead { display: none; }
  table.table-stack,
  table.table-stack tbody,
  table.table-stack tr,
  table.table-stack td { display: block; width: 100%; }
  table.table-stack,
  table.table-stack tbody { background: transparent; }
  table.table-stack tr {
    background: #fff;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: .375rem;
    padding: .35rem .6rem;
    margin-bottom: .5rem;
  }
  table.table-stack td {
    /* Bootstrap fills every cell with --bs-table-bg and adds a bottom
       border + striping/hover box-shadow; in card mode that paints a
       gray band inside the row border. Strip all of it so the card is
       one uniform white. */
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: .3rem 0;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    overflow-wrap: anywhere;
  }
  table.table-stack td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #555;
    flex: 0 0 auto;
  }
  /* Cells with no label (e.g., the empty-results row) shouldn't reserve
     the label gutter. */
  table.table-stack td:not([data-label])::before { content: none; }
}

/* Rich-text (Quill) images are stored via the asset endpoint and may
   carry a fixed pixel width from the resize plugin, which overflows
   narrow viewports. Cap them to their container and keep the aspect
   ratio so they scale down on phones while still honoring the chosen
   size as an upper bound on desktop. Scoped to asset URLs so it never
   touches the landing hero, directory map, or other layout images. */
img[src*="/assets/"] { max-width: 100%; height: auto; }
pre { white-space: pre-wrap; word-break: break-word; font-size: 0.85em; }
table.table th { font-weight: 600; font-size: 0.9em; color: #555; }
.card-header { background: #fafafa; font-weight: 600; }

/* ------------------------------------------------------------------
   Left-side offcanvas sidebar
   ------------------------------------------------------------------ */
.offcanvas-start { width: 260px; }
.sidebar-nav .nav-link {
  color: #333; padding: 0.45rem 1rem;
  border-left: 3px solid transparent;
}
.sidebar-nav .nav-link:hover {
  background: #f0f2f5; color: #000;
  border-left-color: #0d6efd;
}
.sidebar-nav .sidebar-section > .sidebar-toggle {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; color: #555; text-transform: uppercase;
  font-size: 0.8rem; letter-spacing: 0.04em;
}
.sidebar-nav .sidebar-chevron {
  display: inline-block; transition: transform 0.15s ease-in-out;
  color: #6c757d; font-size: 0.9rem;  /* 4.7:1 on white — meets AA */
}
.sidebar-nav .sidebar-toggle:not(.collapsed) .sidebar-chevron {
  transform: rotate(90deg);  /* ▸ → ▾ when expanded */
}
.sidebar-nav .nav-item .nav .nav-link {
  font-size: 0.9rem; padding: 0.3rem 1rem;
}

/* Top bar — slimmer, brand smaller, action links subtle. */
.navbar-brand { font-size: 1rem; font-weight: 600; }

/* Sortable table headers (static/js/table-sort.js + server-sorted lists).
   The arrow slot is always reserved so a column doesn't jiggle sideways
   when it becomes the active sort. */
.sortable-th, .sortable-server th a { cursor: pointer; user-select: none; white-space: nowrap; }
.sortable-server th a { color: inherit; text-decoration: none; }
.sortable-th:hover, .sortable-server th a:hover { color: #0d6efd; }
.sortable-th:focus-visible { outline: 2px solid #0d6efd; outline-offset: -2px; }
.sortable-th::after,
.sortable-server th[aria-sort] a::after,
.sortable-server th:not([aria-sort]) a::after {
  content: "↕"; display: inline-block; width: 1em; margin-left: 0.25em;
  opacity: 0.25; font-size: 0.85em;
}
.sortable-th[aria-sort="ascending"]::after,
.sortable-server th[aria-sort="ascending"] a::after { content: "↑"; opacity: 1; }
.sortable-th[aria-sort="descending"]::after,
.sortable-server th[aria-sort="descending"] a::after { content: "↓"; opacity: 1; }

/* ------------------------------------------------------------------
   Accessibility options widget (static/js/a11y-widget.js + base.html).
   The floating button/panel, plus the preference rules keyed off
   data-attributes on <html>. z-index sits below Bootstrap's modal /
   offcanvas layers so the button tucks behind those overlays instead of
   floating over them.
   ------------------------------------------------------------------ */
.a11y-fab {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 1040;
  width: 3rem; height: 3rem; border-radius: 50%;
  border: 2px solid #fff;
  background: #0a58ca; color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.a11y-fab:hover { background: #094bb0; }
.a11y-panel {
  position: fixed; right: 1rem; bottom: 4.5rem; z-index: 1040;
  width: 18rem; max-width: calc(100vw - 2rem);
  background: #fff; color: #212529;
  border: 1px solid #ced4da; border-radius: 0.5rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  padding: 1rem;
}
.a11y-panel[hidden] { display: none; }
@media print { .a11y-widget { display: none !important; } }

/* Text size — scale the root so all rem-based type and spacing grow
   together (this is a rem zoom, so it composes with browser zoom rather
   than fighting it). */
html[data-a11y-text="1"] { font-size: 112.5%; }
html[data-a11y-text="2"] { font-size: 125%; }
html[data-a11y-text="3"] { font-size: 137.5%; }
html[data-a11y-text="4"] { font-size: 150%; }

/* High contrast — darken muted text to (near) black, underline links,
   and strengthen borders. Deliberately moderate: it does not repaint
   badges/buttons (which already carry text + adequate contrast). */
html[data-a11y-contrast="high"] body { background: #fff; color: #000; }
html[data-a11y-contrast="high"] .text-muted,
html[data-a11y-contrast="high"] .text-secondary,
html[data-a11y-contrast="high"] .small,
html[data-a11y-contrast="high"] .form-text,
html[data-a11y-contrast="high"] table.table th { color: #1a1a1a !important; }
html[data-a11y-contrast="high"] a:not(.btn) { color: #0a3d91 !important; text-decoration: underline; }
html[data-a11y-contrast="high"] .card,
html[data-a11y-contrast="high"] .table,
html[data-a11y-contrast="high"] .table td,
html[data-a11y-contrast="high"] .table th,
html[data-a11y-contrast="high"] .list-group-item,
html[data-a11y-contrast="high"] .border,
html[data-a11y-contrast="high"] .form-control,
html[data-a11y-contrast="high"] .form-select { border-color: #000 !important; }
html[data-a11y-contrast="high"] .card-header { background: #e9e9e9; color: #000; }

/* Larger text spacing — comfort mode for low-vision / dyslexic readers
   (in the spirit of WCAG 1.4.12). Moderate values so tables stay usable. */
html[data-a11y-spacing="on"] body { line-height: 1.8 !important; letter-spacing: 0.03em; word-spacing: 0.08em; }
html[data-a11y-spacing="on"] p { margin-bottom: 1.25em; }

/* ------------------------------------------------------------------
   Contrast fixes over Bootstrap 5.3 defaults (WCAG 1.4.3), needed
   because the page background is off-white (#f7f7f9), which tips
   Bootstrap's #0d6efd text/links to ~4.2:1. Solid button FILLS keep
   #0d6efd (white-on-blue = 4.5:1, passing) — only TEXT-colored blue is
   darkened. Verified: #0a58ca = 6.4:1 white, 6.0:1 off-white.
   ------------------------------------------------------------------ */
:root { --bs-link-color-rgb: 10, 88, 202; --bs-link-hover-color-rgb: 8, 62, 145; }
.text-primary { color: #0a58ca !important; }
.btn-outline-primary {
  --bs-btn-color: #0a58ca; --bs-btn-border-color: #0a58ca;
  --bs-btn-hover-bg: #0a58ca; --bs-btn-hover-border-color: #0a58ca;
}
/* Dark navbar paints inactive links at .55 opacity (~2.4:1 on primary). */
.navbar-dark { --bs-navbar-color: #fff; --bs-navbar-hover-color: #fff; }
/* Amber text/border on white is ~1.6:1. Darken to a readable amber
   (#8a6d00 = 4.9:1) while keeping the warning hue. */
.text-warning { color: #8a6d00 !important; }
.btn-outline-warning {
  --bs-btn-color: #6e5600; --bs-btn-border-color: #8a6d00;
  --bs-btn-hover-bg: #8a6d00; --bs-btn-hover-border-color: #8a6d00; --bs-btn-hover-color: #000;
}
/* Info badges default to white text on #0dcaf0 (1.96:1). Force dark text
   (10.7:1) — matches the branches that already use `text-dark`. */
.badge.bg-info, .badge.text-bg-info { color: #000 !important; }

/* Real-Chrome axe found these on the off-white page bg: Bootstrap 5.3
   renders .text-muted as #6c757d (4.38:1 on #f7f7f9) and <code> as
   #d63384 (4.2:1). Darken both to clear AA on the page background. */
.text-muted, .text-body-secondary { color: #565c64 !important; }  /* 6.3:1 off-white */
code:not([class]) { color: #a3235f; }                             /* 6.6:1 off-white */

/* Real-Chrome axe: btn-outline-secondary text (#6c757d) and light-context
   nav-link tabs (#0d6efd) fall under 4.5:1 on the off-white page bg. */
.btn-outline-secondary { --bs-btn-color: #565c64; }
/* btn-link keeps a hardcoded #0d6efd token in Bootstrap's compiled CSS, so
   the link-color var override doesn't reach it — set it explicitly. */
.btn-link { --bs-btn-color: #0a58ca; --bs-btn-hover-color: #094bb0; }
/* Light-context nav tabs/pills. Exclude .active so an active pill (blue
   background) keeps Bootstrap's white text instead of blue-on-blue. */
.nav:not(.navbar-nav):not(.sidebar-nav) .nav-link:not(.active) { color: #0a58ca; }
.nav:not(.navbar-nav):not(.sidebar-nav) .nav-link:not(.active):hover { color: #094bb0; }

/* Bootstrap danger red (#dc3545) passes on white but drops below 4.5:1 on
   the amber .table-warning row bg (4.08) and the off-white page bg (4.23
   for btn-outline-danger). Darken to #b02a37 (5.9:1 on the amber row). */
.text-danger { color: #b02a37 !important; }
.btn-outline-danger { --bs-btn-color: #b02a37; --bs-btn-border-color: #b02a37; }

/* Board / committee / admin sidebar sections get a distinct purple accent so
   management functions stand apart from the everyday homeowner links.
   #6f42c1 = 6.5:1 on the white sidebar, 5.8:1 on hover — clears WCAG AA. */
.sidebar-nav .sidebar-section .nav-link,
.sidebar-nav .sidebar-section > .sidebar-toggle { color: #6f42c1; }
.sidebar-nav .sidebar-section .nav-link:hover { color: #59359a; border-left-color: #6f42c1; }
.sidebar-nav .sidebar-section .sidebar-chevron { color: #6f42c1; }
