/* =====================================================================
   Backend-Gerüst: feste Seitenleiste links, schwebende Kopfleiste rechts.
   Setzt base.css voraus.
   ===================================================================== */

.app { min-height: 100vh; }

/* --- Seitenleiste --------------------------------------------------------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 60;
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: var(--surface);
  box-shadow: var(--shadow-menu);
  transition: width .2s ease, transform .2s ease;
}

.sidebar-brand {
  display: flex; align-items: center; gap: .75rem;
  padding: 1.1rem 1.5rem 1rem;
  color: var(--text); text-decoration: none;
  white-space: nowrap; overflow: hidden;
}
.sidebar-brand:hover { color: var(--text); }
.brand-mark {
  flex: 0 0 auto;
  display: grid; place-items: center; width: 2rem; height: 2rem;
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--radius); font-size: .75rem; font-weight: 700;
  letter-spacing: .02em; box-shadow: var(--accent-shadow);
}
.brand-name { font-size: 1.15rem; font-weight: 700; letter-spacing: -.02em; }

.sidebar-toggle {
  margin-left: auto; flex: 0 0 auto;
  width: 1.75rem; height: 1.75rem; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--text-muted);
  border-radius: 50%; cursor: pointer;
}
.sidebar-toggle:hover { background: var(--accent-soft); color: var(--accent); }

.sidebar-nav {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: .25rem 0 1.5rem;
}
.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.nav-section {
  display: block; margin: 1.1rem 0 .35rem; padding: 0 1.5rem;
  font-size: .8125rem; color: var(--text-muted); position: relative;
  white-space: nowrap; overflow: hidden;
}
.nav-section::before {
  content: ""; position: absolute; left: 1rem; top: 50%; width: .35rem;
  height: 1px; background: var(--border-strong); opacity: 0;
}

.nav-link {
  display: flex; align-items: center; gap: .5rem;
  margin: .125rem .75rem; padding: .5rem .75rem;
  border-radius: var(--radius);
  color: var(--text); text-decoration: none;
  font-size: .9375rem; line-height: 1.4;
  white-space: nowrap; overflow: hidden;
  transition: background-color .15s ease, color .15s ease;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active {
  background: var(--accent-grad);
  color: var(--accent-ink);
  box-shadow: var(--accent-shadow);
}
.nav-link.active .nav-icon { color: var(--accent-ink); }

.nav-icon { flex: 0 0 1.375rem; width: 1.375rem; height: 1.375rem; color: var(--text-muted); }
.nav-link:hover .nav-icon { color: var(--text); }
.nav-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* --- Unternavigation ------------------------------------------------------ */
.nav-parent {
  width: calc(100% - 1.5rem);
  font: inherit; font-size: .9375rem; text-align: left;
  border: 0; cursor: pointer;
}
.nav-parent.is-current { color: var(--text); background: var(--surface-2); }

.nav-caret {
  flex: 0 0 1rem; width: 1rem; height: 1rem;
  color: var(--text-faint); transition: transform .2s ease;
}
.nav-group.is-open > .nav-parent .nav-caret { transform: rotate(90deg); }

/* Zusammenklappen über max-height statt grid-template-rows: Letzteres würde
   nur die erste Zeile bemaßen, die weiteren <li> landen in impliziten
   auto-Zeilen und bleiben stehen. Der Höchstwert ist großzügig gewählt und
   dient nur der Überblendung. */
.nav-sub {
  list-style: none; margin: 0; padding: 0;
  overflow: hidden;
  max-height: 0;
  transition: max-height .2s ease;
}
.nav-group.is-open > .nav-sub { max-height: 32rem; }
.nav-sub > li:first-child { padding-top: .125rem; }
.nav-sub > li:last-child  { padding-bottom: .25rem; }

