/* 
 * Terms and Definitions Styling
 * Organized by component and functionality
 */

/* ====== GENERAL HEADING STYLES ====== */
h2,
h3,
h4,
h5,
h6 {
  margin-top: 1.5em !important;
}

/* ====== TERMINOLOGY SECTION CONTAINER ====== */
/* Hidden while empty so the bar does not flash before JS decides to fill or remove it */
#terminology-section-utility-container:empty {
  display: none;
}

#terminology-section-utility-container {
  margin: 1em auto;
  width: 100%;
}

@media (min-width: 576px) {
  #terminology-section-utility-container {
    position: sticky;
    top: 3.5em;
    z-index: 10;
  }
}

/* ====== ANCHOR LINKS ====== */
.toc-anchor {
  font-size: 0.875em;
  color: #73c2df;
  text-decoration: none;
  transition: opacity 0.3s ease;
}

.toc-anchor:hover {
  opacity: 1;
}

/* ====== DEFINITION LIST STYLING (BOOTSTRAP CARD STYLE) ====== */
dl.terms-and-definitions-list {
  margin: 0;
  padding: 0;
  position: relative;
  z-index: 1;
  /* Set a baseline z-index for the whole list */
}

/* ====== DEFAULT STYLING ====== */
/* Term styling (dt) */
dl.terms-and-definitions-list>dt {
  font-weight: 700;
  margin: 0;
  background-color: var(--card-bg-dt);
  border: 1px solid var(--card-border);
  padding: 0.5rem 1.25rem;
  /* Increased vertical padding for better readability */
  border-radius: 0.375rem 0.375rem 0 0;
  color: var(--card-text);
  position: relative;
  /* Position relative for stacking */
  line-height: 1.5;
  /* Improve line spacing */
  font-size: 1.05em;
  /* Slightly larger font for better hierarchy */
  /* Use flexbox for proper layout of term text and button container */
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  /* Space between term text and buttons */
  min-height: 2.5rem;
  /* Ensure minimum height for buttons */
}

/* ====== ELLIPSIS TRUNCATION WITH HOVER EXPANSION ====== */
/* Term text styling with ellipsis truncation and hover expansion */
dl.terms-and-definitions-list>dt>span {
  /* Flex item that grows to fill available space */
  flex: 1 1 auto;
  min-width: 0;
  /* Allow flex item to shrink below content size */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.2s ease-in-out;
}

/* On hover or focus (including parent dt), expand to show full content */
/* The term will expand naturally and wrap if needed, buttons will only wrap if necessary */
dl.terms-and-definitions-list>dt>span:hover,
dl.terms-and-definitions-list>dt>span:focus,
dl.terms-and-definitions-list>dt:hover>span,
dl.terms-and-definitions-list>dt:focus>span {
  white-space: normal;
  overflow: visible;
  text-overflow: initial;
  word-wrap: break-word;
  line-height: 1.4;
  /* Don't force full width - let it expand naturally */
  /* Buttons will only wrap if the expanded text actually needs more space */
}

/* Touch device support - also trigger on tap/touch */
dl.terms-and-definitions-list>dt>span:active,
dl.terms-and-definitions-list>dt:active>span {
  white-space: normal;
  overflow: visible;
  text-overflow: initial;
  word-wrap: break-word;
  line-height: 1.4;
}


/* Increase the size for all buttons in definition terms */
dl.terms-and-definitions-list>dt .btn {
  font-size: 1.2em !important;
  /* Increase button size */
}

dl.terms-and-definitions-list>dt:hover {
  background-color: var(--card-hover-bg);
  transition: background-color 0.2s ease-in-out;
}

/* Definition styling (dd) */
dl.terms-and-definitions-list>dd {
  margin: 0;
  background-color: var(--card-bg);
  border: 1px solid var(--card-border);
  border-top: none;
  padding: 0.5rem 2rem;
  color: var(--card-text);
  width: 100%;
  position: relative;
}

/* Style paragraphs inside dd */
dl.terms-and-definitions-list dd p {
  margin: 0;
  color: var(--card-text);
  padding-left: 0.5rem;
}

/* Remove the blue line indicator for dd */
dl.terms-and-definitions-list>dd::before {
  display: none;
}

/* Improve table styling in definitions */
dl.terms-and-definitions-list dd table {
  margin: 0.5em 0;
  width: 100%;
  border-collapse: collapse;
}

dl.terms-and-definitions-list dd table th,
dl.terms-and-definitions-list dd table td {
  padding: 0.5em;
  border: 1px solid var(--table-border);
}

dl.terms-and-definitions-list dd table th {
  background-color: var(--table-header-bg);
}

/*
  Make the meta-info tables collapsible
*/

/* Wrapper for meta info content */
dl>dd:has(table).meta-info-content-wrapper {
  display: block;
  font-size: 0.7em;
  position: relative;
  max-height: none;
  height: auto;
  overflow: visible;
  transition: all 0.3s ease-out;
}

