/* Shared text roles for the authenticated WebApp and AdminApp. */
:root {
    --am-text-primary: #1f2a33;
    --am-text-secondary: #415360;
    --am-text-muted: #52616b;
    --am-text-on-accent: #ffffff;
    --am-text-link: #587789;
    --am-text-link-hover: #2c3942;
}

/* Shared dark-mode palette for the authenticated WebApp and AdminApp. */
[data-bs-theme="dark"] {
    color-scheme: dark;
    --am-dark-canvas: #0c2342;
    --am-dark-nav: #091c35;
    --am-dark-surface: #102c4a;
    --am-dark-surface-alt: #132f50;
    --am-dark-surface-elevated: #163657;
    --am-dark-border: #294969;
    --am-dark-border-strong: #3a5d7d;
    --am-dark-text: #f4f8fc;
    --am-dark-text-secondary: #c9d7e5;
    --am-dark-text-muted: #9db1c5;
    --am-dark-accent: #9bcd32;

    --bs-body-color: var(--am-dark-text);
    --bs-body-color-rgb: 244, 248, 252;
    --bs-body-bg: var(--am-dark-canvas);
    --bs-body-bg-rgb: 12, 35, 66;
    --bs-emphasis-color: #ffffff;
    --bs-emphasis-color-rgb: 255, 255, 255;
    --bs-secondary-color: var(--am-dark-text-secondary);
    --bs-secondary-color-rgb: 201, 215, 229;
    --bs-secondary-bg: var(--am-dark-surface-alt);
    --bs-secondary-bg-rgb: 19, 47, 80;
    --bs-tertiary-color: var(--am-dark-text-muted);
    --bs-tertiary-color-rgb: 157, 177, 197;
    --bs-tertiary-bg: var(--am-dark-surface);
    --bs-tertiary-bg-rgb: 16, 44, 74;
    --bs-border-color: var(--am-dark-border);
    --bs-border-color-translucent: rgba(201, 215, 229, 0.2);
    --bs-link-color: #8fc9f4;
    --bs-link-color-rgb: 143, 201, 244;
    --bs-link-hover-color: #b7ddf8;
    --bs-link-hover-color-rgb: 183, 221, 248;
    --bs-light-rgb: 16, 44, 74;
    --bs-dark-rgb: 9, 28, 53;

    --am-app-bg: var(--am-dark-canvas);
    --am-panel-bg: rgba(16, 44, 74, 0.97);
    --am-panel-header-bg: linear-gradient(180deg, rgba(22, 54, 87, 0.98), rgba(16, 44, 74, 0.96));
    --am-panel-muted-bg: rgba(19, 47, 80, 0.92);
    --am-panel-border: rgba(157, 177, 197, 0.24);
    --am-panel-shadow: 0 .45rem 1.25rem rgba(0, 8, 20, 0.28);
    --am-panel-shadow-hover: 0 .75rem 1.8rem rgba(0, 8, 20, 0.38);
    --am-field-card-header-bg: #163657;
    --am-field-card-footer-bg: #0f2947;
    --am-field-card-image-bg: #132f50;
    --am-field-card-band-border: rgba(201, 215, 229, 0.2);
    --am-field-card-frame: #52789a;
    --am-field-card-frame-hover: #718aa3;
    --am-field-card-shadow: 0 .7rem 1.7rem rgba(0, 8, 20, 0.38);
    --am-field-card-shadow-hover: 0 1rem 2.2rem rgba(0, 8, 20, 0.48);
    --am-field-card-ink: var(--am-dark-text);
    --am-field-card-data-bg: var(--am-dark-surface);
    --am-field-card-data-label: var(--am-dark-text-muted);
    --am-field-card-data-value: var(--am-dark-text);
    --am-field-card-metric-bg: var(--am-dark-surface-alt);
    --am-field-card-metric-border: var(--am-dark-border);
    --am-dark-action-border: #718aa3;
    --am-dark-action-hover-bg: #244666;

    --am-color-stone-050: #102c4a;
    --am-color-stone-050-rgb: 16, 44, 74;
    --am-color-stone-100: #0c2342;
    --am-color-stone-100-rgb: 12, 35, 66;
    --am-color-stone-200: #193957;
    --am-color-stone-200-rgb: 25, 57, 87;
    --am-brand-ink: var(--am-dark-text);
    --am-brand-ink-strong: var(--am-dark-text-secondary);
    --am-brand-muted: var(--am-dark-text-muted);
    --am-brand-surface: var(--am-dark-canvas);
    --am-brand-surface-alt: var(--am-dark-surface);
    --am-brand-surface-muted: var(--am-dark-surface-alt);
    --am-brand-support: var(--am-dark-accent);
    --am-brand-support-strong: #b0dc55;
    --am-brand-info: #72b6e8;
    --am-brand-info-strong: #8fc9f4;
    --am-text-primary: var(--am-dark-text);
    --am-text-secondary: var(--am-dark-text-secondary);
    --am-text-muted: var(--am-dark-text-muted);
    --am-text-on-accent: #ffffff;
    --am-text-link: var(--bs-link-color);
    --am-text-link-hover: var(--bs-link-hover-color);
    --am-muted-text: var(--am-dark-text-muted);
    --am-brand-deep: var(--am-dark-accent);
    --am-brand-soft: rgba(155, 205, 50, 0.14);
    --am-brand-line-soft: rgba(201, 215, 229, 0.14);
    --am-brand-line: rgba(201, 215, 229, 0.24);
    --am-brand-shadow-soft: rgba(0, 8, 20, 0.24);
    --am-brand-shadow: rgba(0, 8, 20, 0.4);
}

