// Theme switcher button group
.pmf-theme-switcher {
  button {
    color: var(--bs-light) !important;
    border: none;
    background: transparent;
    transition: all 0.3s ease;
    opacity: 0.6;

    &:hover {
      color: var(--bs-warning) !important;
      background: rgba(255, 255, 255, 0.1);
      border-radius: 0.375rem;
      opacity: 1;
    }

    &:focus {
      box-shadow: 0 0 0 0.25rem rgba(255, 255, 255, 0.25);
    }

    &.active {
      color: var(--bs-warning) !important;
      opacity: 1;
      background: rgba(255, 255, 255, 0.15);
      border-radius: 0.375rem;
    }

    i {
      font-size: 1.1rem;
      transition: transform 0.3s ease;
    }

    &:hover i {
      transform: scale(1.1);
    }
  }
}

// Dark mode specific styles
[data-bs-theme='dark'] {
  // Global background
  html,
  body {
    background: var(--bs-gray-700) !important;
    color: var(--bs-light);
  }

  // Navigation adjustments for dark mode
  .text-bg-pmf-nav {
    background-color: var(--bs-gray-900) !important;
  }

  // Search form dark mode
  .search {
    .form-control {
      background-color: var(--bs-gray-800);
      border-color: var(--bs-gray-700);
      color: var(--bs-light);

      &:focus {
        background-color: var(--bs-gray-800);
        border-color: var(--bs-primary);
        color: var(--bs-light);
        box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
      }

      &::placeholder {
        color: var(--bs-gray-400);
      }
    }

    .bi-search {
      color: var(--bs-gray-400);
    }
  }

  // Cards and content areas
  .card {
    background-color: var(--bs-gray-800);
    border-color: var(--bs-gray-700);
    color: var(--bs-light);
  }

  // Startpage: card cover should be dark in dark mode
  .card.card-cover {
    background-color: var(--bs-gray-800) !important;
    color: var(--bs-light) !important;
    position: relative;
  }

  // If a background image is set, add a subtle dark overlay for readability
  .card.card-cover::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    pointer-events: none;
  }

  // Ensure inner content sits above the overlay
  .card.card-cover .d-flex {
    position: relative;
    z-index: 1;
  }

  // Explicitly override Bootstrap's text-bg-light on card-cover in dark mode
  .card.card-cover.text-bg-light {
    background-color: var(--bs-gray-800) !important;
    color: var(--bs-light) !important;
  }

  // Footer dark mode
  .text-bg-pmf-footer {
    background-color: var(--bs-gray-900) !important;
  }

  // Links in dark mode
  a {
    color: var(--bs-info);

    &:hover {
      color: var(--bs-info);
      opacity: 0.8;
    }

    &.btn {
      color: var(--bs-light);
    }
  }

  // Form elements
  .form-control,
  .form-select {
    background-color: var(--bs-gray-800);
    border-color: var(--bs-gray-700);
    color: var(--bs-light);

    &:focus {
      background-color: var(--bs-gray-800);
      border-color: var(--bs-primary);
      color: var(--bs-light);
    }
  }
  // required-asterisk
  .pmf-required-asterisk {
    color: var(--bs-danger);
  }
  // Dropdowns
  .dropdown-menu {
    background-color: var(--bs-gray-800);
    border-color: var(--bs-gray-700);

    .dropdown-item {
      color: var(--bs-light);

      &:hover,
      &:focus {
        background-color: var(--bs-gray-700);
        color: var(--bs-light);
      }
    }

    .dropdown-divider {
      border-color: var(--bs-gray-700);
    }
  }

  // Buttons
  .btn-outline-primary {
    color: var(--bs-info);
    border-color: var(--bs-info);

    &:hover {
      background-color: var(--bs-info);
      color: var(--bs-dark);
    }
  }

  // Improve readability of info badges inside tag buttons
  .badge.bg-info {
    color: var(--bs-dark);
  }

  // Ensure badge remains readable when the tag button is hovered
  .btn-outline-primary:hover .badge.bg-info {
    background-color: var(--bs-light);
    color: var(--bs-dark);
  }

  // Light subtle backgrounds should be dark in dark mode
  .bg-light-subtle {
    background-color: var(--bs-gray-800) !important;
    color: var(--bs-light) !important;
  }

  // Alerts and notifications
  .alert {
    &.alert-info {
      background-color: rgba(13, 202, 240, 0.1);
      border-color: var(--bs-info);
      color: var(--bs-info);
    }

    &.alert-warning {
      background-color: rgba(255, 193, 7, 0.1);
      border-color: var(--bs-warning);
      color: var(--bs-warning);
    }

    &.alert-danger {
      background-color: rgba(220, 53, 69, 0.1);
      border-color: var(--bs-danger);
      color: var(--bs-danger);
    }

    &.alert-success {
      background-color: rgba(25, 135, 84, 0.1);
      border-color: var(--bs-success);
      color: var(--bs-success);
    }
  }

  // Breadcrumbs
  .pmf-breadcrumbs {
    background-color: var(--bs-gray-800);
    color: var(--bs-light);
  }

  // Tables
  .table {
    color: var(--bs-light);

    &.table-striped > tbody > tr:nth-of-type(odd) > td {
      background-color: rgba(255, 255, 255, 0.05);
    }

    &.table-hover > tbody > tr:hover > td {
      background-color: rgba(255, 255, 255, 0.075);
    }
  }

  // Borders
  .border {
    border-color: var(--bs-gray-700) !important;
  }

  // Text muted
  .text-muted {
    color: var(--bs-gray-400) !important;
  }
}

