/* Shell V3 — sidebar + topbar + bottom-nav + drawer */

.tb-shell-v3 {
  --tb-bottom-nav-content-height: 58px;
  --tb-bottom-nav-total-height: calc(
    var(--tb-bottom-nav-content-height) + env(safe-area-inset-bottom, 0px)
  );
  background:
    radial-gradient(circle at 85% -10%,
      color-mix(in srgb, var(--tb-color-accent) 9%, transparent),
      transparent 40%),
    radial-gradient(circle at -10% 110%,
      color-mix(in srgb, var(--tb-color-warning) 6%, transparent),
      transparent 45%),
    var(--tb-color-bg);
  min-height: 100vh;
}

body.tb-scroll-lock {
  overflow: hidden;
}

.tb-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.tb-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--tb-color-surface);
  border-right: 1px solid var(--tb-color-border);
  display: flex;
  flex-direction: column;
  gap: var(--tb-space-5);
  padding: var(--tb-space-5) var(--tb-space-3);
}

.tb-sidebar__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--tb-space-2) var(--tb-space-3);
  text-decoration: none;
  color: var(--tb-color-text);
}

.tb-sidebar__brand-logo {
  display: block;
  width: 100%;
  max-width: 200px;
  height: auto;
}

.tb-sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-height: 0;
}

.tb-nav-item {
  display: flex;
  align-items: center;
  gap: var(--tb-space-3);
  padding: 10px var(--tb-space-3);
  border-radius: var(--tb-radius-sm);
  color: var(--tb-color-text-muted);
  text-decoration: none;
  font-size: var(--tb-font-size-sm);
  font-weight: var(--tb-font-weight-medium);
  transition: background-color 120ms ease, color 120ms ease;
}

.tb-nav-item:hover {
  background: var(--tb-color-surface-muted);
  color: var(--tb-color-text);
}

.tb-nav-item.is-active {
  background: var(--tb-color-accent-soft);
  color: var(--tb-color-accent-strong);
  font-weight: var(--tb-font-weight-semibold);
}

.tb-nav-item__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.tb-nav-item:focus-visible {
  outline: 2px solid var(--tb-color-focus);
  outline-offset: 2px;
}

/* Sidebar user block */
.tb-sidebar__user-wrap {
  display: block;
}

.tb-sidebar__user {
  display: flex;
  align-items: center;
  gap: var(--tb-space-3);
  padding: var(--tb-space-3);
  border-radius: var(--tb-radius-md);
  background: var(--tb-color-surface-alt);
  border: 1px solid var(--tb-color-border);
  text-decoration: none;
  color: var(--tb-color-text);
  cursor: pointer;
}

.tb-sidebar__user:hover {
  border-color: var(--tb-color-border-strong);
  background: var(--tb-color-surface-muted);
}

.tb-sidebar__user-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.tb-sidebar__user-meta strong {
  font-size: var(--tb-font-size-sm);
  font-weight: var(--tb-font-weight-semibold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tb-sidebar__user-meta span {
  font-size: var(--tb-font-size-xs);
  color: var(--tb-color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tb-sidebar__user-caret {
  width: 16px;
  height: 16px;
  color: var(--tb-color-text-muted);
  flex-shrink: 0;
}

.tb-sidebar__user-menu {
  right: auto;
  left: 0;
  bottom: calc(100% + var(--tb-space-2));
  top: auto;
  margin: 0;
  min-width: 100%;
}

/* Avatar primitive */
.tb-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--tb-radius-round);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--tb-color-accent-soft);
  color: var(--tb-color-accent-strong);
  font-weight: var(--tb-font-weight-bold);
  font-size: var(--tb-font-size-sm);
  text-transform: uppercase;
  flex-shrink: 0;
  letter-spacing: 0;
}

.tb-avatar--xs { width: 28px; height: 28px; font-size: 11px; }
.tb-avatar--sm { width: 36px; height: 36px; }
.tb-avatar--lg { width: 56px; height: 56px; font-size: var(--tb-font-size-md); }

/* ---- Main column ---- */
.tb-shell__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tb-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  /* Keep blur off the sticky element itself; mobile disables it entirely. */
  background: transparent;
  border-bottom: 1px solid var(--tb-color-border);
  display: flex;
  align-items: center;
  gap: var(--tb-space-3);
  padding: var(--tb-space-3) clamp(16px, 3vw, 32px);
  min-height: 64px;
}

