/**
 * @file
 * Styling for the tdresource hierarchy tree and generated file-type icons.
 */

.tdresources-tree-wrapper {
  margin-top: 0.5em;
}

.tdresources-tree-help {
  margin: 0.25em 0 0.5em;
}

.tdresources-tree {
  max-height: 20em;
  overflow-y: auto;
  border: 1px solid #ccc;
  padding: 0.5em;
}

.tdresources-tree-branch > summary {
  cursor: pointer;
}

.tdresources-tree-leaf {
  margin-left: 1.5em;
}

.tdresources-tree-link--active {
  font-weight: bold;
  text-decoration: underline;
}

.tdresources-intro-counter {
  font-style: italic;
}

.tdresources-intro-counter--over {
  color: #b91c1c;
  font-weight: bold;
}

/*
 * File-type icon: a small colored "document with folded corner" SVG,
 * labelled with the extension, styled per extension below. Colors are
 * applied to the SVG shapes via currentColor, so overriding
 * .tdresources-file-icon--{extension}'s `color` is enough for sites
 * that want different colors without touching the SVG markup.
 */
.tdresources-file-icon {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  width: 1.4em;
  height: 1.6em;
  color: #6b7280;
}

.tdresources-file-icon svg {
  width: 100%;
  height: 100%;
}

.tdresources-file-icon-body {
  fill: currentColor;
}

.tdresources-file-icon-fold {
  fill: rgb(255 255 255 / 40%);
}

.tdresources-file-icon-label {
  fill: #fff;
  font-size: 8px;
  font-family: sans-serif;
  font-weight: bold;
}

.tdresources-file-icon--pdf {
  color: #b91c1c;
}

.tdresources-file-icon--doc,
.tdresources-file-icon--docx {
  color: #1d4ed8;
}

.tdresources-file-icon--xls,
.tdresources-file-icon--xlsx {
  color: #15803d;
}

.tdresources-file-icon--ppt,
.tdresources-file-icon--pptx {
  color: #c2410c;
}

/*
 * "Up to" ancestor trail, shown directly above the page title -- see
 * TdresourcesHookHandler::preprocessPageTitle().
 */
.tdresources-parent-link {
  font-style: italic;
  margin: 0 0 0.25em;
}

/*
 * Line holding the "Add child" link, just above the children table.
 * Added client-side by tdresources.reorder.js. Keeps the blank line's
 * worth of space that separates the hierarchy section from the content
 * before it, and contains the floated link so the table doesn't creep
 * up alongside it.
 */
.tdresources-add-child-line {
  /* Start below the right-floated Edit/Subscribe column: next to it,
   * this line was squeezed into the space left of the floats, so its
   * link didn't reach the right edge. */
  clear: both;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  text-align: right;
}

.tdresources-parent-trail-separator {
  font-style: normal;
  color: #9ca3af;
  margin: 0 0.15em;
}

.tdresources-children-table {
  width: 100%;
  border-collapse: collapse;
}

.tdresources-children-table th,
.tdresources-children-table td {
  padding: 0.25em 0.5em;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
}

/*
 * "Add child" link: right aligned, just above the children table. Added client-side by tdresources.reorder.js, for users who
 * may manage the hierarchy.
 */
.tdresources-add-child-link {
  font-style: normal;
}

/*
 * Children table: the introduction starts on a new line below the
 * title -- see HierarchyManager::buildChildTableRow().
 */
.tdresources-child-intro {
  display: block;
  margin-top: 0.15em;
}

/*
 * Direct "Edit" link, shown to whoever may actually edit the node --
 * see TdresourcesHookHandler::addEditLink().
 */
.tdresources-edit-link {
  display: inline-block;
  float: right;
  clear: right;
  margin-bottom: 0.5em;
}

/*
 * Keep the top of the right-hand column (language flags, or else the
 * "Edit" link) clear of Drupal's contextual links pencil button, which
 * sits in the top-right corner of the node for users who may use
 * contextual links (.contextual-region). Only the topmost item moves
 * down; everything below follows it, so the column stays aligned with
 * the "Add child" link further down.
 */
.contextual-region .tdresources-language-selector,
.contextual-region .tdresources-edit-link {
  margin-top: 2.75rem;
}

.contextual-region .tdresources-language-selector ~ .tdresources-edit-link {
  margin-top: 0;
}

