/* Custom components and layout bridges */

/* ZIQAVO brand lockup: vector mark + wordmark from public/images/brand (the sidebar is always dark,
   so it uses the -dark variants). */
.brand__mark {
  display: block;
  width: 2.5rem;
  height: 2.5rem;
  flex: none;
}

.user-chip__avatar {
  display: grid;
  width: 2.125rem;
  height: 2.125rem;
  color: light-dark(#44615c, #cfe3dd);
  background: light-dark(#e9efec, #24363c);
  border: 0;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  place-items: center;
}

/* One shared shell for public and authenticated routes. */

.app-body {
  --bs-primary-base: var(--color-brand);
  --bs-primary-bg: var(--color-brand);
  --bs-primary-fg: var(--color-brand-text);
  --bs-primary-bg-subtle: var(--color-brand-soft);
  --bs-primary-bg-muted: var(--color-brand-muted);
  --bs-primary-border: var(--color-brand-border);
  --bs-primary-contrast: var(--color-on-brand);
  --bs-primary-focus-ring: color-mix(in srgb, var(--color-brand) 35%, transparent);
  --bs-fg-body: light-dark(#172e38, #e5ecef);
  --bs-fg-2: light-dark(#6b7a83, #9fb0b7);
  --bs-border-color: light-dark(#e4eae7, #2a3b44);
  --bs-bg-body: var(--color-surface);

  /* Shared shape and depth scale, aligned with the SCORE prototype: restrained corners
     (5px controls, 9px surfaces), fine lines and very soft shadows. */
  --radius-sm: 0.3125rem;
  --radius-md: 0.4375rem;
  --radius-lg: 0.5625rem;
  --radius-xl: 0.75rem;
  --surface-border: light-dark(#e5e9e9, #26363f);
  --surface-shadow:
    0 1px 2px light-dark(rgb(23 46 56 / 3%), rgb(0 0 0 / 25%)),
    0 3px 15px light-dark(rgb(23 51 60 / 3%), rgb(0 0 0 / 25%));
  --surface-shadow-hover:
    0 2px 4px light-dark(rgb(23 46 56 / 5%), rgb(0 0 0 / 30%)),
    0 10px 24px light-dark(rgb(23 46 56 / 7%), rgb(0 0 0 / 40%));
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--color-brand) 28%, transparent);

  /* Typography scale of the prototype: medium-weight Manrope headings, compact UI text. */
  --bs-heading-font-weight: 500;
  --bs-font-size-3xl: clamp(1.75rem, 1.45rem + 0.9vw, 1.95rem);
  --bs-font-size-2xl: clamp(1.35rem, 1.2rem + 0.5vw, 1.5rem);
  --bs-font-size-xl: clamp(1.15rem, 1.05rem + 0.35vw, 1.25rem);
  --bs-font-size-lg: 1.0625rem;

  --bs-btn-input-min-height: 2.75rem;
  --bs-btn-input-padding-x: 1rem;
  --bs-btn-input-font-size: 0.9rem;
  --bs-btn-input-border-radius: 0.6rem;
  --bs-btn-input-sm-min-height: 2.125rem;
  --bs-btn-input-sm-padding-x: 0.75rem;
  --bs-btn-input-sm-font-size: 0.85rem;
  --bs-btn-input-sm-border-radius: var(--radius-sm);
  color: var(--bs-fg-body);
  background: var(--color-canvas);
}

.app-shell {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  min-height: 100dvh;
}

.app-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  align-self: start;
  padding: 1.95rem 0.95rem 1.15rem;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--color-sidebar-fg);
  background: var(--color-sidebar-bg);
  /* The sidebar stays dark in both themes; in dark mode a fine line separates it from the canvas. */
  border-right: 1px solid light-dark(transparent, #26363f);
  scrollbar-color: var(--color-sidebar-scrollbar) var(--color-sidebar-bg);
  scrollbar-width: thin;
}

.app-sidebar::-webkit-scrollbar {
  width: 0.6rem;
}

.app-sidebar::-webkit-scrollbar-track {
  background: var(--color-sidebar-bg);
}

.app-sidebar::-webkit-scrollbar-thumb {
  background: var(--color-sidebar-scrollbar);
  border: 2px solid var(--color-sidebar-bg);
  border-radius: 999px;
}

.app-sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--color-sidebar-accent);
}

/* The brand row spans the same height as the header (min-height 4.75rem, content centred), starting
   at the very top of the sidebar, so the logo lines up with the breadcrumb ("Übersicht"). */
.app-sidebar .brand {
  min-height: 4.75rem;
  margin-top: -1.95rem;
  color: #fff;
  align-self: center;
  justify-content: center;
}

/* Optional area behind the sidebar logo (ADR-0063 stage 2c): the layout adds `.brand--backdrop` only when
   the theme stylesheet defines `--color-sidebar-logo-backdrop`. The lockup (mark, wordmark or product
   name) gets the area, so the brand row keeps its height and alignment, also in the mobile offcanvas. */
.app-sidebar .brand--backdrop .brand__lockup {
  max-width: 100%;
  padding: 0.375rem 0.625rem;
  border-radius: var(--radius-lg);
  background: var(--color-sidebar-logo-backdrop, transparent);
  color: var(--color-sidebar-fg-strong);
}

/* Product-name text on the area: black or white, whichever reads better on the chosen colour (OKLCH
   lightness 0.62 ≈ the WCAG crossover; the admin preview uses the same rule). Without relative colour
   syntax the sidebar text colour stays. */
@supports (color: oklch(from red l c h)) {
  .app-sidebar .brand--backdrop .brand__lockup {
    color: oklch(from var(--color-sidebar-logo-backdrop, #000) clamp(0, (0.62 - l) * 1000, 1) 0 0);
  }
}

.app-sidebar .brand--backdrop .brand__name {
  color: inherit;
}

.app-sidebar .nav-link {
  position: relative;
  display: flex;
  min-height: 2.5rem;
  padding: 0.55rem 0.75rem;
  align-items: center;
  gap: 0.75rem;
  border-radius: 0.375rem;
  color: var(--color-sidebar-fg-soft);
  font-size: 0.875rem;
  font-weight: 450;
  line-height: 1.3;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease;
  text-decoration: none;
}

/* Long labels wrap instead of widening the sidebar column. */
.app-sidebar__navigation,
.app-nav-group,
.app-nav-module {
  grid-template-columns: minmax(0, 1fr);
}

.app-sidebar .nav-link,
.app-nav-module__title {
  white-space: normal;
}

/* Sections: small uppercase headings like the prototype, no separator lines. */
.app-nav-group {
  display: grid;
  gap: 0.125rem;
  margin-top: 1.1rem;
}

.app-nav-group__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  margin: 0 0 0.25rem;
  padding: 0.3rem 0.75rem;
  border-radius: 0.35rem;
  color: var(--color-sidebar-fg-subtle);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  list-style: none;
}

.app-nav-group__title::-webkit-details-marker,
.app-nav-module__title::-webkit-details-marker {
  display: none;
}

/* Drawn chevron: points down when open, right when collapsed. */
.app-nav-group__title::after,
.app-nav-module__title::after {
  content: "";
  flex: 0 0 auto;
  width: 0.4rem;
  height: 0.4rem;
  margin-left: auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  opacity: 0.7;
  transform: translateY(-0.1rem) rotate(45deg);
  transition: transform 160ms ease;
}

.app-nav-group:not([open]) > .app-nav-group__title::after,
.app-nav-module:not([open]) > .app-nav-module__title::after {
  transform: rotate(-45deg);
}

.app-nav-module {
  display: grid;
  gap: 0.125rem;
}

/* Modules with several entries: same look as a link, entries indented on a guide line. */
.app-nav-module__title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 2.5rem;
  cursor: pointer;
  margin: 0;
  padding: 0.55rem 0.75rem;
  border-radius: 0.375rem;
  color: var(--color-sidebar-fg-soft);
  font-size: 0.875rem;
  font-weight: 450;
  line-height: 1.3;
  list-style: none;
}

.app-nav-module__label {
  min-width: 0;
  overflow-wrap: break-word;
  hyphens: auto;
}

.app-nav-module__title--active {
  color: var(--color-sidebar-title-active);
}

.app-nav-module__title--active .app-nav-link__icon {
  color: var(--color-sidebar-accent);
}

.app-nav-group__title:hover,
.app-nav-module__title:hover {
  color: var(--color-sidebar-fg-hover);
  background: rgb(255 255 255 / 6%);
}

.app-nav-module:not(.app-nav-module--single) > .nav-link {
  min-height: 2.25rem;
  margin-left: 1.25rem;
  padding: 0.45rem 0.75rem;
  border-radius: 0 0.375rem 0.375rem 0;
  box-shadow: inset 1px 0 0 color-mix(in srgb, var(--color-sidebar-fg) 16%, transparent);
  font-size: 0.84rem;
}

.app-sidebar .app-nav-link__icon {
  display: inline-flex;
  width: 1.125rem;
  height: 1.125rem;
  flex: 0 0 1.125rem;
  color: var(--color-sidebar-fg-muted);
  transition: color 0.15s ease;
}

.app-sidebar .app-nav-link__icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.app-sidebar .nav-link > span:last-child {
  min-width: 0;
  overflow-wrap: break-word;
  hyphens: auto;
}

.app-sidebar .nav-link:hover .app-nav-link__icon,
.app-nav-module__title:hover .app-nav-link__icon {
  color: var(--color-sidebar-accent-soft);
}

.app-sidebar [hidden] {
  display: none !important;
}

/* Tenant tile with initials, as in the prototype. */
.app-sidebar__workspace {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.75rem;
  color: var(--color-sidebar-fg-strong);
  border: 1px solid var(--color-sidebar-line);
  border-radius: 0.5rem;
  background: rgb(255 255 255 / 3%);
  font-size: 0.85rem;
}

.app-sidebar__workspace-mark {
  display: inline-flex;
  flex: 0 0 2.25rem;
  width: 2.25rem;
  height: 2.25rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.4rem;
  color: var(--color-sidebar-mark-fg);
  background: var(--color-sidebar-mark-bg);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.app-sidebar__workspace-text {
  min-width: 0;
}

.app-sidebar__workspace-label {
  display: block;
  margin-bottom: 0.1rem;
  color: var(--color-sidebar-fg-subtle);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.app-sidebar__workspace-slug {
  display: block;
  color: var(--color-sidebar-fg-muted);
  font-size: 0.75rem;
}

.app-sidebar .nav-link:hover {
  color: var(--color-sidebar-fg-hover);
  background: rgb(255 255 255 / 6%);
}

/* Active entry: tinted surface plus accent bar on the left. */
.app-sidebar .nav-link[aria-current="page"] {
  color: var(--color-sidebar-fg-active);
  background: color-mix(in srgb, var(--color-sidebar-accent) 16%, transparent);
  box-shadow: inset 3px 0 0 var(--color-sidebar-accent);
}

.app-sidebar .nav-link[aria-current="page"] .app-nav-link__icon {
  color: var(--color-sidebar-accent);
}

.app-sidebar .nav-link:focus-visible,
.app-nav-group__title:focus-visible,
.app-nav-module__title:focus-visible {
  outline: 2px solid var(--color-sidebar-accent);
  outline-offset: 2px;
}

.app-main {
  min-width: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-main > main {
  flex: 1;
}

.app-header {
  min-height: 4.75rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--surface-border);
}

.app-header form {
  margin: 0;
}

.app-header__start {
  min-width: 0;
}

.app-header__start .breadcrumb {
  flex-wrap: wrap;
}

.app-header__end {
  flex-shrink: 0;
}

/* Header with a module's centre slot (e.g. the workspace bar): three columns so the slot sits in
   the middle; the controls column never gets narrower than its content, so a crowded header shifts
   the slot left instead of overlapping. Below 75rem the slot moves to its own row. */
.app-header--with-center {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(max-content, 1fr);
  grid-template-areas: "start center end";
}

.app-header--with-center .app-header__start {
  grid-area: start;
}

.app-header--with-center .app-header__end {
  grid-area: end;
  justify-self: end;
}

.app-header__center {
  grid-area: center;
  display: flex;
  justify-content: center;
  min-width: 0;
}

@media (max-width: 75rem) {
  .app-header--with-center {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "start end"
      "center center";
  }
}

.user-chip {
  color: var(--color-ink-soft);
}

.user-chip:hover {
  color: var(--color-ink);
}

/* Header user menu (Bootstrap 6 `menu`). The chip is the toggle; the panel opens below, right-aligned. */
.user-menu {
  position: relative;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.1875rem 0.5rem 0.1875rem 0.1875rem;
  font: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;
}

.user-chip:hover,
.user-chip.show {
  color: var(--color-ink);
  background: light-dark(#f2f5f4, #1d2b30);
  border-color: var(--bs-border-color-translucent);
}

.user-chip:focus-visible {
  outline: 2px solid var(--bs-focus-ring-color, currentcolor);
  outline-offset: 2px;
}

.user-chip__chevron {
  display: inline-flex;
  width: 0.875rem;
  height: 0.875rem;
  color: var(--color-muted);
  transition: transform 0.15s ease;
}

.user-chip__chevron svg {
  width: 100%;
  height: 100%;
}

.user-chip.show .user-chip__chevron {
  transform: rotate(180deg);
}

.user-menu__panel {
  --bs-menu-min-width: 15rem;
  --bs-menu-max-height: none;
  --bs-menu-padding-x: 0.375rem;
  --bs-menu-padding-y: 0.375rem;
  --bs-menu-item-padding-y: 0.4375rem;
  --bs-menu-font-size: 0.875rem;
  margin-top: 0.375rem;
}

.user-menu__identity {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.625rem 0.625rem;
}

.user-menu__avatar {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 0.9375rem;
}

.user-menu__identity-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-menu__name {
  overflow: hidden;
  font-weight: 600;
  color: var(--color-ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu__tenant {
  overflow: hidden;
  font-size: 0.75rem;
  color: var(--color-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu__item {
  justify-content: flex-start;
}

.user-menu__item .menu-item-icon {
  display: inline-flex;
  height: var(--bs-menu-icon-size);
  margin-top: 0.0625rem;
  color: var(--color-muted) !important;
}

.user-menu__item .menu-item-icon svg {
  width: 100%;
  height: 100%;
}

.user-menu__item:hover .menu-item-icon {
  color: var(--color-ink) !important;
}

.user-menu__logout {
  margin: 0;
}

.user-menu__item--logout:hover {
  color: var(--bs-danger-text, #b42318);
  background: color-mix(in oklch, var(--bs-danger, #d92d20) 10%, transparent);
}

.user-menu__item--logout:hover .menu-item-icon {
  color: inherit !important;
}

.app-header .btn-text {
  color: var(--color-muted);
  font-size: 0.825rem;
}

.user-chip__name {
  overflow: hidden;
  max-width: 14rem;
  font-size: 0.825rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Content uses the full width beside the sidebar; only extreme screens are capped so lines and
   tables stay scannable. Paragraph-like blocks limit their own measure (section headers, leads). */

.app-content {
  width: 100%;
  max-width: 120rem;
  margin: 0 auto;
  padding: clamp(1.25rem, 2.5vw, 2rem) clamp(1rem, 2.5vw, 2.25rem);
}

/* Pages wrap their content in `.container` (guideline pattern); inside the shell the host already
   limits width and padding, so Bootstrap's fixed container steps would only waste space. */

.app-content .container {
  max-width: none;
  padding-inline: 0;
}

.auth-surface {
  width: 100%;
  max-width: 42rem;
  margin: 1.5rem auto;
}

.app-sidebar[hidden] {
  display: none;
}

.app-body--sidebar-collapsed .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

/* The close button and the backdrop only exist for the drawer on narrow screens. */
.app-sidebar__close,
.app-sidebar-backdrop {
  display: none;
}

/* Narrow screens: the sidebar is a drawer that slides in from the left over the content and starts
   closed (app-shell.js); the content always uses the full width. */
@media (max-width: 52rem) {
  .app-shell,
  .app-body--sidebar-collapsed .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-sidebar {
    position: fixed;
    z-index: 1065;
    inset: 0 auto 0 0;
    width: min(18rem, 85vw);
    height: 100dvh;
    padding-top: 1.15rem;
    box-shadow: 0 0 2.5rem rgb(0 0 0 / 35%);
    animation: app-sidebar-in 160ms ease-out;
  }

  .app-sidebar .brand {
    padding-right: 2.75rem;
  }

  .app-sidebar__close {
    position: absolute;
    top: 0.85rem;
    right: 0.6rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    color: var(--color-sidebar-fg);
    font-size: 1.5rem;
    line-height: 1;
    background: transparent;
    border: 0;
    border-radius: 0.5rem;
  }

  .app-sidebar__close:hover,
  .app-sidebar__close:focus-visible {
    color: #fff;
    background: rgb(255 255 255 / 10%);
  }

  .app-sidebar-backdrop:not([hidden]) {
    position: fixed;
    z-index: 1060;
    inset: 0;
    display: block;
    background: rgb(10 22 28 / 55%);
  }

  /* No scrolling of the page behind the open drawer. */
  .app-body--sidebar-drawer {
    overflow: hidden;
  }

  /* Header on narrow screens: menu button and breadcrumb keep the first row to themselves; the
     controls (messages, theme, review mode, profile, sign-out) move to the second row and a module's
     centre slot (workspace bar) to the third. */
  .app-header,
  .app-header--with-center {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "start"
      "end"
      "center";
    gap: 0.6rem;
    padding: 0.75rem 1rem !important;
  }

  .app-header__start {
    grid-area: start;
  }

  .app-header__end,
  .app-header--with-center .app-header__end {
    grid-area: end;
    flex-wrap: wrap;
    justify-content: flex-end;
    justify-self: stretch;
    gap: 0.5rem 0.75rem !important;
    padding-top: 0.6rem;
    border-top: 1px solid var(--surface-border);
  }

  .app-header__center {
    justify-content: flex-start;
  }
}

@keyframes app-sidebar-in {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar {
    animation: none;
  }
}

/* Shared layout styles stay external to satisfy style-src self. */

.brand__wordmark {
  display: block;
  width: auto;
  height: 1.15rem;
  margin-top: 0.15rem;
}

/* Customer logos (ADR-0063 stage 2): raster images, kept inside the ZIQAVO lockup's box. */
.brand__mark--custom {
  object-fit: contain;
}

.brand__wordmark--custom {
  max-width: 11rem;
  height: 1.5rem;
  margin-top: 0;
  object-fit: contain;
}

/* Customer mark without wordmark: the product name stands next to it as text. */
.brand__name {
  max-width: 10rem;
  overflow: hidden;
  color: var(--color-sidebar-fg-strong);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Footer: branded wordmark centred, build info right. The footer follows the theme, so the light or
   dark wordmark is shown accordingly. */
.app-footer {
  display: grid;
  min-height: 3.5rem;
  font-size: 0.72rem;
  background: var(--color-surface);
  border-top-color: var(--surface-border) !important;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
}

.app-footer__start {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
  grid-column: 1;
  min-width: 0;
}

.app-footer__text,
.app-footer__link-list a {
  overflow-wrap: anywhere;
}

.app-footer__link-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.app-footer__link-list a {
  color: inherit;
}

.app-footer__brand {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  grid-column: 2;
  min-width: 0;
}

.app-footer__wordmark {
  display: block;
  width: auto;
  height: 0.85rem;
}

/* Customer logos: raster images, bounded so a wide wordmark cannot widen the footer. */
.app-footer__wordmark--custom {
  max-width: 9rem;
  height: 1rem;
  object-fit: contain;
}

.app-footer__mark {
  display: block;
  width: 1.1rem;
  height: 1.1rem;
  object-fit: contain;
}

.app-footer__name {
  overflow-wrap: anywhere;
  font-weight: 600;
}

.app-footer__wordmark--dark,
[data-bs-theme="dark"] .app-footer__wordmark--light {
  display: none;
}

[data-bs-theme="dark"] .app-footer__wordmark--dark {
  display: block;
}

.app-footer__end {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem 0.75rem;
  grid-column: 3;
  min-width: 0;
  text-align: right;
}

.app-footer__notice,
.app-footer__build {
  overflow-wrap: anywhere;
}

@media (max-width: 36rem) {
  .app-footer {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: 0.25rem;
  }

  .app-footer__start,
  .app-footer__brand,
  .app-footer__end {
    grid-column: 1;
    justify-content: center;
    justify-self: center;
    text-align: center;
  }
}

@media (max-width: 36rem) {
  /* Avatar and the profile link's aria-label remain; the name would push "Abmelden" off-screen. */

  .user-chip__name {
    display: none;
  }

  /* Phones: the breadcrumb has the first header row to itself (controls are in the second row), so
     the full trail stays visible and long titles wrap. */
  .app-header__start .breadcrumb-link,
  .app-header__start .breadcrumb-item {
    overflow-wrap: anywhere;
  }
}
