/* Global theme control. High-specificity dark selectors override lazy page CSS. */
.theme-toggle {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-control, 15px);
  padding: 0.55rem 0.65rem;
  color: #c3d7cc;
  background: rgba(255, 255, 255, 0.045);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, background-color 160ms ease;
}

.theme-toggle:hover {
  border-color: rgba(183, 233, 130, 0.32);
  color: #fff;
  background: rgba(255, 255, 255, 0.075);
}

.theme-toggle__icon {
  width: 26px;
  height: 26px;
  display: grid;
  flex: 0 0 auto;
  border-radius: 11px;
  color: #214b36;
  background: #b7e982;
  place-items: center;
}

.theme-toggle--compact {
  width: 40px;
  height: 40px;
  min-height: 40px;
  justify-content: center;
  margin: 0;
  border-color: var(--line);
  padding: 0;
  color: var(--ink);
  background: var(--surface-strong);
}

.theme-toggle--compact .theme-toggle__icon {
  width: auto;
  height: auto;
  color: currentColor;
  background: transparent;
}

.theme-toggle--compact:hover {
  border-color: var(--forest);
  color: var(--forest);
  background: var(--surface-soft);
}

.mobile-header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-toggle--login {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 4;
  border-color: rgba(30, 73, 54, 0.2);
  box-shadow: 0 8px 24px rgba(7, 35, 25, 0.12);
}

/* Dark palette */
:root[data-theme='dark'] {
  color: #e3ede7;
  background: #0b1813;
  --workspace: #0b1813;
  --surface: #13251d;
  --surface-strong: #162a21;
  --surface-soft: #1b3127;
  --surface-raised: #1a3026;
  --surface-control: #102119;
  --surface-hover: #203a2e;
  --paper: #162a21;
  --ink: #e3ede7;
  --ink-soft: #b7c9bf;
  --muted: #8fa49a;
  --line: #294238;
  --line-strong: #3a564a;
  --line-soft: #21382f;
  --forest: #62b784;
  --forest-strong: #73c493;
  --forest-dark: #c6e5d1;
  --lime: #a8dc72;
  --danger: #f08a8e;
  --warning: #efbd70;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.26), 0 14px 38px rgba(0, 0, 0, 0.18);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.24), 0 28px 72px rgba(0, 0, 0, 0.28);
}

[data-theme='dark'] {
  scrollbar-color: #466458 #102119;
}

[data-theme='dark'] body {
  color: var(--ink);
  background:
    radial-gradient(circle at 92% -8%, rgba(89, 160, 111, 0.13), transparent 31rem),
    var(--workspace);
}

[data-theme='dark'] ::selection {
  color: #07150f;
  background: #9ed676;
}

[data-theme='dark'] :is(h1, h2, h3, strong) {
  color: var(--ink);
}

[data-theme='dark'] :is(.eyebrow, .page-header__meta small, .section-heading p, .analytics-panel__header p:last-child) {
  color: #9eb3a8;
}

[data-theme='dark'] :is(.app-main, .page, .full-state, .login-page) {
  background-color: var(--workspace);
}

[data-theme='dark'] .panel {
  border-color: var(--line);
  background: rgba(22, 42, 33, 0.96);
  box-shadow: var(--shadow-sm);
}

:root[data-theme='dark'] :is(input, select, textarea) {
  border-color: var(--line-strong);
  color: var(--ink);
  background-color: #102119;
}

:root[data-theme='dark'] :is(input, textarea)::placeholder {
  color: #789086;
}

:root[data-theme='dark'] :is(input, select, textarea):hover {
  border-color: #577467;
}

:root[data-theme='dark'] select {
  color-scheme: dark;
}

[data-theme='dark'] .button--secondary,
[data-theme='dark'] :is(.mobile-menu-button, .table-action, .operational-detail__state button) {
  border-color: var(--line-strong);
  color: var(--ink);
  background: #172b22;
}

[data-theme='dark'] .button--secondary:hover:not(:disabled),
[data-theme='dark'] :is(.mobile-menu-button, .table-action):hover {
  border-color: var(--forest);
  color: #d9eee0;
  background: #1d3529;
}

