:root {
    --site-bg: #f3f3f3;
    --site-surface: #ffffff;
    --site-surface-soft: #fafafa;
    --site-surface-raised: #fbfbfb;
    --site-text: #1f1f1f;
    --site-muted: #5f5f5f;
    --site-border: #e5e5e5;
    --site-border-strong: #d1d1d1;
    --site-primary: #3ca543;
    --site-primary-hover: #2d8032;
    --site-primary-action: #3ca543;
    --site-primary-action-hover: #2d8032;
    --site-on-primary: #ffffff;
    --site-link: #2d8032;
    --site-link-hover: #205d24;
    --site-danger: #c42b1c;
    --site-success: #107c10;
    --site-warning: #8a5700;
    --site-info: #006a8e;
    --site-control-bg: #ffffff;
    --site-control-disabled: #eeeeee;
    --site-focus: rgba(60, 165, 67, 0.3);
    --site-radius: 8px;
    --site-radius-sm: 6px;
    --site-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    --site-font: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
}

body[data-theme="dark"] {
    --site-bg: #202020;
    --site-surface: #2b2b2b;
    --site-surface-soft: #252525;
    --site-surface-raised: #303030;
    --site-text: #f3f3f3;
    --site-muted: #d6d6d6;
    --site-border: #3a3a3a;
    --site-border-strong: #78838f;
    --site-primary: #8cdd91;
    --site-primary-hover: #b8efbb;
    --site-primary-action: #3ca543;
    --site-primary-action-hover: #4db955;
    --site-on-primary: #ffffff;
    --site-link: #9be6a0;
    --site-link-hover: #c8f4cb;
    --site-danger: #ff9b94;
    --site-success: #79d9a6;
    --site-warning: #ffd166;
    --site-info: #7dd3fc;
    --site-control-bg: #30363e;
    --site-control-disabled: #1b1f24;
    --site-focus: rgba(140, 221, 145, 0.34);
    --site-shadow: none;
    color-scheme: dark;
}

body.public-theme,
body.portal-theme,
body.admin-theme {
    background:
        radial-gradient(circle at top left, rgba(60, 165, 67, 0.08), transparent 30rem),
        var(--site-bg) !important;
    color: var(--site-text);
    font-family: var(--site-font);
    letter-spacing: 0;
    color-scheme: light;
    --bs-body-bg: var(--site-bg);
    --bs-body-color: var(--site-text);
    --bs-emphasis-color: var(--site-text);
    --bs-secondary-color: var(--site-muted);
    --bs-tertiary-bg: var(--site-surface-soft);
    --bs-secondary-bg: var(--site-surface-raised);
    --bs-border-color: var(--site-border);
    --bs-link-color: var(--site-link);
    --bs-link-hover-color: var(--site-link-hover);
}

body.public-theme[data-theme="dark"],
body.portal-theme[data-theme="dark"],
body.admin-theme[data-theme="dark"] {
    color-scheme: dark;
}

body[data-theme="dark"] a:not(:where(.btn, .badge, .nav-link, .dropdown-item, .list-group-item, .navbar-brand)) {
    color: var(--site-link);
}

body[data-theme="dark"] a:not(:where(.btn, .badge, .nav-link, .dropdown-item, .list-group-item, .navbar-brand)):hover {
    color: var(--site-link-hover);
}

.card,
.modal-content,
.dropdown-menu,
.offcanvas,
.list-group-item {
    background: var(--site-surface);
    border-color: var(--site-border);
    border-radius: var(--site-radius);
}

.card {
    box-shadow: var(--site-shadow);
}

.card-header {
    background: var(--site-surface-soft);
    border-bottom-color: var(--site-border);
    font-weight: 600;
}

.btn {
    border-radius: var(--site-radius-sm);
    font-weight: 600;
}

.btn-primary {
    background: var(--site-primary-action);
    border-color: var(--site-primary-action);
    color: var(--site-on-primary);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--site-primary-action-hover);
    border-color: var(--site-primary-action-hover);
    color: var(--site-on-primary);
}