.nav-sublink {
  display: flex; align-items: center; gap: .5rem;
  margin: .0625rem .75rem .0625rem 2.35rem;
  padding: .4rem .75rem;
  border-radius: var(--radius);
  color: var(--text-body); text-decoration: none;
  font-size: .875rem; white-space: nowrap; overflow: hidden;
  transition: background-color .15s ease, color .15s ease;
}
.nav-sublink:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-sublink.active {
  background: var(--accent-grad); color: var(--accent-ink);
  box-shadow: var(--accent-shadow);
}
.nav-dot {
  flex: 0 0 .3rem; width: .3rem; height: .3rem; border-radius: 50%;
  background: currentColor; opacity: .45;
}
.nav-sublink.active .nav-dot { opacity: 1; }

/* Eingeklappt bleibt nur das Symbol - die Unterpunkte erscheinen, sobald die
   Leiste beim Überfahren wieder ausfährt. */
.app.is-collapsed .sidebar:not(:hover) .nav-sub { max-height: 0; }
.app.is-collapsed .sidebar:not(:hover) .nav-caret { opacity: 0; }

.sidebar-foot {
  padding: .75rem 1.5rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: .75rem; color: var(--text-faint);
  white-space: nowrap; overflow: hidden;
}

/* --- eingeklappt (nur Symbole) --------------------------------------------- */
.app.is-collapsed .sidebar { width: var(--sidebar-sm); }
.app.is-collapsed .sidebar .brand-name,
.app.is-collapsed .sidebar .nav-text,
.app.is-collapsed .sidebar .sidebar-foot,
.app.is-collapsed .sidebar .nav-section { opacity: 0; pointer-events: none; }
.app.is-collapsed .sidebar .nav-section { height: 1.25rem; margin: .75rem 0 .25rem; }
.app.is-collapsed .sidebar-brand { padding-inline: 1.4rem; }
.app.is-collapsed .sidebar-toggle { display: none; }
.app.is-collapsed .nav-link { margin-inline: .875rem; padding-inline: .6rem; }
.app.is-collapsed .content { margin-left: var(--sidebar-sm); }
.app.is-collapsed .sidebar:hover { width: var(--sidebar-w); box-shadow: var(--shadow-lg); }
.app.is-collapsed .sidebar:hover .brand-name,
.app.is-collapsed .sidebar:hover .nav-text,
.app.is-collapsed .sidebar:hover .sidebar-foot,
.app.is-collapsed .sidebar:hover .nav-section { opacity: 1; pointer-events: auto; }

/* --- Inhaltsbereich --------------------------------------------------------- */
.content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
  transition: margin-left .2s ease;
}

.navbar {
  position: sticky; top: 1rem; z-index: 40;
  margin: 1rem 1.5rem 0;
  display: flex; align-items: center; gap: .75rem;
  height: 3.5rem; padding: 0 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-menu);
}
.navbar-burger {
  display: none;
  width: 2.25rem; height: 2.25rem; place-items: center;
  border: 0; background: transparent; color: var(--text-body);
  border-radius: 50%; cursor: pointer;
}
.navbar-burger:hover { background: var(--accent-soft); color: var(--accent); }
.navbar-title { font-size: 1rem; font-weight: 500; color: var(--text); }
.navbar-spacer { flex: 1; }

.navbar select {
  width: auto; min-width: 9rem; padding: .3rem 2rem .3rem .75rem;
  font-size: .8125rem; border-radius: var(--radius);
}

.user-chip {
  display: flex; align-items: center; gap: .6rem;
  padding: .25rem .5rem .25rem .25rem; border-radius: 999px;
  color: var(--text); text-decoration: none;
}
.user-chip:hover { background: var(--surface-2); color: var(--text); }
.user-avatar {
  flex: 0 0 auto; display: grid; place-items: center;
  width: 2.125rem; height: 2.125rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: .8125rem; font-weight: 600;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: .875rem; font-weight: 500; }
.user-meta small { font-size: .75rem; color: var(--text-muted); }
@media (max-width: 780px) { .user-meta { display: none; } }

.page { flex: 1; padding: 1.5rem; max-width: 100%; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem;
}
.page-head h1 { margin-bottom: .2rem; }
.page-head .subtitle { margin: 0; }

