/*
 * CKAN Accessibility Extension - High Contrast Mode
 * Clean, maintainable CSS with CSS variables and modern selectors
 */

/* ========== 0. ANTI-FLASH PROTECTION ========== */

/* Only hide content briefly if preferences are being restored */
html:not(.accessibility-preferences-loaded) {
    /* Very brief opacity reduction to prevent flash */
    opacity: 0.99;
    transition: opacity 0.05s ease-in;
}

/* Show content normally once preferences are loaded */
html.accessibility-preferences-loaded {
    opacity: 1;
    transition: opacity 0.05s ease-in;
}

/* ========== 1. FONT SIZE CLASSES ========== */
html.font-size-normal { font-size: 100%; }
html.font-size-extra-large { font-size: 150%; }

/* ========== 2. HIGH CONTRAST MODE VARIABLES ========== */
html.high-contrast-mode {
    --bg-main: #000000;
    --text-main: #ffffff;
    /* --accent-primary: #ffff00; */
    --accent-primary: #ffff00;
    --border-main: #ffffff;
    
    /* Inverted theme variables (yellow background) */
    --bg-inverted: var(--accent-primary);
    --text-inverted: var(--bg-main);
    --border-inverted: var(--bg-main);
    
    /* Button specific variables */
    --btn-primary-bg: var(--accent-primary);
    --btn-primary-text: var(--bg-main);
    --btn-primary-border: var(--bg-main);
    --btn-primary-hover-bg: var(--text-inverted);
    --btn-primary-hover-text: var(--bg-inverted);
    --btn-primary-hover-border: var(--border-main);
    --btn-secondary-bg: var(--bg-main);
    --btn-secondary-text: var(--text-main);
    --btn-secondary-border: var(--border-main);
    --btn-secondary-hover-bg: var(--accent-primary);
    --btn-secondary-hover-text: var(--bg-main);
}

/* ========== 3. GLOBAL STYLES ========== */

/* Smooth transitions */
.high-contrast-mode,
.high-contrast-mode * {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Base background and text */
html.high-contrast-mode,
html.high-contrast-mode body {
    background-color: var(--bg-main) !important;
    color: var(--text-main) !important;
}

/* Focus and selection */
.high-contrast-mode *:focus-visible {
    outline: 4px solid var(--accent-primary) !important;
    outline-offset: 3px !important;
}

.high-contrast-mode ::selection {
    background-color: var(--accent-primary) !important;
    color: var(--bg-main) !important;
}

/* ========== 4. TYPOGRAPHY ========== */

/* General text elements */
.high-contrast-mode :is(p, span, li, ul, ol, td, label, strong, em, b, div:not(.module-search)) {
    background-color: transparent;
    color: inherit;
}

/* Headings */
.high-contrast-mode :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6) {
    color: var(--text-main) !important;
    font-weight: 700 !important;
    border-bottom: 3px solid var(--accent-primary) !important;
    padding-bottom: 8px !important;
}

/* Links */
.high-contrast-mode a {
    color: var(--accent-primary) !important;
    text-decoration: underline !important;
    font-weight: 600 !important;
}

.high-contrast-mode a:is(:hover, :focus):not(.media-view) {
    color: var(--bg-main) !important;
    background-color: var(--accent-primary) !important;
}

.high-contrast-mode .media-heading a {
    color: var(--text-inverted)!important;
}

.high-contrast-mode .media-heading a:hover {
    color: var(--text-main)!important;
    background-color: var(--bg-main)!important;
}

/* ========== 5. COMPONENTS ========== */

/* Standard components (black background) */
.high-contrast-mode :is(
    .form-control, .form-select, input, textarea, select,
    .table, td, .card:not(.module-search), .modal-content, .dropdown-menu,
    .context-info, .filters, .results, .dataset-list, .dataset-item
) {
    background-color: var(--bg-main) !important;
    color: var(--text-main) !important;
    border: 2px solid var(--border-main) !important;
}

.high-contrast-mode .form-control::placeholder {
    color: var(--text-main) !important;
}

.high-contrast-mode :is(
    dt, dd
) {
    color: var(--text-main) !important;
}

.high-contrast-mode .form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
}

/* Inverted components (yellow background) */
.high-contrast-mode :is(
    .masthead, .navbar, .card-header, .modal-header, .module-heading,
    .page-header, .account-masthead, footer, table th
) {
    background-color: var(--bg-inverted) !important;
    color: var(--text-inverted) !important;
    border: 3px solid var(--border-inverted) !important;
}

/* ========== 14. SEARCH ICON FIXES ========== */

