/* Arbor Analytics — theme layer over vendored Bootstrap 5.3.
 *
 * Bootstrap 5.3 is driven by CSS custom properties, so the whole palette and type scale
 * are retuned here with no SASS and no build step. Loaded AFTER bootstrap.min.css.
 *
 * Palette comes from the deliverables themselves: the plan draws NRZ circles in green and
 * SRZ circles in brown, so the portal that produces them uses the same two colours. The
 * page sits on warm paper rather than blue-grey — this is a tool that makes printed
 * documents for council, and it should feel like one.
 */

:root {
  /* Brand ---------------------------------------------------------------- */
  --aa-canopy:      #1f4d2f;   /* deep canopy — primary */
  --aa-canopy-dark: #16371f;
  --aa-canopy-tint: #eaf1eb;
  --aa-nrz:         #2f6b34;   /* NRZ green, as drawn on the plan */
  --aa-srz:         #7a5230;   /* SRZ brown, as drawn on the plan */
  --aa-bark:        #4a3b2c;

  /* Surfaces ------------------------------------------------------------- */
  --aa-paper:   #faf9f5;
  --aa-surface: #ffffff;
  --aa-line:    #e3e1d8;
  --aa-ink:     #1c2119;
  --aa-muted:   #6b7263;

  /* Bootstrap overrides -------------------------------------------------- */
  --bs-primary: var(--aa-canopy);
  --bs-primary-rgb: 31, 77, 47;
  --bs-link-color: var(--aa-canopy);
  --bs-link-color-rgb: 31, 77, 47;
  --bs-link-hover-color: var(--aa-canopy-dark);

  --bs-body-bg: var(--aa-paper);
  --bs-body-color: var(--aa-ink);
  --bs-secondary-color: var(--aa-muted);
  --bs-border-color: var(--aa-line);
  --bs-border-radius: .5rem;
  --bs-border-radius-sm: .375rem;
  --bs-border-radius-lg: .75rem;

  --bs-body-font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue",
                         "Noto Sans", Roboto, Arial, sans-serif;
  --bs-body-font-size: 0.975rem;
  --bs-body-line-height: 1.6;

  --bs-focus-ring-color: rgba(31, 77, 47, .28);
  --bs-focus-ring-width: 3px;
}

body {
  /* Trees plotted like a forestry survey sheet, tiled behind everything. Faint by
     design: it must read as paper texture, never compete with a data table. */
  /* One tree, drawn once, behind every page. Two layers: a paper wash on top that
     fades the canopy out of the upper third — page headings sit there and must stay
     crisp — and the drawing beneath it, bottom-anchored so the trunk meets the foot
     of the window. Fixed, so content scrolls over a stationary tree. */
  background-image:
    linear-gradient(to bottom,
      var(--aa-paper) 0%,
      rgba(250, 249, 245, .82) 26%,
      rgba(250, 249, 245, .35) 46%,
      transparent 64%),
    url("/static/tree-branching.svg");
  background-repeat: no-repeat, no-repeat;
  background-position: top center, bottom center;
  background-size: 100% 100%, min(1080px, 130%) auto;
  background-attachment: fixed, fixed;
  -webkit-font-smoothing: antialiased;
}

/* Sign-in has no table to protect, so the motif gets to be a real drawing: one
   branching tree behind the card, anchored to the bottom of the viewport. */
/* Sign-in has no table to protect, so the whole tree gets to show: sized to fit the
   window height (never clipping the crown) and only lightly washed at the very top. */
body.aa-signin {
  background-image:
    linear-gradient(to bottom, var(--aa-paper) 0%, rgba(250, 249, 245, .3) 14%, transparent 40%),
    url("/static/tree-branching.svg");
  background-size: 100% 100%, auto min(94vh, 780px);
}

/* A monstera leaf down each margin, mirrored. Fixed size rather than a stretched
   background — scaling one to viewport height blows the slits up into blobs. Hidden
   once the window is narrow enough that content wants the full width. */
body::before,
body::after {
  content: "";
  position: fixed;
  top: 0;
  bottom: 0;
  width: min(300px, 21vw);
  background: url("/static/monstera-leaf.svg") no-repeat;
  /* contain, so the leaf is sized by the strip's width — sizing it by height made
     it wider than the strip, which clipped the left and right lobes off. */
  background-size: contain;
  pointer-events: none;
  z-index: -1;
}
body::before { left: 0;  background-position: left 22%; }
body::after  { right: 0; background-position: right 62%; transform: scaleX(-1); }