/* Authentication */
[data-theme='dark'] .login-form-wrap {
  background:
    radial-gradient(circle at 100% 0, rgba(83, 148, 102, 0.16), transparent 24rem),
    #0d1d16;
}

[data-theme='dark'] .login-form {
  border-color: var(--line-strong);
  background: rgba(20, 39, 30, 0.97);
  box-shadow: var(--shadow);
}

[data-theme='dark'] .login-form__security {
  color: #a6d5b7;
  background: #1c3829;
}

[data-theme='dark'] .login-form label {
  color: var(--ink-soft);
}

[data-theme='dark'] .login-note,
[data-theme='dark'] .divider {
  color: var(--muted);
}

/* Navigation */
[data-theme='dark'] .sidebar {
  background:
    radial-gradient(circle at -20% 100%, rgba(168, 220, 114, 0.09), transparent 21rem),
    linear-gradient(180deg, #0b2a20, #081f18);
}

[data-theme='dark'] .theme-toggle--compact {
  border-color: var(--line-strong);
  color: var(--ink);
  background: #162a21;
}

[data-theme='dark'] .mobile-header {
  border-color: var(--line);
  color: var(--ink);
  background: rgba(12, 27, 20, 0.96);
}

[data-theme='dark'] .mobile-menu {
  border-color: var(--line);
  background: #102119;
  box-shadow: -24px 0 64px rgba(0, 0, 0, 0.32);
}

[data-theme='dark'] .mobile-menu .main-nav a {
  color: #b2c6bb;
}

[data-theme='dark'] .mobile-menu .main-nav a:hover {
  background: #193027;
}

[data-theme='dark'] .mobile-menu__account {
  border-color: var(--line);
  background: #13261e;
}

[data-theme='dark'] .mobile-menu__account .account-copy strong {
  color: var(--ink);
}

[data-theme='dark'] .portal-context--mobile select {
  border-color: var(--line-strong);
  color: var(--ink);
  background: #13261e;
}

/* Filters, metrics and analytical surfaces */
[data-theme='dark'] :is(
  .analysis-filters,
  .record-filters,
  .analysis-filters__heading,
  .record-filters__heading,
  .analysis-filters__advanced,
  .record-filters__advanced,
  .prototype-toolbar,
  .network-toolbar
) {
  border-color: var(--line);
  background: var(--surface-strong);
}

[data-theme='dark'] :is(.analysis-filters__heading, .record-filters__heading, .prototype-toolbar, .network-toolbar) {
  background: #192d24;
}

[data-theme='dark'] .fiscal-filters__heading {
  border-color: var(--line);
  background: #192d24;
}

[data-theme='dark'] .fiscal-filters__heading > div > span {
  border-color: var(--line);
  color: #83ca9c;
  background: #203b2d;
}

[data-theme='dark'] .fiscal-filters__controls :is(input, select) {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface-control);
}

[data-theme='dark'] :is(.analysis-filters__title > span, .record-filters__heading > div > span, .metric-icon, .workspace-section__title > span) {
  color: #83ca9c;
  background: #203b2d;
}

[data-theme='dark'] :is(.filter-presets > div, .segmented-control, .workspace-tabs) {
  border-color: var(--line);
  background: #13261e;
}

[data-theme='dark'] :is(.filter-presets button, .segmented-control button, .workspace-tabs button) {
  color: #9db1a7;
}

[data-theme='dark'] :is(.filter-presets button, .segmented-control button, .workspace-tabs button):hover {
  color: #cce8d5;
  background: #20392e;
}

[data-theme='dark'] :is(
  .metric-tile,
  .metric-tile:nth-child(odd),
  .metric-tile:nth-child(-n+2),
  .analytics-panel,
  .workspace-chart,
  .workspace-table-card,
  .smartway-score-grid > article,
  .calendar-day-view,
  .calendar-day-view dl > div,
  .admin-data-summary span
) {
  border-color: var(--line);
  background: var(--surface-strong);
}

[data-theme='dark'] .metric-tile:hover {
  border-color: #47685a;
  background: #1a3026;
}

[data-theme='dark'] :is(.section-count, .page-header__badge) {
  border-color: var(--line);
  color: var(--ink-soft);
  background: #172b22;
  box-shadow: none;
}

