/* Basis und Shell des EST Development Managers. Besitzer: S4.
   Inhalt: Reset, Typografie, Fokus, Shell (Seitenleiste, Kopfzeile, Handy-Navigation), Seitenkopf,
   Login, Hilfsklassen. Komponenten: components.css · Layout-Bausteine: layout.css.
   Alle Werte aus tokens.css. Klassen-Konvention: docs/ui-contract.md §4.
   Breakpoints: Handy < 768px · Tablet 768–1099px · Desktop ≥ 1100px. */

/* --- Reset ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--topbar-height) + var(--space-4));
}

body.est-body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--sans);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.est-body.has-overlay { overflow: hidden; }

h1, h2, h3, h4, p, ul, ol, dl, dd, figure, pre { margin: 0; }
ul, ol { padding: 0; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--navy); text-decoration-thickness: var(--hairline); text-underline-offset: var(--space-0); }
a:hover { color: var(--navy-3); }
[hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible { outline: var(--focus-ring); outline-offset: var(--focus-offset); }

::selection { background: var(--navy); color: var(--white); }

/* --- Hilfsklassen ------------------------------------------------------------- */
.u-hidden { display: none !important; }
.u-sr-only {
  position: absolute !important;
  width: var(--hairline);
  height: var(--hairline);
  margin: calc(var(--hairline) * -1);
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.u-muted { color: var(--muted); }
.u-mono { font-family: var(--mono); font-size: var(--fs-sm); }
.u-right { text-align: right; margin-left: auto; }
.u-nowrap { white-space: nowrap; }
.u-only-mobile { display: none !important; }

.est-skip-link {
  position: absolute;
  left: var(--space-4);
  top: var(--space-4);
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-btn);
  background: var(--white);
  color: var(--navy);
  box-shadow: var(--shadow-raised);
  transform: translateY(-200%);
}
.est-skip-link:focus { transform: none; }

.est-icon { flex-shrink: 0; }

/* --- Shell -------------------------------------------------------------------- */
.est-shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.est-sidebar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  /* Der untere Abstand gehört dem letzten Kind (Benutzer-Menü): So schließt das haftende Menü bündig ab. */
  padding: calc(var(--space-5) + var(--safe-top)) var(--space-4) 0;
  padding-left: calc(var(--space-4) + var(--safe-left));
  overflow-x: hidden;
  overflow-y: auto;
  /* Das Benutzer-Menü haftet am Fuß: Springt der Fokus per Tastatur auf einen Punkt, scrollt die Leiste ihn bis
     über das Menü – er liegt nie darunter (Fokus sichtbar, SPEC §10). */
  scroll-padding-bottom: var(--user-menu-height);
  /* Niedrige Fenster: Die Leiste scrollt; ein schmaler Balken nimmt Logo und Navigation kaum Breite weg. */
  scrollbar-width: thin;
  scrollbar-color: var(--navy-line) transparent;
  background: var(--navy);
  color: var(--on-navy);
}
.est-sidebar__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2); }
/* Logo (SPEC_IDEEN Ergänzung B). Ursache des „abgeschnittenen“ Logos: Der Rahmen ist ein Spalten-Flex, dessen
   Kinder sich auf die volle Breite strecken (align-items: stretch). Mit „height: 40px; width: auto“ wurde das
   Bild dadurch auf die Breite des Produktnamens gezogen (170 × 40 statt 92 × 40) – verzerrt und ohne Luft zum
   Rand. Jetzt: Kinder am Anfang ausgerichtet, die Breite ist festgelegt, die Höhe folgt dem Seitenverhältnis
   der Datei; nichts streckt, schrumpft oder beschneidet das Bild. */
.est-sidebar__brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-1) var(--space-2);
  color: var(--white);
  text-decoration: none;
  border-radius: var(--radius-btn);
}
.est-sidebar__logo,
.est-topbar__logo,
.est-login__logo {
  flex: none;
  align-self: flex-start;
  height: auto;
  max-width: 100%;
  object-fit: contain;
}
.est-sidebar__logo { width: var(--logo-width); }
.est-sidebar__product {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  letter-spacing: var(--eyebrow-spacing);
  text-transform: uppercase;
  color: var(--kicker-on-navy);
}
.est-sidebar__close {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  flex-shrink: 0;
  border: 0;
  border-radius: var(--radius-btn);
  background: none;
  color: var(--on-navy);
  cursor: pointer;
}
.est-sidebar__close:hover { background: var(--navy-hover); color: var(--white); }
.est-sidebar__cta { display: flex; }
.est-sidebar__cta .est-btn { flex: 1; }