.footer { padding: 0 1.5rem 1.5rem; color: var(--text-faint); font-size: .8125rem; }

/* --- kleine Bildschirme: Schublade ------------------------------------------- */
.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(47, 43, 61, .5); backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s ease;
}

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .content { margin-left: 0; }
  .navbar-burger { display: grid; }
  .app.is-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .app.is-open .sidebar-backdrop { opacity: 1; visibility: visible; }
  .app.is-collapsed .sidebar { width: var(--sidebar-w); }
  .app.is-collapsed .content { margin-left: 0; }
  .sidebar-toggle { display: none; }
}

@media (max-width: 640px) {
  .page, .navbar { margin-inline: 0; }
  .navbar { margin: .75rem; }
  .page { padding: .75rem; }
  .footer { padding: 0 .75rem 1rem; }
  .table-wrap { margin: 0 -1.5rem; }
}

/* --- geteilte Ansicht mit Baum ------------------------------------------------ */
.split { display: grid; grid-template-columns: 21rem minmax(0, 1fr); gap: 1.5rem; align-items: start; }
@media (max-width: 1200px) { .split { grid-template-columns: 1fr; } }

.tree-panel { position: sticky; top: 5.75rem; max-height: calc(100vh - 7.5rem); overflow-y: auto; }

/* --- Baum ---------------------------------------------------------------------- */
.tree { --indent: 1.1rem; }
.tree ul { list-style: none; margin: 0; padding: 0 0 0 var(--indent); }
.tree > ul { padding-left: 0; }
.tree li { position: relative; margin: 1px 0; }
.tree ul ul::before {
  content: ""; position: absolute; left: calc(var(--indent) * -1 + .55rem);
  top: 0; bottom: 0; width: 1px; background: var(--border);
}

.tree-row {
  display: flex; align-items: center; gap: .35rem;
  padding: .35rem .5rem; border-radius: var(--radius);
  color: var(--text-body); font-size: .9375rem;
}
.tree-row:hover { background: var(--surface-2); }
.tree-row.is-active { background: var(--accent-grad); box-shadow: var(--accent-shadow); }
.tree-row.is-active .tree-name,
.tree-row.is-active .tree-icon,
.tree-row.is-active .tree-toggle { color: var(--accent-ink); }
.tree-row.is-active .tree-count {
  background: rgba(255, 255, 255, .25); color: var(--accent-ink); border-color: transparent;
}
.tree-row.is-disabled .tree-name { opacity: .55; text-decoration: line-through; }

.tree-toggle {
  flex: 0 0 1.05rem; width: 1.05rem; height: 1.05rem; padding: 0;
  border: 0; background: none; color: var(--text-faint);
  cursor: pointer; font-size: .55rem; line-height: 1;
  display: grid; place-items: center;
}
.tree-toggle:hover { color: var(--text); }
.tree-toggle[hidden] { visibility: hidden; display: grid; }

.tree-icon { flex: 0 0 auto; font-size: .8rem; opacity: .85; }
.tree-name {
  flex: 1; min-width: 0; color: inherit; text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree-name:hover { color: inherit; }
.tree-count {
  flex: 0 0 auto; min-width: 1.5rem; text-align: center;
  background: var(--surface-3); color: var(--text-muted);
  border: 0; border-radius: 999px;
  font-size: .6875rem; line-height: 1.25rem; padding: 0 .4rem;
}
.tree li.collapsed > ul { display: none; }

/* --- Kleinteile ------------------------------------------------------------------ */
.token-list { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .6rem; }
.token-list code { font-size: .75rem; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1.25rem; }
.kv dt {
  font-size: .75rem; font-weight: 500; text-transform: uppercase;
  letter-spacing: var(--tracking-wide); color: var(--text-muted); margin-bottom: .15rem;
}
.kv dd { margin: 0; font-size: .9375rem; color: var(--text-body); }

.section-links { display: flex; gap: .5rem; flex-wrap: wrap; }

/* --- Anmeldeseite ------------------------------------------------------------------ */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: var(--bg); }
.login-card { width: min(26rem, 100%); }
.login-card .panel { padding: 2rem; box-shadow: var(--shadow-lg); margin: 0; }
.login-card .brand-mark { width: 2.5rem; height: 2.5rem; font-size: .875rem; margin-bottom: 1.25rem; }
.login-card h1 { font-size: 1.375rem; font-weight: 600; }
.login-card .field { margin-bottom: 1rem; }
.login-foot {
  margin-top: 1.25rem; display: flex; justify-content: space-between;
  align-items: center; color: var(--text-faint); font-size: .75rem;
}

