.af-summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin: 0 0 1.5rem 0;
}

.af-card {
  background: var(--color-base-50, #fff);
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.75rem;
  padding: 1.1rem 1.25rem;
}

.af-card__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-base-500, #6b7280);
  margin-bottom: 0.35rem;
}

.af-card__value {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--color-base-900, #111827);
}

.af-chart-canvas-wrap {
  /* Chart.js's default aspect-ratio sizing can't tell title/legend/x-axis-label
     overhead apart from real plot space, so it's given an explicit height and
     told (maintainAspectRatio: false in the template JS) to just fill it. */
  height: 320px;
}

.af-chart-wrap {
  background: var(--color-base-50, #fff);
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.75rem;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.af-job-panel {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.af-job-status {
  font-size: 0.85rem;
  color: var(--color-base-600, #4b5563);
}

/* Also applied to links that act as buttons (a "view this elsewhere" action),
   which need the anchor defaults neutralised to sit level with real buttons. */
.af-btn {
  display: inline-block;
  line-height: 1.25;
  text-decoration: none;
  border: 1px solid var(--color-primary-600, #f66f00);
  background: var(--color-primary-600, #f66f00);
  color: #fff;
  border-radius: 0.5rem;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.af-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.af-btn--secondary {
  background: transparent;
  color: var(--color-primary-600, #f66f00);
}

.af-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.af-info-card {
  background: var(--color-base-50, #fff);
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.75rem;
  padding: 1rem 1.25rem 1.25rem;
}

.af-info-card__header {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-base-900, #111827);
  padding-bottom: 0.6rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid var(--color-base-200, #e5e7eb);
}

.af-info-card__row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.85rem;
  padding: 0.3rem 0;
  color: var(--color-base-700, #374151);
}

.af-info-card__row span:first-child {
  color: var(--color-base-500, #6b7280);
}

.af-stat-badge {
  display: inline-block;
  background: var(--color-base-100, #f3f4f6);
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-size: 0.8rem;
  color: var(--color-base-700, #374151);
}

.af-stat-badge--accent {
  background: var(--color-primary-50, #fff4eb);
  border-color: var(--color-primary-200, #ffd5b2);
  color: var(--color-primary-700, #cc5c00);
}

.af-date-input {
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.5rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

.af-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--color-base-200, #e5e7eb);
}

.af-tab {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--color-base-600, #4b5563);
  border-bottom: 2px solid transparent;
}

.af-tab--active {
  color: var(--color-primary-600, #f66f00);
  border-bottom-color: var(--color-primary-600, #f66f00);
  font-weight: 600;
}

.af-period-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  background: var(--color-base-50, #fff);
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.75rem;
  padding: 0.75rem 1.25rem;
  margin-bottom: 1.5rem;
}

/* Inactive pills read as available actions rather than disabled ones, so they
   stay in the brand's colour family. */
.af-period {
  border: 1px solid var(--color-primary-200, #ffd5b2);
  background: transparent;
  color: var(--color-primary-700, #cc5c00);
  border-radius: 0.4rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.af-period:hover:not(.af-period--active) {
  background: var(--color-primary-50, #fff4eb);
  border-color: var(--color-primary-400, #ff953d);
}

.af-period--active {
  background: var(--color-primary-600, #f66f00);
  border-color: var(--color-primary-600, #f66f00);
  color: #fff;
}

.af-table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  margin: 0.5rem 0;
}

.af-table-toolbar select,
.af-table-toolbar input {
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.4rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

.af-table-scroll {
  overflow-x: auto;
}

.af-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.af-table th,
.af-table td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--color-base-200, #e5e7eb);
  white-space: nowrap;
}

.af-table th {
  color: var(--color-base-500, #6b7280);
  font-weight: 600;
}

.af-table tbody tr:nth-child(even) {
  background: var(--color-base-50, #f9fafb);
}

/* Panel with a proper header bar. Replaces an earlier negative-margin hack
   that left section titles sitting outside their card. */
/* No overflow:hidden here on purpose: a section can hold a themed dropdown
   or date-picker popover (see .af-dropdown__list / .af-calendar below) that
   needs to float past its own bottom edge. Clipping was cutting those off —
   the corner-rounding job it used to do is handled by rounding the header's
   own top corners instead (below), which achieves the same look without
   clipping anything nested inside. */
.af-section {
  background: var(--color-base-50, #fff);
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.75rem;
  margin-bottom: 1.5rem;
}

.af-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.8rem 1.25rem;
  background: var(--color-base-100, #f3f4f6);
  border-bottom: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.75rem 0.75rem 0 0;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-base-900, #111827);
}

.af-section__header .af-job-status {
  font-weight: 400;
}

.af-section__body {
  padding: 1.25rem;
}

.af-subgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

/* Same reasoning as .af-section above: the Historical/Forecast Weather
   subpanels hold date fields, so this can't clip their calendar popovers. */
.af-subpanel {
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.6rem;
}

.af-subpanel__header {
  padding: 0.6rem 1rem;
  background: var(--color-base-100, #f3f4f6);
  border-bottom: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.6rem 0.6rem 0 0;
  font-weight: 600;
  font-size: 0.85rem;
}

.af-subpanel__body {
  padding: 1rem;
}

.af-field-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 0.6rem;
}

.af-field-row label {
  font-size: 0.8rem;
  color: var(--color-base-600, #4b5563);
}

.af-select {
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.5rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
  width: 100%;
}

.af-toggle {
  display: flex;
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.5rem;
  overflow: hidden;
}

.af-toggle button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--color-base-700, #374151);
}

.af-toggle button.af-toggle--active {
  background: var(--color-primary-600, #f66f00);
  color: #fff;
}

/* ---- busy / loading feedback -------------------------------------------
   Queries against the production database can take seconds, so anything that
   triggers one needs to say so immediately. */
.af-spinner {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-right: 0.45em;
  vertical-align: -0.1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: af-spin 0.6s linear infinite;
}

@keyframes af-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .af-spinner { animation-duration: 2s; }
}

.af-is-busy {
  opacity: 0.85;
  cursor: progress;
}

.af-loading-banner {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--color-primary-700, #cc5c00);
  background: var(--color-primary-50, #fff4eb);
  border: 1px solid var(--color-primary-200, #ffd5b2);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
}

.af-loading-banner::before {
  content: "";
  width: 0.75em;
  height: 0.75em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: af-spin 0.6s linear infinite;
}

/* Controls stay visible but read as unavailable while a load is running. */
.af-control--busy {
  opacity: 0.55;
  cursor: progress;
}

/* Charts and tables dim slightly so it's obvious they're being replaced. */
body.af-loading .af-chart-canvas-wrap,
body.af-loading .af-table-scroll {
  opacity: 0.45;
  transition: opacity 0.15s ease;
}

/* ---- sortable headers + column hints ----------------------------------- */
.af-table th.af-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.af-table th.af-sortable:hover {
  color: var(--color-primary-600, #f66f00);
}

.af-table th.af-sorted {
  color: var(--color-primary-600, #f66f00);
}

.af-sort-arrow {
  margin-left: 0.3rem;
  font-size: 0.7em;
  opacity: 0.6;
}

.af-table th.af-sorted .af-sort-arrow {
  opacity: 1;
}

/* Column provenance ("where does this number come from?"), matching the
   info icons anode-admin puts in its table headers. */
.af-hint {
  cursor: help;
  text-decoration: none;
  border: 0;
  opacity: 0.55;
}

/* ---- section header toolbar -------------------------------------------- */
/* Buttons and the data filter sit on the right of a section's header bar,
   rather than floating over its title. */
.af-section__tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-left: auto;
}

.af-section__tools label {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--color-base-600, #4b5563);
}

.af-filter-select {
  border: 1px solid var(--color-base-200, #e5e7eb);
  border-radius: 0.4rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  background: var(--color-base-50, #fff);
}

/* ---- landing page ------------------------------------------------------ */
.af-landing {
  min-height: 100vh;
  margin: 0;
  padding: 3rem 1.5rem;
  display: flex;
  justify-content: center;
  background: linear-gradient(160deg, #fff4eb 0%, #ffffff 45%);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #111827;
}

.af-landing__inner {
  width: 100%;
  max-width: 720px;
}

.af-landing__logo {
  color: #111827;
  height: 30px;
  margin-bottom: 2rem;
}

.af-landing h1 {
  font-size: 2rem;
  line-height: 1.2;
  margin: 0 0 0.75rem;
}

.af-landing p {
  color: #4b5563;
  line-height: 1.6;
  margin: 0 0 1rem;
}

.af-landing__actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1.75rem 0;
}

.af-landing__btn {
  display: inline-block;
  border-radius: 0.5rem;
  padding: 0.6rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid #f66f00;
  background: #f66f00;
  color: #fff;
}

.af-landing__btn--ghost {
  background: transparent;
  color: #cc5c00;
}

.af-landing__cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.af-landing__card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
}

.af-landing__endpoints {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  padding: 0.5rem 1.25rem;
}

.af-landing__endpoints code {
  font-size: 0.8rem;
  color: #cc5c00;
}

/* ---- form controls -----------------------------------------------------
   Selects, search boxes and date inputs are part of the same control set as
   the buttons next to them, so they carry the brand colour too: a tinted
   border, an orange focus ring, an orange caret and selection, and a chevron
   drawn in the brand colour instead of the browser's default grey one. */
.af-filter-select,
.af-select,
.af-date-input,
.af-table-toolbar select,
.af-table-toolbar input {
  border: 1px solid var(--color-primary-200, #ffd5b2);
  background-color: var(--color-base-50, #fff);
  color: var(--color-base-800, #1f2937);
  /* Colours the native bits browsers won't let CSS reach directly. */
  accent-color: var(--color-primary-600, #f66f00);
  caret-color: var(--color-primary-600, #f66f00);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.af-filter-select:hover,
.af-select:hover,
.af-date-input:hover,
.af-table-toolbar select:hover,
.af-table-toolbar input:hover {
  border-color: var(--color-primary-400, #ff953d);
}

.af-filter-select:focus,
.af-select:focus,
.af-date-input:focus,
.af-table-toolbar select:focus,
.af-table-toolbar input:focus {
  outline: none;
  border-color: var(--color-primary-600, #f66f00);
  box-shadow: 0 0 0 3px var(--color-primary-100, #ffe9d6);
}

.af-table-toolbar input::placeholder {
  color: var(--color-primary-300, #ffb980);
}

/* The chevron has to be drawn by hand: `appearance: none` removes the
   browser's, which can't be recoloured any other way. */
select.af-filter-select,
select.af-select,
.af-table-toolbar select {
  appearance: none;
  padding-right: 1.7rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.75 6 6.5l5-4.75' fill='none' stroke='%23f66f00' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  background-size: 0.65em;
}

::selection {
  background: var(--color-primary-100, #ffe9d6);
}

/* ---- themed dropdown ---------------------------------------------------
   Replaces the native <select> popup, whose open list is drawn by the OS in
   the *system* accent colour and cannot be reached from CSS at all. The real
   select is still there, just moved out of sight (see enhanceSelect in
   forecast_page.js) so its value and change events keep working. */
.af-dropdown {
  position: relative;
  display: inline-block;
}

.af-dropdown--block {
  display: block;
  width: 100%;
}

.af-dropdown__native {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.af-dropdown__button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  border: 1px solid var(--color-primary-200, #ffd5b2);
  border-radius: 0.4rem;
  background: var(--color-base-50, #fff);
  color: var(--color-base-800, #1f2937);
  padding: 0.28rem 1.7rem 0.28rem 0.5rem;
  font: inherit;
  font-size: 0.8rem;
  text-align: left;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.75 6 6.5l5-4.75' fill='none' stroke='%23f66f00' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  background-size: 0.65em;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.af-dropdown__button:hover {
  border-color: var(--color-primary-400, #ff953d);
}

.af-dropdown__button:focus-visible,
.af-dropdown__button[aria-expanded="true"] {
  outline: none;
  border-color: var(--color-primary-600, #f66f00);
  box-shadow: 0 0 0 3px var(--color-primary-100, #ffe9d6);
}

/* Matches the padding of the taller .af-select fields it also replaces. */
select.af-select ~ .af-dropdown__button {
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
}

.af-dropdown__list {
  position: absolute;
  z-index: 60;
  top: calc(100% + 0.25rem);
  left: 0;
  min-width: 100%;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--color-base-50, #fff);
  border: 1px solid var(--color-primary-200, #ffd5b2);
  border-radius: 0.5rem;
  box-shadow: 0 10px 28px rgb(17 24 39 / 14%);
  max-height: 15rem;
  overflow-y: auto;
}

.af-dropdown__option {
  padding: 0.35rem 0.6rem;
  border-radius: 0.35rem;
  font-size: 0.8rem;
  white-space: nowrap;
  cursor: pointer;
  color: var(--color-base-800, #1f2937);
}

.af-dropdown__option:hover {
  background: var(--color-primary-50, #fff4eb);
  color: var(--color-primary-700, #cc5c00);
}

.af-dropdown__option[aria-selected="true"] {
  background: var(--color-primary-600, #f66f00);
  color: #fff;
}

/* ---- themed date picker ------------------------------------------------
   The panel an <input type="date"> opens is an OS control, so the calendar
   here is drawn in the page instead (see enhanceDateInput). The field itself
   is still the same input, holding the same ISO value. */
.af-datefield {
  position: relative;
  display: inline-block;
}

.af-datefield .af-date-input {
  padding-right: 1.9rem;
  width: 100%;
}

.af-datefield__toggle {
  position: absolute;
  top: 50%;
  right: 0.4rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem;
  border: 0;
  border-radius: 0.3rem;
  background: transparent;
  color: var(--color-primary-600, #f66f00);
  cursor: pointer;
  line-height: 0;
}

.af-datefield__toggle:hover {
  background: var(--color-primary-50, #fff4eb);
}

.af-datefield__toggle:focus-visible {
  outline: 2px solid var(--color-primary-600, #f66f00);
  outline-offset: 1px;
}

.af-calendar {
  position: absolute;
  z-index: 60;
  top: calc(100% + 0.3rem);
  left: 0;
  width: 15.5rem;
  padding: 0.6rem;
  background: var(--color-base-50, #fff);
  border: 1px solid var(--color-primary-200, #ffd5b2);
  border-radius: 0.6rem;
  box-shadow: 0 10px 28px rgb(17 24 39 / 14%);
}

.af-calendar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  font-size: 0.82rem;
  color: var(--color-base-900, #111827);
}

.af-calendar__nav {
  border: 1px solid var(--color-primary-200, #ffd5b2);
  border-radius: 0.35rem;
  background: transparent;
  color: var(--color-primary-700, #cc5c00);
  width: 1.5rem;
  height: 1.5rem;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
}

.af-calendar__nav:hover {
  background: var(--color-primary-50, #fff4eb);
  border-color: var(--color-primary-400, #ff953d);
}

.af-calendar__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.12rem;
}

.af-calendar__weekdays span {
  text-align: center;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--color-base-500, #6b7280);
  padding-bottom: 0.2rem;
}

.af-calendar__day {
  border: 0;
  border-radius: 0.35rem;
  background: transparent;
  color: var(--color-base-800, #1f2937);
  padding: 0.3rem 0;
  font-size: 0.75rem;
  cursor: pointer;
}

.af-calendar__day:hover {
  background: var(--color-primary-50, #fff4eb);
  color: var(--color-primary-700, #cc5c00);
}

/* Days spilling in from the neighbouring months stay legible but recede. */
.af-calendar__day--outside {
  color: var(--color-base-400, #9ca3af);
}

.af-calendar__day--today {
  box-shadow: inset 0 0 0 1px var(--color-primary-300, #ffb980);
}

.af-calendar__day--selected {
  background: var(--color-primary-600, #f66f00);
  color: #fff;
  font-weight: 600;
}

.af-calendar__footer {
  display: flex;
  justify-content: space-between;
  margin-top: 0.5rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--color-base-200, #e5e7eb);
}

.af-calendar__link {
  border: 0;
  background: transparent;
  color: var(--color-primary-700, #cc5c00);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.1rem 0.2rem;
  border-radius: 0.25rem;
}

.af-calendar__link:hover {
  background: var(--color-primary-50, #fff4eb);
}