@media (max-width: 1200px) {
  body::before, body::after { display: none; }
}

/* Typography ------------------------------------------------------------- */
h1, h2, h3, .h1, .h2, .h3 {
  font-weight: 640;
  letter-spacing: -0.018em;   /* tightened tracking is most of the "designed" feel */
  color: var(--aa-ink);
}
h1, .h1 { font-size: clamp(1.45rem, 1.15rem + 1vw, 1.85rem); }
h2, .h2 { font-size: 1.15rem; }

.eyebrow {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--aa-muted);
}

.lead-sm { color: var(--aa-muted); font-size: .95rem; }

/* Numbers in tables should align: tabular figures, always. */
.tabular { font-variant-numeric: tabular-nums; }

/* App shell -------------------------------------------------------------- */
.aa-nav {
  background: var(--aa-surface);
  border-bottom: 1px solid var(--aa-line);
  box-shadow: 0 1px 2px rgba(28, 33, 25, .04);
}
.aa-brand {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--aa-ink);
  text-decoration: none;
}
.aa-brand:hover { color: var(--aa-canopy); }
/* Height-constrained, width auto: the logo is a fixed-ratio bitmap and must never be
   squashed by a narrow nav. The width/height ATTRIBUTES on the <img> are set to the
   displayed size, not the file's, so a stale stylesheet renders a small logo rather
   than a 640px one. */
.aa-brand img { flex: none; height: 38px; width: auto; }
.aa-brand small {
  display: block;
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .04em;
  color: var(--aa-muted);
  text-transform: uppercase;
}

.aa-navlink {
  color: var(--aa-muted);
  text-decoration: none;
  font-weight: 550;
  font-size: .92rem;
  padding: .35rem .1rem;
  border-bottom: 2px solid transparent;
}
.aa-navlink:hover { color: var(--aa-ink); }
.aa-navlink[aria-current="page"] {
  color: var(--aa-canopy);
  border-bottom-color: var(--aa-canopy);
}

/* Cards ------------------------------------------------------------------ */
.aa-card {
  background: var(--aa-surface);
  border: 1px solid var(--aa-line);
  border-radius: var(--bs-border-radius-lg);
  box-shadow: 0 1px 2px rgba(28, 33, 25, .04), 0 8px 24px -18px rgba(28, 33, 25, .18);
}
.aa-card-pad { padding: clamp(1.1rem, .8rem + 1vw, 1.75rem); }

/* A hairline rule in brand colour along the top of the sign-in card. */
.aa-card-accent { border-top: 3px solid var(--aa-canopy); }

/* Forms ------------------------------------------------------------------ */
.form-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--aa-ink);
  margin-bottom: .3rem;
  letter-spacing: .005em;
}
.form-control {
  border-color: var(--aa-line);
  padding: .5rem .7rem;
  background: #fff;
}
.form-control:focus {
  border-color: var(--aa-nrz);
  box-shadow: 0 0 0 var(--bs-focus-ring-width) var(--bs-focus-ring-color);
}
.form-text { font-size: .8rem; color: var(--aa-muted); }
.req { color: var(--aa-srz); font-weight: 700; }

.btn-primary {
  --bs-btn-bg: var(--aa-canopy);
  --bs-btn-border-color: var(--aa-canopy);
  --bs-btn-hover-bg: var(--aa-canopy-dark);
  --bs-btn-hover-border-color: var(--aa-canopy-dark);
  --bs-btn-active-bg: var(--aa-canopy-dark);
  --bs-btn-disabled-bg: var(--aa-muted);
  --bs-btn-disabled-border-color: var(--aa-muted);
  font-weight: 550;
}
.btn-outline-secondary {
  --bs-btn-color: var(--aa-muted);
  --bs-btn-border-color: var(--aa-line);
  --bs-btn-hover-bg: var(--aa-canopy-tint);
  --bs-btn-hover-border-color: var(--aa-line);
  --bs-btn-hover-color: var(--aa-ink);
  font-weight: 550;
}