[data-theme='dark'] .apex-chart__loading {
  background: linear-gradient(90deg, #172b22, #213a2f, #172b22);
}

[data-theme='dark'] .apex-chart :is(
  .apexcharts-tooltip,
  .apexcharts-xaxistooltip,
  .apexcharts-yaxistooltip
) {
  border-color: var(--line-strong) !important;
  color: var(--ink) !important;
  background: var(--surface-raised) !important;
}

[data-theme='dark'] .apex-chart .apexcharts-tooltip-title {
  border-bottom-color: var(--line) !important;
  background: var(--surface-hover) !important;
}

[data-theme='dark'] .apex-chart :is(.apexcharts-xaxistooltip-bottom::before, .apexcharts-xaxistooltip-bottom::after) {
  border-bottom-color: var(--surface-raised) !important;
}

/* Shared tables */
[data-theme='dark'] .data-table {
  --table-border: var(--line);
  --table-header-bg: #1a3026;
  --table-primary-bg: #182c23;
  --table-hover-bg: #203a2e;
  --table-muted: #8fa49a;
  border-color: var(--line-strong);
  background: #13261e;
  scrollbar-color: #49675a #102119;
}

[data-theme='dark'] .data-table :is(th, td) {
  color: var(--ink);
}

[data-theme='dark'] .data-table thead th {
  color: #b1c5bb;
}

[data-theme='dark'] .data-table__sort:hover,
[data-theme='dark'] .data-table__sort:focus-visible {
  color: #b8e4c7;
  background: #244034;
}

[data-theme='dark'] .data-table__cell--date {
  color: #c6ded1;
}

[data-theme='dark'] :is(.data-table__pagination, .data-table__sort-mobile) {
  border-color: var(--line);
  background: #15291f;
}

[data-theme='dark'] .table-toolbar {
  border-color: var(--line);
  color: var(--ink);
  background: #192e24;
}

[data-theme='dark'] .data-table__pagination button {
  border-color: var(--line-strong);
  color: var(--ink);
  background: #172b22;
}

[data-theme='dark'] :is(.operational-records__row--expanded > th, .operational-records__row--expanded > td, .operational-records__detail-row > td) {
  background: #1a3026 !important;
}

[data-theme='dark'] .operational-detail {
  border-color: var(--line-strong);
  background: #13261e;
}

[data-theme='dark'] .operational-detail__heading {
  border-color: var(--line);
  background: #203a2d;
}

[data-theme='dark'] .operational-detail__heading strong {
  color: #c8e5d2;
}

[data-theme='dark'] .operational-records__expand:hover,
[data-theme='dark'] .operational-records__expand:focus-visible,
[data-theme='dark'] .operational-records__expand[aria-expanded='true'] {
  border-color: #47685a;
  background: #274235;
}

/* Calendars, lists and detail workspaces */
[data-theme='dark'] :is(
  .calendar-day,
  .calendar-timeline > button,
  .network-card,
  .document-row,
  .network-detail__grid > div,
  .prototype-detail__facts > div,
  .network-detail__activity,
  .document-list,
  .network-list
) {
  border-color: var(--line);
  color: var(--ink);
  background: #14271f;
}

[data-theme='dark'] :is(.calendar-day--event, .calendar-timeline > button.active, .calendar-day--selected, .network-card--selected, .document-row--selected) {
  border-color: #4e765f;
  color: var(--ink);
  background: #1d382b;
}

[data-theme='dark'] :is(.network-detail, .prototype-detail) {
  background: var(--surface-strong);
}

[data-theme='dark'] :is(.network-card__logo, .network-detail__logo) {
  border-color: #3a4c44;
  background: #fff;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
}

/* Administration and dialogs */
[data-theme='dark'] :is(
  .action-modal__dialog,
  .entity-detail-modal__dialog,
  .receipt-submission__dialog,
  .admin-audit-dialog,
  .admin-receipt-dialog,
  .admin-user-dialog,
  .admin-donations-filter__menu
) {
  border-color: var(--line-strong);
  color: var(--ink);
  background: #14271f;
  box-shadow: var(--shadow);
}

[data-theme='dark'] :is(
  .action-modal__header,
  .action-modal__footer,
  .entity-detail-modal__topbar,
  .entity-detail-modal__footer,
  .receipt-submission__header,
  .receipt-submission__footer,
  .admin-donations__heading,
  .admin-receipts-panel__heading,
  .admin-users-heading
) {
  border-color: var(--line);
  background: #192e24;
}

[data-theme='dark'] :is(.action-modal__close, .entity-detail-modal__close) {
  border-color: var(--line);
  color: var(--ink);
  background: #1d3429;
}

[data-theme='dark'] :is(.action-modal, .entity-detail-modal, .receipt-submission, .admin-audit-dialog-backdrop, .admin-receipt-dialog-backdrop, .admin-user-dialog-backdrop) {
  background: rgba(2, 10, 6, 0.76);
}

/* Partner surfaces that are light in the default theme */
[data-theme='dark'] :is(
  .partner-section,
  .partner-metric,
  .partner-opportunity,
  .partner-map,
  .partner-map__card,
  .partner-preferences,
  .partner-profile,
  .partner-receipt-action,
  .partner-receipt-client,
  .partner-receipt-workspace,
  .partner-resource-list,
  .partner-empty-state
) {
  border-color: var(--line);
  color: var(--ink);
  background-color: var(--surface-strong);
}

/*
 * Component surface audit
 *
 * Keep this layer after every component stylesheet. Several legacy components
 * still use literal light colours, so the dark theme owns their final computed
 * surface and text colours here.
 */
:root[data-theme='dark'] :is(
  .impact-section .impact-item,
  .benefit-split > article,
  .report-metrics > div,
  .period-brief__highlight
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-strong);
}

