/**
 * Accessibility Fixes for WCAG AA Compliance
 *
 * Ensures color contrast ratios meet minimum standards:
 * - Normal text: 4.5:1 minimum
 * - Large text (18pt+): 3:1 minimum
 * - UI components: 3:1 minimum
 */

/* ===== Text Contrast Improvements ===== */

/* Ensure body text has sufficient contrast */
body {
  color: #212529; /* Dark gray instead of pure black for better readability */
}

[data-bs-theme="dark"] body {
  color: #e9ecef; /* Light gray on dark background — meets 4.5:1 contrast */
}

/* Muted text - often too light */
.text-muted {
  color: #5a5a5a !important; /* Darker gray for 4.5:1 contrast on white */
}

[data-bs-theme="dark"] .text-muted {
  color: #adb5bd !important; /* Lighter gray for dark backgrounds */
}

/* Secondary text */
.text-secondary {
  color: #4a4a4a !important;
}

[data-bs-theme="dark"] .text-secondary {
  color: #ced4da !important;
}

/* Small text needs higher contrast */
small,
.small {
  color: #333333;
}

[data-bs-theme="dark"] small,
[data-bs-theme="dark"] .small {
  color: #dee2e6;
}

/* ===== Link Contrast & Distinguishability ===== */
/* Links must be distinguishable from surrounding text without relying solely on color */

