/*
 * WCAG contrast fixes (audit 2026-11-06, X-1 dark theme / X-2 light theme).
 *
 * Root causes: Bootstrap's warning/info/success colours used as text on white or
 * with white text as badge backgrounds (1.65-2.9:1), and hard-coded light colours
 * that ignore the dark theme. Targeted overrides, loaded last; the long-term fix
 * is to route page CSS through Bootstrap theme variables.
 */

/* ---- Light theme -------------------------------------------------------- */
[data-bs-theme="light"] .badge.bg-warning,
[data-bs-theme="light"] .badge.bg-info,
[data-bs-theme="light"] .badge.bg-warning .small,
[data-bs-theme="light"] .badge.bg-info .small { color: #1f2937 !important; }            /* was white on amber/cyan, 2.1-2.4:1 */
[data-bs-theme="light"] .text-info,
[data-bs-theme="light"] .btn-outline-info { color: #0e7490 !important; }               /* was #0dcaf0, 1.65-1.96:1 */
[data-bs-theme="light"] .btn-outline-info { border-color: #0e7490 !important; }
[data-bs-theme="light"] .btn-outline-info:hover,
[data-bs-theme="light"] .btn-outline-info:focus { background-color: #0e7490 !important; color: #fff !important; }
[data-bs-theme="light"] .text-success,
[data-bs-theme="light"] .currency-cell,
[data-bs-theme="light"] .kpi-value.positive { color: #047857 !important; }              /* was #10b981 / #27ae60, 2.5-2.9:1 */
[data-bs-theme="light"] .text-warning { color: #92400e !important; }

/* ---- Dark theme --------------------------------------------------------- */
[data-bs-theme="dark"] { --text-dark: #f1f5f9; }                                         /* landing section titles were #0f172a on #111827 (1.01:1) */
[data-bs-theme="dark"] .navbar-main-brand span:not(.badge) { color: #a5b4fc !important; } /* brand 2.84:1 -> 7:1 */
[data-bs-theme="dark"] .status-active { color: #14532d !important; }                      /* admin users: white on light green 1.1:1 */
[data-bs-theme="dark"] .value-param-btn { color: #212529; }                               /* white text on white button 1.0:1 */
[data-bs-theme="dark"] .chart-card { background-color: var(--bs-body-bg); color: var(--bs-body-color); }
[data-bs-theme="dark"] .chart-card h1, [data-bs-theme="dark"] .chart-card h2,
[data-bs-theme="dark"] .chart-card h3, [data-bs-theme="dark"] .chart-card h4,
[data-bs-theme="dark"] .chart-card h5 { color: var(--bs-body-color); }
[data-bs-theme="dark"] .bg-light { background-color: var(--bs-tertiary-bg) !important; }  /* light panels kept light text on light bg (1.0:1) */
[data-bs-theme="dark"] .bg-light .text-dark { color: inherit !important; }
[data-bs-theme="dark"] .leaflet-control-attribution,
[data-bs-theme="dark"] .leaflet-control-attribution a { color: #1f2937; }                 /* attribution links 1.2-1.8:1 */
[data-bs-theme="dark"] .leaflet-bar a { color: #1f2937; }

/* ---- Dark theme: second pass (found by re-running the checker) ----------- */
[data-bs-theme="dark"] .section-title { color: #f1f5f9 !important; }                      /* landing titles */
[data-bs-theme="dark"] .filter-bar { background-color: var(--bs-tertiary-bg) !important; } /* /table filter labels were light-on-light */
[data-bs-theme="dark"] .footer-logo span { color: #a5b4fc !important; }                    /* footer brand 2.84:1 */
[data-bs-theme="dark"] .region-badge { color: #212529; }                                   /* valuation badges: light text on light chip */
[data-bs-theme="dark"] .date-range-display { color: inherit; }                             /* #333 on dark panel */

/* ---- Target size (WCAG 2.5.8: >= 24x24 px) and minimum text size (audit 2026-11-06) ---- */
.card__source-link,
.table .btn-sm, .table .btn-xs, table.table td > button, table.table td > a.btn,
footer a, .footer-links a, .footer-section a {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 24px; min-width: 24px; padding-block: 0.15rem;
}
footer a, .footer-links a, .footer-section a { justify-content: flex-start; }
.table.table-sm td > a:not(.btn) {
  display: inline-flex; align-items: center; min-height: 24px; padding-block: 0.15rem;
}
.breadcrumb a, .breadcrumb-nav a, .toc-list a {
  min-height: 24px; padding-block: 0.15rem;
}
.breadcrumb a, .breadcrumb-nav a { display: inline-flex; align-items: center; }
.public-observatory-link-row > a {
  display: inline-flex; align-items: center; min-width: 24px; min-height: 24px;
}
.target-size-link {
  display: inline-flex; align-items: center; min-width: 24px; min-height: 24px;
  padding-block: 0.15rem; vertical-align: middle;
}
.help-category-card > a,
.legal-toc li > a,
.contact-card p > a,
.auth-legal-footer a,
.auth-login-card a:not(.btn) {
  display: inline-flex; align-items: center; min-height: 24px; padding-block: 0.15rem;
}
#contactPrivacyConsent { width: 24px; height: 24px; }
#contactPrivacyConsent + .form-check-label a {
  display: inline-flex; align-items: center; min-height: 24px; vertical-align: middle;
}
.select2-selection__clear { min-width: 24px; min-height: 24px; display: inline-flex; align-items: center; justify-content: center; }
.card__info-label { font-size: 0.75rem; }                       /* was 11 px on 146 card labels */
table small, .table small, small.text-muted, .badge { font-size: max(12px, 0.8em); }

/* ---- Small-screen overflow ------------------------------------------------ */
.sales-toolbar-select { max-width: 100%; min-width: 0; }
.d-flex:has(> .sales-toolbar-select) { flex-wrap: wrap; max-width: 100%; }
.analytics-header { max-width: 100%; box-sizing: border-box; }
@media (max-width: 767.98px) { .analytics-header { margin-inline: 0; border-radius: 16px; } }   /* -24px side margins pushed the page 3 px wider than the viewport */

/* Sale detail: the grouped workflow section's toggle */
details.hero-more-actions > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; }
details.hero-more-actions > summary::-webkit-details-marker { display: none; }
details.hero-more-actions[open] > summary { margin-bottom: 0.75rem; }

/* ---- Dark theme: third pass, from the failing-element analysis (audit 2026-11-06) ---- */
.badge.bg-info, .badge.bg-warning { color: #1f2937 !important; }                         /* both themes: white on cyan/amber was 2.1-2.4:1 */
[data-bs-theme="dark"] .workflow-features li { color: #cbd5e1; }                         /* landing: #334155 on dark, 1.7:1 */
[data-bs-theme="dark"] .section-subtitle { color: #94a3b8; }
[data-bs-theme="dark"] .property-content { background-color: var(--bs-body-bg); }        /* landing cards: light text on a white body */
[data-bs-theme="dark"] .property-content .property-title { color: var(--bs-body-color); }
[data-bs-theme="dark"] .property-content .property-detail { color: #cbd5e1; }
[data-bs-theme="dark"] .full-width-section { background-color: var(--bs-body-bg); color: var(--bs-body-color); }
[data-bs-theme="dark"] .full-width-section h4 { color: var(--bs-body-color); }
[data-bs-theme="dark"] label.form-label { color: #adb5bd; }
[data-bs-theme="dark"] .indicator-trend, [data-bs-theme="dark"] .kpi-trend.positive { color: #34d399; }
[data-bs-theme="dark"] .kpi-trend.negative, [data-bs-theme="dark"] .kpi-trend.negative span { color: #f87171; }
[data-bs-theme="dark"] .export-btn { color: #1d4ed8; }
[data-bs-theme="dark"] .chart-control-btn.active { background-color: #2563eb; color: #fff; }
[data-bs-theme="dark"] .value-param-btn.active { color: #fff; }
[data-bs-theme="dark"] .region-badge { color: #212529 !important; }
[data-bs-theme="dark"] .leaflet-bar a, [data-bs-theme="dark"] .leaflet-bar a span,
[data-bs-theme="dark"] .leaflet-control-attribution, [data-bs-theme="dark"] .leaflet-control-attribution * { color: #1f2937 !important; }
[data-bs-theme="dark"] .stat-card .stat-value { color: #a5b4fc; }
[data-bs-theme="dark"] .badge-role { color: #7f1d1d; }
[data-bs-theme="dark"] .page-item.active .page-link { color: #fff; }
[data-bs-theme="dark"] legend.filter-section-title { color: #a5b4fc; }
[data-bs-theme="dark"] .template-type.dashboard { color: #0d47a1; }
[data-bs-theme="dark"] .template-type.search { color: #1b5e20; }
[data-bs-theme="dark"] .template-type.property { color: #8a4b00; }
[data-bs-theme="dark"] .feat-pill.missing { color: #475569; }
[data-bs-theme="dark"] .table-light td, [data-bs-theme="dark"] .table-light th { color: #212529 !important; }
[data-bs-theme="dark"] .stat-item .label { color: #adb5bd; }
[data-bs-theme="dark"] .clients-table, [data-bs-theme="dark"] .clients-table .table { background-color: var(--bs-body-bg); color: var(--bs-body-color); }

/* ---- Dark theme: fourth pass ---- */
html[data-bs-theme="dark"] .workflow-content .btn-warning, html[data-bs-theme="dark"] .workflow-content .btn-info { color: #fff !important; }
html[data-bs-theme="dark"] .indicator-trend, html[data-bs-theme="dark"] .indicator-card .indicator-trend { color: #6ee7b7 !important; }
html[data-bs-theme="dark"] .value-param-btn.active { background: #0056b3; border-color: #0056b3; color: #fff; }
html[data-bs-theme="dark"] .leaflet-control-zoom a, html[data-bs-theme="dark"] .leaflet-control-zoom a *,
html[data-bs-theme="dark"] .leaflet-bar a, html[data-bs-theme="dark"] .leaflet-bar a * { color: #1f2937 !important; }
html[data-bs-theme="dark"] .page-item.active .page-link, html[data-bs-theme="dark"] .page-item.active > .page-link { color: #fff !important; }
html[data-bs-theme="dark"] thead.table-light th, html[data-bs-theme="dark"] .table-light > tr > th,
html[data-bs-theme="dark"] .table > thead.table-light > tr > th { color: #212529 !important; }
html[data-bs-theme="dark"] .pagination-enhanced { background-color: var(--bs-body-bg); }
html[data-bs-theme="dark"] .pagination-info, html[data-bs-theme="dark"] .pagination-info strong { color: var(--bs-body-color); }
html[data-bs-theme="dark"] .text-center.text-muted { color: #adb5bd; }

/* ---- Dark theme: fifth pass. Page CSS such as
   `[data-bs-theme=dark] .dashboard-container .dashboard-content :is(span, th, td…)` has specificity
   (0,3,1) and !important, so the stubborn overrides need a longer selector. ---- */
html[data-bs-theme="dark"] body .leaflet-container .leaflet-bar a,
html[data-bs-theme="dark"] body .leaflet-container .leaflet-bar a span,
html[data-bs-theme="dark"] body .leaflet-container .leaflet-control-attribution,
html[data-bs-theme="dark"] body .leaflet-container .leaflet-control-attribution a,
html[data-bs-theme="dark"] body .leaflet-container .leaflet-control-attribution span { color: #1f2937 !important; }
html[data-bs-theme="dark"] body .table-light th, html[data-bs-theme="dark"] body thead.table-light th,
html[data-bs-theme="dark"] body .table-light td, html[data-bs-theme="dark"] body tr.table-light td { color: #212529 !important; }
html[data-bs-theme="dark"] body .pagination-enhanced .pagination-info,
html[data-bs-theme="dark"] body .pagination-enhanced .pagination-info strong { color: var(--bs-body-color) !important; }
html[data-bs-theme="dark"] body .pagination-enhanced .page-item.active .page-link { color: #fff !important; }
html[data-bs-theme="dark"] body .btn-outline-primary { color: #bfdbfe; }

/* ---- Dark theme: sales page pass (user feedback 2026-11-24) ---- */
/* Text is forced dark on warning/info badges (above), so their background must stay light:
   in dark mode the valuation "Medium" badge rendered dark text on a brown fill (1.6:1). */
[data-bs-theme="dark"] .badge.bg-warning { background-color: #fbbf24 !important; color: #1f2937 !important; }
[data-bs-theme="dark"] .badge.bg-info { background-color: #67e8f9 !important; color: #1f2937 !important; }
/* Table header strip: gradient background with text that fell back to black in dark mode. */
[data-bs-theme="dark"] .table-header-section,
[data-bs-theme="dark"] .table-header-section p,
[data-bs-theme="dark"] .table-header-section strong { color: #fff; }
[data-bs-theme="dark"] .sales-valuation-stat-value,
[data-bs-theme="dark"] .sales-valuation-title { color: var(--color-text-primary, #f8f9fa); }
[data-bs-theme="dark"] .sales-valuation-stat-label,
[data-bs-theme="dark"] .sales-valuation-range { color: var(--color-text-secondary, #adb5bd); }

/* Dark theme, filter panel + map toolbar (found by a production contrast scan, 2026-11-24):
   the active "Clear" date preset was blue-900 text on the dark page (1.9:1), outline-secondary
   controls ("By Zone", "Clear Filters") were #565e64 on near-black (2.9:1), and the active
   Provinces layer toggle drew light-yellow text on a yellow fill (1.3:1, unreadable). */
[data-bs-theme="dark"] .filter-preset-btn.is-active { color: #dbeafe; border-color: #60a5fa; background-color: rgba(96, 165, 250, 0.18); }
[data-bs-theme="dark"] .btn-outline-secondary { color: #cbd5e1; border-color: #64748b; }
[data-bs-theme="dark"] .btn-outline-secondary:hover,
[data-bs-theme="dark"] .btn-check:checked + .btn-outline-secondary { color: #0f172a; background-color: #cbd5e1; border-color: #cbd5e1; }
[data-bs-theme="dark"] #geo-layer-controls .btn-outline-warning.active { color: #1f2937 !important; }
[data-bs-theme="dark"] #geo-layer-controls .btn-outline-danger.active { color: #fff !important; }
[data-bs-theme="dark"] .btn.btn-outline-secondary { --bs-btn-color: #cbd5e1; --bs-btn-border-color: #64748b; --bs-btn-hover-color: #0f172a; --bs-btn-hover-bg: #cbd5e1; --bs-btn-hover-border-color: #cbd5e1; }
[data-bs-theme="dark"] .btn.btn-outline-secondary:not(:hover):not(.active):not(:focus-visible) { color: #cbd5e1; }
[data-bs-theme="dark"] .btn-check:checked + .btn.btn-outline-secondary:not(:hover):not(.active):not(:focus-visible) { color: #0f172a; background-color: #cbd5e1; border-color: #cbd5e1; }
