/*
 * Layout: the app frame of the Pipelet apps, plain pages (login, errors, print), page header, grids.
 *
 * App frame (layout/app.html), no JavaScript:
 *   .app-header     sticky at the top (the only sticky bar; one row from 48em up): glass surface, backdrop
 *                   filter and accent bar (all theme tokens; none in neutral); the row holds the brand (logo +
 *                   "Edge OCPP" in the serif), the section links and the account menu
 *   .app-body       below the header; with a side menu (.app-body-sidenav) two columns: the side menu
 *                   (--pe-sidebar-width) and the content (up to --pe-content-max)
 *   .app-sidenav    the entries of the current section as a vertical list on --pe-surface-sidebar with a border
 *                   at its right; sticky below the header and scrolling on its own. The list lies in a
 *                   <details class="app-sidenav-menu">: wide, ::details-content is shown and the <summary>
 *                   hidden; below 48em the menu is a folded <details> above the content whose summary names the
 *                   current entry. A browser without ::details-content keeps the folded menu everywhere.
 *   .account-menu   a <details>: the button shows the person symbol only; the absolutely placed panel names
 *                   the account, has one row per setting (light/dark, language) and the actions below a line
 *                   (js/menu.js closes it on Escape and on a click or focus outside; it works without)
 *   .app-main       the content on the page surface of the theme (bronze gradient); without a side menu
 *                   (/account) centred at --pe-content-max
 * Plain pages (layout/base.html) get the same header with the brand only, then the centred card. In print
 * the chrome is hidden.
 *
 * Never a coloured accent border at the left (the active entry of the side menu is marked by its surface and
 * weight): the user's rule for Momentum Design Bronze, checked by test_css.py.
 *
 * The geometry is the same in every theme; a theme changes token values only. Only var(--…) from tokens.css;
 * lengths in media queries are the only literal lengths.
 */

/* ------------------------------------------------------------------ app frame */

/* the z-index keeps the open account menu above the side menu and the content */
.app-header {
  position: sticky;
  top: 0;
  z-index: var(--pe-z-header);
  background: var(--pe-surface-header);
  -webkit-backdrop-filter: var(--pe-header-backdrop);
  backdrop-filter: var(--pe-header-backdrop);
  border-bottom: var(--pe-border-width) solid var(--color-border-secondary);
}

.app-header::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  inset-block-start: 0;
  block-size: var(--pe-accent-bar-height);
  background: var(--pe-accent-bar);
  pointer-events: none;
}

/* the full width: the brand stands above the side menu, the account menu at the right edge */
.app-header-inner {
  display: flex;
  align-items: center;
  gap: var(--spacing-3xl);
  min-height: var(--pe-header-height);
  padding-inline: var(--spacing-3xl);
}

/* ------------------------------------------------------------------ brand */

.app-brand {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: var(--spacing-md);
  color: var(--color-text-primary);
  text-decoration: none;
}

.app-brand:hover {
  color: var(--color-text-primary);
}

.brand-logo {
  flex: none;
  width: var(--pe-logo-width);
  height: var(--pe-logo-height);
}

.app-brand-name {
  font-family: var(--font-family-serif);
  font-size: var(--text-lg);
  line-height: var(--leading-lg);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ section navigation (header) */

.app-nav ul {
  display: flex;
  gap: var(--spacing-xs);
  list-style: none;
  margin: 0;
  padding: 0;
}

.app-nav-link {
  display: inline-flex;
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  text-decoration: none;
  white-space: nowrap;
}

.app-nav-link:hover,
.app-nav-link.active {
  background: var(--color-bg-active);
  color: var(--color-text-primary);
}

.app-nav-link.active {
  font-weight: var(--font-weight-semibold);
}

/* ------------------------------------------------------------------ account menu */

/* The button shows the person symbol only (the name is its aria-label and title, and stands in the panel).
   The panel, from top to bottom: who is signed in (display name, below it login name and role), the two
   settings as one row each (label and a switch), then - below a line - the actions with their symbols. */

.user-menu {
  flex-shrink: 0;
  margin-inline-start: auto;
}

.account-menu {
  position: relative;
}

.account-menu > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--pe-control-height);
  height: var(--pe-control-height);
  border: var(--pe-border-width) solid var(--color-border-secondary);
  border-radius: var(--radius-full);
  color: var(--color-text-secondary);
  cursor: pointer;
  list-style: none;
}

.account-menu > summary::-webkit-details-marker {
  display: none;
}

.account-menu > summary:hover,
.account-menu[open] > summary {
  background: var(--color-bg-active);
  color: var(--color-text-primary);
}

