/* App shell: Bootstrap 5.3 plus a few variables (sidebar layout, brand palette). */

:root {
  /* The app is light-only: keep native controls (select popups, date pickers)
     light even when the OS is in dark mode. */
  color-scheme: light;
  --app-sidebar-width: 18rem;
  --app-topbar-height: 4rem;
  /* Brand palette: teal and forest greens with lime and orange accents. */
  --app-accent: #0b7a6b;        /* teal: primary actions, links, active nav */
  --app-accent-dark: #08604f;   /* teal hover */
  --app-accent-soft: #e3f1ee;   /* teal tint: avatar, highlights */
  --app-forest: #123d2f;        /* deep forest green: headings, emphasis */
  --app-lime: #8cc63f;          /* lime accent */
  --app-orange: #f0932b;        /* orange accent */
  --app-earth: #2e2419;         /* earth brown */
  --app-mint: #eef6ec;          /* soft mint background */
  --app-muted: #6b7280;         /* gray-500 */
  --app-border: #e5e7eb;        /* gray-200 */
  --app-hover: #f9fafb;         /* gray-50 */
  /* Menus: every dropdown (select menus and Bootstrap .dropdown-menu) shares one
     surface, so they read as the same component as the inputs that open them. */
  --app-menu-radius: .375rem;   /* Bootstrap's input/button radius */
  --app-menu-shadow: 0 12px 28px -8px rgba(17, 24, 39, .18), 0 2px 6px rgba(17, 24, 39, .06);
  --app-menu-item-hover: rgba(17, 24, 39, .045);
  --bs-link-color-rgb: 11, 122, 107;
  --bs-primary: var(--app-accent);
  --bs-primary-rgb: 11, 122, 107;
}

.btn-primary {
  --bs-btn-bg: var(--app-accent);
  --bs-btn-border-color: var(--app-accent);
  --bs-btn-hover-bg: var(--app-accent-dark);
  --bs-btn-hover-border-color: var(--app-accent-dark);
  --bs-btn-active-bg: var(--app-forest);
  --bs-btn-active-border-color: var(--app-forest);
}
.btn-outline-primary {
  --bs-btn-color: var(--app-accent);
  --bs-btn-border-color: var(--app-accent);
  --bs-btn-hover-bg: var(--app-accent);
  --bs-btn-hover-border-color: var(--app-accent);
}

/* --- Sidebar ------------------------------------------------------------------- */

.app-sidebar {
  background: #fff;
  border-right: 1px solid var(--app-border);
}
@media (min-width: 992px) {
  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--app-sidebar-width);
    z-index: 1030;
  }
}
@media (max-width: 991.98px) {
  .app-sidebar.offcanvas-lg { --bs-offcanvas-width: 20rem; }
}

.app-brand { height: var(--app-topbar-height); flex-shrink: 0; }

/* Brand mark (static/img/logo.svg): a sprout growing from the ground. */
.app-logo { display: block; flex-shrink: 0; width: 2rem; height: 2rem; }
.app-logo-lg { width: 2.5rem; height: 2.5rem; }

.app-nav { margin-left: -.5rem; margin-right: -.5rem; }
.app-nav li + li { margin-top: .25rem; }

.app-nav-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem;
  border-radius: .375rem;
  font-size: .875rem;
  font-weight: 600;
  line-height: 1.5rem;
  color: #374151;               /* gray-700 */
  text-decoration: none;
}
.app-nav-link .bi { font-size: 1.25rem; color: #9ca3af; } /* gray-400 */
.app-nav-link:hover,
.app-nav-link:focus-visible { background: var(--app-hover); color: var(--app-accent); }
.app-nav-link:hover .bi,
.app-nav-link:focus-visible .bi { color: var(--app-accent); }
.app-nav-link.active { background: var(--app-hover); color: var(--app-accent); }
.app-nav-link.active .bi { color: var(--app-accent); }
/* Logout is a POST form; make its button look like the other nav links. */
.app-nav-button { width: 100%; border: 0; background: none; text-align: left; }
.app-nav-link .app-nav-external { font-size: .75rem; }

.app-nav-heading {
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.5rem;
  color: #9ca3af;
  margin-bottom: .5rem;
}

.app-initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-width: 1.75rem;
  height: 1.5rem;
  padding: 0 .25rem;
  border: 1px solid var(--app-border);
  border-radius: .5rem;
  background: #fff;
  color: #9ca3af;
  font-size: .625rem;
  font-weight: 600;
}
.app-nav-link:hover .app-initial,
.app-nav-link.active .app-initial { border-color: var(--app-accent); color: var(--app-accent); }