/*
 * Subscribe/unsubscribe button, logged-in users only, right aligned
 * below the "Edit" link -- see
 * TdresourcesHookHandler::addSubscriptionButton(). Uses the theme's
 * .button styling where available; the rules below only make sure it
 * looks like a button in themes without one.
 */
.tdresources-subscription {
  float: right;
  clear: right;
  margin: 0 0 0.5em 0.5em;
}

.tdresources-subscription-button {
  display: inline-block;
  padding: 0.2em 0.8em;
  border: 1px solid currentColor;
  border-radius: 1em;
  font-size: 0.9em;
  text-decoration: none;
  cursor: pointer;
}

.tdresources-subscription-button--subscribed {
  opacity: 0.75;
}

/*
 * Top-right language selector, shown when a node has two or more
 * published translations -- see
 * TdresourcesHookHandler::addLanguageSelector().
 */
.tdresources-language-selector {
  float: right;
  margin-bottom: 0.5em;
}

.tdresources-language-link {
  display: inline-block;
  vertical-align: middle;
  margin-left: 0.4em;
  /* 150% of the original 1.3em. */
  font-size: 1.95em;
  line-height: 1;
  text-decoration: none;
  border-radius: 50%;
}

/*
 * Round flag: a 1em circle that clips a square SVG flag image (see
 * LanguageFlagMapper::getFlagImageUrl()) filling it edge to edge.
 */
.tdresources-language-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
  border-radius: 50%;
  overflow: hidden;
  vertical-align: middle;
  /* Thin edge, so light flags stay visible on a white background. */
  box-shadow: 0 0 0 1px rgb(0 0 0 / 15%);
}

.tdresources-language-flag-image {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
}