/* Benutzer-Menü am Fuß der Seitenleiste bzw. in der Schublade (docs/ui-contract.md §8.3).
   Es haftet am unteren Rand der Leiste: Ist das Fenster niedriger als die Leiste (z. B. iPad im Querformat,
   kleiner Laptop), scrollt die Navigation darunter durch – „Abmelden“ bleibt ohne Scrollen erreichbar.
   Der untere Innenabstand der Leiste liegt deshalb im Menü. */
.est-user-menu {
  position: sticky;
  bottom: 0;
  z-index: var(--z-raised);
  margin-top: auto;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: var(--space-2);
  min-width: 0;
  padding-top: var(--space-4);
  padding-bottom: calc(var(--space-4) + var(--safe-bottom));
  border-top: var(--hairline) solid var(--navy-line);
  background: var(--navy);
}
.est-user-menu__account {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  min-height: var(--touch-min);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-btn);
  color: var(--on-navy);
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.est-user-menu__account:hover { background: var(--navy-hover); color: var(--white); }
.est-user-menu__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--avatar);
  height: var(--avatar);
  flex-shrink: 0;
  border: var(--hairline) solid var(--navy-line);
  border-radius: 50%;
  color: var(--white);
}
.est-user-menu__text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: var(--lh-snug); }
.est-user-menu__line { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.est-user-menu__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--white);
}
.est-user-menu__role {
  flex-shrink: 0;
  padding: 0 var(--space-1);
  border: var(--hairline) solid var(--navy-line);
  border-radius: var(--radius-sm);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-kind);
  color: var(--kicker-on-navy);
}
.est-user-menu__hint { font-size: var(--fs-xs); color: var(--on-navy-2); }
.est-sidebar__footer { display: flex; }
.est-sidebar__footer .est-btn { flex: 1; }

.est-nav { display: flex; flex-direction: column; gap: var(--space-1); }
/* Shell ohne Benutzer-Menü: Die Navigation ist das letzte Kind und trägt den unteren Abstand der Leiste. */
.est-sidebar > .est-nav:last-child { padding-bottom: calc(var(--space-4) + var(--safe-bottom)); }
.est-nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--touch-min);
  padding: 0 var(--space-3);
  border-radius: var(--radius-btn);
  color: var(--on-navy);
  font-weight: var(--fw-medium);
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.est-nav__item:hover { background: var(--navy-hover); color: var(--white); }
.est-nav__item.is-active { background: var(--white); color: var(--navy); }
.est-nav__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.est-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--badge-size);
  height: var(--badge-size);
  padding: 0 var(--space-1);
  border-radius: var(--radius-chip);
  background: var(--orange);
  color: var(--navy);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.est-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.est-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: calc(var(--topbar-height) + var(--safe-top));
  padding: var(--safe-top) calc(var(--space-6) + var(--safe-right)) 0 var(--space-6);
  background: var(--topbar-bg);
  -webkit-backdrop-filter: saturate(1.4) blur(var(--blur));
  backdrop-filter: saturate(1.4) blur(var(--blur));
  border-bottom: var(--hairline) solid var(--line);
}
.est-topbar__menu {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  margin-left: calc(var(--space-2) * -1);
  border: 0;
  border-radius: var(--radius-btn);
  background: none;
  color: var(--navy);
  cursor: pointer;
}
.est-topbar__menu:hover { background: var(--navy-tint); }
.est-topbar__brand { display: none; border-radius: var(--radius-sm); }
.est-topbar__logo { width: var(--logo-width-sm); align-self: center; }
.est-topbar__actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.est-topbar__limit { min-width: 0; }

.est-content {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  padding: var(--space-6) calc(var(--space-6) + var(--safe-right)) var(--space-8) var(--space-6);
}

.est-scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-scrim);
  background: var(--overlay);
  animation: est-fade var(--dur-mid) var(--ease);
}

.est-bottombar { display: none; }

/* --- Seitenkopf ----------------------------------------------------------------- */
.est-page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-5);
  margin-bottom: var(--space-6);
}
.est-page-head__text { min-width: 0; }
.est-page-head__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.est-eyebrow {
  margin-bottom: var(--space-2);
  font-size: var(--eyebrow-size);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
  letter-spacing: var(--eyebrow-spacing);
  text-transform: uppercase;
  color: var(--orange-text-page);
}
/* Auf weißen Flächen gilt die CD-Textfarbe --orange-text. */
.est-card .est-eyebrow,
.est-login .est-eyebrow,
.est-modal .est-eyebrow,
.est-sheet .est-eyebrow { color: var(--orange-text); }
.est-page-title {
  font-family: var(--serif);
  font-weight: var(--fw-regular);
  font-size: var(--title-size);
  line-height: var(--lh-tight);
  color: var(--navy);
  overflow-wrap: anywhere;
}

