/* Knihoveda-only fixes that must load after the shared catalog stylesheet. */

/* Modern autocomplete. VuFind's current script renders `.ac-item`; the legacy
   parent theme only styles `.item`, which allowed long suggestions to stretch
   across the whole results page. The width itself is synchronized with the
   complete search bar by autocomplete_modern.js. */
.autocomplete-results {
  display: none;
  box-sizing: border-box;
  max-height: min(28rem, 55vh);
  margin-top: 6px;
  padding: var(--space-2);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md, 10px);
  box-shadow: 0 14px 36px rgba(31, 41, 55, 0.16),
    0 3px 10px rgba(31, 41, 55, 0.08);
  color: var(--text-main);
  font-family: inherit;
  z-index: 31000;
}

.autocomplete-results.open {
  display: block;
}

.autocomplete-results:empty {
  display: none;
}

.autocomplete-results .ac-item,
.autocomplete-results .item {
  display: block;
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 0.7rem 0.8rem;
  overflow-wrap: anywhere;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm, 6px);
  color: var(--text-main);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.4;
  text-align: left;
  text-decoration: none;
  transition: background-color 0.12s ease, color 0.12s ease;
  white-space: normal;
}

.autocomplete-results .ac-item + .ac-item,
.autocomplete-results .item + .item {
  margin-top: 2px;
}