/* Reset search icon styles to prevent conflicts */
.high-contrast-mode .search-form button i,
.high-contrast-mode .search-form .btn i {
    font-size: 1em !important;
    margin: 0 !important;
    transform: none !important;
    transition: none !important;
}

/* Reset any other icons that might be affected */
.high-contrast-mode .navbar i,
.high-contrast-mode .masthead i,
.high-contrast-mode .module-search i:not(.accessibility-controls i) {
    font-size: 1em !important;
    margin: 0 !important;
    transform: none !important;
    transition: none !important;
    color: var(--text-main)!important;
}

/* Ensure search functionality works */
.high-contrast-mode .search-form button,
.high-contrast-mode .search-form .btn {
    background-color: var(--bg-main) !important;
    color: var(--text-main) !important;
    border: 2px solid var(--border-main) !important;
    padding: 8px 12px !important;
    font-size: 1rem !important;
    border-radius: 4px !important;
}

.high-contrast-mode .search-form button:hover,
.high-contrast-mode .search-form .btn:hover {
    background-color: var(--accent-primary) !important;
    color: var(--bg-main) !important;
    border-color: var(--accent-primary) !important;
    transform: none !important;
}

/* ========== 6. CONTEXTUAL OVERRIDES ========== */

/* Headings in inverted components */
.high-contrast-mode :is(.masthead, .navbar, .card-header, .modal-header, footer, .module-search) :is(h1, h2, h3, h4, h5, h6) {
    color: var(--text-inverted) !important;
    border-bottom: none !important;
}

/* Site title and logo */
.high-contrast-mode :is(.site-title, .site-description, .logo-text, .logo-text a) {
    color: var(--text-inverted) !important;
    background-color: transparent !important;
}

/* Links in inverted components */
.high-contrast-mode :is(.masthead, .navbar, footer, .account-masthead, .module-search) a {
    color: var(--text-inverted) !important;
    text-decoration: underline !important;
    font-weight: 700 !important;
}

.high-contrast-mode :is(.masthead, .navbar, footer, .account-masthead, .module-search) a:is(:hover, :focus) {
    color: var(--text-main) !important;
    background-color: var(--bg-main) !important;
}

/* ========== 7. SEARCH MODULE FIXES ========== */

/* Search module container */
.high-contrast-mode .module-search {
    background-color: var(--bg-inverted) !important;
    color: var(--text-inverted) !important;
    border: 3px solid var(--border-inverted) !important;
}

/* Search input and placeholder */
.high-contrast-mode .module-search input,
.high-contrast-mode .module-search input::placeholder {
    background-color: var(--bg-inverted) !important;
    color: var(--text-inverted) !important;
    border: 3px solid var(--border-inverted) !important;
}

/* Search button icon */
.high-contrast-mode .module-search .search-form button i {
    color: var(--text-inverted) !important;
    background-color: transparent !important;
}

/* Search form elements */
.high-contrast-mode .module-search .search-form {
    background-color: transparent !important;
}

.high-contrast-mode .module-search .search-form button {
    background-color: var(--bg-main) !important;
    color: var(--text-main) !important;
    border: 2px solid var(--border-main) !important;
}

/* ========== 9. SEARCH CONTAINER & ICON FIXES ========== */

/* Remove borders from search container */
html.high-contrast-mode .module-search,
html.high-contrast-mode .module-search.card,
html.high-contrast-mode .module-search.card.box {
    border: none !important;
    box-shadow: none !important;
    background-color: transparent !important;
}

/* Remove borders from search form elements */
html.high-contrast-mode .search-form,
html.high-contrast-mode .search-input,
html.high-contrast-mode .form-group,
html.high-contrast-mode .search-giant {
    border: none !important;
    box-shadow: none !important;
    background-color: transparent !important;
}

/* Fix search icon and remove its border */
html.high-contrast-mode .homepage .search-form button,
html.high-contrast-mode .homepage .search-form button i,
html.high-contrast-mode .homepage .search-form .btn,
html.high-contrast-mode .homepage .search-form .btn i {
    border: none !important;
    box-shadow: none !important;
    background-color: transparent !important;
    color: var(--btn-primary-text) !important;
}

/* Remove any input group styling */
html.high-contrast-mode .input-group,
html.high-contrast-mode .input-group-text,
html.high-contrast-mode .input-group-append,
html.high-contrast-mode .input-group-prepend {
    border: none !important;
    box-shadow: none !important;
    background-color: transparent !important;
}