/* Default links - add underline for non-color distinction */
a {
  color: #0056b3; /* Darker blue for better contrast */
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover,
a:focus {
  color: #003d82; /* Even darker on hover */
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

[data-bs-theme="dark"] a {
  color: #4da3ff; /* Brighter blue for dark mode */
}

[data-bs-theme="dark"] a:hover,
[data-bs-theme="dark"] a:focus {
  color: #66b3ff;
}

/* Navigation links - no underline (distinguished by position/context) */
.nav-link,
.navbar-brand,
.dropdown-item {
  text-decoration: none !important;
}

/* Button-styled links - no underline */
.btn,
a.btn {
  text-decoration: none !important;
}

/* Card title links - no underline (distinguished by weight/size) */
.card a.text-reset,
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  text-decoration: none;
}

.card a.text-reset:hover,
.card a.text-reset:focus,
h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover, h5 a:hover, h6 a:hover,
h1 a:focus, h2 a:focus, h3 a:focus, h4 a:focus, h5 a:focus, h6 a:focus {
  text-decoration: underline;
}

/* Footer links - underline for accessibility */
.footer a:not(.btn):not(.navbar-brand) {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer a:not(.btn):not(.navbar-brand):hover,
.footer a:not(.btn):not(.navbar-brand):focus {
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

/* Breadcrumb links */
.breadcrumb-item a {
  text-decoration: underline;
}

/* Pagination links - no underline (distinguished by box/context) */
.page-link {
  text-decoration: none !important;
}

/* Badge links - no underline */
.badge {
  text-decoration: none !important;
}

a.badge {
  text-decoration: none !important;
}

/* Link in nav/navbar */
.nav-link {
  color: #212529 !important;
}

.nav-link:hover,
.nav-link:focus {
  color: #000000 !important;
}

[data-bs-theme="dark"] .nav-link {
  color: #f8f9fa !important;
}

[data-bs-theme="dark"] .nav-link:hover,
[data-bs-theme="dark"] .nav-link:focus {
  color: #ffffff !important;
}

/* ===== Button Contrast ===== */

/* Light buttons often have contrast issues */
.btn-light {
  color: #212529 !important;
  background-color: #f8f9fa !important;
  border-color: #d1d5db !important;
}

.btn-light:hover,
.btn-light:focus {
  color: #000000 !important;
  background-color: #e9ecef !important;
}

/* Outline buttons */
.btn-outline-secondary {
  color: #383838 !important;
  border-color: #6c757d !important;
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
  background-color: #6c757d !important;
  color: #ffffff !important;
}

/* ===== Form Elements ===== */

/* Placeholder text */
::placeholder {
  color: #5a5a5a !important;
  opacity: 1;
}

[data-bs-theme="dark"] ::placeholder {
  color: #adb5bd !important;
}

/* Form labels */
.form-label {
  color: #212529;
}

[data-bs-theme="dark"] .form-label {
  color: #f8f9fa;
}

/* Help text */
.form-text {
  color: #4a4a4a !important;
}

[data-bs-theme="dark"] .form-text {
  color: #ced4da !important;
}

/* ===== Card Elements ===== */

/* Card subtle text */
.card-subtitle {
  color: #4a4a4a !important;
}

[data-bs-theme="dark"] .card-subtitle {
  color: #ced4da !important;
}

/* ===== Footer ===== */

/* Footer links often have contrast issues */
.footer a {
  color: #0056b3;
}

.footer a:hover,
.footer a:focus {
  color: #003d82;
}

[data-bs-theme="dark"] .footer a {
  color: #4da3ff;
}

[data-bs-theme="dark"] .footer a:hover,
[data-bs-theme="dark"] .footer a:focus {
  color: #66b3ff;
}

/* ===== Breadcrumbs ===== */

.breadcrumb-item {
  color: #4a4a4a;
}

.breadcrumb-item.active {
  color: #212529;
}

[data-bs-theme="dark"] .breadcrumb-item {
  color: #ced4da;
}

[data-bs-theme="dark"] .breadcrumb-item.active {
  color: #f8f9fa;
}

/* ===== Badges ===== */

/* Light badges */
.badge.bg-light {
  color: #212529 !important;
  background-color: #e9ecef !important;
}

/* Secondary badges */
.badge.bg-secondary {
  background-color: #5a6268 !important; /* Darker for better contrast */
}

/* ===== Alerts ===== */

/* Info alerts often have low contrast */
.alert-info {
  color: #055160 !important;
  background-color: #cff4fc !important;
  border-color: #9eeaf9 !important;
}

/* Warning alerts */
.alert-warning {
  color: #664d03 !important;
  background-color: #fff3cd !important;
  border-color: #ffecb5 !important;
}

/* ===== Images in Blog Content ===== */

/* Constrain markdown images to the article column and centre them */
.post-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 0.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

[data-bs-theme="dark"] .post-content img {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Caption rendered from markdown image title attribute */
.post-content img + em,
.post-content figure figcaption {
  display: block;
  text-align: center;
  font-size: 0.9rem;
  color: #6c757d;
  margin-top: -0.75rem;
  margin-bottom: 1.5rem;
}

[data-bs-theme="dark"] .post-content img + em,
[data-bs-theme="dark"] .post-content figure figcaption {
  color: #adb5bd;
}

/* ===== Tables in Blog Content ===== */

/* Hugo renders markdown tables as plain <table> — apply Bootstrap-like styling */
.post-content table {
  width: 100%;
  margin-bottom: 1rem;
  border-collapse: collapse;
  border: 1px solid #dee2e6;
}

.post-content table th,
.post-content table td {
  padding: 0.75rem;
  vertical-align: top;
  border: 1px solid #dee2e6;
}

.post-content table thead th {
  vertical-align: bottom;
  background-color: #f8f9fa;
  border-bottom: 2px solid #dee2e6;
  font-weight: 600;
}

.post-content table tbody tr:nth-of-type(odd) {
  background-color: rgba(0, 0, 0, 0.02);
}

.post-content table tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

/* Responsive wrapper — handled via CSS overflow */
.post-content table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

[data-bs-theme="dark"] .post-content table {
  border-color: #495057;
}

[data-bs-theme="dark"] .post-content table th,
[data-bs-theme="dark"] .post-content table td {
  border-color: #495057;
}

[data-bs-theme="dark"] .post-content table thead th {
  background-color: #343a40;
}

[data-bs-theme="dark"] .post-content table tbody tr:nth-of-type(odd) {
  background-color: rgba(255, 255, 255, 0.03);
}

[data-bs-theme="dark"] .post-content table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.06);
}

/* ===== Code Blocks ===== */

code {
  color: #d63384; /* Better pink contrast */
}

[data-bs-theme="dark"] code {
  color: #ff6ec7;
}

/* ===== Focus States for Keyboard Navigation ===== */

/* Enhanced focus visibility */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
.btn:focus {
  outline: 3px solid #0056b3 !important;
  outline-offset: 2px;
}

[data-bs-theme="dark"] a:focus,
[data-bs-theme="dark"] button:focus,
[data-bs-theme="dark"] input:focus,
[data-bs-theme="dark"] select:focus,
[data-bs-theme="dark"] textarea:focus,
[data-bs-theme="dark"] .btn:focus {
  outline: 3px solid #4da3ff !important;
  outline-offset: 2px;
}

/* ===== Skip to Content Link ===== */

.skip-to-content {
  position: absolute;
  top: -40px;
  left: 0;
  background: #000000;
  color: #ffffff;
  padding: 8px;
  text-decoration: none;
  z-index: 10000;
}

.skip-to-content:focus {
  top: 0;
}