body[data-theme="dark"] .btn i,
body[data-theme="dark"] .btn span,
body[data-theme="dark"] .badge i,
body[data-theme="dark"] .badge span,
body[data-theme="dark"] .alert i,
body[data-theme="dark"] .alert span {
    color: inherit !important;
}

body[data-theme="dark"] .btn-primary,
body[data-theme="dark"] .btn-success,
body[data-theme="dark"] .btn-danger,
body[data-theme="dark"] .btn-secondary,
body[data-theme="dark"] .btn-dark {
    color: #ffffff !important;
}

body[data-theme="dark"] .btn-warning {
    border-color: #dba900;
    background: #f5c842;
    color: #302300 !important;
}

body[data-theme="dark"] .btn-warning:hover,
body[data-theme="dark"] .btn-warning:focus,
body[data-theme="dark"] .btn-warning:active {
    border-color: #f0c62c;
    background: #ffda56;
    color: #302300 !important;
}

body[data-theme="dark"] .btn-info {
    border-color: #49b7ca;
    background: #8bd8e6;
    color: #07343d !important;
}

body[data-theme="dark"] .btn-info:hover,
body[data-theme="dark"] .btn-info:focus,
body[data-theme="dark"] .btn-info:active {
    border-color: #70c9d8;
    background: #a7e4ee;
    color: #07343d !important;
}

body[data-theme="dark"] .btn-light {
    border-color: #dce7ef;
    background: #f7fbfe;
    color: #102f49 !important;
}

body[data-theme="dark"] .btn-light:hover,
body[data-theme="dark"] .btn-light:focus,
body[data-theme="dark"] .btn-light:active {
    border-color: #ffffff;
    background: #ffffff;
    color: #102f49 !important;
}

body[data-theme="dark"] .btn-outline-primary { color: var(--site-link); border-color: var(--site-link); }
body[data-theme="dark"] .btn-outline-success { color: var(--site-success); border-color: var(--site-success); }
body[data-theme="dark"] .btn-outline-warning { color: var(--site-warning); border-color: var(--site-warning); }
body[data-theme="dark"] .btn-outline-danger { color: var(--site-danger); border-color: var(--site-danger); }
body[data-theme="dark"] .btn-outline-info { color: var(--site-info); border-color: var(--site-info); }

body[data-theme="dark"] .btn-outline-primary:hover,
body[data-theme="dark"] .btn-outline-primary:focus,
body[data-theme="dark"] .btn-outline-success:hover,
body[data-theme="dark"] .btn-outline-success:focus,
body[data-theme="dark"] .btn-outline-warning:hover,
body[data-theme="dark"] .btn-outline-warning:focus,
body[data-theme="dark"] .btn-outline-danger:hover,
body[data-theme="dark"] .btn-outline-danger:focus,
body[data-theme="dark"] .btn-outline-info:hover,
body[data-theme="dark"] .btn-outline-info:focus {
    background: var(--site-surface-raised);
}

.btn-outline-secondary,
.theme-toggle-btn {
    background: var(--site-surface-raised);
    border-color: var(--site-border-strong);
    color: var(--site-text);
}

.form-control,
.form-select,
.input-group-text {
    background: var(--site-control-bg);
    color: var(--site-text);
    border-color: var(--site-border-strong);
    border-radius: var(--site-radius-sm);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--site-primary);
    box-shadow: 0 0 0 3px var(--site-focus);
}

.table {
    color: var(--site-text);
    border-color: var(--site-border);
}