/* --- Newsletter-Baukasten (Hülle; .gjs-*-Regeln stehen in editor.css) ---------------- */
.editor-shell { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.editor-source textarea { min-height: 22rem; }
.editor-bar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }
.token-chip {
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-muted); border-radius: 999px;
  padding: .15rem .6rem; font-family: var(--font-mono); font-size: .75rem; cursor: pointer;
}
.token-chip:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }

/* --- Einrichtung der Zwei-Faktor-Anmeldung ---------------------------------- */
.qr-einrichtung { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1.75rem; align-items: start; }
@media (max-width: 640px) { .qr-einrichtung { grid-template-columns: 1fr; } }

/* Der Code braucht dunkel auf hell, auch im dunklen Erscheinungsbild - ein
   Lesegerät erwartet es so. Deshalb bleibt die Fläche immer weiß. */
.qr-bild {
  background: #fff; padding: .75rem; border-radius: var(--radius);
  border: 1px solid var(--border); line-height: 0;
  box-shadow: var(--shadow-sm);
}
.qr-bild svg { display: block; width: 12.5rem; height: auto; }
/* Zweiter Schritt der Anmeldung: das Konto steht fest, gefragt ist nur der Code. */
.login-konto {
  margin: 0 0 1.25rem; padding: .6rem .875rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text-body); font-size: .875rem;
}
.link-btn {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; color: var(--accent); text-decoration: none;
}
.link-btn:hover { color: var(--accent-hover); text-decoration: underline; }
/* --- Hilfe ------------------------------------------------------------------
   Die Schublade fährt von rechts ein und legt sich über den Inhalt. Bewusst
   kein eigenes Fenster: man soll nachschlagen können, ohne die Seite zu
   verlieren, auf der man gerade steht. */
.help-open {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; flex: 0 0 auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text-muted); cursor: pointer;
}
.help-open:hover { color: var(--accent); border-color: var(--accent); }

.help-badge {
  position: absolute; top: -.35rem; right: -.35rem;
  min-width: 1.05rem; height: 1.05rem; padding: 0 .2rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--err); color: #fff;
  font-size: .625rem; font-weight: 700; line-height: 1;
}

.help-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 20, 34, .5);
}

.help-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 61;
  width: min(30rem, 100vw);
  display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -18px 0 48px rgba(15, 20, 34, .28);
}
.help-drawer[hidden], .help-backdrop[hidden] { display: none; }

.help-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.help-head h2 { margin: 0; font-size: 1.0625rem; }
.help-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text-muted); cursor: pointer;
}
.help-close:hover { background: var(--surface-2); color: var(--text); }

.help-search { padding: .9rem 1.25rem; border-bottom: 1px solid var(--border); }
.help-search input { width: 100%; }

.help-body { flex: 1; overflow-y: auto; padding: .5rem 1.25rem 2rem; }

.help-section { margin-top: 1.25rem; }
.help-section[hidden] { display: none; }
.help-section h3 {
  margin: 0 0 .5rem; font-size: .6875rem; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; color: var(--text-faint);
}

.help-article {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); margin-bottom: .5rem;
}
.help-article[hidden] { display: none; }
.help-article > summary {
  display: block; cursor: pointer; padding: .7rem .875rem;
  list-style: none;
}
.help-article > summary::-webkit-details-marker { display: none; }
.help-article > summary:hover .help-article-title { color: var(--accent); }
.help-article[open] { background: var(--surface); border-color: var(--accent); }