.autocomplete-results .ac-item:hover,
.autocomplete-results .ac-item:focus,
.autocomplete-results .ac-item.selected,
.autocomplete-results .ac-item.is-selected,
.autocomplete-results .item:hover,
.autocomplete-results .item:focus,
.autocomplete-results .item.selected {
  outline: none;
  background: var(--primary-light-solid, #f7eded);
  color: var(--primary);
  text-decoration: none;
}

.autocomplete-results .ac-item b,
.autocomplete-results .item b {
  color: var(--primary);
  font-weight: 700;
}

.autocomplete-results .ac-item small,
.autocomplete-results .item small {
  display: block;
  margin-top: var(--space-1);
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.autocomplete-results .loading {
  color: var(--text-muted);
  cursor: default;
  font-style: normal;
}

.autocomplete-results .ac-section-header {
  padding: var(--space-2) 0.8rem var(--space-1);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.autocomplete-results .ac-section-divider {
  margin: var(--space-2) 0;
  border: 0;
  border-top: 1px solid var(--border-color);
  opacity: 1;
}

.autocomplete-results::-webkit-scrollbar {
  width: 10px;
}

.autocomplete-results::-webkit-scrollbar-thumb {
  background: #c8cdd3;
  background-clip: padding-box;
  border: 3px solid transparent;
  border-radius: 999px;
}

@media (max-width: 767px) {
  .autocomplete-results {
    max-height: 50vh;
    margin-top: 4px;
    padding: var(--space-1);
  }

  .autocomplete-results .ac-item,
  .autocomplete-results .item {
    padding: 0.65rem 0.7rem;
  }
}

/* The catalog stylesheet puts the account sidebar second. Restore the
   navigation-first layout on account pages, including Checkouts/History. */
body:is(.template-dir-myresearch, .template-dir-holds.template-name-list, .template-dir-checkouts) .account-dashboard-sidebar {
  order: 1;
}

body:is(.template-dir-myresearch, .template-dir-holds.template-name-list, .template-dir-checkouts) .account-dashboard-main {
  order: 2;
}

/* Short Select all label for the standard Knihoveda Results toolbar. */
body.inst-av.template-dir-search.template-name-results .results-select-all-label {
  align-items: center;
  cursor: pointer;
  display: inline-flex;
  font-size: 0.9rem;
  font-weight: 500;
  margin: 0;
  white-space: nowrap;
}

@media (max-width: 1016px) {
  body.inst-av.template-dir-search.template-name-results .results-select-all-label {
    display: none !important;
  }
}

/* Set the stroke of previous/next arrows on Results and Record pages. */
body.inst-av.template-dir-search.template-name-results
  .results-count .arrow-btn svg,
body.inst-av.template-dir-record
  .record-title-navigation .arrow-btn svg,
body.inst-av.template-dir-record
  .record-counter-mobile .arrow-btn svg {
  stroke-width: 2.8 !important;
}

/* Keep database links neutral until the user points at them. */
body.inst-av.template-dir-search.template-name-results
  .result-source-link,
body.inst-av.template-dir-record
  .record-source-badge-stack .result-source-link {
  background: transparent !important;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

body.inst-av.template-dir-search.template-name-results
  .result-source-link:hover,
body.inst-av.template-dir-search.template-name-results
  .result-source-link:focus-visible,
body.inst-av.template-dir-record
  .record-source-badge-stack .result-source-link:hover,
body.inst-av.template-dir-record
  .record-source-badge-stack .result-source-link:focus-visible {
  background: var(--primary-light) !important;
  text-decoration: none;
}

/* Give the missing-cover icon the same complete slot as a real cover image. */
@media screen {
  body.inst-av.template-dir-search.template-name-results
    .result-image-box[id^="obalka_format_"]:has(> svg) {
    box-sizing: border-box;
    border: 1.875px solid #d1d5db;
    border-radius: var(--radius-sm);
  }
}

/* Reuse the Results database badge directly below the record title. */
body.inst-av.template-dir-record .record-main-title:has(+ .record-source-badge-stack) {
  margin-bottom: var(--space-2);
}

body.inst-av.template-dir-record .record-source-badge-stack {
  margin-top: 0;
  margin-bottom: var(--space-4);
}

body.inst-av.template-dir-record
  .record-source-badge-stack:has(+ .record-digital-copy-links) {
  margin-bottom: var(--space-2);
}

body.inst-av.template-dir-record .record-digital-copy-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
  font-size: 0.9em;
}

body.inst-av.template-dir-record .record-digital-copy-links a {
  font-size: inherit;
  font-weight: inherit;
  text-decoration: none;
}

body.inst-av.template-dir-record .record-digital-copy-links a:hover,
body.inst-av.template-dir-record .record-digital-copy-links a:focus-visible {
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

body.inst-av.template-dir-record .record-permalink-copy {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 100%;
}

body.inst-av.template-dir-record .record-permalink-copy__value {
  min-width: 0;
  overflow-wrap: anywhere;
}

body.inst-av.template-dir-record .record-permalink-copy__action {
  display: inline-flex;
  flex: 0 0 auto;
}

body.inst-av.template-dir-record .record-permalink-copy__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.125rem;
  min-width: 2.125rem;
  max-width: 2.125rem;
  height: 2.125rem;
  min-height: 2.125rem;
  max-height: 2.125rem;
  padding: 0;
}

body.inst-av.template-dir-record
  .record-permalink-copy__button.text-success {
  border-color: rgba(31, 169, 113, 0.45);
  color: #1f8f62;
}

@media (max-width: 1016px) {
  body.inst-av.template-dir-record .record-source-badge-stack {
    order: 2;
    margin-left: var(--space-4);
    margin-right: var(--space-4);
  }

  body.inst-av.template-dir-record .record-digital-copy-links {
    order: 3;
    margin-left: var(--space-4);
    margin-right: var(--space-4);
  }
}

/* Preserve the intrinsic aspect ratio of every image in the record gallery. */
body.inst-av.template-dir-record .record-media-col .gallery .recordcover {
  aspect-ratio: auto !important;
  height: auto !important;
  max-height: 150px !important;
  max-width: 100% !important;
  margin-left: auto !important;
  margin-right: auto !important;
  object-fit: contain !important;
  width: auto !important;
}

/* Google Books cover may be slightly taller than the other record images. */
body.inst-av.template-dir-record .record-media-col .gallery .recordcover.google-books-cover {
  max-height: 200px !important;
}

/* Knihoveda nests all covers in .gallery. Apply the catalog's record-media-col
   behavior to that wrapper so its media items behave identically. */
@media (max-width: 1016px) {
  body.inst-av.template-dir-record .record-media-col .gallery {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: var(--space-3);
    justify-content: flex-start;
    margin-bottom: calc(var(--space-4) / 2);
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  body.inst-av.template-dir-record .record-media-col .gallery::-webkit-scrollbar {
    display: none;
  }

  body.inst-av.template-dir-record .record-media-col .gallery > .swipebox,
  body.inst-av.template-dir-record .record-media-col .gallery > .image-link,
  body.inst-av.template-dir-record .record-media-col .gallery > .record-cover-format-fallback {
    flex: 0 0 auto;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    max-width: none;
    text-align: left;
    width: auto !important;
  }

  body.inst-av.template-dir-record .record-media-col .gallery .recordcover {
    height: 180px !important;
    max-height: 180px !important;
    max-width: none !important;
    width: auto !important;
    object-fit: contain;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
  }
}

/* Mobile, tablet and laptop use the compact mark. Match its height to search. */
@media (max-width: 1439px) {
  body.inst-av #header .knihoveda-header-logo,
  body.inst-av #header .knihoveda-header-logo__picture,
  body.inst-av #header .knihoveda-header-logo .logo-icon {
    height: var(--input-height) !important;
    max-height: var(--input-height) !important;
  }

  body.inst-av #header .knihoveda-header-logo__picture,
  body.inst-av #header .knihoveda-header-logo .logo-icon {
    display: block;
    width: auto !important;
  }
}

/* Mobile/tablet: logo and all five utility actions share the top row. */
@media (max-width: 1016px) {
  body.inst-av #header .header-inner {
    align-items: center !important;
    column-gap: var(--space-2) !important;
    display: grid !important;
    grid-template-areas:
      "knihoveda-logo knihoveda-actions"
      "knihoveda-search knihoveda-search" !important;
    grid-template-columns: auto minmax(0, 1fr) !important;
    grid-template-rows: auto auto !important;
    row-gap: var(--space-2) !important;
  }

  body.inst-av #header .header-left {
    display: contents !important;
  }

  body.inst-av #header .knihoveda-header-logo {
    align-self: center;
    grid-area: knihoveda-logo;
    justify-self: start;
  }

  body.inst-av #header .header-left > .search-area {
    grid-area: knihoveda-search !important;
    margin: 0 !important;
    max-width: none !important;
    order: initial !important;
    width: 100% !important;
  }

  body.inst-av #header .header-right {
    align-items: center !important;
    display: flex !important;
    flex: 0 0 auto !important;
    grid-area: knihoveda-actions;
    justify-self: end !important;
    min-width: 0;
    width: auto !important;
  }

  body.inst-av #header .header-actions {
    align-items: center !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: var(--space-2) !important;
    grid-template-columns: none !important;
    justify-content: flex-end !important;
    margin: 0 !important;
    width: auto !important;
  }

  body.inst-av #header .header-actions > .knihoveda-utility-action,
  body.inst-av #header .header-actions > .lang-toggle-form,
  body.inst-av #header .header-actions > #langDropdown {
    flex: 0 0 var(--item-height) !important;
    grid-column: auto !important;
    grid-row: auto !important;
    height: var(--item-height) !important;
    margin: 0 !important;
    width: var(--item-height) !important;
  }
}
/* Record keywords: compact expand/collapse control. */
.keyword-inline-group {
  align-items: center;
  display: inline-flex;
  gap: 0.25rem;
}

