/*
  Seitengerüst (E-51, templates/base.html, js/nav.js): Kopfzeile mit Menü-Knopf, Logo, Seitentitel, Kennzeichen
  „Testsystem“/„Demo“ und Konto; Hauptnavigation als Seitenleiste.
  - PC ab 80 rem: Leiste links neben dem Inhalt, einklappbar auf Symbole (html.sidebar-collapsed, js/nav-early.js).
  - Tablet und Handy: Leiste als Overlay von links (.sidebar.is-open), Hintergrund abgedunkelt.
  - Ohne JavaScript: Leiste als Liste über dem Inhalt (noscript-Stil in base.html).
  Ergänzt app.css; dort bleiben Farben, Maße und die Regeln für Gäste (.mainnav in der Kopfzeile).
*/

:root {
  --header-h: 3.5rem;
  --sidebar-w: 15rem;
  --sidebar-w-collapsed: 4.25rem;
}

html {
  scroll-padding-top: calc(var(--header-h) + var(--space-2));
}

html.menu-open {
  overflow: hidden; /* Hintergrund steht still, solange das Menü offen ist (nur senkrecht relevant) */
}

/* --- Kopfzeile ---------------------------------------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: var(--space-2);
  min-height: var(--header-h);
  padding: 0.375rem var(--space-3);
}

.menu-toggle,
.sidebar-close {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  min-height: var(--tap);
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
}

.menu-toggle:hover,
.sidebar-close:hover {
  color: inherit;
  background: rgb(0 0 0 / 0.18);
  border: 0;
}

.menu-icon {
  width: 1.5rem;
  height: 1.5rem;
}

.topbar .brand {
  flex: none;
}

.page-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Gäste: „Über“ und „Anmelden“ rechts in der Kopfzeile */
.topbar > .mainnav {
  flex: none;
}

.topbar > .mainnav ul {
  flex-wrap: nowrap;
}

/* Glocke der Benachrichtigungen (notifications/_bell.html) rechts vor dem Konto */
.header-actions {
  display: flex;
  flex: none;
  margin: 0;
  padding: 0;
  list-style: none;
}

.header-actions .nav-bell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 var(--space-2);
  border-radius: var(--radius);
  text-decoration: none;
}

.header-actions .nav-bell:hover {
  background: rgb(0 0 0 / 0.18);
}

.header-actions .nav-bell[aria-current="page"] {
  box-shadow: inset 0 -3px 0 currentColor;
}

.account-link {
  display: inline-flex;
  flex: 0 1 auto;
  align-items: center;
  gap: var(--space-2);
  min-width: var(--tap);
  max-width: 16rem;
  min-height: var(--tap);
  padding: 0 var(--space-2);
  border-radius: var(--radius);
  text-decoration: none;
}

.account-link:hover {
  background: rgb(0 0 0 / 0.18);
}

.account-link[aria-current="page"] .account-name {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.3em;
}

.account-icon {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
}

.account-name {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 47.99rem) {
  .topbar {
    gap: var(--space-1);
    padding: 0.375rem var(--space-2);
  }

  .page-title {
    font-size: 1rem;
  }

  .env-badge-label {
    padding: 0.2em 0.5em;
    font-size: 0.75rem;
  }

  .account-link {
    justify-content: center;
    padding: 0;
  }

  .header-actions .nav-bell {
    padding: 0 var(--space-1);
  }

  .account-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
}

/* Sehr schmal mit Kennzeichen: das Logo weicht dem Seitentitel (die Leiste nennt den Namen der Wehr) */
@media (max-width: 29.99rem) {
  .topbar:has(.env-badge) .brand {
    display: none;
  }
}

/* --- Kennzeichen „Testsystem“/„Demo“ mit kleinem Menü --------------------------------------------------------- */

.env-badge {
  flex: none;
  position: relative;
}

.env-badge > summary {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--space-1);
  list-style: none;
  cursor: pointer;
  border-radius: var(--radius);
}

.env-badge > summary::-webkit-details-marker {
  display: none;
}