/* never wider than the window: a long name is cut, a row that does not fit wraps */
.account-menu-panel {
  position: absolute;
  inset-inline-end: 0;
  inset-block-start: calc(100% + var(--spacing-sm));
  z-index: var(--pe-z-overlay);
  width: min(var(--pe-menu-width), calc(100vw - 2 * var(--spacing-xl)));
  padding-block: var(--spacing-xs);
  background: var(--color-bg-primary);
  border: var(--pe-border-width) solid var(--color-border-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
}

.account-menu .form {
  display: flex;
}

.account-menu-head {
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: var(--pe-border-width) solid var(--color-border-secondary);
  margin-bottom: var(--spacing-xs);
}

.account-menu-name,
.account-menu-meta {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-menu-name {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
}

.account-menu-meta {
  font-size: var(--text-xs);
  line-height: var(--leading-xs);
  color: var(--color-text-tertiary);
}

.account-menu-login {
  font-family: var(--font-family-mono);
}

.account-menu-setting {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-xs) var(--spacing-lg);
  padding: var(--spacing-xs) var(--spacing-lg);
}

.account-menu-label {
  color: var(--color-text-secondary);
}

/* a switch of a few values: the choices side by side in one frame, the current one on a raised surface, in
   the primary text colour and semibold (never by colour alone) */
.segmented {
  display: inline-flex;
  gap: var(--spacing-xxs);
  padding: var(--spacing-xxs);
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-md);
}

.segment {
  padding: var(--spacing-xxs) var(--spacing-md);
  border: var(--pe-border-width) solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font: inherit;
  color: var(--color-text-secondary);
  white-space: nowrap;
  cursor: pointer;
}

.segment:hover {
  color: var(--color-text-primary);
}

.segment[aria-current="true"] {
  background: var(--color-bg-primary);
  border-color: var(--color-border-primary);
  box-shadow: var(--shadow-xs);
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
}

.account-menu-divider {
  margin-block: var(--spacing-xs);
  border-top: var(--pe-border-width) solid var(--color-border-secondary);
}

.account-menu-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-lg);
  border: 0;
  background: transparent;
  font: inherit;
  color: var(--color-text-secondary);
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}

.account-menu-item:hover {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

/* ------------------------------------------------------------------ body: side menu and content */

.app-body-sidenav {
  display: grid;
  grid-template-columns: var(--pe-sidebar-width) minmax(0, 1fr);
  align-items: start;
}

/* sticky right below the header, as high as the rest of the window, scrolling on its own when long */
.app-sidenav {
  position: sticky;
  top: calc(var(--pe-header-height) + var(--pe-border-width));
  height: calc(100vh - var(--pe-header-height) - var(--pe-border-width));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--spacing-xl) var(--spacing-lg);
  background: var(--pe-surface-sidebar);
  border-inline-end: var(--pe-border-width) solid var(--color-border-secondary);
}

.app-sidenav-summary {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  min-height: var(--pe-control-height);
  padding: var(--spacing-md) var(--spacing-lg);
  border: var(--pe-border-width) solid var(--color-border-secondary);
  border-radius: var(--radius-md);
  background: var(--pe-surface-card);
  color: var(--color-text-primary);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  list-style: none;
}

.app-sidenav-summary::-webkit-details-marker {
  display: none;
}

.app-sidenav-summary:hover {
  background: var(--color-bg-active);
}

.app-sidenav-current {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-sidenav-chevron {
  margin-inline-start: auto;
  color: var(--color-text-tertiary);
  transition: transform var(--pe-duration-fast) var(--pe-easing-standard);
}

.app-sidenav-menu[open] .app-sidenav-chevron {
  transform: rotate(90deg);
}

.app-sidenav-title {
  margin: 0;
  padding: var(--spacing-xs) var(--spacing-lg) var(--spacing-md);
  font-size: var(--text-xs);
  line-height: var(--leading-xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--pe-letter-spacing-caps);
  text-transform: uppercase;
  color: var(--color-text-tertiary);
}

.app-sidenav-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xxs);
  list-style: none;
  margin: 0;
  padding: 0;
}

.app-sidenav-children {
  margin-block-start: var(--spacing-xxs);
  padding-inline-start: var(--spacing-lg);
}

/* no bar or border at the left of the active entry: its surface, colour and weight mark it */
.app-sidenav-link {
  display: block;
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  text-decoration: none;
}

.app-sidenav-link:hover {
  background: var(--pe-sidenav-hover-bg);
  color: var(--color-text-primary);
}

.app-sidenav-link.active {
  background: var(--pe-sidenav-active-bg);
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
}

.app-sidenav-link.ancestor {
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
}

/* wide: the list is always shown and the summary hidden; only where the browser knows ::details-content
   (else the folded menu stays, it works there as well) */
@supports selector(::details-content) {
  .app-sidenav-menu::details-content {
    display: block;
    content-visibility: visible;
  }

  .app-sidenav-summary {
    display: none;
  }
}

/* ------------------------------------------------------------------ main */

