/**
 * Copyright (c) 2026 ResearchSpace contributors.
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

/* Starter header and footer. Colours and fonts come from the ResearchSpace
   theme; a custom app can override the --rs-project-* variables below in its
   own stylesheet. Needs enableHeaderFooterLayout=true in ui.prop. */

.rs-project-header,
.rs-project-footer {
  --rs-project-accent: var(--rs-color-action, #306eb0);
  --rs-project-text: var(--rs-color-text, #29353d);
  --rs-project-muted: var(--rs-color-text-muted, #5c6670);
  --rs-project-surface: var(--rs-color-surface, #fff);
  --rs-project-subtle: var(--rs-color-surface-subtle, #eef2ef);
  --rs-project-border: var(--rs-color-border, #d9ddd9);
  font-family: var(--rs-font-family-body, sans-serif);
  color: var(--rs-project-text);
  background: var(--rs-project-surface);
}

.rs-project-header a,
.rs-project-footer a,
.rs-project-header .dropdown-toggle {
  color: inherit;
}

.rs-project-footer a:focus-visible {
  outline: 2px solid var(--rs-color-focus, var(--rs-project-accent));
  outline-offset: 2px;
}

/* Header links and menu toggles: no underline and no box on focus. The platform's
   focus styles (dotted underline, outline) lingered on a link after a click, since
   it keeps focus, e.g. Workspace in the workspace. Keyboard focus shows as the
   accent colour instead. */
.rs-project-header a:not(.btn):not([role="button"]):focus,
.rs-project-header a:not(.btn):not([role="button"]):focus-visible,
.rs-project-header .dropdown-toggle:focus,
.rs-project-header .dropdown-toggle:focus-visible {
  text-decoration: none !important;
  outline: none !important;
  box-shadow: none !important;
}

.rs-project-header a:not(.btn):not([role="button"]):focus-visible,
.rs-project-header .dropdown-toggle:focus-visible {
  color: var(--rs-color-focus, var(--rs-project-accent)) !important;
}

.rs-project-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 24px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Dropdown toggles read as navigation links, not buttons, also while open. */
.rs-project-header .dropdown .dropdown-toggle.btn,
.rs-project-header .dropdown.open .dropdown-toggle.btn {
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
  color: inherit;
  font: inherit;
  /* _buttons.scss sets every .btn to 13px !important below 768px. */
  font-size: inherit !important;
}

/* Menus in the nav and the utilities open just below the header row, with
   their right edge under the right edge of their own toggle, so a menu stays
   next to what opened it. To start at the header's lower edge, the items
   stretch to the row's height and the menu adds the row's padding.
   rs-dropdown places its own menus, so only plain dropdowns need this. */
.rs-project-header__row {
  position: relative;
}

.rs-project-nav,
.rs-project-utilities,
.rs-project-account,
.rs-project-nav > .rs-project-links,
.rs-project-header .rs-project-account > .nav {
  align-self: stretch;
  align-items: stretch;
}

.rs-project-nav,
.rs-project-account {
  display: flex;
}

.rs-project-nav .dropdown:not(.rs-anchored-dropdown),
.rs-project-utilities .dropdown:not(.rs-anchored-dropdown) {
  position: relative;
  align-self: stretch;
}

.rs-project-nav .dropdown:not(.rs-anchored-dropdown) > .dropdown-menu,
.rs-project-utilities .dropdown:not(.rs-anchored-dropdown) > .dropdown-menu {
  top: calc(100% + var(--rs-project-row-pad));
  right: 0;
  left: auto;
  min-width: 160px; /* the platform's min-width: stretch would fill the row */
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px); /* instead of the platform's 350px */
  overflow-y: auto;
}

/* Two-column grid menus: a little narrower than the platform's 700px, so a
   menu under the leftmost toggle still fits mid-size screens. */
.rs-project-header .dropdown-grid-container:not(.rs-project-menu-column) {
  width: 620px;
}

/* Search and Add Documentation menus look different: an add menu has a solid
   title band and a "+" badge on each icon, a search menu a magnifier badge.
   Mark the dropdown with class="rs-project-menu-add" or "rs-project-menu-search". */
.rs-project-header .rs-project-menu-add .dropdown-menu > .dropdown-sectionTitle:first-child {
  background: var(--rs-color-action, #306eb0);
  color: var(--rs-color-on-dark, #fff);
}

.rs-project-header .rs-project-menu-add .dropdown-item-iconContainer,
.rs-project-header .rs-project-menu-search .dropdown-item-iconContainer {
  position: relative;
}

.rs-project-header .rs-project-menu-add .dropdown-item-iconContainer::after,
.rs-project-header .rs-project-menu-search .dropdown-item-iconContainer::after {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font: 14px/18px "Material Symbols Rounded";
  text-align: center;
}

.rs-project-header .rs-project-menu-add .dropdown-item-iconContainer::after {
  content: "add";
  background: var(--rs-color-action, #306eb0);
  color: var(--rs-color-on-dark, #fff);
}

.rs-project-header .rs-project-menu-search .dropdown-item-iconContainer::after {
  content: "search";
  border: 1px solid var(--rs-project-border);
  background: var(--rs-project-surface);
  color: var(--rs-project-muted);
}

/* Section titles in the grid menus (e.g. "Help and guides") on a band in the
   theme's selected-button colour, edge to edge across the menu's 4px padding. */
.rs-project-header .dropdown-menu .dropdown-sectionTitle {
  margin: 0 -4px;
  padding: 10px 29px;
  background: var(--color-btn-default-bg-active, var(--rs-project-subtle));
  border-bottom: none;
}

.rs-project-header .dropdown-menu > .dropdown-sectionTitle:first-child {
  margin-top: -4px;
}

/* Later sections are set off by a line, not another band. */
.rs-project-header .dropdown-menu > .dropdown-sectionTitle:not(:first-child) {
  margin-top: 4px;
  border-top: 1px solid var(--rs-project-border);
  background: none;
}

/* A line between groups inside one grid menu: <li role="separator" class="divider"></li>
   between items spans the whole menu, edge to edge. */
.rs-project-header .dropdown-grid-container > .divider {
  grid-column: 1 / -1;
  height: 1px;
  margin: 8px -14px;
  background: var(--rs-project-border);
}

/* A short grid menu in one narrow column, e.g. the account menu:
   class="dropdown-grid-container rs-project-menu-column". */
.rs-project-header .dropdown-grid-container.rs-project-menu-column {
  width: 340px;
  max-width: 100%;
  grid-template-columns: 1fr;
}

.rs-project-header .rs-project-menu-column > li > a,
.rs-project-header .rs-project-menu-column li a {
  padding-top: 12px;
  padding-bottom: 12px;
}

/* Grid menu icons take the theme's colours in turn, so every menu follows the
   theme without colours in the templates. */
.rs-project-header .dropdown-grid-container > * { --rs-project-icon: var(--rs-color-action, #306eb0); }
.rs-project-header .dropdown-grid-container > :nth-child(5n+2) { --rs-project-icon: var(--rs-color-brand-accent, #c79f70); }
.rs-project-header .dropdown-grid-container > :nth-child(5n+3) { --rs-project-icon: var(--rs-color-danger, #a63f32); }
.rs-project-header .dropdown-grid-container > :nth-child(5n+4) { --rs-project-icon: var(--rs-color-success, #3e684e); }
.rs-project-header .dropdown-grid-container > :nth-child(5n+5) { --rs-project-icon: var(--rs-color-warning, #87602b); }

.rs-project-header .dropdown-item-iconContainer,
.rs-project-header .dropdown-item-iconContainer i {
  color: var(--rs-project-icon);
}

/* Menu toggles in the header read as plain labels: no carets. */
.rs-project-header .caret {
  display: none;
}

/* Icon and label links in the utilities (e.g. System settings), like Help. */
.rs-project-utilities a.rs-project-settings,
.rs-project-account > .nav > li > a.rs-project-settings {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: none;
  background: none;
  text-decoration: none;
}

/* The project menu, at the left, opens below the header row, starting under
   its toggle: the about block spans the row's height (padding included). */
.rs-project-about {
  position: relative;
  display: flex;
  align-items: center;
  align-self: stretch;
  margin-block: calc(-1 * var(--rs-project-row-pad));
  padding-block: var(--rs-project-row-pad);
}

.rs-project-about .dropdown {
  position: static;
}

.rs-project-about .dropdown > .dropdown-menu {
  top: 100%;
  left: 0;
  min-width: 160px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

/* Grid menu items (project-menu-item.hbs and the like) whose link is not a
   direct child of the list item, e.g. a dialog trigger. */
.rs-project-header .dropdown-grid-container li a {
  display: flex;
  align-items: start;
  gap: 15px;
  padding: 20px 20px 20px 15px;
  white-space: normal;
}

/* Header */
/* A dialog opened from a header menu (e.g. Contact and support) hides the menu
   behind it; Bootstrap sets modal-open on body while a dialog is open. */
.modal-open .rs-project-header .dropdown-menu {
  display: none;
}

.rs-project-header {
  border-bottom: 1px solid var(--rs-project-border);
}

.rs-project-skip {
  position: absolute;
  left: -9999px;
}

.rs-project-skip:focus {
  left: 16px;
  top: 8px;
  z-index: 1;
  padding: 8px 12px;
  background: var(--rs-project-surface);
}

.rs-project-header__row {
  --rs-project-row-pad: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: var(--rs-project-row-pad) 24px;
}

/* Bootstrap stacks .nav items outside a navbar; keep them on the header row. */
.rs-project-header .nav {
  display: flex;
  align-items: center;
  gap: 24px;
  margin: 0;
}

.rs-project-header .nav::before,
.rs-project-header .nav::after {
  display: none;
}

.rs-project-header .nav > li {
  float: none;
}

/* Non-item children of a header nav (e.g. an invisible event listener) take no
   place, so they add no gap. */
.rs-project-header .nav > :not(li) {
  position: absolute;
}

.rs-project-brand a,
.rs-project-footer__brand {
  display: flex;
  flex-direction: column;
  text-decoration: none;
}

.rs-project-brand__name {
  font: 500 20px/1.2 var(--rs-font-family-brand, Georgia, serif);
}

.rs-project-brand__subtitle {
  color: var(--rs-project-muted);
  font-size: var(--rs-font-size-sm, 12px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* The project menu sits next to the brand; the nav (search, workspace) and the
   utilities (help, account) sit at the right. The nav keeps its items on one
   line; when the row is too narrow, it wraps instead. */
.rs-project-about,
.rs-project-nav {
  font-size: var(--rs-font-size-lg, 16px);
}

.rs-project-nav {
  margin-left: auto;
}

.rs-project-nav > .rs-project-links {
  flex-wrap: nowrap;
}

.rs-project-utilities {
  display: flex;
  gap: 24px;
}

/* One alignment for every header item, whether a link (Workspace, System
   settings) or a dropdown button (Search, Create, Help, the user): each list
   item and dropdown is a flex box centred on the row, and each link or toggle
   lays out its icon and label on one centred line, at one size. */
.rs-project-utilities {
  font-size: var(--rs-font-size-lg, 16px);
}

.rs-project-links li,
.rs-project-header .nav > li,
.rs-project-header .dropdown {
  display: flex;
  align-items: center;
}

.rs-project-links a,
.rs-project-header .dropdown-toggle,
.rs-project-header .dropdown-toggle > div,
.rs-project-utilities a,
.rs-project-menu-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
}

/* Icons in the row: the same font (Material Symbols Rounded, via rs-icon
   symbol="true") at one size, set as boxes so they centre like the labels. */
.rs-project-links a > i,
.rs-project-header .dropdown-toggle i,
.rs-project-utilities a > i,
.rs-project-menu-button > i {
  display: block;
  width: 20px;
  height: 20px;
  font-size: 20px;
  line-height: 1;
}

/* The Menu button and its panel: wide screens show the items on the row. */
.rs-project-menu {
  display: contents;
}

.rs-project-menu-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.rs-project-menu-button {
  display: none;
}

.rs-project-account > .nav > li > a,
.rs-project-sign-in {
  padding: 6px 14px;
  border: 1px solid var(--rs-project-border);
  border-radius: 4px;
}

.rs-project-strip {
  padding: 8px 24px;
  border-top: 1px solid var(--rs-project-border);
  background: var(--rs-project-subtle);
  color: var(--rs-project-muted);
}

/* Footer */
.rs-project-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  padding: 14px 24px;
  border-top: 1px solid var(--rs-project-border);
}

.rs-project-footer__powered {
  color: var(--rs-project-muted);
}

/* Upper part of the footer: a full-width row above the links (public pages only). */
.rs-project-footer__about {
  flex-basis: 100%;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rs-project-border);
}

/* In the workspace, keep the header to one compact row. */
.rs-app-layout--frames .rs-project-header__row {
  --rs-project-row-pad: 6px;
}

.rs-app-layout--frames .rs-project-brand__subtitle,
.rs-app-layout--frames .rs-project-strip,
.rs-app-layout--frames .rs-project-footer__about {
  display: none;
}

/* In the workspace, the Workspace link reads as the current place. */
.rs-app-layout--frames .rs-project-nav__workspace a {
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 6px;
}

/* Mid widths: Help, System settings and the user name show as icons only
   (their titles still name them). */
@media (min-width: 1281px) and (max-width: 1500px) {
  .rs-project-utilities .rs-project-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

/* Narrow screens: the brand and a Menu button; the rest opens in a panel
   under the header, one item per line, with menus opening in place. */
@media (max-width: 1280px) {
  .rs-project-header__row {
    flex-wrap: nowrap;
    justify-content: space-between;
  }

  .rs-project-menu-button {
    display: inline-flex;
    flex: none;
    padding: 6px 12px;
    border: 1px solid var(--rs-project-border);
    border-radius: 4px;
    cursor: pointer;
    font-size: var(--rs-font-size-lg, 16px);
    font-weight: normal;
    margin: 0;
  }

  .rs-project-menu-toggle:focus-visible + .rs-project-menu-button {
    outline: 2px solid var(--rs-color-focus, var(--rs-project-accent));
    outline-offset: 2px;
  }

  .rs-project-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    padding: 0 24px 8px;
    border-bottom: 1px solid var(--rs-project-border);
    background: var(--rs-project-surface);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12);
  }

  .rs-project-menu-toggle:checked ~ .rs-project-menu {
    display: block;
  }

  .rs-project-menu .rs-project-about,
  .rs-project-menu .rs-project-nav,
  .rs-project-menu .rs-project-utilities,
  .rs-project-menu .rs-project-links,
  .rs-project-menu .rs-project-account > .nav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    margin: 0;
    padding: 0;
  }

  /* One line per item. */
  .rs-project-menu .rs-project-about,
  .rs-project-menu .rs-project-links > li,
  .rs-project-menu .rs-project-links > mp-has-permission > li,
  .rs-project-menu .rs-project-utilities > .dropdown,
  .rs-project-menu .rs-project-account > .nav > li {
    padding: 12px 0;
    border-bottom: 1px solid var(--rs-project-border);
  }

  .rs-project-menu .rs-project-account > .nav > li:last-child {
    border-bottom: none;
  }

  /* Menus open in place, below their toggle, in one column. */
  .rs-project-header .rs-project-menu .dropdown {
    position: relative;
    width: 100%;
  }

  .rs-project-header .rs-project-menu .dropdown > .dropdown-menu {
    position: static;
    float: none;
    width: 100%;
    max-width: none;
    max-height: none;
    margin-top: 8px;
    border: none;
    box-shadow: none;
  }

  .rs-project-header .dropdown-grid-container {
    width: auto;
    max-width: 100%;
    grid-template-columns: 1fr;
  }

  .rs-project-menu .rs-project-account > .nav > li > a.rs-project-sign-in {
    display: inline-block;
  }
}

@media (max-width: 640px) {
  .rs-project-header__row,
  .rs-project-footer,
  .rs-project-menu {
    padding-left: 16px;
    padding-right: 16px;
  }
}
