/*
 * Accessibility layer (WCAG 2.1 AA), loaded after the theme by the root layout.
 *
 *  1. Text that was too light to read on a light background. The theme and several page
 *     stylesheets use greys around 2.3:1; AA asks for 4.5:1. Only the light style is
 *     changed. Selectors start with html.light-style so they win over the originals
 *     wherever those happen to be loaded.
 *  2. A visible focus outline for keyboard users (the theme removes it from buttons).
 *  3. The "Skip to main content" link.
 *
 * The brand blue (#00a6fb) is 2.7:1 against white. Where it is used as TEXT on a light
 * background (links, outlined buttons, small labels) a darker shade of the same blue is used,
 * --rmx-a11y-primary-text. Where WHITE TEXT sits on it (filled buttons, badges, the selected
 * pill) the fill is a darker shade of the same colour: section 4 (the owner's go-ahead, L53).
 */

/* ---- 1. Text colours ------------------------------------------------------------------ */

html.light-style {
    --rmx-a11y-muted: #6f6b7d;   /* 5.2:1 on white, 4.8:1 on the page background (#f8f7fa) */
    --rmx-a11y-slate: #5d6b82;   /* 5.4:1 on white, 4.9:1 on #f1f5f9 */
    --rmx-a11y-success: #146c3c; /* 6.5:1 on white, 5.4:1 or more on the light green badge backgrounds */
    --rmx-a11y-warning: #9a5512;
    --rmx-a11y-danger: #c2272d;
    --rmx-a11y-info: #006f7d;
    --rmx-a11y-focus: #1d4ed8;

    /* Bootstrap's "secondary" text: placeholders, help text, descriptions. */
    --bs-secondary-color: var(--rmx-a11y-muted);
}

html.dark-style {
    --rmx-a11y-focus: #93c5fd;
}

html.light-style .text-muted,
html.light-style .menu-header .menu-header-text,
html.light-style .kpi-label,
html.light-style .id-chip,
html.light-style .integ-desc,
html.light-style .listings-table thead th,
html.light-style .rmx-toast__close {
    color: var(--rmx-a11y-muted) !important;
}

/* The dashboard takes its secondary text (card labels, table headings) from this variable. */
html.light-style .container-xxl {
    --kpi-secondary: var(--rmx-a11y-muted);
}

/* Public site: top navigation links and small counters. */
html.light-style .rmx-front-navbar {
    --rmx-frontnav-link: var(--rmx-a11y-slate);
}

html.light-style [data-updates-tab] small,
html.light-style .tab-btn:not(.active),
html.light-style [data-history-empty] p {
    color: var(--rmx-a11y-slate) !important;
    opacity: 1;
}

/* These sit on tinted backgrounds, so they need to be a little darker still. */
html.light-style .strategy-filter-label {
    color: #4a566b !important;
}

html.light-style .marketplace-seller-id,
html.light-style .bg-light .text-muted {
    color: #55535f !important;
}

/* The selected tab of the dashboard's insight card: violet on pale violet. */
html.light-style .nav-pills-modern .nav-link.active {
    color: #4447cf !important;
}

/* Small coloured labels on the reports and integrations pages. */
html.light-style .report-card-badge--schedules,
html.light-style .report-card-badge--schedules span,
html.light-style .integ-stat-pill--connected {
    color: var(--rmx-a11y-success) !important;
}

html.light-style .report-card-badge--runs,
html.light-style .report-card-badge--runs span {
    color: var(--rmx-a11y-warning) !important;
}

html.light-style .report-card-badge--history,
html.light-style .report-card-badge--history span {
    color: #0369a1 !important;
}

html.light-style .integ-stat-pill--total {
    color: #4447cf !important;
}

/* An outlined "success" button is green text on white. */
html.light-style .btn-outline-success:not(:active):not(.active) {
    color: var(--rmx-a11y-success) !important;
    border-color: var(--rmx-a11y-success);
}

/* The brand blue as text on a light background: same hue, dark enough to read (5.9:1 on
   white, 4.8:1 on the palest blue it sits on). Filled buttons keep the brand colour. */
html.light-style {
    --rmx-a11y-primary-text: #0069a3;
    --bs-link-color-rgb: 0, 105, 163;
    --bs-link-hover-color-rgb: 0, 85, 132;
}

html.light-style .text-primary,
html.light-style .btn-label-primary,
html.light-style .btn-text-primary,
html.light-style .btn-outline-primary:not(:active):not(.active):not(.show),
html.light-style .history-type-tab.active,
html.light-style .rmx-toc-link.active,
html.light-style .rmx-help-category__meta .fw-semibold {
    color: var(--rmx-a11y-primary-text) !important;
}

html.light-style .btn-outline-primary:not(:active):not(.active):not(.show) {
    border-color: var(--rmx-a11y-primary-text);
}

