/* ==========================================================================
   sidebar_toybox.css — Toy Box skin for the app-shell sidebar.

   The sidebar in base.html uses the DESIGN-SYSTEM component API documented in
   DESIGN.md §4 and demoed in the specimen:  .tb-side / .tb-side__label /
   .tb-side__item  ([aria-current] = violet fill), plus a few app-shell-only
   sub-elements (__logo, __icon-btn, __avatar, __foot-link, __logout) for the
   header/footer chrome the marketing rail doesn't have.

   Self-contained on purpose:
   • We do NOT load site_toybox.css here — its bare element selectors (body, a,
     h1–h3, .card, table…) would leak into every page that has no .tbm wrapper,
     including the /studio/ surfaces that share this same shell.
   • Tokens are re-declared with a --tb- prefix and SCOPED to the sidebar chrome,
     so we never clobber the global --ink the clay/material components rely on.
   Loaded in <head> AFTER the clay/material design system so it always wins.
   ========================================================================== */

/* --- Toy Box tokens, scoped to the shell sidebar chrome only ------------- */
.sidebar,
#global-sidebar-tooltip,
.tb-acct-menu,
.app-shell-mobile-btn{
  --tb-violet:      oklch(58% 0.19 300);
  --tb-violet-deep: oklch(46% 0.17 300);
  --tb-rose:        oklch(70% 0.16 10);
  --tb-card:        oklch(99.5% 0.002 300);   /* raised panel face */
  --tb-ink:         oklch(23% 0.03 300);      /* primary text (local, not global --ink) */
  --tb-soft:        oklch(45% 0.025 300);     /* muted text / rest icons */
  --tb-hover:       oklch(93% 0.03 300);      /* subtle hover wash */
  --tb-border:      oklch(88% 0.03 300);
  --tb-r-md: 18px; --tb-r-sm: 12px;
  --tb-lift: 0 2px 4px rgb(40 20 80 / .06), 0 12px 28px -8px rgb(40 20 80 / .16),
             0 32px 64px -24px rgb(40 20 80 / .22);
  --tb-ring-strong: 0 0 0 3px oklch(58% 0.19 300 / .30);
  --tb-dur: .15s;
}

/* --- Panel: light card surface + soft lift + hairline edge --------------- */
.sidebar.tb-side{
  background: var(--tb-card);
  border: 0;
  border-inline-end: 1px solid var(--tb-border);
  box-shadow: var(--tb-lift);
}

/* --- Panel layout: the app shell rail is a full-height flex COLUMN -------
   The "loaded AFTER the design system so it always wins" note above does not
   hold for a page that links site_toybox.css from its own content/styles block
   -- base.html renders those after this file, so that sheet's marketing
   nav-rail rule (.tb-side{display:grid;align-content:start;padding:1rem})
   wins on equal specificity and silently re-lays-out the shell: `flex flex-col`
   is off, the nav's `flex-1` stops expanding, and the user chip rides up under
   the last nav item instead of sitting at the bottom. Element + both classes
   outranks a lone class whatever the load order. --- */
aside.sidebar.tb-side{
  display: flex;
  flex-direction: column;
  padding: 0;
  gap: 0;
  border-radius: 0;
}

/* --- Header: brand mark + collapse/close icon buttons ------------------- */
.sidebar > .h-16{ border-bottom: 1px solid var(--tb-border); }

.tb-side__logo{
  background: var(--tb-card);
  border: 1px solid var(--tb-border);
  box-shadow: var(--tb-lift);
}
.tb-side__logo-mark{
  width: 24px;
  height: 24px;
  object-fit: contain;
}
.tb-side__icon-btn,
.tb-side__icon-btn--rose{ transition: color var(--tb-dur), background var(--tb-dur); }
.tb-side__icon-btn:hover{ background: var(--tb-hover); color: var(--tb-violet-deep); }
.tb-side__icon-btn--rose:hover{ background: var(--tb-hover); color: var(--tb-rose); }