:root[data-theme='dark'] :is(.impact-group > h3, .impact-item__label) {
  color: var(--ink-soft);
}

:root[data-theme='dark'] :is(.impact-item p, .benefit-split dt) {
  color: var(--muted);
}

:root[data-theme='dark'] .benefit-split {
  border-color: var(--line);
  background: var(--line);
}

:root[data-theme='dark'] :is(
  .macro-markets__heading > span,
  .macro-market-card__icon
) {
  color: #8bd0a2;
  background: #203b2d;
}

:root[data-theme='dark'] .macro-market-card__icon {
  border-color: #315040;
}

:root[data-theme='dark'] .macro-market-card__identity > span {
  color: var(--muted);
}

:root[data-theme='dark'] :is(
  .macro-markets__export,
  .macro-market-card,
  .macro-markets__empty
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-strong);
}

:root[data-theme='dark'] .macro-markets__export:hover:not(:disabled) {
  border-color: var(--forest);
  color: #d8eee0;
  background: var(--surface-hover);
}

:root[data-theme='dark'] :is(
  .macro-markets__heading p:last-child,
  .macro-market-card__ratio span,
  .macro-market-card dt,
  .macro-markets__empty
) {
  color: var(--muted);
}

:root[data-theme='dark'] .macro-market-card__meter {
  background: #263d33;
}

:root[data-theme='dark'] :is(
  .calendar-mode-switch > .workspace-tabs,
  .calendar-panel > .workspace-tabs,
  .calendar-day-view,
  .calendar-day-view dl > div,
  .agenda-detail dl > div
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-control);
}

:root[data-theme='dark'] :is(
  .agenda-detail dt,
  .agenda-detail > div:first-child small,
  .agenda-detail > p
) {
  color: var(--muted);
}

:root[data-theme='dark'] .agenda-detail dd {
  color: var(--ink);
}

:root[data-theme='dark'] .calendar-visit-participants li {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface-raised);
}

:root[data-theme='dark'] .calendar-visit-participants dd > span {
  color: var(--muted);
}

:root[data-theme='dark'] .calendar-controls button {
  border-color: var(--line-strong);
  color: #8bd0a2;
  background: var(--surface-raised);
}

:root[data-theme='dark'] .calendar-controls button:hover:not(:disabled) {
  border-color: var(--forest);
  background: var(--surface-hover);
}

:root[data-theme='dark'] .calendar-controls button:disabled {
  color: #61776d;
  background: #12241c;
}