.env-badge-label {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.2em 0.7em;
  color: #4a3500;
  background: #ffe08a;
  border: 1px solid #4a3500;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.env-badge-label::after {
  content: "";
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0.35em 0.3em 0 0.3em;
  border-color: currentColor transparent transparent transparent;
}

.env-badge[open] .env-badge-label::after {
  transform: rotate(180deg);
}

.env-panel {
  position: fixed;
  top: calc(var(--header-h) + var(--space-1));
  right: var(--space-3);
  z-index: 120;
  width: min(24rem, calc(100vw - 2 * var(--space-3)));
  padding: var(--space-3) var(--space-4);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 4px solid #e0b100;
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
  font-size: 0.9375rem;
}

.env-panel p {
  margin-bottom: var(--space-3);
}

.env-panel .testsystem-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
}

.env-panel .testsystem-actions .nav-button {
  justify-content: flex-start;
  width: 100%;
  color: var(--color-link);
  background: transparent;
  border: 2px solid currentColor;
  font-weight: 600;
  text-decoration: none;
}

.env-panel .testsystem-actions .nav-button:hover {
  color: var(--color-on-accent);
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}

/* --- Gerüst: Leiste und Seite nebeneinander ------------------------------------------------------------------- */

.layout {
  display: flex;
  flex: 1 0 auto;
  min-width: 0;
}

.page {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
}

.page > .content {
  flex: 1 0 auto;
}

/* --- Seitenleiste ------------------------------------------------------------------------------------------- */

.sidebar {
  color: var(--color-text);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: var(--header-h);
  padding: 0.375rem var(--space-2) 0.375rem var(--space-4);
  color: var(--color-header-text);
  background: var(--color-header-bg);
  font-weight: 700;
}

.sidebar-head :focus-visible {
  outline-color: var(--color-header-focus);
}

.sidebar .mainnav ul {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 2px;
  padding: var(--space-2);
}

.sidebar .mainnav li.nav-separator {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

.sidebar .mainnav a,
.sidebar .mainnav .nav-button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--tap);
  padding: 0 var(--space-3);
  color: var(--color-text);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 500;
  line-height: 1.25;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar .mainnav a:hover,
.sidebar .mainnav .nav-button:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

/* Aktueller Eintrag: Balken links, fett, Hintergrund – nicht nur Farbe */
.sidebar .mainnav a[aria-current="page"] {
  color: var(--color-link);
  background: var(--color-surface-2);
  box-shadow: inset 4px 0 0 var(--color-accent);
  font-weight: 700;
  text-decoration: none;
}

.nav-icon {
  flex: none;
  width: 1.375rem;
  height: 1.375rem;
}

/* PC: Leiste neben dem Inhalt, klebt unter der Kopfzeile */
@media (min-width: 80rem) {
  .sidebar {
    position: sticky;
    top: var(--header-h);
    flex: none;
    align-self: flex-start;
    width: var(--sidebar-w);
    height: calc(100vh - var(--header-h));
    overflow-x: hidden;
    overflow-y: auto;
  }

  .sidebar-head,
  .sidebar-backdrop {
    display: none !important;
  }

  .sidebar-collapsed .sidebar {
    width: var(--sidebar-w-collapsed);
  }

  /* Eingeklappt: nur Symbole; der Text bleibt im Link (Bildschirmleser), wird aber abgeschnitten */
  .sidebar-collapsed .sidebar .mainnav a,
  .sidebar-collapsed .sidebar .mainnav .nav-button {
    width: 3rem;
    gap: 2rem;
    padding: 0 calc((3rem - 1.375rem) / 2);
  }
}

/* Tablet und Handy: Leiste als Overlay von links */
@media (max-width: 79.99rem) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 200;
    width: min(20rem, 86vw);
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(-100%);
    visibility: hidden;
    box-shadow: 4px 0 24px rgb(0 0 0 / 0.3);
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }

  .sidebar.is-open {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgb(0 0 0 / 0.5);
  }

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

/* --- Druck: weder Leiste noch Kopfzeilen-Bedienung ----------------------------------------------------------- */

@media print {
  .sidebar,
  .sidebar-backdrop,
  .menu-toggle,
  .env-badge,
  .account-link {
    display: none !important;
  }

  .layout,
  .page {
    display: block;
  }
}