/* Table ------------------------------------------------------------------ */
.aa-table { margin: 0; }
.aa-table > thead > tr > th {
  background: #f4f3ee;
  border-bottom: 1px solid var(--aa-line);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--aa-muted);
  padding: .6rem .9rem;
  white-space: nowrap;
}
.aa-table > tbody > tr > td {
  padding: .8rem .9rem;
  border-bottom: 1px solid var(--aa-line);
  vertical-align: middle;
}
.aa-table > tbody > tr:last-child > td { border-bottom: 0; }
.aa-table > tbody > tr:hover > td { background: var(--aa-canopy-tint); }
.aa-table a { text-decoration: none; font-weight: 550; }
.aa-table a:hover { text-decoration: underline; }

/* On a phone a ten-column table is a horizontal-scroll puzzle, so an .aa-table-stack
   turns each row into a card and every cell carries its own label. Narrow tables
   (the plan sheets) stay tables — they fit. */
@media (max-width: 575px) {
  .aa-table-stack > thead { display: none; }
  .aa-table-stack, .aa-table-stack > tbody,
  .aa-table-stack > tbody > tr, .aa-table-stack > tbody > tr > td { display: block; width: 100%; }
  .aa-table-stack > tbody > tr { border-bottom: 1px solid var(--aa-line); padding: .6rem 0; }
  .aa-table-stack > tbody > tr:last-child { border-bottom: 0; }
  .aa-table-stack > tbody > tr > td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: .2rem .9rem;
    border-bottom: 0;
  }
  .aa-table-stack > tbody > tr > td::before {
    content: attr(data-label);
    flex: none;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--aa-muted);
  }
  /* The row's headline cell and the actions carry no label. */
  .aa-table-stack > tbody > tr > td:not([data-label])::before { content: none; }
  .aa-table-stack > tbody > tr > td.aa-cell-title {
    display: block;
    font-weight: 600;
    padding-bottom: .4rem;
  }
  .aa-table-stack > tbody > tr > td.aa-cell-actions { justify-content: flex-end; padding-top: .5rem; }
}

/* The bulk-select column: as narrow as a checkbox, no wider. */
.aa-cell-tick { width: 1%; white-space: nowrap; }

/* Wide content must scroll inside its own box, never the page body. */
.aa-scroll-x { overflow-x: auto; }

/* Site cell: address on top, location beneath in muted small caps. */
.aa-site { display: block; color: var(--aa-ink); }
.aa-site-sub { display: block; font-size: .8rem; color: var(--aa-muted); }

/* Badges ----------------------------------------------------------------- */
.aa-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .72rem;
  font-weight: 650;
  letter-spacing: .02em;
  padding: .2rem .5rem;
  border-radius: 999px;
  border: 1px solid transparent;
}
.aa-badge-pending {
  background: #fdf6ec;
  border-color: #ecdcc2;
  color: var(--aa-srz);
}
.aa-badge-dot {
  width: .4rem; height: .4rem; border-radius: 50%;
  background: currentColor; flex: none;
}

/* Empty state ------------------------------------------------------------ */
.aa-empty {
  text-align: center;
  padding: clamp(2rem, 1rem + 4vw, 3.5rem) 1.5rem;
}
.aa-empty svg { color: var(--aa-line); margin-bottom: .75rem; }

/* Detail list ------------------------------------------------------------ */
.aa-detail { display: grid; gap: 0; margin: 0; }
.aa-detail > div {
  display: grid;
  grid-template-columns: minmax(9rem, 13rem) 1fr;
  gap: 1rem;
  padding: .7rem 0;
  border-bottom: 1px solid var(--aa-line);
}
.aa-detail > div:last-child { border-bottom: 0; }
.aa-detail dt { color: var(--aa-muted); font-size: .85rem; font-weight: 550; }
.aa-detail dd { margin: 0; }
@media (max-width: 34rem) {
  .aa-detail > div { grid-template-columns: 1fr; gap: .1rem; }
}

/* "Not built yet" panel — honest about what this slice does not do. */
.aa-pending {
  border-left: 3px solid var(--aa-srz);
  background: #fdfbf7;
  border-radius: 0 var(--bs-border-radius) var(--bs-border-radius) 0;
  padding: 1rem 1.1rem;
}