:root[data-theme='dark'] :is(
  .calendar-day__summary,
  .calendar-layout--visits .calendar-day__summary
) {
  border-left-color: var(--forest);
  color: #bde7cb;
  background: #1f3a2d;
}

:root[data-theme='dark'] .calendar-day__summary small {
  color: #a4bdb1;
}

:root[data-theme='dark'] .calendar-agenda__list > button {
  border-color: transparent;
  color: var(--ink);
  background: var(--surface-control);
}

:root[data-theme='dark'] .calendar-agenda__list > button:hover {
  border-color: #3e5f51;
  background: var(--surface-raised);
}

:root[data-theme='dark'] .calendar-agenda__list > button.active {
  border-color: var(--forest);
  color: var(--ink);
  background: #1f3a2d;
}

:root[data-theme='dark'] :is(
  .calendar-agenda__list > button small,
  .calendar-day-view p,
  .calendar-day-view dt
) {
  color: var(--muted);
}

/* Shared selectors used by the extended and administration workspaces. */
:root[data-theme='dark'] :is(
  .network-mode,
  .network-list,
  .document-list,
  .admin-user-list,
  .settings-value,
  .workspace-tabs,
  .admin-tabs,
  .analysis-filters__mobile-toggle,
  .admin-receipt-workspace > .workspace-tabs
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-strong);
}

:root[data-theme='dark'] :is(
  .network-card__icon,
  .document-row__icon,
  .admin-avatar,
  .page-state__icon,
  .admin-donations__title > span,
  .receipt-submission__title > span,
  .admin-master-data__heading > span,
  .admin-users-summary > article > span,
  .admin-visit-section-title > span
) {
  color: #84ca9c;
  background: #203b2d;
}

:root[data-theme='dark'] :is(
  .network-tags span,
  .reason-pill,
  .entity-detail-modal__badges span,
  .entity-detail-tags span.positive
) {
  border-color: var(--line);
  color: var(--ink-soft);
  background: #1c3429;
}

:root[data-theme='dark'] :is(
  .workspace-status--success,
  .prototype-status--progress,
  .metric-delta--good,
  .entity-detail-modal__state > span.active,
  .entity-schedule-grid span.active
) {
  color: #a8dfba;
  background: #1e432f;
}

:root[data-theme='dark'] :is(
  .workspace-status--progress,
  .workspace-status--warning,
  .prototype-status--warning,
  .network-status--pending
) {
  color: #f1c981;
  background: #47381f;
}

:root[data-theme='dark'] :is(
  .network-status--active,
  .analysis-filters__global-badge
) {
  border-color: #39664c;
  color: #a8dfba;
  background: #1e432f;
}

:root[data-theme='dark'] :is(
  .prototype-status--neutral,
  .metric-delta--neutral,
  .main-nav .prototype-nav-link small,
  .mobile-menu .main-nav a small
) {
  color: #a9beb3;
  background: #263c33;
}

:root[data-theme='dark'] :is(
  .reports-list > button,
  .admin-user-list > button,
  .settings-grid article,
  .report-metrics > div
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-strong);
}

:root[data-theme='dark'] :is(
  .reports-list > button:hover,
  .admin-user-list > button:hover,
  .reports-list > button.active,
  .admin-user-list > button.active
) {
  border-color: #4e765f;
  color: var(--ink);
  background: var(--surface-hover);
}

:root[data-theme='dark'] :is(
  .network-list__pagination .data-table__pagination,
  .data-table__pagination button,
  .data-table__sort-mobile,
  .data-table__sort-mobile button
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-control);
}

/* Notices remain semantic without introducing a light-mode island. */
:root[data-theme='dark'] .prototype-notice {
  border-color: #765a2d;
  border-left-color: var(--warning);
  color: #f0cc8d;
  background: #352b1d;
}

:root[data-theme='dark'] .prototype-notice :is(strong, span, small) {
  color: #e7c486;
  background: transparent;
}

:root[data-theme='dark'] :is(
  .network-detail__privacy,
  .prototype-gate
) {
  border-color: #395e4d;
  color: var(--ink-soft);
  background: #172d23;
}