dl>dd:has(table).meta-info-content-wrapper td,
dl>dd:has(table).meta-info-content-wrapper th {
  padding: 0.3em;
}

/* Collapsed state for meta info content */
dl>dd:has(table).collapsed.meta-info-content-wrapper {
  max-height: 0;
  height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  margin-bottom: 0;
  overflow: hidden;
  transition: all 0.3s ease-out;
  line-height: 0;
}

/* The inner content wrapper to ensure proper spacing */
dl>dd:has(table).meta-info-content-wrapper>div {
  display: block;
  padding: inherit;
}

/* Meta info toggle button */
.meta-info-toggle-button {
  position: relative;
  cursor: pointer;
}

/*
  END Make the meta-info tables collapsible
*/

/* Borders and spacing between elements */
dl.terms-and-definitions-list dt+dd {
  border-bottom: none;
}

dl.terms-and-definitions-list dd+dd {
  border-top: none;
  border-bottom: none;
}

dl.terms-and-definitions-list dd+dt {
  margin-top: 1rem;
}

/* Last definition in a group */
dl.terms-and-definitions-list dd.last-dd {
  border-radius: 0 0 0.375rem 0.375rem;
  border-bottom: 1px solid var(--card-border);
}

/* ====== DENSE INFO STYLING ====== */
/* Apply original, more condensed styling when the html element has class "dense-info" */
html.dense-info dl.terms-and-definitions-list>dt {
  padding: 0.1rem 1.25rem;
  /* Keep flexbox for consistent layout, just reduce padding */
  line-height: inherit;
  font-size: inherit;
  min-height: auto;
  /* Remove minimum height in dense mode */
}

html.dense-info dl.terms-and-definitions-list dd+dt {
  margin-top: 0.3rem;
}

html.dense-info dl.terms-and-definitions-list>dt::before {
  display: none;
  /* Remove the blue indicator bar */
}

html.dense-info dl.terms-and-definitions-list>dt>span {
  /* Keep flex properties for consistent behavior */
  flex: 1 1 auto;
  min-width: 0;
}

/* ====== TRANSCLUSIONS STYLING ====== */
/* Base transclusion styles */
.term-external {
  position: relative;
}

dl.terms-and-definitions-list>dt.term-external,
dl.terms-and-definitions-list>dd.term-external {
  background: var(--external-term-bg);
}

/* Local term styling */
.term-local {
  position: relative;
}

dl.terms-and-definitions-list>dt.term-local,
dl.terms-and-definitions-list>dd.term-local {
  background: var(--local-term-bg);
}

/* Generic class for all original terms (both local and external) */
dl.terms-and-definitions-list .term-original-term {
  font-style: italic;
}

dl.terms-and-definitions-list .term-external-parenthetical-terms {
  font-weight: normal;
}

/* Local term original term and parenthetical styling */
dl.terms-and-definitions-list .term-local-original-term {
  font-style: italic;
}

dl.terms-and-definitions-list .term-local-parenthetical-terms {
  font-weight: normal;
}

/* Fix for all buttons */
.btn {
  font-variant: small-caps;
  text-transform: uppercase;
  position: relative;
  z-index: 5;
  /* Higher z-index for all buttons */
}

.transclusion-heading {
  font-size: 1.3em;
  font-weight: bold;
  margin: 0.2em 0 0.2em;
}

/* Embedded transclusions in definition lists */
dl.terms-and-definitions-list>dd.term-external-embedded {
  position: relative;
  padding-left: 2.5rem;
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
}

/* Arrow styling for transclusions */
dl.terms-and-definitions-list span.term-external::after {
  content: "";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' class='bi bi-box-arrow-right' viewBox='0 0 16 16' fill='currentColor'%3E%3Cpath fill-rule='evenodd' d='M10 12.5a.5.5 0 0 1-.5.5h-8a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h8a.5.5 0 0 1 .5.5v2a.5.5 0 0 0 1 0v-2A1.5 1.5 0 0 0 9.5 2h-8A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h8a1.5 1.5 0 0 0 1.5-1.5v-2a.5.5 0 0 0-1 0v2z'/%3E%3Cpath fill-rule='evenodd' d='M15.854 8.354a.5.5 0 0 0 0-.708l-3-3a.5.5 0 0 0-.708.708L14.293 7.5H5.5a.5.5 0 0 0 0 1h8.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  width: 0.8rem;
  height: 0.8rem;
  left: 0.2rem;
}

/* Dark mode: invert the transclusion arrow icon */
[data-bs-theme="dark"] dl.terms-and-definitions-list span.term-external::after {
  filter: invert(1);
}

/* Inline span styling for transclusions */
dl.terms-and-definitions-list span.term-external {
  padding-left: 1.5rem;
  display: inline-block;
}

.placeholder-tref {
  display: none;
}