.table thead th {
    background: var(--site-surface-soft);
    color: var(--site-muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.text-muted {
    color: var(--site-muted) !important;
}

body[data-theme="dark"] .card,
body[data-theme="dark"] .modal-content,
body[data-theme="dark"] .dropdown-menu,
body[data-theme="dark"] .offcanvas,
body[data-theme="dark"] .table,
body[data-theme="dark"] .list-group-item {
    background: var(--site-surface);
    color: var(--site-text);
    border-color: var(--site-border);
}

body[data-theme="dark"] .table {
    --bs-table-bg: var(--site-surface);
    --bs-table-color: var(--site-text);
    --bs-table-striped-bg: #242424;
    --bs-table-striped-color: var(--site-text);
    --bs-table-hover-bg: #333333;
    --bs-table-hover-color: var(--site-text);
    --bs-table-border-color: var(--site-border-strong);
}

body[data-theme="dark"] .table tbody,
body[data-theme="dark"] .table tbody tr,
body[data-theme="dark"] .table tbody td,
body[data-theme="dark"] .table tbody th {
    background-color: var(--bs-table-bg) !important;
    color: var(--site-text) !important;
}

body[data-theme="dark"] .table-striped tbody tr:nth-of-type(odd) td,
body[data-theme="dark"] .table-striped tbody tr:nth-of-type(odd) th {
    background-color: var(--bs-table-striped-bg) !important;
    color: var(--site-text) !important;
}

body[data-theme="dark"] .table-hover tbody tr:hover td,
body[data-theme="dark"] .table-hover tbody tr:hover th {
    background-color: var(--bs-table-hover-bg) !important;
    color: var(--site-text) !important;
}

body[data-theme="dark"] .navbar:not(#publicSiteHeader).navbar-dark .navbar-brand,
body[data-theme="dark"] .navbar:not(#publicSiteHeader).navbar-dark .nav-link,
body[data-theme="dark"] .navbar:not(#publicSiteHeader) .navbar-brand,
body[data-theme="dark"] .navbar:not(#publicSiteHeader) .nav-link {
    color: var(--site-text) !important;
}

body[data-theme="dark"] .badge.bg-light,
body[data-theme="dark"] .badge.text-dark {
    color: var(--site-text) !important;
    background: #3a3a3a !important;
    border-color: var(--site-border-strong) !important;
}

body[data-theme="dark"] .form-control::placeholder {
    color: #bdbdbd;
}

body[data-theme="dark"] .form-control,
body[data-theme="dark"] .form-select,
body[data-theme="dark"] .input-group-text {
    background: var(--site-control-bg) !important;
    color: var(--site-text) !important;
    border-color: var(--site-border-strong) !important;
}

body[data-theme="dark"] .form-control:disabled,
body[data-theme="dark"] .form-select:disabled,
body[data-theme="dark"] .form-control[readonly],
body[data-theme="dark"] fieldset:disabled .form-control,
body[data-theme="dark"] fieldset:disabled .form-select {
    background: var(--site-control-disabled) !important;
    color: #aeb9c3 !important;
    opacity: 1;
}

body[data-theme="dark"] select option,
body[data-theme="dark"] select optgroup {
    background: var(--site-control-bg);
    color: var(--site-text);
}

body[data-theme="dark"] .form-check-input {
    background-color: var(--site-control-bg);
    border-color: var(--site-border-strong);
}

body[data-theme="dark"] .form-check-input:checked {
    background-color: var(--site-primary-action);
    border-color: var(--site-primary);
}

body[data-theme="dark"] .nav-tabs {
    border-bottom-color: var(--site-border-strong);
}

body[data-theme="dark"] .nav-tabs .nav-link {
    background: transparent;
    color: var(--site-text) !important;
    border-color: transparent;
}

body[data-theme="dark"] .nav-tabs .nav-link:hover,
body[data-theme="dark"] .nav-tabs .nav-link:focus {
    background: var(--site-surface-soft);
    border-color: var(--site-border-strong);
}

body[data-theme="dark"] .nav-tabs .nav-link.active,
body[data-theme="dark"] .nav-tabs .nav-item.show .nav-link {
    background: var(--site-surface-raised) !important;
    color: var(--site-text) !important;
    border-color: var(--site-border-strong) var(--site-border-strong) var(--site-surface-raised) !important;
}

body[data-theme="dark"] .nav-pills .nav-link {
    color: var(--site-text) !important;
}

body[data-theme="dark"] .nav-pills .nav-link.active,
body[data-theme="dark"] .nav-pills .show > .nav-link {
    background: #0f6cbd !important;
    color: #ffffff !important;
}

body[data-theme="dark"] .dropdown-item,
body[data-theme="dark"] .list-group-item-action {
    color: var(--site-text);
}

body[data-theme="dark"] .dropdown-item:hover,
body[data-theme="dark"] .dropdown-item:focus,
body[data-theme="dark"] .list-group-item-action:hover,
body[data-theme="dark"] .list-group-item-action:focus {
    background: var(--site-surface-raised);
    color: var(--site-text);
}

body[data-theme="dark"] .page-link {
    border-color: var(--site-border-strong);
    background: var(--site-surface);
    color: var(--site-link);
}

body[data-theme="dark"] .page-link:hover,
body[data-theme="dark"] .page-link:focus {
    background: var(--site-surface-raised);
    color: var(--site-link-hover);
}

body[data-theme="dark"] .page-item.active .page-link {
    border-color: var(--site-primary-action);
    background: var(--site-primary-action);
    color: #ffffff;
}

body[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(1) brightness(1.8);
    opacity: .82;
}

body[data-theme="dark"] .progress {
    background: var(--site-border-strong);
}

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

body[data-theme="dark"] .text-dark:not(.btn):not(.badge) {
    color: var(--site-text) !important;
}

body[data-theme="dark"] .text-muted,
body[data-theme="dark"] .text-secondary,
body[data-theme="dark"] .form-text {
    color: var(--site-muted) !important;
}

body[data-theme="dark"] .text-primary { color: var(--site-link) !important; }
body[data-theme="dark"] .text-success { color: var(--site-success) !important; }
body[data-theme="dark"] .text-warning { color: var(--site-warning) !important; }
body[data-theme="dark"] .text-danger { color: var(--site-danger) !important; }
body[data-theme="dark"] .text-info { color: var(--site-info) !important; }

body[data-theme="dark"] .alert-success {
    border-color: #2d6a4d;
    background: #123326;
    color: #a5e8c2;
}

body[data-theme="dark"] .alert-danger {
    border-color: #74404a;
    background: #3a1c23;
    color: #ffb8c1;
}

body[data-theme="dark"] .alert-warning {
    border-color: #745b24;
    background: #372b13;
    color: #ffdc8a;
}

body[data-theme="dark"] .alert-info {
    border-color: #286171;
    background: #102f38;
    color: #a9e8f2;
}

body[data-theme="dark"] .badge.bg-success,
body[data-theme="dark"] .badge.bg-danger,
body[data-theme="dark"] .badge.bg-primary,
body[data-theme="dark"] .badge.bg-secondary,
body[data-theme="dark"] .badge.text-bg-success,
body[data-theme="dark"] .badge.text-bg-danger,
body[data-theme="dark"] .badge.text-bg-primary,
body[data-theme="dark"] .badge.text-bg-secondary {
    color: #ffffff !important;
}

body[data-theme="dark"] .badge.bg-warning,
body[data-theme="dark"] .badge.text-bg-warning {
    background: #f5c842 !important;
    color: #302300 !important;
}

body[data-theme="dark"] .badge.bg-info,
body[data-theme="dark"] .badge.text-bg-info {
    background: #8bd8e6 !important;
    color: #07343d !important;
}

body[data-theme="dark"] .bg-white,
body[data-theme="dark"] .bg-light,
body[data-theme="dark"] .bg-body-tertiary,
body[data-theme="dark"] .table-light,
body[data-theme="dark"] [style*="background:#fff"],
body[data-theme="dark"] [style*="background: #fff"],
body[data-theme="dark"] [style*="background-color:#fff"],
body[data-theme="dark"] [style*="background-color: #fff"],
body[data-theme="dark"] [style*="background:#ffffff"],
body[data-theme="dark"] [style*="background: #ffffff"],
body[data-theme="dark"] [style*="background-color:#ffffff"],
body[data-theme="dark"] [style*="background-color: #ffffff"] {
    background-color: var(--site-surface-raised) !important;
    color: var(--site-text) !important;
}

body[data-theme="dark"] .bg-white .text-dark,
body[data-theme="dark"] .bg-light .text-dark,
body[data-theme="dark"] .bg-body-tertiary .text-dark,
body[data-theme="dark"] .table-light .text-dark {
    color: var(--site-text) !important;
}

body[data-theme="dark"] .table-light > :not(caption) > * > * {
    background-color: var(--site-surface-raised) !important;
    color: var(--site-text) !important;
    border-color: var(--site-border-strong) !important;
}

/* Legacy editor output may carry light-theme inline colours. Keep scientific
   biographies and abstracts readable without affecting images or layout. */
body[data-theme="dark"] .rich-text-content,
body[data-theme="dark"] .rich-text-content :where(p, span, small, strong, em, li, h1, h2, h3, h4, h5, h6) {
    background-color: transparent !important;
    color: var(--site-text) !important;
}

body[data-theme="dark"] .rich-text-content a {
    color: var(--site-link) !important;
}

body:not(.public-theme) .theme-toggle-btn {
    min-width: 88px;
}

.auth-shell {
    min-height: calc(100vh - 7rem);
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
}

.auth-panel {
    width: min(100%, 1040px);
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(340px, 0.95fr);
    gap: 1rem;
    align-items: stretch;
}

.auth-hero,
.auth-card {
    border: 1px solid var(--site-border);
    border-radius: 12px;
    background: color-mix(in srgb, var(--site-surface) 92%, transparent);
    box-shadow: var(--site-shadow);
}

.auth-hero {
    padding: clamp(1.5rem, 3vw, 2.4rem);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    position: relative;
}

.auth-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--site-primary) 18%, transparent), transparent 42%),
        radial-gradient(circle at 86% 15%, color-mix(in srgb, var(--site-primary) 16%, transparent), transparent 18rem);
    pointer-events: none;
}

.auth-hero > * {
    position: relative;
    z-index: 1;
}

.auth-eyebrow {
    color: var(--site-primary);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.auth-title {
    color: var(--site-text);
    font-size: clamp(1.9rem, 4vw, 3rem);
    font-weight: 700;
    line-height: 1.08;
    margin: 0.6rem 0 0.85rem;
}

.auth-copy {
    color: var(--site-muted);
    max-width: 35rem;
    font-size: 1rem;
    line-height: 1.6;
}

.auth-meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.65rem;
    margin-top: 2rem;
}

.auth-meta-item {
    padding: 0.85rem;
    border: 1px solid var(--site-border);
    border-radius: 10px;
    background: var(--site-surface-raised);
}

.auth-meta-item i {
    color: var(--site-primary);
    display: block;
    margin-bottom: 0.35rem;
}

.auth-meta-item span {
    display: block;
    color: var(--site-text);
    font-size: 0.86rem;
    font-weight: 650;
}

.auth-card {
    padding: clamp(1.25rem, 3vw, 2rem);
}

.auth-card-header {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1.4rem;
}

.auth-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--site-primary-action);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.auth-card h2 {
    color: var(--site-text);
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
}