/* --- Main column and top bar ---------------------------------------------------- */

@media (min-width: 992px) {
  .app-main { padding-left: var(--app-sidebar-width); }
}

/* Full width next to the sidebar; only side padding, no max-width cap. */
.app-container {
  width: 100%;
  padding: 0 1rem;
}
@media (min-width: 576px) { .app-container { padding: 0 1.5rem; } }
@media (min-width: 992px) { .app-container { padding: 0 2rem; } }

.app-topbar {
  height: var(--app-topbar-height);
  background: #fff;
  border-bottom: 1px solid var(--app-border);
  z-index: 1020;
}

.app-search {
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  padding-left: 1.75rem;
  font-size: .875rem;
  background: transparent;
}
.app-search::placeholder { color: #9ca3af; }
.app-search-icon {
  position: absolute;
  left: 0;
  color: #9ca3af;
  pointer-events: none;
}

.app-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--app-accent-soft);
  color: var(--app-accent);
  font-size: .75rem;
  font-weight: 700;
}

/* --- Content ----------------------------------------------------------------- */

.card { border: 1px solid var(--app-border); box-shadow: none; }
.table > :not(caption) > * > * { padding-top: .6rem; padding-bottom: .6rem; }
.display-6 { font-weight: 600; }

/* --- Page header + table (list pages) ---------------------------------------- */