:root[data-theme='dark'] .state-card__icon--warning {
  color: #f0c47c;
  background: #47381f;
}

/* Administration tables, forms and detail panels. */
:root[data-theme='dark'] :is(
  .admin-donations,
  .admin-donations__export,
  .admin-donations__receipts,
  .admin-donations__search,
  .admin-donations__zero,
  .admin-donations__filters,
  .admin-donations-filter > summary,
  .admin-donations__detail,
  .admin-receipts-detail,
  .admin-request-toolbar__actions button,
  .admin-request-message,
  .admin-audit-message,
  .admin-audit-pagination button,
  .admin-visit-form > section,
  .admin-visit-inline-input button,
  .admin-visit-chips button,
  .admin-visit-team label,
  .admin-users-summary > article,
  .admin-users-message,
  .admin-user-security,
  .admin-users-actions button,
  .admin-user-confirm,
  .admin-master-data__toolbar label > div,
  .admin-master-data__check,
  .admin-master-data__enum-summary
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-strong);
}

:root[data-theme='dark'] .admin-user-form__error {
  border-color: #d37a72;
  color: #f2bbb5;
  background: #301d1c;
}

:root[data-theme='dark'] .admin-master-data__notice {
  border-color: var(--forest);
  color: var(--ink);
  background: var(--surface-soft);
}

:root[data-theme='dark'] :is(
  .admin-master-data__notice span,
  .admin-master-data__enum-summary span,
  .admin-master-data__enum-summary small
) {
  color: var(--muted);
}

/* Workspace ERP dos dados mestres (2026-08-06). As superfícies da página já
   usam as variáveis do tema; aqui ficam só os acentos que precisam de valor
   próprio no escuro -- o item ativo da navegação, o selo de origem manual e a
   linha selecionada, que no claro são verdes muito lavados e no escuro
   desapareceriam contra o fundo. */
:root[data-theme='dark'] :is(
  .admin-master-data__nav,
  .admin-master-data__workspace,
  .admin-master-data__detail,
  .admin-master-data__scope label > div,
  .admin-master-data__nav-compact select
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-strong);
}

:root[data-theme='dark'] :is(
  .admin-master-data__detail > header,
  .admin-master-data__detail > footer
) {
  border-color: var(--line);
  background: var(--surface);
}

:root[data-theme='dark'] .admin-master-data__nav button {
  color: var(--ink-soft);
}

:root[data-theme='dark'] .admin-master-data__nav button:hover {
  background: var(--surface-control);
}

:root[data-theme='dark'] .admin-master-data__nav button.is-active {
  color: #a8dfba;
  background: #203b2d;
}

:root[data-theme='dark'] .admin-master-data__nav button.is-active svg {
  color: #84ca9c;
}

:root[data-theme='dark'] .admin-master-data__code small {
  border-color: #39664c;
  color: #a8dfba;
  background: #172d23;
}

:root[data-theme='dark'] .admin-master-data tr.is-selected > * {
  background: #1c3327;
}

:root[data-theme='dark'] .admin-master-data__detail header > button {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface-control);
}

:root[data-theme='dark'] .admin-master-data__heading > span {
  border-color: var(--line);
  color: var(--muted);
  background: var(--surface-control);
}

:root[data-theme='dark'] :is(
  .admin-donations__expand-column button:hover,
  .admin-receipts-expand-column button:hover:not(:disabled),
  .admin-users-actions button:hover,
  .admin-visit-chips button:hover,
  .admin-visit-team label.selected
) {
  border-color: #4e765f;
  color: var(--ink);
  background: var(--surface-hover);
}

:root[data-theme='dark'] :is(
  .admin-audit-dialog > header button,
  .admin-receipt-dialog > header button,
  .admin-user-dialog > header button,
  .receipt-submission__header > button
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-raised);
}

:root[data-theme='dark'] :is(
  .admin-audit-dialog--visit > footer,
  .receipt-submission__footer,
  .action-modal__footer
) {
  border-color: var(--line);
  background: #192e24;
}

:root[data-theme='dark'] .action-modal__body {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-control);
}

:root[data-theme='dark'] .action-field {
  color: var(--ink-soft);
}