.tb-topbar::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: color-mix(in srgb, var(--tb-color-surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.tb-topbar__menu {
  display: none;
  background: transparent;
  border: 0;
  padding: 10px;
  border-radius: var(--tb-radius-sm);
  color: var(--tb-color-text);
  cursor: pointer;
  line-height: 0;
}

.tb-topbar__menu svg {
  width: 22px;
  height: 22px;
}

.tb-topbar__menu:hover {
  background: var(--tb-color-surface-muted);
}

.tb-topbar__brand {
  display: none;
  align-items: center;
  text-decoration: none;
}

.tb-topbar__brand-logo {
  height: 28px;
  width: auto;
}

.tb-topbar__title {
  flex: 1;
  min-width: 0;
  font-weight: var(--tb-font-weight-semibold);
  font-size: var(--tb-font-size-md);
  color: var(--tb-color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tb-topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--tb-space-2);
}

.tb-shell__messages {
  padding: var(--tb-space-3) clamp(16px, 3vw, 32px) 0;
}

.tb-shell__content {
  flex: 1;
  padding: var(--tb-space-6) clamp(16px, 3vw, 32px) var(--tb-space-8);
  max-width: 1400px;
  width: 100%;
  box-sizing: border-box;
}

.tb-shell__mobile-actions {
  display: contents;
}

/* ---- Bottom nav (mobile) ---- */
.tb-bottom-nav {
  display: none;
  z-index: 100;
  width: 100%;
  max-width: 100vw;
  background: var(--tb-color-surface);
  border-top: 1px solid var(--tb-color-border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tb-bottom-nav__item {
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  min-height: var(--tb-bottom-nav-content-height);
  border: 0;
  background: transparent;
  color: var(--tb-color-text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: var(--tb-font-weight-medium);
  cursor: pointer;
  border-radius: 0;
}

.tb-bottom-nav__item:hover {
  background: transparent;
  color: var(--tb-color-text);
}

.tb-bottom-nav__item.is-active {
  color: var(--tb-color-accent-strong);
  background: transparent;
}

.tb-bottom-nav__item svg {
  width: 22px;
  height: 22px;
}

/* ---- Drawers (mobile main menu + More sheet) ---- */
.tb-drawer {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
}

.tb-drawer[aria-hidden="false"] {
  display: block;
}

.tb-drawer__backdrop {
  position: absolute;
  inset: 0;
  background: var(--tb-color-overlay-50);
  animation: tb-drawer-fade 180ms ease-out;
}

.tb-drawer__panel {
  position: absolute;
  left: 0;
  right: 0;
  background: var(--tb-color-surface);
  overflow-y: auto;
  box-shadow: var(--tb-shadow-lg);
}

.tb-drawer--bottom .tb-drawer__panel {
  bottom: 0;
  border-radius: var(--tb-radius-lg) var(--tb-radius-lg) 0 0;
  padding: var(--tb-space-4) var(--tb-space-5) calc(var(--tb-space-6) + env(safe-area-inset-bottom, 0px));
  max-height: 82vh;
  animation: tb-drawer-slide-up 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.tb-drawer--top .tb-drawer__panel {
  top: 0;
  border-radius: 0 0 var(--tb-radius-lg) var(--tb-radius-lg);
  padding: calc(var(--tb-space-5) + env(safe-area-inset-top, 0px)) var(--tb-space-5) var(--tb-space-5);
  max-height: 82vh;
  animation: tb-drawer-slide-down 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.tb-drawer--top .tb-drawer__grip {
  display: none;
}

@keyframes tb-drawer-slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

@keyframes tb-drawer-slide-down {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}

@keyframes tb-drawer-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.tb-drawer__grip {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--tb-color-border-strong);
  margin: 0 auto var(--tb-space-4);
}

.tb-drawer__title {
  margin: 0 0 var(--tb-space-3);
  font-size: var(--tb-font-size-md);
  font-weight: var(--tb-font-weight-semibold);
}

.tb-drawer__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tb-drawer__list a,
.tb-drawer__list button {
  display: flex;
  align-items: center;
  gap: var(--tb-space-3);
  width: 100%;
  padding: var(--tb-space-3);
  border-radius: var(--tb-radius-sm);
  background: transparent;
  border: 0;
  color: var(--tb-color-text);
  text-align: left;
  text-decoration: none;
  font-family: inherit;
  font-size: var(--tb-font-size-sm);
  font-weight: var(--tb-font-weight-medium);
  cursor: pointer;
}

.tb-drawer__list a:hover,
.tb-drawer__list button:hover {
  background: var(--tb-color-surface-muted);
}

.tb-drawer__list a.is-active,
.tb-drawer__list button.is-active {
  background: var(--tb-color-accent-soft);
  color: var(--tb-color-accent-strong);
  font-weight: var(--tb-font-weight-semibold);
}

.tb-drawer__list a.is-active svg,
.tb-drawer__list button.is-active svg {
  color: var(--tb-color-accent-strong);
}

.tb-drawer__list svg {
  width: 20px;
  height: 20px;
  color: var(--tb-color-text-muted);
  flex-shrink: 0;
}

.tb-drawer__list form {
  margin: 0;
}

/* ---- Responsive ---- */
@media (max-width: 960px) {
  body.tb-shell-v3--app {
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .tb-shell {
    height: 100%;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .tb-sidebar {
    display: none;
  }

  .tb-shell__main {
    position: relative;
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  .tb-topbar {
    position: relative;
    top: auto;
    flex: 0 0 auto;
  }

  .tb-topbar::before {
    background: var(--tb-color-surface);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .tb-topbar__menu {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .tb-topbar__brand {
    display: inline-flex;
  }

  .tb-topbar__title {
    display: none;
  }

  .tb-bottom-nav {
    display: flex;
    position: relative;
    flex: 0 0 auto;
    width: 100%;
  }

  .tb-shell__content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--tb-space-6);
  }

  .tb-shell-has-sticky-cta .tb-shell__content {
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }

  .tb-shell-has-fab .tb-shell__content {
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }

  .tb-shell__mobile-actions {
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    bottom: var(--tb-bottom-nav-total-height);
    z-index: 120;
    height: 0;
    pointer-events: none;
  }

  .tb-shell__mobile-actions > * {
    pointer-events: auto;
  }

  .tb-shell-has-fab .tb-shell__mobile-actions .tb-fab {
    position: absolute;
    right: 16px;
    bottom: var(--tb-space-4);
  }

  body.tb-scroll-lock .tb-shell__content,
  body.tb-no-scroll .tb-shell__content,
  body.editor-touch-scroll-lock .tb-shell__content {
    overflow: hidden;
  }
}

/* Desktop: drawer not needed */
@media (min-width: 961px) {
  .tb-drawer {
    display: none !important;
  }
}

/* ---- Auth shell (login / invitation screens) ----
   V3-design-taal zonder app-navigatie: gecentreerde kaart-flow. */
.tb-auth-shell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: var(--tb-space-6) var(--tb-space-4);
}

.tb-auth-shell__inner {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: var(--tb-space-4);
}

.tb-auth-shell__logo {
  text-align: center;
}

.tb-auth-shell__logo img {
  width: 100%;
  max-width: 300px;
  height: auto;
}

.tb-auth-shell__hint {
  margin: 0;
  text-align: center;
  font-size: var(--tb-font-size-sm);
  color: var(--tb-color-text-muted);
}

/* Password login is a collapsed fallback next to the default magic-link
   flow (see templates/accounts/login.html). Matches the disclosure styling
   already used in .tb-pwa-tip__how. */
.tb-auth-shell__password-toggle summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--tb-color-accent-strong);
  font-size: var(--tb-font-size-sm);
}

.tb-auth-shell__password-toggle .tb-card {
  margin-top: var(--tb-space-3);
}

.tb-auth-shell__password-toggle .tb-auth-shell__hint {
  margin-top: var(--tb-space-3);
}

.tb-auth-submit {
  width: 100%;
}