/* htmx ------------------------------------------------------------------- */
/* Dim only the region being swapped, and only once the request is slow enough
   to notice — a flash on every fast request reads as jank, not feedback. */
.htmx-request.aa-swap, .htmx-request .aa-swap { opacity: .55; }
.aa-swap { transition: opacity .12s ease-in-out .08s; }

/* Respect a user who has asked for less motion. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* Print: the portal is not the deliverable, but a jobs list does get printed. */
@media print {
  .aa-nav, .aa-actions, .aa-pager { display: none !important; }
  body { background: #fff; }
  body::before, body::after { display: none; }
  .aa-card { border: 0; box-shadow: none; }
}

/* Sign-in page: the mark carries the brand here, so it is sized to be seen, and the
   card is centred in the viewport instead of floating above a field of empty paper. */
/* The sign-in logo: capped by width on a phone, by a sane maximum on a desktop. */
.aa-signin-mark img { width: min(100%, 230px); height: auto; }
.aa-center-viewport { min-height: calc(100vh - 8rem); align-content: center; }

/* Bootstrap's default <code> pink fights the palette. */
code {
  color: var(--aa-srz);
  background: #f5f2ec;
  padding: .1rem .3rem;
  border-radius: .25rem;
  font-size: .85em;
}

/* Places suggestions, floating under the site-address input. */
.aa-suggest {
  position: absolute;
  z-index: 1050;
  inset-inline: 0;
  max-height: 16rem;
  overflow-y: auto;
}
.aa-suggest .list-group-item {
  border-radius: 0;
  font-size: .95rem;
}

/* Import page: the expected sheet structure, listed so the page cannot claim a field
   the parser does not actually read. */
.aa-fieldlist {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: .9rem;
}
.aa-fieldlist li {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem 0;
  border-bottom: 1px solid var(--aa-line);
}
.aa-fieldlist li:last-child { border-bottom: 0; }
.aa-fieldlist li span:first-child { flex: 1; }

.aa-badge-req {
  background: var(--aa-canopy-tint);
  border-color: #cfe0d2;
  color: var(--aa-canopy);
}

/* A spreadsheet reference (Job Details.Location) reads better as a location than code. */
.aa-cell {
  background: rgba(255, 255, 255, .55);
  color: inherit;
  font-weight: 600;
}

/* A file input is a control, not text: match the other fields' height. */
input[type="file"].form-control { padding: .42rem .6rem; }

/* Zone radii in the tree table: coloured as they are drawn on the plan — NRZ green
   solid, SRZ brown dotted — so the table and the deliverable speak the same language. */
.aa-zone {
  display: inline-block;
  padding: .1rem .45rem;
  border-radius: .25rem;
  font-weight: 650;
  font-size: .85rem;
}
.aa-zone-nrz { background: var(--aa-canopy-tint); color: var(--aa-nrz); border: 1px solid #cfe0d2; }
.aa-zone-srz { background: #fdf6ec; color: var(--aa-srz); border: 1px dashed #e2cdb2; }
/* The nominated protection fence — yellow, as drawn on the plan. */
.aa-zone-fence { background: #fdf8e3; color: #9a7b12; border: 1px solid #ecd88a; }

/* Current derived values, shown while editing a tree. */
.aa-zones {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: .7rem .9rem;
  background: var(--aa-canopy-tint);
  border-radius: var(--bs-border-radius);
}

/* ── Site base map ─────────────────────────────────────────────────────────────── */
.site-map-controls {
  display: flex;
  align-items: flex-end;
  gap: .75rem;
  margin-bottom: .9rem;
}
.site-map-canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 30rem;
  background: #eceae3;
  border: 1px solid var(--aa-line);
  border-radius: var(--bs-border-radius);
  overflow: hidden;
}
/* Square, because the Static Maps base image the plan is drawn on is 640×640: what the
   arborist frames here is the ground the plan will cover. */
.site-map-stage {
  position: relative;
}
.site-map-north {
  position: absolute;
  /* Bottom-right, sitting just above Google's pan control so neither is covered. */
  right: .6rem;
  bottom: 4.4rem;
  z-index: 1;
  width: 2.6rem;
  height: 2.6rem;
  padding: .2rem;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--aa-line);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  pointer-events: none; /* purely decorative — clicks fall through to the map */
}
.site-map-north svg {
  display: block;
  width: 100%;
  height: 100%;
}
.site-map-north .north { fill: #c0392b; }   /* the needle's north half — compass red */
.site-map-north .south { fill: #b8b5ac; }
.site-map-canvas.is-unavailable {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 7;
  background:
    repeating-linear-gradient(45deg, #eceae3 0 10px, #e4e1d8 10px 20px);
}
.site-map-status {
  margin: 0 0 .6rem;
  font-size: .875rem;
  color: var(--aa-muted);
}
.site-map-status.is-warn {
  color: var(--aa-srz);
  background: #fdf6ec;
  border-left: 3px solid var(--aa-srz);
  padding: .5rem .75rem;
}
.site-map-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-top: .9rem;
}
.aa-badge-ok {
  background: var(--aa-canopy-tint);
  border-color: #cfe0d2;
  color: var(--aa-nrz);
}

/* ── Tree markers on the base map ──────────────────────────────────────────────── */
.site-map-markers {
  display: grid;
  gap: .5rem;
  margin-top: .9rem;
  padding-top: .9rem;
  border-top: 1px solid var(--aa-line);
}
#marker-place.is-active {
  background: var(--aa-canopy);
  border-color: var(--aa-canopy);
  color: #fff;
}
.marker-list {
  list-style: none;
  margin: .25rem 0 0;
  padding: 0;
  display: grid;
  gap: 1px;
  background: var(--aa-line);
  border: 1px solid var(--aa-line);
  border-radius: var(--bs-border-radius);
  overflow: hidden;
  max-height: 16rem;
  overflow-y: auto;
}
.marker-list:empty { display: none; }
.marker-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .45rem .6rem;
  background: var(--aa-surface);
  cursor: pointer;
}
.marker-row:hover { background: var(--aa-canopy-tint); }
.marker-no {
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--aa-canopy);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.marker-text { flex: 1; font-size: .9rem; }
.marker-actions { display: flex; gap: .4rem; flex: none; }

/* Marker reconciliation notice — the check that gates plan generation. */
.marker-reconcile {
  font-size: .875rem;
  padding: .5rem .75rem;
  border-left: 3px solid var(--aa-srz);
  background: #fdf6ec;
  color: var(--aa-srz);
}
.marker-reconcile.is-ok {
  border-left-color: var(--aa-nrz);
  background: var(--aa-canopy-tint);
  color: var(--aa-nrz);
}
.marker-renumber { flex: none; width: 4.5rem; }
.marker-renumber input { text-align: center; font-variant-numeric: tabular-nums; }
.marker-warn { color: var(--aa-srz); font-weight: 600; }
.marker-row[data-outside="1"] .marker-no { background: var(--aa-brick); }

/* Canopy: a measurement, not a protection zone — lighter than both zone badges. */
.aa-zone-canopy {
  background: #f4f8f2;
  color: #5c8f52;
  border: 1px solid #dbe8d6;
}

/* ── Tree photograph ───────────────────────────────────────────────────────────── */
.tree-photo { display: grid; gap: .75rem; }
.tree-photo-img {
  display: block;
  width: 100%;
  max-width: 28rem;
  border-radius: var(--bs-border-radius);
  border: 1px solid var(--aa-line);
}
.tree-photo-none {
  margin: 0;
  padding: 1.25rem;
  border: 1px dashed var(--aa-line);
  border-radius: var(--bs-border-radius);
  color: var(--aa-muted);
  font-size: .9rem;
  background: #faf9f5;
}
.tree-photo-form { max-width: 28rem; }

/* Pager: range on the left, numbered pages centred on the CARD rather than between
   their neighbours — an empty third column keeps the numbers still while the range text
   grows from "1–20 of 23" to "381–400 of 800". Collapses to two stacked rows on a phone,
   where there is no room for both beside each other. */
.aa-pager {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  border-top: 1px solid var(--aa-line);
}
.aa-pager-range { white-space: nowrap; }
.aa-pager-pages {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: .25rem;
  flex-wrap: wrap;
  justify-content: center;
}
.aa-pager-page { min-width: 2.25rem; }
.aa-pager-gap { color: var(--aa-muted); padding: 0 .15rem; }

@media (max-width: 575px) {
  .aa-pager { grid-template-columns: 1fr; justify-items: center; }
  .aa-pager-pages { grid-column: 1; }
}

/* The one-time code: wide, spaced digits, so a six-figure code reads as six figures. */
.aa-otp {
  font-size: 1.5rem;
  letter-spacing: .4em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding-left: .4em;
}

/* Icon-only buttons: square, so a row of them lines up, and the glyph is sized in em so
   it tracks the button's font size rather than being pinned to one pixel value. */
.aa-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
}
.aa-icon-btn svg { width: 1em; height: 1em; }
/* An explicit gap, because a flex row eats the whitespace between the two buttons and
   they end up sharing an edge — which reads as one wide control, not two. */
.aa-row-actions {
  display: inline-flex;
  gap: .375rem;
  justify-content: flex-end;
}

/* Modal ------------------------------------------------------------------ */
/* A native <dialog>, styled to match the cards. Bootstrap's modal needs its JS
   bundle, which the portal does not ship — the element gives us the same thing. */
.aa-modal {
  border: 1px solid var(--aa-line);
  border-radius: var(--bs-border-radius-lg);
  padding: 0;
  width: min(760px, 94vw);
  max-height: 88vh;
  background: var(--aa-surface);
  color: var(--aa-ink);
  box-shadow: 0 24px 60px rgba(28, 33, 25, .28);
}
.aa-modal::backdrop { background: rgba(28, 33, 25, .42); }

.aa-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem 1.15rem;
  border-bottom: 1px solid var(--aa-line);
}