/* --- Login ---------------------------------------------------------------------- */
body.est-body--login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  padding: calc(var(--space-6) + var(--safe-top)) calc(var(--space-4) + var(--safe-right))
    calc(var(--space-6) + var(--safe-bottom)) calc(var(--space-4) + var(--safe-left));
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 55%, var(--navy-3) 100%);
}
.est-login__brand { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); max-width: 100%; }
.est-login__logo { width: var(--logo-width-login); align-self: center; }
.est-login__kicker {
  font-size: var(--eyebrow-size);
  font-weight: var(--fw-medium);
  letter-spacing: var(--eyebrow-spacing);
  text-transform: uppercase;
  color: var(--kicker-on-navy);
}
.est-login {
  width: min(var(--login-width), 100%);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-6);
  background: var(--white);
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-overlay);
}
.est-login__submit { width: 100%; }
.est-login__foot { font-size: var(--fs-sm); color: var(--on-navy-2); text-align: center; }

/* --- Bewegung --------------------------------------------------------------------- */
@keyframes est-fade { from { opacity: 0; } }
@keyframes est-rise { from { opacity: 0; transform: translateY(var(--space-3)); } }
@keyframes est-sheet-up { from { transform: translateY(100%); } }
@keyframes est-spin { to { transform: rotate(360deg); } }
@keyframes est-pulse { 50% { opacity: .45; } }