.tdresources-language-link--current {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/*
 * Unpublished tdresource nodes get a slightly pink background, applied
 * to the node's own wrapper element -- see
 * TdresourcesHookHandler::addUnpublishedClass().
 */
.tdresources-unpublished {
  background-color: #fdf1f6;
}

/*
 * Editors-only "Unpublished children" list -- see
 * TdresourcesHookHandler::addUnpublishedChildrenList().
 */
.tdresources-unpublished-children {
  margin-top: 1.5em;
  padding-top: 0.5em;
  border-top: 1px solid #e5e7eb;
}

.tdresources-unpublished-children h3 {
  margin: 0 0 0.25em;
  font-size: 1em;
}

/*
 * Year and version: label and value on one line ("Year: 2026"). Added
 * by TdresourcesHookHandler::preprocessField() whenever these fields'
 * label is set to "Inline", so it works whether or not the active
 * theme styles Drupal's own field--label-inline class. Flexbox lays
 * the label and value out side by side regardless of the theme's
 * field markup; any float/padding a theme applies to inline labels
 * is neutralized so spacing comes only from the gap below.
 */
.tdresources-inline-field {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 0.4em;
}

.tdresources-inline-field > * {
  float: none;
  margin: 0;
  padding: 0;
}

/*
 * Colon after the label. Themes that output field--label-inline
 * (Olivero and Classy-derived themes) already add their own colon, so
 * only add one where the theme doesn't, to avoid "Year:: 2026".
 */
.tdresources-inline-field:not(.field--label-inline) > .tdresources-inline-field__label::after {
  content: ":";
}

/*
 * File attachments with a small preview -- see
 * AttachmentPreviewFormatter. One row per file: a 96px preview box,
 * then the file link (and size).
 */
.tdresources-attachment {
  display: flex;
  align-items: center;
  gap: 0.75em;
  margin: 0 0 0.6em;
}

.tdresources-attachment__preview {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
  overflow: hidden;
  border: 1px solid rgb(0 0 0 / 15%);
  border-radius: 4px;
  background: #fff;
  text-decoration: none;
}

.tdresources-attachment__link {
  min-width: 0;
  overflow-wrap: anywhere;
}

.tdresources-attachment-preview--image,
.tdresources-attachment-preview--pdf {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

/* PDF first page: top of the page, filling the box's width. */
.tdresources-attachment-preview--pdf {
  width: 100%;
  align-self: flex-start;
}

.tdresources-attachment-preview--text {
  align-self: stretch;
  width: 100%;
  margin: 0;
  padding: 4px;
  overflow: hidden;
  font-size: 7px;
  line-height: 1.3;
  color: #444;
  white-space: pre-wrap;
  word-break: break-all;
  text-align: left;
}

.tdresources-attachment-preview--badge {
  padding: 0.35em 0.6em;
  border-radius: 3px;
  font-family: system-ui, sans-serif;
  font-size: 0.85em;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #fff;
  background: #6b7280;
}

.tdresources-attachment-preview--badge-text { background: #2b579a; }
.tdresources-attachment-preview--badge-sheet { background: #217346; }
.tdresources-attachment-preview--badge-slides { background: #c43e1c; }
.tdresources-attachment-preview--badge-pdf { background: #b30b00; }

/*
 * External links in resource text -- see LinkAnnotator. Dead links are
 * struck through with a "(dead link)" note; working links with a
 * stored preview show a popup (thumbnail, page title, site) on mouse
 * hover or keyboard focus.
 */
.tdresources-link--dead {
  text-decoration: line-through;
  opacity: 0.7;
}

.tdresources-dead-link {
  font-size: 0.85em;
  font-style: italic;
  color: #b30b00;
  cursor: help;
  white-space: nowrap;
}

.tdresources-link--preview {
  position: relative;
}

.tdresources-link-preview {
  display: none;
  position: absolute;
  z-index: 500;
  top: 100%;
  left: 0;
  width: 240px;
  max-width: 80vw;
  margin-top: 6px;
  padding: 0 0 8px;
  overflow: hidden;
  border: 1px solid rgb(0 0 0 / 15%);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 6px 18px rgb(0 0 0 / 18%);
  color: #222;
  font-size: 0.85rem;
  font-style: normal;
  font-weight: normal;
  line-height: 1.35;
  text-align: left;
  text-decoration: none;
  white-space: normal;
  pointer-events: none;
}

.tdresources-link--preview:hover .tdresources-link-preview,
.tdresources-link--preview:focus-visible .tdresources-link-preview {
  display: block;
}

.tdresources-link-preview__image {
  display: block;
  width: 100%;
  height: auto;
  max-height: 160px;
  object-fit: cover;
  border-bottom: 1px solid rgb(0 0 0 / 10%);
}

.tdresources-link-preview__title {
  display: block;
  padding: 8px 10px 2px;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tdresources-link-preview__host {
  display: block;
  padding: 2px 10px 0;
  color: #666;
  font-size: 0.8em;
}

/* No hover on touch screens: don't leave a popup stuck open after a tap. */
@media (hover: none) {
  .tdresources-link--preview:hover .tdresources-link-preview {
    display: none;
  }
}

/*
 * "(History)" after the version -- see VersionHistory::buildHistory().
 * The popup lists every version with a link; it opens on mouse hover
 * or keyboard focus, and stays open while the pointer moves into it
 * (it is part of the hovered element, joined without a gap).
 */
.tdresources-version-history {
  position: relative;
  display: inline-block;
  margin-left: 0.4em;
  cursor: help;
  font-size: 0.9em;
  text-decoration: underline dotted;
}

.tdresources-version-history__popup {
  display: none;
  position: absolute;
  z-index: 500;
  top: 100%;
  left: 0;
  padding-top: 4px;
  cursor: auto;
  text-decoration: none;
}

.tdresources-version-history:hover .tdresources-version-history__popup,
.tdresources-version-history:focus-within .tdresources-version-history__popup {
  display: block;
}

.tdresources-version-history__list {
  display: block;
  min-width: 14em;
  max-height: 18em;
  overflow-y: auto;
  padding: 6px 0;
  border: 1px solid rgb(0 0 0 / 15%);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 6px 18px rgb(0 0 0 / 18%);
  color: #222;
  font-size: 0.95em;
  line-height: 1.4;
  white-space: nowrap;
}

.tdresources-version-history__item {
  display: block;
  padding: 3px 12px;
}

.tdresources-version-history__date {
  margin-left: 0.5em;
  color: #666;
  font-size: 0.85em;
}

/* Shown when an older revision of a resource is being viewed. */
.tdresources-older-version {
  margin: 0.25em 0 0.75em;
  padding: 0.5em 0.75em;
  border-left: 4px solid #c47f00;
  background: #fff6e0;
}

/* Child listed in another language than the table's (it has no version
 * in the table's language): its language code after the title. */
.tdresources-child-language {
  padding: 0 0.3em;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: 0.7em;
  font-weight: 600;
  letter-spacing: 0.03em;
  opacity: 0.7;
  vertical-align: middle;
  cursor: help;
}