/* Scoped to [open]: a bare `display: flex` would override the UA stylesheet's
   `dialog:not([open]) { display: none }` and leave the dialog on the page shut. */
.aa-modal[open] {
  display: flex;
  flex-direction: column;
}

.aa-modal-body {
  padding: 1.15rem;
  /* Takes whatever the head leaves and scrolls inside it — no height arithmetic that
     has to be kept in step with the head's padding. */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* Loader ----------------------------------------------------------------- */
/* A tree drawing itself limb by limb: same motif as the page background, at the one
   moment where watching something grow is the point. */
.aa-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .6rem;
  padding: 2.25rem 0;
  color: var(--aa-muted);
}
.aa-loader svg { width: 64px; height: 64px; }
.aa-loader path {
  stroke: var(--aa-canopy);
  /* One dash long enough to cover the longest limb, offset out of sight to start. */
  stroke-dasharray: 40;
  stroke-dashoffset: 40;
  animation: aa-grow 2.1s ease-in-out infinite;
}
/* Trunk first, then out along the limbs — the order a tree actually grows in. */
.aa-loader path:nth-child(1) { animation-delay: 0s; }
.aa-loader path:nth-child(2) { animation-delay: .10s; }
.aa-loader path:nth-child(3) { animation-delay: .14s; }
.aa-loader path:nth-child(4) { animation-delay: .26s; }
.aa-loader path:nth-child(5) { animation-delay: .30s; }
.aa-loader path:nth-child(6) { animation-delay: .30s; }
.aa-loader path:nth-child(7) { animation-delay: .34s; }
.aa-loader path:nth-child(8) { animation-delay: .18s; }
.aa-loader path:nth-child(9) { animation-delay: .38s; }