/* Plain links. :where() keeps this as weak as the theme's own `a` rule, so any class that
   gives a link its own colour still wins. */
:where(html.light-style) a {
    color: var(--rmx-a11y-primary-text);
}

/* Status colours as text. The backgrounds and the buttons keep the theme's colours. */
html.light-style .text-success,
html.light-style .bg-label-success {
    color: var(--rmx-a11y-success) !important;
}

html.light-style .text-warning,
html.light-style .bg-label-warning {
    color: var(--rmx-a11y-warning) !important;
}

html.light-style .text-danger,
html.light-style .bg-label-danger,
html.light-style .invalid-feedback {
    color: var(--rmx-a11y-danger) !important;
}

html.light-style .text-info,
html.light-style .bg-label-info {
    color: var(--rmx-a11y-info) !important;
}

html.light-style .bg-label-primary {
    color: #4b4fd9 !important; /* 5.1:1 on its #e7e7ff background */
}

html.light-style .badge.bg-label-secondary {
    color: #5a5c63 !important;
}

/* API docs: the shortcut hint was white on white, the action button dark on indigo. */
html.light-style .docs-search-trigger kbd {
    color: #475569;
}

html.light-style .docs-action-btn {
    background: #4f52e0;
}

html.light-style .docs-action-btn,
html.light-style .docs-action-btn span {
    color: #ffffff !important;
}

/* The listing page: its back link (#94a3b8, 2.6:1) and its status badges (2.9:1 to 4.2:1). */
html.light-style .ld-back-link:not(:hover) {
    color: var(--rmx-a11y-muted);
}