[data-bs-theme="dark"] body {
    background: var(--am-dark-canvas);
    color: var(--am-dark-text);
}

[data-bs-theme="dark"] .navbar.bg-white,
[data-bs-theme="dark"] .bg-white,
[data-bs-theme="dark"] .bg-light {
    background-color: var(--am-dark-surface) !important;
}

[data-bs-theme="dark"] .navbar-light {
    --bs-navbar-color: var(--am-dark-text-secondary);
    --bs-navbar-hover-color: #ffffff;
    --bs-navbar-active-color: #ffffff;
    --bs-navbar-brand-color: var(--am-dark-text);
    --bs-navbar-brand-hover-color: #ffffff;
    --bs-navbar-toggler-border-color: var(--am-dark-border);
}

[data-bs-theme="dark"] .navbar-toggler-icon {
    filter: invert(1) grayscale(1) brightness(1.7);
}

[data-bs-theme="dark"] :is(.card, .modal-content, .dropdown-menu, .list-group-item, .accordion-item, .offcanvas, .popover, .toast) {
    background-color: var(--am-dark-surface);
    border-color: var(--am-dark-border);
    color: var(--am-dark-text);
}

[data-bs-theme="dark"] :is(.card-header, .card-footer, .modal-header, .modal-footer, .accordion-button, .dropdown-header) {
    background-color: var(--am-dark-surface-alt);
    border-color: var(--am-dark-border);
    color: var(--am-dark-text);
}

[data-bs-theme="dark"] :is(.form-control, .form-select, .input-group-text) {
    background-color: var(--am-dark-surface-alt);
    border-color: var(--am-dark-border-strong);
    color: var(--am-dark-text);
}

[data-bs-theme="dark"] :is(.form-control, .form-select)::placeholder {
    color: var(--am-dark-text-muted);
    opacity: 1;
}

[data-bs-theme="dark"] .form-control:disabled,
[data-bs-theme="dark"] .form-select:disabled {
    background-color: var(--am-dark-nav);
    color: var(--am-dark-text-muted);
}

[data-bs-theme="dark"] .table {
    --bs-table-color: var(--am-dark-text);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--am-dark-border);
    --bs-table-striped-color: var(--am-dark-text);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.035);
    --bs-table-hover-color: #ffffff;
    --bs-table-hover-bg: rgba(143, 201, 244, 0.1);
}

[data-bs-theme="dark"] :is(.text-dark, .navbar-brand, h1, h2, h3, h4, h5, h6) {
    color: var(--am-dark-text) !important;
}

[data-bs-theme="dark"] :is(.text-muted, .form-text) {
    color: var(--am-dark-text-muted) !important;
}

[data-bs-theme="dark"] :is(.text-body, .text-body-emphasis) {
    color: var(--am-text-primary) !important;
}

[data-bs-theme="dark"] :is(.text-body-secondary, .text-secondary) {
    color: var(--am-text-secondary) !important;
}

[data-bs-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: var(--am-dark-text-secondary);
    --bs-btn-border-color: var(--am-dark-action-border);
    --bs-btn-hover-color: #ffffff;
    --bs-btn-hover-bg: var(--am-dark-action-hover-bg);
    --bs-btn-hover-border-color: var(--am-dark-text-muted);
    --bs-btn-focus-shadow-rgb: 143, 201, 244;
    --bs-btn-active-color: #ffffff;
    --bs-btn-active-bg: #2b5074;
    --bs-btn-active-border-color: var(--am-dark-text-secondary);
    --bs-btn-disabled-color: var(--am-dark-text-muted);
    --bs-btn-disabled-border-color: var(--am-dark-border-strong);
}

[data-bs-theme="dark"] :is(.badge.bg-warning, .btn-warning) {
    color: #332300 !important;
}

[data-bs-theme="dark"] .field-card-header__action {
    background: var(--am-dark-surface);
    border-color: var(--am-dark-action-border);
    color: var(--am-dark-text-secondary);
}

[data-bs-theme="dark"] .field-card-header__action:hover,
[data-bs-theme="dark"] .field-card-header__action:focus-visible {
    background: var(--am-dark-action-hover-bg);
    border-color: var(--am-dark-text-muted);
    color: #ffffff;
}