@keyframes aa-grow {
  0%   { stroke-dashoffset: 40; opacity: 1; }
  45%  { stroke-dashoffset: 0;  opacity: 1; }
  82%  { stroke-dashoffset: 0;  opacity: 1; }
  100% { stroke-dashoffset: 0;  opacity: 0; }
}

/* Reduced motion: the finished tree, held still. `animation: none` rather than a
   shorter duration — the global clamp above would otherwise flicker it. */
@media (prefers-reduced-motion: reduce) {
  .aa-loader path { animation: none; stroke-dashoffset: 0; }
}

/* The full-page overlay ---------------------------------------------------- */
/* Raised by loading.js, never by htmx's own indicator styles: one place to look
   whatever was clicked, and nothing that can be left switched on by a stray class. */
.aa-loading {
  position: fixed;
  inset: 0;
  z-index: 1080;
  display: grid;
  place-items: center;
  background: rgba(250, 249, 245, .88);
  /* Hidden AND inert: opacity alone would leave it swallowing clicks. */
  opacity: 0;
  visibility: hidden;
  transition: opacity .18s ease-in-out, visibility 0s linear .18s;
}
body.aa-busy .aa-loading {
  opacity: 1;
  visibility: visible;
  transition: opacity .18s ease-in-out, visibility 0s;
}