/* --- Tablet: schmale Seitenleiste (nur Icons) --------------------------------------- */
@media (min-width: 768px) and (max-width: 1099px) {
  /* Verdichtet: Mit acht Navigationspunkten und dem Benutzer-Menü bleibt die Leiste so kurz wie möglich. */
  .est-sidebar { width: calc(var(--sidebar-width-narrow) + var(--safe-left)); gap: var(--space-3); scroll-padding-bottom: var(--user-menu-height-rail); padding-top: calc(var(--space-4) + var(--safe-top)); padding-right: var(--space-2); padding-left: calc(var(--space-2) + var(--safe-left)); align-items: stretch; }
  /* Schmale Leiste: Das Logo füllt die ganze verfügbare Breite (Höhe folgt dem Seitenverhältnis) – ohne
     Innenabstand des Rahmens, damit es so groß wie möglich bleibt; der Produktname entfällt. */
  .est-sidebar__head { justify-content: center; }
  .est-sidebar__brand { flex: 1; min-height: var(--touch-min); padding: 0; align-items: center; justify-content: center; }
  .est-sidebar__logo { width: 100%; align-self: center; }
  .est-sidebar__product,
  .est-user-menu__text,
  .est-sidebar .est-btn__label {
    position: absolute;
    width: var(--hairline);
    height: var(--hairline);
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  /* Beschriftung klein unter dem Icon (wie in der Bottom-Bar): auf Touch-Geräten erscheint kein title-Tooltip. */
  .est-nav__item { flex-direction: column; justify-content: center; gap: var(--space-0); min-height: var(--rail-item); padding: var(--space-2) 0; }
  .est-nav__label { flex: none; max-width: 100%; font-size: var(--fs-2xs); line-height: var(--lh-snug); }
  .est-nav__item .est-badge { position: absolute; top: calc(var(--space-1) * -1); right: calc(var(--space-1) * -1); }
  .est-sidebar .est-btn { padding: 0; }
  .est-user-menu { align-items: stretch; gap: var(--space-1); padding-top: var(--space-3); }
  .est-user-menu__account { justify-content: center; padding: var(--space-1) 0; }
  .est-topbar { padding-left: var(--space-5); padding-right: calc(var(--space-5) + var(--safe-right)); }
  .est-content { padding: var(--space-5) calc(var(--space-5) + var(--safe-right)) var(--space-8) var(--space-5); }
}

/* Tablet im Querformat (z. B. iPad 1024 × 700): Die Punkte der Leiste rücken zusammen (weiter ≥ 44 px hoch),
   damit Navigation und Benutzer-Menü ohne Scrollen in die Fensterhöhe passen. */
@media (min-width: 768px) and (max-width: 1099px) and (max-height: 760px) {
  .est-nav { gap: var(--space-0); }
  .est-nav__item { min-height: calc(var(--touch-min) + var(--space-1)); padding: var(--space-1) 0; }
}

/* Breite Leiste in niedrigen Fenstern (z. B. Laptop 1366 × 768, innen rund 657 px hoch): Die Abstände rücken
   zusammen, und der Hauptknopf „Neues Projekt“ haftet über dem Benutzer-Menü – er ist ohne Scrollen sichtbar.
   Der frei gehaltene Streifen für fokussierte Punkte wächst um den Knopf samt seinem oberen Innenabstand. */
@media (min-width: 1100px) and (max-height: 760px) {
  .est-sidebar {
    gap: var(--space-3);
    padding-top: calc(var(--space-4) + var(--safe-top));
    scroll-padding-bottom: calc(var(--user-menu-height) + var(--touch-min) + var(--space-2));
  }
  .est-nav { gap: var(--space-0); }
  .est-sidebar__cta {
    position: sticky;
    bottom: var(--user-menu-height);
    z-index: var(--z-raised);
    flex-shrink: 0;
    padding-top: var(--space-2);
    background: var(--navy);
  }
}

/* --- Handy: Schublade + Bottom-Bar --------------------------------------------------- */
@media (max-width: 767px) {
  .u-only-mobile { display: revert !important; }
  .u-only-desktop { display: none !important; }

  /* Tastatur-Fokus: Scrollt die Seite zu einem fokussierten Element, bleibt der Streifen der festen Bottom-Bar
     frei – samt Aktions- bzw. Auswahl-Leiste, solange eine darüber liegt. Sonst läge der Fokus darunter. */
  html { scroll-padding-bottom: calc(var(--bottombar-height) + var(--safe-bottom) + var(--space-4)); }
  html:has(.est-actionbar),
  html:has(.est-selection-bar:not([hidden])) {
    scroll-padding-bottom: calc(var(--bottombar-height) + var(--safe-bottom) + var(--floatbar-height) + var(--space-4));
  }

  .est-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--z-drawer);
    width: min(var(--drawer-width), 86vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--dur-slow) var(--ease), visibility 0s linear var(--dur-slow);
    box-shadow: none;
  }
  /* Beim Öffnen wird nur die Verschiebung animiert: Die Leiste ist sofort sichtbar und damit fokussierbar. */
  .est-sidebar.is-open {
    transform: none;
    visibility: visible;
    transition: transform var(--dur-slow) var(--ease);
    box-shadow: var(--shadow-overlay);
  }
  /* Offene Schublade verhält sich wie ein Dialog: Der Hintergrund scrollt nicht mit. */
  body.est-body.has-nav-open { overflow: hidden; }
  .est-sidebar__close { display: inline-flex; }

  .est-topbar { gap: var(--space-2); padding-left: calc(var(--space-4) + var(--safe-left)); padding-right: calc(var(--space-4) + var(--safe-right)); }
  .est-topbar__menu { display: inline-flex; }
  .est-topbar__brand { display: flex; align-items: center; min-height: var(--touch-min); }
  .est-topbar__limit { margin-left: auto; }
  .est-topbar__actions { margin-left: 0; }
  .est-topbar__actions:empty { display: none; }

  .est-content {
    padding: var(--space-5) calc(var(--space-4) + var(--safe-right))
      calc(var(--bottombar-height) + var(--safe-bottom) + var(--space-6)) calc(var(--space-4) + var(--safe-left));
  }
  .est-body:has(.est-actionbar) .est-content {
    padding-bottom: calc(var(--bottombar-height) + var(--safe-bottom) + var(--touch-min) + var(--space-7));
  }

  .est-page-head { flex-direction: column; align-items: stretch; margin-bottom: var(--space-5); }
  .est-page-head__actions .est-btn { flex: 1 1 auto; }

  .est-bottombar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: var(--z-bottombar);
    display: flex;
    align-items: stretch;
    height: calc(var(--bottombar-height) + var(--safe-bottom));
    padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    background: var(--bottombar-bg);
    -webkit-backdrop-filter: saturate(1.4) blur(var(--blur));
    backdrop-filter: saturate(1.4) blur(var(--blur));
    border-top: var(--hairline) solid var(--line);
    box-shadow: var(--shadow-bar);
  }
  .est-bottombar__item {
    position: relative;
    flex: 1 1 auto;
    min-width: var(--touch-min);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-0);
    padding: 0 var(--space-1);
    border: 0;
    background: none;
    color: var(--muted);
    font-size: var(--fs-2xs);
    font-weight: var(--fw-medium);
    line-height: var(--lh-snug);
    text-decoration: none;
    cursor: pointer;
  }
  .est-bottombar__item::before {
    content: "";
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: var(--border-strong);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    background: transparent;
  }
  .est-bottombar__item.is-active { color: var(--navy); }
  .est-bottombar__item.is-active::before { background: var(--orange); }
  .est-bottombar__label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .est-bottombar__item .est-badge { position: absolute; top: var(--space-1); left: calc(50% + var(--space-2)); }

  .est-login { padding: var(--space-5); }
}

@media (min-width: 768px) {
  .est-scrim { display: none; }
}

/* Übergänge ganz abschalten statt nur verkürzen: Eine Dauer > 0 auf allen Elementen würde auch vererbte
   Eigenschaften (z. B. visibility der Schublade) kurz animieren – deren Inhalt wäre dann beim Öffnen noch
   nicht fokussierbar. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