/* Shared page header (core/page.html): breadcrumbs, title, actions. */
.min-w-0 { min-width: 0; }
.app-crumb { font-size: .875rem; font-weight: 500; color: #6b7280; text-decoration: none; }
a.app-crumb:hover { color: #374151; }
.app-crumb .bi { font-size: 1.1rem; color: #9ca3af; }
.app-crumb-sep { font-size: .9rem; color: #9ca3af; flex-shrink: 0; }
.app-heading {
  font-size: 1.5rem; line-height: 1.75rem; font-weight: 700; color: var(--app-forest);
  margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (min-width: 576px) { .app-heading { font-size: 1.875rem; line-height: 2.25rem; letter-spacing: -.025em; } }
.app-page-subtitle { font-size: .875rem; color: #6b7280; margin: .5rem 0 0; }

.app-table-wrap {
  overflow-x: auto;
  background: #fff;
  border-radius: .5rem;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / .05);
  outline: 1px solid rgb(0 0 0 / .05);
}

.app-table {
  width: 100%;
  margin: 0;
  font-size: .875rem;
  border-collapse: collapse;
}
.app-table thead th {
  background: #f9fafb;               /* gray-50 */
  color: #111827;                    /* gray-900 */
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  padding: .875rem .75rem;
  border-bottom: 1px solid #d1d5db;  /* gray-300 */
}
.app-table tbody td {
  color: #6b7280;                    /* gray-500 */
  white-space: nowrap;
  padding: 1rem .75rem;
  border-top: 1px solid #e5e7eb;     /* gray-200 */
  vertical-align: middle;
}
.app-table tbody tr:first-child td { border-top: 0; }
.app-table tfoot td,
.app-table tfoot th {
  padding: .875rem .75rem;
  border-top: 1px solid #d1d5db;
  color: #111827;
  font-weight: 600;
}
.app-table th:first-child,
.app-table td:first-child { padding-left: 1rem; }
.app-table th:last-child,
.app-table td:last-child { padding-right: 1rem; }
@media (min-width: 576px) {
  .app-table th:first-child,
  .app-table td:first-child { padding-left: 1.5rem; }
  .app-table th:last-child,
  .app-table td:last-child { padding-right: 1.5rem; }
}
.app-table .app-cell-primary { color: #111827; font-weight: 500; }
.app-table .text-end { text-align: right; }
.app-table a { color: var(--app-accent); text-decoration: none; font-weight: 500; }
.app-table a:hover { color: var(--app-forest); }
.app-table .app-empty { text-align: center; padding: 2.5rem 1rem; color: #6b7280; white-space: normal; }

/* --- Dashboard (NobleUI-style cards on a soft grey page) --------------------- */

.app-main { background: #f6faf6; min-height: 100vh; }  /* faint mint, lighter than --app-mint */
.app-card {
  border: 1px solid #d1d5db;  /* gray-300: gray-200 vanishes on the mint page */
  border-radius: .5rem;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / .05);
  background: #fff;
}
.app-card-title {
  font-size: .8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .02em;
  color: #111827;
  margin: 0;
}
.app-kpi { font-size: 1.75rem; font-weight: 600; line-height: 1.2; color: #111827; }
.app-micro { font-size: .6875rem; letter-spacing: .03em; }
.app-progress {
  width: 100%;
  max-width: 9rem;
  height: .5rem;
  border-radius: 999px;
  background: var(--app-mint);
  overflow: hidden;
}
.app-progress-wide { max-width: none; height: .375rem; }
.app-progress-bar { height: 100%; background: var(--app-accent); border-radius: 999px; }
.app-card .btn-outline-primary.active { color: #fff; background: var(--app-accent); }

/* Brand touches */
.app-kpi { color: var(--app-forest); }
.app-card-title { color: var(--app-forest); }
.app-nav-link.active { background: var(--app-mint); }

/* Country switcher */
.dropdown-menu {
  --bs-dropdown-border-color: var(--app-border);
  --bs-dropdown-border-radius: var(--app-menu-radius);
  --bs-dropdown-box-shadow: var(--app-menu-shadow);
  --bs-dropdown-padding-x: .375rem;
  --bs-dropdown-padding-y: .375rem;
  --bs-dropdown-item-border-radius: .25rem;
  --bs-dropdown-link-hover-bg: var(--app-menu-item-hover);
  --bs-dropdown-link-active-bg: var(--app-mint);
  --bs-dropdown-link-active-color: var(--app-forest);
  box-shadow: var(--app-menu-shadow) !important; /* beats the .shadow-sm utility in the templates */
}
.dropdown-item { border-radius: var(--bs-dropdown-item-border-radius); }
.dropdown-item.active .app-initial { border-color: var(--app-accent); color: var(--app-accent); }
.app-forest { color: var(--app-forest); }
/* White outline button (country switcher, back links) with dark text in every state (Bootstrap's outline hover/open state is white text). */
.app-btn-light {
  --bs-btn-bg: #fff;
  --bs-btn-color: var(--app-forest);
  --bs-btn-hover-bg: var(--app-mint);
  --bs-btn-hover-color: var(--app-forest);
  --bs-btn-hover-border-color: var(--app-accent);
  --bs-btn-active-bg: #fff;
  --bs-btn-active-color: var(--app-forest);
  --bs-btn-active-border-color: var(--app-accent);
}

/* --- Filters ------------------------------------------------------------------- */
.app-filter-label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: #6b7280; margin-bottom: .35rem; }
.app-input-icon { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: #9ca3af; pointer-events: none; }
/* Plain fields (filter bars, table rows) share one size with the buttons beside
   them: 40px tall, 14px text, the same border and radius. Outlined form fields
   (.app-outlined) keep their own 56px Material size. */
:root { --app-control-height: 2.5rem; --app-control-height-sm: 2rem; --app-control-border: #d1d5db; }
.form-control:not(.app-outlined *):not(textarea),
.form-select:not(.app-outlined *) {
  height: var(--app-control-height);
  padding-top: .5rem;
  padding-bottom: .5rem;
  font-size: .875rem;
  line-height: 1.5;
  color: #111827;
  border-color: var(--app-control-border);
  border-radius: .375rem;
}
textarea.form-control:not(.app-outlined *) { font-size: .875rem; border-color: var(--app-control-border); }
.form-control:not(.app-outlined *)::placeholder { color: #9ca3af; }
.form-control:not(.app-outlined *):hover:not(:focus):not(:disabled),
.form-select:not(.app-outlined *):hover:not(:focus):not(:disabled) { border-color: #9ca3af; }
.input-group-text { font-size: .875rem; border-color: var(--app-control-border); }
.form-control-sm:not(.app-outlined *):not(textarea), .form-select-sm:not(.app-outlined *) {
  height: var(--app-control-height-sm);
  padding-top: .25rem;
  padding-bottom: .25rem;
  font-size: .8125rem;
}
/* Buttons in a filter bar line up with the fields. */
#record-filters .btn, .app-btn-control { display: inline-flex; align-items: center; height: var(--app-control-height); font-size: .875rem; }
#record-filters input[type="date"] { min-width: 9.5rem; }
.app-chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .25rem .35rem .25rem .7rem;
  border-radius: 999px; background: var(--app-mint); border: 1px solid #d6e9d3;
  font-size: .8125rem; color: var(--app-forest);
}
.app-chip-remove {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.25rem; height: 1.25rem; border-radius: 50%;
  color: var(--app-forest); text-decoration: none;
}
.app-chip-remove:hover { background: #d6e9d3; }

/* --- Record detail --------------------------------------------------------------- */
.app-fields dt { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: #6b7280; margin-bottom: .2rem; }
.app-fields dd { margin: 0; color: #111827; font-weight: 500; }
.app-fields-stacked > div + div { margin-top: .9rem; }

.app-steps { list-style: none; margin: 0; padding: 0; position: relative; }
.app-step { display: flex; align-items: center; gap: .75rem; padding: .45rem 0; position: relative; font-size: .9rem; color: #6b7280; }
.app-step + .app-step::before {
  content: ""; position: absolute; left: .6875rem; top: -.55rem; height: 1.1rem; width: 2px; background: #e5e7eb;
}
.app-step-dot {
  width: 1.375rem; height: 1.375rem; flex-shrink: 0; border-radius: 50%;
  border: 2px solid #d1d5db; background: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: .75rem;
}
.app-step-current { color: var(--app-forest); font-weight: 600; }
.app-step-current .app-step-dot { background: var(--app-accent); border-color: var(--app-accent); color: #fff; }
.app-step-next { color: #111827; }
.app-step-next .app-step-dot { border-color: var(--app-accent); }


/* Inputs inside a table (district/program rows on the country form). */
.app-table-form tbody td { padding-top: .5rem; padding-bottom: .5rem; vertical-align: middle; }
.app-table-form tbody td .form-control { min-width: 8rem; }
.app-table-form .app-col-code { width: 7.5rem; }
.app-table-form .app-col-code .form-control { min-width: 5.5rem; text-transform: uppercase; }

/* Actions column: as narrow as its icons, so spare width goes to the data columns. */
.app-col-actions { width: 1%; white-space: nowrap; }

/* Several icon actions in one cell sit side by side. */
.app-row-actions { display: inline-flex; gap: .25rem; }

/* Icon-only row action (pencil = edit) with a tooltip naming the record. */
.app-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; border-radius: .375rem;
  font-size: 1.125rem; line-height: 1;
  color: #111827; text-decoration: none;
  transition: background-color 150ms var(--app-ease), color 150ms var(--app-ease);
}
/* Beats .app-table a (teal links) so table icons stay black until hovered. */
.app-table a.app-icon-btn { color: #111827; font-weight: normal; }
.app-icon-btn:hover, .app-icon-btn:focus-visible,
.app-table a.app-icon-btn:hover, .app-table a.app-icon-btn:focus-visible { background: var(--app-mint); color: var(--app-accent); }
.app-icon-btn:focus-visible { outline: 2px solid var(--app-accent); outline-offset: 1px; }
.tooltip { --bs-tooltip-bg: var(--app-forest); --bs-tooltip-font-size: .75rem; }

/* Confirmation dialog for dangerous actions (core/base.html). */
.app-confirm-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.5rem; height: 2.5rem; border-radius: 50%;
  background: #fee2e2; color: #dc2626; font-size: 1.15rem;
}
.is-primary .app-confirm-icon { background: var(--app-mint); color: var(--app-accent); }

/* --- Material-style form controls (static/js/forms.js) ------------------------
   MUI's outlined text field and select, drawn with Bootstrap's form classes.
   Markup: core/_form_field.html (.app-outlined > control + .app-outlined-label). */

:root {
  --app-field-border: rgba(0, 0, 0, .23);
  --app-field-border-hover: rgba(0, 0, 0, .87);
  --app-field-label: rgba(0, 0, 0, .6);
  --app-field-error: #d32f2f;
  --app-ease: cubic-bezier(0, 0, .2, 1);
}

.app-outlined { position: relative; }
.app-outlined .form-control,
.app-outlined .form-select {
  height: 3.5rem;
  padding: 1rem .875rem;
  font-size: 1rem;
  line-height: 1.5rem;
  color: rgba(0, 0, 0, .87);
  background-color: #fff;
  border: 1px solid var(--app-field-border);
  border-radius: .25rem;
  transition: border-color 150ms var(--app-ease), box-shadow 150ms var(--app-ease);
}
.app-outlined .form-select { padding-right: 2.5rem; }

/* Password inputs with a show/hide eye button (static/js/forms.js). */
.app-password { position: relative; }
.app-password .form-control { padding-right: 3rem; }
.app-password-toggle {
  position: absolute; top: 50%; right: .5rem; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; padding: 0; border: 0; border-radius: 50%;
  background: none; color: var(--app-muted); font-size: 1.15rem; line-height: 1;
  transition: background-color 150ms var(--app-ease), color 150ms var(--app-ease);
}
.app-password-toggle:hover { background: var(--app-hover); color: var(--app-forest); }
.app-password-toggle:focus-visible { outline: 2px solid var(--app-accent); outline-offset: 1px; }
.app-outlined .form-control:hover:not(:disabled),
.app-outlined .form-select:hover:not(:disabled) { border-color: var(--app-field-border-hover); }
/* Focus: a 2px primary outline drawn inside, so nothing shifts. */
.app-outlined .form-control:focus,
.app-outlined .form-select:focus,
.app-select.is-open .form-select {
  border-color: var(--app-accent);
  box-shadow: inset 0 0 0 1px var(--app-accent);
  outline: 0;
}
.app-outlined .form-control:disabled,
.app-outlined .form-select:disabled {
  color: rgba(0, 0, 0, .38);
  background-color: #fff;
  border-color: rgba(0, 0, 0, .26);
}
/* Placeholders only show once the label has moved out of the way. */
.app-outlined:not(.is-filled):not(:focus-within) .form-control::placeholder { color: transparent; }

.app-outlined-label {
  position: absolute;
  top: 1rem;
  left: .625rem;
  max-width: calc(100% - 2.5rem);
  padding: 0 .25rem;
  margin: 0;
  overflow: hidden;
  font-size: 1rem;
  line-height: 1.5rem;
  color: var(--app-field-label);
  white-space: nowrap;
  text-overflow: ellipsis;
  pointer-events: none;
  transform-origin: top left;
  transition: transform 200ms var(--app-ease), color 200ms var(--app-ease), max-width 200ms var(--app-ease);
  z-index: 1;
}
/* Floated: shrink to 75% and sit centred on the top border, over a white notch. */
.app-outlined.is-filled .app-outlined-label,
.app-outlined:focus-within .app-outlined-label {
  max-width: calc(133% - 2rem);
  background: #fff;
  transform: translateY(-1.5625rem) scale(.75);
}
.app-outlined:focus-within .app-outlined-label { color: var(--app-accent); }
.app-outlined-label .app-required { color: inherit; }
.app-outlined:has(:disabled) .app-outlined-label { color: rgba(0, 0, 0, .38); }

.app-outlined.is-invalid .form-control,
.app-outlined.is-invalid .form-select { border-color: var(--app-field-error); }
.app-outlined.is-invalid .form-control:focus,
.app-outlined.is-invalid .form-select:focus,
.app-outlined.is-invalid .app-select.is-open .form-select { box-shadow: inset 0 0 0 1px var(--app-field-error); }
.app-outlined.is-invalid .app-outlined-label { color: var(--app-field-error); }

.app-helper { margin: .1875rem .875rem 0; font-size: .75rem; line-height: 1.66; color: var(--app-field-label); }
.app-helper.is-error { color: var(--app-field-error); }

/* Select: button + listbox in place of the native popup. */
.app-select { position: relative; }
.app-outlined .app-select { position: static; }
.app-select-native {
  position: absolute !important;
  width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important;
  overflow: hidden !important; clip: rect(0, 0, 0, 0) !important;
  border: 0 !important; opacity: 0; pointer-events: none;
}
.app-select-button {
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
  /* MUI's solid caret; it flips while the menu is open. */
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3e%3cpath fill='%23757575' d='M7 10l5 5 5-5z'/%3e%3c/svg%3e");
  background-size: 1.5rem;
  background-position: right .5rem center;
}
.app-select.is-open .app-select-button {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3e%3cpath fill='%23757575' d='M7 14l5-5 5 5z'/%3e%3c/svg%3e");
}
.app-select-value { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.app-select-menu {
  position: absolute;
  top: calc(100% + .25rem);
  left: 0;
  right: 0;
  z-index: 1050;
  max-height: 18.75rem;
  padding: .375rem;
  margin: 0;
  overflow-y: auto;
  list-style: none;
  background: #fff;
  border: 1px solid var(--app-border);
  border-radius: var(--app-menu-radius);
  box-shadow: var(--app-menu-shadow);
  transform-origin: top center;
  animation: app-menu-in 150ms var(--app-ease);
}
/* With a search box: the panel holds the box, and only the list scrolls. */
.app-select-menu.has-search {
  display: flex;
  flex-direction: column;
  max-height: 22.5rem;
  padding: 0;
  overflow: hidden;
}
.app-select-menu.has-search[hidden] { display: none; }
.app-select-search {
  flex: none;
  width: calc(100% - .75rem);
  margin: .375rem .375rem 0;
  padding: .4375rem .75rem .4375rem 2.25rem;
  font-size: .875rem;
  color: rgba(0, 0, 0, .87);
  background: var(--app-hover) url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='%239ca3af' d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/%3e%3c/svg%3e") no-repeat .75rem center / .875rem;
  border: 1px solid var(--app-border);
  border-radius: .25rem;
  outline: 0;
}
.app-select-search:focus { background-color: #fff; border-color: var(--app-accent); box-shadow: 0 0 0 .2rem rgba(11, 122, 107, .15); }
.app-select-search::-webkit-search-cancel-button { cursor: pointer; }
.app-select-list {
  flex: 1 1 auto;
  min-height: 0;
  padding: .375rem;
  margin: 0;
  overflow-y: auto;
  list-style: none;
}
.app-select-empty { padding: .75rem 1rem; font-size: .875rem; color: var(--app-muted); text-align: center; }
.app-select.drop-up .app-select-menu { top: auto; bottom: calc(100% + .25rem); transform-origin: bottom center; }
.app-outlined .app-select-menu { top: calc(3.5rem + .25rem); }
.app-outlined .app-select.drop-up .app-select-menu { top: auto; bottom: calc(100% + .25rem); }
@keyframes app-menu-in {
  from { opacity: 0; transform: scale(.9, .75); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .app-select-menu { animation: none; }
  .app-outlined-label { transition: none; }
}
.app-select-option {
  min-height: 2.25rem;
  padding: .375rem 1rem;
  overflow: hidden;
  font-size: 1rem;
  line-height: 1.5rem;
  color: rgba(0, 0, 0, .87);
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  user-select: none;
  border-radius: .25rem;
}
.app-select-group { padding: 0; margin: 0; list-style: none; }
/* Group headers stay pinned while their options scroll (MUI ListSubheader). */
.app-select-subheader {
  position: sticky;
  top: -.5rem;
  z-index: 1;
  padding: .5rem 1rem .25rem;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .02em;
  line-height: 1.5rem;
  color: var(--app-field-label);
  text-transform: uppercase;
  background: #fff;
}
.app-select-group .app-select-option { padding-left: 1.5rem; }
.app-select-option.is-active { background: var(--app-menu-item-hover); }
.app-select-option[aria-selected="true"] { background: var(--app-mint); color: var(--app-forest); font-weight: 500; }
.app-select-option[aria-selected="true"].is-active { background: #e2efdf; }
.app-select-option.is-placeholder { color: var(--app-field-label); font-style: italic; }
.app-select-option[aria-disabled="true"] { opacity: .38; cursor: default; }
/* Compact menus for the smaller filter selects. */
.app-select:has(.form-select-sm) .app-select-option,
#record-filters .app-select-option { font-size: .875rem; min-height: 2rem; padding: .3125rem 1rem; }

/* Form cards: a bordered card with a header strip, and dividers between groups inside it. */
.app-form-card { outline: 0; border: 1px solid var(--app-border); }
.app-form-card-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--app-border); }
.app-form-group { padding: 1.5rem; }
/* Detail rows inside a bordered card: label | value, a divider between rows. */
.app-kv { margin: 0; }
.app-kv > div {
  display: grid; grid-template-columns: minmax(8rem, 14rem) 1fr; gap: .25rem 1.5rem;
  padding: .875rem 1.5rem; border-top: 1px solid var(--app-border);
}
.app-kv > div:first-child { border-top: 0; }
.app-kv dt { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--app-muted); padding-top: .15rem; }
.app-kv dd { margin: 0; color: #111827; font-weight: 500; word-break: break-word; }
.app-kv-stacked > div { grid-template-columns: 1fr; }
.app-kv a { color: var(--app-accent); text-decoration: none; }
.app-kv a:hover { color: var(--app-forest); text-decoration: underline; }
@media (max-width: 575.98px) { .app-kv > div { grid-template-columns: 1fr; } }
.app-form-card .app-table thead th { border-top: 0; }
/* Tabs inside a card: an underline bar under the card's top edge. */
.app-tabs-header { padding: 0 1rem; border-bottom: 1px solid var(--app-border); }
.app-tabs { gap: .25rem; margin-bottom: -1px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.app-tabs .nav-link {
  display: inline-flex; align-items: center; white-space: nowrap;
  padding: .9rem .75rem; font-size: .875rem; font-weight: 500; color: var(--app-muted);
  background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  transition: color 150ms var(--app-ease), border-color 150ms var(--app-ease);
}
.app-tabs .nav-link:hover { color: var(--app-forest); border-bottom-color: var(--app-border); }
.app-tabs .nav-link.active { color: var(--app-accent); border-bottom-color: var(--app-accent); }
.app-tabs .nav-link:focus-visible { outline: 2px solid var(--app-accent); outline-offset: -2px; }
.app-tab-count {
  margin-left: .4rem; padding: 0 .45rem; min-width: 1.4rem; text-align: center;
  font-size: .75rem; line-height: 1.25rem; border-radius: 999px;
  background: var(--app-hover); color: var(--app-muted); border: 1px solid var(--app-border);
}
.app-tabs .nav-link.active .app-tab-count { background: var(--app-mint); color: var(--app-accent); border-color: #d6e9d3; }
.app-form-group + .app-form-group { border-top: 1px solid var(--app-border); }

/* Note and primary action above a table inside a tab (country districts/programs). */
.app-pane-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .85rem 1rem; border-bottom: 1px solid var(--app-border);
}
@media (max-width: 575.98px) { .app-pane-toolbar { flex-direction: column; align-items: stretch; } }

/* Checkboxes, radios and switches in the primary colour, as MUI does. */
.form-check-input:checked { background-color: var(--app-accent); border-color: var(--app-accent); }
.form-check-input:focus { border-color: var(--app-accent); box-shadow: 0 0 0 .25rem rgba(11, 122, 107, .2); }
.form-switch .form-check-input:focus:not(:checked) {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%2368a99f'/%3e%3c/svg%3e");
}
/* Plain Bootstrap fields (filter bars) focus in the primary colour too, and an
   open plain select looks exactly like a focused plain input. */
.form-control:focus, .form-select:focus,
.app-select.is-open .form-select:not(.app-outlined *) { border-color: var(--app-accent); box-shadow: 0 0 0 .25rem rgba(11, 122, 107, .2); }

/* --- Date picker (flatpickr, static/js/forms.js) --------------------------------
   Same surface as the select menus; teal for the chosen day, a ring for today,
   and greyed-out days outside the allowed range (e.g. after today). */
.app-date-input {
  padding-right: 2.75rem !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M14 0H2a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2M1 3.857C1 3.384 1.448 3 2 3h12c.552 0 1 .384 1 .857v10.286c0 .473-.448.857-1 .857H2c-.552 0-1-.384-1-.857z'/%3E%3Cpath d='M6.5 7a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m-9 3a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m-9 3a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .875rem center;
  background-size: 1.125rem;
  cursor: pointer;
}
.app-outlined:focus-within .app-date-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='%230b7a6b' viewBox='0 0 16 16'%3E%3Cpath d='M14 0H2a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2M1 3.857C1 3.384 1.448 3 2 3h12c.552 0 1 .384 1 .857v10.286c0 .473-.448.857-1 .857H2c-.552 0-1-.384-1-.857z'/%3E%3Cpath d='M6.5 7a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m-9 3a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m-9 3a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2m3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2'/%3E%3C/svg%3E");
}

.flatpickr-calendar {
  width: 19rem;
  padding: .5rem;
  font-family: inherit;
  border: 1px solid var(--app-border);
  border-radius: var(--app-menu-radius);
  box-shadow: var(--app-menu-shadow);
}
.flatpickr-calendar.arrowTop::before, .flatpickr-calendar.arrowTop::after,
.flatpickr-calendar.arrowBottom::before, .flatpickr-calendar.arrowBottom::after { display: none; }
.flatpickr-calendar.open { margin-top: .25rem; }
.flatpickr-innerContainer, .flatpickr-rContainer, .flatpickr-days, .dayContainer { width: 100%; min-width: 0; max-width: none; }

.flatpickr-months { align-items: center; padding: .25rem 0 .5rem; }
.flatpickr-months .flatpickr-month { height: 2.25rem; color: var(--app-forest); }
.flatpickr-current-month {
  display: flex; align-items: center; justify-content: center; gap: .375rem;
  height: 2.25rem; padding: 0; font-size: .9375rem; font-weight: 600;
}
.flatpickr-current-month span.cur-month { font-weight: 600; margin: 0; }
.flatpickr-current-month span.cur-month:hover { background: none; }
.flatpickr-current-month .numInputWrapper { width: 4.5ch; }
.flatpickr-current-month input.cur-year { font-weight: 600; padding: 0; }
.flatpickr-current-month .numInputWrapper:hover { background: var(--app-menu-item-hover); border-radius: .25rem; }
.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
  top: .75rem; display: grid; place-items: center;
  width: 2rem; height: 2rem; padding: 0; margin: 0 .25rem;
  color: var(--app-muted); border-radius: 50%;
}
.flatpickr-months .flatpickr-prev-month:hover,
.flatpickr-months .flatpickr-next-month:hover { color: var(--app-forest); background: var(--app-menu-item-hover); }
.flatpickr-months .flatpickr-disabled { visibility: hidden; }

span.flatpickr-weekday { font-size: .75rem; font-weight: 600; color: var(--app-muted); }

.flatpickr-day {
  max-width: none; height: 2.375rem; line-height: 2.375rem;
  font-size: .875rem; color: #111827; border: 0; border-radius: 50%;
}
.flatpickr-day:hover, .flatpickr-day:focus { background: var(--app-mint); }
.flatpickr-day.today { box-shadow: inset 0 0 0 1px var(--app-accent); color: var(--app-accent); font-weight: 600; }
.flatpickr-day.today:hover, .flatpickr-day.today:focus { background: var(--app-accent-soft); color: var(--app-accent); }
.flatpickr-day.selected, .flatpickr-day.selected:hover, .flatpickr-day.selected:focus {
  background: var(--app-accent); color: #fff; box-shadow: none; font-weight: 600;
}
.flatpickr-day.prevMonthDay, .flatpickr-day.nextMonthDay { color: #9ca3af; }
.flatpickr-day.flatpickr-disabled, .flatpickr-day.flatpickr-disabled:hover {
  color: #d1d5db; background: none; cursor: not-allowed; text-decoration: line-through;
}

/* Month and year views: the header title drills up (days -> months -> years). */
.flatpickr-current-month span.cur-month,
.flatpickr-current-month .numInputWrapper { display: none; }
.app-dp-title {
  display: inline-flex; align-items: center; gap: .375rem; white-space: nowrap;
  padding: .25rem .625rem; font: inherit; font-weight: 600; color: var(--app-forest);
  background: none; border: 0; border-radius: var(--app-menu-radius); cursor: pointer;
}
.app-dp-title .bi { font-size: .75rem; color: var(--app-muted); }
.app-dp-title:hover:not(:disabled) { background: var(--app-menu-item-hover); }
.app-dp-title:disabled { cursor: default; opacity: 1; }
.app-dp-title:focus-visible, .app-dp-nav:focus-visible, .app-dp-cell:focus-visible {
  outline: 2px solid var(--app-accent); outline-offset: 1px;
}

.app-dp-panel {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column;
  padding: .5rem; background: #fff; border-radius: var(--app-menu-radius);
}
.app-dp-head { display: flex; align-items: center; justify-content: space-between; padding: .25rem .25rem .75rem; }
.app-dp-head .app-dp-title { font-size: .9375rem; }
.app-dp-nav {
  display: grid; place-items: center; width: 2rem; height: 2rem; padding: 0;
  color: var(--app-muted); background: none; border: 0; border-radius: 50%;
}
.app-dp-nav:hover:not(:disabled) { color: var(--app-forest); background: var(--app-menu-item-hover); }
.app-dp-nav:disabled { visibility: hidden; }
.app-dp-grid {
  flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 1fr; gap: .375rem;
}
.app-dp-cell {
  font-size: .875rem; color: #111827; background: none;
  border: 0; border-radius: 999px; cursor: pointer;
}
.app-dp-cell:hover:not(:disabled) { background: var(--app-mint); }
.app-dp-cell.is-today { box-shadow: inset 0 0 0 1px var(--app-accent); color: var(--app-accent); font-weight: 600; }
.app-dp-cell.is-selected { background: var(--app-accent); color: #fff; box-shadow: none; font-weight: 600; }
.app-dp-cell.is-selected:hover { background: var(--app-accent-dark); }
.app-dp-cell:disabled { color: #d1d5db; cursor: not-allowed; text-decoration: line-through; }

/* While the calendar is open, focus sits in it: the field keeps its focused look. */
.app-outlined.is-picking .app-outlined-label {
  max-width: calc(133% - 2rem);
  color: var(--app-accent);
  background: #fff;
  transform: translateY(-1.5625rem) scale(.75);
}
.app-outlined.is-picking .form-control { border-color: var(--app-accent); box-shadow: inset 0 0 0 1px var(--app-accent); }

/* Error pages (403/404): centered in the content area beside the sidebar. */
.app-error-state {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - var(--app-topbar-height) - 3rem);
}
@media (min-width: 992px) {
  .app-error-state { min-height: calc(100vh - var(--app-topbar-height) - 6rem); }
}
.app-error-state--bare { min-height: 100vh; padding: 1.5rem 1rem; }
.app-error-card {
  width: 100%; max-width: 36rem; padding: 3rem 2.5rem;
  background: #fff; border-radius: .75rem;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / .05), 0 8px 24px -12px rgb(17 24 39 / .12);
}
.app-error-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 4rem; height: 4rem; margin-bottom: 1.25rem;
  border-radius: 50%; background: var(--app-accent-soft); color: var(--app-accent);
  font-size: 1.75rem;
}
.app-error-code {
  margin-bottom: .25rem; font-size: .75rem; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; color: var(--app-muted);
}