/* Mobile ------------------------------------------------------------------ */
/* Touch targets. A 2rem icon button is comfortable with a mouse and a miss with a
   thumb, so coarse pointers get the 44px the platform guidelines ask for. Keyed on
   the pointer, not the width: a small laptop still has a mouse, a big tablet does not. */
@media (pointer: coarse) {
  .aa-icon-btn { width: 2.75rem; height: 2.75rem; }
  .aa-row-actions { gap: .5rem; }
}

@media (max-width: 575px) {
  /* The dialog becomes the screen. A long tree form in a centred 88vh box leaves the
     first field under the notch and the buttons below the fold; full-bleed gives the
     form the whole viewport and keeps its own scroll. */
  .aa-modal {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  /* dvh, so the iOS address bar sliding away does not leave a gap under the form. */
  @supports (height: 100dvh) {
    .aa-modal { height: 100dvh; max-height: 100dvh; }
  }
  /* Form actions stack and go full width — two half-width buttons side by side are
     both harder to hit and easier to hit by accident. */
  .aa-actions { flex-direction: column; align-items: stretch !important; gap: .6rem !important; }
  .aa-actions .btn { width: 100%; }
  .aa-actions .lead-sm { display: none; }

  /* A long botanic name or a raw coordinate has no break opportunity, so it pushes
     the detail list wider than the phone and scrolls the whole page sideways. */
  .aa-detail dd { overflow-wrap: anywhere; }
}

/* Tooltips ---------------------------------------------------------------- */
/* Drawn from the button's own title, moved to data-tip by tooltips.js so the browser
   does not add a second one of its own a beat later. Shown on focus as well as hover:
   a control that only explains itself to a mouse explains itself to half the users. */
[data-tip] { position: relative; }

[data-tip]::after,
[data-tip]::before {
  position: absolute;
  z-index: 1090;
  opacity: 0;
  pointer-events: none;
  /* The delay is the whole point of a tooltip: it answers a pause, not a pass-over. */
  transition: opacity .12s ease-in-out .3s;
}

[data-tip]::after {
  content: attr(data-tip);
  left: 50%;
  bottom: calc(100% + .5rem);
  transform: translateX(-50%);
  width: max-content;
  max-width: 15rem;
  padding: .35rem .55rem;
  border-radius: var(--bs-border-radius-sm);
  background: var(--aa-ink);
  color: var(--aa-paper);
  font-size: .78rem;
  font-weight: 450;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  box-shadow: 0 4px 14px rgba(28, 33, 25, .22);
}

/* The pointer, so the label reads as attached to the button and not floating near it. */
[data-tip]::before {
  content: "";
  left: 50%;
  bottom: calc(100% + .15rem);
  transform: translateX(-50%);
  border: .35rem solid transparent;
  border-top-color: var(--aa-ink);
}

[data-tip]:hover::after, [data-tip]:hover::before,
[data-tip]:focus-visible::after, [data-tip]:focus-visible::before { opacity: 1; }

/* Row actions sit inside the table's horizontal scroller, which clips both axes — a
   tooltip above them would be cut off on the first row. They point left instead,
   into the width of the row, where there is always room. */
.aa-row-actions [data-tip]::after {
  left: auto;
  right: calc(100% + .5rem);
  bottom: auto;
  top: 50%;
  transform: translateY(-50%);
  text-align: left;
}
.aa-row-actions [data-tip]::before {
  left: auto;
  right: calc(100% + .15rem);
  bottom: auto;
  top: 50%;
  transform: translateY(-50%);
  border-top-color: transparent;
  border-left-color: var(--aa-ink);
}

/* A tooltip is a hover affordance. On a touch screen there is no hover, the first tap
   is the click, and a label that appears as the thumb lands just covers the next row. */
@media (pointer: coarse) {
  [data-tip]::after, [data-tip]::before { display: none; }
}