.help-article-title { display: block; font-size: .875rem; font-weight: 600; color: var(--text); }
.help-article-teaser { display: block; margin-top: .15rem; font-size: .75rem; color: var(--text-muted); }

.help-article-body { padding: 0 .875rem .875rem; font-size: .8125rem; line-height: 1.6; color: var(--text-body); }

.help-figure {
  margin: 0 0 .9rem; padding: .75rem; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border);
}
.help-figure svg { display: block; width: 100%; height: auto; }

.help-steps { margin: 0 0 .75rem; padding-left: 1.15rem; }
.help-steps li { margin-bottom: .4rem; }

.help-notes { margin: 0; padding: 0; list-style: none; }
.help-notes li {
  position: relative; margin-bottom: .4rem; padding-left: .95rem;
  color: var(--text-muted);
}
.help-notes li::before {
  content: ''; position: absolute; left: 0; top: .55em;
  width: .3rem; height: .3rem; border-radius: 999px; background: var(--accent);
}
.help-article-body code {
  padding: .05rem .3rem; border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: .9em;
}
.help-empty { padding: 1.5rem .25rem; color: var(--text-muted); font-size: .8125rem; }

/* Farben der Zeichnungen: folgen dem Erscheinungsbild statt fester Werte. */
.help-figure .hf-flaeche    { fill: var(--surface); stroke: var(--border); }
.help-figure .hf-ton        { fill: var(--surface-2); }
.help-figure .hf-rahmen     { fill: none; stroke: var(--border); }
.help-figure .hf-linie      { fill: var(--border); }
.help-figure .hf-linie-voll { fill: none; stroke: var(--border); stroke-width: 1.4; }
.help-figure .hf-stark      { fill: var(--text-faint); }
.help-figure .hf-akzent     { fill: var(--accent); }
.help-figure .hf-akzent-weich { fill: var(--accent); fill-opacity: .16; stroke: var(--accent); stroke-opacity: .5; }
.help-figure .hf-strich     { stroke: var(--text-faint); }
.help-figure .hf-qr         { fill: #fff; stroke: var(--border); }
.help-figure .hf-qr-punkt   { fill: #12233b; }
.help-figure text           { font-family: inherit; }
.help-figure .hf-text       { fill: #fff; font-size: 11px; font-weight: 600; }
.help-figure .hf-klein      { fill: var(--text-body); font-size: 10px; }
.help-figure .hf-mini       { fill: var(--text-muted); font-size: 8.5px; }
.help-figure .hf-num        { fill: var(--accent); font-size: 12px; font-weight: 700; }
.help-figure .hf-num-hell   { fill: #fff; font-size: 12px; font-weight: 700; }
.help-figure .hf-mono       { fill: var(--text-body); font-size: 10px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.help-figure .hf-mono-mini  { fill: var(--text-muted); font-size: 7.5px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.help-figure .hf-code       { fill: var(--text); font-size: 12px; font-weight: 700; letter-spacing: .06em; }

/* --- Hinweise zur Einrichtung ------------------------------------------------ */
.setup-hint {
  display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap;
  padding: .8rem 1rem; margin-bottom: .75rem;
  border: 1px solid var(--border); border-left-width: 3px;
  border-radius: var(--radius); background: var(--surface);
  font-size: .8125rem; line-height: 1.55;
}
.setup-hint .setup-text { flex: 1 1 20rem; }
.setup-hint .setup-text strong { display: block; color: var(--text); }
.setup-hint .setup-text span { color: var(--text-muted); }
.setup-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

.setup-error { border-left-color: var(--err); }
.setup-error .setup-text strong { color: var(--err); }
.setup-info  { border-left-color: var(--accent); }

.setup-dismiss {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.6rem; height: 1.6rem; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text-faint); cursor: pointer;
}
.setup-dismiss:hover { background: var(--surface-2); color: var(--text); }

@media (max-width: 640px) {
  .help-drawer { width: 100vw; }
}