html.light-style .ld-status--active { color: #15803d; }
html.light-style .ld-status--inactive { color: #b91c1c; }
html.light-style .ld-status--oos { color: #b45309; }

/* ---- 1b. Text colours in dark mode ------------------------------------------------------
 * The theme's dark greys (#76778e, the admin area's #64748b) are 2.2:1 to 3.3:1 on the dark
 * cards and bars (#2f3349, #2b2f44, #1e293b). #acaec3 is 4.8:1 or more on every dark surface
 * the pages use, #94a3b8 5.7:1 or more on the admin area's.
 */
html.dark-style {
    --rmx-a11y-muted-dark: #acaec3;
    --bs-secondary-color: var(--rmx-a11y-muted-dark);
    --admin-text-muted: #94a3b8;
}

html.dark-style .text-muted,
html.dark-style .card-header small,
html.dark-style .kpi-label,
html.dark-style .integ-desc,
html.dark-style .form-control::placeholder,
html.dark-style .search-toggler span {
    color: var(--rmx-a11y-muted-dark) !important;
}

html.dark-style .container-xxl {
    --kpi-secondary: var(--rmx-a11y-muted-dark);
}

html.dark-style .ld-back-link:not(:hover) {
    color: var(--rmx-a11y-muted-dark);
}

/* Violet text on the pale-violet "label" badges: 2.6:1 in dark mode. */
html.dark-style .bg-label-primary {
    color: #a5a7ff !important;
}

/* The documentation's "API playground" button: white on light indigo, 2.4:1 in dark mode. */
html.dark-style .docs-action-btn {
    color: #0b1120;
}

/* Table headings and the SKU/ASIN chips: 2.8:1 to 4.2:1 on the dark tables; #b4b7c9 is 5.3:1
   or more on the chip's own background, the lightest of them. */
html.dark-style .listings-table thead th,
html.dark-style .table-card thead th,
html.dark-style .id-chip {
    color: #b4b7c9 !important;
}

/* Text in the onboarding page's grey boxes: 4.2:1 on #44475b. */
html.dark-style .bg-light .small {
    color: #d0d2de !important;
}

/* Coloured text on the dark surfaces: the light-mode shade of each colour is 2:1 to 4.2:1. */
html.dark-style .nav-pills-modern .nav-link.active {
    color: #c5c7ff !important;
}

html.dark-style .integ-stat-pill--total {
    color: #a5a7ff !important;
}

html.dark-style .bg-label-secondary {
    color: #c3c5d1 !important;
}

html.dark-style .bg-label-success {
    color: #5ee39b !important;
}

/* "Active" on the subscriptions page kept its light-mode pale green background: 1.9:1. */
html.dark-style .bg-success-subtle {
    background-color: rgba(40, 199, 111, 0.16) !important;
    color: #5ee39b !important;
}

html.dark-style .btn-outline-primary:not(:hover):not(:active):not(.active),
html.dark-style .btn-label-primary:not(:hover):not(:active):not(.active) {
    color: #7cd0ff !important;
}

html.dark-style .btn-outline-primary:not(:hover):not(:active):not(.active) {
    border-color: #7cd0ff !important;
}

html.dark-style .btn-outline-secondary:not(:hover):not(:active):not(.active) {
    color: #c3c5d1 !important;
    border-color: #8b8ea3 !important;
}

/* White on the theme's dark-mode red is 3.3:1; this red is 5:1. */
html.dark-style .btn-danger:not(:disabled) {
    background-color: #d32f2f !important;
    border-color: #d32f2f !important;
}

/* The legal pages' contents list: violet on the dark page, 4.2:1. */
html.dark-style .rmx-toc-link.active {
    color: #c084fc !important;
}

/* Marketplaces pages: Tailwind's light-mode colours on the dark cards. */
html.dark-style .marketplace-domain {
    color: #cbd5e1 !important;
}

html.dark-style .text-indigo-600 {
    color: #a5b4fc !important;
    border-color: currentColor !important;
}

html.dark-style .delete-marketplace {
    color: #f87171 !important;
    border-color: currentColor !important;
}

/* The strategy picker had light text on its white light-mode background (1.2:1). */
html.dark-style select.strategy-select {
    background-color: #1e293b;
    color: #e2e8f0;
    border-color: #475569;
}

/* Admin area: the subscription page's tabs, #94a3b8 on #334155 (4:1). */
html.dark-style .subscription-tabs .tab-btn:not(.active) {
    color: #cbd5e1 !important;
}

/* ---- 2. Keyboard focus ---------------------------------------------------------------- */

a:focus-visible,
button:focus-visible,
.btn:focus-visible,
[role="button"]:focus-visible,
[role="tab"]:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible,
summary:focus-visible,
.form-check-input:focus-visible,
.page-link:focus-visible,
.dropdown-item:focus-visible {
    outline: 2px solid var(--rmx-a11y-focus, #1d4ed8) !important;
    outline-offset: 2px;
}

/* ---- 3. Skip link --------------------------------------------------------------------- */

.rmx-skip-link {
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 100000;
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    background: #1d2433;
    color: #ffffff;
    font-weight: 600;
    text-decoration: none;
    transform: translateY(-200%);
}

.rmx-skip-link:focus {
    transform: none;
    color: #ffffff;
}

[dir="rtl"] .rmx-skip-link {
    left: auto;
    right: 0.5rem;
}

/* The skip link's targets take focus from the link only; they are not tab stops. */
#main-content:focus {
    outline: none;
}

/* ---- 4. White text on the brand colour (L53) ------------------------------------------- */
/*
 * White on #00a6fb is 2.7:1 and on the dark pages' purple 3.96:1; AA asks 4.5:1. Filled buttons,
 * the header's button, badges and the selected pill take a darker shade of the same colour; the
 * brand colour itself (links, logo, accents, charts) is unchanged.
 *   blue   #0077b8 4.85:1, hover and pressed #00669e 6.19:1
 *   purple #9333ea 5.38:1, hover and pressed #7e22ce 6.98:1 (the public pages in dark mode)
 * !important and the html prefix: the theme's hover rules are !important, and the public pages'
 * stylesheets load after this one.
 */

html .btn-primary,
html .rmx-front-navbar__cta {
    background-color: #0077b8 !important;
    border-color: #0077b8 !important;
}

html .btn-primary:hover,
html .btn-primary:focus,
html .btn-primary:active,
html .btn-primary.active,
html .show > .btn-primary.dropdown-toggle,
html .btn-check:checked + .btn-primary,
html .btn-outline-primary:hover,
html .btn-outline-primary:active,
html .btn-outline-primary.active,
html .rmx-front-navbar__cta:hover,
html .rmx-front-navbar__cta:focus-visible,
html .rmx-front-navbar__cta-outline:hover,
html .rmx-front-navbar__cta-outline:focus-visible {
    background-color: #00669e !important;
    border-color: #00669e !important;
}

html.light-style .badge.bg-primary,
html.light-style .nav-pills .nav-link.active {
    background-color: #0077b8 !important;
}

/* The public pages in dark mode: their primary is the brand purple. */
html[data-theme='dark'] .rmx-front-navbar__cta,
html[data-theme='dark'] .rmx-front-content .btn-primary,
html[data-theme='dark'] .rmx-front-content .badge.bg-primary {
    background-color: #9333ea !important;
    border-color: #9333ea !important;
}

html[data-theme='dark'] .rmx-front-navbar__cta:hover,
html[data-theme='dark'] .rmx-front-navbar__cta:focus-visible,
html[data-theme='dark'] .rmx-front-navbar__cta-outline:hover,
html[data-theme='dark'] .rmx-front-navbar__cta-outline:focus-visible,
html[data-theme='dark'] .rmx-front-content .btn-primary:hover,
html[data-theme='dark'] .rmx-front-content .btn-primary:focus-visible,
html[data-theme='dark'] .rmx-front-content .btn-primary:active,
html[data-theme='dark'] .rmx-front-content .btn-outline-primary:hover,
html[data-theme='dark'] .rmx-front-content .btn-outline-primary:active {
    background-color: #7e22ce !important;
    border-color: #7e22ce !important;
}