[data-bs-theme="dark"] .card-field .btn.btn-outline-secondary {
    background: transparent;
    border-color: var(--am-dark-action-border);
    color: var(--am-dark-text-secondary);
    opacity: 1;
}

[data-bs-theme="dark"] .card-field .btn.btn-outline-secondary:hover,
[data-bs-theme="dark"] .card-field .btn.btn-outline-secondary:focus-visible {
    background: var(--am-dark-action-hover-bg);
    border-color: var(--am-dark-text-muted);
    color: #ffffff;
}

[data-bs-theme="dark"] .footer {
    background: var(--am-dark-nav);
    border-color: var(--am-dark-border) !important;
    color: var(--am-dark-text-muted) !important;
}

[data-bs-theme="dark"] :is(.auth-card, .app-menu-tile, .release-modules__item, .research-chat__message) {
    background: var(--am-dark-surface) !important;
    border-color: var(--am-dark-border) !important;
    color: var(--am-dark-text) !important;
}

[data-bs-theme="dark"] :is(.auth-header, .auth-footer) {
    background: var(--am-dark-surface-alt) !important;
    border-color: var(--am-dark-border) !important;
    color: var(--am-dark-text-secondary) !important;
}

[data-bs-theme="dark"] :is(.auth-subtitle, .auth-process) {
    color: var(--am-dark-text-secondary) !important;
}

/* Keep the shared Module Settings and Access Profiles surfaces and foregrounds
   coupled so a dark card can never retain light-theme text colors. */
[data-bs-theme="dark"] .module-preferences,
[data-bs-theme="dark"] .module-field-access {
    --module-preferences-surface: var(--am-dark-surface);
    --module-preferences-surface-muted: var(--am-dark-surface-alt);
    --module-preferences-border: var(--am-dark-border);
    --module-preferences-border-soft: rgba(201, 215, 229, .2);
    --module-preferences-border-hover: var(--am-dark-border-strong);
    --module-preferences-text: var(--am-dark-text);
    --module-preferences-text-secondary: var(--am-dark-text-secondary);
}

[data-bs-theme="dark"] :is(
    .module-preferences__group h2,
    .module-preferences__title,
    .access-profile-permissions__copy,
    .access-profile-permissions__copy-field .form-label,
    .access-profile-permissions__toolbar,
    .access-profile-permissions__select-all .form-check-label
) {
    color: var(--module-preferences-text) !important;
}

[data-bs-theme="dark"] :is(
    .module-preferences__description,
    .access-profile-permissions__toolbar .text-muted,
    .access-profile-permissions__switches .form-check-label
) {
    color: var(--module-preferences-text-secondary) !important;
}

[data-bs-theme="dark"] .access-profile-permissions__copy {
    background: var(--module-preferences-surface-muted) !important;
    border-color: var(--module-preferences-border) !important;
}

[data-bs-theme="dark"] .module-preferences__item--soon .module-preferences__icon {
    background: var(--am-dark-surface-alt);
    color: var(--am-dark-text-muted);
}

[data-bs-theme="dark"] :is(
    .support-assistant__panel,
    .support-assistant__header,
    .support-assistant__messages,
    .support-assistant__message--assistant,
    .support-assistant__suggestions,
    .support-assistant__form,
    .card-field,
    .field-section-card,
    .field-mini-panel,
    .card-modern .card-header,
    .card-modern .card-footer,
    .soil-tests-year-block,
    .analysis-section,
    .map-legend__item,
    .field-diary__modal-content,
    .field-diary-stat,
    .field-diary-chips button,
    .getting-started-step,
    .work-messages-panel,
    .work-message__bubble,
    .work-messages-attachment-picker,
    .module-preferences__item,
    .module-field-access__field,
    .organization-tree__node,
    .organization-tree__member
) {
    background: var(--am-dark-surface) !important;
    border-color: var(--am-dark-border) !important;
    color: var(--am-dark-text) !important;
}

[data-bs-theme="dark"] .card-field {
    border-color: var(--am-field-card-frame) !important;
    box-shadow: var(--am-field-card-shadow);
}

[data-bs-theme="dark"] .card-field:hover {
    border-color: var(--am-field-card-frame-hover) !important;
    box-shadow: var(--am-field-card-shadow-hover);
}

[data-bs-theme="dark"] .field-card-weather-icon {
    filter: brightness(0) invert(1);
    opacity: .92;
}

[data-bs-theme="dark"] :is(
    .support-assistant__title,
    .support-assistant__message--assistant,
    .field-diary__detail-title,
    .field-diary__event-title,
    .field-diary-entry__title,
    .field-diary-stat strong,
    .card-field dd
) {
    color: var(--am-dark-text) !important;
}

[data-bs-theme="dark"] :is(
    .support-assistant__subtitle,
    .field-diary__detail-time,
    .field-diary__detail-text,
    .field-diary__event-time,
    .field-diary__event-summary,
    .card-field dt,
    .card-field .card-subtitle
) {
    color: var(--am-dark-text-secondary) !important;
}