.keyword-toggle-btn {
  align-items: center;
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: currentColor;
  cursor: pointer;
  display: inline-flex;
  height: 1.5rem;
  justify-content: center;
  padding: 0;
  width: 1.5rem;
}

.keyword-toggle-btn:hover {
  background-color: #edf0f2;
}

.keyword-toggle-btn:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.keyword-toggle-icon {
  transition: transform 0.15s ease-in-out;
}

.keyword-toggle-btn[aria-expanded="true"] .keyword-toggle-icon {
  transform: rotate(180deg);
}

/* Authority detail follows the visual language of the bibliographic record. */
.template-dir-authority .authority-record-content .top-nav {
  align-items: center;
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-2);
  justify-content: flex-start;
}

.template-dir-authority .authority-record-content .top-nav-spacer,
.template-dir-authority .authority-record-content .center-controls {
  display: none;
}

.template-dir-authority .authority-record-content .top-actions {
  gap: var(--space-2);
  margin-left: auto;
}

.template-dir-authority .authority-record-content .top-actions .action-btn,
.template-dir-authority .authority-record-content .top-actions .back-btn {
  height: var(--button-height);
  justify-content: center;
  max-height: var(--button-height);
  min-height: var(--button-height);
}

.template-dir-authority .auth-detail-subtitle {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.template-dir-authority .authority-main-details {
  --bs-table-accent-bg: transparent;
  --bs-table-bg: transparent;
  --bs-table-hover-bg: transparent;
  --bs-table-striped-bg: transparent;
  background: transparent;
  border-collapse: collapse;
  font-size: 0.9em;
  margin-top: 0;
}

.template-dir-authority .authority-main-details > tbody > tr,
.template-dir-authority .authority-main-details > tbody > tr:hover,
.template-dir-authority .authority-main-details > tbody > tr:focus,
.template-dir-authority .authority-main-details > tbody > tr:active {
  background: transparent !important;
  background-color: transparent !important;
  border-bottom: 1px solid var(--border-color);
  box-shadow: none !important;
}

.template-dir-authority .authority-main-details > tbody > tr:last-child {
  border-bottom: 0;
}

.template-dir-authority .authority-main-details > tbody > tr > th,
.template-dir-authority .authority-main-details > tbody > tr > td,
.template-dir-authority .authority-main-details > tbody > tr:nth-of-type(odd) > th,
.template-dir-authority .authority-main-details > tbody > tr:nth-of-type(odd) > td,
.template-dir-authority .authority-main-details > tbody > tr:hover > th,
.template-dir-authority .authority-main-details > tbody > tr:hover > td {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  padding: var(--space-2) 0;
  vertical-align: top;
}

.template-dir-authority .authority-main-details > tbody > tr > th {
  color: var(--text-muted);
  font-weight: 500;
  padding-right: var(--space-5);
  width: 18ch;
}

.template-dir-authority .authority-main-details td div + div {
  margin-top: var(--space-1);
}

.template-dir-authority .marc21-data {
  border-color: var(--border-color);
  box-shadow: none;
  margin: 1.5rem 0;
}

.template-dir-authority .marc-toggle-btn {
  background: #f9fafb;
  border: 0;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  padding: var(--space-3) var(--space-4);
}

.template-dir-authority .marc-toggle-btn .marc-label {
  color: var(--text-main);
  font-size: var(--text-lg);
  font-weight: 700;
}

.template-dir-authority .marc-content {
  background: #fff;
  overflow-x: auto;
  padding: 0;
}

.template-dir-authority .staff-view--marc {
  background: #fff;
  border-collapse: collapse;
  color: var(--text-main);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  margin: 0;
  min-width: 920px;
  width: 100%;
}

.template-dir-authority .staff-view--marc .pace-car {
  display: none;
}

.template-dir-authority .staff-view--marc > tbody > tr > th,
.template-dir-authority .staff-view--marc .marc__field strong {
  color: var(--primary);
  font-weight: 800;
}

.template-dir-authority .staff-view--marc > tbody > tr:hover > th,
.template-dir-authority .staff-view--marc > tbody > tr:hover > td {
  background: var(--primary-light) !important;
}

@media (max-width: 767px) {
  .template-dir-authority .authority-main-details,
  .template-dir-authority .authority-main-details > tbody,
  .template-dir-authority .authority-main-details > tbody > tr,
  .template-dir-authority .authority-main-details > tbody > tr > th,
  .template-dir-authority .authority-main-details > tbody > tr > td {
    display: block;
  }

  .template-dir-authority .authority-main-details > tbody > tr > th,
  .template-dir-authority .authority-main-details > tbody > tr > td {
    padding-left: 0;
    padding-right: 0;
    width: 100%;
  }

  .template-dir-authority .authority-main-details > tbody > tr > th {
    padding-bottom: var(--space-1);
  }

  .template-dir-authority .authority-main-details > tbody > tr > td {
    padding-top: 0;
  }

  .template-dir-authority .authority-record-content .record-home-btn__text,
  .template-dir-authority .authority-record-content .back-btn .btn-text {
    display: none;
  }
}