:root[data-theme='dark'] .action-field :is(input, select, textarea) {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface-raised);
}

:root[data-theme='dark'] .action-field :is(input, select, textarea):hover {
  border-color: #577467;
}

:root[data-theme='dark'] .action-field :is(input, select, textarea):focus {
  border-color: var(--forest);
  box-shadow: 0 0 0 3px rgba(98, 183, 132, 0.18);
}

:root[data-theme='dark'] .action-field small {
  color: var(--muted);
}

:root[data-theme='dark'] .action-modal__safety {
  border-color: #395e4d;
  color: var(--ink-soft);
  background: #172d23;
}

:root[data-theme='dark'] :is(
  .store-receipt-row--expanded > th,
  .store-receipt-row--expanded > td,
  .store-receipt-detail-row > td
) {
  border-color: var(--line);
  background: var(--surface-soft);
}

:root[data-theme='dark'] .store-receipt-detail {
  border-color: var(--line);
  background: var(--surface-strong);
}

:root[data-theme='dark'] .store-receipt-detail__heading {
  border-color: var(--line-soft);
}

:root[data-theme='dark'] .store-receipt-expand button:hover:not(:disabled),
:root[data-theme='dark'] .store-receipt-expand button:focus-visible {
  color: var(--forest-strong);
  background: var(--surface-soft);
}

:root[data-theme='dark'] :is(
  .entity-detail-modal__hero,
  .entity-detail-section,
  .entity-documents button,
  .receipt-submission__stages,
  .receipt-submission__stages span,
  .receipt-upload:hover,
  .receipt-upload--ready,
  .local-feedback
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-strong);
}

:root[data-theme='dark'] :is(
  .entity-detail-modal__monogram,
  .entity-documents__icon
) {
  color: #84ca9c;
  background: #203b2d;
}

:root[data-theme='dark'] .receipt-submission__stages div.complete span {
  color: #a8dfba;
  background: #1e432f;
}

/* Green interactive fills need dark ink to retain AA contrast. */
:root[data-theme='dark'] :is(
  .button--primary,
  .network-mode button[aria-pressed='true'],
  .admin-tabs button[aria-selected='true'],
  .segmented-control button[aria-pressed='true'],
  .portal-section-tabs button[aria-selected='true'],
  .admin-area-filter button[aria-pressed='true'],
  .workspace-tabs button[aria-selected='true'],
  .admin-request-toolbar__actions .admin-request-send,
  .admin-donations__search,
  .admin-donations__zero[aria-pressed='true'],
  .receipt-submission__stages div.active span,
  .agenda-date,
  .entity-responsible > span,
  .partner-map__card-title > span
) {
  color: #07150f;
}

:root[data-theme='dark'] :is(
  .main-nav a.active,
  .mobile-menu .main-nav a.active,
  .brand__mark,
  .account-avatar
) {
  color: #07150f;
}

/* Partner portal cards and nested controls. */
:root[data-theme='dark'] :is(
  .partner-receipt-toolbar,
  .partner-receipt-clients,
  .partner-receipt-table,
  .partner-receipt-submitted,
  .partner-opportunity dl,
  .partner-collection-list > article,
  .partner-help,
  .partner-resource-list > article,
  .partner-preferences label,
  .partner-interest-summary > div
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-strong);
}

:root[data-theme='dark'] .partner-receipt-client {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-control);
}

:root[data-theme='dark'] .partner-receipt-client--selected {
  border-color: var(--forest);
  background: var(--surface-hover);
}

:root[data-theme='dark'] :is(
  .partner-receipt-toolbar select,
  .workspace-toolbar select,
  .workspace-toolbar input,
  .workspace-search input,
  .admin-audit-filters select,
  .admin-audit-pagination select,
  .admin-receipts-filters select,
  .admin-request-toolbar input,
  .admin-users-filters select,
  .admin-users-search > div
) {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface-control);
}

:root[data-theme='dark'] :is(
  .multi-select-filter summary,
  .multi-select-filter__popover,
  .multi-select-filter__search input,
  .multi-select-filter__check,
  .table-toolbar__filter select
) {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface-control);
}