/* ====== ERROR MESSAGES ====== */
/* No cross-reference found styling */
.no-xref-found-message {
  background: var(--error-message-bg);
  color: var(--error-message-text);
  margin: 0 0.5em;
  padding: 0 0.8em;
  border-radius: 0.25rem;
  font-size: 0.8rem;
  font-variant: small-caps;
  text-transform: uppercase;
}

/* ====== TERM REFERENCE STYLING ====== */
/* Inline term references (clickable links to definitions) */
.term-reference {
  text-decoration: none;
  transition: box-shadow 0.3s ease-in-out;
  border-bottom: 1px dashed var(--term-reference-border);
  padding: 0 1px;
  margin-left: 0.1rem;
  margin-right: 0.1em;
}

.term-reference:hover {
  box-shadow: inset 0 0 0 3px var(--term-reference-border);
}

/* Remove arrow for term references that are dt elements or inside dt elements */
dt.term-reference::after,
dt .term-reference::after {
  display: none;
}

/* ====== INLINE REFERENCE (IREF) STYLING ====== */
/* Wrapper for iref content */
.iref-content {
  margin: 1rem 0;
}

/* Definition list within iref - use similar styling to main terms list */
dl.iref-definition-list {
  margin: 0;
  padding: 0;
}

/* Term styling for iref - lighter appearance to indicate it's a copy */
dl.iref-definition-list>dt.iref-term {
  background-color: rgba(var(--card-bg-dt-rgb, 248, 249, 250), 0.5);
  border: none;
  box-shadow: none;
  padding: 1rem 2.25rem 0.5rem 0rem;
  border-radius: 0.375rem 0.375rem 0 0;
  transition: background-color 0.3s ease-in-out, transform 0.2s ease-in-out;
}

/* Subtle hover effect for iref terms */
dl.iref-definition-list>dt.iref-term:hover {
  background-color: rgba(var(--card-bg-dt-rgb, 248, 249, 250), 0.5);
  transform: translateX(2px);
}

/* Definition styling for iref - very light background, no border */
dl.iref-definition-list>dd.iref-definition {
  margin: 0;
  background-color: rgba(var(--card-bg-rgb, 255, 255, 255), 0.5);
  padding: 0rem 2rem;
  transition: background-color 0.3s ease-in-out, transform 0.2s ease-in-out;
}

dl.iref-definition-list>dt.iref-term,
dl.iref-definition-list>dd.iref-definition {
  font-size: 0.8em;
}

/* Subtle hover effect for iref definitions */
dl.iref-definition-list>dd.iref-definition:hover {
  background-color: rgba(var(--card-bg-rgb, 255, 255, 255), 0.5);
  transform: translateX(2px);
}

/* Subtle separator between consecutive iref dd elements */
dl.iref-definition-list>dd.iref-definition+dd.iref-definition {
  border-top: 1px dashed rgba(0, 0, 0, 0.1);
}


/* Last dd in iref gets rounded bottom corners */
dl.iref-definition-list>dd.iref-definition:last-child {
  border-radius: 0 0 0.375rem 0.375rem;
}

/* Style paragraphs inside iref dd */
dl.iref-definition-list dd.iref-definition p {
  margin: 0;
  color: var(--card-text);
  padding-left: 0.5rem;
}

/* Button link to original term in iref dt */
a.iref-go-to-glossary-button {
  margin-left: 0.5rem;
  white-space: nowrap;
  text-decoration: none;
  position: relative;
}

a.iref-go-to-glossary-button:hover {
  text-decoration: none;
}

/* Arrow icon for the button */
a.iref-go-to-glossary-button .iref-button-icon {
  position: absolute;
  top: 50%;
  left: 0.3rem;
  transform: translateY(-50%);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' class='bi bi-box-arrow-right' viewBox='0 0 16 16' fill='currentColor'%3E%3Cpath fill-rule='evenodd' d='M10 12.5a.5.5 0 0 1-.5.5h-8a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h8a.5.5 0 0 1 .5.5v2a.5.5 0 0 0 1 0v-2A1.5 1.5 0 0 0 9.5 2h-8A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h8a1.5 1.5 0 0 0 1.5-1.5v-2a.5.5 0 0 0-1 0v2z'/%3E%3Cpath fill-rule='evenodd' d='M15.854 8.354a.5.5 0 0 0 0-.708l-3-3a.5.5 0 0 0-.708.708L14.293 7.5H5.5a.5.5 0 0 0 0 1h8.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  width: 0.8rem;
  height: 0.8rem;
  display: inline-block;
  content: "";
}

/* Dark mode: invert the iref button icon */
[data-bs-theme="dark"] a.iref-go-to-glossary-button .iref-button-icon {
  filter: invert(1);
}

/* iref not found message */
.iref-not-found {
  margin: 0.5rem 0;
  padding: 0.5rem 1rem;
  background-color: var(--warning-message-bg);
  border: 1px solid var(--warning-message-border);
  border-radius: 0.375rem;
  color: var(--warning-message-text);
}