.app-main {
  max-width: var(--pe-content-max);
  margin-inline: auto;
  padding: var(--spacing-3xl) var(--spacing-3xl) var(--spacing-5xl);
}

/* next to the side menu the content starts at the menu (not centred in the rest of the window) */
.app-body-sidenav .app-main {
  margin-inline: 0;
  padding-inline: var(--spacing-4xl);
}

/* ------------------------------------------------------------------ page header and grids */

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-3xl);
}

.page-header h1 {
  margin: 0;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
}

.grid {
  display: grid;
  gap: var(--spacing-xl);
}

.grid-tiles {
  grid-template-columns: repeat(auto-fill, minmax(var(--pe-tile-min), 1fr));
}

.form-columns {
  display: grid;
  gap: var(--spacing-xl);
  grid-template-columns: repeat(auto-fit, minmax(var(--pe-tile-min), 1fr));
  align-items: start;
}

.form-grid {
  display: grid;
  gap: 0 var(--spacing-xl);
  grid-template-columns: repeat(auto-fit, minmax(var(--pe-tile-min), 1fr));
}

.narrow {
  max-width: var(--pe-narrow-max);
}

/* ------------------------------------------------------------------ plain pages (login, errors, print) */

.plain-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xl);
  padding: var(--spacing-5xl) var(--spacing-xl);
}

.plain-card {
  width: 100%;
  max-width: var(--pe-narrow-max);
  padding: var(--spacing-4xl) var(--spacing-3xl);
  background: var(--pe-surface-card);
  border: var(--pe-border-width) solid var(--color-border-secondary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}

.plain-card h1 {
  font-size: var(--text-xl);
  line-height: var(--leading-lg);
}

.plain-footer {
  display: flex;
  justify-content: center;
}

/* ------------------------------------------------------------------ narrow screens */

/* below 64em the header keeps its one row (the side menu sticks right below it): the section links shrink
   and scroll sideways if needed (the page itself never scrolls sideways) */
@media (max-width: 64em) {
  .app-header-inner {
    gap: var(--spacing-lg);
  }

  .app-nav {
    min-width: 0;
    overflow-x: auto;
  }

  /* room for the focus outline: a scrolling box clips everything outside it */
  .app-nav ul {
    padding: calc(var(--pe-focus-width) + var(--pe-focus-offset));
  }
}

@media (max-width: 48em) {
  /* the header scrolls away here: nothing to keep anchors clear of */
  html {
    scroll-padding-top: 0;
  }

  /* relative, not static: the header scrolls away, but keeps its z-index, so the open account menu stays
     above the side menu and everything after it */
  .app-header {
    position: relative;
  }

  /* brand and account menu in the first row, the section links in a row of their own */
  .app-header-inner {
    flex-wrap: wrap;
    gap: var(--spacing-md) var(--spacing-lg);
    padding: var(--spacing-md) var(--spacing-xl);
  }

  .app-nav {
    order: 3;
    flex-basis: 100%;
  }

  /* no column: the side menu is a folded menu above the content */
  .app-body-sidenav {
    display: block;
  }

  .app-sidenav {
    position: static;
    height: auto;
    overflow: visible;
    padding: var(--spacing-xl) var(--spacing-xl) 0;
    background: none;
    border-inline-end: 0;
  }

  .app-sidenav-summary {
    display: flex;
  }

  .app-sidenav-menu:not([open])::details-content {
    content-visibility: hidden;
  }

  .app-sidenav-menu[open] .app-sidenav-summary {
    margin-bottom: var(--spacing-xs);
  }

  .app-sidenav-title {
    display: none;
  }

  .app-main,
  .app-body-sidenav .app-main {
    padding: var(--spacing-xl) var(--spacing-xl) var(--spacing-4xl);
  }

  .app-brand-name {
    font-size: var(--text-md);
  }
}

/* ------------------------------------------------------------------ session warning */

.session-warning {
  position: fixed;
  inset-inline-end: var(--spacing-xl);
  inset-block-end: var(--spacing-xl);
  z-index: var(--pe-z-toast);
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
  max-width: var(--pe-narrow-max);
  padding: var(--spacing-lg) var(--spacing-xl);
  background: var(--color-bg-warning-subtle);
  color: var(--color-text-primary);
  border: var(--pe-border-width) solid var(--badge-warning-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.session-warning p {
  margin: 0;
}

/* ------------------------------------------------------------------ print */

@media print {
  .app-header,
  .app-sidenav,
  .skip-link,
  .plain-footer,
  .session-warning {
    display: none;
  }

  .app-body-sidenav {
    display: block;
  }

  .app-main,
  .app-body-sidenav .app-main,
  .plain-main {
    max-width: none;
    padding: 0;
  }

  .plain-card {
    max-width: none;
    padding: 0;
    border: 0;
    box-shadow: none;
  }
}