.auth-card p {
    color: var(--site-muted);
    margin: 0.2rem 0 0;
}

.auth-card .form-control {
    min-height: 46px;
}

.auth-card .btn {
    min-height: 46px;
}

.auth-link-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.9rem;
    flex-wrap: wrap;
}

.auth-link-row a {
    font-weight: 600;
    text-decoration: none;
}

@media (max-width: 860px) {
    .auth-panel {
        grid-template-columns: 1fr;
    }

    .auth-meta {
        grid-template-columns: 1fr;
    }
}
/* Progressive AJAX navigation feedback. Pages remain fully functional without JS. */
.ajax-navigation-progress {
    position: fixed;
    inset: 0 auto auto 0;
    z-index: 10000;
    width: 0;
    height: 3px;
    opacity: 0;
    pointer-events: none;
    background: linear-gradient(90deg, #0d6efd, #20c997, #ffc107);
    box-shadow: 0 0 12px rgba(13, 110, 253, .5);
    transition: width .25s ease, opacity .2s ease;
}

.ajax-navigation-loading .ajax-navigation-progress { width: 82%; opacity: 1; }
.ajax-navigation-loading body { cursor: progress; }

@media (prefers-reduced-motion: reduce) {
    .ajax-navigation-progress { transition: none; }
}