/* Remove any additional borders from search components */
html.high-contrast-mode .ster-home-search,
html.high-contrast-mode .module-content {
    border: none !important;
    box-shadow: none !important;
    background-color: transparent !important;
}

/* ========== 10. AGGRESSIVE OVERRIDES ========== */

/* Nuclear option - override everything for the search field */
html.high-contrast-mode input#field-main-search {
    background-color: var(--btn-primary-bg) !important;
    color: var(--text-inverted) !important;
    border: 3px solid var(--border-inverted) !important;
    font-weight: 600 !important;
    font-size: 1.1em !important;
}

html.high-contrast-mode input#field-main-search::placeholder {
    color: var(--text-inverted) !important;
    opacity: 1 !important;
}

html.high-contrast-mode .btn-default {
    background-color: var(--btn-primary-bg) !important;
    color: var(--btn-primary-text) !important;
    border: 3px solid var(--btn-primary-border) !important;
}

html.high-contrast-mode .btn-default:hover {
    background-color: var(--btn-primary-hover-bg) !important;
    color: var(--btn-primary-hover-text) !important;
    border: 3px solid var(--btn-primary-hover-border) !important;
}


html.high-contrast-mode input#field-main-search:focus {
    background-color: var(--btn-primary-bg) !important;
    color: var(--text-inverted) !important;
    border: 4px solid var(--border-inverted) !important;
    box-shadow: 0 0 0 0.3rem rgba(0, 0, 0, 0.3) !important;
}

/* ========== 11. FRONT CATEGORIES ========== */

/* Front categories styling */
html.js.high-contrast-mode body div.homepage div.container.front-categories div.front-categories div.view-content div.grid-2 div span a {
    color: var(--text-inverted) !important;
    background-color: var(--accent-primary) !important;
}

/* ========== 12. SCROLLBAR ========== */

.high-contrast-mode ::-webkit-scrollbar {
    width: 16px !important;
}

.high-contrast-mode ::-webkit-scrollbar-track {
    background: var(--bg-main) !important;
}

.high-contrast-mode ::-webkit-scrollbar-thumb {
    background: var(--accent-primary) !important;
    border: 2px solid var(--border-main) !important;
    border-radius: 8px !important;
}

.high-contrast-mode ::-webkit-scrollbar-thumb:hover {
    background: var(--text-main) !important;
}

/* .accessibility-btn {
    font-size: 0.8rem;
    padding: 0.5rem 1rem;
    margin: 0 4px;
    border-radius: 6px;
    border: 2px solid #222;
    background-color: #fff;
    color: #111;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    position: relative;
    overflow: hidden;
    font-weight: 600;
    letter-spacing: 0.02em;
    outline: none;
} */

.accessibility-btn {
    font-size: 0.8rem;
    vertical-align: text-bottom;
    padding: 0.1rem 1rem;
    margin: 0 4px;
    border-radius: 6px;
    border: none;
    background-color: transparent;
    color: #111;
    transition: all 0.2s ease;
    box-shadow: none;
    position: relative;
    overflow: hidden;
    font-weight: 600;
    letter-spacing: 0.02em;
    outline: none;
}

#accessibility-btn-font-normal i {
    font-size: 0.6rem;
}

.accessibility-last-listelement {
    margin-right: 30px;
}




.accessibility-btn:focus {
    outline: 3px solid #0056b3;
    outline-offset: 2px;
    z-index: 2;
}

.accessibility-btn:hover,
.accessibility-btn:focus-visible {
    background-color: #e9ecef;
    color: #000;
    border-color: #0056b3;
    box-shadow: 0 3px 8px rgba(0,0,0,0.18);
    text-decoration: underline;
}

.accessibility-btn:active {
    background-color: #d6d8db;
    color: #000;
    border-color: #0056b3;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.accessibility-btn.active {
    background-color: #0056b3 !important;
    border-color: #0056b3 !important;
    color: #fff !important;
    box-shadow: 0 2px 6px rgba(0,86,179,0.25);
    font-weight: 700;
    text-decoration: underline;
}

.accessibility-btn.active:hover,
.accessibility-btn.active:focus-visible {
    background-color: #003366 !important;
    border-color: #003366 !important;
    box-shadow: 0 4px 10px rgba(0,86,179,0.35);
}

.accessibility-btn:disabled,
.accessibility-btn[disabled] {
    cursor: not-allowed;
}

.accessibility-btn i {
    margin-right: 6px;
    font-size: 1.5em;
    vertical-align: middle;
}

.accessibility-btn .btn-text {
    font-weight: 700;
    font-size: 1em;
    letter-spacing: 0.01em;
}