/* --- Nav items: FULL Toy Box .tb-side__item spec (layout + skin) --------
   Mirrors site_toybox.css .tb-side__item so the rows keep flex layout,
   padding and rounding once the clay-nav-item classes are gone. --- */
.sidebar .tb-side__item{
  display: flex;
  align-items: center;
  gap: .7em;
  font-weight: 600;
  font-size: .95rem;
  text-decoration: none;
  color: var(--tb-ink);
  padding: .6em .8em;
  border: 0;
  border-radius: var(--tb-r-md);
  background: transparent;
  transition: background var(--tb-dur), color var(--tb-dur);
}
.sidebar .tb-side__item:hover{
  background: var(--tb-hover);
  color: var(--tb-ink);
  transform: none;
}
/* Active row — flat violet fill, white content (DS [aria-current] rule) */
.sidebar .tb-side__item[aria-current]{
  background: var(--tb-violet);
  color: #fff;
}
.sidebar .tb-side__item[aria-current]:hover{ background: var(--tb-violet-deep); }
.sidebar .tb-side__item:focus-visible{ outline: none; box-shadow: var(--tb-ring-strong); }

/* Stacked "Studio" sub-label: muted at rest, legible on the violet row */
.sidebar .sidebar-subtext{ color: var(--tb-soft); opacity: 1; }
.sidebar .tb-side__item[aria-current] .sidebar-subtext{ color: #fff; opacity: .82; }

/* --- Footer: user row + logout ------------------------------------------ */
.sidebar > div:last-child{ border-top: 1px solid var(--tb-border); }

.tb-side__avatar{
  background: linear-gradient(135deg, var(--tb-violet), var(--tb-violet-deep));
}
.tb-side__foot-link{ transition: background var(--tb-dur); }
.tb-side__foot-link:hover{ background: var(--tb-hover); }

/* --- Account chip (a <button>) + the account menu it rolls up ------------
   The menu is teleported to <body> by _sidebar.html, so it carries its own
   token scope (see the token selector above). */
button.tb-side__foot-link{
  width: 100%; border: 0; background: transparent; color: inherit;
  font: inherit; text-align: start; cursor: pointer;
}
.tb-side__foot-link.is-open{ background: var(--tb-hover); }
.tb-side__foot-link:focus-visible{ outline: none; box-shadow: var(--tb-ring-strong); }
.tb-side__foot-chevron{
  font-size: 1.15rem !important; color: var(--tb-soft); flex-shrink: 0;
  transition: color var(--tb-dur);
}
.tb-side__foot-link:hover .tb-side__foot-chevron,
.tb-side__foot-link.is-open .tb-side__foot-chevron{ color: var(--tb-violet); }

.tb-acct-menu{
  position: fixed; z-index: 60;
  padding: .4rem;
  background: var(--tb-card);
  color: var(--tb-ink);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-r-md);
  box-shadow: var(--tb-lift);
  transform-origin: bottom center;
}
@media (min-width: 1024px){
  .tb-acct-menu.is-side{ transform-origin: bottom left; }
  [dir="rtl"] .tb-acct-menu.is-side{ transform-origin: bottom right; }
}
.tb-acct-menu__head{
  display: flex; align-items: center; gap: .7rem;
  padding: .55rem .6rem .65rem;
}
.tb-acct-menu__avatar{
  width: 2.5rem; height: 2.5rem; border-radius: 999px; flex-shrink: 0; overflow: hidden;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .95rem;
}
.tb-acct-menu__avatar img{ width: 100%; height: 100%; object-fit: cover; }
.tb-acct-menu__who{ min-width: 0; }
.tb-acct-menu__name,
.tb-acct-menu__meta{ margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-acct-menu__name{ font-weight: 800; font-size: .92rem; line-height: 1.25; }
.tb-acct-menu__meta{ font-size: .76rem; color: var(--tb-soft); line-height: 1.3; }
.tb-acct-menu__sep{ height: 1px; margin: .3rem .35rem; background: var(--tb-border); }
.tb-acct-menu__item{
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .65rem; border-radius: var(--tb-r-sm);
  color: var(--tb-ink); font-weight: 700; font-size: .9rem; text-decoration: none;
  outline: none;
  transition: background var(--tb-dur), color var(--tb-dur);
}
.tb-acct-menu__item .material-symbols-outlined{ font-size: 1.25rem; color: var(--tb-soft); transition: color var(--tb-dur); }
.tb-acct-menu__label{ flex: 1; min-width: 0; }
.tb-acct-menu__tick{ opacity: 0; color: var(--tb-violet) !important; font-size: 1.1rem !important; }
.tb-acct-menu__item[aria-current="page"] .tb-acct-menu__tick{ opacity: 1; }
.tb-acct-menu__item[aria-current="page"]{ color: var(--tb-violet-deep); }
.tb-acct-menu__item:hover,
.tb-acct-menu__item:focus-visible{ background: var(--tb-hover); }
.tb-acct-menu__item:hover .material-symbols-outlined,
.tb-acct-menu__item:focus-visible .material-symbols-outlined{ color: var(--tb-violet); }
.tb-acct-menu__item:focus-visible{ box-shadow: inset 0 0 0 2px var(--tb-violet); }
.tb-acct-menu__item--exit:hover,
.tb-acct-menu__item--exit:focus-visible{
  background: oklch(70% 0.16 10 / .14);
  color: oklch(48% 0.17 10);
}
.tb-acct-menu__item--exit:hover .material-symbols-outlined,
.tb-acct-menu__item--exit:focus-visible .material-symbols-outlined{ color: oklch(55% 0.18 10); }
.tb-acct-menu__item--exit:focus-visible{ box-shadow: inset 0 0 0 2px var(--tb-rose); }
.dark .tb-acct-menu__item--exit:hover,
.dark .tb-acct-menu__item--exit:focus-visible{ color: oklch(82% 0.1 10); }

/* Roll-up: rises out of the chip. Classes driven by x-transition. */
.tb-acct-enter{ transition: opacity .16s ease-out, transform .2s cubic-bezier(.2,.8,.2,1); }
.tb-acct-leave{ transition: opacity .1s ease-in, transform .1s ease-in; }
.tb-acct-from{ opacity: 0; transform: translateY(6px) scale(.98); }
.tb-acct-to{ opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce){
  .tb-acct-from{ transform: none; }
}


/* --- Collapsed-state tooltip (built by JS with .clay-card) --------------- */
#global-sidebar-tooltip{
  background: var(--tb-card);
  color: var(--tb-ink);
  box-shadow: var(--tb-lift);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-r-sm);
}

/* --- Mobile menu (hamburger) button ------------------------------------- */
.app-shell-mobile-btn{
  background: var(--tb-card) !important;
  color: var(--tb-ink) !important;
  box-shadow: var(--tb-lift) !important;
  border: 1px solid var(--tb-border) !important;
  border-radius: var(--tb-r-md) !important;
}

/* --- Optional dark seam (harmless if the shell never sets .dark) --------- */
.dark .sidebar,
.dark #global-sidebar-tooltip,
.dark .tb-acct-menu,
.dark .app-shell-mobile-btn{
  --tb-violet-deep: oklch(80% 0.13 300);
  --tb-card:   oklch(25.5% 0.026 300);
  --tb-ink:    oklch(95% 0.008 300);
  --tb-soft:   oklch(72% 0.02 300);
  --tb-hover:  oklch(33% 0.028 300);
  --tb-border: oklch(40% 0.02 300);
  --tb-lift: 0 2px 4px rgb(0 0 0 / .35), 0 12px 28px -8px rgb(0 0 0 / .55),
             0 32px 64px -24px rgb(0 0 0 / .65);
}