// High contrast mode specific styles
[data-bs-theme='high-contrast'] {
  // Global background with maximum contrast
  html,
  body {
    background: var(--bs-dark) !important;
    color: var(--bs-light) !important;
  }

  // Custom scrollbar for high contrast mode
  scrollbar-color: var(--bs-primary) var(--bs-dark);
  scrollbar-width: auto;

  &::-webkit-scrollbar {
    width: 14px;
    height: 14px;
    display: block;
  }

  *::-webkit-scrollbar {
    width: 14px;
    height: 14px;
  }

  &::-webkit-scrollbar-track,
  *::-webkit-scrollbar-track {
    background: var(--bs-dark) !important;
    box-shadow: inset 0 0 0 1px var(--bs-primary);
  }

  &::-webkit-scrollbar-thumb,
  *::-webkit-scrollbar-thumb {
    background-color: var(--bs-primary) !important;
    border-radius: 0;
    border: 2px solid var(--bs-dark);

    &:hover {
      background-color: var(--bs-light) !important;
    }
  }

  //Theme Switcher Button for high contrast mode
  .pmf-theme-switcher {
    button {
      color: var(--bs-light) !important;
      border: none;
      background: transparent;
      transition: all 0.3s ease;
      opacity: 1;

      &:hover {
        color: var(--bs-dark) !important;
        background: var(--bs-light) !important;
        opacity: 1;
      }

      &.active {
        color: var(--bs-dark) !important;
        opacity: 1;
        background: var(--bs-primary) !important;
      }

      i {
        font-size: 1.3rem;
        transition: transform 0.3s ease;
      }
    }
  }

  // Navigation adjustments for high contrast mode
  .text-bg-pmf-nav {
    background-color: var(--bs-dark) !important;
    border: 2px solid var(--bs-light) !important;
  }

  // Search form high contrast mode
  .search {
    .form-control {
      background-color: var(--bs-dark);
      border: 2px solid var(--bs-light);
      color: var(--bs-light);
      font-weight: 800;

      &:focus {
        background-color: var(--bs-dark);
        border: 2px solid var(--bs-primary);
        color: var(--bs-light);
        box-shadow: 0 0 0 0.25rem rgba(255, 255, 0, 0.5);
      }

      &::placeholder {
        color: var(--bs-light);
      }
    }

    .bi-search {
      color: var(--bs-light);
    }
  }

  // Cards and content areas
  .card {
    background-color: #000000;
    border: 2px solid #ffffff;
    color: #ffffff;
  }

  // Startpage: card cover in high contrast mode
  .card.card-cover {
    background-color: #000000 !important;
    color: #ffffff !important;
    border: 2px solid #ffffff !important;
  }

  // Remove overlay in high contrast mode for clarity
  .card.card-cover::before {
    display: none;
  }

  // Override text-bg-light on card-cover in high contrast mode
  .card.card-cover.text-bg-light {
    background-color: #000000 !important;
    color: #ffffff !important;
  }

  // Footer high contrast mode
  footer {
    background-color: var(--bs-dark) !important;
    color: var(--bs-primary) !important;
    border: 4px solid var(--bs-primary) !important;
    border-radius: 0px 0px 10px 10px !important;
    margin-top: -4px;
  }

  // Links in high contrast mode - yellow for maximum visibility
  a {
    color: var(--bs-primary);
    text-decoration: underline;

    &:hover {
      color: var(--bs-dark);
      text-decoration: none;
      background-color: var(--bs-primary);
      border-radius: 4px;
    }
  }

  // Apply larger sizing only to main content links
  .pmf-content a,
  main a {
    font-size: 1.3rem;
    font-weight: 800;
  }

  //Logo link exception - yellow border on hover & scale up for better visibility
  #phpmyfaq-logo {
    transform: scale(1.3);
    border: 5px solid transparent;
    border-radius: 8px;
    padding: 2px;
    display: inline-block;

    &:hover {
      background-color: transparent !important;
      text-decoration: none;
      border-color: var(--bs-primary) !important;
    }
  }
  // Logo image - invert colors for high-contrast mode
  #phpmyfaq-logo img {
    filter: brightness(0) invert(1) saturate(2);
    width: 100%;
  }
  // Heading style exceptions
  h1.pmf-start-page,
  .pmf-start-page.h1 {
    background: var(--bs-primary);
    -webkit-background-clip: text;
    background-clip: text;
    border: 3px dashed var(--bs-primary);
    border-radius: 8px;
  }

  // Form elements
  .form-control,
  .form-select {
    background-color: var(--bs-primary);
    border: 2px solid var(--bs-primary);
    color: var(--bs-dark);
    font-size: 1.3rem;

    &:focus {
      background-color: var(--bs-dark);
      border: 2px solid var(--bs-primary);
      color: var(--bs-light);
    }
  }
  // required-asterisk
  .pmf-required-asterisk {
    color: var(--bs-primary);
    font-weight: bold;
  }
  // Dropdowns
  .dropdown-menu {
    background-color: var(--bs-dark);
    border: 2px solid var(--bs-light);
    font-size: 1.3rem;

    .dropdown-item {
      color: var(--bs-light);

      &:hover,
      &:focus {
        background-color: var(--bs-primary);
        color: #000000;
      }
    }

    .dropdown-divider {
      border-color: var(--bs-light);
    }
  }

  // Buttons
  .btn {
    border: 2px solid var(--bs-light);
  }

  .btn-outline-primary {
    color: var(--bs-primary);
    border: 2px solid var(--bs-primary);

    &:hover {
      background-color: var(--bs-primary);
      color: #000000;
    }
  }

  .btn-primary {
    background-color: var(--bs-primary);
    color: #000000;
    border: 2px solid var(--bs-primary);

    &:hover {
      background-color: var(--bs-primary);
      border-color: var(--bs-primary);
    }
  }

  // Improve readability of badges
  .badge {
    border: 4px solid var(--bs-dark);
    font-weight: 800;

    &.bg-info {
      background-color: var(--bs-primary) !important;
      color: #000000;
    }

    &.bg-success {
      background-color: #00ff00 !important;
      color: #000000;
    }

    &.bg-warning {
      background-color: #ffff00 !important;
      color: #000000;
    }

    &.bg-danger {
      background-color: #ff0000 !important;
      color: #ffffff;
    }
  }

  // Light subtle backgrounds
  .bg-light-subtle {
    background-color: #000000 !important;
    color: #ffffff !important;
    border: 1px solid #ffffff !important;
  }

  // Alerts and notifications with strong borders
  .alert {
    background-color: #000000;
    color: #ffffff;
    border: 2px solid #ffffff;

    &.alert-info {
      border-color: #00ffff;
      color: #00ffff;
    }

    &.alert-warning {
      border-color: #ffff00;
      color: #ffff00;
    }

    &.alert-danger {
      border-color: #ff0000;
      color: #ff0000;
    }

    &.alert-success {
      border-color: #00ff00;
      color: #00ff00;
    }
  }

  // Breadcrumbs
  .pmf-breadcrumbs {
    background-color: #000000;
    color: #ffffff;
    border: 1px solid #ffffff;
  }

  // Tables with strong contrast
  .table {
    border: 2px solid var(--bs-primary) !important;
    background-color: var(--bs-dark);
    color: var(--bs-light);

    th,
    td {
      border: 2px solid var(--bs-primary) !important;
      background-color: var(--bs-dark);
      color: var(--bs-light);
    }

    &.table-striped > tbody > tr:nth-of-type(odd) > td {
      background-color: #1a1a1a;
    }

    &.table-hover > tbody > tr:hover > td {
      background-color: #333333;
    }
  }

  // Borders
  .border {
    border: 2px solid #ffffff !important;
  }

  // Text muted still needs to be visible
  .text-muted {
    color: #e0e0e0 !important;
  }

  // Navigation text
  .navbar,
  .nav-link {
    color: #ffffff !important;

    &:hover {
      background-color: var(--bs-primary);
      color: #000 !important;
      border-radius: 5px;
    }
  }
}

// Smooth transitions for theme switching
body,
.card,
.btn,
.form-control,
.alert,
a,
.navbar,
.dropdown-menu {
  transition:
    background-color 0.3s ease,
    border-color 0.3s ease,
    color 0.3s ease;
}