.high-contrast-mode .accessibility-btn {
    background-color: var(--btn-primary-bg) !important;
    border-color: var(--btn-primary-border) !important;
    color: var(--btn-primary-text) !important;
    box-shadow: 0 1px 3px rgba(255,255,255,0.25);
}

.high-contrast-mode .accessibility-btn:hover,
.high-contrast-mode .accessibility-btn:focus-visible {
    background-color: var(--btn-primary-hover-bg) !important;
    border-color: var(--btn-primary-border) !important;
    color: var(--btn-primary-hover-text) !important;
    box-shadow: 0 3px 8px rgba(255,255,255,0.35);
    text-decoration: underline;
}

.high-contrast-mode .accessibility-btn.active {
    background-color: var(--btn-primary-hover-bg) !important;
    border-color: var(--btn-primary-border) !important;
    color: var(--btn-primary-hover-text) !important;
    box-shadow: 0 2px 6px rgba(255,255,255,0.5);
    font-weight: 900;
    text-decoration: underline;
}

.high-contrast-mode .accessibility-btn.active:hover,
.high-contrast-mode .accessibility-btn.active:focus-visible {
    background-color: var(--bg-inverted) !important;
    border-color: #000 !important;
    color: #000 !important;
    box-shadow: 0 4px 10px rgba(255,255,255,0.7);
}

/* ========== 12. SCROLLBAR ========== */


.accessibility-controls {
    margin-right: 15px;
    display: inline-block;
    left: 40%;
    position: relative;
}

/* ========== active Tabs ========== */


.high-contrast-mode .nav-tabs li.active a {
    color: var(--text-inverted)!important;
}

.high-contrast-mode .masthead .navbar li.active a {
    color: var(--text-main)!important;
    background-color: var(--bg-main)!important;
}

/* ========== primary btn ========== */

html.high-contrast-mode .btn-primary {
    background-color: var(--btn-primary-bg) !important;
    color: var(--btn-primary-text) !important;
    border: 3px solid var(--btn-primary-border) !important;
}

html.high-contrast-mode .btn-primary:hover {
    background-color: var(--btn-primary-hover-bg) !important;
    color: var(--btn-primary-hover-text) !important;
    border: 3px solid var(--btn-primary-hover-border) !important;
}

/* ========== primary btn ========== */

html.high-contrast-mode .homepage .module-search .tags {
    background-color: var(--bg-inverted)!important;
    color: var(--text-inverted)!important;
    border-color: var(--border-inverted)!important;
}

.account-masthead ul.list-unstyled {
    display: flex;
    align-items: center;
}

.high-contrast-mode a.badge {
    color: var(--text-inverted)!important;
    background-color: var(--bg-inverted)!important;
}

/* ========== resource page ========== */

.high-contrast-mode .module-resource {
    background-color: var(--bg-main);
}

.high-contrast-mode .module-resource p {
    color: var(--text-main)!important;
}

.high-contrast-mode .nav-tabs li a.active {
  color: var(--text-inverted) !important;
}

.high-contrast-mode .module-narrow .nav-item.active > a, 
.high-contrast-mode .module-narrow .nav-aside li.active a {
  background-color: var(--bg-inverted)!important;
  color: var(--text-inverted)!important;
}

.high-contrast-mode .module-narrow .nav-item.active > a::before, 
.high-contrast-mode .module-narrow .nav-aside li.active a::before {
  border-left-color: var(--bg-inverted)!important;
}

/* ========== select2 ========== */

.high-contrast-mode .select2-choice {
    color: var(--text-inverted)!important;
}

.high-contrast-mode .select2-drop {
    background-color: var(--bg-main)!important;
}

.high-contrast-mode .select2-choices input.select2-input {
    color: var(--text-inverted)!important;
}

.high-contrast-mode .select2-search input.select2-input {
    color: var(--text-inverted)!important;
}

.high-contrast-mode .select2-results {
    color: var(--text-inverted)!important;
    background-color: var(--bg-inverted)!important;
}

.high-contrast-mode .select2-results .select2-highlighted {
    color: var(--text-main)!important;
    background-color: var(--bg-main)!important;
}

/* */

.high-contrast-mode .stages li.active .highlight {
  color: var(--text-inverted)!important;
  background: var(--bg-inverted)!important;
}

.high-contrast-mode .stages li:before {
  color: var(--text-inverted)!important;
  background: var(--bg-inverted)!important;
}

.high-contrast-mode .stages li.active:before {
  color: var(--text-main)!important;
  background: var(--bg-main)!important;
}