:root[data-theme='dark'] :is(
  .multi-select-filter__popover button:hover:not(:disabled),
  .multi-select-filter__popover button.is-selected,
  .multi-select-filter__footer
) {
  color: var(--ink);
  background: var(--surface-hover);
}

/*
 * Final light-island audit. These selectors come from lazy administration,
 * map and modal stylesheets loaded after this file; the root scope ensures the
 * dark contract keeps ownership of their computed surfaces.
 */
:root[data-theme='dark'] :is(
  .explained-metric-card__hint,
  .entity-detail-facts > div,
  .entity-detail-notes,
  .location-panel__summary,
  .location-panel__results-heading > span,
  .location-entity,
  .location-panel__note,
  .receipt-submission__body,
  .receipt-submission__context,
  .receipt-submission__fields input,
  .receipt-submission__fields select,
  .receipt-submission__fields textarea,
  .admin-audit-form-grid input,
  .admin-audit-form-grid select,
  .admin-audit-form-grid textarea,
  .admin-locations__notice,
  .admin-locations__heading > span,
  .admin-locations__toolbar label > div,
  .admin-locations__current-status,
  .partner-map__header,
  .partner-map__header > span,
  .partner-map__marker span,
  .partner-map__note,
  .admin-user-form input,
  .admin-user-form select,
  .partner-demo-note,
  .data-table--cards tbody > tr:not(.data-table__detail-row):not(.data-table__empty-row),
  .data-table--cards .data-table__empty-row,
  .metric-ledger,
  .admin-health-grid > article,
  .admin-matrix__header,
  .code-pill
) {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface-strong);
}

:root[data-theme='dark'] :is(
  .admin-donations__row--expanded > th,
  .admin-donations__row--expanded > td,
  .admin-donations__detail-row > td,
  .admin-receipts-row--expanded > th,
  .admin-receipts-row--expanded > td,
  .admin-receipts-detail-row > td,
  .admin-request-row--selected > th,
  .admin-request-row--selected > td,
  .admin-request-row--blocked > th,
  .admin-request-row--blocked > td,
  .location-entity:hover,
  .location-entity--selected
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-hover);
}

:root[data-theme='dark'] :is(
  .entity-documents__status--ready,
  .prototype-status--success,
  .network-detail__activity-heading > span,
  .network-tags--green span,
  .calendar-day__count
) {
  border-color: #39664c;
  color: #a8dfba;
  background: #1e432f;
}

:root[data-theme='dark'] :is(
  .entity-documents__status--pending,
  .receipt-submission__comparison,
  .page-header__badge--prototype
) {
  border-color: #765a2d;
  color: #f0cc8d;
  background: #352b1d;
}

:root[data-theme='dark'] :is(
  .receipt-submission__comparison.match,
  .receipt-submission__review-file,
  .receipt-upload--ready
) {
  border-color: #39664c;
  color: #a8dfba;
  background: #172d23;
}

:root[data-theme='dark'] :is(
  .receipt-upload--error,
  .admin-locations__form-error,
  .admin-master-data__form-error,
  .metric-delta--bad,
  .admin-guide-feedback
) {
  border-color: #7b4545;
  color: #f2b0b2;
  background: #3a2022;
}

:root[data-theme='dark'] :is(
  .workspace-status--neutral,
  .location-entity__icon,
  .admin-users-identity > span
) {
  border-color: var(--line);
  color: var(--ink-soft);
  background: var(--surface-soft);
}

:root[data-theme='dark'] :is(
  .admin-donations-filter__options label:hover,
  .admin-visit-upload > strong,
  .admin-visit-upload:hover > strong
) {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface-hover);
}

:root[data-theme='dark'] :is(.location-radius-map, .location-panel__map-loading) {
  border-color: var(--line);
  background: #102119;
}

:root[data-theme='dark'] .location-radius-map .leaflet-control-attribution {
  color: var(--ink-soft);
  background: rgba(16, 33, 25, 0.9);
}

:root[data-theme='dark'] :is(.page-state__skeleton, .state-card__loader) {
  background: linear-gradient(90deg, #172b22, #213a2f, #172b22);
}

@media (max-width: 760px) {
  .theme-toggle--login {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
  }
}
