/* ======================================================================
   APP-SHELL-MODUL (shared) — 1Grain.Connect (flow.1grain.tech)
   Single Source of Truth: Shell-Layout + Sidebar-Styles leben HIER.

   Nutzung (in jeder internen Seite):
     <body class="app-shell">
       <div id="app-shell-root"></div>
       <main class="app-main" id="app-main" data-title="Kunde anlegen"> … </main>
       <script src="../assets/js/app-shell.js" data-shell-base="../"></script>

   Design-System: identisch zum internen Formular (Navy #253449 · Teal
   #4aa0a0 · Gold #EAB85E · Outfit/Nunito Sans). Operate-Mode: feste linke
   Sidebar statt Marketing-Navbar.

   Einheitensystem: rem (1rem = 16px), px nur für Border/Icon-/Bildmaße.
   Tokens mit Fallbacks: das Modul funktioniert auch ohne host-Stylesheet.
   ====================================================================== */

/* ===== 1. SHELL-TOKENS (Fallbacks für Host-unabhängige Nutzung) ===== */
:root {
  --app-sidebar-w: 17.5rem;                 /* 280px */
  --app-topbar-h: 4rem;                     /* 64px */
  --app-sidebar-top: #26364e;
  --app-sidebar-bottom: #1b2635;
  --app-sidebar-ink: rgba(255, 255, 255, 0.72);
  --app-sidebar-ink-soft: rgba(255, 255, 255, 0.44);
  --app-sidebar-line: rgba(255, 255, 255, 0.09);
  --app-active-bg: rgba(74, 160, 160, 0.18);
  --app-nav-muted: rgba(91, 103, 116, 0.9);
}

/* ===== 2. GRID / BODY ===== */
body.app-shell {
  display: grid;
  grid-template-columns: var(--app-sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  background: var(--light, #f6f6f6);
}
#app-shell-root { display: contents; }

/* ===== 3. SIDEBAR ===== */
.app-sidebar {
  grid-column: 1;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.25rem 0.875rem 1rem;          /* 20px 14px 16px */
  color: var(--white, #ffffff);
  background: linear-gradient(180deg, var(--app-sidebar-top) 0%, var(--app-sidebar-bottom) 100%);
  border-right: 1px solid rgba(0, 0, 0, 0.18);
  z-index: 60;
}
.app-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;                            /* 12px */
  padding: 0.25rem 0.5rem 1.25rem;         /* 4px 8px 20px */
  text-decoration: none;
  color: inherit;
}
.app-brand-logo {
  width: 2.25rem;                          /* 36px */
  height: 2.25rem;
  flex-shrink: 0;
}
.app-brand-text { display: flex; flex-direction: column; gap: 0.0625rem; min-width: 0; }
.app-brand-name {
  font-family: var(--font-head, 'Outfit', sans-serif);
  font-size: 1.3125rem;                    /* 21px */
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--white, #ffffff);
}
.app-brand-sub {
  font-family: var(--font-content, 'Nunito Sans', sans-serif);
  font-size: 0.6875rem;                    /* 11px */
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--app-sidebar-ink-soft);
}

/* ===== 4. SIDEBAR-NAVIGATION ===== */
.app-nav { display: flex; flex-direction: column; gap: 0.1875rem; } /* 3px */
.app-nav-label {
  padding: 0.5rem 0.75rem 0.375rem;        /* 8px 12px 6px */
  font-family: var(--font-content, 'Nunito Sans', sans-serif);
  font-size: 0.6875rem;                    /* 11px */
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--app-sidebar-ink-soft);
}
.app-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;                            /* 12px */
  padding: 0.6875rem 0.75rem;              /* 11px 12px */
  border-radius: 0.625rem;                 /* 10px */
  font-family: var(--font-content, 'Nunito Sans', sans-serif);
  font-size: 0.9375rem;                    /* 15px */
  font-weight: 600;
  line-height: 1.2;
  color: var(--app-sidebar-ink);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.app-nav-item:hover { background: rgba(255, 255, 255, 0.07); color: var(--white, #ffffff); }
.app-nav-item.is-active {
  background: var(--app-active-bg);
  color: var(--white, #ffffff);
}
.app-nav-item.is-active::before {
  content: '';
  position: absolute;
  left: -0.875rem;                         /* 14px — an den Sidebar-Rand */
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 1.25rem;                         /* 20px */
  border-radius: 0 3px 3px 0;
  background: var(--teal, #4aa0a0);
}
.app-nav-icon { width: 18px; height: 18px; flex-shrink: 0; } /* Icon-Maß in px */

.app-sidebar-foot {
  margin-top: auto;
  padding: 0.875rem 0.75rem 0.25rem;       /* 14px 12px 4px */
  border-top: 1px solid var(--app-sidebar-line);
  font-family: var(--font-content, 'Nunito Sans', sans-serif);
  font-size: 0.75rem;                      /* 12px */
  line-height: 1.5;
  color: var(--app-sidebar-ink-soft);
}

/* ===== 5. HAUPTSÄULE: TOPBAR + CONTENT ===== */
.app-main {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.75rem;                            /* 12px */
  height: var(--app-topbar-h);
  padding: 0 1.5rem;                       /* 24px */
  background: rgba(255, 255, 255, 0.82);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border, #e3e7ec);
}
.app-topbar-title {
  font-family: var(--font-head, 'Outfit', sans-serif);
  font-size: 1.125rem;                     /* 18px */
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--navy, #253449);
  margin: 0;
}
/* Inhalte erst nach bestätigter Session einblenden (kein Flash). */
body.app-shell:not(.app-authed) .app-main { visibility: hidden; }
.app-topbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;                            /* 12px */
  margin-left: auto;
}
.app-user-email {
  font-size: 0.8125rem;                    /* 13px */
  color: var(--ink-soft, #64748b);
  max-width: 14rem;                        /* 224px */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-logout {
  font: inherit;
  font-size: 0.8125rem;                    /* 13px */
  font-weight: 600;
  color: var(--navy, #253449);
  background: transparent;
  border: 1px solid var(--border, #e3e7ec);
  border-radius: 0.625rem;                 /* 10px */
  padding: 0.375rem 0.75rem;               /* 6px 12px */
  cursor: pointer;
}
.app-logout:hover { background: rgba(37, 52, 73, 0.06); }
@media (max-width: 30em) { .app-user-email { display: none; } }
.app-content { flex: 1; min-width: 0; padding: 2.5rem 1.5rem 3.75rem; } /* 40px 24px 60px */

/* ===== 6. BURGER + OVERLAY (mobil) ===== */
.app-burger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.5rem;                           /* 40px */
  height: 2.5rem;
  margin-left: -0.5rem;                    /* 40px Trefferfläche, optisch bündig */
  padding: 0;
  color: var(--navy, #253449);
  background: transparent;
  border: none;
  border-radius: 0.625rem;                 /* 10px */
  cursor: pointer;
}
.app-burger:hover { background: rgba(37, 52, 73, 0.07); }
.app-burger-icon { width: 22px; height: 22px; } /* Icon-Maß in px */
.app-burger-icon--close { display: none; }
body.app-nav-open .app-burger-icon--open { display: none; }
body.app-nav-open .app-burger-icon--close { display: block; }
.app-overlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(15, 19, 23, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}
body.app-nav-open .app-overlay { opacity: 1; visibility: visible; }

/* ===== 7. RESPONSIVE (mobil: Sidebar als Off-Canvas) ===== */
@media (max-width: 47.9375em) { /* 767px */
  body.app-shell { grid-template-columns: minmax(0, 1fr); }
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--app-sidebar-w);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.28);
  }
  body.app-nav-open .app-sidebar { transform: translateX(0); }
  body.app-nav-open { overflow: hidden; }
  .app-main { grid-column: 1; }
  .app-burger { display: inline-flex; }
  .app-topbar { padding: 0 1rem; }         /* 16px */
  .app-content { padding: 1.75rem 1rem 3rem; } /* 28px 16px 48px */
}

/* ===== 8. MOTION-PREFERENZ ===== */
@media (prefers-reduced-motion: reduce) {
  .app-sidebar { transition: none; }
  .app-overlay { transition: none; }
}
